1 // Copyright 2020 The Chromium Embedded Framework 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_APP_MANAGER_H_ 6 #define CEF_LIBCEF_COMMON_APP_MANAGER_H_ 7 #pragma once 8 9 #include <list> 10 11 #include "include/cef_app.h" 12 #include "include/cef_request_context.h" 13 14 #include "base/callback.h" 15 #include "build/build_config.h" 16 #include "content/public/common/content_client.h" 17 18 class CefBrowserContext; 19 struct CefSchemeInfo; 20 21 // Exposes global application state in the main and render processes. 22 class CefAppManager { 23 public: 24 CefAppManager(const CefAppManager&) = delete; 25 CefAppManager& operator=(const CefAppManager&) = delete; 26 27 // Returns the singleton instance that is scoped to CEF lifespan. 28 static CefAppManager* Get(); 29 30 // The following methods are available in both processes. 31 32 virtual CefRefPtr<CefApp> GetApplication() = 0; 33 virtual content::ContentClient* GetContentClient() = 0; 34 35 // Custom scheme information will be registered first with all processes 36 // (url/url_util.h) via ContentClient::AddAdditionalSchemes which calls 37 // AddCustomScheme, and second with Blink (SchemeRegistry) via 38 // ContentRendererClient::WebKitInitialized which calls GetCustomSchemes. 39 void AddCustomScheme(CefSchemeInfo* scheme_info); 40 bool HasCustomScheme(const std::string& scheme_name); 41 42 using SchemeInfoList = std::list<CefSchemeInfo>; 43 const SchemeInfoList* GetCustomSchemes(); 44 45 // Called from ContentClient::AddAdditionalSchemes. 46 void AddAdditionalSchemes(content::ContentClient::Schemes* schemes); 47 48 // The following methods are only available in the main (browser) process. 49 50 // Called from CefRequestContextImpl. |initialized_cb| may be executed 51 // synchronously or asynchronously. 52 virtual CefRefPtr<CefRequestContext> GetGlobalRequestContext() = 0; 53 virtual CefBrowserContext* CreateNewBrowserContext( 54 const CefRequestContextSettings& settings, 55 base::OnceClosure initialized_cb) = 0; 56 57 #if BUILDFLAG(IS_WIN) 58 // Returns the module name (usually libcef.dll). 59 const wchar_t* GetResourceDllName(); 60 #endif 61 62 protected: 63 CefAppManager(); 64 virtual ~CefAppManager(); 65 66 private: 67 // Custom schemes handled by the client. 68 SchemeInfoList scheme_info_list_; 69 bool scheme_info_list_locked_ = false; 70 }; 71 72 #endif // CEF_LIBCEF_COMMON_APP_MANAGER_H_ 73