1 // Copyright 2020 The Chromium Embedded Framework Authors. 2 // Portions copyright 2012 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #ifndef CEF_LIBCEF_COMMON_CHROME_CHROME_MAIN_DELEGATE_CEF_ 7 #define CEF_LIBCEF_COMMON_CHROME_CHROME_MAIN_DELEGATE_CEF_ 8 9 #include <memory> 10 11 #include "include/cef_app.h" 12 #include "libcef/common/app_manager.h" 13 #include "libcef/common/chrome/chrome_content_client_cef.h" 14 #include "libcef/common/main_runner_handler.h" 15 #include "libcef/common/task_runner_manager.h" 16 17 #include "chrome/app/chrome_main_delegate.h" 18 19 class ChromeContentBrowserClientCef; 20 class ChromeContentRendererClientCef; 21 22 // CEF override of ChromeMainDelegate 23 class ChromeMainDelegateCef : public ChromeMainDelegate, 24 public CefAppManager, 25 public CefTaskRunnerManager { 26 public: 27 // |runner| will be non-nullptr for the main process only, and will outlive 28 // this object. 29 ChromeMainDelegateCef(CefMainRunnerHandler* runner, 30 CefSettings* settings, 31 CefRefPtr<CefApp> application); 32 33 ChromeMainDelegateCef(const ChromeMainDelegateCef&) = delete; 34 ChromeMainDelegateCef& operator=(const ChromeMainDelegateCef&) = delete; 35 36 ~ChromeMainDelegateCef() override; 37 38 // ChromeMainDelegate overrides. 39 bool BasicStartupComplete(int* exit_code) override; 40 void PreSandboxStartup() override; 41 void PreBrowserMain() override; 42 absl::variant<int, content::MainFunctionParams> RunProcess( 43 const std::string& process_type, 44 content::MainFunctionParams main_function_params) override; 45 #if BUILDFLAG(IS_LINUX) 46 void ZygoteForked() override; 47 #endif 48 content::ContentClient* CreateContentClient() override; 49 content::ContentBrowserClient* CreateContentBrowserClient() override; 50 content::ContentRendererClient* CreateContentRendererClient() override; 51 52 protected: 53 // CefAppManager overrides. GetApplication()54 CefRefPtr<CefApp> GetApplication() override { return application_; } GetContentClient()55 content::ContentClient* GetContentClient() override { 56 return &chrome_content_client_cef_; 57 } 58 CefRefPtr<CefRequestContext> GetGlobalRequestContext() override; 59 CefBrowserContext* CreateNewBrowserContext( 60 const CefRequestContextSettings& settings, 61 base::OnceClosure initialized_cb) override; 62 63 // CefTaskRunnerManager overrides. 64 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() 65 override; 66 scoped_refptr<base::SingleThreadTaskRunner> GetUserVisibleTaskRunner() 67 override; 68 scoped_refptr<base::SingleThreadTaskRunner> GetUserBlockingTaskRunner() 69 override; 70 scoped_refptr<base::SingleThreadTaskRunner> GetRenderTaskRunner() override; 71 scoped_refptr<base::SingleThreadTaskRunner> GetWebWorkerTaskRunner() override; 72 73 private: 74 ChromeContentBrowserClientCef* content_browser_client() const; 75 ChromeContentRendererClientCef* content_renderer_client() const; 76 77 CefMainRunnerHandler* const runner_; 78 CefSettings* const settings_; 79 CefRefPtr<CefApp> application_; 80 81 // We use this instead of ChromeMainDelegate::chrome_content_client_. 82 ChromeContentClientCef chrome_content_client_cef_; 83 }; 84 85 #endif // CEF_LIBCEF_COMMON_CHROME_CHROME_MAIN_DELEGATE_CEF_ 86