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 ~AlloyMainDelegate() override; 40 41 // content::ContentMainDelegate overrides. 42 void PreCreateMainMessageLoop() override; 43 bool BasicStartupComplete(int* exit_code) override; 44 void PreSandboxStartup() override; 45 void SandboxInitialized(const std::string& process_type) override; 46 int RunProcess( 47 const std::string& process_type, 48 const content::MainFunctionParams& main_function_params) override; 49 void ProcessExiting(const std::string& process_type) override; 50 #if defined(OS_LINUX) 51 void ZygoteForked() override; 52 #endif 53 content::ContentBrowserClient* CreateContentBrowserClient() override; 54 content::ContentRendererClient* CreateContentRendererClient() override; 55 content::ContentUtilityClient* CreateContentUtilityClient() override; 56 57 protected: 58 // CefAppManager overrides. GetApplication()59 CefRefPtr<CefApp> GetApplication() override { return application_; } GetContentClient()60 content::ContentClient* GetContentClient() override { 61 return &content_client_; 62 } 63 CefRefPtr<CefRequestContext> GetGlobalRequestContext() override; 64 CefBrowserContext* CreateNewBrowserContext( 65 const CefRequestContextSettings& settings, 66 base::OnceClosure initialized_cb) override; 67 68 // CefTaskRunnerManager overrides. 69 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() 70 override; 71 scoped_refptr<base::SingleThreadTaskRunner> GetUserVisibleTaskRunner() 72 override; 73 scoped_refptr<base::SingleThreadTaskRunner> GetUserBlockingTaskRunner() 74 override; 75 scoped_refptr<base::SingleThreadTaskRunner> GetRenderTaskRunner() override; 76 scoped_refptr<base::SingleThreadTaskRunner> GetWebWorkerTaskRunner() override; 77 78 private: 79 void InitializeResourceBundle(); 80 81 CefMainRunnerHandler* const runner_; 82 CefSettings* const settings_; 83 CefRefPtr<CefApp> application_; 84 85 std::unique_ptr<AlloyContentBrowserClient> browser_client_; 86 std::unique_ptr<AlloyContentRendererClient> renderer_client_; 87 std::unique_ptr<ChromeContentUtilityClient> utility_client_; 88 AlloyContentClient content_client_; 89 90 CefResourceBundleDelegate resource_bundle_delegate_; 91 92 DISALLOW_COPY_AND_ASSIGN(AlloyMainDelegate); 93 }; 94 95 #endif // CEF_LIBCEF_COMMON_ALLOY_ALLOY_MAIN_DELEGATE_H_ 96