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_CONTENT_BROWSER_CLIENT_H_ 6 #define CEF_LIBCEF_BROWSER_ALLOY_ALLOY_CONTENT_BROWSER_CLIENT_H_ 7 #pragma once 8 9 #include <string> 10 #include <utility> 11 12 #include "include/cef_request_context_handler.h" 13 #include "libcef/browser/request_context_impl.h" 14 15 #include "base/memory/ref_counted.h" 16 #include "build/build_config.h" 17 #include "content/public/browser/content_browser_client.h" 18 #include "third_party/skia/include/core/SkColor.h" 19 20 class AlloyBrowserMainParts; 21 class CefDevToolsDelegate; 22 23 namespace content { 24 class SiteInstance; 25 } // namespace content 26 27 namespace extensions { 28 class Extension; 29 } 30 31 class AlloyContentBrowserClient : public content::ContentBrowserClient { 32 public: 33 AlloyContentBrowserClient(); 34 ~AlloyContentBrowserClient() override; 35 36 // ContentBrowserClient implementation. 37 std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts( 38 content::MainFunctionParams parameters) override; 39 void RenderProcessWillLaunch(content::RenderProcessHost* host) override; 40 bool ShouldUseProcessPerSite(content::BrowserContext* browser_context, 41 const GURL& site_url) override; 42 bool ShouldUseSpareRenderProcessHost(content::BrowserContext* browser_context, 43 const GURL& site_url) override; 44 bool DoesSiteRequireDedicatedProcess(content::BrowserContext* browser_context, 45 const GURL& effective_site_url) override; 46 bool ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( 47 base::StringPiece scheme, 48 bool is_embedded_origin_secure) override; 49 bool ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel( 50 base::StringPiece scheme, 51 bool is_embedded_origin_secure) override; 52 void OverrideURLLoaderFactoryParams( 53 content::BrowserContext* browser_context, 54 const url::Origin& origin, 55 bool is_for_isolated_world, 56 network::mojom::URLLoaderFactoryParams* factory_params) override; 57 void GetAdditionalWebUISchemes( 58 std::vector<std::string>* additional_schemes) override; 59 void GetAdditionalViewSourceSchemes( 60 std::vector<std::string>* additional_schemes) override; 61 void GetAdditionalAllowedSchemesForFileSystem( 62 std::vector<std::string>* additional_allowed_schemes) override; 63 bool IsWebUIAllowedToMakeNetworkRequests(const url::Origin& origin) override; 64 bool IsHandledURL(const GURL& url) override; 65 void SiteInstanceGotProcess(content::SiteInstance* site_instance) override; 66 void SiteInstanceDeleting(content::SiteInstance* site_instance) override; 67 void BindHostReceiverForRenderer( 68 content::RenderProcessHost* render_process_host, 69 mojo::GenericPendingReceiver receiver) override; 70 void AppendExtraCommandLineSwitches(base::CommandLine* command_line, 71 int child_process_id) override; 72 std::string GetApplicationLocale() override; 73 scoped_refptr<network::SharedURLLoaderFactory> 74 GetSystemSharedURLLoaderFactory() override; 75 network::mojom::NetworkContext* GetSystemNetworkContext() override; 76 scoped_refptr<content::QuotaPermissionContext> CreateQuotaPermissionContext() 77 override; 78 content::MediaObserver* GetMediaObserver() override; 79 content::SpeechRecognitionManagerDelegate* 80 CreateSpeechRecognitionManagerDelegate() override; 81 content::GeneratedCodeCacheSettings GetGeneratedCodeCacheSettings( 82 content::BrowserContext* context) override; 83 void AllowCertificateError( 84 content::WebContents* web_contents, 85 int cert_error, 86 const net::SSLInfo& ssl_info, 87 const GURL& request_url, 88 bool is_main_frame_request, 89 bool strict_enforcement, 90 base::OnceCallback<void(content::CertificateRequestResultType)> callback) 91 override; 92 base::OnceClosure SelectClientCertificate( 93 content::WebContents* web_contents, 94 net::SSLCertRequestInfo* cert_request_info, 95 net::ClientCertIdentityList client_certs, 96 std::unique_ptr<content::ClientCertificateDelegate> delegate) override; 97 bool CanCreateWindow(content::RenderFrameHost* opener, 98 const GURL& opener_url, 99 const GURL& opener_top_level_frame_url, 100 const url::Origin& source_origin, 101 content::mojom::WindowContainerType container_type, 102 const GURL& target_url, 103 const content::Referrer& referrer, 104 const std::string& frame_name, 105 WindowOpenDisposition disposition, 106 const blink::mojom::WindowFeatures& features, 107 bool user_gesture, 108 bool opener_suppressed, 109 bool* no_javascript_access) override; 110 void OverrideWebkitPrefs(content::WebContents* web_contents, 111 blink::web_pref::WebPreferences* prefs) override; 112 bool OverrideWebPreferencesAfterNavigation( 113 content::WebContents* web_contents, 114 blink::web_pref::WebPreferences* prefs) override; 115 void BrowserURLHandlerCreated(content::BrowserURLHandler* handler) override; 116 std::string GetDefaultDownloadName() override; 117 void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override; 118 std::unique_ptr<content::DevToolsManagerDelegate> 119 CreateDevToolsManagerDelegate() override; 120 void RegisterAssociatedInterfaceBindersForRenderFrameHost( 121 content::RenderFrameHost& render_frame_host, 122 blink::AssociatedInterfaceRegistry& associated_registry) override; 123 std::vector<std::unique_ptr<content::NavigationThrottle>> 124 CreateThrottlesForNavigation( 125 content::NavigationHandle* navigation_handle) override; 126 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> 127 CreateURLLoaderThrottles( 128 const network::ResourceRequest& request, 129 content::BrowserContext* browser_context, 130 const base::RepeatingCallback<content::WebContents*()>& wc_getter, 131 content::NavigationUIData* navigation_ui_data, 132 int frame_tree_node_id) override; 133 std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> 134 WillCreateURLLoaderRequestInterceptors( 135 content::NavigationUIData* navigation_ui_data, 136 int frame_tree_node_id, 137 const scoped_refptr<network::SharedURLLoaderFactory>& 138 network_loader_factory) override; 139 140 #if BUILDFLAG(IS_LINUX) 141 void GetAdditionalMappedFilesForChildProcess( 142 const base::CommandLine& command_line, 143 int child_process_id, 144 content::PosixFileDescriptorInfo* mappings) override; 145 #endif 146 147 void ExposeInterfacesToRenderer( 148 service_manager::BinderRegistry* registry, 149 blink::AssociatedInterfaceRegistry* associated_registry, 150 content::RenderProcessHost* render_process_host) override; 151 std::unique_ptr<net::ClientCertStore> CreateClientCertStore( 152 content::BrowserContext* browser_context) override; 153 std::unique_ptr<content::LoginDelegate> CreateLoginDelegate( 154 const net::AuthChallengeInfo& auth_info, 155 content::WebContents* web_contents, 156 const content::GlobalRequestID& request_id, 157 bool is_request_for_main_frame, 158 const GURL& url, 159 scoped_refptr<net::HttpResponseHeaders> response_headers, 160 bool first_auth_attempt, 161 LoginAuthRequiredCallback auth_required_callback) override; 162 void RegisterNonNetworkNavigationURLLoaderFactories( 163 int frame_tree_node_id, 164 ukm::SourceIdObj ukm_source_id, 165 NonNetworkURLLoaderFactoryMap* factories) override; 166 void RegisterNonNetworkSubresourceURLLoaderFactories( 167 int render_process_id, 168 int render_frame_id, 169 const absl::optional<url::Origin>& request_initiator_origin, 170 NonNetworkURLLoaderFactoryMap* factories) override; 171 bool WillCreateURLLoaderFactory( 172 content::BrowserContext* browser_context, 173 content::RenderFrameHost* frame, 174 int render_process_id, 175 URLLoaderFactoryType type, 176 const url::Origin& request_initiator, 177 absl::optional<int64_t> navigation_id, 178 ukm::SourceIdObj ukm_source_id, 179 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, 180 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* 181 header_client, 182 bool* bypass_redirect_checks, 183 bool* disable_secure_dns, 184 network::mojom::URLLoaderFactoryOverridePtr* factory_override) override; 185 void OnNetworkServiceCreated( 186 network::mojom::NetworkService* network_service) override; 187 bool ConfigureNetworkContextParams( 188 content::BrowserContext* context, 189 bool in_memory, 190 const base::FilePath& relative_partition_path, 191 network::mojom::NetworkContextParams* network_context_params, 192 cert_verifier::mojom::CertVerifierCreationParams* 193 cert_verifier_creation_params) override; 194 std::vector<base::FilePath> GetNetworkContextsParentDirectory() override; 195 bool HandleExternalProtocol( 196 const GURL& url, 197 content::WebContents::Getter web_contents_getter, 198 int child_id, 199 int frame_tree_node_id, 200 content::NavigationUIData* navigation_data, 201 bool is_main_frame, 202 network::mojom::WebSandboxFlags sandbox_flags, 203 ui::PageTransition page_transition, 204 bool has_user_gesture, 205 const absl::optional<url::Origin>& initiating_origin, 206 content::RenderFrameHost* initiator_document, 207 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) 208 override; 209 bool HandleExternalProtocol( 210 content::WebContents::Getter web_contents_getter, 211 int frame_tree_node_id, 212 content::NavigationUIData* navigation_data, 213 network::mojom::WebSandboxFlags sandbox_flags, 214 const network::ResourceRequest& request, 215 const absl::optional<url::Origin>& initiating_origin, 216 content::RenderFrameHost* initiator_document, 217 mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) 218 override; 219 std::unique_ptr<content::OverlayWindow> CreateWindowForPictureInPicture( 220 content::PictureInPictureWindowController* controller) override; 221 void RegisterBrowserInterfaceBindersForFrame( 222 content::RenderFrameHost* render_frame_host, 223 mojo::BinderMapWithContext<content::RenderFrameHost*>* map) override; 224 base::FilePath GetSandboxedStorageServiceDataDirectory() override; 225 std::string GetProduct() override; 226 std::string GetChromeProduct() override; 227 std::string GetUserAgent() override; 228 std::string GetReducedUserAgent() override; 229 blink::UserAgentMetadata GetUserAgentMetadata() override; 230 base::flat_set<std::string> GetPluginMimeTypesWithExternalHandlers( 231 content::BrowserContext* browser_context) override; 232 bool ArePersistentMediaDeviceIDsAllowed( 233 content::BrowserContext* browser_context, 234 const GURL& scope, 235 const net::SiteForCookies& site_for_cookies, 236 const absl::optional<url::Origin>& top_frame_origin) override; 237 bool ShouldAllowPluginCreation( 238 const url::Origin& embedder_origin, 239 const content::PepperPluginInfo& plugin_info) override; 240 void OnWebContentsCreated(content::WebContents* web_contents) override; 241 bool IsFindInPageDisabledForOrigin(const url::Origin& origin) override; 242 243 CefRefPtr<CefRequestContextImpl> request_context() const; 244 CefDevToolsDelegate* devtools_delegate() const; 245 246 scoped_refptr<base::SingleThreadTaskRunner> background_task_runner() const; 247 scoped_refptr<base::SingleThreadTaskRunner> user_visible_task_runner() const; 248 scoped_refptr<base::SingleThreadTaskRunner> user_blocking_task_runner() const; 249 250 private: 251 // Returns the extension or app associated with |site_instance| or NULL. 252 const extensions::Extension* GetExtension( 253 content::SiteInstance* site_instance); 254 255 AlloyBrowserMainParts* browser_main_parts_ = nullptr; 256 }; 257 258 #endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_CONTENT_BROWSER_CLIENT_H_ 259