blob: 6b284064211ea7ef1e28910ebf4716a4ae723774 [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]30fde822011-10-28 09:49:0517#include "chrome/browser/content_settings/cookie_settings.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]631bb742011-11-02 11:29:39129using content::BrowserThread;
130
[email protected]c5dbef02011-05-13 05:06:09131namespace {
132
[email protected]b8148ac2011-07-13 22:03:25133// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42134bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37135 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25136 return false;
137
138 // Special case the new tab page. In older versions of Chrome, the new tab
139 // page was hosted at chrome-internal:<blah>. This might be in people's saved
140 // sessions or bookmarks, so we say any URL with that scheme triggers the new
141 // tab page.
142 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
143 // Rewrite it with the proper new tab URL.
144 *url = GURL(chrome::kChromeUINewTabURL);
145 }
146
147 return true;
148}
149
[email protected]8d3132f62011-10-12 07:13:42150// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
151// below. Extension, and isolated apps require different privileges to be
152// granted to their RenderProcessHosts. This classification allows us to make
153// sure URLs are served by hosts with the right set of privileges.
154enum RenderProcessHostPrivilege {
155 PRIV_NORMAL,
156 PRIV_EXTENSION,
157 PRIV_ISOLATED,
158};
159
160RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
161 const GURL& url,
162 ExtensionService* service) {
163 // Default to a normal renderer cause it is lower privileged. This should only
164 // occur if the URL on a site instance is either malformed, or uninitialized.
165 // If it is malformed, then there is no need for better privileges anyways.
166 // If it is uninitialized, but eventually settles on being an a scheme other
167 // than normal webrenderer, the navigation logic will correct us out of band
168 // anyways.
169 if (!url.is_valid())
170 return PRIV_NORMAL;
171
172 if (url.SchemeIs(chrome::kExtensionScheme)) {
173 const Extension* extension = service->GetExtensionByURL(url);
174 if (extension && extension->is_storage_isolated()) {
175 return PRIV_ISOLATED;
176 }
177
178 return PRIV_EXTENSION;
179 }
180
181 return PRIV_NORMAL;
182}
183
184RenderProcessHostPrivilege GetProcessPrivilege(
185 RenderProcessHost* process_host,
186 ExtensionProcessManager* extension_process_manager) {
[email protected]676f6ab2011-10-19 20:23:21187 if (!extension_process_manager->IsExtensionProcess(process_host->id()))
188 return PRIV_NORMAL;
189
190 std::set<const Extension*> extensions_for_process(
191 extension_process_manager->GetExtensionsForProcess(process_host->id()));
192 for (std::set<const Extension*>::iterator iter =
193 extensions_for_process.begin();
194 iter != extensions_for_process.end(); ++iter) {
195 if ((*iter)->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42196 return PRIV_ISOLATED;
[email protected]8d3132f62011-10-12 07:13:42197 }
198
[email protected]676f6ab2011-10-19 20:23:21199 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42200}
201
[email protected]9dbfff12011-07-01 19:37:07202} // namespace
[email protected]c5dbef02011-05-13 05:06:09203
[email protected]d977f9c2011-03-14 16:10:26204namespace chrome {
205
[email protected]b48c9182011-10-26 18:03:30206void ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]4573fbd2011-10-31 20:25:18207 const content::MainFunctionParams& parameters,
[email protected]b48c9182011-10-26 18:03:30208 std::vector<content::BrowserMainParts*>* parts_list) {
209 // Construct the Main browser parts based on the OS type.
210#if defined(OS_WIN)
211 parts_list->push_back(new ChromeBrowserMainPartsWin(parameters));
[email protected]f967b722011-09-07 00:58:04212#elif defined(OS_MACOSX)
[email protected]b48c9182011-10-26 18:03:30213 parts_list->push_back(new ChromeBrowserMainPartsMac(parameters));
214#elif defined(OS_CHROMEOS)
215 parts_list->push_back(new ChromeBrowserMainPartsChromeos(parameters));
216#elif defined(OS_LINUX)
217 parts_list->push_back(new ChromeBrowserMainPartsLinux(parameters));
218#elif defined(OS_POSIX)
219 parts_list->push_back(new ChromeBrowserMainPartsPosix(parameters));
[email protected]f967b722011-09-07 00:58:04220#else
[email protected]b48c9182011-10-26 18:03:30221 NOTREACHED();
222 parts_list->push_back(new ChromeBrowserMainParts(parameters));
223#endif
224
225 // Construct additional browser parts.
226#if defined(USE_AURA)
227 parts_list->push_back(new ChromeBrowserPartsAura());
228#endif
229#if defined(TOOLKIT_USES_GTK)
230 parts_list->push_back(new ChromeBrowserPartsGtk());
[email protected]f967b722011-09-07 00:58:04231#endif
232}
233
[email protected]b45937e2011-10-07 19:49:17234RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
235 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48236#if defined(USE_AURA)
237 return new RenderWidgetHostViewAura(widget);
238#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17239 return new RenderWidgetHostViewViews(widget);
240#elif defined(OS_WIN)
241 if (views::Widget::IsPureViews())
242 return new RenderWidgetHostViewViews(widget);
243 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21244#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17245 return new RenderWidgetHostViewGtk(widget);
246#elif defined(OS_MACOSX)
247 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
248#else
249#error Need to create your platform ViewForWidget here.
250#endif
251}
252
[email protected]74313b42011-08-24 16:51:32253TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
254 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26255#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32256 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21257#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32258 return new TabContentsViewGtk(tab_contents);
259#elif defined(OS_MACOSX)
260 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32261#else
262#error Need to create your platform TabContentsView here.
263#endif
264}
265
[email protected]f364d1392011-04-08 21:03:10266void ChromeContentBrowserClient::RenderViewHostCreated(
267 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46268
269 SiteInstance* site_instance = render_view_host->site_instance();
270 Profile* profile = Profile::FromBrowserContext(
271 site_instance->browsing_instance()->browser_context());
272
273 new ChromeRenderViewHostObserver(render_view_host,
274 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10275 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26276}
277
[email protected]05fcf982011-04-19 00:44:14278void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
279 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02280 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37281 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14282 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02283 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14284 host->channel()->AddFilter(new PrintingMessageFilter());
285 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02286 new SearchProviderInstallStateMessageFilter(id, profile));
287 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03288 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
289 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38290
[email protected]2ccf45c2011-08-19 23:35:50291 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
292 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07293
294 SendExtensionWebRequestStatusToHost(host);
[email protected]c14406092011-10-27 13:43:42295 ContentSettingsForOneType settings;
296 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
297 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &settings);
298 host->Send(new ChromeViewMsg_SetImageSettingRules(settings));
[email protected]05fcf982011-04-19 00:44:14299}
300
[email protected]97e6c4c2011-05-18 16:08:51301void ChromeContentBrowserClient::PluginProcessHostCreated(
302 PluginProcessHost* host) {
303 host->AddFilter(new ChromePluginMessageFilter(host));
304}
305
[email protected]5327dfb2011-05-03 17:50:36306void ChromeContentBrowserClient::WorkerProcessHostCreated(
307 WorkerProcessHost* host) {
308 host->AddFilter(new ChromeWorkerMessageFilter(host));
309}
310
[email protected]1fd1a502011-03-30 16:55:56311content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
312 return ChromeWebUIFactory::GetInstance();
313}
314
[email protected]3d7474ff2011-07-27 17:47:37315GURL ChromeContentBrowserClient::GetEffectiveURL(
316 content::BrowserContext* browser_context, const GURL& url) {
317 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08318 // Get the effective URL for the given actual URL. If the URL is part of an
319 // installed app, the effective URL is an extension URL with the ID of that
320 // extension as the host. This has the effect of grouping apps together in
321 // a common SiteInstance.
322 if (!profile || !profile->GetExtensionService())
323 return url;
324
325 const Extension* extension =
326 profile->GetExtensionService()->GetExtensionByWebExtent(url);
327 if (!extension)
328 return url;
329
330 // If the URL is part of an extension's web extent, convert it to an
331 // extension URL.
332 return extension->GetResourceURL(url.path());
333}
334
[email protected]056ad2a2011-07-12 02:13:55335bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37336 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55337 // Non-extension URLs should generally use process-per-site-instance.
338 // Because we expect to use the effective URL, hosted apps URLs should have
339 // an extension scheme by now.
340 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
341 return false;
342
[email protected]3d7474ff2011-07-27 17:47:37343 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55344 if (!profile || !profile->GetExtensionService())
345 return false;
346
347 const Extension* extension =
348 profile->GetExtensionService()->GetExtensionByURL(effective_url);
349 if (!extension)
350 return false;
351
352 // If the URL is part of a hosted app that does not have the background
353 // permission, we want to give each instance its own process to improve
354 // responsiveness.
355 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
356 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
357 return false;
358
359 // Hosted apps that have the background permission must use process per site,
360 // since all instances can make synchronous calls to the background window.
361 // Other extensions should use process per site as well.
362 return true;
363}
364
[email protected]0f012df82011-05-19 14:15:29365bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03366 return url == GURL(chrome::kChromeUICrashURL) ||
367 url == GURL(chrome::kChromeUIKillURL) ||
368 url == GURL(chrome::kChromeUIHangURL) ||
369 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29370}
371
[email protected]2a5221b2011-09-27 23:07:31372bool ChromeContentBrowserClient::IsSuitableHost(
373 RenderProcessHost* process_host,
374 const GURL& site_url) {
375 Profile* profile =
376 Profile::FromBrowserContext(process_host->browser_context());
377 ExtensionProcessManager* extension_process_manager =
378 profile->GetExtensionProcessManager();
[email protected]8d3132f62011-10-12 07:13:42379 ExtensionService* service = profile->GetExtensionService();
[email protected]2a5221b2011-09-27 23:07:31380
[email protected]8d3132f62011-10-12 07:13:42381 // These may be NULL during tests. In that case, just assume any site can
382 // share any host.
383 if (!extension_process_manager || !service)
[email protected]2a5221b2011-09-27 23:07:31384 return true;
385
[email protected]a8c269a2011-10-25 20:17:22386 // Experimental:
387 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
388 // to share a renderer process. (We could allow pages from the same site or
389 // extensions of the same type to share, if we knew what the given process
390 // was dedicated to. Allowing no sharing is simpler for now.) This may
391 // cause resource exhaustion issues if too many sites are open at once.
392 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
393 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
394 return false;
395
[email protected]8d3132f62011-10-12 07:13:42396 return GetProcessPrivilege(process_host, extension_process_manager) ==
397 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]2a5221b2011-09-27 23:07:31398}
399
[email protected]e3daf3c2011-10-05 21:17:08400bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
401 const GURL& current_url,
402 const GURL& new_url) {
403 if (current_url.is_empty()) {
404 // Always choose a new process when navigating to extension URLs. The
405 // process grouping logic will combine all of a given extension's pages
406 // into the same process.
407 if (new_url.SchemeIs(chrome::kExtensionScheme))
408 return true;
409
410 return false;
411 }
412
413 // Also, we must switch if one is an extension and the other is not the exact
414 // same extension.
415 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
416 new_url.SchemeIs(chrome::kExtensionScheme)) {
417 if (current_url.GetOrigin() != new_url.GetOrigin())
418 return true;
419 }
420
421 return false;
422}
423
[email protected]763ec4ca2011-04-29 15:48:12424std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
425 const std::string& alias_name) {
426 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
427}
428
[email protected]b80f68432011-05-02 17:22:30429void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
430 CommandLine* command_line, int child_process_id) {
431#if defined(USE_LINUX_BREAKPAD)
432 if (IsCrashReporterEnabled()) {
433 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
434 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
435 }
436#elif defined(OS_MACOSX)
437 if (IsCrashReporterEnabled()) {
438 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
439 child_process_logging::GetClientId());
440 }
441#endif // OS_MACOSX
442
[email protected]f1933792011-06-14 00:49:34443 if (logging::DialogsAreSuppressed())
444 command_line->AppendSwitch(switches::kNoErrorDialogs);
445
[email protected]b80f68432011-05-02 17:22:30446 std::string process_type =
447 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17448 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52449 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30450 FilePath user_data_dir =
451 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
452 if (!user_data_dir.empty())
453 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
454#if defined(OS_CHROMEOS)
455 const std::string& login_profile =
456 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
457 if (!login_profile.empty())
458 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
459#endif
460
461 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
462
[email protected]3d7474ff2011-07-27 17:47:37463 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]718eab62011-10-05 21:16:52464
465 ExtensionProcessManager* extension_process_manager =
466 profile->GetExtensionProcessManager();
467 if (extension_process_manager->IsExtensionProcess(
468 process->id())) {
469 command_line->AppendSwitch(switches::kExtensionProcess);
470 }
471
[email protected]3d7474ff2011-07-27 17:47:37472 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30473 // Currently this pref is only registered if applied via a policy.
474 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
475 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
476 // Turn this policy into a command line switch.
477 command_line->AppendSwitch(switches::kDisable3DAPIs);
478 }
479
480 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46481 // in the Profile preferences or the browser process.
482 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
483 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30484 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46485 }
[email protected]4287a3d2011-06-13 23:56:51486
487 static const char* const kSwitchNames[] = {
488 switches::kAllowHTTPBackgroundPage,
489 switches::kAllowScriptingGallery,
490 switches::kAppsCheckoutURL,
491 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31492 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51493 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51494 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51495 switches::kDomAutomationController,
496 switches::kDumpHistogramsOnExit,
497 switches::kEnableClickToPlay,
498 switches::kEnableCrxlessWebApps,
499 switches::kEnableExperimentalExtensionApis,
500 switches::kEnableInBrowserThumbnailing,
501 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12502 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51503 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24504 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51505 switches::kEnableSearchProviderApiV2,
506 switches::kEnableWatchdog,
507 switches::kExperimentalSpellcheckerFeatures,
508 switches::kMemoryProfiling,
509 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04510 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51511 switches::kPpapiFlashArgs,
512 switches::kPpapiFlashInProcess,
513 switches::kPpapiFlashPath,
514 switches::kPpapiFlashVersion,
515 switches::kProfilingAtStart,
516 switches::kProfilingFile,
517 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51518 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03519 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51520 };
521
522 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
523 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17524 } else if (process_type == switches::kUtilityProcess) {
525 if (browser_command_line.HasSwitch(
526 switches::kEnableExperimentalExtensionApis)) {
527 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
528 }
[email protected]4287a3d2011-06-13 23:56:51529 } else if (process_type == switches::kPluginProcess) {
530 static const char* const kSwitchNames[] = {
531 #if defined(OS_CHROMEOS)
532 switches::kLoginProfile,
533 #endif
534 switches::kMemoryProfiling,
535 switches::kSilentDumpOnDCHECK,
536 switches::kUserDataDir,
537 };
538
539 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
540 arraysize(kSwitchNames));
541 } else if (process_type == switches::kZygoteProcess) {
542 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51543 switches::kUserDataDir, // Make logs go to the right file.
544 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
545 switches::kPpapiFlashInProcess,
546 switches::kPpapiFlashPath,
547 switches::kPpapiFlashVersion,
548 };
549
550 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
551 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30552 }
[email protected]6f08af82011-09-15 01:19:03553
554 // The command line switch kEnableBenchmarking needs to be specified along
555 // with the kEnableStatsTable switch to ensure that the stats table global
556 // is initialized correctly.
557 if (command_line->HasSwitch(switches::kEnableBenchmarking))
558 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30559}
560
561std::string ChromeContentBrowserClient::GetApplicationLocale() {
562 return g_browser_process->GetApplicationLocale();
563}
564
[email protected]b5cca982011-05-26 04:42:08565std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37566 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
567 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08568}
569
[email protected]ac55e292011-06-24 05:16:08570SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
571 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
[email protected]2cc6a9292011-10-13 21:41:01572#if defined(TOUCH_UI)
573 // In touch builds, we want large default favicons for the tabstrip, but in
574 // other places (such as bookmark, manage search engines, homepage) we assume
575 // default favicons are 16x16.
576 return rb.GetBitmapNamed(IDR_DEFAULT_LARGE_FAVICON);
577#else
[email protected]ac55e292011-06-24 05:16:08578 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
[email protected]2cc6a9292011-10-13 21:41:01579#endif
[email protected]ac55e292011-06-24 05:16:08580}
581
[email protected]a2176792011-05-08 19:30:49582bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09583 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19584 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09585 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
587 ProfileIOData* io_data =
588 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05589 return io_data->GetCookieSettings()->
590 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49591}
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]30fde822011-10-28 09:49:05603 bool allow = io_data->GetCookieSettings()->
604 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01605
[email protected]8093a542011-05-13 07:29:32606 BrowserThread::PostTask(
607 BrowserThread::UI, FROM_HERE,
608 NewRunnableFunction(
609 &TabSpecificContentSettings::CookiesRead,
610 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01611 return allow;
612}
613
614bool ChromeContentBrowserClient::AllowSetCookie(
615 const GURL& url,
616 const GURL& first_party,
617 const std::string& cookie_line,
618 const content::ResourceContext& context,
619 int render_process_id,
620 int render_view_id,
621 net::CookieOptions* options) {
622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32623 ProfileIOData* io_data =
624 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01625
[email protected]30fde822011-10-28 09:49:05626 CookieSettings* cookie_settings = io_data->GetCookieSettings();
627 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
628
629 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09630 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01631
[email protected]8093a542011-05-13 07:29:32632 BrowserThread::PostTask(
633 BrowserThread::UI, FROM_HERE,
634 NewRunnableFunction(
635 &TabSpecificContentSettings::CookieChanged,
636 render_process_id, render_view_id, url, cookie_line, *options,
637 !allow));
[email protected]ed24fad2011-05-10 22:44:01638 return allow;
639}
640
[email protected]d5a19162011-06-30 18:51:54641bool ChromeContentBrowserClient::AllowSaveLocalState(
642 const content::ResourceContext& context) {
643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
644 ProfileIOData* io_data =
645 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
646 return !io_data->clear_local_state_on_exit()->GetValue();
647}
648
[email protected]6133f922011-07-01 21:34:34649net::URLRequestContext*
650ChromeContentBrowserClient::OverrideRequestContextForURL(
651 const GURL& url, const content::ResourceContext& context) {
652 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
653 if (url.SchemeIs(chrome::kExtensionScheme)) {
654 ProfileIOData* io_data =
655 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
656 return io_data->extensions_request_context();
657 }
658
659 return NULL;
660}
661
[email protected]317f96c92011-05-31 06:53:41662QuotaPermissionContext*
663ChromeContentBrowserClient::CreateQuotaPermissionContext() {
664 return new ChromeQuotaPermissionContext();
665}
666
[email protected]a0ce3282011-08-19 20:49:52667void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42668 // On Mac, this call needs to be done on the UI thread. On other platforms,
669 // do it on the FILE thread so we don't slow down UI.
670#if defined(OS_MACOSX)
671 platform_util::OpenItem(path);
672#else
673 BrowserThread::PostTask(
674 BrowserThread::FILE, FROM_HERE,
675 NewRunnableFunction(&platform_util::OpenItem, path));
676#endif
677}
678
[email protected]a0ce3282011-08-19 20:49:52679void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
680#if defined(OS_MACOSX)
681 // Mac needs to run this operation on the UI thread.
682 platform_util::ShowItemInFolder(path);
683#else
684 BrowserThread::PostTask(
685 BrowserThread::FILE, FROM_HERE,
686 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
687#endif
688}
689
[email protected]848dd042011-06-04 18:24:03690void ChromeContentBrowserClient::AllowCertificateError(
691 SSLCertErrorHandler* handler,
692 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58693 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41694 // If the tab is being prerendered, cancel the prerender and the request.
695 TabContents* tab = tab_util::GetTabContentsByID(
696 handler->render_process_host_id(),
697 handler->tab_contents_id());
698 if (!tab) {
699 NOTREACHED();
700 return;
701 }
702 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50703 prerender::PrerenderManagerFactory::GetForProfile(
704 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41705 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
706 if (prerender_manager->prerender_tracker()->TryCancel(
707 handler->render_process_host_id(),
708 handler->tab_contents_id(),
709 prerender::FINAL_STATUS_SSL_ERROR)) {
710 handler->CancelRequest();
711 return;
712 }
713 }
714
715 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03716 SSLBlockingPage* blocking_page = new SSLBlockingPage(
717 handler, overridable, callback);
718 blocking_page->Show();
719}
720
[email protected]c99c442e2011-08-24 11:37:30721void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45722 int render_process_id,
723 int render_view_id,
724 SSLClientAuthHandler* handler) {
725 TabContents* tab = tab_util::GetTabContentsByID(
726 render_process_id, render_view_id);
727 if (!tab) {
728 NOTREACHED();
729 return;
730 }
731
732 TabContentsWrapper* wrapper =
733 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30734 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45735}
736
737void ChromeContentBrowserClient::AddNewCertificate(
738 net::URLRequest* request,
739 net::X509Certificate* cert,
740 int render_process_id,
741 int render_view_id) {
742 // The handler will run the UI and delete itself when it's finished.
743 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
744}
745
[email protected]941623e2011-06-07 23:06:04746void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
747 const GURL& source_origin,
748 int callback_context,
749 int render_process_id,
750 int render_view_id) {
751 RenderViewHost* rvh = RenderViewHost::FromID(
752 render_process_id, render_view_id);
753 if (!rvh) {
754 NOTREACHED();
755 return;
756 }
757
758 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37759 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04760 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37761 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04762 service->RequestPermission(
763 source_origin, render_process_id, render_view_id, callback_context,
764 tab_util::GetTabContentsByID(render_process_id, render_view_id));
765}
766
767WebKit::WebNotificationPresenter::Permission
768 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02769 const GURL& source_origin,
770 const content::ResourceContext& context,
771 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
773 ProfileIOData* io_data =
774 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
775
[email protected]34eec7ffe32011-11-02 23:49:02776 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
777 source_origin, render_process_id,
778 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04779 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04780
781 // Fall back to the regular notification preferences, which works on an
782 // origin basis.
[email protected]34eec7ffe32011-11-02 23:49:02783 // TODO(dcheng): Change to just source_origin once WebKit side is cleaned up.
[email protected]941623e2011-06-07 23:06:04784 return io_data->GetNotificationService() ?
[email protected]34eec7ffe32011-11-02 23:49:02785 io_data->GetNotificationService()->HasPermission(
786 source_origin.GetOrigin()) :
[email protected]941623e2011-06-07 23:06:04787 WebKit::WebNotificationPresenter::PermissionNotAllowed;
788}
789
790void ChromeContentBrowserClient::ShowDesktopNotification(
791 const DesktopNotificationHostMsg_Show_Params& params,
792 int render_process_id,
793 int render_view_id,
794 bool worker) {
795 RenderViewHost* rvh = RenderViewHost::FromID(
796 render_process_id, render_view_id);
797 if (!rvh) {
798 NOTREACHED();
799 return;
800 }
801
802 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37803 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04804 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37805 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04806 service->ShowDesktopNotification(
807 params, render_process_id, render_view_id,
808 worker ? DesktopNotificationService::WorkerNotification :
809 DesktopNotificationService::PageNotification);
810}
811
812void ChromeContentBrowserClient::CancelDesktopNotification(
813 int render_process_id,
814 int render_view_id,
815 int notification_id) {
816 RenderViewHost* rvh = RenderViewHost::FromID(
817 render_process_id, render_view_id);
818 if (!rvh) {
819 NOTREACHED();
820 return;
821 }
822
823 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37824 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04825 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37826 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04827 service->CancelDesktopNotification(
828 render_process_id, render_view_id, notification_id);
829}
830
[email protected]9f3fba52011-06-08 20:37:19831bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:02832 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:19833 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:02834 const content::ResourceContext& context,
835 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:19836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
837 // If the opener is trying to create a background window but doesn't have
838 // the appropriate permission, fail the attempt.
839 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
840 ProfileIOData* io_data =
841 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:02842 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
843 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:19844 }
845 return true;
846}
847
848std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
849 const GURL& url, const content::ResourceContext& context) {
850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
851 // Check if it's an extension-created worker, in which case we want to use
852 // the name of the extension.
853 ProfileIOData* io_data =
854 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
855 const Extension* extension =
856 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
857 return extension ? extension->name() : std::string();
858}
859
[email protected]3cb054e62011-06-13 05:21:17860ResourceDispatcherHost*
861 ChromeContentBrowserClient::GetResourceDispatcherHost() {
862 return g_browser_process->resource_dispatcher_host();
863}
864
865ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
866 return g_browser_process->clipboard();
867}
868
[email protected]8f6a3b852011-07-19 16:48:56869MHTMLGenerationManager*
870 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
871 return g_browser_process->mhtml_generation_manager();
872}
873
[email protected]dce502762011-07-20 08:53:49874DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
875 return g_browser_process->devtools_manager();
876}
877
[email protected]ae6e9912011-07-27 01:18:28878net::NetLog* ChromeContentBrowserClient::GetNetLog() {
879 return g_browser_process->net_log();
880}
881
[email protected]3bc0b562011-08-24 23:51:04882speech_input::SpeechInputManager*
883 ChromeContentBrowserClient::GetSpeechInputManager() {
884 return speech_input::ChromeSpeechInputManager::GetInstance();
885}
886
[email protected]32538d92011-08-25 00:09:23887AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
888 return new ChromeAccessTokenStore();
889}
890
[email protected]dbae6b02011-06-29 23:51:41891bool ChromeContentBrowserClient::IsFastShutdownPossible() {
892 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
893 return !browser_command_line.HasSwitch(switches::kChromeFrame);
894}
895
[email protected]5092c282011-10-29 21:48:37896WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
897 return RenderViewHostDelegateHelper::GetWebkitPrefs(rvh);
[email protected]181a95ee2011-07-12 19:26:36898}
899
900void ChromeContentBrowserClient::UpdateInspectorSetting(
901 RenderViewHost* rvh, const std::string& key, const std::string& value) {
902 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37903 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36904}
905
906void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
907 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37908 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36909}
910
[email protected]b8148ac2011-07-13 22:03:25911void ChromeContentBrowserClient::BrowserURLHandlerCreated(
912 BrowserURLHandler* handler) {
913 // Add the default URL handlers.
914 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
915 BrowserURLHandler::null_handler());
916 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
917 &ExtensionWebUI::HandleChromeURLOverrideReverse);
918
919 // about:
920 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
921 BrowserURLHandler::null_handler());
922 // chrome: & friends.
923 handler->AddHandlerPair(&HandleWebUI,
924 BrowserURLHandler::null_handler());
925}
926
927void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37928 Profile* profile = Profile::FromBrowserContext(
929 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25930 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
931 BrowsingDataRemover::EVERYTHING,
932 base::Time());
933 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
934 // BrowsingDataRemover takes care of deleting itself when done.
935}
936
937void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37938 Profile* profile = Profile::FromBrowserContext(
939 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25940 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
941 BrowsingDataRemover::EVERYTHING,
942 base::Time());
[email protected]dceaa912011-09-06 17:17:23943 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25944 remover->Remove(remove_mask);
945 // BrowsingDataRemover takes care of deleting itself when done.
946}
947
[email protected]e1d16eb92011-08-18 23:19:32948FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
949 return download_util::GetDefaultDownloadDirectory();
950}
951
[email protected]c9b6eb62011-10-18 20:49:39952std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
953 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
954}
955
[email protected]b80f68432011-05-02 17:22:30956#if defined(OS_LINUX)
957int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:52958 const CommandLine& command_line) {
959 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:07960 ExtensionCrashHandlerHostLinux* crash_handler =
961 ExtensionCrashHandlerHostLinux::GetInstance();
962 return crash_handler->GetDeathSignalSocket();
963 }
964
[email protected]718eab62011-10-05 21:16:52965 std::string process_type =
966 command_line.GetSwitchValueASCII(switches::kProcessType);
967
968 if (process_type == switches::kRendererProcess)
969 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
970
[email protected]b80f68432011-05-02 17:22:30971 if (process_type == switches::kPluginProcess)
972 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
973
974 if (process_type == switches::kPpapiPluginProcess)
975 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
976
977 if (process_type == switches::kGpuProcess)
978 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
979
980 return -1;
981}
[email protected]9dbfff12011-07-01 19:37:07982#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30983
[email protected]4a65826d2011-08-25 16:04:01984#if defined(OS_WIN)
985const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
986 return chrome::kBrowserResourcesDll;
987}
988#endif
989
[email protected]37a72af2011-06-13 05:42:01990#if defined(USE_NSS)
991crypto::CryptoModuleBlockingPasswordDelegate*
992 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
993 const GURL& url) {
994 return browser::NewCryptoModuleBlockingDialogDelegate(
995 browser::kCryptoModulePasswordKeygen, url.host());
996}
997#endif
998
[email protected]d977f9c2011-03-14 16:10:26999} // namespace chrome