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 "content/public/browser/content_browser_client.h"
19 class ChromeContentBrowserClientParts
;
26 class QuotaPermissionContext
;
29 namespace extensions
{
30 class BrowserPermissionsPolicyDelegate
;
33 namespace user_prefs
{
34 class PrefRegistrySyncable
;
37 namespace version_info
{
43 class ChromeContentBrowserClient
: public content::ContentBrowserClient
{
45 ChromeContentBrowserClient();
46 ~ChromeContentBrowserClient() override
;
48 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
50 // Notification that the application locale has changed. This allows us to
51 // update our I/O thread cache of this value.
52 static void SetApplicationLocale(const std::string
& locale
);
54 content::BrowserMainParts
* CreateBrowserMainParts(
55 const content::MainFunctionParams
& parameters
) override
;
56 void PostAfterStartupTask(const tracked_objects::Location
& from_here
,
57 const scoped_refptr
<base::TaskRunner
>& task_runner
,
58 const base::Closure
& task
) override
;
59 std::string
GetStoragePartitionIdForSite(
60 content::BrowserContext
* browser_context
,
61 const GURL
& site
) override
;
62 bool IsValidStoragePartitionId(content::BrowserContext
* browser_context
,
63 const std::string
& partition_id
) override
;
64 void GetStoragePartitionConfigForSite(
65 content::BrowserContext
* browser_context
,
68 std::string
* partition_domain
,
69 std::string
* partition_name
,
70 bool* in_memory
) override
;
71 content::WebContentsViewDelegate
* GetWebContentsViewDelegate(
72 content::WebContents
* web_contents
) override
;
73 void RenderProcessWillLaunch(content::RenderProcessHost
* host
) override
;
74 bool ShouldUseProcessPerSite(content::BrowserContext
* browser_context
,
75 const GURL
& effective_url
) override
;
76 GURL
GetEffectiveURL(content::BrowserContext
* browser_context
,
77 const GURL
& url
) override
;
78 void GetAdditionalWebUISchemes(
79 std::vector
<std::string
>* additional_schemes
) override
;
80 void GetAdditionalWebUIHostsToIgnoreParititionCheck(
81 std::vector
<std::string
>* hosts
) override
;
82 net::URLRequestContextGetter
* CreateRequestContext(
83 content::BrowserContext
* browser_context
,
84 content::ProtocolHandlerMap
* protocol_handlers
,
85 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
86 net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
87 content::BrowserContext
* browser_context
,
88 const base::FilePath
& partition_path
,
90 content::ProtocolHandlerMap
* protocol_handlers
,
91 content::URLRequestInterceptorScopedVector request_interceptors
) override
;
92 bool IsHandledURL(const GURL
& url
) override
;
93 bool CanCommitURL(content::RenderProcessHost
* process_host
,
94 const GURL
& url
) override
;
95 bool IsIllegalOrigin(content::ResourceContext
* resource_context
,
97 const GURL
& origin
) override
;
98 bool ShouldAllowOpenURL(content::SiteInstance
* site_instance
,
99 const GURL
& url
) override
;
100 bool IsSuitableHost(content::RenderProcessHost
* process_host
,
101 const GURL
& site_url
) override
;
102 bool MayReuseHost(content::RenderProcessHost
* process_host
) override
;
103 bool ShouldTryToUseExistingProcessHost(
104 content::BrowserContext
* browser_context
,
105 const GURL
& url
) override
;
106 void SiteInstanceGotProcess(content::SiteInstance
* site_instance
) override
;
107 void SiteInstanceDeleting(content::SiteInstance
* site_instance
) override
;
108 bool ShouldSwapBrowsingInstancesForNavigation(
109 content::SiteInstance
* site_instance
,
110 const GURL
& current_url
,
111 const GURL
& new_url
) override
;
112 bool ShouldSwapProcessesForRedirect(
113 content::ResourceContext
* resource_context
,
114 const GURL
& current_url
,
115 const GURL
& new_url
) override
;
116 bool ShouldAssignSiteForURL(const GURL
& url
) override
;
117 std::string
GetCanonicalEncodingNameByAliasName(
118 const std::string
& alias_name
) override
;
119 void AppendExtraCommandLineSwitches(base::CommandLine
* command_line
,
120 int child_process_id
) override
;
121 std::string
GetApplicationLocale() override
;
122 std::string
GetAcceptLangs(content::BrowserContext
* context
) override
;
123 const gfx::ImageSkia
* GetDefaultFavicon() override
;
124 bool AllowAppCache(const GURL
& manifest_url
,
125 const GURL
& first_party
,
126 content::ResourceContext
* context
) override
;
127 bool AllowServiceWorker(const GURL
& scope
,
128 const GURL
& first_party
,
129 content::ResourceContext
* context
,
130 int render_process_id
,
131 int render_frame_id
) override
;
132 bool AllowGetCookie(const GURL
& url
,
133 const GURL
& first_party
,
134 const net::CookieList
& cookie_list
,
135 content::ResourceContext
* context
,
136 int render_process_id
,
137 int render_frame_id
) override
;
138 bool AllowSetCookie(const GURL
& url
,
139 const GURL
& first_party
,
140 const std::string
& cookie_line
,
141 content::ResourceContext
* context
,
142 int render_process_id
,
144 net::CookieOptions
* options
) override
;
145 bool AllowSaveLocalState(content::ResourceContext
* context
) override
;
146 bool AllowWorkerDatabase(
148 const base::string16
& name
,
149 const base::string16
& display_name
,
150 unsigned long estimated_size
,
151 content::ResourceContext
* context
,
152 const std::vector
<std::pair
<int, int>>& render_frames
) override
;
153 void AllowWorkerFileSystem(
155 content::ResourceContext
* context
,
156 const std::vector
<std::pair
<int, int>>& render_frames
,
157 base::Callback
<void(bool)> callback
) override
;
158 bool AllowWorkerIndexedDB(
160 const base::string16
& name
,
161 content::ResourceContext
* context
,
162 const std::vector
<std::pair
<int, int>>& render_frames
) override
;
164 #if defined(ENABLE_WEBRTC)
165 bool AllowWebRTCIdentityCache(const GURL
& url
,
166 const GURL
& first_party_url
,
167 content::ResourceContext
* context
) override
;
168 #endif // defined(ENABLE_WEBRTC)
170 net::URLRequestContext
* OverrideRequestContextForURL(
172 content::ResourceContext
* context
) override
;
173 content::QuotaPermissionContext
* CreateQuotaPermissionContext() override
;
174 void AllowCertificateError(
175 int render_process_id
,
178 const net::SSLInfo
& ssl_info
,
179 const GURL
& request_url
,
180 content::ResourceType resource_type
,
182 bool strict_enforcement
,
183 bool expired_previous_decision
,
184 const base::Callback
<void(bool)>& callback
,
185 content::CertificateRequestResultType
* request
) override
;
186 void SelectClientCertificate(
187 content::WebContents
* web_contents
,
188 net::SSLCertRequestInfo
* cert_request_info
,
189 scoped_ptr
<content::ClientCertificateDelegate
> delegate
) override
;
190 void AddCertificate(net::CertificateMimeType cert_type
,
191 const void* cert_data
,
193 int render_process_id
,
194 int render_frame_id
) override
;
195 content::MediaObserver
* GetMediaObserver() override
;
196 content::PlatformNotificationService
* GetPlatformNotificationService()
198 bool CanCreateWindow(const GURL
& opener_url
,
199 const GURL
& opener_top_level_frame_url
,
200 const GURL
& source_origin
,
201 WindowContainerType container_type
,
202 const GURL
& target_url
,
203 const content::Referrer
& referrer
,
204 WindowOpenDisposition disposition
,
205 const blink::WebWindowFeatures
& features
,
207 bool opener_suppressed
,
208 content::ResourceContext
* context
,
209 int render_process_id
,
210 int opener_render_view_id
,
211 int opener_render_frame_id
,
212 bool* no_javascript_access
) override
;
213 void ResourceDispatcherHostCreated() override
;
214 content::SpeechRecognitionManagerDelegate
*
215 CreateSpeechRecognitionManagerDelegate() override
;
216 net::NetLog
* GetNetLog() override
;
217 content::AccessTokenStore
* CreateAccessTokenStore() override
;
218 bool IsFastShutdownPossible() override
;
219 void OverrideWebkitPrefs(content::RenderViewHost
* rvh
,
220 content::WebPreferences
* prefs
) override
;
221 void BrowserURLHandlerCreated(content::BrowserURLHandler
* handler
) override
;
222 void ClearCache(content::RenderFrameHost
* rfh
) override
;
223 void ClearCookies(content::RenderFrameHost
* rfh
) override
;
224 base::FilePath
GetDefaultDownloadDirectory() override
;
225 std::string
GetDefaultDownloadName() override
;
226 base::FilePath
GetShaderDiskCacheDirectory() override
;
227 void DidCreatePpapiPlugin(content::BrowserPpapiHost
* browser_host
) override
;
228 content::BrowserPpapiHost
* GetExternalBrowserPpapiHost(
229 int plugin_process_id
) override
;
230 bool AllowPepperSocketAPI(
231 content::BrowserContext
* browser_context
,
234 const content::SocketPermissionRequest
* params
) override
;
235 ui::SelectFilePolicy
* CreateSelectFilePolicy(
236 content::WebContents
* web_contents
) override
;
237 void GetAdditionalAllowedSchemesForFileSystem(
238 std::vector
<std::string
>* additional_schemes
) override
;
239 void GetURLRequestAutoMountHandlers(
240 std::vector
<storage::URLRequestAutoMountHandler
>* handlers
) override
;
241 void GetAdditionalFileSystemBackends(
242 content::BrowserContext
* browser_context
,
243 const base::FilePath
& storage_partition_path
,
244 ScopedVector
<storage::FileSystemBackend
>* additional_backends
) override
;
245 content::DevToolsManagerDelegate
* GetDevToolsManagerDelegate() override
;
246 content::TracingDelegate
* GetTracingDelegate() override
;
247 bool IsPluginAllowedToCallRequestOSFileHandle(
248 content::BrowserContext
* browser_context
,
249 const GURL
& url
) override
;
250 bool IsPluginAllowedToUseDevChannelAPIs(
251 content::BrowserContext
* browser_context
,
252 const GURL
& url
) override
;
253 void OverridePageVisibilityState(
254 content::RenderFrameHost
* render_frame_host
,
255 blink::WebPageVisibilityState
* visibility_state
) override
;
257 #if defined(OS_ANDROID)
258 void GetAdditionalMappedFilesForChildProcess(
259 const base::CommandLine
& command_line
,
260 int child_process_id
,
261 content::FileDescriptorInfo
* mappings
,
262 std::map
<int, base::MemoryMappedFile::Region
>* regions
) override
;
263 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
264 void GetAdditionalMappedFilesForChildProcess(
265 const base::CommandLine
& command_line
,
266 int child_process_id
,
267 content::FileDescriptorInfo
* mappings
) override
;
268 #endif // defined(OS_ANDROID)
270 const wchar_t* GetResourceDllName() override
;
271 void PreSpawnRenderer(sandbox::TargetPolicy
* policy
, bool* success
) override
;
272 base::string16
GetAppContainerSidForSandboxType(
273 int sandbox_type
) const override
;
275 void RegisterFrameMojoShellServices(
276 content::ServiceRegistry
* registry
,
277 content::RenderFrameHost
* render_frame_host
) override
;
278 void RegisterInProcessMojoApplications(
279 StaticMojoApplicationMap
* apps
) override
;
280 void OpenURL(content::BrowserContext
* browser_context
,
281 const content::OpenURLParams
& params
,
282 const base::Callback
<void(content::WebContents
*)>& callback
)
284 content::PresentationServiceDelegate
* GetPresentationServiceDelegate(
285 content::WebContents
* web_contents
) override
;
287 void RecordURLMetric(const std::string
& metric
, const GURL
& url
) override
;
290 friend class DisableWebRtcEncryptionFlagTest
;
292 #if defined(ENABLE_WEBRTC)
293 // Copies disable WebRTC encryption switch depending on the channel.
294 static void MaybeCopyDisableWebRtcEncryptionSwitch(
295 base::CommandLine
* to_command_line
,
296 const base::CommandLine
& from_command_line
,
297 version_info::Channel channel
);
300 void FileSystemAccessed(
302 const std::vector
<std::pair
<int, int> >& render_frames
,
303 base::Callback
<void(bool)> callback
,
306 #if defined(ENABLE_EXTENSIONS)
307 void GuestPermissionRequestHelper(
309 const std::vector
<std::pair
<int, int> >& render_frames
,
310 base::Callback
<void(bool)> callback
,
313 static void RequestFileSystemPermissionOnUIThread(
314 int render_process_id
,
317 bool allowed_by_default
,
318 const base::Callback
<void(bool)>& callback
);
321 #if defined(ENABLE_PLUGINS)
322 // Set of origins that can use TCP/UDP private APIs from NaCl.
323 std::set
<std::string
> allowed_socket_origins_
;
324 // Set of origins that can get a handle for FileIO from NaCl.
325 std::set
<std::string
> allowed_file_handle_origins_
;
326 // Set of origins that can use "dev chanel" APIs from NaCl, even on stable
327 // versions of Chrome.
328 std::set
<std::string
> allowed_dev_channel_origins_
;
331 // Vector of additional ChromeContentBrowserClientParts.
332 // Parts are deleted in the reverse order they are added.
333 std::vector
<ChromeContentBrowserClientParts
*> extra_parts_
;
335 base::WeakPtrFactory
<ChromeContentBrowserClient
> weak_factory_
;
337 DISALLOW_COPY_AND_ASSIGN(ChromeContentBrowserClient
);
340 } // namespace chrome
342 #endif // CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_