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.
5 #ifndef CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_
6 #define CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_
13 #include "base/compiler_specific.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "chrome/common/chrome_version_info.h"
18 #include "content/public/browser/content_browser_client.h"
20 class ChromeContentBrowserClientParts
;
27 class QuotaPermissionContext
;
30 namespace extensions
{
31 class BrowserPermissionsPolicyDelegate
;
35 class PrerenderTracker
;
38 namespace user_prefs
{
39 class PrefRegistrySyncable
;
44 class ChromeContentBrowserClient
: public content::ContentBrowserClient
{
46 ChromeContentBrowserClient();
47 ~ChromeContentBrowserClient() override
;
49 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
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
);
55 content::BrowserMainParts
* CreateBrowserMainParts(
56 const content::MainFunctionParams
& parameters
) override
;
57 std::string
GetStoragePartitionIdForSite(
58 content::BrowserContext
* browser_context
,
59 const GURL
& site
) override
;
60 bool IsValidStoragePartitionId(content::BrowserContext
* browser_context
,
61 const std::string
& partition_id
) override
;
62 void GetStoragePartitionConfigForSite(
63 content::BrowserContext
* browser_context
,
66 std::string
* partition_domain
,
67 std::string
* partition_name
,
68 bool* in_memory
) override
;
69 content::WebContentsViewDelegate
* GetWebContentsViewDelegate(
70 content::WebContents
* web_contents
) override
;
71 void RenderProcessWillLaunch(content::RenderProcessHost
* host
) override
;
72 bool ShouldUseProcessPerSite(content::BrowserContext
* browser_context
,
73 const GURL
& effective_url
) override
;
74 GURL
GetEffectiveURL(content::BrowserContext
* browser_context
,
75 const GURL
& url
) override
;
76 void GetAdditionalWebUISchemes(
77 std::vector
<std::string
>* additional_schemes
) override
;
78 void GetAdditionalWebUIHostsToIgnoreParititionCheck(
79 std::vector
<std::string
>* hosts
) override
;
80 net::URLRequestContextGetter
* CreateRequestContext(
81 content::BrowserContext
* browser_context
,
82 content::ProtocolHandlerMap
* protocol_handlers
,
83 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
84 net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
85 content::BrowserContext
* browser_context
,
86 const base::FilePath
& partition_path
,
88 content::ProtocolHandlerMap
* protocol_handlers
,
89 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
90 bool IsHandledURL(const GURL
& url
) override
;
91 bool CanCommitURL(content::RenderProcessHost
* process_host
,
92 const GURL
& url
) override
;
93 bool ShouldAllowOpenURL(content::SiteInstance
* site_instance
,
94 const GURL
& url
) override
;
95 bool IsSuitableHost(content::RenderProcessHost
* process_host
,
96 const GURL
& site_url
) override
;
97 bool MayReuseHost(content::RenderProcessHost
* process_host
) override
;
98 bool ShouldTryToUseExistingProcessHost(
99 content::BrowserContext
* browser_context
,
100 const GURL
& url
) override
;
101 void SiteInstanceGotProcess(content::SiteInstance
* site_instance
) override
;
102 void SiteInstanceDeleting(content::SiteInstance
* site_instance
) override
;
103 bool ShouldSwapBrowsingInstancesForNavigation(
104 content::SiteInstance
* site_instance
,
105 const GURL
& current_url
,
106 const GURL
& new_url
) override
;
107 bool ShouldSwapProcessesForRedirect(
108 content::ResourceContext
* resource_context
,
109 const GURL
& current_url
,
110 const GURL
& new_url
) override
;
111 bool ShouldAssignSiteForURL(const GURL
& url
) override
;
112 std::string
GetCanonicalEncodingNameByAliasName(
113 const std::string
& alias_name
) override
;
114 void AppendExtraCommandLineSwitches(base::CommandLine
* command_line
,
115 int child_process_id
) override
;
116 std::string
GetApplicationLocale() override
;
117 std::string
GetAcceptLangs(content::BrowserContext
* context
) override
;
118 const gfx::ImageSkia
* GetDefaultFavicon() override
;
119 bool AllowAppCache(const GURL
& manifest_url
,
120 const GURL
& first_party
,
121 content::ResourceContext
* context
) override
;
122 bool AllowServiceWorker(const GURL
& scope
,
123 const GURL
& first_party
,
124 content::ResourceContext
* context
) override
;
125 bool AllowGetCookie(const GURL
& url
,
126 const GURL
& first_party
,
127 const net::CookieList
& cookie_list
,
128 content::ResourceContext
* context
,
129 int render_process_id
,
130 int render_frame_id
) override
;
131 bool AllowSetCookie(const GURL
& url
,
132 const GURL
& first_party
,
133 const std::string
& cookie_line
,
134 content::ResourceContext
* context
,
135 int render_process_id
,
137 net::CookieOptions
* options
) override
;
138 bool AllowSaveLocalState(content::ResourceContext
* context
) override
;
139 bool AllowWorkerDatabase(
141 const base::string16
& name
,
142 const base::string16
& display_name
,
143 unsigned long estimated_size
,
144 content::ResourceContext
* context
,
145 const std::vector
<std::pair
<int, int>>& render_frames
) override
;
146 void AllowWorkerFileSystem(
148 content::ResourceContext
* context
,
149 const std::vector
<std::pair
<int, int>>& render_frames
,
150 base::Callback
<void(bool)> callback
) override
;
151 bool AllowWorkerIndexedDB(
153 const base::string16
& name
,
154 content::ResourceContext
* context
,
155 const std::vector
<std::pair
<int, int>>& render_frames
) override
;
156 net::URLRequestContext
* OverrideRequestContextForURL(
158 content::ResourceContext
* context
) override
;
159 content::QuotaPermissionContext
* CreateQuotaPermissionContext() override
;
160 void AllowCertificateError(
161 int render_process_id
,
164 const net::SSLInfo
& ssl_info
,
165 const GURL
& request_url
,
166 content::ResourceType resource_type
,
168 bool strict_enforcement
,
169 bool expired_previous_decision
,
170 const base::Callback
<void(bool)>& callback
,
171 content::CertificateRequestResultType
* request
) override
;
172 void SelectClientCertificate(
173 int render_process_id
,
175 net::SSLCertRequestInfo
* cert_request_info
,
176 const base::Callback
<void(net::X509Certificate
*)>& callback
) override
;
177 void AddCertificate(net::CertificateMimeType cert_type
,
178 const void* cert_data
,
180 int render_process_id
,
181 int render_frame_id
) override
;
182 content::MediaObserver
* GetMediaObserver() override
;
183 blink::WebNotificationPermission
CheckDesktopNotificationPermission(
184 const GURL
& source_origin
,
185 content::ResourceContext
* context
,
186 int render_process_id
) override
;
187 void ShowDesktopNotification(
188 const content::ShowDesktopNotificationHostMsgParams
& params
,
189 content::BrowserContext
* browser_context
,
190 int render_process_id
,
191 scoped_ptr
<content::DesktopNotificationDelegate
> delegate
,
192 base::Closure
* cancel_callback
) override
;
193 void RequestPermission(
194 content::PermissionType permission
,
195 content::WebContents
* web_contents
,
197 const GURL
& requesting_frame
,
199 const base::Callback
<void(bool)>& result_callback
) override
;
200 void CancelPermissionRequest(content::PermissionType permission
,
201 content::WebContents
* web_contents
,
203 const GURL
& requesting_frame
) override
;
204 void RegisterPermissionUsage(content::PermissionType permission
,
205 content::WebContents
* web_contents
,
206 const GURL
& frame_url
,
207 const GURL
& main_frame_url
) override
;
208 bool CanCreateWindow(const GURL
& opener_url
,
209 const GURL
& opener_top_level_frame_url
,
210 const GURL
& source_origin
,
211 WindowContainerType container_type
,
212 const GURL
& target_url
,
213 const content::Referrer
& referrer
,
214 WindowOpenDisposition disposition
,
215 const blink::WebWindowFeatures
& features
,
217 bool opener_suppressed
,
218 content::ResourceContext
* context
,
219 int render_process_id
,
221 bool* no_javascript_access
) override
;
222 void ResourceDispatcherHostCreated() override
;
223 content::SpeechRecognitionManagerDelegate
*
224 CreateSpeechRecognitionManagerDelegate() override
;
225 net::NetLog
* GetNetLog() override
;
226 content::AccessTokenStore
* CreateAccessTokenStore() override
;
227 bool IsFastShutdownPossible() override
;
228 void OverrideWebkitPrefs(content::RenderViewHost
* rvh
,
230 content::WebPreferences
* prefs
) override
;
231 void BrowserURLHandlerCreated(content::BrowserURLHandler
* handler
) override
;
232 void ClearCache(content::RenderViewHost
* rvh
) override
;
233 void ClearCookies(content::RenderViewHost
* rvh
) override
;
234 base::FilePath
GetDefaultDownloadDirectory() override
;
235 std::string
GetDefaultDownloadName() override
;
236 void DidCreatePpapiPlugin(content::BrowserPpapiHost
* browser_host
) override
;
237 content::BrowserPpapiHost
* GetExternalBrowserPpapiHost(
238 int plugin_process_id
) override
;
239 bool AllowPepperSocketAPI(
240 content::BrowserContext
* browser_context
,
243 const content::SocketPermissionRequest
* params
) override
;
244 ui::SelectFilePolicy
* CreateSelectFilePolicy(
245 content::WebContents
* web_contents
) override
;
246 void GetAdditionalAllowedSchemesForFileSystem(
247 std::vector
<std::string
>* additional_schemes
) override
;
248 void GetURLRequestAutoMountHandlers(
249 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) override
;
250 void GetAdditionalFileSystemBackends(
251 content::BrowserContext
* browser_context
,
252 const base::FilePath
& storage_partition_path
,
253 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) override
;
254 content::DevToolsManagerDelegate
* GetDevToolsManagerDelegate() override
;
255 bool IsPluginAllowedToCallRequestOSFileHandle(
256 content::BrowserContext
* browser_context
,
257 const GURL
& url
) override
;
258 bool IsPluginAllowedToUseDevChannelAPIs(
259 content::BrowserContext
* browser_context
,
260 const GURL
& url
) override
;
261 net::CookieStore
* OverrideCookieStoreForRenderProcess(
262 int render_process_id
) override
;
264 #if defined(OS_POSIX) && !defined(OS_MACOSX)
265 void GetAdditionalMappedFilesForChildProcess(
266 const base::CommandLine
& command_line
,
267 int child_process_id
,
268 content::FileDescriptorInfo
* mappings
) override
;
271 virtual const wchar_t* GetResourceDllName() override
;
272 virtual void PreSpawnRenderer(sandbox::TargetPolicy
* policy
,
273 bool* success
) override
;
275 bool CheckMediaAccessPermission(content::BrowserContext
* browser_context
,
276 const GURL
& security_origin
,
277 content::MediaStreamType type
) override
;
280 friend class DisableWebRtcEncryptionFlagTest
;
282 #if defined(ENABLE_WEBRTC)
283 // Copies disable WebRTC encryption switch depending on the channel.
284 static void MaybeCopyDisableWebRtcEncryptionSwitch(
285 base::CommandLine
* to_command_line
,
286 const base::CommandLine
& from_command_line
,
287 VersionInfo::Channel channel
);
290 void FileSystemAccessed(
292 const std::vector
<std::pair
<int, int> >& render_frames
,
293 base::Callback
<void(bool)> callback
,
296 #if defined(ENABLE_EXTENSIONS)
297 void GuestPermissionRequestHelper(
299 const std::vector
<std::pair
<int, int> >& render_frames
,
300 base::Callback
<void(bool)> callback
,
303 static void RequestFileSystemPermissionOnUIThread(
304 int render_process_id
,
307 bool allowed_by_default
,
308 const base::Callback
<void(bool)>& callback
);
311 #if defined(ENABLE_PLUGINS)
312 // Set of origins that can use TCP/UDP private APIs from NaCl.
313 std::set
<std::string
> allowed_socket_origins_
;
314 // Set of origins that can get a handle for FileIO from NaCl.
315 std::set
<std::string
> allowed_file_handle_origins_
;
316 // Set of origins that can use "dev chanel" APIs from NaCl, even on stable
317 // versions of Chrome.
318 std::set
<std::string
> allowed_dev_channel_origins_
;
321 // The prerender tracker used to determine whether a render process is used
322 // for prerendering and an override cookie store must be provided.
323 // This needs to be kept as a member rather than just looked up from
324 // the profile due to initialization ordering, as well as due to threading.
325 // It is initialized on the UI thread when the ResoureDispatcherHost is
326 // created. It is used only the IO thread.
327 prerender::PrerenderTracker
* prerender_tracker_
;
329 // Vector of additional ChromeContentBrowserClientParts.
330 // Parts are deleted in the reverse order they are added.
331 std::vector
<ChromeContentBrowserClientParts
*> extra_parts_
;
333 base::WeakPtrFactory
<ChromeContentBrowserClient
> weak_factory_
;
335 DISALLOW_COPY_AND_ASSIGN(ChromeContentBrowserClient
);
338 } // namespace chrome
340 #endif // CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_