1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_DELEGATE_H_ 6 #define CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_DELEGATE_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "include/cef_app.h" 12 #include "libcef/common/alloy/alloy_content_client.h" 13 #include "libcef/common/app_manager.h" 14 #include "libcef/common/main_runner_handler.h" 15 #include "libcef/common/resource_bundle_delegate.h" 16 #include "libcef/common/task_runner_manager.h" 17 18 #include "base/compiler_specific.h" 19 #include "content/public/app/content_main_delegate.h" 20 21 namespace base { 22 class CommandLine; 23 } 24 25 class AlloyContentBrowserClient; 26 class AlloyContentRendererClient; 27 class ChromeContentUtilityClient; 28 29 // Manages state specific to the CEF runtime. 30 class AlloyMainDelegate : public content::ContentMainDelegate, 31 public CefAppManager, 32 public CefTaskRunnerManager { 33 public: 34 // |runner| and |settings| will be non-nullptr for the main process only, 35 // and will outlive this object. 36 AlloyMainDelegate(CefMainRunnerHandler* runner, 37 CefSettings* settings, 38 CefRefPtr<CefApp> application); 39 40 AlloyMainDelegate(const AlloyMainDelegate&) = delete; 41 AlloyMainDelegate& operator=(const AlloyMainDelegate&) = delete; 42 43 ~AlloyMainDelegate() override; 44 45 // content::ContentMainDelegate overrides. 46 void PreBrowserMain() override; 47 bool BasicStartupComplete(int* exit_code) override; 48 void PreSandboxStartup() override; 49 void SandboxInitialized(const std::string& process_type) override; 50 absl::variant<int, content::MainFunctionParams> RunProcess( 51 const std::string& process_type, 52 content::MainFunctionParams main_function_params) override; 53 void ProcessExiting(const std::string& process_type) override; 54 #if BUILDFLAG(IS_LINUX) 55 void ZygoteForked() override; 56 #endif 57 content::ContentBrowserClient* CreateContentBrowserClient() override; 58 content::ContentRendererClient* CreateContentRendererClient() override; 59 content::ContentUtilityClient* CreateContentUtilityClient() override; 60 61 protected: 62 // CefAppManager overrides. GetApplication()63 CefRefPtr<CefApp> GetApplication() override { return application_; } GetContentClient()64 content::ContentClient* GetContentClient() override { 65 return &content_client_; 66 } 67 CefRefPtr<CefRequestContext> GetGlobalRequestContext() override; 68 CefBrowserContext* CreateNewBrowserContext( 69 const CefRequestContextSettings& settings, 70 base::OnceClosure initialized_cb) override; 71 72 // CefTaskRunnerManager overrides. 73 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() 74 override; 75 scoped_refptr<base::SingleThreadTaskRunner> GetUserVisibleTaskRunner() 76 override; 77 scoped_refptr<base::SingleThreadTaskRunner> GetUserBlockingTaskRunner() 78 override; 79 scoped_refptr<base::SingleThreadTaskRunner> GetRenderTaskRunner() override; 80 scoped_refptr<base::SingleThreadTaskRunner> GetWebWorkerTaskRunner() override; 81 82 private: 83 void InitializeResourceBundle(); 84 85 CefMainRunnerHandler* const runner_; 86 CefSettings* const settings_; 87 CefRefPtr<CefApp> application_; 88 89 std::unique_ptr<AlloyContentBrowserClient> browser_client_; 90 std::unique_ptr<AlloyContentRendererClient> renderer_client_; 91 std::unique_ptr<ChromeContentUtilityClient> utility_client_; 92 AlloyContentClient content_client_; 93 94 CefResourceBundleDelegate resource_bundle_delegate_; 95 }; 96 97 #endif // CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_DELEGATE_H_ 98