blob: 8072046919e92f88f1a6c50218b23fb2116da200 [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// Copyright (c) 2011 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.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]b80f68432011-05-02 17:22:307#include "base/command_line.h"
8#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:259#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3010#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2311#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1212#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0313#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]97e6c4c2011-05-18 16:08:5114#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4115#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3616#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4917#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3218#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3219#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0420#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1021#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2622#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2523#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]39a5b532011-10-22 01:47:0724#include "chrome/browser/extensions/extension_webrequest_api.h"
[email protected]32538d92011-08-25 00:09:2325#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2827#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0428#include "chrome/browser/notifications/desktop_notification_service.h"
29#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4230#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1231#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4132#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5033#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4134#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1435#include "chrome/browser/printing/printing_message_filter.h"
36#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3237#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1438#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3339#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]05fcf982011-04-19 00:44:1440#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0441#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4642#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4543#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0344#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3645#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4546#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
47#include "chrome/browser/tab_contents/tab_util.h"
48#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5649#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3050#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0151#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3052#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0453#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3454#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1255#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3856#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0957#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2558#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0959#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5160#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1461#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2662#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4963#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0964#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4165#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4566#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1267#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3268#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3669#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0470#include "content/common/desktop_notification_messages.h"
[email protected]c9b6eb62011-10-18 20:49:3971#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3472#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0173#include "net/base/cookie_monster.h"
74#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3975#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0876#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2677
[email protected]5778d502011-10-13 17:13:2178#if defined(OS_CHROMEOS)
79#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
80#elif defined(USE_AURA)
[email protected]199fc7a2011-09-28 22:45:3881#include "chrome/browser/chrome_browser_main_aura.h"
82#elif defined(OS_WIN)
83#include "chrome/browser/chrome_browser_main_win.h"
84#elif defined(OS_MACOSX)
85#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]c92f4ed2011-10-21 19:50:2186#elif defined(TOOLKIT_USES_GTK)
[email protected]199fc7a2011-09-28 22:45:3887#include "chrome/browser/chrome_browser_main_gtk.h"
88#endif
89
[email protected]b80f68432011-05-02 17:22:3090#if defined(OS_LINUX)
91#include "base/linux_util.h"
92#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4393#endif
[email protected]b80f68432011-05-02 17:22:3094
[email protected]080f34f2011-09-20 05:39:2695#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:3296#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:2197#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:3298#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
99#elif defined(OS_MACOSX)
100#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32101#endif
102
[email protected]37a72af2011-06-13 05:42:01103#if defined(USE_NSS)
104#include "chrome/browser/ui/crypto_module_password_dialog.h"
105#endif
106
[email protected]b45937e2011-10-07 19:49:17107
108#if defined(USE_AURA) || defined(TOUCH_UI)
109#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
110#elif defined(OS_WIN)
111#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
112#include "content/browser/renderer_host/render_widget_host_view_win.h"
[email protected]c92f4ed2011-10-21 19:50:21113#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17114#include "content/browser/renderer_host/render_widget_host_view_gtk.h"
115#elif defined(OS_MACOSX)
116#include "content/browser/renderer_host/render_widget_host_view_mac.h"
117#endif
118
[email protected]c5dbef02011-05-13 05:06:09119namespace {
120
[email protected]b8148ac2011-07-13 22:03:25121// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42122bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37123 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25124 return false;
125
126 // Special case the new tab page. In older versions of Chrome, the new tab
127 // page was hosted at chrome-internal:<blah>. This might be in people's saved
128 // sessions or bookmarks, so we say any URL with that scheme triggers the new
129 // tab page.
130 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
131 // Rewrite it with the proper new tab URL.
132 *url = GURL(chrome::kChromeUINewTabURL);
133 }
134
135 return true;
136}
137
[email protected]8d3132f62011-10-12 07:13:42138// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
139// below. Extension, and isolated apps require different privileges to be
140// granted to their RenderProcessHosts. This classification allows us to make
141// sure URLs are served by hosts with the right set of privileges.
142enum RenderProcessHostPrivilege {
143 PRIV_NORMAL,
144 PRIV_EXTENSION,
145 PRIV_ISOLATED,
146};
147
148RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
149 const GURL& url,
150 ExtensionService* service) {
151 // Default to a normal renderer cause it is lower privileged. This should only
152 // occur if the URL on a site instance is either malformed, or uninitialized.
153 // If it is malformed, then there is no need for better privileges anyways.
154 // If it is uninitialized, but eventually settles on being an a scheme other
155 // than normal webrenderer, the navigation logic will correct us out of band
156 // anyways.
157 if (!url.is_valid())
158 return PRIV_NORMAL;
159
160 if (url.SchemeIs(chrome::kExtensionScheme)) {
161 const Extension* extension = service->GetExtensionByURL(url);
162 if (extension && extension->is_storage_isolated()) {
163 return PRIV_ISOLATED;
164 }
165
166 return PRIV_EXTENSION;
167 }
168
169 return PRIV_NORMAL;
170}
171
172RenderProcessHostPrivilege GetProcessPrivilege(
173 RenderProcessHost* process_host,
174 ExtensionProcessManager* extension_process_manager) {
[email protected]676f6ab2011-10-19 20:23:21175 if (!extension_process_manager->IsExtensionProcess(process_host->id()))
176 return PRIV_NORMAL;
177
178 std::set<const Extension*> extensions_for_process(
179 extension_process_manager->GetExtensionsForProcess(process_host->id()));
180 for (std::set<const Extension*>::iterator iter =
181 extensions_for_process.begin();
182 iter != extensions_for_process.end(); ++iter) {
183 if ((*iter)->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42184 return PRIV_ISOLATED;
[email protected]8d3132f62011-10-12 07:13:42185 }
186
[email protected]676f6ab2011-10-19 20:23:21187 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42188}
189
[email protected]9dbfff12011-07-01 19:37:07190} // namespace
[email protected]c5dbef02011-05-13 05:06:09191
[email protected]d977f9c2011-03-14 16:10:26192namespace chrome {
193
[email protected]f967b722011-09-07 00:58:04194content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
195 const MainFunctionParams& parameters) {
[email protected]5778d502011-10-13 17:13:21196#if defined(OS_CHROMEOS)
197 return new ChromeBrowserMainPartsChromeos(parameters);
198#elif defined(USE_AURA)
[email protected]199fc7a2011-09-28 22:45:38199 return new ChromeBrowserMainPartsAura(parameters);
200#elif defined(OS_WIN)
[email protected]e6b5bc22011-09-08 22:01:56201 return new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04202#elif defined(OS_MACOSX)
[email protected]46c83b62011-09-08 22:09:04203 return new ChromeBrowserMainPartsMac(parameters);
[email protected]c92f4ed2011-10-21 19:50:21204#elif defined(TOOLKIT_USES_GTK)
[email protected]e6b5bc22011-09-08 22:01:56205 return new ChromeBrowserMainPartsGtk(parameters);
[email protected]f967b722011-09-07 00:58:04206#else
207 return NULL;
208#endif
209}
210
[email protected]b45937e2011-10-07 19:49:17211RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
212 RenderWidgetHost* widget) {
213#if defined(USE_AURA) || defined(TOUCH_UI)
214 return new RenderWidgetHostViewViews(widget);
215#elif defined(OS_WIN)
216 if (views::Widget::IsPureViews())
217 return new RenderWidgetHostViewViews(widget);
218 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21219#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17220 return new RenderWidgetHostViewGtk(widget);
221#elif defined(OS_MACOSX)
222 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
223#else
224#error Need to create your platform ViewForWidget here.
225#endif
226}
227
[email protected]74313b42011-08-24 16:51:32228TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
229 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26230#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32231 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21232#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32233 return new TabContentsViewGtk(tab_contents);
234#elif defined(OS_MACOSX)
235 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32236#else
237#error Need to create your platform TabContentsView here.
238#endif
239}
240
[email protected]f364d1392011-04-08 21:03:10241void ChromeContentBrowserClient::RenderViewHostCreated(
242 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46243
244 SiteInstance* site_instance = render_view_host->site_instance();
245 Profile* profile = Profile::FromBrowserContext(
246 site_instance->browsing_instance()->browser_context());
247
248 new ChromeRenderViewHostObserver(render_view_host,
249 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10250 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26251}
252
[email protected]05fcf982011-04-19 00:44:14253void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
254 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02255 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37256 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14257 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02258 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14259 host->channel()->AddFilter(new PrintingMessageFilter());
260 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02261 new SearchProviderInstallStateMessageFilter(id, profile));
262 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03263 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
264 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38265
[email protected]2ccf45c2011-08-19 23:35:50266 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
267 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07268
269 SendExtensionWebRequestStatusToHost(host);
[email protected]05fcf982011-04-19 00:44:14270}
271
[email protected]97e6c4c2011-05-18 16:08:51272void ChromeContentBrowserClient::PluginProcessHostCreated(
273 PluginProcessHost* host) {
274 host->AddFilter(new ChromePluginMessageFilter(host));
275}
276
[email protected]5327dfb2011-05-03 17:50:36277void ChromeContentBrowserClient::WorkerProcessHostCreated(
278 WorkerProcessHost* host) {
279 host->AddFilter(new ChromeWorkerMessageFilter(host));
280}
281
[email protected]1fd1a502011-03-30 16:55:56282content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
283 return ChromeWebUIFactory::GetInstance();
284}
285
[email protected]3d7474ff2011-07-27 17:47:37286GURL ChromeContentBrowserClient::GetEffectiveURL(
287 content::BrowserContext* browser_context, const GURL& url) {
288 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08289 // Get the effective URL for the given actual URL. If the URL is part of an
290 // installed app, the effective URL is an extension URL with the ID of that
291 // extension as the host. This has the effect of grouping apps together in
292 // a common SiteInstance.
293 if (!profile || !profile->GetExtensionService())
294 return url;
295
296 const Extension* extension =
297 profile->GetExtensionService()->GetExtensionByWebExtent(url);
298 if (!extension)
299 return url;
300
301 // If the URL is part of an extension's web extent, convert it to an
302 // extension URL.
303 return extension->GetResourceURL(url.path());
304}
305
[email protected]056ad2a2011-07-12 02:13:55306bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37307 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55308 // Non-extension URLs should generally use process-per-site-instance.
309 // Because we expect to use the effective URL, hosted apps URLs should have
310 // an extension scheme by now.
311 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
312 return false;
313
[email protected]3d7474ff2011-07-27 17:47:37314 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55315 if (!profile || !profile->GetExtensionService())
316 return false;
317
318 const Extension* extension =
319 profile->GetExtensionService()->GetExtensionByURL(effective_url);
320 if (!extension)
321 return false;
322
323 // If the URL is part of a hosted app that does not have the background
324 // permission, we want to give each instance its own process to improve
325 // responsiveness.
326 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
327 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
328 return false;
329
330 // Hosted apps that have the background permission must use process per site,
331 // since all instances can make synchronous calls to the background window.
332 // Other extensions should use process per site as well.
333 return true;
334}
335
[email protected]0f012df82011-05-19 14:15:29336bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03337 return url == GURL(chrome::kChromeUICrashURL) ||
338 url == GURL(chrome::kChromeUIKillURL) ||
339 url == GURL(chrome::kChromeUIHangURL) ||
340 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29341}
342
[email protected]2a5221b2011-09-27 23:07:31343bool ChromeContentBrowserClient::IsSuitableHost(
344 RenderProcessHost* process_host,
345 const GURL& site_url) {
346 Profile* profile =
347 Profile::FromBrowserContext(process_host->browser_context());
348 ExtensionProcessManager* extension_process_manager =
349 profile->GetExtensionProcessManager();
[email protected]8d3132f62011-10-12 07:13:42350 ExtensionService* service = profile->GetExtensionService();
[email protected]2a5221b2011-09-27 23:07:31351
[email protected]8d3132f62011-10-12 07:13:42352 // These may be NULL during tests. In that case, just assume any site can
353 // share any host.
354 if (!extension_process_manager || !service)
[email protected]2a5221b2011-09-27 23:07:31355 return true;
356
[email protected]8d3132f62011-10-12 07:13:42357 return GetProcessPrivilege(process_host, extension_process_manager) ==
358 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]2a5221b2011-09-27 23:07:31359}
360
[email protected]e3daf3c2011-10-05 21:17:08361bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
362 const GURL& current_url,
363 const GURL& new_url) {
364 if (current_url.is_empty()) {
365 // Always choose a new process when navigating to extension URLs. The
366 // process grouping logic will combine all of a given extension's pages
367 // into the same process.
368 if (new_url.SchemeIs(chrome::kExtensionScheme))
369 return true;
370
371 return false;
372 }
373
374 // Also, we must switch if one is an extension and the other is not the exact
375 // same extension.
376 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
377 new_url.SchemeIs(chrome::kExtensionScheme)) {
378 if (current_url.GetOrigin() != new_url.GetOrigin())
379 return true;
380 }
381
382 return false;
383}
384
[email protected]763ec4ca2011-04-29 15:48:12385std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
386 const std::string& alias_name) {
387 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
388}
389
[email protected]b80f68432011-05-02 17:22:30390void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
391 CommandLine* command_line, int child_process_id) {
392#if defined(USE_LINUX_BREAKPAD)
393 if (IsCrashReporterEnabled()) {
394 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
395 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
396 }
397#elif defined(OS_MACOSX)
398 if (IsCrashReporterEnabled()) {
399 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
400 child_process_logging::GetClientId());
401 }
402#endif // OS_MACOSX
403
[email protected]f1933792011-06-14 00:49:34404 if (logging::DialogsAreSuppressed())
405 command_line->AppendSwitch(switches::kNoErrorDialogs);
406
[email protected]b80f68432011-05-02 17:22:30407 std::string process_type =
408 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17409 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52410 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30411 FilePath user_data_dir =
412 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
413 if (!user_data_dir.empty())
414 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
415#if defined(OS_CHROMEOS)
416 const std::string& login_profile =
417 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
418 if (!login_profile.empty())
419 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
420#endif
421
422 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
423
[email protected]3d7474ff2011-07-27 17:47:37424 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]718eab62011-10-05 21:16:52425
426 ExtensionProcessManager* extension_process_manager =
427 profile->GetExtensionProcessManager();
428 if (extension_process_manager->IsExtensionProcess(
429 process->id())) {
430 command_line->AppendSwitch(switches::kExtensionProcess);
431 }
432
[email protected]3d7474ff2011-07-27 17:47:37433 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30434 // Currently this pref is only registered if applied via a policy.
435 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
436 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
437 // Turn this policy into a command line switch.
438 command_line->AppendSwitch(switches::kDisable3DAPIs);
439 }
440
441 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46442 // in the Profile preferences or the browser process.
443 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
444 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30445 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46446 }
[email protected]4287a3d2011-06-13 23:56:51447
448 static const char* const kSwitchNames[] = {
449 switches::kAllowHTTPBackgroundPage,
450 switches::kAllowScriptingGallery,
451 switches::kAppsCheckoutURL,
452 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31453 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51454 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51455 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51456 switches::kDomAutomationController,
457 switches::kDumpHistogramsOnExit,
458 switches::kEnableClickToPlay,
459 switches::kEnableCrxlessWebApps,
460 switches::kEnableExperimentalExtensionApis,
461 switches::kEnableInBrowserThumbnailing,
462 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12463 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51464 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24465 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51466 switches::kEnableSearchProviderApiV2,
467 switches::kEnableWatchdog,
468 switches::kExperimentalSpellcheckerFeatures,
469 switches::kMemoryProfiling,
470 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04471 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51472 switches::kPpapiFlashArgs,
473 switches::kPpapiFlashInProcess,
474 switches::kPpapiFlashPath,
475 switches::kPpapiFlashVersion,
476 switches::kProfilingAtStart,
477 switches::kProfilingFile,
478 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51479 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03480 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51481 };
482
483 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
484 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17485 } else if (process_type == switches::kUtilityProcess) {
486 if (browser_command_line.HasSwitch(
487 switches::kEnableExperimentalExtensionApis)) {
488 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
489 }
[email protected]4287a3d2011-06-13 23:56:51490 } else if (process_type == switches::kPluginProcess) {
491 static const char* const kSwitchNames[] = {
492 #if defined(OS_CHROMEOS)
493 switches::kLoginProfile,
494 #endif
495 switches::kMemoryProfiling,
496 switches::kSilentDumpOnDCHECK,
497 switches::kUserDataDir,
498 };
499
500 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
501 arraysize(kSwitchNames));
502 } else if (process_type == switches::kZygoteProcess) {
503 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51504 switches::kUserDataDir, // Make logs go to the right file.
505 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
506 switches::kPpapiFlashInProcess,
507 switches::kPpapiFlashPath,
508 switches::kPpapiFlashVersion,
509 };
510
511 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
512 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30513 }
[email protected]6f08af82011-09-15 01:19:03514
515 // The command line switch kEnableBenchmarking needs to be specified along
516 // with the kEnableStatsTable switch to ensure that the stats table global
517 // is initialized correctly.
518 if (command_line->HasSwitch(switches::kEnableBenchmarking))
519 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30520}
521
522std::string ChromeContentBrowserClient::GetApplicationLocale() {
523 return g_browser_process->GetApplicationLocale();
524}
525
[email protected]b5cca982011-05-26 04:42:08526std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37527 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
528 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08529}
530
[email protected]ac55e292011-06-24 05:16:08531SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
532 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
[email protected]2cc6a9292011-10-13 21:41:01533#if defined(TOUCH_UI)
534 // In touch builds, we want large default favicons for the tabstrip, but in
535 // other places (such as bookmark, manage search engines, homepage) we assume
536 // default favicons are 16x16.
537 return rb.GetBitmapNamed(IDR_DEFAULT_LARGE_FAVICON);
538#else
[email protected]ac55e292011-06-24 05:16:08539 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
[email protected]2cc6a9292011-10-13 21:41:01540#endif
[email protected]ac55e292011-06-24 05:16:08541}
542
[email protected]a2176792011-05-08 19:30:49543bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09544 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19545 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09546 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
548 ProfileIOData* io_data =
549 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]efa55212011-05-13 16:19:38550 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]0a608842011-09-08 10:55:19551 GetCookieContentSetting(manifest_url, first_party, true);
[email protected]a2176792011-05-08 19:30:49552 DCHECK(setting != CONTENT_SETTING_DEFAULT);
553 return setting != CONTENT_SETTING_BLOCK;
554}
555
[email protected]ed24fad2011-05-10 22:44:01556bool ChromeContentBrowserClient::AllowGetCookie(
557 const GURL& url,
558 const GURL& first_party,
559 const net::CookieList& cookie_list,
560 const content::ResourceContext& context,
561 int render_process_id,
562 int render_view_id) {
563 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32564 ProfileIOData* io_data =
565 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09566 ContentSetting setting = io_data->GetHostContentSettingsMap()->
567 GetCookieContentSetting(url, first_party, false);
568 bool allow = setting == CONTENT_SETTING_ALLOW ||
569 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01570
[email protected]8093a542011-05-13 07:29:32571 BrowserThread::PostTask(
572 BrowserThread::UI, FROM_HERE,
573 NewRunnableFunction(
574 &TabSpecificContentSettings::CookiesRead,
575 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01576 return allow;
577}
578
579bool ChromeContentBrowserClient::AllowSetCookie(
580 const GURL& url,
581 const GURL& first_party,
582 const std::string& cookie_line,
583 const content::ResourceContext& context,
584 int render_process_id,
585 int render_view_id,
586 net::CookieOptions* options) {
587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32588 ProfileIOData* io_data =
589 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09590 ContentSetting setting = io_data->GetHostContentSettingsMap()->
591 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01592
[email protected]5b52ad42011-05-26 14:26:09593 if (setting == CONTENT_SETTING_SESSION_ONLY)
594 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01595
[email protected]5b52ad42011-05-26 14:26:09596 bool allow = setting == CONTENT_SETTING_ALLOW ||
597 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01598
[email protected]8093a542011-05-13 07:29:32599 BrowserThread::PostTask(
600 BrowserThread::UI, FROM_HERE,
601 NewRunnableFunction(
602 &TabSpecificContentSettings::CookieChanged,
603 render_process_id, render_view_id, url, cookie_line, *options,
604 !allow));
[email protected]ed24fad2011-05-10 22:44:01605 return allow;
606}
607
[email protected]d5a19162011-06-30 18:51:54608bool ChromeContentBrowserClient::AllowSaveLocalState(
609 const content::ResourceContext& context) {
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
611 ProfileIOData* io_data =
612 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
613 return !io_data->clear_local_state_on_exit()->GetValue();
614}
615
[email protected]6133f922011-07-01 21:34:34616net::URLRequestContext*
617ChromeContentBrowserClient::OverrideRequestContextForURL(
618 const GURL& url, const content::ResourceContext& context) {
619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
620 if (url.SchemeIs(chrome::kExtensionScheme)) {
621 ProfileIOData* io_data =
622 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
623 return io_data->extensions_request_context();
624 }
625
626 return NULL;
627}
628
[email protected]317f96c92011-05-31 06:53:41629QuotaPermissionContext*
630ChromeContentBrowserClient::CreateQuotaPermissionContext() {
631 return new ChromeQuotaPermissionContext();
632}
633
[email protected]a0ce3282011-08-19 20:49:52634void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42635 // On Mac, this call needs to be done on the UI thread. On other platforms,
636 // do it on the FILE thread so we don't slow down UI.
637#if defined(OS_MACOSX)
638 platform_util::OpenItem(path);
639#else
640 BrowserThread::PostTask(
641 BrowserThread::FILE, FROM_HERE,
642 NewRunnableFunction(&platform_util::OpenItem, path));
643#endif
644}
645
[email protected]a0ce3282011-08-19 20:49:52646void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
647#if defined(OS_MACOSX)
648 // Mac needs to run this operation on the UI thread.
649 platform_util::ShowItemInFolder(path);
650#else
651 BrowserThread::PostTask(
652 BrowserThread::FILE, FROM_HERE,
653 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
654#endif
655}
656
[email protected]848dd042011-06-04 18:24:03657void ChromeContentBrowserClient::AllowCertificateError(
658 SSLCertErrorHandler* handler,
659 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58660 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41661 // If the tab is being prerendered, cancel the prerender and the request.
662 TabContents* tab = tab_util::GetTabContentsByID(
663 handler->render_process_host_id(),
664 handler->tab_contents_id());
665 if (!tab) {
666 NOTREACHED();
667 return;
668 }
669 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50670 prerender::PrerenderManagerFactory::GetForProfile(
671 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41672 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
673 if (prerender_manager->prerender_tracker()->TryCancel(
674 handler->render_process_host_id(),
675 handler->tab_contents_id(),
676 prerender::FINAL_STATUS_SSL_ERROR)) {
677 handler->CancelRequest();
678 return;
679 }
680 }
681
682 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03683 SSLBlockingPage* blocking_page = new SSLBlockingPage(
684 handler, overridable, callback);
685 blocking_page->Show();
686}
687
[email protected]c99c442e2011-08-24 11:37:30688void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45689 int render_process_id,
690 int render_view_id,
691 SSLClientAuthHandler* handler) {
692 TabContents* tab = tab_util::GetTabContentsByID(
693 render_process_id, render_view_id);
694 if (!tab) {
695 NOTREACHED();
696 return;
697 }
698
699 TabContentsWrapper* wrapper =
700 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30701 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45702}
703
704void ChromeContentBrowserClient::AddNewCertificate(
705 net::URLRequest* request,
706 net::X509Certificate* cert,
707 int render_process_id,
708 int render_view_id) {
709 // The handler will run the UI and delete itself when it's finished.
710 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
711}
712
[email protected]941623e2011-06-07 23:06:04713void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
714 const GURL& source_origin,
715 int callback_context,
716 int render_process_id,
717 int render_view_id) {
718 RenderViewHost* rvh = RenderViewHost::FromID(
719 render_process_id, render_view_id);
720 if (!rvh) {
721 NOTREACHED();
722 return;
723 }
724
725 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37726 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04727 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37728 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04729 service->RequestPermission(
730 source_origin, render_process_id, render_view_id, callback_context,
731 tab_util::GetTabContentsByID(render_process_id, render_view_id));
732}
733
734WebKit::WebNotificationPresenter::Permission
735 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
736 const GURL& source_url,
737 const content::ResourceContext& context) {
738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
739 ProfileIOData* io_data =
740 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
741
742 const Extension* extension =
743 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
744 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52745 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04746 return WebKit::WebNotificationPresenter::PermissionAllowed;
747 }
748
749 // Fall back to the regular notification preferences, which works on an
750 // origin basis.
751 return io_data->GetNotificationService() ?
752 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
753 WebKit::WebNotificationPresenter::PermissionNotAllowed;
754}
755
756void ChromeContentBrowserClient::ShowDesktopNotification(
757 const DesktopNotificationHostMsg_Show_Params& params,
758 int render_process_id,
759 int render_view_id,
760 bool worker) {
761 RenderViewHost* rvh = RenderViewHost::FromID(
762 render_process_id, render_view_id);
763 if (!rvh) {
764 NOTREACHED();
765 return;
766 }
767
768 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37769 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04770 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37771 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04772 service->ShowDesktopNotification(
773 params, render_process_id, render_view_id,
774 worker ? DesktopNotificationService::WorkerNotification :
775 DesktopNotificationService::PageNotification);
776}
777
778void ChromeContentBrowserClient::CancelDesktopNotification(
779 int render_process_id,
780 int render_view_id,
781 int notification_id) {
782 RenderViewHost* rvh = RenderViewHost::FromID(
783 render_process_id, render_view_id);
784 if (!rvh) {
785 NOTREACHED();
786 return;
787 }
788
789 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37790 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04791 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37792 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04793 service->CancelDesktopNotification(
794 render_process_id, render_view_id, notification_id);
795}
796
[email protected]9f3fba52011-06-08 20:37:19797bool ChromeContentBrowserClient::CanCreateWindow(
798 const GURL& source_url,
799 WindowContainerType container_type,
800 const content::ResourceContext& context) {
801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
802 // If the opener is trying to create a background window but doesn't have
803 // the appropriate permission, fail the attempt.
804 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
805 ProfileIOData* io_data =
806 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
807 const Extension* extension =
808 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
809 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52810 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19811 }
812 return true;
813}
814
815std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
816 const GURL& url, const content::ResourceContext& context) {
817 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
818 // Check if it's an extension-created worker, in which case we want to use
819 // the name of the extension.
820 ProfileIOData* io_data =
821 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
822 const Extension* extension =
823 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
824 return extension ? extension->name() : std::string();
825}
826
[email protected]3cb054e62011-06-13 05:21:17827ResourceDispatcherHost*
828 ChromeContentBrowserClient::GetResourceDispatcherHost() {
829 return g_browser_process->resource_dispatcher_host();
830}
831
832ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
833 return g_browser_process->clipboard();
834}
835
[email protected]8f6a3b852011-07-19 16:48:56836MHTMLGenerationManager*
837 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
838 return g_browser_process->mhtml_generation_manager();
839}
840
[email protected]dce502762011-07-20 08:53:49841DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
842 return g_browser_process->devtools_manager();
843}
844
[email protected]ae6e9912011-07-27 01:18:28845net::NetLog* ChromeContentBrowserClient::GetNetLog() {
846 return g_browser_process->net_log();
847}
848
[email protected]3bc0b562011-08-24 23:51:04849speech_input::SpeechInputManager*
850 ChromeContentBrowserClient::GetSpeechInputManager() {
851 return speech_input::ChromeSpeechInputManager::GetInstance();
852}
853
[email protected]32538d92011-08-25 00:09:23854AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
855 return new ChromeAccessTokenStore();
856}
857
[email protected]dbae6b02011-06-29 23:51:41858bool ChromeContentBrowserClient::IsFastShutdownPossible() {
859 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
860 return !browser_command_line.HasSwitch(switches::kChromeFrame);
861}
862
[email protected]3d7474ff2011-07-27 17:47:37863WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
864 content::BrowserContext* browser_context, bool is_web_ui) {
865 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
866 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36867}
868
869void ChromeContentBrowserClient::UpdateInspectorSetting(
870 RenderViewHost* rvh, const std::string& key, const std::string& value) {
871 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37872 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36873}
874
875void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
876 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37877 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36878}
879
[email protected]b8148ac2011-07-13 22:03:25880void ChromeContentBrowserClient::BrowserURLHandlerCreated(
881 BrowserURLHandler* handler) {
882 // Add the default URL handlers.
883 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
884 BrowserURLHandler::null_handler());
885 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
886 &ExtensionWebUI::HandleChromeURLOverrideReverse);
887
888 // about:
889 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
890 BrowserURLHandler::null_handler());
891 // chrome: & friends.
892 handler->AddHandlerPair(&HandleWebUI,
893 BrowserURLHandler::null_handler());
894}
895
896void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37897 Profile* profile = Profile::FromBrowserContext(
898 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25899 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
900 BrowsingDataRemover::EVERYTHING,
901 base::Time());
902 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
903 // BrowsingDataRemover takes care of deleting itself when done.
904}
905
906void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37907 Profile* profile = Profile::FromBrowserContext(
908 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25909 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
910 BrowsingDataRemover::EVERYTHING,
911 base::Time());
[email protected]dceaa912011-09-06 17:17:23912 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25913 remover->Remove(remove_mask);
914 // BrowsingDataRemover takes care of deleting itself when done.
915}
916
[email protected]e1d16eb92011-08-18 23:19:32917FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
918 return download_util::GetDefaultDownloadDirectory();
919}
920
[email protected]c9b6eb62011-10-18 20:49:39921std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
922 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
923}
924
[email protected]b80f68432011-05-02 17:22:30925#if defined(OS_LINUX)
926int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:52927 const CommandLine& command_line) {
928 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:07929 ExtensionCrashHandlerHostLinux* crash_handler =
930 ExtensionCrashHandlerHostLinux::GetInstance();
931 return crash_handler->GetDeathSignalSocket();
932 }
933
[email protected]718eab62011-10-05 21:16:52934 std::string process_type =
935 command_line.GetSwitchValueASCII(switches::kProcessType);
936
937 if (process_type == switches::kRendererProcess)
938 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
939
[email protected]b80f68432011-05-02 17:22:30940 if (process_type == switches::kPluginProcess)
941 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
942
943 if (process_type == switches::kPpapiPluginProcess)
944 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
945
946 if (process_type == switches::kGpuProcess)
947 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
948
949 return -1;
950}
[email protected]9dbfff12011-07-01 19:37:07951#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30952
[email protected]4a65826d2011-08-25 16:04:01953#if defined(OS_WIN)
954const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
955 return chrome::kBrowserResourcesDll;
956}
957#endif
958
[email protected]37a72af2011-06-13 05:42:01959#if defined(USE_NSS)
960crypto::CryptoModuleBlockingPasswordDelegate*
961 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
962 const GURL& url) {
963 return browser::NewCryptoModuleBlockingDialogDelegate(
964 browser::kCryptoModulePasswordKeygen, url.host());
965}
966#endif
967
[email protected]d977f9c2011-03-14 16:10:26968} // namespace chrome