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 "content/public/browser/content_browser_client.h" 15 16 #if defined(OS_ANDROID) 17 #include "base/memory/scoped_ptr.h" 18 #endif 19 20 namespace content { 21 class QuotaPermissionContext; 22 } 23 24 namespace extensions { 25 class BrowserPermissionsPolicyDelegate; 26 } 27 28 namespace user_prefs { 29 class PrefRegistrySyncable; 30 } 31 32 namespace chrome { 33 34 class ChromeContentBrowserClient : public content::ContentBrowserClient { 35 public: 36 ChromeContentBrowserClient(); 37 virtual ~ChromeContentBrowserClient(); 38 39 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 40 41 // Notification that the application locale has changed. This allows us to 42 // update our I/O thread cache of this value. 43 static void SetApplicationLocale(const std::string& locale); 44 45 virtual content::BrowserMainParts* CreateBrowserMainParts( 46 const content::MainFunctionParams& parameters) OVERRIDE; 47 virtual std::string GetStoragePartitionIdForSite( 48 content::BrowserContext* browser_context, 49 const GURL& site) OVERRIDE; 50 virtual bool IsValidStoragePartitionId( 51 content::BrowserContext* browser_context, 52 const std::string& partition_id) OVERRIDE; 53 virtual void GetStoragePartitionConfigForSite( 54 content::BrowserContext* browser_context, 55 const GURL& site, 56 bool can_be_default, 57 std::string* partition_domain, 58 std::string* partition_name, 59 bool* in_memory) OVERRIDE; 60 virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( 61 content::WebContents* web_contents) OVERRIDE; 62 virtual void GuestWebContentsCreated( 63 content::WebContents* guest_web_contents, 64 content::WebContents* opener_web_contents, 65 content::BrowserPluginGuestDelegate** guest_delegate, 66 scoped_ptr<base::DictionaryValue> extra_params) OVERRIDE; 67 virtual void GuestWebContentsAttached( 68 content::WebContents* guest_web_contents, 69 content::WebContents* embedder_web_contents, 70 const base::DictionaryValue& extra_params) OVERRIDE; 71 virtual void RenderProcessHostCreated( 72 content::RenderProcessHost* host) OVERRIDE; 73 virtual bool ShouldUseProcessPerSite(content::BrowserContext* browser_context, 74 const GURL& effective_url) OVERRIDE; 75 virtual GURL GetEffectiveURL(content::BrowserContext* browser_context, 76 const GURL& url) OVERRIDE; 77 virtual void GetAdditionalWebUISchemes( 78 std::vector<std::string>* additional_schemes) OVERRIDE; 79 virtual net::URLRequestContextGetter* CreateRequestContext( 80 content::BrowserContext* browser_context, 81 content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; 82 virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( 83 content::BrowserContext* browser_context, 84 const base::FilePath& partition_path, 85 bool in_memory, 86 content::ProtocolHandlerMap* protocol_handlers) OVERRIDE; 87 virtual bool IsHandledURL(const GURL& url) OVERRIDE; 88 virtual bool CanCommitURL(content::RenderProcessHost* process_host, 89 const GURL& url) OVERRIDE; 90 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, 91 const GURL& site_url) OVERRIDE; 92 virtual bool ShouldTryToUseExistingProcessHost( 93 content::BrowserContext* browser_context, const GURL& url) OVERRIDE; 94 virtual void SiteInstanceGotProcess( 95 content::SiteInstance* site_instance) OVERRIDE; 96 virtual void SiteInstanceDeleting(content::SiteInstance* site_instance) 97 OVERRIDE; 98 virtual bool ShouldSwapProcessesForNavigation( 99 content::SiteInstance* site_instance, 100 const GURL& current_url, 101 const GURL& new_url) OVERRIDE; 102 virtual bool ShouldSwapProcessesForRedirect( 103 content::ResourceContext* resource_context, 104 const GURL& current_url, 105 const GURL& new_url) OVERRIDE; 106 virtual bool ShouldAssignSiteForURL(const GURL& url) OVERRIDE; 107 virtual std::string GetCanonicalEncodingNameByAliasName( 108 const std::string& alias_name) OVERRIDE; 109 virtual void AppendExtraCommandLineSwitches(CommandLine* command_line, 110 int child_process_id) OVERRIDE; 111 virtual std::string GetApplicationLocale() OVERRIDE; 112 virtual std::string GetAcceptLangs( 113 content::BrowserContext* context) OVERRIDE; 114 virtual gfx::ImageSkia* GetDefaultFavicon() OVERRIDE; 115 virtual bool AllowAppCache(const GURL& manifest_url, 116 const GURL& first_party, 117 content::ResourceContext* context) OVERRIDE; 118 virtual bool AllowGetCookie(const GURL& url, 119 const GURL& first_party, 120 const net::CookieList& cookie_list, 121 content::ResourceContext* context, 122 int render_process_id, 123 int render_view_id) OVERRIDE; 124 virtual bool AllowSetCookie(const GURL& url, 125 const GURL& first_party, 126 const std::string& cookie_line, 127 content::ResourceContext* context, 128 int render_process_id, 129 int render_view_id, 130 net::CookieOptions* options) OVERRIDE; 131 virtual bool AllowSaveLocalState(content::ResourceContext* context) OVERRIDE; 132 virtual bool AllowWorkerDatabase( 133 const GURL& url, 134 const string16& name, 135 const string16& display_name, 136 unsigned long estimated_size, 137 content::ResourceContext* context, 138 const std::vector<std::pair<int, int> >& render_views) OVERRIDE; 139 virtual bool AllowWorkerFileSystem( 140 const GURL& url, 141 content::ResourceContext* context, 142 const std::vector<std::pair<int, int> >& render_views) OVERRIDE; 143 virtual bool AllowWorkerIndexedDB( 144 const GURL& url, 145 const string16& name, 146 content::ResourceContext* context, 147 const std::vector<std::pair<int, int> >& render_views) OVERRIDE; 148 virtual net::URLRequestContext* OverrideRequestContextForURL( 149 const GURL& url, content::ResourceContext* context) OVERRIDE; 150 virtual content::QuotaPermissionContext* 151 CreateQuotaPermissionContext() OVERRIDE; 152 virtual void AllowCertificateError( 153 int render_process_id, 154 int render_view_id, 155 int cert_error, 156 const net::SSLInfo& ssl_info, 157 const GURL& request_url, 158 ResourceType::Type resource_type, 159 bool overridable, 160 bool strict_enforcement, 161 const base::Callback<void(bool)>& callback, 162 content::CertificateRequestResultType* request) OVERRIDE; 163 virtual void SelectClientCertificate( 164 int render_process_id, 165 int render_view_id, 166 const net::HttpNetworkSession* network_session, 167 net::SSLCertRequestInfo* cert_request_info, 168 const base::Callback<void(net::X509Certificate*)>& callback) OVERRIDE; 169 virtual void AddCertificate( 170 net::URLRequest* request, 171 net::CertificateMimeType cert_type, 172 const void* cert_data, 173 size_t cert_size, 174 int render_process_id, 175 int render_view_id) OVERRIDE; 176 virtual content::MediaObserver* GetMediaObserver() OVERRIDE; 177 virtual void RequestDesktopNotificationPermission( 178 const GURL& source_origin, 179 int callback_context, 180 int render_process_id, 181 int render_view_id) OVERRIDE; 182 virtual WebKit::WebNotificationPresenter::Permission 183 CheckDesktopNotificationPermission( 184 const GURL& source_origin, 185 content::ResourceContext* context, 186 int render_process_id) OVERRIDE; 187 virtual void ShowDesktopNotification( 188 const content::ShowDesktopNotificationHostMsgParams& params, 189 int render_process_id, 190 int render_view_id, 191 bool worker) OVERRIDE; 192 virtual void CancelDesktopNotification( 193 int render_process_id, 194 int render_view_id, 195 int notification_id) OVERRIDE; 196 virtual bool CanCreateWindow(const GURL& opener_url, 197 const GURL& opener_top_level_frame_url, 198 const GURL& source_origin, 199 WindowContainerType container_type, 200 const GURL& target_url, 201 const content::Referrer& referrer, 202 WindowOpenDisposition disposition, 203 const WebKit::WebWindowFeatures& features, 204 bool user_gesture, 205 bool opener_suppressed, 206 content::ResourceContext* context, 207 int render_process_id, 208 bool is_guest, 209 int opener_id, 210 bool* no_javascript_access) OVERRIDE; 211 virtual std::string GetWorkerProcessTitle( 212 const GURL& url, content::ResourceContext* context) OVERRIDE; 213 virtual void ResourceDispatcherHostCreated() OVERRIDE; 214 virtual content::SpeechRecognitionManagerDelegate* 215 GetSpeechRecognitionManagerDelegate() OVERRIDE; 216 virtual net::NetLog* GetNetLog() OVERRIDE; 217 virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE; 218 virtual bool IsFastShutdownPossible() OVERRIDE; 219 virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh, 220 const GURL& url, 221 WebPreferences* prefs) OVERRIDE; 222 virtual void UpdateInspectorSetting(content::RenderViewHost* rvh, 223 const std::string& key, 224 const std::string& value) OVERRIDE; 225 virtual void BrowserURLHandlerCreated( 226 content::BrowserURLHandler* handler) OVERRIDE; 227 virtual void ClearCache(content::RenderViewHost* rvh) OVERRIDE; 228 virtual void ClearCookies(content::RenderViewHost* rvh) OVERRIDE; 229 virtual base::FilePath GetDefaultDownloadDirectory() OVERRIDE; 230 virtual std::string GetDefaultDownloadName() OVERRIDE; 231 virtual void DidCreatePpapiPlugin( 232 content::BrowserPpapiHost* browser_host) OVERRIDE; 233 virtual content::BrowserPpapiHost* GetExternalBrowserPpapiHost( 234 int plugin_process_id) OVERRIDE; 235 virtual bool SupportsBrowserPlugin(content::BrowserContext* browser_context, 236 const GURL& site_url) OVERRIDE; 237 virtual bool AllowPepperSocketAPI( 238 content::BrowserContext* browser_context, 239 const GURL& url, 240 bool private_api, 241 const content::SocketPermissionRequest& params) OVERRIDE; 242 virtual ui::SelectFilePolicy* CreateSelectFilePolicy( 243 content::WebContents* web_contents) OVERRIDE; 244 virtual void GetAdditionalAllowedSchemesForFileSystem( 245 std::vector<std::string>* additional_schemes) OVERRIDE; 246 virtual void GetAdditionalFileSystemBackends( 247 content::BrowserContext* browser_context, 248 const base::FilePath& storage_partition_path, 249 ScopedVector<fileapi::FileSystemBackend>* additional_backends) OVERRIDE; 250 251 #if defined(OS_POSIX) && !defined(OS_MACOSX) 252 virtual void GetAdditionalMappedFilesForChildProcess( 253 const CommandLine& command_line, 254 int child_process_id, 255 std::vector<content::FileDescriptorInfo>* mappings) OVERRIDE; 256 #endif 257 #if defined(OS_WIN) 258 virtual const wchar_t* GetResourceDllName() OVERRIDE; 259 virtual void PreSpawnRenderer(sandbox::TargetPolicy* policy, 260 bool* success) OVERRIDE; 261 #endif 262 #if defined(USE_NSS) 263 virtual 264 crypto::CryptoModuleBlockingPasswordDelegate* GetCryptoPasswordDelegate( 265 const GURL& url) OVERRIDE; 266 #endif 267 268 private: 269 #if defined(ENABLE_PLUGINS) 270 // Set of origins that can use TCP/UDP private APIs from NaCl. 271 std::set<std::string> allowed_socket_origins_; 272 #endif 273 scoped_ptr<extensions::BrowserPermissionsPolicyDelegate> 274 permissions_policy_delegate_; 275 276 DISALLOW_COPY_AND_ASSIGN(ChromeContentBrowserClient); 277 }; 278 279 } // namespace chrome 280 281 #endif // CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_ 282