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_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_ 6 #define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_ 7 #pragma once 8 9 #include "include/cef_request_context_handler.h" 10 #include "libcef/browser/alloy/chrome_profile_alloy.h" 11 #include "libcef/browser/browser_context.h" 12 #include "libcef/browser/request_context_handler_map.h" 13 14 #include "chrome/browser/download/download_prefs.h" 15 #include "components/proxy_config/pref_proxy_config_tracker.h" 16 #include "components/visitedlink/browser/visitedlink_delegate.h" 17 18 class CefDownloadManagerDelegate; 19 class CefSSLHostStateDelegate; 20 class CefVisitedLinkListener; 21 class MediaDeviceIDSalt; 22 class PrefService; 23 24 namespace extensions { 25 class CefExtensionSystem; 26 } 27 28 namespace visitedlink { 29 class VisitedLinkWriter; 30 } 31 32 // See CefBrowserContext documentation for usage. Only accessed on the UI thread 33 // unless otherwise indicated. ChromeProfileAlloy must be the first listed base 34 // class to avoid issues when casting between void* and content::BrowserContext* 35 // in Chromium code. 36 class AlloyBrowserContext : public ChromeProfileAlloy, 37 public CefBrowserContext, 38 public visitedlink::VisitedLinkDelegate { 39 public: 40 explicit AlloyBrowserContext(const CefRequestContextSettings& settings); 41 42 AlloyBrowserContext(const AlloyBrowserContext&) = delete; 43 AlloyBrowserContext& operator=(const AlloyBrowserContext&) = delete; 44 45 // CefBrowserContext overrides. AsBrowserContext()46 content::BrowserContext* AsBrowserContext() override { return this; } AsProfile()47 Profile* AsProfile() override { return this; } 48 bool IsInitialized() const override; 49 void StoreOrTriggerInitCallback(base::OnceClosure callback) override; 50 void Initialize() override; 51 void Shutdown() override; 52 void RemoveCefRequestContext(CefRequestContextImpl* context) override; 53 void LoadExtension(const CefString& root_directory, 54 CefRefPtr<CefDictionaryValue> manifest, 55 CefRefPtr<CefExtensionHandler> handler, 56 CefRefPtr<CefRequestContext> loader_context) override; 57 bool GetExtensions(std::vector<CefString>& extension_ids) override; 58 CefRefPtr<CefExtension> GetExtension(const CefString& extension_id) override; 59 bool UnloadExtension(const CefString& extension_id) override; 60 bool IsPrintPreviewSupported() const override; 61 62 // content::BrowserContext overrides. 63 content::ResourceContext* GetResourceContext() override; 64 content::ClientHintsControllerDelegate* GetClientHintsControllerDelegate() 65 override; 66 base::FilePath GetPath() override; 67 base::FilePath GetPath() const override; 68 std::unique_ptr<content::ZoomLevelDelegate> CreateZoomLevelDelegate( 69 const base::FilePath& partition_path) override; 70 content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; 71 content::BrowserPluginGuestManager* GetGuestManager() override; 72 storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; 73 content::PlatformNotificationService* GetPlatformNotificationService() 74 override; 75 content::PushMessagingService* GetPushMessagingService() override; 76 content::StorageNotificationService* GetStorageNotificationService() override; 77 content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; 78 content::PermissionControllerDelegate* GetPermissionControllerDelegate() 79 override; 80 content::BackgroundFetchDelegate* GetBackgroundFetchDelegate() override; 81 content::BackgroundSyncController* GetBackgroundSyncController() override; 82 content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate() 83 override; 84 std::string GetMediaDeviceIDSalt() override; 85 86 // Profile overrides. 87 ChromeZoomLevelPrefs* GetZoomLevelPrefs() override; 88 scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override; 89 PrefService* GetPrefs() override; AllowsBrowserWindows()90 bool AllowsBrowserWindows() const override { return false; } 91 const PrefService* GetPrefs() const override; 92 ProfileKey* GetProfileKey() const override; 93 policy::SchemaRegistryService* GetPolicySchemaRegistryService() override; 94 policy::UserCloudPolicyManager* GetUserCloudPolicyManager() override; 95 policy::ProfilePolicyConnector* GetProfilePolicyConnector() override; 96 const policy::ProfilePolicyConnector* GetProfilePolicyConnector() 97 const override; 98 bool IsNewProfile() const override; 99 100 // Values checked in ProfileNetworkContextService::CreateNetworkContextParams 101 // when creating the NetworkContext. ShouldRestoreOldSessionCookies()102 bool ShouldRestoreOldSessionCookies() override { 103 return ShouldPersistSessionCookies(); 104 } ShouldPersistSessionCookies()105 bool ShouldPersistSessionCookies() const override { 106 return !!settings_.persist_session_cookies; 107 } 108 109 // visitedlink::VisitedLinkDelegate methods. 110 void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; 111 112 // Manages extensions. extension_system()113 extensions::CefExtensionSystem* extension_system() const { 114 return extension_system_; 115 } 116 117 // Called from AlloyBrowserHostImpl::DidFinishNavigation to update the table 118 // of visited links. 119 void AddVisitedURLs(const std::vector<GURL>& urls); 120 121 // Called from DownloadPrefs::FromBrowserContext. 122 DownloadPrefs* GetDownloadPrefs(); 123 124 private: 125 ~AlloyBrowserContext() override; 126 127 std::unique_ptr<PrefService> pref_service_; 128 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 129 130 std::unique_ptr<CefDownloadManagerDelegate> download_manager_delegate_; 131 std::unique_ptr<CefSSLHostStateDelegate> ssl_host_state_delegate_; 132 std::unique_ptr<visitedlink::VisitedLinkWriter> visitedlink_master_; 133 // |visitedlink_listener_| is owned by visitedlink_master_. 134 CefVisitedLinkListener* visitedlink_listener_ = nullptr; 135 136 // Owned by the KeyedService system. 137 extensions::CefExtensionSystem* extension_system_ = nullptr; 138 139 // The key to index KeyedService instances created by 140 // SimpleKeyedServiceFactory. 141 std::unique_ptr<ProfileKey> key_; 142 143 std::unique_ptr<DownloadPrefs> download_prefs_; 144 145 std::unique_ptr<content::ResourceContext> resource_context_; 146 147 scoped_refptr<MediaDeviceIDSalt> media_device_id_salt_; 148 }; 149 150 #endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_CONTEXT_H_ 151