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 virtual ~ChromeContentBrowserClient();
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 virtual content::BrowserMainParts* CreateBrowserMainParts(
56 const content::MainFunctionParams& parameters) OVERRIDE;
57 virtual std::string GetStoragePartitionIdForSite(
58 content::BrowserContext* browser_context,
59 const GURL& site) OVERRIDE;
60 virtual bool IsValidStoragePartitionId(
61 content::BrowserContext* browser_context,
62 const std::string& partition_id) OVERRIDE;
63 virtual void GetStoragePartitionConfigForSite(
64 content::BrowserContext* browser_context,
67 std::string* partition_domain,
68 std::string* partition_name,
69 bool* in_memory) OVERRIDE;
70 virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate(
71 content::WebContents* web_contents) OVERRIDE;
72 virtual void RenderProcessWillLaunch(
73 content::RenderProcessHost* host) OVERRIDE;
74 virtual bool ShouldUseProcessPerSite(content::BrowserContext* browser_context,
75 const GURL& effective_url) OVERRIDE;
76 virtual GURL GetEffectiveURL(content::BrowserContext* browser_context,
77 const GURL& url) OVERRIDE;
78 virtual void GetAdditionalWebUISchemes(
79 std::vector<std::string>* additional_schemes) OVERRIDE;
80 virtual void GetAdditionalWebUIHostsToIgnoreParititionCheck(
81 std::vector<std::string>* hosts) OVERRIDE;
82 virtual net::URLRequestContextGetter* CreateRequestContext(
83 content::BrowserContext* browser_context,
84 content::ProtocolHandlerMap* protocol_handlers,
85 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE;
86 virtual 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 virtual bool IsHandledURL(const GURL& url) OVERRIDE;
93 virtual bool CanCommitURL(content::RenderProcessHost* process_host,
94 const GURL& url) OVERRIDE;
95 virtual bool ShouldAllowOpenURL(content::SiteInstance* site_instance,
96 const GURL& url) OVERRIDE;
97 virtual bool IsSuitableHost(content::RenderProcessHost* process_host,
98 const GURL& site_url) OVERRIDE;
99 virtual bool MayReuseHost(content::RenderProcessHost* process_host) OVERRIDE;
100 virtual bool ShouldTryToUseExistingProcessHost(
101 content::BrowserContext* browser_context, const GURL& url) OVERRIDE;
102 virtual void SiteInstanceGotProcess(
103 content::SiteInstance* site_instance) OVERRIDE;
104 virtual void SiteInstanceDeleting(content::SiteInstance* site_instance)
106 virtual void WorkerProcessCreated(content::SiteInstance* site_instance,
107 int worker_process_id) OVERRIDE;
108 virtual void WorkerProcessTerminated(content::SiteInstance* site_instance,
109 int worker_process_id) OVERRIDE;
110 virtual bool ShouldSwapBrowsingInstancesForNavigation(
111 content::SiteInstance* site_instance,
112 const GURL& current_url,
113 const GURL& new_url) OVERRIDE;
114 virtual bool ShouldSwapProcessesForRedirect(
115 content::ResourceContext* resource_context,
116 const GURL& current_url,
117 const GURL& new_url) OVERRIDE;
118 virtual bool ShouldAssignSiteForURL(const GURL& url) OVERRIDE;
119 virtual std::string GetCanonicalEncodingNameByAliasName(
120 const std::string& alias_name) OVERRIDE;
121 virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
122 int child_process_id) OVERRIDE;
123 virtual std::string GetApplicationLocale() OVERRIDE;
124 virtual std::string GetAcceptLangs(
125 content::BrowserContext* context) OVERRIDE;
126 virtual const gfx::ImageSkia* GetDefaultFavicon() OVERRIDE;
127 virtual bool AllowAppCache(const GURL& manifest_url,
128 const GURL& first_party,
129 content::ResourceContext* context) OVERRIDE;
130 virtual bool AllowGetCookie(const GURL& url,
131 const GURL& first_party,
132 const net::CookieList& cookie_list,
133 content::ResourceContext* context,
134 int render_process_id,
135 int render_frame_id) OVERRIDE;
136 virtual bool AllowSetCookie(const GURL& url,
137 const GURL& first_party,
138 const std::string& cookie_line,
139 content::ResourceContext* context,
140 int render_process_id,
142 net::CookieOptions* options) OVERRIDE;
143 virtual bool AllowSaveLocalState(content::ResourceContext* context) OVERRIDE;
144 virtual bool AllowWorkerDatabase(
146 const base::string16& name,
147 const base::string16& display_name,
148 unsigned long estimated_size,
149 content::ResourceContext* context,
150 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE;
151 virtual void AllowWorkerFileSystem(
153 content::ResourceContext* context,
154 const std::vector<std::pair<int, int> >& render_frames,
155 base::Callback<void(bool)> callback) OVERRIDE;
156 virtual bool AllowWorkerIndexedDB(
158 const base::string16& name,
159 content::ResourceContext* context,
160 const std::vector<std::pair<int, int> >& render_frames) OVERRIDE;
161 virtual net::URLRequestContext* OverrideRequestContextForURL(
162 const GURL& url, content::ResourceContext* context) OVERRIDE;
163 virtual content::QuotaPermissionContext*
164 CreateQuotaPermissionContext() OVERRIDE;
165 virtual void AllowCertificateError(
166 int render_process_id,
169 const net::SSLInfo& ssl_info,
170 const GURL& request_url,
171 content::ResourceType resource_type,
173 bool strict_enforcement,
174 bool expired_previous_decision,
175 const base::Callback<void(bool)>& callback,
176 content::CertificateRequestResultType* request) OVERRIDE;
177 virtual void SelectClientCertificate(
178 int render_process_id,
180 const net::HttpNetworkSession* network_session,
181 net::SSLCertRequestInfo* cert_request_info,
182 const base::Callback<void(net::X509Certificate*)>& callback) OVERRIDE;
183 virtual void AddCertificate(net::CertificateMimeType cert_type,
184 const void* cert_data,
186 int render_process_id,
187 int render_frame_id) OVERRIDE;
188 virtual content::MediaObserver* GetMediaObserver() OVERRIDE;
189 virtual void RequestDesktopNotificationPermission(
190 const GURL& source_origin,
191 content::RenderFrameHost* render_frame_host,
192 const base::Callback<void(blink::WebNotificationPermission)>& callback)
194 virtual blink::WebNotificationPermission
195 CheckDesktopNotificationPermission(
196 const GURL& source_origin,
197 content::ResourceContext* context,
198 int render_process_id) OVERRIDE;
199 virtual void ShowDesktopNotification(
200 const content::ShowDesktopNotificationHostMsgParams& params,
201 content::RenderFrameHost* render_frame_host,
202 scoped_ptr<content::DesktopNotificationDelegate> delegate,
203 base::Closure* cancel_callback) OVERRIDE;
204 virtual void RequestGeolocationPermission(
205 content::WebContents* web_contents,
207 const GURL& requesting_frame,
209 base::Callback<void(bool)> result_callback,
210 base::Closure* cancel_callback) OVERRIDE;
211 virtual void RequestMidiSysExPermission(
212 content::WebContents* web_contents,
214 const GURL& requesting_frame,
216 base::Callback<void(bool)> result_callback,
217 base::Closure* cancel_callback) OVERRIDE;
218 virtual void DidUseGeolocationPermission(content::WebContents* web_contents,
219 const GURL& frame_url,
220 const GURL& main_frame_url) OVERRIDE;
221 virtual void RequestProtectedMediaIdentifierPermission(
222 content::WebContents* web_contents,
224 base::Callback<void(bool)> result_callback,
225 base::Closure* cancel_callback) OVERRIDE;
226 virtual bool CanCreateWindow(const GURL& opener_url,
227 const GURL& opener_top_level_frame_url,
228 const GURL& source_origin,
229 WindowContainerType container_type,
230 const GURL& target_url,
231 const content::Referrer& referrer,
232 WindowOpenDisposition disposition,
233 const blink::WebWindowFeatures& features,
235 bool opener_suppressed,
236 content::ResourceContext* context,
237 int render_process_id,
239 bool* no_javascript_access) OVERRIDE;
240 virtual std::string GetWorkerProcessTitle(
241 const GURL& url, content::ResourceContext* context) OVERRIDE;
242 virtual void ResourceDispatcherHostCreated() OVERRIDE;
243 virtual content::SpeechRecognitionManagerDelegate*
244 GetSpeechRecognitionManagerDelegate() OVERRIDE;
245 virtual net::NetLog* GetNetLog() OVERRIDE;
246 virtual content::AccessTokenStore* CreateAccessTokenStore() OVERRIDE;
247 virtual bool IsFastShutdownPossible() OVERRIDE;
248 virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh,
250 content::WebPreferences* prefs) OVERRIDE;
251 virtual void UpdateInspectorSetting(content::RenderViewHost* rvh,
252 const std::string& key,
253 const std::string& value) OVERRIDE;
254 virtual void BrowserURLHandlerCreated(
255 content::BrowserURLHandler* handler) OVERRIDE;
256 virtual void ClearCache(content::RenderViewHost* rvh) OVERRIDE;
257 virtual void ClearCookies(content::RenderViewHost* rvh) OVERRIDE;
258 virtual base::FilePath GetDefaultDownloadDirectory() OVERRIDE;
259 virtual std::string GetDefaultDownloadName() OVERRIDE;
260 virtual void DidCreatePpapiPlugin(
261 content::BrowserPpapiHost* browser_host) OVERRIDE;
262 virtual content::BrowserPpapiHost* GetExternalBrowserPpapiHost(
263 int plugin_process_id) OVERRIDE;
264 virtual bool AllowPepperSocketAPI(
265 content::BrowserContext* browser_context,
268 const content::SocketPermissionRequest* params) OVERRIDE;
269 virtual ui::SelectFilePolicy* CreateSelectFilePolicy(
270 content::WebContents* web_contents) OVERRIDE;
271 virtual void GetAdditionalAllowedSchemesForFileSystem(
272 std::vector<std::string>* additional_schemes) OVERRIDE;
273 virtual void GetURLRequestAutoMountHandlers(
274 std::vector<fileapi::URLRequestAutoMountHandler>* handlers) OVERRIDE;
275 virtual void GetAdditionalFileSystemBackends(
276 content::BrowserContext* browser_context,
277 const base::FilePath& storage_partition_path,
278 ScopedVector<fileapi::FileSystemBackend>* additional_backends) OVERRIDE;
279 virtual content::DevToolsManagerDelegate*
280 GetDevToolsManagerDelegate() OVERRIDE;
281 virtual bool IsPluginAllowedToCallRequestOSFileHandle(
282 content::BrowserContext* browser_context,
283 const GURL& url) OVERRIDE;
284 virtual bool IsPluginAllowedToUseDevChannelAPIs(
285 content::BrowserContext* browser_context,
286 const GURL& url) OVERRIDE;
287 virtual net::CookieStore* OverrideCookieStoreForRenderProcess(
288 int render_process_id) OVERRIDE;
290 #if defined(OS_POSIX) && !defined(OS_MACOSX)
291 virtual void GetAdditionalMappedFilesForChildProcess(
292 const base::CommandLine& command_line,
293 int child_process_id,
294 std::vector<content::FileDescriptorInfo>* mappings) OVERRIDE;
297 virtual const wchar_t* GetResourceDllName() OVERRIDE;
298 virtual void PreSpawnRenderer(sandbox::TargetPolicy* policy,
299 bool* success) OVERRIDE;
303 friend class DisableWebRtcEncryptionFlagTest;
305 #if defined(ENABLE_WEBRTC)
306 // Copies disable WebRTC encryption switch depending on the channel.
307 static void MaybeCopyDisableWebRtcEncryptionSwitch(
308 base::CommandLine* to_command_line,
309 const base::CommandLine& from_command_line,
310 VersionInfo::Channel channel);
313 void FileSystemAccessed(
315 const std::vector<std::pair<int, int> >& render_frames,
316 base::Callback<void(bool)> callback,
319 #if defined(ENABLE_EXTENSIONS)
320 void GuestPermissionRequestHelper(
322 const std::vector<std::pair<int, int> >& render_frames,
323 base::Callback<void(bool)> callback,
326 static void RequestFileSystemPermissionOnUIThread(
327 int render_process_id,
330 bool allowed_by_default,
331 const base::Callback<void(bool)>& callback);
334 #if defined(ENABLE_PLUGINS)
335 // Set of origins that can use TCP/UDP private APIs from NaCl.
336 std::set<std::string> allowed_socket_origins_;
337 // Set of origins that can get a handle for FileIO from NaCl.
338 std::set<std::string> allowed_file_handle_origins_;
339 // Set of origins that can use "dev chanel" APIs from NaCl, even on stable
340 // versions of Chrome.
341 std::set<std::string> allowed_dev_channel_origins_;
344 // The prerender tracker used to determine whether a render process is used
345 // for prerendering and an override cookie store must be provided.
346 // This needs to be kept as a member rather than just looked up from
347 // the profile due to initialization ordering, as well as due to threading.
348 // It is initialized on the UI thread when the ResoureDispatcherHost is
349 // created. It is used only the IO thread.
350 prerender::PrerenderTracker* prerender_tracker_;
352 // Vector of additional ChromeContentBrowserClientParts.
353 // Parts are deleted in the reverse order they are added.
354 std::vector<ChromeContentBrowserClientParts*> extra_parts_;
356 base::WeakPtrFactory<ChromeContentBrowserClient> weak_factory_;
358 DISALLOW_COPY_AND_ASSIGN(ChromeContentBrowserClient);
361 } // namespace chrome
363 #endif // CHROME_BROWSER_CHROME_CONTENT_BROWSER_CLIENT_H_