content_browser_client.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 CONTENT_PUBLIC_BROWSER_CONTENT_BROWSER_CLIENT_H_ 6#define CONTENT_PUBLIC_BROWSER_CONTENT_BROWSER_CLIENT_H_ 7 8#include <string> 9#include <utility> 10#include <vector> 11 12#include "base/callback_forward.h" 13#include "content/public/browser/file_descriptor_info.h" 14#include "content/public/common/socket_permission_request.h" 15#include "content/public/common/content_client.h" 16#include "content/public/common/window_container_type.h" 17#include "net/cookies/canonical_cookie.h" 18#include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h" 19 20#if defined(OS_POSIX) && !defined(OS_MACOSX) 21#include "base/posix/global_descriptors.h" 22#endif 23 24 25class CommandLine; 26class FilePath; 27class GURL; 28 29namespace webkit_glue { 30struct WebPreferences; 31} 32 33namespace crypto { 34class CryptoModuleBlockingPasswordDelegate; 35} 36 37namespace gfx { 38class ImageSkia; 39} 40 41namespace net { 42class CookieOptions; 43class HttpNetworkSession; 44class NetLog; 45class SSLCertRequestInfo; 46class SSLInfo; 47class URLRequest; 48class URLRequestContext; 49class X509Certificate; 50} 51 52namespace content { 53 54class AccessTokenStore; 55class BrowserChildProcessHost; 56class BrowserContext; 57class BrowserMainParts; 58class BrowserPpapiHost; 59class BrowserURLHandler; 60class MediaObserver; 61class QuotaPermissionContext; 62class RenderProcessHost; 63class RenderViewHost; 64class RenderViewHostDelegateView; 65class ResourceContext; 66class SiteInstance; 67class SpeechInputManagerDelegate; 68class SpeechRecognitionManagerDelegate; 69class WebContents; 70class WebContentsView; 71class WebContentsViewDelegate; 72class WebUIControllerFactory; 73struct MainFunctionParams; 74struct ShowDesktopNotificationHostMsgParams; 75 76// Embedder API (or SPI) for participating in browser logic, to be implemented 77// by the client of the content browser. See ChromeContentBrowserClient for the 78// principal implementation. The methods are assumed to be called on the UI 79// thread unless otherwise specified. Use this "escape hatch" sparingly, to 80// avoid the embedder interface ballooning and becoming very specific to Chrome. 81// (Often, the call out to the client can happen in a different part of the code 82// that either already has a hook out to the embedder, or calls out to one of 83// the observer interfaces.) 84class CONTENT_EXPORT ContentBrowserClient { 85 public: 86 virtual ~ContentBrowserClient() {} 87 88 // Allows the embedder to set any number of custom BrowserMainParts 89 // implementations for the browser startup code. See comments in 90 // browser_main_parts.h. 91 virtual BrowserMainParts* CreateBrowserMainParts( 92 const MainFunctionParams& parameters); 93 94 // Allows an embedder to return their own WebContentsView implementation. 95 // Return NULL to let the default one for the platform be created. Otherwise 96 // |render_view_host_delegate_view| also needs to be provided, and it is 97 // owned by the embedder. 98 virtual WebContentsView* OverrideCreateWebContentsView( 99 WebContents* web_contents, 100 RenderViewHostDelegateView** render_view_host_delegate_view); 101 102 // If content creates the WebContentsView implementation, it will ask the 103 // embedder to return an (optional) delegate to customize it. The view will 104 // own the delegate. 105 virtual WebContentsViewDelegate* GetWebContentsViewDelegate( 106 WebContents* web_contents); 107 108 // Notifies that a new RenderHostView has been created. 109 virtual void RenderViewHostCreated(RenderViewHost* render_view_host) {} 110 111 // Notifies that a RenderProcessHost has been created. This is called before 112 // the content layer adds its own BrowserMessageFilters, so that the 113 // embedder's IPC filters have priority. 114 virtual void RenderProcessHostCreated(RenderProcessHost* host) {} 115 116 // Notifies that a BrowserChildProcessHost has been created. 117 virtual void BrowserChildProcessHostCreated(BrowserChildProcessHost* host) {} 118 119 // Gets the WebUIControllerFactory which will be responsible for generating 120 // WebUIs. Can return NULL if the embedder doesn't need WebUI support. 121 virtual WebUIControllerFactory* GetWebUIControllerFactory(); 122 123 // Get the effective URL for the given actual URL, to allow an embedder to 124 // group different url schemes in the same SiteInstance. 125 virtual GURL GetEffectiveURL(BrowserContext* browser_context, 126 const GURL& url); 127 128 // Returns whether all instances of the specified effective URL should be 129 // rendered by the same process, rather than using process-per-site-instance. 130 virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context, 131 const GURL& effective_url); 132 133 // Returns whether a specified URL is handled by the embedder's internal 134 // protocol handlers. 135 virtual bool IsHandledURL(const GURL& url); 136 137 // Returns whether a new view for a given |site_url| can be launched in a 138 // given |process_host|. 139 virtual bool IsSuitableHost(RenderProcessHost* process_host, 140 const GURL& site_url); 141 142 // Returns whether a new process should be created or an existing one should 143 // be reused based on the URL we want to load. This should return false, 144 // unless there is a good reason otherwise. 145 virtual bool ShouldTryToUseExistingProcessHost( 146 BrowserContext* browser_context, const GURL& url); 147 148 // Called when a site instance is first associated with a process. 149 virtual void SiteInstanceGotProcess(SiteInstance* site_instance) {} 150 151 // Called from a site instance's destructor. 152 virtual void SiteInstanceDeleting(SiteInstance* site_instance) {} 153 154 // Returns true if for the navigation from |current_url| to |new_url|, 155 // processes should be swapped (even if we are in a process model that 156 // doesn't usually swap). 157 virtual bool ShouldSwapProcessesForNavigation(const GURL& current_url, 158 const GURL& new_url); 159 160 // Returns true if the given navigation redirect should cause a renderer 161 // process swap. 162 // This is called on the IO thread. 163 virtual bool ShouldSwapProcessesForRedirect(ResourceContext* resource_context, 164 const GURL& current_url, 165 const GURL& new_url); 166 167 // See CharacterEncoding's comment. 168 virtual std::string GetCanonicalEncodingNameByAliasName( 169 const std::string& alias_name); 170 171 // Allows the embedder to pass extra command line flags. 172 // switches::kProcessType will already be set at this point. 173 virtual void AppendExtraCommandLineSwitches(CommandLine* command_line, 174 int child_process_id) {} 175 176 // Returns the locale used by the application. 177 // This is called on the UI and IO threads. 178 virtual std::string GetApplicationLocale(); 179 180 // Returns the languages used in the Accept-Languages HTTP header. 181 // (Not called GetAcceptLanguages so it doesn't clash with win32). 182 virtual std::string GetAcceptLangs(BrowserContext* context); 183 184 // Returns the default favicon. The callee doesn't own the given bitmap. 185 virtual gfx::ImageSkia* GetDefaultFavicon(); 186 187 // Allow the embedder to control if an AppCache can be used for the given url. 188 // This is called on the IO thread. 189 virtual bool AllowAppCache(const GURL& manifest_url, 190 const GURL& first_party, 191 ResourceContext* context); 192 193 // Allow the embedder to control if the given cookie can be read. 194 // This is called on the IO thread. 195 virtual bool AllowGetCookie(const GURL& url, 196 const GURL& first_party, 197 const net::CookieList& cookie_list, 198 ResourceContext* context, 199 int render_process_id, 200 int render_view_id); 201 202 // Allow the embedder to control if the given cookie can be set. 203 // This is called on the IO thread. 204 virtual bool AllowSetCookie(const GURL& url, 205 const GURL& first_party, 206 const std::string& cookie_line, 207 ResourceContext* context, 208 int render_process_id, 209 int render_view_id, 210 net::CookieOptions* options); 211 212 // Returns whether plug-ins should access locally stored data or whether all 213 // access should be blocked. The default is to allow local data access. 214 // This is called on the IO thread. 215 virtual bool AllowPluginLocalDataAccess( 216 const GURL& document_url, 217 const GURL& plugin_url, 218 content::ResourceContext* context); 219 220 // Returns whether plug-ins should keep locally stored data for the session 221 // only. The default is to store local data permanently. 222 // This is called on the IO thread. 223 virtual bool AllowPluginLocalDataSessionOnly( 224 const GURL& url, 225 content::ResourceContext* context); 226 227 // This is called on the IO thread. 228 virtual bool AllowSaveLocalState(ResourceContext* context); 229 230 // Allow the embedder to control if access to web database by a shared worker 231 // is allowed. |render_views| is a vector of pairs of 232 // RenderProcessID/RenderViewID of RenderViews that are using this worker. 233 // This is called on the IO thread. 234 virtual bool AllowWorkerDatabase( 235 const GURL& url, 236 const string16& name, 237 const string16& display_name, 238 unsigned long estimated_size, 239 ResourceContext* context, 240 const std::vector<std::pair<int, int> >& render_views); 241 242 // Allow the embedder to control if access to file system by a shared worker 243 // is allowed. 244 // This is called on the IO thread. 245 virtual bool AllowWorkerFileSystem( 246 const GURL& url, 247 ResourceContext* context, 248 const std::vector<std::pair<int, int> >& render_views); 249 250 // Allow the embedder to control if access to IndexedDB by a shared worker 251 // is allowed. 252 // This is called on the IO thread. 253 virtual bool AllowWorkerIndexedDB( 254 const GURL& url, 255 const string16& name, 256 ResourceContext* context, 257 const std::vector<std::pair<int, int> >& render_views); 258 259 // Allow the embedder to override the request context based on the URL for 260 // certain operations, like cookie access. Returns NULL to indicate the 261 // regular request context should be used. 262 // This is called on the IO thread. 263 virtual net::URLRequestContext* OverrideRequestContextForURL( 264 const GURL& url, ResourceContext* context); 265 266 // Allow the embedder to specify a string version of the storage partition 267 // config with a site. 268 virtual std::string GetStoragePartitionIdForSite( 269 content::BrowserContext* browser_context, 270 const GURL& site); 271 272 // Allows the embedder to provide a validation check for |partition_id|s. 273 // This domain of valid entries should match the range of outputs for 274 // GetStoragePartitionIdForChildProcess(). 275 virtual bool IsValidStoragePartitionId(BrowserContext* browser_context, 276 const std::string& partition_id); 277 278 // Allows the embedder to provide a storage parititon configuration for a 279 // site. A storage partition configuration includes a domain of the embedder's 280 // choice, an optional name within that domain, and whether the partition is 281 // in-memory only. The |partition_domain| is [a-z]* UTF-8 string, specifying 282 // the domain in which partitions live (similar to namespace). Within a 283 // domain, partitions can be uniquely identified by the combination of 284 // |partition_name| and |in_memory| values. When a partition is not to be 285 // persisted, the |in_memory| value must be set to true. 286 virtual void GetStoragePartitionConfigForSite( 287 content::BrowserContext* browser_context, 288 const GURL& site, 289 std::string* partition_domain, 290 std::string* partition_name, 291 bool* in_memory); 292 293 // Create and return a new quota permission context. 294 virtual QuotaPermissionContext* CreateQuotaPermissionContext(); 295 296 // Open the given file in the desktop's default manner. 297 virtual void OpenItem(const FilePath& path) {} 298 299 // Show the given file in a file manager. If possible, select the file. 300 virtual void ShowItemInFolder(const FilePath& path) {} 301 302 // Informs the embedder that a certificate error has occured. If 303 // |overridable| is true and if |strict_enforcement| is false, the user 304 // can ignore the error and continue. The embedder can call the callback 305 // asynchronously. If |cancel_request| is set to true, the request will be 306 // cancelled immediately and the callback won't be run. 307 virtual void AllowCertificateError( 308 int render_process_id, 309 int render_view_id, 310 int cert_error, 311 const net::SSLInfo& ssl_info, 312 const GURL& request_url, 313 bool overridable, 314 bool strict_enforcement, 315 const base::Callback<void(bool)>& callback, 316 bool* cancel_request) {} 317 318 // Selects a SSL client certificate and returns it to the |callback|. If no 319 // certificate was selected NULL is returned to the |callback|. 320 virtual void SelectClientCertificate( 321 int render_process_id, 322 int render_view_id, 323 const net::HttpNetworkSession* network_session, 324 net::SSLCertRequestInfo* cert_request_info, 325 const base::Callback<void(net::X509Certificate*)>& callback) {} 326 327 // Adds a downloaded client cert. The embedder should ensure that there's 328 // a private key for the cert, displays the cert to the user, and adds it upon 329 // user approval. If the downloaded data could not be interpreted as a valid 330 // certificate, |cert| will be NULL. 331 virtual void AddNewCertificate( 332 net::URLRequest* request, 333 net::X509Certificate* cert, 334 int render_process_id, 335 int render_view_id) {} 336 337 // Returns a a class to get notifications about media event. The embedder can 338 // return NULL if they're not interested. 339 virtual MediaObserver* GetMediaObserver(); 340 341 // Asks permission to show desktop notifications. 342 virtual void RequestDesktopNotificationPermission( 343 const GURL& source_origin, 344 int callback_context, 345 int render_process_id, 346 int render_view_id) {} 347 348 // Checks if the given page has permission to show desktop notifications. 349 // This is called on the IO thread. 350 virtual WebKit::WebNotificationPresenter::Permission 351 CheckDesktopNotificationPermission( 352 const GURL& source_url, 353 ResourceContext* context, 354 int render_process_id); 355 356 // Show a desktop notification. If |worker| is true, the request came from an 357 // HTML5 web worker, otherwise, it came from a renderer. 358 virtual void ShowDesktopNotification( 359 const ShowDesktopNotificationHostMsgParams& params, 360 int render_process_id, 361 int render_view_id, 362 bool worker) {} 363 364 // Cancels a displayed desktop notification. 365 virtual void CancelDesktopNotification( 366 int render_process_id, 367 int render_view_id, 368 int notification_id) {} 369 370 // Returns true if the given page is allowed to open a window of the given 371 // type. If true is returned, |no_javascript_access| will indicate whether 372 // the window that is created should be scriptable/in the same process. 373 // This is called on the IO thread. 374 virtual bool CanCreateWindow( 375 const GURL& opener_url, 376 const GURL& source_origin, 377 WindowContainerType container_type, 378 ResourceContext* context, 379 int render_process_id, 380 bool* no_javascript_access); 381 382 // Returns a title string to use in the task manager for a process host with 383 // the given URL, or the empty string to fall back to the default logic. 384 // This is called on the IO thread. 385 virtual std::string GetWorkerProcessTitle(const GURL& url, 386 ResourceContext* context); 387 388 // Notifies the embedder that the ResourceDispatcherHost has been created. 389 // This is when it can optionally add a delegate. 390 virtual void ResourceDispatcherHostCreated() {} 391 392 // Allows the embedder to return a delegate for the SpeechRecognitionManager. 393 // The delegate will be owned by the manager. It's valid to return NULL. 394 virtual SpeechRecognitionManagerDelegate* 395 GetSpeechRecognitionManagerDelegate(); 396 397 // Getters for common objects. 398 virtual net::NetLog* GetNetLog(); 399 400 // Creates a new AccessTokenStore for gelocation. 401 virtual AccessTokenStore* CreateAccessTokenStore(); 402 403 // Returns true if fast shutdown is possible. 404 virtual bool IsFastShutdownPossible(); 405 406 // Called by WebContents to override the WebKit preferences that are used by 407 // the renderer. The content layer will add its own settings, and then it's up 408 // to the embedder to update it if it wants. 409 virtual void OverrideWebkitPrefs(RenderViewHost* render_view_host, 410 const GURL& url, 411 webkit_glue::WebPreferences* prefs) {} 412 413 // Inspector setting was changed and should be persisted. 414 virtual void UpdateInspectorSetting(RenderViewHost* rvh, 415 const std::string& key, 416 const std::string& value) {} 417 418 // Clear the Inspector settings. 419 virtual void ClearInspectorSettings(RenderViewHost* rvh) {} 420 421 // Notifies that BrowserURLHandler has been created, so that the embedder can 422 // optionally add their own handlers. 423 virtual void BrowserURLHandlerCreated(BrowserURLHandler* handler) {} 424 425 // Clears browser cache. 426 virtual void ClearCache(RenderViewHost* rvh) {} 427 428 // Clears browser cookies. 429 virtual void ClearCookies(RenderViewHost* rvh) {} 430 431 // Returns the default download directory. 432 // This can be called on any thread. 433 virtual FilePath GetDefaultDownloadDirectory(); 434 435 // Returns the default filename used in downloads when we have no idea what 436 // else we should do with the file. 437 virtual std::string GetDefaultDownloadName(); 438 439 // Notification that a pepper plugin has just been spawned. This allows the 440 // embedder to add filters onto the host to implement interfaces. 441 // This is called on the IO thread. 442 virtual void DidCreatePpapiPlugin(BrowserPpapiHost* browser_host) {} 443 444 // Gets the host for an external out-of-process plugin. 445 virtual content::BrowserPpapiHost* GetExternalBrowserPpapiHost( 446 int plugin_child_id); 447 448 // Returns true if renderer processes can use Pepper TCP/UDP sockets from 449 // the given origin and connection type. 450 virtual bool AllowPepperSocketAPI(BrowserContext* browser_context, 451 const GURL& url, 452 const SocketPermissionRequest& params); 453 454 // Returns true if renderer processes can use private Pepper File APIs. 455 virtual bool AllowPepperPrivateFileAPI(); 456 457 // Returns the directory containing hyphenation dictionaries. 458 virtual FilePath GetHyphenDictionaryDirectory(); 459 460#if defined(OS_POSIX) && !defined(OS_MACOSX) 461 // Populates |mappings| with all files that need to be mapped before launching 462 // a child process. 463 virtual void GetAdditionalMappedFilesForChildProcess( 464 const CommandLine& command_line, 465 int child_process_id, 466 std::vector<FileDescriptorInfo>* mappings) {} 467#endif 468 469#if defined(OS_WIN) 470 // Returns the name of the dll that contains cursors and other resources. 471 virtual const wchar_t* GetResourceDllName(); 472#endif 473 474#if defined(USE_NSS) 475 // Return a delegate to authenticate and unlock |module|. 476 // This is called on a worker thread. 477 virtual 478 crypto::CryptoModuleBlockingPasswordDelegate* GetCryptoPasswordDelegate( 479 const GURL& url); 480#endif 481}; 482 483} // namespace content 484 485#endif // CONTENT_PUBLIC_BROWSER_CONTENT_BROWSER_CLIENT_H_ 486