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 "base/macros.h" 18 #include "chrome/app/chrome_main_delegate.h" 19 20 class ChromeContentBrowserClientCef; 21 class ChromeContentRendererClientCef; 22 23 // CEF override of ChromeMainDelegate 24 class ChromeMainDelegateCef : public ChromeMainDelegate, 25 public CefAppManager, 26 public CefTaskRunnerManager { 27 public: 28 // |runner| will be non-nullptr for the main process only, and will outlive 29 // this object. 30 ChromeMainDelegateCef(CefMainRunnerHandler* runner, 31 CefSettings* settings, 32 CefRefPtr<CefApp> application); 33 ~ChromeMainDelegateCef() override; 34 35 // ChromeMainDelegate overrides. 36 bool BasicStartupComplete(int* exit_code) override; 37 void PreSandboxStartup() override; 38 void PreCreateMainMessageLoop() override; 39 int RunProcess( 40 const std::string& process_type, 41 const content::MainFunctionParams& main_function_params) override; 42 #if defined(OS_LINUX) 43 void ZygoteForked() override; 44 #endif 45 content::ContentClient* CreateContentClient() override; 46 content::ContentBrowserClient* CreateContentBrowserClient() override; 47 content::ContentRendererClient* CreateContentRendererClient() override; 48 49 protected: 50 // CefAppManager overrides. GetApplication()51 CefRefPtr<CefApp> GetApplication() override { return application_; } GetContentClient()52 content::ContentClient* GetContentClient() override { 53 return &chrome_content_client_cef_; 54 } 55 CefRefPtr<CefRequestContext> GetGlobalRequestContext() override; 56 CefBrowserContext* CreateNewBrowserContext( 57 const CefRequestContextSettings& settings, 58 base::OnceClosure initialized_cb) override; 59 60 // CefTaskRunnerManager overrides. 61 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() 62 override; 63 scoped_refptr<base::SingleThreadTaskRunner> GetUserVisibleTaskRunner() 64 override; 65 scoped_refptr<base::SingleThreadTaskRunner> GetUserBlockingTaskRunner() 66 override; 67 scoped_refptr<base::SingleThreadTaskRunner> GetRenderTaskRunner() override; 68 scoped_refptr<base::SingleThreadTaskRunner> GetWebWorkerTaskRunner() override; 69 70 private: 71 ChromeContentBrowserClientCef* content_browser_client() const; 72 ChromeContentRendererClientCef* content_renderer_client() const; 73 74 CefMainRunnerHandler* const runner_; 75 CefSettings* const settings_; 76 CefRefPtr<CefApp> application_; 77 78 // We use this instead of ChromeMainDelegate::chrome_content_client_. 79 ChromeContentClientCef chrome_content_client_cef_; 80 81 DISALLOW_COPY_AND_ASSIGN(ChromeMainDelegateCef); 82 }; 83 84 #endif // CEF_LIBCEF_COMMON_CHROME_CHROME_MAIN_DELEGATE_CEF_ 85