blob: cd84fd2ae9d09aab250859e1c97adf1dd98f7761 [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]b48c9182011-10-26 18:03:3071#include "content/public/browser/browser_main_parts.h"
[email protected]c9b6eb62011-10-18 20:49:3972#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3473#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0174#include "net/base/cookie_monster.h"
75#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3976#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0877#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2678
[email protected]b48c9182011-10-26 18:03:3079#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3880#include "chrome/browser/chrome_browser_main_win.h"
81#elif defined(OS_MACOSX)
82#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:3083#elif defined(OS_CHROMEOS)
84#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
85#elif defined(OS_LINUX)
86#include "chrome/browser/chrome_browser_main_linux.h"
87#elif defined(OS_POSIX)
88#include "chrome/browser/chrome_browser_main_posix.h"
89#endif
90
91#if defined(USE_AURA)
92#include "chrome/browser/chrome_browser_parts_aura.h"
93#endif
94
95#if defined(TOOLKIT_USES_GTK)
96#include "chrome/browser/chrome_browser_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:3897#endif
98
[email protected]b80f68432011-05-02 17:22:3099#if defined(OS_LINUX)
100#include "base/linux_util.h"
101#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43102#endif
[email protected]b80f68432011-05-02 17:22:30103
[email protected]080f34f2011-09-20 05:39:26104#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32105#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21106#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32107#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
108#elif defined(OS_MACOSX)
109#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32110#endif
111
[email protected]37a72af2011-06-13 05:42:01112#if defined(USE_NSS)
113#include "chrome/browser/ui/crypto_module_password_dialog.h"
114#endif
115
[email protected]91ad1472011-10-27 15:09:48116#if defined(USE_AURA)
117#include "content/browser/renderer_host/render_widget_host_view_aura.h"
118#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17119#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
120#elif defined(OS_WIN)
121#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
122#include "content/browser/renderer_host/render_widget_host_view_win.h"
[email protected]c92f4ed2011-10-21 19:50:21123#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17124#include "content/browser/renderer_host/render_widget_host_view_gtk.h"
125#elif defined(OS_MACOSX)
126#include "content/browser/renderer_host/render_widget_host_view_mac.h"
127#endif
128
[email protected]c5dbef02011-05-13 05:06:09129namespace {
130
[email protected]b8148ac2011-07-13 22:03:25131// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42132bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37133 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25134 return false;
135
136 // Special case the new tab page. In older versions of Chrome, the new tab
137 // page was hosted at chrome-internal:<blah>. This might be in people's saved
138 // sessions or bookmarks, so we say any URL with that scheme triggers the new
139 // tab page.
140 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
141 // Rewrite it with the proper new tab URL.
142 *url = GURL(chrome::kChromeUINewTabURL);
143 }
144
145 return true;
146}
147
[email protected]8d3132f62011-10-12 07:13:42148// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
149// below. Extension, and isolated apps require different privileges to be
150// granted to their RenderProcessHosts. This classification allows us to make
151// sure URLs are served by hosts with the right set of privileges.
152enum RenderProcessHostPrivilege {
153 PRIV_NORMAL,
154 PRIV_EXTENSION,
155 PRIV_ISOLATED,
156};
157
158RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
159 const GURL& url,
160 ExtensionService* service) {
161 // Default to a normal renderer cause it is lower privileged. This should only
162 // occur if the URL on a site instance is either malformed, or uninitialized.
163 // If it is malformed, then there is no need for better privileges anyways.
164 // If it is uninitialized, but eventually settles on being an a scheme other
165 // than normal webrenderer, the navigation logic will correct us out of band
166 // anyways.
167 if (!url.is_valid())
168 return PRIV_NORMAL;
169
170 if (url.SchemeIs(chrome::kExtensionScheme)) {
171 const Extension* extension = service->GetExtensionByURL(url);
172 if (extension && extension->is_storage_isolated()) {
173 return PRIV_ISOLATED;
174 }
175
176 return PRIV_EXTENSION;
177 }
178
179 return PRIV_NORMAL;
180}
181
182RenderProcessHostPrivilege GetProcessPrivilege(
183 RenderProcessHost* process_host,
184 ExtensionProcessManager* extension_process_manager) {
[email protected]676f6ab2011-10-19 20:23:21185 if (!extension_process_manager->IsExtensionProcess(process_host->id()))
186 return PRIV_NORMAL;
187
188 std::set<const Extension*> extensions_for_process(
189 extension_process_manager->GetExtensionsForProcess(process_host->id()));
190 for (std::set<const Extension*>::iterator iter =
191 extensions_for_process.begin();
192 iter != extensions_for_process.end(); ++iter) {
193 if ((*iter)->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42194 return PRIV_ISOLATED;
[email protected]8d3132f62011-10-12 07:13:42195 }
196
[email protected]676f6ab2011-10-19 20:23:21197 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42198}
199
[email protected]9dbfff12011-07-01 19:37:07200} // namespace
[email protected]c5dbef02011-05-13 05:06:09201
[email protected]d977f9c2011-03-14 16:10:26202namespace chrome {
203
[email protected]b48c9182011-10-26 18:03:30204void ChromeContentBrowserClient::CreateBrowserMainParts(
205 const MainFunctionParams& parameters,
206 std::vector<content::BrowserMainParts*>* parts_list) {
207 // Construct the Main browser parts based on the OS type.
208#if defined(OS_WIN)
209 parts_list->push_back(new ChromeBrowserMainPartsWin(parameters));
[email protected]f967b722011-09-07 00:58:04210#elif defined(OS_MACOSX)
[email protected]b48c9182011-10-26 18:03:30211 parts_list->push_back(new ChromeBrowserMainPartsMac(parameters));
212#elif defined(OS_CHROMEOS)
213 parts_list->push_back(new ChromeBrowserMainPartsChromeos(parameters));
214#elif defined(OS_LINUX)
215 parts_list->push_back(new ChromeBrowserMainPartsLinux(parameters));
216#elif defined(OS_POSIX)
217 parts_list->push_back(new ChromeBrowserMainPartsPosix(parameters));
[email protected]f967b722011-09-07 00:58:04218#else
[email protected]b48c9182011-10-26 18:03:30219 NOTREACHED();
220 parts_list->push_back(new ChromeBrowserMainParts(parameters));
221#endif
222
223 // Construct additional browser parts.
224#if defined(USE_AURA)
225 parts_list->push_back(new ChromeBrowserPartsAura());
226#endif
227#if defined(TOOLKIT_USES_GTK)
228 parts_list->push_back(new ChromeBrowserPartsGtk());
[email protected]f967b722011-09-07 00:58:04229#endif
230}
231
[email protected]b45937e2011-10-07 19:49:17232RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
233 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48234#if defined(USE_AURA)
235 return new RenderWidgetHostViewAura(widget);
236#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17237 return new RenderWidgetHostViewViews(widget);
238#elif defined(OS_WIN)
239 if (views::Widget::IsPureViews())
240 return new RenderWidgetHostViewViews(widget);
241 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21242#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17243 return new RenderWidgetHostViewGtk(widget);
244#elif defined(OS_MACOSX)
245 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
246#else
247#error Need to create your platform ViewForWidget here.
248#endif
249}
250
[email protected]74313b42011-08-24 16:51:32251TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
252 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26253#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32254 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21255#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32256 return new TabContentsViewGtk(tab_contents);
257#elif defined(OS_MACOSX)
258 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32259#else
260#error Need to create your platform TabContentsView here.
261#endif
262}
263
[email protected]f364d1392011-04-08 21:03:10264void ChromeContentBrowserClient::RenderViewHostCreated(
265 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46266
267 SiteInstance* site_instance = render_view_host->site_instance();
268 Profile* profile = Profile::FromBrowserContext(
269 site_instance->browsing_instance()->browser_context());
270
271 new ChromeRenderViewHostObserver(render_view_host,
272 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10273 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26274}
275
[email protected]05fcf982011-04-19 00:44:14276void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
277 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02278 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37279 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14280 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02281 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14282 host->channel()->AddFilter(new PrintingMessageFilter());
283 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02284 new SearchProviderInstallStateMessageFilter(id, profile));
285 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03286 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
287 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38288
[email protected]2ccf45c2011-08-19 23:35:50289 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
290 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07291
292 SendExtensionWebRequestStatusToHost(host);
[email protected]c14406092011-10-27 13:43:42293 ContentSettingsForOneType settings;
294 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
295 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &settings);
296 host->Send(new ChromeViewMsg_SetImageSettingRules(settings));
[email protected]05fcf982011-04-19 00:44:14297}
298
[email protected]97e6c4c2011-05-18 16:08:51299void ChromeContentBrowserClient::PluginProcessHostCreated(
300 PluginProcessHost* host) {
301 host->AddFilter(new ChromePluginMessageFilter(host));
302}
303
[email protected]5327dfb2011-05-03 17:50:36304void ChromeContentBrowserClient::WorkerProcessHostCreated(
305 WorkerProcessHost* host) {
306 host->AddFilter(new ChromeWorkerMessageFilter(host));
307}
308
[email protected]1fd1a502011-03-30 16:55:56309content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
310 return ChromeWebUIFactory::GetInstance();
311}
312
[email protected]3d7474ff2011-07-27 17:47:37313GURL ChromeContentBrowserClient::GetEffectiveURL(
314 content::BrowserContext* browser_context, const GURL& url) {
315 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08316 // Get the effective URL for the given actual URL. If the URL is part of an
317 // installed app, the effective URL is an extension URL with the ID of that
318 // extension as the host. This has the effect of grouping apps together in
319 // a common SiteInstance.
320 if (!profile || !profile->GetExtensionService())
321 return url;
322
323 const Extension* extension =
324 profile->GetExtensionService()->GetExtensionByWebExtent(url);
325 if (!extension)
326 return url;
327
328 // If the URL is part of an extension's web extent, convert it to an
329 // extension URL.
330 return extension->GetResourceURL(url.path());
331}
332
[email protected]056ad2a2011-07-12 02:13:55333bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37334 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55335 // Non-extension URLs should generally use process-per-site-instance.
336 // Because we expect to use the effective URL, hosted apps URLs should have
337 // an extension scheme by now.
338 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
339 return false;
340
[email protected]3d7474ff2011-07-27 17:47:37341 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55342 if (!profile || !profile->GetExtensionService())
343 return false;
344
345 const Extension* extension =
346 profile->GetExtensionService()->GetExtensionByURL(effective_url);
347 if (!extension)
348 return false;
349
350 // If the URL is part of a hosted app that does not have the background
351 // permission, we want to give each instance its own process to improve
352 // responsiveness.
353 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
354 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
355 return false;
356
357 // Hosted apps that have the background permission must use process per site,
358 // since all instances can make synchronous calls to the background window.
359 // Other extensions should use process per site as well.
360 return true;
361}
362
[email protected]0f012df82011-05-19 14:15:29363bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03364 return url == GURL(chrome::kChromeUICrashURL) ||
365 url == GURL(chrome::kChromeUIKillURL) ||
366 url == GURL(chrome::kChromeUIHangURL) ||
367 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29368}
369
[email protected]2a5221b2011-09-27 23:07:31370bool ChromeContentBrowserClient::IsSuitableHost(
371 RenderProcessHost* process_host,
372 const GURL& site_url) {
373 Profile* profile =
374 Profile::FromBrowserContext(process_host->browser_context());
375 ExtensionProcessManager* extension_process_manager =
376 profile->GetExtensionProcessManager();
[email protected]8d3132f62011-10-12 07:13:42377 ExtensionService* service = profile->GetExtensionService();
[email protected]2a5221b2011-09-27 23:07:31378
[email protected]8d3132f62011-10-12 07:13:42379 // These may be NULL during tests. In that case, just assume any site can
380 // share any host.
381 if (!extension_process_manager || !service)
[email protected]2a5221b2011-09-27 23:07:31382 return true;
383
[email protected]a8c269a2011-10-25 20:17:22384 // Experimental:
385 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
386 // to share a renderer process. (We could allow pages from the same site or
387 // extensions of the same type to share, if we knew what the given process
388 // was dedicated to. Allowing no sharing is simpler for now.) This may
389 // cause resource exhaustion issues if too many sites are open at once.
390 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
391 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
392 return false;
393
[email protected]8d3132f62011-10-12 07:13:42394 return GetProcessPrivilege(process_host, extension_process_manager) ==
395 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]2a5221b2011-09-27 23:07:31396}
397
[email protected]e3daf3c2011-10-05 21:17:08398bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
399 const GURL& current_url,
400 const GURL& new_url) {
401 if (current_url.is_empty()) {
402 // Always choose a new process when navigating to extension URLs. The
403 // process grouping logic will combine all of a given extension's pages
404 // into the same process.
405 if (new_url.SchemeIs(chrome::kExtensionScheme))
406 return true;
407
408 return false;
409 }
410
411 // Also, we must switch if one is an extension and the other is not the exact
412 // same extension.
413 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
414 new_url.SchemeIs(chrome::kExtensionScheme)) {
415 if (current_url.GetOrigin() != new_url.GetOrigin())
416 return true;
417 }
418
419 return false;
420}
421
[email protected]763ec4ca2011-04-29 15:48:12422std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
423 const std::string& alias_name) {
424 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
425}
426
[email protected]b80f68432011-05-02 17:22:30427void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
428 CommandLine* command_line, int child_process_id) {
429#if defined(USE_LINUX_BREAKPAD)
430 if (IsCrashReporterEnabled()) {
431 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
432 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
433 }
434#elif defined(OS_MACOSX)
435 if (IsCrashReporterEnabled()) {
436 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
437 child_process_logging::GetClientId());
438 }
439#endif // OS_MACOSX
440
[email protected]f1933792011-06-14 00:49:34441 if (logging::DialogsAreSuppressed())
442 command_line->AppendSwitch(switches::kNoErrorDialogs);
443
[email protected]b80f68432011-05-02 17:22:30444 std::string process_type =
445 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17446 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52447 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30448 FilePath user_data_dir =
449 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
450 if (!user_data_dir.empty())
451 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
452#if defined(OS_CHROMEOS)
453 const std::string& login_profile =
454 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
455 if (!login_profile.empty())
456 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
457#endif
458
459 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
460
[email protected]3d7474ff2011-07-27 17:47:37461 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]718eab62011-10-05 21:16:52462
463 ExtensionProcessManager* extension_process_manager =
464 profile->GetExtensionProcessManager();
465 if (extension_process_manager->IsExtensionProcess(
466 process->id())) {
467 command_line->AppendSwitch(switches::kExtensionProcess);
468 }
469
[email protected]3d7474ff2011-07-27 17:47:37470 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30471 // Currently this pref is only registered if applied via a policy.
472 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
473 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
474 // Turn this policy into a command line switch.
475 command_line->AppendSwitch(switches::kDisable3DAPIs);
476 }
477
478 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46479 // in the Profile preferences or the browser process.
480 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
481 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30482 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46483 }
[email protected]4287a3d2011-06-13 23:56:51484
485 static const char* const kSwitchNames[] = {
486 switches::kAllowHTTPBackgroundPage,
487 switches::kAllowScriptingGallery,
488 switches::kAppsCheckoutURL,
489 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31490 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51491 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51492 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51493 switches::kDomAutomationController,
494 switches::kDumpHistogramsOnExit,
495 switches::kEnableClickToPlay,
496 switches::kEnableCrxlessWebApps,
497 switches::kEnableExperimentalExtensionApis,
498 switches::kEnableInBrowserThumbnailing,
499 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12500 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51501 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24502 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51503 switches::kEnableSearchProviderApiV2,
504 switches::kEnableWatchdog,
505 switches::kExperimentalSpellcheckerFeatures,
506 switches::kMemoryProfiling,
507 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04508 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51509 switches::kPpapiFlashArgs,
510 switches::kPpapiFlashInProcess,
511 switches::kPpapiFlashPath,
512 switches::kPpapiFlashVersion,
513 switches::kProfilingAtStart,
514 switches::kProfilingFile,
515 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51516 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03517 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51518 };
519
520 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
521 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17522 } else if (process_type == switches::kUtilityProcess) {
523 if (browser_command_line.HasSwitch(
524 switches::kEnableExperimentalExtensionApis)) {
525 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
526 }
[email protected]4287a3d2011-06-13 23:56:51527 } else if (process_type == switches::kPluginProcess) {
528 static const char* const kSwitchNames[] = {
529 #if defined(OS_CHROMEOS)
530 switches::kLoginProfile,
531 #endif
532 switches::kMemoryProfiling,
533 switches::kSilentDumpOnDCHECK,
534 switches::kUserDataDir,
535 };
536
537 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
538 arraysize(kSwitchNames));
539 } else if (process_type == switches::kZygoteProcess) {
540 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51541 switches::kUserDataDir, // Make logs go to the right file.
542 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
543 switches::kPpapiFlashInProcess,
544 switches::kPpapiFlashPath,
545 switches::kPpapiFlashVersion,
546 };
547
548 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
549 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30550 }
[email protected]6f08af82011-09-15 01:19:03551
552 // The command line switch kEnableBenchmarking needs to be specified along
553 // with the kEnableStatsTable switch to ensure that the stats table global
554 // is initialized correctly.
555 if (command_line->HasSwitch(switches::kEnableBenchmarking))
556 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30557}
558
559std::string ChromeContentBrowserClient::GetApplicationLocale() {
560 return g_browser_process->GetApplicationLocale();
561}
562
[email protected]b5cca982011-05-26 04:42:08563std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37564 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
565 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08566}
567
[email protected]ac55e292011-06-24 05:16:08568SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
569 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
[email protected]2cc6a9292011-10-13 21:41:01570#if defined(TOUCH_UI)
571 // In touch builds, we want large default favicons for the tabstrip, but in
572 // other places (such as bookmark, manage search engines, homepage) we assume
573 // default favicons are 16x16.
574 return rb.GetBitmapNamed(IDR_DEFAULT_LARGE_FAVICON);
575#else
[email protected]ac55e292011-06-24 05:16:08576 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
[email protected]2cc6a9292011-10-13 21:41:01577#endif
[email protected]ac55e292011-06-24 05:16:08578}
579
[email protected]a2176792011-05-08 19:30:49580bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09581 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19582 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09583 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
585 ProfileIOData* io_data =
586 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]efa55212011-05-13 16:19:38587 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]0a608842011-09-08 10:55:19588 GetCookieContentSetting(manifest_url, first_party, true);
[email protected]a2176792011-05-08 19:30:49589 DCHECK(setting != CONTENT_SETTING_DEFAULT);
590 return setting != CONTENT_SETTING_BLOCK;
591}
592
[email protected]ed24fad2011-05-10 22:44:01593bool ChromeContentBrowserClient::AllowGetCookie(
594 const GURL& url,
595 const GURL& first_party,
596 const net::CookieList& cookie_list,
597 const content::ResourceContext& context,
598 int render_process_id,
599 int render_view_id) {
600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32601 ProfileIOData* io_data =
602 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09603 ContentSetting setting = io_data->GetHostContentSettingsMap()->
604 GetCookieContentSetting(url, first_party, false);
605 bool allow = setting == CONTENT_SETTING_ALLOW ||
606 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01607
[email protected]8093a542011-05-13 07:29:32608 BrowserThread::PostTask(
609 BrowserThread::UI, FROM_HERE,
610 NewRunnableFunction(
611 &TabSpecificContentSettings::CookiesRead,
612 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01613 return allow;
614}
615
616bool ChromeContentBrowserClient::AllowSetCookie(
617 const GURL& url,
618 const GURL& first_party,
619 const std::string& cookie_line,
620 const content::ResourceContext& context,
621 int render_process_id,
622 int render_view_id,
623 net::CookieOptions* options) {
624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32625 ProfileIOData* io_data =
626 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09627 ContentSetting setting = io_data->GetHostContentSettingsMap()->
628 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01629
[email protected]5b52ad42011-05-26 14:26:09630 if (setting == CONTENT_SETTING_SESSION_ONLY)
631 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01632
[email protected]5b52ad42011-05-26 14:26:09633 bool allow = setting == CONTENT_SETTING_ALLOW ||
634 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01635
[email protected]8093a542011-05-13 07:29:32636 BrowserThread::PostTask(
637 BrowserThread::UI, FROM_HERE,
638 NewRunnableFunction(
639 &TabSpecificContentSettings::CookieChanged,
640 render_process_id, render_view_id, url, cookie_line, *options,
641 !allow));
[email protected]ed24fad2011-05-10 22:44:01642 return allow;
643}
644
[email protected]d5a19162011-06-30 18:51:54645bool ChromeContentBrowserClient::AllowSaveLocalState(
646 const content::ResourceContext& context) {
647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
648 ProfileIOData* io_data =
649 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
650 return !io_data->clear_local_state_on_exit()->GetValue();
651}
652
[email protected]6133f922011-07-01 21:34:34653net::URLRequestContext*
654ChromeContentBrowserClient::OverrideRequestContextForURL(
655 const GURL& url, const content::ResourceContext& context) {
656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
657 if (url.SchemeIs(chrome::kExtensionScheme)) {
658 ProfileIOData* io_data =
659 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
660 return io_data->extensions_request_context();
661 }
662
663 return NULL;
664}
665
[email protected]317f96c92011-05-31 06:53:41666QuotaPermissionContext*
667ChromeContentBrowserClient::CreateQuotaPermissionContext() {
668 return new ChromeQuotaPermissionContext();
669}
670
[email protected]a0ce3282011-08-19 20:49:52671void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42672 // On Mac, this call needs to be done on the UI thread. On other platforms,
673 // do it on the FILE thread so we don't slow down UI.
674#if defined(OS_MACOSX)
675 platform_util::OpenItem(path);
676#else
677 BrowserThread::PostTask(
678 BrowserThread::FILE, FROM_HERE,
679 NewRunnableFunction(&platform_util::OpenItem, path));
680#endif
681}
682
[email protected]a0ce3282011-08-19 20:49:52683void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
684#if defined(OS_MACOSX)
685 // Mac needs to run this operation on the UI thread.
686 platform_util::ShowItemInFolder(path);
687#else
688 BrowserThread::PostTask(
689 BrowserThread::FILE, FROM_HERE,
690 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
691#endif
692}
693
[email protected]848dd042011-06-04 18:24:03694void ChromeContentBrowserClient::AllowCertificateError(
695 SSLCertErrorHandler* handler,
696 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58697 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41698 // If the tab is being prerendered, cancel the prerender and the request.
699 TabContents* tab = tab_util::GetTabContentsByID(
700 handler->render_process_host_id(),
701 handler->tab_contents_id());
702 if (!tab) {
703 NOTREACHED();
704 return;
705 }
706 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50707 prerender::PrerenderManagerFactory::GetForProfile(
708 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41709 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
710 if (prerender_manager->prerender_tracker()->TryCancel(
711 handler->render_process_host_id(),
712 handler->tab_contents_id(),
713 prerender::FINAL_STATUS_SSL_ERROR)) {
714 handler->CancelRequest();
715 return;
716 }
717 }
718
719 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03720 SSLBlockingPage* blocking_page = new SSLBlockingPage(
721 handler, overridable, callback);
722 blocking_page->Show();
723}
724
[email protected]c99c442e2011-08-24 11:37:30725void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45726 int render_process_id,
727 int render_view_id,
728 SSLClientAuthHandler* handler) {
729 TabContents* tab = tab_util::GetTabContentsByID(
730 render_process_id, render_view_id);
731 if (!tab) {
732 NOTREACHED();
733 return;
734 }
735
736 TabContentsWrapper* wrapper =
737 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30738 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45739}
740
741void ChromeContentBrowserClient::AddNewCertificate(
742 net::URLRequest* request,
743 net::X509Certificate* cert,
744 int render_process_id,
745 int render_view_id) {
746 // The handler will run the UI and delete itself when it's finished.
747 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
748}
749
[email protected]941623e2011-06-07 23:06:04750void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
751 const GURL& source_origin,
752 int callback_context,
753 int render_process_id,
754 int render_view_id) {
755 RenderViewHost* rvh = RenderViewHost::FromID(
756 render_process_id, render_view_id);
757 if (!rvh) {
758 NOTREACHED();
759 return;
760 }
761
762 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37763 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04764 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37765 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04766 service->RequestPermission(
767 source_origin, render_process_id, render_view_id, callback_context,
768 tab_util::GetTabContentsByID(render_process_id, render_view_id));
769}
770
771WebKit::WebNotificationPresenter::Permission
772 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
773 const GURL& source_url,
774 const content::ResourceContext& context) {
775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
776 ProfileIOData* io_data =
777 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
778
779 const Extension* extension =
780 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
781 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52782 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04783 return WebKit::WebNotificationPresenter::PermissionAllowed;
784 }
785
786 // Fall back to the regular notification preferences, which works on an
787 // origin basis.
788 return io_data->GetNotificationService() ?
789 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
790 WebKit::WebNotificationPresenter::PermissionNotAllowed;
791}
792
793void ChromeContentBrowserClient::ShowDesktopNotification(
794 const DesktopNotificationHostMsg_Show_Params& params,
795 int render_process_id,
796 int render_view_id,
797 bool worker) {
798 RenderViewHost* rvh = RenderViewHost::FromID(
799 render_process_id, render_view_id);
800 if (!rvh) {
801 NOTREACHED();
802 return;
803 }
804
805 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37806 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04807 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37808 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04809 service->ShowDesktopNotification(
810 params, render_process_id, render_view_id,
811 worker ? DesktopNotificationService::WorkerNotification :
812 DesktopNotificationService::PageNotification);
813}
814
815void ChromeContentBrowserClient::CancelDesktopNotification(
816 int render_process_id,
817 int render_view_id,
818 int notification_id) {
819 RenderViewHost* rvh = RenderViewHost::FromID(
820 render_process_id, render_view_id);
821 if (!rvh) {
822 NOTREACHED();
823 return;
824 }
825
826 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37827 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04828 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37829 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04830 service->CancelDesktopNotification(
831 render_process_id, render_view_id, notification_id);
832}
833
[email protected]9f3fba52011-06-08 20:37:19834bool ChromeContentBrowserClient::CanCreateWindow(
835 const GURL& source_url,
836 WindowContainerType container_type,
837 const content::ResourceContext& context) {
838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
839 // If the opener is trying to create a background window but doesn't have
840 // the appropriate permission, fail the attempt.
841 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
842 ProfileIOData* io_data =
843 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
844 const Extension* extension =
845 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
846 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52847 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19848 }
849 return true;
850}
851
852std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
853 const GURL& url, const content::ResourceContext& context) {
854 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
855 // Check if it's an extension-created worker, in which case we want to use
856 // the name of the extension.
857 ProfileIOData* io_data =
858 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
859 const Extension* extension =
860 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
861 return extension ? extension->name() : std::string();
862}
863
[email protected]3cb054e62011-06-13 05:21:17864ResourceDispatcherHost*
865 ChromeContentBrowserClient::GetResourceDispatcherHost() {
866 return g_browser_process->resource_dispatcher_host();
867}
868
869ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
870 return g_browser_process->clipboard();
871}
872
[email protected]8f6a3b852011-07-19 16:48:56873MHTMLGenerationManager*
874 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
875 return g_browser_process->mhtml_generation_manager();
876}
877
[email protected]dce502762011-07-20 08:53:49878DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
879 return g_browser_process->devtools_manager();
880}
881
[email protected]ae6e9912011-07-27 01:18:28882net::NetLog* ChromeContentBrowserClient::GetNetLog() {
883 return g_browser_process->net_log();
884}
885
[email protected]3bc0b562011-08-24 23:51:04886speech_input::SpeechInputManager*
887 ChromeContentBrowserClient::GetSpeechInputManager() {
888 return speech_input::ChromeSpeechInputManager::GetInstance();
889}
890
[email protected]32538d92011-08-25 00:09:23891AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
892 return new ChromeAccessTokenStore();
893}
894
[email protected]dbae6b02011-06-29 23:51:41895bool ChromeContentBrowserClient::IsFastShutdownPossible() {
896 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
897 return !browser_command_line.HasSwitch(switches::kChromeFrame);
898}
899
[email protected]3d7474ff2011-07-27 17:47:37900WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
901 content::BrowserContext* browser_context, bool is_web_ui) {
902 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
903 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36904}
905
906void ChromeContentBrowserClient::UpdateInspectorSetting(
907 RenderViewHost* rvh, const std::string& key, const std::string& value) {
908 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37909 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36910}
911
912void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
913 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37914 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36915}
916
[email protected]b8148ac2011-07-13 22:03:25917void ChromeContentBrowserClient::BrowserURLHandlerCreated(
918 BrowserURLHandler* handler) {
919 // Add the default URL handlers.
920 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
921 BrowserURLHandler::null_handler());
922 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
923 &ExtensionWebUI::HandleChromeURLOverrideReverse);
924
925 // about:
926 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
927 BrowserURLHandler::null_handler());
928 // chrome: & friends.
929 handler->AddHandlerPair(&HandleWebUI,
930 BrowserURLHandler::null_handler());
931}
932
933void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37934 Profile* profile = Profile::FromBrowserContext(
935 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25936 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
937 BrowsingDataRemover::EVERYTHING,
938 base::Time());
939 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
940 // BrowsingDataRemover takes care of deleting itself when done.
941}
942
943void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37944 Profile* profile = Profile::FromBrowserContext(
945 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25946 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
947 BrowsingDataRemover::EVERYTHING,
948 base::Time());
[email protected]dceaa912011-09-06 17:17:23949 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25950 remover->Remove(remove_mask);
951 // BrowsingDataRemover takes care of deleting itself when done.
952}
953
[email protected]e1d16eb92011-08-18 23:19:32954FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
955 return download_util::GetDefaultDownloadDirectory();
956}
957
[email protected]c9b6eb62011-10-18 20:49:39958std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
959 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
960}
961
[email protected]b80f68432011-05-02 17:22:30962#if defined(OS_LINUX)
963int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:52964 const CommandLine& command_line) {
965 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:07966 ExtensionCrashHandlerHostLinux* crash_handler =
967 ExtensionCrashHandlerHostLinux::GetInstance();
968 return crash_handler->GetDeathSignalSocket();
969 }
970
[email protected]718eab62011-10-05 21:16:52971 std::string process_type =
972 command_line.GetSwitchValueASCII(switches::kProcessType);
973
974 if (process_type == switches::kRendererProcess)
975 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
976
[email protected]b80f68432011-05-02 17:22:30977 if (process_type == switches::kPluginProcess)
978 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
979
980 if (process_type == switches::kPpapiPluginProcess)
981 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
982
983 if (process_type == switches::kGpuProcess)
984 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
985
986 return -1;
987}
[email protected]9dbfff12011-07-01 19:37:07988#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30989
[email protected]4a65826d2011-08-25 16:04:01990#if defined(OS_WIN)
991const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
992 return chrome::kBrowserResourcesDll;
993}
994#endif
995
[email protected]37a72af2011-06-13 05:42:01996#if defined(USE_NSS)
997crypto::CryptoModuleBlockingPasswordDelegate*
998 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
999 const GURL& url) {
1000 return browser::NewCryptoModuleBlockingDialogDelegate(
1001 browser::kCryptoModulePasswordKeygen, url.host());
1002}
1003#endif
1004
[email protected]d977f9c2011-03-14 16:10:261005} // namespace chrome