blob: 7d00b316f063755230613a704004d6a830892647 [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]8aa7a412011-11-07 12:33:4240#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1441#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0442#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4643#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4544#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0345#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3646#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4547#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
48#include "chrome/browser/tab_contents/tab_util.h"
49#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5650#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3051#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0152#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3053#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0454#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3455#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1256#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3857#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0958#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2559#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0960#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5161#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1462#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2663#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4964#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0965#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4166#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4567#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1268#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3269#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3670#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0471#include "content/common/desktop_notification_messages.h"
[email protected]b48c9182011-10-26 18:03:3072#include "content/public/browser/browser_main_parts.h"
[email protected]c9b6eb62011-10-18 20:49:3973#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3474#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0175#include "net/base/cookie_monster.h"
76#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3977#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0878#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2679
[email protected]b48c9182011-10-26 18:03:3080#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3881#include "chrome/browser/chrome_browser_main_win.h"
82#elif defined(OS_MACOSX)
83#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:3084#elif defined(OS_CHROMEOS)
85#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
86#elif defined(OS_LINUX)
87#include "chrome/browser/chrome_browser_main_linux.h"
88#elif defined(OS_POSIX)
89#include "chrome/browser/chrome_browser_main_posix.h"
90#endif
91
[email protected]b48c9182011-10-26 18:03:3092#if defined(TOOLKIT_USES_GTK)
93#include "chrome/browser/chrome_browser_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:3894#endif
95
[email protected]c7480942011-11-08 19:18:2796#if defined(TOOLKIT_VIEWS)
97#include "chrome/browser/chrome_browser_parts_views.h"
98#endif
99
100#if defined(USE_AURA)
101#include "chrome/browser/chrome_browser_parts_aura.h"
[email protected]2ddfe432011-11-07 19:26:30102#endif
103
[email protected]b80f68432011-05-02 17:22:30104#if defined(OS_LINUX)
105#include "base/linux_util.h"
106#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43107#endif
[email protected]b80f68432011-05-02 17:22:30108
[email protected]c7480942011-11-08 19:18:27109#if defined(TOUCH_UI)
110#include "chrome/browser/chrome_browser_parts_touch.h"
111#endif
112
[email protected]080f34f2011-09-20 05:39:26113#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32114#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21115#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32116#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
117#elif defined(OS_MACOSX)
118#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32119#endif
120
[email protected]37a72af2011-06-13 05:42:01121#if defined(USE_NSS)
122#include "chrome/browser/ui/crypto_module_password_dialog.h"
123#endif
124
[email protected]91ad1472011-10-27 15:09:48125#if defined(USE_AURA)
126#include "content/browser/renderer_host/render_widget_host_view_aura.h"
127#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17128#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
129#elif defined(OS_WIN)
130#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
131#include "content/browser/renderer_host/render_widget_host_view_win.h"
[email protected]c92f4ed2011-10-21 19:50:21132#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17133#include "content/browser/renderer_host/render_widget_host_view_gtk.h"
134#elif defined(OS_MACOSX)
135#include "content/browser/renderer_host/render_widget_host_view_mac.h"
136#endif
137
[email protected]631bb742011-11-02 11:29:39138using content::BrowserThread;
139
[email protected]c5dbef02011-05-13 05:06:09140namespace {
141
[email protected]b8148ac2011-07-13 22:03:25142// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42143bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37144 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25145 return false;
146
147 // Special case the new tab page. In older versions of Chrome, the new tab
148 // page was hosted at chrome-internal:<blah>. This might be in people's saved
149 // sessions or bookmarks, so we say any URL with that scheme triggers the new
150 // tab page.
151 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
152 // Rewrite it with the proper new tab URL.
153 *url = GURL(chrome::kChromeUINewTabURL);
154 }
155
156 return true;
157}
158
[email protected]8d3132f62011-10-12 07:13:42159// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
160// below. Extension, and isolated apps require different privileges to be
161// granted to their RenderProcessHosts. This classification allows us to make
162// sure URLs are served by hosts with the right set of privileges.
163enum RenderProcessHostPrivilege {
164 PRIV_NORMAL,
165 PRIV_EXTENSION,
166 PRIV_ISOLATED,
167};
168
169RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
170 const GURL& url,
171 ExtensionService* service) {
172 // Default to a normal renderer cause it is lower privileged. This should only
173 // occur if the URL on a site instance is either malformed, or uninitialized.
174 // If it is malformed, then there is no need for better privileges anyways.
175 // If it is uninitialized, but eventually settles on being an a scheme other
176 // than normal webrenderer, the navigation logic will correct us out of band
177 // anyways.
178 if (!url.is_valid())
179 return PRIV_NORMAL;
180
181 if (url.SchemeIs(chrome::kExtensionScheme)) {
182 const Extension* extension = service->GetExtensionByURL(url);
183 if (extension && extension->is_storage_isolated()) {
184 return PRIV_ISOLATED;
185 }
186
187 return PRIV_EXTENSION;
188 }
189
190 return PRIV_NORMAL;
191}
192
193RenderProcessHostPrivilege GetProcessPrivilege(
194 RenderProcessHost* process_host,
195 ExtensionProcessManager* extension_process_manager) {
[email protected]676f6ab2011-10-19 20:23:21196 if (!extension_process_manager->IsExtensionProcess(process_host->id()))
197 return PRIV_NORMAL;
198
199 std::set<const Extension*> extensions_for_process(
200 extension_process_manager->GetExtensionsForProcess(process_host->id()));
201 for (std::set<const Extension*>::iterator iter =
202 extensions_for_process.begin();
203 iter != extensions_for_process.end(); ++iter) {
204 if ((*iter)->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42205 return PRIV_ISOLATED;
[email protected]8d3132f62011-10-12 07:13:42206 }
207
[email protected]676f6ab2011-10-19 20:23:21208 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42209}
210
[email protected]9dbfff12011-07-01 19:37:07211} // namespace
[email protected]c5dbef02011-05-13 05:06:09212
[email protected]d977f9c2011-03-14 16:10:26213namespace chrome {
214
[email protected]b48c9182011-10-26 18:03:30215void ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]4573fbd2011-10-31 20:25:18216 const content::MainFunctionParams& parameters,
[email protected]b48c9182011-10-26 18:03:30217 std::vector<content::BrowserMainParts*>* parts_list) {
218 // Construct the Main browser parts based on the OS type.
219#if defined(OS_WIN)
220 parts_list->push_back(new ChromeBrowserMainPartsWin(parameters));
[email protected]f967b722011-09-07 00:58:04221#elif defined(OS_MACOSX)
[email protected]b48c9182011-10-26 18:03:30222 parts_list->push_back(new ChromeBrowserMainPartsMac(parameters));
223#elif defined(OS_CHROMEOS)
224 parts_list->push_back(new ChromeBrowserMainPartsChromeos(parameters));
225#elif defined(OS_LINUX)
226 parts_list->push_back(new ChromeBrowserMainPartsLinux(parameters));
227#elif defined(OS_POSIX)
228 parts_list->push_back(new ChromeBrowserMainPartsPosix(parameters));
[email protected]f967b722011-09-07 00:58:04229#else
[email protected]b48c9182011-10-26 18:03:30230 NOTREACHED();
231 parts_list->push_back(new ChromeBrowserMainParts(parameters));
232#endif
233
[email protected]c7480942011-11-08 19:18:27234 // Construct additional browser parts. Stages are called in the order in
235 // which they are added.
[email protected]b48c9182011-10-26 18:03:30236#if defined(TOOLKIT_USES_GTK)
237 parts_list->push_back(new ChromeBrowserPartsGtk());
[email protected]f967b722011-09-07 00:58:04238#endif
[email protected]c7480942011-11-08 19:18:27239
240#if defined(TOOLKIT_VIEWS)
241 parts_list->push_back(new ChromeBrowserPartsViews());
242#endif
243
244#if defined(USE_AURA)
245 parts_list->push_back(new ChromeBrowserPartsAura());
246#endif
247
[email protected]2ddfe432011-11-07 19:26:30248#if defined(TOUCH_UI)
249 parts_list->push_back(new ChromeBrowserPartsTouch());
250#endif
[email protected]c7480942011-11-08 19:18:27251
[email protected]f967b722011-09-07 00:58:04252}
253
[email protected]b45937e2011-10-07 19:49:17254RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
255 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48256#if defined(USE_AURA)
257 return new RenderWidgetHostViewAura(widget);
258#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17259 return new RenderWidgetHostViewViews(widget);
260#elif defined(OS_WIN)
261 if (views::Widget::IsPureViews())
262 return new RenderWidgetHostViewViews(widget);
263 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21264#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17265 return new RenderWidgetHostViewGtk(widget);
266#elif defined(OS_MACOSX)
267 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
268#else
269#error Need to create your platform ViewForWidget here.
270#endif
271}
272
[email protected]74313b42011-08-24 16:51:32273TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
274 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26275#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32276 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21277#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32278 return new TabContentsViewGtk(tab_contents);
279#elif defined(OS_MACOSX)
280 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32281#else
282#error Need to create your platform TabContentsView here.
283#endif
284}
285
[email protected]f364d1392011-04-08 21:03:10286void ChromeContentBrowserClient::RenderViewHostCreated(
287 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46288
289 SiteInstance* site_instance = render_view_host->site_instance();
290 Profile* profile = Profile::FromBrowserContext(
291 site_instance->browsing_instance()->browser_context());
292
293 new ChromeRenderViewHostObserver(render_view_host,
294 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10295 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26296}
297
[email protected]05fcf982011-04-19 00:44:14298void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
299 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02300 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37301 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14302 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02303 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]8aa7a412011-11-07 12:33:42304 host->channel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]05fcf982011-04-19 00:44:14305 host->channel()->AddFilter(new PrintingMessageFilter());
306 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02307 new SearchProviderInstallStateMessageFilter(id, profile));
308 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03309 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
310 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38311
[email protected]2ccf45c2011-08-19 23:35:50312 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
313 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07314
315 SendExtensionWebRequestStatusToHost(host);
[email protected]b3db76a2011-11-08 17:42:11316 ContentSettingsForOneType settings;
317 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
318 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &settings);
319 host->Send(new ChromeViewMsg_SetImageSettingRules(settings));
[email protected]05fcf982011-04-19 00:44:14320}
321
[email protected]97e6c4c2011-05-18 16:08:51322void ChromeContentBrowserClient::PluginProcessHostCreated(
323 PluginProcessHost* host) {
324 host->AddFilter(new ChromePluginMessageFilter(host));
325}
326
[email protected]5327dfb2011-05-03 17:50:36327void ChromeContentBrowserClient::WorkerProcessHostCreated(
328 WorkerProcessHost* host) {
329 host->AddFilter(new ChromeWorkerMessageFilter(host));
330}
331
[email protected]1fd1a502011-03-30 16:55:56332content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
333 return ChromeWebUIFactory::GetInstance();
334}
335
[email protected]3d7474ff2011-07-27 17:47:37336GURL ChromeContentBrowserClient::GetEffectiveURL(
337 content::BrowserContext* browser_context, const GURL& url) {
338 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08339 // Get the effective URL for the given actual URL. If the URL is part of an
340 // installed app, the effective URL is an extension URL with the ID of that
341 // extension as the host. This has the effect of grouping apps together in
342 // a common SiteInstance.
343 if (!profile || !profile->GetExtensionService())
344 return url;
345
346 const Extension* extension =
347 profile->GetExtensionService()->GetExtensionByWebExtent(url);
348 if (!extension)
349 return url;
350
351 // If the URL is part of an extension's web extent, convert it to an
352 // extension URL.
353 return extension->GetResourceURL(url.path());
354}
355
[email protected]056ad2a2011-07-12 02:13:55356bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37357 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55358 // Non-extension URLs should generally use process-per-site-instance.
359 // Because we expect to use the effective URL, hosted apps URLs should have
360 // an extension scheme by now.
361 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
362 return false;
363
[email protected]3d7474ff2011-07-27 17:47:37364 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55365 if (!profile || !profile->GetExtensionService())
366 return false;
367
368 const Extension* extension =
369 profile->GetExtensionService()->GetExtensionByURL(effective_url);
370 if (!extension)
371 return false;
372
373 // If the URL is part of a hosted app that does not have the background
374 // permission, we want to give each instance its own process to improve
375 // responsiveness.
376 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
377 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
378 return false;
379
380 // Hosted apps that have the background permission must use process per site,
381 // since all instances can make synchronous calls to the background window.
382 // Other extensions should use process per site as well.
383 return true;
384}
385
[email protected]0f012df82011-05-19 14:15:29386bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03387 return url == GURL(chrome::kChromeUICrashURL) ||
388 url == GURL(chrome::kChromeUIKillURL) ||
389 url == GURL(chrome::kChromeUIHangURL) ||
390 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29391}
392
[email protected]2a5221b2011-09-27 23:07:31393bool ChromeContentBrowserClient::IsSuitableHost(
394 RenderProcessHost* process_host,
395 const GURL& site_url) {
396 Profile* profile =
397 Profile::FromBrowserContext(process_host->browser_context());
398 ExtensionProcessManager* extension_process_manager =
399 profile->GetExtensionProcessManager();
[email protected]8d3132f62011-10-12 07:13:42400 ExtensionService* service = profile->GetExtensionService();
[email protected]2a5221b2011-09-27 23:07:31401
[email protected]8d3132f62011-10-12 07:13:42402 // These may be NULL during tests. In that case, just assume any site can
403 // share any host.
404 if (!extension_process_manager || !service)
[email protected]2a5221b2011-09-27 23:07:31405 return true;
406
[email protected]a8c269a2011-10-25 20:17:22407 // Experimental:
408 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
409 // to share a renderer process. (We could allow pages from the same site or
410 // extensions of the same type to share, if we knew what the given process
411 // was dedicated to. Allowing no sharing is simpler for now.) This may
412 // cause resource exhaustion issues if too many sites are open at once.
413 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
414 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
415 return false;
416
[email protected]8d3132f62011-10-12 07:13:42417 return GetProcessPrivilege(process_host, extension_process_manager) ==
418 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]2a5221b2011-09-27 23:07:31419}
420
[email protected]e3daf3c2011-10-05 21:17:08421bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
422 const GURL& current_url,
423 const GURL& new_url) {
424 if (current_url.is_empty()) {
425 // Always choose a new process when navigating to extension URLs. The
426 // process grouping logic will combine all of a given extension's pages
427 // into the same process.
428 if (new_url.SchemeIs(chrome::kExtensionScheme))
429 return true;
430
431 return false;
432 }
433
434 // Also, we must switch if one is an extension and the other is not the exact
435 // same extension.
436 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
437 new_url.SchemeIs(chrome::kExtensionScheme)) {
438 if (current_url.GetOrigin() != new_url.GetOrigin())
439 return true;
440 }
441
442 return false;
443}
444
[email protected]763ec4ca2011-04-29 15:48:12445std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
446 const std::string& alias_name) {
447 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
448}
449
[email protected]b80f68432011-05-02 17:22:30450void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
451 CommandLine* command_line, int child_process_id) {
452#if defined(USE_LINUX_BREAKPAD)
453 if (IsCrashReporterEnabled()) {
454 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
455 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
456 }
457#elif defined(OS_MACOSX)
458 if (IsCrashReporterEnabled()) {
459 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
460 child_process_logging::GetClientId());
461 }
462#endif // OS_MACOSX
463
[email protected]f1933792011-06-14 00:49:34464 if (logging::DialogsAreSuppressed())
465 command_line->AppendSwitch(switches::kNoErrorDialogs);
466
[email protected]b80f68432011-05-02 17:22:30467 std::string process_type =
468 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17469 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52470 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30471 FilePath user_data_dir =
472 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
473 if (!user_data_dir.empty())
474 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
475#if defined(OS_CHROMEOS)
476 const std::string& login_profile =
477 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
478 if (!login_profile.empty())
479 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
480#endif
481
482 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
483
[email protected]3d7474ff2011-07-27 17:47:37484 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]718eab62011-10-05 21:16:52485
486 ExtensionProcessManager* extension_process_manager =
487 profile->GetExtensionProcessManager();
488 if (extension_process_manager->IsExtensionProcess(
489 process->id())) {
490 command_line->AppendSwitch(switches::kExtensionProcess);
491 }
492
[email protected]3d7474ff2011-07-27 17:47:37493 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30494 // Currently this pref is only registered if applied via a policy.
495 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
496 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
497 // Turn this policy into a command line switch.
498 command_line->AppendSwitch(switches::kDisable3DAPIs);
499 }
500
501 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46502 // in the Profile preferences or the browser process.
503 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
504 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30505 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46506 }
[email protected]4287a3d2011-06-13 23:56:51507
508 static const char* const kSwitchNames[] = {
509 switches::kAllowHTTPBackgroundPage,
510 switches::kAllowScriptingGallery,
511 switches::kAppsCheckoutURL,
512 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31513 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51514 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51515 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51516 switches::kDomAutomationController,
517 switches::kDumpHistogramsOnExit,
518 switches::kEnableClickToPlay,
519 switches::kEnableCrxlessWebApps,
520 switches::kEnableExperimentalExtensionApis,
521 switches::kEnableInBrowserThumbnailing,
522 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12523 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51524 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24525 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51526 switches::kEnableSearchProviderApiV2,
527 switches::kEnableWatchdog,
528 switches::kExperimentalSpellcheckerFeatures,
529 switches::kMemoryProfiling,
530 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04531 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51532 switches::kPpapiFlashArgs,
533 switches::kPpapiFlashInProcess,
534 switches::kPpapiFlashPath,
535 switches::kPpapiFlashVersion,
536 switches::kProfilingAtStart,
537 switches::kProfilingFile,
538 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51539 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03540 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51541 };
542
543 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
544 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17545 } else if (process_type == switches::kUtilityProcess) {
546 if (browser_command_line.HasSwitch(
547 switches::kEnableExperimentalExtensionApis)) {
548 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
549 }
[email protected]4287a3d2011-06-13 23:56:51550 } else if (process_type == switches::kPluginProcess) {
551 static const char* const kSwitchNames[] = {
552 #if defined(OS_CHROMEOS)
553 switches::kLoginProfile,
554 #endif
555 switches::kMemoryProfiling,
556 switches::kSilentDumpOnDCHECK,
557 switches::kUserDataDir,
558 };
559
560 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
561 arraysize(kSwitchNames));
562 } else if (process_type == switches::kZygoteProcess) {
563 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51564 switches::kUserDataDir, // Make logs go to the right file.
565 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
566 switches::kPpapiFlashInProcess,
567 switches::kPpapiFlashPath,
568 switches::kPpapiFlashVersion,
569 };
570
571 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
572 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30573 }
[email protected]6f08af82011-09-15 01:19:03574
575 // The command line switch kEnableBenchmarking needs to be specified along
576 // with the kEnableStatsTable switch to ensure that the stats table global
577 // is initialized correctly.
578 if (command_line->HasSwitch(switches::kEnableBenchmarking))
579 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30580}
581
582std::string ChromeContentBrowserClient::GetApplicationLocale() {
583 return g_browser_process->GetApplicationLocale();
584}
585
[email protected]b5cca982011-05-26 04:42:08586std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37587 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
588 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08589}
590
[email protected]ac55e292011-06-24 05:16:08591SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
592 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
[email protected]2cc6a9292011-10-13 21:41:01593#if defined(TOUCH_UI)
594 // In touch builds, we want large default favicons for the tabstrip, but in
595 // other places (such as bookmark, manage search engines, homepage) we assume
596 // default favicons are 16x16.
597 return rb.GetBitmapNamed(IDR_DEFAULT_LARGE_FAVICON);
598#else
[email protected]ac55e292011-06-24 05:16:08599 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
[email protected]2cc6a9292011-10-13 21:41:01600#endif
[email protected]ac55e292011-06-24 05:16:08601}
602
[email protected]a2176792011-05-08 19:30:49603bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09604 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19605 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09606 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
608 ProfileIOData* io_data =
609 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05610 return io_data->GetCookieSettings()->
611 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49612}
613
[email protected]ed24fad2011-05-10 22:44:01614bool ChromeContentBrowserClient::AllowGetCookie(
615 const GURL& url,
616 const GURL& first_party,
617 const net::CookieList& cookie_list,
618 const content::ResourceContext& context,
619 int render_process_id,
620 int render_view_id) {
621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32622 ProfileIOData* io_data =
623 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05624 bool allow = io_data->GetCookieSettings()->
625 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01626
[email protected]8093a542011-05-13 07:29:32627 BrowserThread::PostTask(
628 BrowserThread::UI, FROM_HERE,
629 NewRunnableFunction(
630 &TabSpecificContentSettings::CookiesRead,
631 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01632 return allow;
633}
634
635bool ChromeContentBrowserClient::AllowSetCookie(
636 const GURL& url,
637 const GURL& first_party,
638 const std::string& cookie_line,
639 const content::ResourceContext& context,
640 int render_process_id,
641 int render_view_id,
642 net::CookieOptions* options) {
643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32644 ProfileIOData* io_data =
645 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01646
[email protected]30fde822011-10-28 09:49:05647 CookieSettings* cookie_settings = io_data->GetCookieSettings();
648 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
649
650 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09651 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01652
[email protected]8093a542011-05-13 07:29:32653 BrowserThread::PostTask(
654 BrowserThread::UI, FROM_HERE,
655 NewRunnableFunction(
656 &TabSpecificContentSettings::CookieChanged,
657 render_process_id, render_view_id, url, cookie_line, *options,
658 !allow));
[email protected]ed24fad2011-05-10 22:44:01659 return allow;
660}
661
[email protected]d5a19162011-06-30 18:51:54662bool ChromeContentBrowserClient::AllowSaveLocalState(
663 const content::ResourceContext& context) {
664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
665 ProfileIOData* io_data =
666 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
667 return !io_data->clear_local_state_on_exit()->GetValue();
668}
669
[email protected]6133f922011-07-01 21:34:34670net::URLRequestContext*
671ChromeContentBrowserClient::OverrideRequestContextForURL(
672 const GURL& url, const content::ResourceContext& context) {
673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
674 if (url.SchemeIs(chrome::kExtensionScheme)) {
675 ProfileIOData* io_data =
676 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
677 return io_data->extensions_request_context();
678 }
679
680 return NULL;
681}
682
[email protected]317f96c92011-05-31 06:53:41683QuotaPermissionContext*
684ChromeContentBrowserClient::CreateQuotaPermissionContext() {
685 return new ChromeQuotaPermissionContext();
686}
687
[email protected]a0ce3282011-08-19 20:49:52688void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42689 // On Mac, this call needs to be done on the UI thread. On other platforms,
690 // do it on the FILE thread so we don't slow down UI.
691#if defined(OS_MACOSX)
692 platform_util::OpenItem(path);
693#else
694 BrowserThread::PostTask(
695 BrowserThread::FILE, FROM_HERE,
696 NewRunnableFunction(&platform_util::OpenItem, path));
697#endif
698}
699
[email protected]a0ce3282011-08-19 20:49:52700void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
701#if defined(OS_MACOSX)
702 // Mac needs to run this operation on the UI thread.
703 platform_util::ShowItemInFolder(path);
704#else
705 BrowserThread::PostTask(
706 BrowserThread::FILE, FROM_HERE,
707 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
708#endif
709}
710
[email protected]848dd042011-06-04 18:24:03711void ChromeContentBrowserClient::AllowCertificateError(
712 SSLCertErrorHandler* handler,
713 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58714 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41715 // If the tab is being prerendered, cancel the prerender and the request.
716 TabContents* tab = tab_util::GetTabContentsByID(
717 handler->render_process_host_id(),
718 handler->tab_contents_id());
719 if (!tab) {
720 NOTREACHED();
721 return;
722 }
723 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50724 prerender::PrerenderManagerFactory::GetForProfile(
725 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41726 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
727 if (prerender_manager->prerender_tracker()->TryCancel(
728 handler->render_process_host_id(),
729 handler->tab_contents_id(),
730 prerender::FINAL_STATUS_SSL_ERROR)) {
731 handler->CancelRequest();
732 return;
733 }
734 }
735
736 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03737 SSLBlockingPage* blocking_page = new SSLBlockingPage(
738 handler, overridable, callback);
739 blocking_page->Show();
740}
741
[email protected]c99c442e2011-08-24 11:37:30742void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45743 int render_process_id,
744 int render_view_id,
745 SSLClientAuthHandler* handler) {
746 TabContents* tab = tab_util::GetTabContentsByID(
747 render_process_id, render_view_id);
748 if (!tab) {
749 NOTREACHED();
750 return;
751 }
752
753 TabContentsWrapper* wrapper =
754 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30755 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45756}
757
758void ChromeContentBrowserClient::AddNewCertificate(
759 net::URLRequest* request,
760 net::X509Certificate* cert,
761 int render_process_id,
762 int render_view_id) {
763 // The handler will run the UI and delete itself when it's finished.
764 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
765}
766
[email protected]941623e2011-06-07 23:06:04767void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
768 const GURL& source_origin,
769 int callback_context,
770 int render_process_id,
771 int render_view_id) {
772 RenderViewHost* rvh = RenderViewHost::FromID(
773 render_process_id, render_view_id);
774 if (!rvh) {
775 NOTREACHED();
776 return;
777 }
778
779 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37780 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04781 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37782 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04783 service->RequestPermission(
784 source_origin, render_process_id, render_view_id, callback_context,
785 tab_util::GetTabContentsByID(render_process_id, render_view_id));
786}
787
788WebKit::WebNotificationPresenter::Permission
789 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02790 const GURL& source_origin,
791 const content::ResourceContext& context,
792 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
794 ProfileIOData* io_data =
795 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
796
[email protected]34eec7ffe32011-11-02 23:49:02797 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
798 source_origin, render_process_id,
799 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04800 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04801
802 // Fall back to the regular notification preferences, which works on an
803 // origin basis.
804 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:37805 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:04806 WebKit::WebNotificationPresenter::PermissionNotAllowed;
807}
808
809void ChromeContentBrowserClient::ShowDesktopNotification(
810 const DesktopNotificationHostMsg_Show_Params& params,
811 int render_process_id,
812 int render_view_id,
813 bool worker) {
814 RenderViewHost* rvh = RenderViewHost::FromID(
815 render_process_id, render_view_id);
816 if (!rvh) {
817 NOTREACHED();
818 return;
819 }
820
821 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37822 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04823 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37824 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04825 service->ShowDesktopNotification(
826 params, render_process_id, render_view_id,
827 worker ? DesktopNotificationService::WorkerNotification :
828 DesktopNotificationService::PageNotification);
829}
830
831void ChromeContentBrowserClient::CancelDesktopNotification(
832 int render_process_id,
833 int render_view_id,
834 int notification_id) {
835 RenderViewHost* rvh = RenderViewHost::FromID(
836 render_process_id, render_view_id);
837 if (!rvh) {
838 NOTREACHED();
839 return;
840 }
841
842 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37843 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04844 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37845 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04846 service->CancelDesktopNotification(
847 render_process_id, render_view_id, notification_id);
848}
849
[email protected]9f3fba52011-06-08 20:37:19850bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:02851 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:19852 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:02853 const content::ResourceContext& context,
854 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:19855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
856 // If the opener is trying to create a background window but doesn't have
857 // the appropriate permission, fail the attempt.
858 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
859 ProfileIOData* io_data =
860 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:02861 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
862 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:19863 }
864 return true;
865}
866
867std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
868 const GURL& url, const content::ResourceContext& context) {
869 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
870 // Check if it's an extension-created worker, in which case we want to use
871 // the name of the extension.
872 ProfileIOData* io_data =
873 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
874 const Extension* extension =
875 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
876 return extension ? extension->name() : std::string();
877}
878
[email protected]3cb054e62011-06-13 05:21:17879ResourceDispatcherHost*
880 ChromeContentBrowserClient::GetResourceDispatcherHost() {
881 return g_browser_process->resource_dispatcher_host();
882}
883
884ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
885 return g_browser_process->clipboard();
886}
887
[email protected]8f6a3b852011-07-19 16:48:56888MHTMLGenerationManager*
889 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
890 return g_browser_process->mhtml_generation_manager();
891}
892
[email protected]dce502762011-07-20 08:53:49893DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
894 return g_browser_process->devtools_manager();
895}
896
[email protected]ae6e9912011-07-27 01:18:28897net::NetLog* ChromeContentBrowserClient::GetNetLog() {
898 return g_browser_process->net_log();
899}
900
[email protected]3bc0b562011-08-24 23:51:04901speech_input::SpeechInputManager*
902 ChromeContentBrowserClient::GetSpeechInputManager() {
903 return speech_input::ChromeSpeechInputManager::GetInstance();
904}
905
[email protected]32538d92011-08-25 00:09:23906AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
907 return new ChromeAccessTokenStore();
908}
909
[email protected]dbae6b02011-06-29 23:51:41910bool ChromeContentBrowserClient::IsFastShutdownPossible() {
911 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
912 return !browser_command_line.HasSwitch(switches::kChromeFrame);
913}
914
[email protected]5092c282011-10-29 21:48:37915WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
916 return RenderViewHostDelegateHelper::GetWebkitPrefs(rvh);
[email protected]181a95ee2011-07-12 19:26:36917}
918
919void ChromeContentBrowserClient::UpdateInspectorSetting(
920 RenderViewHost* rvh, const std::string& key, const std::string& value) {
921 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37922 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36923}
924
925void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
926 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37927 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36928}
929
[email protected]b8148ac2011-07-13 22:03:25930void ChromeContentBrowserClient::BrowserURLHandlerCreated(
931 BrowserURLHandler* handler) {
932 // Add the default URL handlers.
933 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
934 BrowserURLHandler::null_handler());
935 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
936 &ExtensionWebUI::HandleChromeURLOverrideReverse);
937
938 // about:
939 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
940 BrowserURLHandler::null_handler());
941 // chrome: & friends.
942 handler->AddHandlerPair(&HandleWebUI,
943 BrowserURLHandler::null_handler());
944}
945
946void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37947 Profile* profile = Profile::FromBrowserContext(
948 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25949 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
950 BrowsingDataRemover::EVERYTHING,
951 base::Time());
952 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
953 // BrowsingDataRemover takes care of deleting itself when done.
954}
955
956void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37957 Profile* profile = Profile::FromBrowserContext(
958 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25959 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
960 BrowsingDataRemover::EVERYTHING,
961 base::Time());
[email protected]dceaa912011-09-06 17:17:23962 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25963 remover->Remove(remove_mask);
964 // BrowsingDataRemover takes care of deleting itself when done.
965}
966
[email protected]e1d16eb92011-08-18 23:19:32967FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
968 return download_util::GetDefaultDownloadDirectory();
969}
970
[email protected]c9b6eb62011-10-18 20:49:39971std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
972 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
973}
974
[email protected]b80f68432011-05-02 17:22:30975#if defined(OS_LINUX)
976int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:52977 const CommandLine& command_line) {
978 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:07979 ExtensionCrashHandlerHostLinux* crash_handler =
980 ExtensionCrashHandlerHostLinux::GetInstance();
981 return crash_handler->GetDeathSignalSocket();
982 }
983
[email protected]718eab62011-10-05 21:16:52984 std::string process_type =
985 command_line.GetSwitchValueASCII(switches::kProcessType);
986
987 if (process_type == switches::kRendererProcess)
988 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
989
[email protected]b80f68432011-05-02 17:22:30990 if (process_type == switches::kPluginProcess)
991 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
992
993 if (process_type == switches::kPpapiPluginProcess)
994 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
995
996 if (process_type == switches::kGpuProcess)
997 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
998
999 return -1;
1000}
[email protected]9dbfff12011-07-01 19:37:071001#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:301002
[email protected]4a65826d2011-08-25 16:04:011003#if defined(OS_WIN)
1004const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1005 return chrome::kBrowserResourcesDll;
1006}
1007#endif
1008
[email protected]37a72af2011-06-13 05:42:011009#if defined(USE_NSS)
1010crypto::CryptoModuleBlockingPasswordDelegate*
1011 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1012 const GURL& url) {
1013 return browser::NewCryptoModuleBlockingDialogDelegate(
1014 browser::kCryptoModulePasswordKeygen, url.host());
1015}
1016#endif
1017
[email protected]d977f9c2011-03-14 16:10:261018} // namespace chrome