1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_ 6 #define CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_ 7 8 #include <set> 9 #include <string> 10 #include <utility> 11 #include <vector> 12 13 #include "base/compiler_specific.h" 14 #include "base/gtest_prod_util.h" 15 #include "chrome/common/chrome_version_info.h" 16 #include "content/public/browser/content_browser_client.h" 17 18 #if defined(OS_ANDROID) 19 #include "base/memory/scoped_ptr.h" 20 #endif 21 22 namespace base { 23 class CommandLine; 24 } 25 26 namespace content { 27 class QuotaPermissionContext; 28 } 29 30 namespace extensions { 31 class BrowserPermissionsPolicyDelegate; 32 } 33 34 namespace prerender { 35 class PrerenderTracker; 36 } 37 38 namespace user_prefs { 39 class PrefRegistrySyncable; 40 } 41 42 namespace chrome { 43 44 class ChromeContentBrowserClient : public content::ContentBrowserClient { 45 public: 46 ChromeContentBrowserClient(); 47 virtual ~ChromeContentBrowserClient(); 48 49 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 50 51 // Notification that the application locale has changed. This allows us to 52 // update our I/O thread cache of this value. 53 static void SetApplicationLocale(const std::string& locale); 54 55 virtual content::BrowserMainParts* CreateBrowserMainParts( 56 const content::MainFunctionParams& parameters) OVERRIDE; 57 virtual std::string GetStoragePartitionIdForSite( 58 content::BrowserContext* browser_context, 59 const GURL& site) OVERRIDE; 60 virtual bool IsValidStoragePartitionId( 61 content::BrowserContext* browser_context, 62 const std::string& partition_id) OVERRIDE; 63 virtual void GetStoragePartitionConfigForSite( 64 content::BrowserContext* browser_context, 65 const GURL& site, 66 bool can_be_default, 67 std::string* partition_domain, 68 std::string* partition_name, 69 bool* in_memory) OVERRIDE; 70 virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( 71 content::WebContents* web_contents) OVERRIDE; 72 virtual void GuestWebContentsCreated( 73 int guest_instance_id, 74 content::SiteInstance* guest_site_instance, 75 content::WebContents* guest_web_contents, 76 content::WebContents* opener_web_contents, 77 content::BrowserPluginGuestDelegate** guest_delegate, 78 scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE; 79 virtual void RenderProcessWillLaunch( 80 content::RenderProcessHost* host) OVERRIDE; 81 virtual bool ShouldUseProcessPerSite(content::BrowserContext* browser_context, 82 const GURL& effective_url) OVERRIDE; 83 virtual GURL GetEffectiveURL(content::BrowserContext* browser_context, 84 const GURL& url) OVERRIDE; 85 virtual void GetAdditionalWebUISchemes( 86 std::vector<std::string>* additional_schemes) OVERRIDE; 87 virtual void GetAdditionalWebUIHostsToIgnoreParititionCheck( 88 std::vector<std::string>* hosts) OVERRIDE; 89 virtual net::URLRequestContextGetter* CreateRequestContext( 90 content::BrowserContext* browser_context, 91 content::ProtocolHandlerMap* protocol_handlers, 92 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; 93 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( 94 content::BrowserContext* browser_context, 95 const base::FilePath& partition_path, 96 bool in_memory, 97 content::ProtocolHandlerMap* protocol_handlers, 98 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; 99 virtual bool IsHandledURL(const GURL& url) OVERRIDE; 100 virtual bool CanCommitURL(content::RenderProcessHost* process_host, 101 const GURL& url) OVERRIDE; 102 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance, 103 const GURL& url) OVERRIDE; 104 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, 105 const GURL& site_url) OVERRIDE; 106 virtual bool MayReuseHost(content::RenderProcessHost* process_host) OVERRIDE; 107 virtual bool ShouldTryToUseExistingProcessHost( 108 content::BrowserContext* browser_context, const GURL& url) OVERRIDE; 109 virtual void SiteInstanceGotProcess( 110 content::SiteInstance* site_instance) OVERRIDE; 111 virtual void SiteInstanceDeleting(content::SiteInstance* site_instance) 112 OVERRIDE; 113 virtual void WorkerProcessCreated(content::SiteInstance* site_instance, 114 int worker_process_id) OVERRIDE; 115 virtual void WorkerProcessTerminated(content::SiteInstance* site_instance, 116 int worker_process_id) OVERRIDE; 117 virtual bool ShouldSwapBrowsingInstancesForNavigation( 118 content::SiteInstance* site_instance, 119 const GURL& current_url, 120 const GURL& new_url) OVERRIDE; 121 virtual bool ShouldSwapProcessesForRedirect( 122 content::ResourceContext* resource_context, 123 const GURL& current_url, 124 const GURL& new_url) OVERRIDE; 125 virtual bool ShouldAssignSiteForURL(const GURL& url) OVERRIDE; 126 virtual std::string GetCanonicalEncodingNameByAliasName( 127 const std::string& alias_name) OVERRIDE; 128 virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line, 129 int child_process_id) OVERRIDE; 130 virtual std::string GetApplicationLocale() OVERRIDE; 131 virtual std::string GetAcceptLangs( 132 content::BrowserContext* context) OVERRIDE; 133 virtual const gfx::ImageSkia* GetDefaultFavicon() OVERRIDE; 134 virtual bool AllowAppCache(const GURL& manifest_url, 135 const GURL& first_party, 136 content::ResourceContext* context) OVERRIDE; 137 virtual bool AllowGetCookie(const GURL& url, 138 const GURL& first_party, 139 const net::CookieList& cookie_list, 140 content::ResourceContext* context, 141 int render_process_id, 142 int render_frame_id) OVERRIDE; 143 virtual bool AllowSetCookie(const GURL& url, 144 const GURL& first_party, 145 const std::string& cookie_line, 146 content::ResourceContext* context, 147 int render_process_id, 148 int render_frame_id, 149 net::CookieOptions* options) OVERRIDE; 150 virtual bool AllowSaveLocalState(content::ResourceContext* context) OVERRIDE; 151 virtual bool AllowWorkerDatabase( 152 const GURL& url, 153 const base::string16& name, 154 const base::string16& display_name, 155 unsigned long estimated_size, 156 content::ResourceContext* context, 157 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE; 158 virtual bool AllowWorkerFileSystem( 159 const GURL& url, 160 content::ResourceContext* context, 161 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE; 162 virtual bool AllowWorkerIndexedDB( 163 const GURL& url, 164 const base::string16& name, 165 content::ResourceContext* context, 166 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE; 167 virtual net::URLRequestContext* OverrideRequestContextForURL( 168 const GURL& url, content::ResourceContext* context) OVERRIDE; 169 virtual content::QuotaPermissionContext* 170 CreateQuotaPermissionContext() OVERRIDE; 171 virtual void AllowCertificateError( 172 int render_process_id, 173 int render_frame_id, 174 int cert_error, 175 const net::SSLInfo& ssl_info, 176 const GURL& request_url, 177 ResourceType::Type resource_type, 178 bool overridable, 179 bool strict_enforcement, 180 const base::Callback<void(bool)>& callback, 181 content::CertificateRequestResultType* request) OVERRIDE; 182 virtual void SelectClientCertificate( 183 int render_process_id, 184 int render_frame_id, 185 const net::HttpNetworkSession* network_session, 186 net::SSLCertRequestInfo* cert_request_info, 187 const base::Callback<void(net::X509Certificate*)>& callback) OVERRIDE; 188 virtual void AddCertificate(net::CertificateMimeType cert_type, 189 const void* cert_data, 190 size_t cert_size, 191 int render_process_id, 192 int render_frame_id) OVERRIDE; 193 virtual content::MediaObserver* GetMediaObserver() OVERRIDE; 194 virtual void RequestDesktopNotificationPermission( 195 const GURL& source_origin, 196 content::RenderFrameHost* render_frame_host, 197 const base::Closure& callback) OVERRIDE; 198 virtual blink::WebNotificationPresenter::Permission 199 CheckDesktopNotificationPermission( 200 const GURL& source_origin, 201 content::ResourceContext* context, 202 int render_process_id) OVERRIDE; 203 virtual void ShowDesktopNotification( 204 const content::ShowDesktopNotificationHostMsgParams& params, 205 content::RenderFrameHost* render_frame_host, 206 content::DesktopNotificationDelegate* delegate, 207 base::Closure* cancel_callback) OVERRIDE; 208 virtual void RequestGeolocationPermission( 209 content::WebContents* web_contents, 210 int bridge_id, 211 const GURL& requesting_frame, 212 bool user_gesture, 213 base::Callback<void(bool)> result_callback, 214 base::Closure* cancel_callback) OVERRIDE; 215 virtual void RequestMidiSysExPermission( 216 content::WebContents* web_contents, 217 int bridge_id, 218 const GURL& requesting_frame, 219 bool user_gesture, 220 base::Callback<void(bool)> result_callback, 221 base::Closure* cancel_callback) OVERRIDE; 222 virtual void RequestProtectedMediaIdentifierPermission( 223 content::WebContents* web_contents, 224 const GURL& origin, 225 base::Callback<void(bool)> result_callback, 226 base::Closure* cancel_callback) OVERRIDE; 227 virtual bool CanCreateWindow(const GURL& opener_url, 228 const GURL& opener_top_level_frame_url, 229 const GURL& source_origin, 230 WindowContainerType container_type, 231 const GURL& target_url, 232 const content::Referrer& referrer, 233 WindowOpenDisposition disposition, 234 const blink::WebWindowFeatures& features, 235 bool user_gesture, 236 bool opener_suppressed, 237 content::ResourceContext* context, 238 int render_process_id, 239 int opener_id, 240 bool* no_javascript_access) OVERRIDE; 241 virtual std::string GetWorkerProcessTitle( 242 const GURL& url, content::ResourceContext* context) OVERRIDE; 243 virtual void ResourceDispatcherHostCreated() OVERRIDE; 244 virtual content::SpeechRecognitionManagerDelegate* 245 GetSpeechRecognitionManagerDelegate() OVERRIDE; 246 virtual net::NetLog* GetNetLog() OVERRIDE; 247 virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE; 248 virtual bool IsFastShutdownPossible() OVERRIDE; 249 virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh, 250 const GURL& url, 251 WebPreferences* prefs) OVERRIDE; 252 virtual void UpdateInspectorSetting(content::RenderViewHost* rvh, 253 const std::string& key, 254 const std::string& value) OVERRIDE; 255 virtual void BrowserURLHandlerCreated( 256 content::BrowserURLHandler* handler) OVERRIDE; 257 virtual void ClearCache(content::RenderViewHost* rvh) OVERRIDE; 258 virtual void ClearCookies(content::RenderViewHost* rvh) OVERRIDE; 259 virtual base::FilePath GetDefaultDownloadDirectory() OVERRIDE; 260 virtual std::string GetDefaultDownloadName() OVERRIDE; 261 virtual void DidCreatePpapiPlugin( 262 content::BrowserPpapiHost* browser_host) OVERRIDE; 263 virtual content::BrowserPpapiHost* GetExternalBrowserPpapiHost( 264 int plugin_process_id) OVERRIDE; 265 virtual bool AllowPepperSocketAPI( 266 content::BrowserContext* browser_context, 267 const GURL& url, 268 bool private_api, 269 const content::SocketPermissionRequest* params) OVERRIDE; 270 virtual ui::SelectFilePolicy* CreateSelectFilePolicy( 271 content::WebContents* web_contents) OVERRIDE; 272 virtual void GetAdditionalAllowedSchemesForFileSystem( 273 std::vector<std::string>* additional_schemes) OVERRIDE; 274 virtual void GetURLRequestAutoMountHandlers( 275 std::vector<fileapi::URLRequestAutoMountHandler>* handlers) OVERRIDE; 276 virtual void GetAdditionalFileSystemBackends( 277 content::BrowserContext* browser_context, 278 const base::FilePath& storage_partition_path, 279 ScopedVector<fileapi::FileSystemBackend>* additional_backends) OVERRIDE; 280 virtual content::DevToolsManagerDelegate* 281 GetDevToolsManagerDelegate() OVERRIDE; 282 virtual bool IsPluginAllowedToCallRequestOSFileHandle( 283 content::BrowserContext* browser_context, 284 const GURL& url) OVERRIDE; 285 virtual bool IsPluginAllowedToUseDevChannelAPIs( 286 content::BrowserContext* browser_context, 287 const GURL& url) OVERRIDE; 288 virtual net::CookieStore* OverrideCookieStoreForRenderProcess( 289 int render_process_id) OVERRIDE; 290 291 #if defined(OS_POSIX) && !defined(OS_MACOSX) 292 virtual void GetAdditionalMappedFilesForChildProcess( 293 const base::CommandLine& command_line, 294 int child_process_id, 295 std::vector<content::FileDescriptorInfo>* mappings) OVERRIDE; 296 #endif 297 #if defined(OS_WIN) 298 virtual const wchar_t* GetResourceDllName() OVERRIDE; 299 virtual void PreSpawnRenderer(sandbox::TargetPolicy* policy, 300 bool* success) OVERRIDE; 301 #endif 302 303 private: 304 #if defined(ENABLE_WEBRTC) 305 // Copies disable WebRTC encryption switch depending on the channel. 306 static void MaybeCopyDisableWebRtcEncryptionSwitch( 307 base::CommandLine* to_command_line, 308 const base::CommandLine& from_command_line, 309 VersionInfo::Channel channel); 310 #endif 311 312 #if defined(ENABLE_PLUGINS) 313 // Set of origins that can use TCP/UDP private APIs from NaCl. 314 std::set<std::string> allowed_socket_origins_; 315 // Set of origins that can get a handle for FileIO from NaCl. 316 std::set<std::string> allowed_file_handle_origins_; 317 // Set of origins that can use "dev chanel" APIs from NaCl, even on stable 318 // versions of Chrome. 319 std::set<std::string> allowed_dev_channel_origins_; 320 #endif 321 scoped_ptr<extensions::BrowserPermissionsPolicyDelegate> 322 permissions_policy_delegate_; 323 324 // The prerender tracker used to determine whether a render process is used 325 // for prerendering and an override cookie store must be provided. 326 // This needs to be kept as a member rather than just looked up from 327 // the profile due to initialization ordering, as well as due to threading. 328 // It is initialized on the UI thread when the ResoureDispatcherHost is 329 // created. It is used only the IO thread. 330 prerender::PrerenderTracker* prerender_tracker_; 331 332 friend class DisableWebRtcEncryptionFlagTest; 333 334 DISALLOW_COPY_AND_ASSIGN(ChromeContentBrowserClient); 335 }; 336 337 } // namespace chrome 338 339 #endif // CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_ 340