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