1 // Copyright 2019 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 WEBLAYER_BROWSER_CONTENT_BROWSER_CLIENT_IMPL_H_ 6 #define WEBLAYER_BROWSER_CONTENT_BROWSER_CLIENT_IMPL_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/callback.h" 12 #include "base/compiler_specific.h" 13 #include "base/files/file_path.h" 14 #include "build/build_config.h" 15 #include "content/public/browser/content_browser_client.h" 16 #include "services/service_manager/public/cpp/binder_registry.h" 17 18 class PrefService; 19 20 namespace weblayer { 21 22 class FeatureListCreator; 23 class SafeBrowsingService; 24 struct MainParams; 25 26 blink::UserAgentMetadata GetUserAgentMetadata(); 27 28 class ContentBrowserClientImpl : public content::ContentBrowserClient { 29 public: 30 explicit ContentBrowserClientImpl(MainParams* params); 31 ~ContentBrowserClientImpl() override; 32 33 // ContentBrowserClient overrides. 34 std::unique_ptr<content::BrowserMainParts> CreateBrowserMainParts( 35 const content::MainFunctionParams& parameters) override; 36 std::string GetApplicationLocale() override; 37 std::string GetAcceptLangs(content::BrowserContext* context) override; 38 content::WebContentsViewDelegate* GetWebContentsViewDelegate( 39 content::WebContents* web_contents) override; 40 bool CanShutdownGpuProcessNowOnIOThread() override; 41 content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; 42 void LogWebFeatureForCurrentPage(content::RenderFrameHost* render_frame_host, 43 blink::mojom::WebFeature feature) override; 44 std::string GetProduct() override; 45 std::string GetUserAgent() override; 46 blink::UserAgentMetadata GetUserAgentMetadata() override; 47 void OverrideWebkitPrefs(content::RenderViewHost* render_view_host, 48 blink::web_pref::WebPreferences* prefs) override; 49 void ConfigureNetworkContextParams( 50 content::BrowserContext* context, 51 bool in_memory, 52 const base::FilePath& relative_partition_path, 53 network::mojom::NetworkContextParams* network_context_params, 54 network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) 55 override; 56 void OnNetworkServiceCreated( 57 network::mojom::NetworkService* network_service) override; 58 std::vector<std::unique_ptr<blink::URLLoaderThrottle>> 59 CreateURLLoaderThrottles( 60 const network::ResourceRequest& request, 61 content::BrowserContext* browser_context, 62 const base::RepeatingCallback<content::WebContents*()>& wc_getter, 63 content::NavigationUIData* navigation_ui_data, 64 int frame_tree_node_id) override; 65 bool IsHandledURL(const GURL& url) override; 66 std::vector<url::Origin> GetOriginsRequiringDedicatedProcess() override; 67 bool MayReuseHost(content::RenderProcessHost* process_host) override; 68 void OverridePageVisibilityState( 69 content::RenderFrameHost* render_frame_host, 70 content::PageVisibilityState* visibility_state) override; 71 bool ShouldDisableSiteIsolation() override; 72 std::vector<std::string> GetAdditionalSiteIsolationModes() override; 73 void PersistIsolatedOrigin(content::BrowserContext* context, 74 const url::Origin& origin) override; 75 base::OnceClosure SelectClientCertificate( 76 content::WebContents* web_contents, 77 net::SSLCertRequestInfo* cert_request_info, 78 net::ClientCertIdentityList client_certs, 79 std::unique_ptr<content::ClientCertificateDelegate> delegate) override; 80 bool CanCreateWindow(content::RenderFrameHost* opener, 81 const GURL& opener_url, 82 const GURL& opener_top_level_frame_url, 83 const url::Origin& source_origin, 84 content::mojom::WindowContainerType container_type, 85 const GURL& target_url, 86 const content::Referrer& referrer, 87 const std::string& frame_name, 88 WindowOpenDisposition disposition, 89 const blink::mojom::WindowFeatures& features, 90 bool user_gesture, 91 bool opener_suppressed, 92 bool* no_javascript_access) override; 93 content::ControllerPresentationServiceDelegate* 94 GetControllerPresentationServiceDelegate( 95 content::WebContents* web_contents) override; 96 std::vector<std::unique_ptr<content::NavigationThrottle>> 97 CreateThrottlesForNavigation(content::NavigationHandle* handle) override; 98 content::GeneratedCodeCacheSettings GetGeneratedCodeCacheSettings( 99 content::BrowserContext* context) override; 100 bool BindAssociatedReceiverFromFrame( 101 content::RenderFrameHost* render_frame_host, 102 const std::string& interface_name, 103 mojo::ScopedInterfaceEndpointHandle* handle) override; 104 void ExposeInterfacesToRenderer( 105 service_manager::BinderRegistry* registry, 106 blink::AssociatedInterfaceRegistry* associated_registry, 107 content::RenderProcessHost* render_process_host) override; 108 void BindMediaServiceReceiver(content::RenderFrameHost* render_frame_host, 109 mojo::GenericPendingReceiver receiver) override; 110 void RegisterBrowserInterfaceBindersForFrame( 111 content::RenderFrameHost* render_frame_host, 112 mojo::BinderMapWithContext<content::RenderFrameHost*>* map) override; 113 void BindHostReceiverForRenderer( 114 content::RenderProcessHost* render_process_host, 115 mojo::GenericPendingReceiver receiver) override; 116 void RenderProcessWillLaunch(content::RenderProcessHost* host) override; 117 scoped_refptr<content::QuotaPermissionContext> CreateQuotaPermissionContext() 118 override; 119 #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_BSD) 120 void GetAdditionalMappedFilesForChildProcess( 121 const base::CommandLine& command_line, 122 int child_process_id, 123 content::PosixFileDescriptorInfo* mappings) override; 124 #endif // defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_ANDROID) || defined(OS_BSD) 125 void AppendExtraCommandLineSwitches(base::CommandLine* command_line, 126 int child_process_id) override; 127 #if defined(OS_ANDROID) 128 bool WillCreateURLLoaderFactory( 129 content::BrowserContext* browser_context, 130 content::RenderFrameHost* frame, 131 int render_process_id, 132 URLLoaderFactoryType type, 133 const url::Origin& request_initiator, 134 base::Optional<int64_t> navigation_id, 135 ukm::SourceIdObj ukm_source_id, 136 mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, 137 mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* 138 header_client, 139 bool* bypass_redirect_checks, 140 bool* disable_secure_dns, 141 network::mojom::URLLoaderFactoryOverridePtr* factory_override) override; 142 WideColorGamutHeuristic GetWideColorGamutHeuristic() override; 143 std::unique_ptr<content::LoginDelegate> CreateLoginDelegate( 144 const net::AuthChallengeInfo& auth_info, 145 content::WebContents* web_contents, 146 const content::GlobalRequestID& request_id, 147 bool is_main_frame, 148 const GURL& url, 149 scoped_refptr<net::HttpResponseHeaders> response_headers, 150 bool first_auth_attempt, 151 LoginAuthRequiredCallback auth_required_callback) override; 152 std::unique_ptr<content::TtsEnvironmentAndroid> CreateTtsEnvironmentAndroid() 153 override; 154 #endif // OS_ANDROID 155 content::SpeechRecognitionManagerDelegate* 156 CreateSpeechRecognitionManagerDelegate() override; 157 ukm::UkmService* GetUkmService() override; 158 bool HasErrorPage(int http_status_code) override; 159 160 void CreateFeatureListAndFieldTrials(); 161 162 private: 163 std::unique_ptr<PrefService> CreateLocalState(); 164 165 #if defined(OS_ANDROID) 166 SafeBrowsingService* GetSafeBrowsingService(); 167 #endif 168 169 MainParams* params_; 170 171 // Local-state is created early on, before BrowserProcess. Ownership moves to 172 // BrowserMainParts, then BrowserProcess. BrowserProcess ultimately owns 173 // local-state so that it can be destroyed along with other BrowserProcess 174 // state. 175 std::unique_ptr<PrefService> local_state_; 176 177 std::unique_ptr<FeatureListCreator> feature_list_creator_; 178 }; 179 180 } // namespace weblayer 181 182 #endif // WEBLAYER_BROWSER_CONTENT_BROWSER_CLIENT_IMPL_H_ 183