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