Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / chrome_content_browser_client.h
blob1c7d5117e3a77295193fead1b0b908280bff9abf
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_
8 #include <set>
9 #include <string>
10 #include <utility>
11 #include <vector>
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;
22 namespace base {
23 class CommandLine;
26 namespace content {
27 class QuotaPermissionContext;
30 namespace extensions {
31 class BrowserPermissionsPolicyDelegate;
34 namespace prerender {
35 class PrerenderTracker;
38 namespace user_prefs {
39 class PrefRegistrySyncable;
42 namespace chrome {
44 class ChromeContentBrowserClient : public content::ContentBrowserClient {
45 public:
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,
65 const GURL& site,
66 bool can_be_default,
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,
89 bool in_memory,
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)
105 override;
106 virtual bool ShouldSwapBrowsingInstancesForNavigation(
107 content::SiteInstance* site_instance,
108 const GURL& current_url,
109 const GURL& new_url) override;
110 virtual bool ShouldSwapProcessesForRedirect(
111 content::ResourceContext* resource_context,
112 const GURL& current_url,
113 const GURL& new_url) override;
114 virtual bool ShouldAssignSiteForURL(const GURL& url) override;
115 virtual std::string GetCanonicalEncodingNameByAliasName(
116 const std::string& alias_name) override;
117 virtual void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
118 int child_process_id) override;
119 virtual std::string GetApplicationLocale() override;
120 virtual std::string GetAcceptLangs(
121 content::BrowserContext* context) override;
122 virtual const gfx::ImageSkia* GetDefaultFavicon() override;
123 virtual bool AllowAppCache(const GURL& manifest_url,
124 const GURL& first_party,
125 content::ResourceContext* context) override;
126 virtual bool AllowServiceWorker(const GURL& scope,
127 const GURL& first_party,
128 content::ResourceContext* context) override;
129 virtual bool AllowGetCookie(const GURL& url,
130 const GURL& first_party,
131 const net::CookieList& cookie_list,
132 content::ResourceContext* context,
133 int render_process_id,
134 int render_frame_id) override;
135 virtual bool AllowSetCookie(const GURL& url,
136 const GURL& first_party,
137 const std::string& cookie_line,
138 content::ResourceContext* context,
139 int render_process_id,
140 int render_frame_id,
141 net::CookieOptions* options) override;
142 virtual bool AllowSaveLocalState(content::ResourceContext* context) override;
143 virtual bool AllowWorkerDatabase(
144 const GURL& url,
145 const base::string16& name,
146 const base::string16& display_name,
147 unsigned long estimated_size,
148 content::ResourceContext* context,
149 const std::vector<std::pair<int, int> >& render_frames) override;
150 virtual void AllowWorkerFileSystem(
151 const GURL& url,
152 content::ResourceContext* context,
153 const std::vector<std::pair<int, int> >& render_frames,
154 base::Callback<void(bool)> callback) override;
155 virtual bool AllowWorkerIndexedDB(
156 const GURL& url,
157 const base::string16& name,
158 content::ResourceContext* context,
159 const std::vector<std::pair<int, int> >& render_frames) override;
160 virtual net::URLRequestContext* OverrideRequestContextForURL(
161 const GURL& url, content::ResourceContext* context) override;
162 virtual content::QuotaPermissionContext*
163 CreateQuotaPermissionContext() override;
164 virtual void AllowCertificateError(
165 int render_process_id,
166 int render_frame_id,
167 int cert_error,
168 const net::SSLInfo& ssl_info,
169 const GURL& request_url,
170 content::ResourceType resource_type,
171 bool overridable,
172 bool strict_enforcement,
173 bool expired_previous_decision,
174 const base::Callback<void(bool)>& callback,
175 content::CertificateRequestResultType* request) override;
176 virtual void SelectClientCertificate(
177 int render_process_id,
178 int render_frame_id,
179 net::SSLCertRequestInfo* cert_request_info,
180 const base::Callback<void(net::X509Certificate*)>& callback) override;
181 virtual void AddCertificate(net::CertificateMimeType cert_type,
182 const void* cert_data,
183 size_t cert_size,
184 int render_process_id,
185 int render_frame_id) override;
186 virtual content::MediaObserver* GetMediaObserver() override;
187 virtual void RequestDesktopNotificationPermission(
188 const GURL& source_origin,
189 content::RenderFrameHost* render_frame_host,
190 const base::Callback<void(blink::WebNotificationPermission)>& callback)
191 override;
192 virtual blink::WebNotificationPermission
193 CheckDesktopNotificationPermission(
194 const GURL& source_origin,
195 content::ResourceContext* context,
196 int render_process_id) override;
197 virtual void ShowDesktopNotification(
198 const content::ShowDesktopNotificationHostMsgParams& params,
199 content::RenderFrameHost* render_frame_host,
200 scoped_ptr<content::DesktopNotificationDelegate> delegate,
201 base::Closure* cancel_callback) override;
202 virtual void RequestGeolocationPermission(
203 content::WebContents* web_contents,
204 int bridge_id,
205 const GURL& requesting_frame,
206 bool user_gesture,
207 const base::Callback<void(bool)>& result_callback) override;
208 virtual void CancelGeolocationPermissionRequest(
209 content::WebContents* web_contents,
210 int bridge_id,
211 const GURL& requesting_frame) override;
212 virtual void RequestMidiSysExPermission(
213 content::WebContents* web_contents,
214 int bridge_id,
215 const GURL& requesting_frame,
216 bool user_gesture,
217 base::Callback<void(bool)> result_callback,
218 base::Closure* cancel_callback) override;
219 virtual void DidUseGeolocationPermission(content::WebContents* web_contents,
220 const GURL& frame_url,
221 const GURL& main_frame_url) override;
222 virtual void RequestProtectedMediaIdentifierPermission(
223 content::WebContents* web_contents,
224 const GURL& origin,
225 base::Callback<void(bool)> result_callback,
226 base::Closure* cancel_callback) override;
227 virtual bool CanCreateWindow(const GURL& opener_url,
228 const GURL& opener_top_level_frame_url,
229 const GURL& source_origin,
230 WindowContainerType container_type,
231 const GURL& target_url,
232 const content::Referrer& referrer,
233 WindowOpenDisposition disposition,
234 const blink::WebWindowFeatures& features,
235 bool user_gesture,
236 bool opener_suppressed,
237 content::ResourceContext* context,
238 int render_process_id,
239 int opener_id,
240 bool* no_javascript_access) override;
241 virtual void ResourceDispatcherHostCreated() override;
242 virtual content::SpeechRecognitionManagerDelegate*
243 GetSpeechRecognitionManagerDelegate() override;
244 virtual net::NetLog* GetNetLog() override;
245 virtual content::AccessTokenStore* CreateAccessTokenStore() override;
246 virtual bool IsFastShutdownPossible() override;
247 virtual void OverrideWebkitPrefs(content::RenderViewHost* rvh,
248 const GURL& url,
249 content::WebPreferences* prefs) override;
250 virtual void BrowserURLHandlerCreated(
251 content::BrowserURLHandler* handler) override;
252 virtual void ClearCache(content::RenderViewHost* rvh) override;
253 virtual void ClearCookies(content::RenderViewHost* rvh) override;
254 virtual base::FilePath GetDefaultDownloadDirectory() override;
255 virtual std::string GetDefaultDownloadName() override;
256 virtual void DidCreatePpapiPlugin(
257 content::BrowserPpapiHost* browser_host) override;
258 virtual content::BrowserPpapiHost* GetExternalBrowserPpapiHost(
259 int plugin_process_id) override;
260 virtual bool AllowPepperSocketAPI(
261 content::BrowserContext* browser_context,
262 const GURL& url,
263 bool private_api,
264 const content::SocketPermissionRequest* params) override;
265 virtual ui::SelectFilePolicy* CreateSelectFilePolicy(
266 content::WebContents* web_contents) override;
267 virtual void GetAdditionalAllowedSchemesForFileSystem(
268 std::vector<std::string>* additional_schemes) override;
269 virtual void GetURLRequestAutoMountHandlers(
270 std::vector<storage::URLRequestAutoMountHandler>* handlers) override;
271 virtual void GetAdditionalFileSystemBackends(
272 content::BrowserContext* browser_context,
273 const base::FilePath& storage_partition_path,
274 ScopedVector<storage::FileSystemBackend>* additional_backends) override;
275 virtual content::DevToolsManagerDelegate*
276 GetDevToolsManagerDelegate() override;
277 virtual bool IsPluginAllowedToCallRequestOSFileHandle(
278 content::BrowserContext* browser_context,
279 const GURL& url) override;
280 virtual bool IsPluginAllowedToUseDevChannelAPIs(
281 content::BrowserContext* browser_context,
282 const GURL& url) override;
283 virtual net::CookieStore* OverrideCookieStoreForRenderProcess(
284 int render_process_id) override;
286 #if defined(OS_POSIX) && !defined(OS_MACOSX)
287 virtual void GetAdditionalMappedFilesForChildProcess(
288 const base::CommandLine& command_line,
289 int child_process_id,
290 content::FileDescriptorInfo* mappings) override;
291 #endif
292 #if defined(OS_WIN)
293 virtual const wchar_t* GetResourceDllName() override;
294 virtual void PreSpawnRenderer(sandbox::TargetPolicy* policy,
295 bool* success) override;
296 #endif
297 virtual bool CheckMediaAccessPermission(
298 content::BrowserContext* browser_context,
299 const GURL& security_origin,
300 content::MediaStreamType type) override;
302 private:
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);
311 #endif
313 void FileSystemAccessed(
314 const GURL& url,
315 const std::vector<std::pair<int, int> >& render_frames,
316 base::Callback<void(bool)> callback,
317 bool allow);
319 #if defined(ENABLE_EXTENSIONS)
320 void GuestPermissionRequestHelper(
321 const GURL& url,
322 const std::vector<std::pair<int, int> >& render_frames,
323 base::Callback<void(bool)> callback,
324 bool allow);
326 static void RequestFileSystemPermissionOnUIThread(
327 int render_process_id,
328 int render_frame_id,
329 const GURL& url,
330 bool allowed_by_default,
331 const base::Callback<void(bool)>& callback);
332 #endif
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_;
342 #endif
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_