blob: 7269b0a4f9e3a5e690784b902b29ec84f2960e34 [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]7c3228a2011-11-11 21:35:227#include <set>
8#include <vector>
9
[email protected]317c58f02011-11-09 02:15:0310#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3011#include "base/command_line.h"
12#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2513#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3014#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2315#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1216#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0317#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]97e6c4c2011-05-18 16:08:5118#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4119#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5620#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0521#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4522#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3223#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3224#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0425#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1026#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2627#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2528#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]39a5b532011-10-22 01:47:0729#include "chrome/browser/extensions/extension_webrequest_api.h"
[email protected]32538d92011-08-25 00:09:2330#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1231#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2832#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0433#include "chrome/browser/notifications/desktop_notification_service.h"
34#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4235#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1236#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4137#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5038#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4139#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1440#include "chrome/browser/printing/printing_message_filter.h"
41#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3242#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1443#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3344#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4245#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1446#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0447#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4648#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4549#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0350#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3651#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4552#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
53#include "chrome/browser/tab_contents/tab_util.h"
54#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5655#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3056#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0157#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3058#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0459#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4460#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3461#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1262#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3863#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0964#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2565#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0966#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5167#include "content/browser/plugin_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2668#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4969#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0970#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4171#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4572#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1273#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3274#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3675#include "content/browser/worker_host/worker_process_host.h"
[email protected]b48c9182011-10-26 18:03:3076#include "content/public/browser/browser_main_parts.h"
[email protected]f3b1a082011-11-18 00:34:3077#include "content/public/browser/render_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3978#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3479#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0180#include "net/base/cookie_monster.h"
81#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3982#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0883#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2684
[email protected]b48c9182011-10-26 18:03:3085#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3886#include "chrome/browser/chrome_browser_main_win.h"
87#elif defined(OS_MACOSX)
88#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5689#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3090#elif defined(OS_CHROMEOS)
91#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3592#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3093#include "chrome/browser/chrome_browser_main_linux.h"
94#elif defined(OS_POSIX)
95#include "chrome/browser/chrome_browser_main_posix.h"
96#endif
97
[email protected]b48c9182011-10-26 18:03:3098#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:3199#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38100#endif
101
[email protected]c7480942011-11-08 19:18:27102#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31103#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27104#endif
105
106#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31107#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
108#endif
109
[email protected]e60c0232011-11-11 19:56:35110#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30111#include "base/linux_util.h"
112#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43113#endif
[email protected]b80f68432011-05-02 17:22:30114
[email protected]080f34f2011-09-20 05:39:26115#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32116#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21117#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45118#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]74313b42011-08-24 16:51:32119#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
120#elif defined(OS_MACOSX)
121#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32122#endif
123
[email protected]37a72af2011-06-13 05:42:01124#if defined(USE_NSS)
125#include "chrome/browser/ui/crypto_module_password_dialog.h"
126#endif
127
[email protected]91ad1472011-10-27 15:09:48128#if defined(USE_AURA)
129#include "content/browser/renderer_host/render_widget_host_view_aura.h"
[email protected]b45937e2011-10-07 19:49:17130#elif defined(OS_WIN)
[email protected]b45937e2011-10-07 19:49:17131#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]c8c77182011-12-21 15:04:47138using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39139using content::BrowserThread;
140
[email protected]c5dbef02011-05-13 05:06:09141namespace {
142
[email protected]b8148ac2011-07-13 22:03:25143// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42144bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37145 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25146 return false;
147
148 // Special case the new tab page. In older versions of Chrome, the new tab
149 // page was hosted at chrome-internal:<blah>. This might be in people's saved
150 // sessions or bookmarks, so we say any URL with that scheme triggers the new
151 // tab page.
152 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
153 // Rewrite it with the proper new tab URL.
154 *url = GURL(chrome::kChromeUINewTabURL);
155 }
156
157 return true;
158}
159
[email protected]8d3132f62011-10-12 07:13:42160// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
161// below. Extension, and isolated apps require different privileges to be
162// granted to their RenderProcessHosts. This classification allows us to make
163// sure URLs are served by hosts with the right set of privileges.
164enum RenderProcessHostPrivilege {
165 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45166 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42167 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45168 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42169};
170
171RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
172 const GURL& url,
173 ExtensionService* service) {
174 // Default to a normal renderer cause it is lower privileged. This should only
175 // occur if the URL on a site instance is either malformed, or uninitialized.
176 // If it is malformed, then there is no need for better privileges anyways.
177 // If it is uninitialized, but eventually settles on being an a scheme other
178 // than normal webrenderer, the navigation logic will correct us out of band
179 // anyways.
180 if (!url.is_valid())
181 return PRIV_NORMAL;
182
183 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44184 const Extension* extension =
185 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45186 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42187 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45188 if (extension && extension->is_hosted_app())
189 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42190
191 return PRIV_EXTENSION;
192 }
193
194 return PRIV_NORMAL;
195}
196
197RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30198 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46199 extensions::ProcessMap* process_map,
200 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46201 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30202 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46203 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21204 return PRIV_NORMAL;
205
[email protected]6f371442011-11-09 06:45:46206 for (std::set<std::string>::iterator iter = extension_ids.begin();
207 iter != extension_ids.end(); ++iter) {
208 const Extension* extension = service->GetExtensionById(*iter, false);
209 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42210 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45211 if (extension && extension->is_hosted_app())
212 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42213 }
214
[email protected]676f6ab2011-10-19 20:23:21215 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42216}
217
[email protected]eec0b33c2011-12-05 22:09:45218bool IsIsolatedAppInProcess(const GURL& site_url,
219 content::RenderProcessHost* process_host,
220 extensions::ProcessMap* process_map,
221 ExtensionService* service) {
222 std::set<std::string> extension_ids =
223 process_map->GetExtensionsInProcess(process_host->GetID());
224 if (extension_ids.empty())
225 return false;
226
227 for (std::set<std::string>::iterator iter = extension_ids.begin();
228 iter != extension_ids.end(); ++iter) {
229 const Extension* extension = service->GetExtensionById(*iter, false);
230 if (extension &&
231 extension->is_storage_isolated() &&
232 extension->url() == site_url)
233 return true;
234 }
235
236 return false;
237}
238
[email protected]6786bf402011-12-03 15:19:45239bool CertMatchesFilter(const net::X509Certificate& cert,
240 const base::DictionaryValue& filter) {
241 // TODO(markusheintz): This is the minimal required filter implementation.
242 // Implement a better matcher.
243
244 // An empty filter matches any client certificate since no requirements are
245 // specified at all.
246 if (filter.empty())
247 return true;
248
249 std::string common_name;
250 if (filter.GetString("ISSUER.CN", &common_name) &&
251 (cert.issuer().common_name == common_name)) {
252 return true;
253 }
254 return false;
255}
256
[email protected]9dbfff12011-07-01 19:37:07257} // namespace
[email protected]c5dbef02011-05-13 05:06:09258
[email protected]d977f9c2011-03-14 16:10:26259namespace chrome {
260
[email protected]50462bf02011-11-21 19:13:31261content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
262 const content::MainFunctionParams& parameters) {
263 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30264 // Construct the Main browser parts based on the OS type.
265#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31266 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04267#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31268 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30269#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31270 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35271#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31272 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30273#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31274 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04275#else
[email protected]b48c9182011-10-26 18:03:30276 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31277 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30278#endif
279
[email protected]c7480942011-11-08 19:18:27280 // Construct additional browser parts. Stages are called in the order in
281 // which they are added.
[email protected]b48c9182011-10-26 18:03:30282#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31283 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04284#endif
[email protected]c7480942011-11-08 19:18:27285
286#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31287 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27288#endif
289
290#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31291 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27292#endif
293
[email protected]50462bf02011-11-21 19:13:31294 return main_parts;
[email protected]f967b722011-09-07 00:58:04295}
296
[email protected]b45937e2011-10-07 19:49:17297RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
298 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48299#if defined(USE_AURA)
300 return new RenderWidgetHostViewAura(widget);
[email protected]b45937e2011-10-07 19:49:17301#elif defined(OS_WIN)
[email protected]b45937e2011-10-07 19:49:17302 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21303#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17304 return new RenderWidgetHostViewGtk(widget);
305#elif defined(OS_MACOSX)
306 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
307#else
308#error Need to create your platform ViewForWidget here.
309#endif
310}
311
[email protected]74313b42011-08-24 16:51:32312TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
313 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26314#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32315 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21316#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45317 return new TabContentsViewGtk(tab_contents,
318 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32319#elif defined(OS_MACOSX)
320 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32321#else
322#error Need to create your platform TabContentsView here.
323#endif
324}
325
[email protected]f364d1392011-04-08 21:03:10326void ChromeContentBrowserClient::RenderViewHostCreated(
327 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46328
329 SiteInstance* site_instance = render_view_host->site_instance();
330 Profile* profile = Profile::FromBrowserContext(
331 site_instance->browsing_instance()->browser_context());
332
333 new ChromeRenderViewHostObserver(render_view_host,
334 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10335 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26336}
337
[email protected]f3b1a082011-11-18 00:34:30338void ChromeContentBrowserClient::RenderProcessHostCreated(
339 content::RenderProcessHost* host) {
340 int id = host->GetID();
341 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
342 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02343 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30344 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
345 host->GetChannel()->AddFilter(new PrintingMessageFilter());
346 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02347 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30348 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56349#if defined(OS_MACOSX)
350 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
351#endif
[email protected]f3b1a082011-11-18 00:34:30352 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03353 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38354
[email protected]2ccf45c2011-08-19 23:35:50355 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
356 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07357
358 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56359
360 RendererContentSettingRules rules;
361 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
362 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14363}
364
[email protected]97e6c4c2011-05-18 16:08:51365void ChromeContentBrowserClient::PluginProcessHostCreated(
366 PluginProcessHost* host) {
[email protected]f6d2a3e2011-11-17 21:42:40367#if !defined(USE_AURA)
[email protected]97e6c4c2011-05-18 16:08:51368 host->AddFilter(new ChromePluginMessageFilter(host));
[email protected]f6d2a3e2011-11-17 21:42:40369#endif
[email protected]97e6c4c2011-05-18 16:08:51370}
371
[email protected]1fd1a502011-03-30 16:55:56372content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
373 return ChromeWebUIFactory::GetInstance();
374}
375
[email protected]3d7474ff2011-07-27 17:47:37376GURL ChromeContentBrowserClient::GetEffectiveURL(
377 content::BrowserContext* browser_context, const GURL& url) {
378 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08379 // Get the effective URL for the given actual URL. If the URL is part of an
380 // installed app, the effective URL is an extension URL with the ID of that
381 // extension as the host. This has the effect of grouping apps together in
382 // a common SiteInstance.
383 if (!profile || !profile->GetExtensionService())
384 return url;
385
[email protected]615d88f2011-12-13 01:47:44386 const Extension* extension = profile->GetExtensionService()->extensions()->
387 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08388 if (!extension)
389 return url;
390
[email protected]15877ca2011-11-18 22:40:52391 // Bookmark apps do not use the hosted app process model, and should be
392 // treated as normal URLs.
393 if (extension->from_bookmark())
394 return url;
395
[email protected]36fb2c7c2011-04-04 15:49:08396 // If the URL is part of an extension's web extent, convert it to an
397 // extension URL.
398 return extension->GetResourceURL(url.path());
399}
400
[email protected]056ad2a2011-07-12 02:13:55401bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37402 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55403 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52404 // Because we expect to use the effective URL, URLs for hosted apps (apart
405 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55406 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
407 return false;
408
[email protected]3d7474ff2011-07-27 17:47:37409 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55410 if (!profile || !profile->GetExtensionService())
411 return false;
412
[email protected]615d88f2011-12-13 01:47:44413 const Extension* extension = profile->GetExtensionService()->extensions()->
414 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55415 if (!extension)
416 return false;
417
418 // If the URL is part of a hosted app that does not have the background
419 // permission, we want to give each instance its own process to improve
420 // responsiveness.
421 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
422 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
423 return false;
424
425 // Hosted apps that have the background permission must use process per site,
426 // since all instances can make synchronous calls to the background window.
427 // Other extensions should use process per site as well.
428 return true;
429}
430
[email protected]0f012df82011-05-19 14:15:29431bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03432 return url == GURL(chrome::kChromeUICrashURL) ||
433 url == GURL(chrome::kChromeUIKillURL) ||
434 url == GURL(chrome::kChromeUIHangURL) ||
435 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29436}
437
[email protected]46fb9442011-12-09 17:57:47438bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
439 return ProfileIOData::IsHandledURL(url);
440}
441
[email protected]2a5221b2011-09-27 23:07:31442bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30443 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31444 const GURL& site_url) {
445 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30446 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42447 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46448 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31449
[email protected]ffa97602011-11-17 17:55:52450 // Don't allow the Task Manager to share a process with anything else.
451 // Otherwise it can affect the renderers it is observing.
452 // Note: we could create another RenderProcessHostPrivilege bucket for
453 // this to allow multiple chrome://tasks instances to share, but that's
454 // a very unlikely case without serious consequences.
455 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
456 return false;
457
[email protected]8d3132f62011-10-12 07:13:42458 // These may be NULL during tests. In that case, just assume any site can
459 // share any host.
[email protected]6f371442011-11-09 06:45:46460 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31461 return true;
462
[email protected]a8c269a2011-10-25 20:17:22463 // Experimental:
464 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
465 // to share a renderer process. (We could allow pages from the same site or
466 // extensions of the same type to share, if we knew what the given process
467 // was dedicated to. Allowing no sharing is simpler for now.) This may
468 // cause resource exhaustion issues if too many sites are open at once.
469 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
470 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
471 return false;
472
[email protected]eec0b33c2011-12-05 22:09:45473 // An isolated app is only allowed to share with the exact same app in order
474 // to provide complete renderer process isolation. This also works around
475 // issue http://crbug.com/85588, where different isolated apps in the same
476 // process would end up using the first app's storage contexts.
477 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42478 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45479 if (privilege_required == PRIV_ISOLATED)
480 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
481
482 // Otherwise, just make sure the process privilege matches the privilege
483 // required by the site.
484 return GetProcessPrivilege(process_host, process_map, service) ==
485 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31486}
487
[email protected]6f371442011-11-09 06:45:46488void ChromeContentBrowserClient::SiteInstanceGotProcess(
489 SiteInstance* site_instance) {
490 CHECK(site_instance->HasProcess());
491
492 Profile* profile = Profile::FromBrowserContext(
493 site_instance->browsing_instance()->browser_context());
494 ExtensionService* service = profile->GetExtensionService();
495 if (!service)
496 return;
497
498 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44499 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
500 site_instance->site()));
[email protected]6f371442011-11-09 06:45:46501 if (!extension)
502 return;
503
[email protected]6bc04fd82011-12-04 02:29:35504 service->process_map()->Insert(extension->id(),
505 site_instance->GetProcess()->GetID(),
506 site_instance->id());
[email protected]6f371442011-11-09 06:45:46507 BrowserThread::PostTask(
508 BrowserThread::IO, FROM_HERE,
509 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
510 profile->GetExtensionInfoMap(),
511 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35512 site_instance->GetProcess()->GetID(),
513 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46514}
515
516void ChromeContentBrowserClient::SiteInstanceDeleting(
517 SiteInstance* site_instance) {
518 if (!site_instance->HasProcess())
519 return;
520
521 Profile* profile = Profile::FromBrowserContext(
522 site_instance->browsing_instance()->browser_context());
523 ExtensionService* service = profile->GetExtensionService();
524 if (!service)
525 return;
526
527 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44528 service->extensions()->GetExtensionOrAppByURL(
529 ExtensionURLInfo(site_instance->site()));
[email protected]6f371442011-11-09 06:45:46530 if (!extension)
531 return;
532
[email protected]6bc04fd82011-12-04 02:29:35533 service->process_map()->Remove(extension->id(),
534 site_instance->GetProcess()->GetID(),
535 site_instance->id());
[email protected]6f371442011-11-09 06:45:46536 BrowserThread::PostTask(
537 BrowserThread::IO, FROM_HERE,
538 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
539 profile->GetExtensionInfoMap(),
540 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35541 site_instance->GetProcess()->GetID(),
542 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46543}
544
[email protected]e3daf3c2011-10-05 21:17:08545bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
546 const GURL& current_url,
547 const GURL& new_url) {
548 if (current_url.is_empty()) {
549 // Always choose a new process when navigating to extension URLs. The
550 // process grouping logic will combine all of a given extension's pages
551 // into the same process.
552 if (new_url.SchemeIs(chrome::kExtensionScheme))
553 return true;
554
555 return false;
556 }
557
558 // Also, we must switch if one is an extension and the other is not the exact
559 // same extension.
560 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
561 new_url.SchemeIs(chrome::kExtensionScheme)) {
562 if (current_url.GetOrigin() != new_url.GetOrigin())
563 return true;
564 }
565
566 return false;
567}
568
[email protected]763ec4ca2011-04-29 15:48:12569std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
570 const std::string& alias_name) {
571 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
572}
573
[email protected]b80f68432011-05-02 17:22:30574void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
575 CommandLine* command_line, int child_process_id) {
576#if defined(USE_LINUX_BREAKPAD)
577 if (IsCrashReporterEnabled()) {
578 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
579 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
580 }
581#elif defined(OS_MACOSX)
582 if (IsCrashReporterEnabled()) {
583 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
584 child_process_logging::GetClientId());
585 }
586#endif // OS_MACOSX
587
[email protected]f1933792011-06-14 00:49:34588 if (logging::DialogsAreSuppressed())
589 command_line->AppendSwitch(switches::kNoErrorDialogs);
590
[email protected]b80f68432011-05-02 17:22:30591 std::string process_type =
592 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17593 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52594 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30595 FilePath user_data_dir =
596 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
597 if (!user_data_dir.empty())
598 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
599#if defined(OS_CHROMEOS)
600 const std::string& login_profile =
601 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
602 if (!login_profile.empty())
603 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
604#endif
605
[email protected]f3b1a082011-11-18 00:34:30606 content::RenderProcessHost* process =
607 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37608 if (process) {
609 Profile* profile = Profile::FromBrowserContext(
610 process->GetBrowserContext());
611 extensions::ProcessMap* process_map =
612 profile->GetExtensionService()->process_map();
613 if (process_map && process_map->Contains(process->GetID()))
614 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30615
[email protected]a8d851f82011-12-21 00:32:37616 PrefService* prefs = profile->GetPrefs();
617 // Currently this pref is only registered if applied via a policy.
618 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
619 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
620 // Turn this policy into a command line switch.
621 command_line->AppendSwitch(switches::kDisable3DAPIs);
622 }
[email protected]718eab62011-10-05 21:16:52623
[email protected]a8d851f82011-12-21 00:32:37624 // Disable client-side phishing detection in the renderer if it is
625 // disabled in the Profile preferences or the browser process.
626 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
627 !g_browser_process->safe_browsing_detection_service()) {
628 command_line->AppendSwitch(
629 switches::kDisableClientSidePhishingDetection);
630 }
[email protected]8c40da62011-07-13 22:58:46631 }
[email protected]4287a3d2011-06-13 23:56:51632
633 static const char* const kSwitchNames[] = {
634 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48635 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18636 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51637 switches::kAllowScriptingGallery,
638 switches::kAppsCheckoutURL,
639 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31640 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51641 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51642 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51643 switches::kDomAutomationController,
644 switches::kDumpHistogramsOnExit,
645 switches::kEnableClickToPlay,
646 switches::kEnableCrxlessWebApps,
647 switches::kEnableExperimentalExtensionApis,
648 switches::kEnableInBrowserThumbnailing,
649 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12650 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51651 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53652 switches::kEnablePlatformApps,
[email protected]5714ee32011-08-18 01:51:24653 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51654 switches::kEnableSearchProviderApiV2,
655 switches::kEnableWatchdog,
656 switches::kExperimentalSpellcheckerFeatures,
657 switches::kMemoryProfiling,
658 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04659 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51660 switches::kPpapiFlashArgs,
661 switches::kPpapiFlashInProcess,
662 switches::kPpapiFlashPath,
663 switches::kPpapiFlashVersion,
664 switches::kProfilingAtStart,
665 switches::kProfilingFile,
666 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51667 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03668 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51669 };
670
671 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
672 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17673 } else if (process_type == switches::kUtilityProcess) {
674 if (browser_command_line.HasSwitch(
675 switches::kEnableExperimentalExtensionApis)) {
676 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
677 }
[email protected]4287a3d2011-06-13 23:56:51678 } else if (process_type == switches::kPluginProcess) {
679 static const char* const kSwitchNames[] = {
680 #if defined(OS_CHROMEOS)
681 switches::kLoginProfile,
682 #endif
683 switches::kMemoryProfiling,
684 switches::kSilentDumpOnDCHECK,
685 switches::kUserDataDir,
686 };
687
688 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
689 arraysize(kSwitchNames));
690 } else if (process_type == switches::kZygoteProcess) {
691 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51692 switches::kUserDataDir, // Make logs go to the right file.
693 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
694 switches::kPpapiFlashInProcess,
695 switches::kPpapiFlashPath,
696 switches::kPpapiFlashVersion,
697 };
698
699 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
700 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30701 }
[email protected]6f08af82011-09-15 01:19:03702
703 // The command line switch kEnableBenchmarking needs to be specified along
704 // with the kEnableStatsTable switch to ensure that the stats table global
705 // is initialized correctly.
706 if (command_line->HasSwitch(switches::kEnableBenchmarking))
707 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30708}
709
710std::string ChromeContentBrowserClient::GetApplicationLocale() {
711 return g_browser_process->GetApplicationLocale();
712}
713
[email protected]597a867b2011-11-18 18:31:20714std::string ChromeContentBrowserClient::GetAcceptLangs(
715 content::BrowserContext* context) {
716 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37717 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08718}
719
[email protected]ac55e292011-06-24 05:16:08720SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22721 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08722 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
723}
724
[email protected]a2176792011-05-08 19:30:49725bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09726 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19727 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09728 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
730 ProfileIOData* io_data =
731 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05732 return io_data->GetCookieSettings()->
733 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49734}
735
[email protected]ed24fad2011-05-10 22:44:01736bool ChromeContentBrowserClient::AllowGetCookie(
737 const GURL& url,
738 const GURL& first_party,
739 const net::CookieList& cookie_list,
740 const content::ResourceContext& context,
741 int render_process_id,
742 int render_view_id) {
743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32744 ProfileIOData* io_data =
745 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05746 bool allow = io_data->GetCookieSettings()->
747 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01748
[email protected]8093a542011-05-13 07:29:32749 BrowserThread::PostTask(
750 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03751 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
752 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01753 return allow;
754}
755
756bool ChromeContentBrowserClient::AllowSetCookie(
757 const GURL& url,
758 const GURL& first_party,
759 const std::string& cookie_line,
760 const content::ResourceContext& context,
761 int render_process_id,
762 int render_view_id,
763 net::CookieOptions* options) {
764 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32765 ProfileIOData* io_data =
766 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01767
[email protected]30fde822011-10-28 09:49:05768 CookieSettings* cookie_settings = io_data->GetCookieSettings();
769 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
770
771 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09772 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01773
[email protected]8093a542011-05-13 07:29:32774 BrowserThread::PostTask(
775 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03776 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
777 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01778 return allow;
779}
780
[email protected]d5a19162011-06-30 18:51:54781bool ChromeContentBrowserClient::AllowSaveLocalState(
782 const content::ResourceContext& context) {
783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
784 ProfileIOData* io_data =
785 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
786 return !io_data->clear_local_state_on_exit()->GetValue();
787}
788
[email protected]5c5a88e2011-11-12 00:45:35789bool ChromeContentBrowserClient::AllowWorkerDatabase(
790 int worker_route_id,
791 const GURL& url,
792 const string16& name,
793 const string16& display_name,
794 unsigned long estimated_size,
795 WorkerProcessHost* worker_process_host) {
796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
797 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
798 worker_process_host->resource_context()->GetUserData(NULL));
799 CookieSettings* cookie_settings = io_data->GetCookieSettings();
800 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
801
802 // Record access to database for potential display in UI: Find the worker
803 // instance and forward the message to all attached documents.
804 WorkerProcessHost::Instances::const_iterator i;
805 for (i = worker_process_host->instances().begin();
806 i != worker_process_host->instances().end(); ++i) {
807 if (i->worker_route_id() != worker_route_id)
808 continue;
809 const WorkerDocumentSet::DocumentInfoSet& documents =
810 i->worker_document_set()->documents();
811 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
812 documents.begin(); doc != documents.end(); ++doc) {
813 BrowserThread::PostTask(
814 BrowserThread::UI, FROM_HERE,
815 base::Bind(
816 &TabSpecificContentSettings::WebDatabaseAccessed,
817 doc->render_process_id(), doc->render_view_id(),
818 url, name, display_name, !allow));
819 }
820 break;
821 }
822
823 return allow;
824}
825
826bool ChromeContentBrowserClient::AllowWorkerFileSystem(
827 int worker_route_id,
828 const GURL& url,
829 WorkerProcessHost* worker_process_host) {
830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
831 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
832 worker_process_host->resource_context()->GetUserData(NULL));
833 CookieSettings* cookie_settings = io_data->GetCookieSettings();
834 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
835
836 // Record access to file system for potential display in UI: Find the worker
837 // instance and forward the message to all attached documents.
838 WorkerProcessHost::Instances::const_iterator i;
839 for (i = worker_process_host->instances().begin();
840 i != worker_process_host->instances().end(); ++i) {
841 if (i->worker_route_id() != worker_route_id)
842 continue;
843 const WorkerDocumentSet::DocumentInfoSet& documents =
844 i->worker_document_set()->documents();
845 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
846 documents.begin(); doc != documents.end(); ++doc) {
847 BrowserThread::PostTask(
848 BrowserThread::UI, FROM_HERE,
849 base::Bind(
850 &TabSpecificContentSettings::FileSystemAccessed,
851 doc->render_process_id(), doc->render_view_id(), url, !allow));
852 }
853 break;
854 }
855
856 return allow;
857}
858
[email protected]6133f922011-07-01 21:34:34859net::URLRequestContext*
860ChromeContentBrowserClient::OverrideRequestContextForURL(
861 const GURL& url, const content::ResourceContext& context) {
862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
863 if (url.SchemeIs(chrome::kExtensionScheme)) {
864 ProfileIOData* io_data =
865 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
866 return io_data->extensions_request_context();
867 }
868
869 return NULL;
870}
871
[email protected]317f96c92011-05-31 06:53:41872QuotaPermissionContext*
873ChromeContentBrowserClient::CreateQuotaPermissionContext() {
874 return new ChromeQuotaPermissionContext();
875}
876
[email protected]a0ce3282011-08-19 20:49:52877void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42878 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42879}
880
[email protected]a0ce3282011-08-19 20:49:52881void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52882 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52883}
884
[email protected]848dd042011-06-04 18:24:03885void ChromeContentBrowserClient::AllowCertificateError(
886 SSLCertErrorHandler* handler,
887 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58888 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41889 // If the tab is being prerendered, cancel the prerender and the request.
890 TabContents* tab = tab_util::GetTabContentsByID(
891 handler->render_process_host_id(),
892 handler->tab_contents_id());
893 if (!tab) {
894 NOTREACHED();
895 return;
896 }
897 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50898 prerender::PrerenderManagerFactory::GetForProfile(
899 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41900 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
901 if (prerender_manager->prerender_tracker()->TryCancel(
902 handler->render_process_host_id(),
903 handler->tab_contents_id(),
904 prerender::FINAL_STATUS_SSL_ERROR)) {
905 handler->CancelRequest();
906 return;
907 }
908 }
909
910 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03911 SSLBlockingPage* blocking_page = new SSLBlockingPage(
912 handler, overridable, callback);
913 blocking_page->Show();
914}
915
[email protected]c99c442e2011-08-24 11:37:30916void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45917 int render_process_id,
918 int render_view_id,
919 SSLClientAuthHandler* handler) {
920 TabContents* tab = tab_util::GetTabContentsByID(
921 render_process_id, render_view_id);
922 if (!tab) {
923 NOTREACHED();
924 return;
925 }
926
[email protected]6786bf402011-12-03 15:19:45927 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
928 GURL requesting_url("https://" + cert_request_info->host_and_port);
929 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
930 << cert_request_info->host_and_port;
931
932 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
933 DCHECK(profile);
934 scoped_ptr<Value> filter(
935 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
936 requesting_url,
937 requesting_url,
938 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
939 std::string(), NULL));
940
941 if (filter.get()) {
942 // Try to automatically select a client certificate.
943 if (filter->IsType(Value::TYPE_DICTIONARY)) {
944 DictionaryValue* filter_dict =
945 static_cast<DictionaryValue*>(filter.get());
946
947 const std::vector<scoped_refptr<net::X509Certificate> >&
948 all_client_certs = cert_request_info->client_certs;
949 for (size_t i = 0; i < all_client_certs.size(); ++i) {
950 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
951 // Use the first certificate that is matched by the filter.
952 handler->CertificateSelected(all_client_certs[i]);
953 return;
954 }
955 }
956 } else {
957 NOTREACHED();
958 }
959 }
960
[email protected]8ec26472011-06-06 16:52:45961 TabContentsWrapper* wrapper =
962 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45963 if (!wrapper) {
[email protected]6786bf402011-12-03 15:19:45964 // If there is no TabContentsWrapper for the given TabContents then we can't
965 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14966 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45967 handler->CertificateSelected(NULL);
968 return;
969 }
970 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45971}
972
973void ChromeContentBrowserClient::AddNewCertificate(
974 net::URLRequest* request,
975 net::X509Certificate* cert,
976 int render_process_id,
977 int render_view_id) {
978 // The handler will run the UI and delete itself when it's finished.
979 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
980}
981
[email protected]941623e2011-06-07 23:06:04982void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
983 const GURL& source_origin,
984 int callback_context,
985 int render_process_id,
986 int render_view_id) {
987 RenderViewHost* rvh = RenderViewHost::FromID(
988 render_process_id, render_view_id);
989 if (!rvh) {
990 NOTREACHED();
991 return;
992 }
993
[email protected]f3b1a082011-11-18 00:34:30994 content::RenderProcessHost* process = rvh->process();
995 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04996 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37997 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04998 service->RequestPermission(
999 source_origin, render_process_id, render_view_id, callback_context,
1000 tab_util::GetTabContentsByID(render_process_id, render_view_id));
1001}
1002
1003WebKit::WebNotificationPresenter::Permission
1004 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021005 const GURL& source_origin,
1006 const content::ResourceContext& context,
1007 int render_process_id) {
[email protected]941623e2011-06-07 23:06:041008 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1009 ProfileIOData* io_data =
1010 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1011
[email protected]34eec7ffe32011-11-02 23:49:021012 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1013 source_origin, render_process_id,
1014 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041015 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041016
1017 // Fall back to the regular notification preferences, which works on an
1018 // origin basis.
1019 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371020 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041021 WebKit::WebNotificationPresenter::PermissionNotAllowed;
1022}
1023
1024void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171025 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041026 int render_process_id,
1027 int render_view_id,
1028 bool worker) {
1029 RenderViewHost* rvh = RenderViewHost::FromID(
1030 render_process_id, render_view_id);
1031 if (!rvh) {
1032 NOTREACHED();
1033 return;
1034 }
1035
[email protected]f3b1a082011-11-18 00:34:301036 content::RenderProcessHost* process = rvh->process();
1037 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041038 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371039 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041040 service->ShowDesktopNotification(
1041 params, render_process_id, render_view_id,
1042 worker ? DesktopNotificationService::WorkerNotification :
1043 DesktopNotificationService::PageNotification);
1044}
1045
1046void ChromeContentBrowserClient::CancelDesktopNotification(
1047 int render_process_id,
1048 int render_view_id,
1049 int notification_id) {
1050 RenderViewHost* rvh = RenderViewHost::FromID(
1051 render_process_id, render_view_id);
1052 if (!rvh) {
1053 NOTREACHED();
1054 return;
1055 }
1056
[email protected]f3b1a082011-11-18 00:34:301057 content::RenderProcessHost* process = rvh->process();
1058 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041059 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371060 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041061 service->CancelDesktopNotification(
1062 render_process_id, render_view_id, notification_id);
1063}
1064
[email protected]9f3fba52011-06-08 20:37:191065bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021066 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191067 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021068 const content::ResourceContext& context,
1069 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191070 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1071 // If the opener is trying to create a background window but doesn't have
1072 // the appropriate permission, fail the attempt.
1073 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1074 ProfileIOData* io_data =
1075 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021076 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1077 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191078 }
1079 return true;
1080}
1081
1082std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1083 const GURL& url, const content::ResourceContext& context) {
1084 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1085 // Check if it's an extension-created worker, in which case we want to use
1086 // the name of the extension.
1087 ProfileIOData* io_data =
1088 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1089 const Extension* extension =
1090 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1091 return extension ? extension->name() : std::string();
1092}
1093
[email protected]3cb054e62011-06-13 05:21:171094ResourceDispatcherHost*
1095 ChromeContentBrowserClient::GetResourceDispatcherHost() {
1096 return g_browser_process->resource_dispatcher_host();
1097}
1098
1099ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1100 return g_browser_process->clipboard();
1101}
1102
[email protected]8f6a3b852011-07-19 16:48:561103MHTMLGenerationManager*
1104 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1105 return g_browser_process->mhtml_generation_manager();
1106}
1107
[email protected]ae6e9912011-07-27 01:18:281108net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1109 return g_browser_process->net_log();
1110}
1111
[email protected]3bc0b562011-08-24 23:51:041112speech_input::SpeechInputManager*
1113 ChromeContentBrowserClient::GetSpeechInputManager() {
1114 return speech_input::ChromeSpeechInputManager::GetInstance();
1115}
1116
[email protected]32538d92011-08-25 00:09:231117AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1118 return new ChromeAccessTokenStore();
1119}
1120
[email protected]dbae6b02011-06-29 23:51:411121bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1122 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1123 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1124}
1125
[email protected]5092c282011-10-29 21:48:371126WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
1127 return RenderViewHostDelegateHelper::GetWebkitPrefs(rvh);
[email protected]181a95ee2011-07-12 19:26:361128}
1129
1130void ChromeContentBrowserClient::UpdateInspectorSetting(
1131 RenderViewHost* rvh, const std::string& key, const std::string& value) {
1132 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]f3b1a082011-11-18 00:34:301133 rvh->process()->GetBrowserContext(), key, value);
[email protected]181a95ee2011-07-12 19:26:361134}
1135
1136void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
1137 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]f3b1a082011-11-18 00:34:301138 rvh->process()->GetBrowserContext());
[email protected]181a95ee2011-07-12 19:26:361139}
1140
[email protected]b8148ac2011-07-13 22:03:251141void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1142 BrowserURLHandler* handler) {
1143 // Add the default URL handlers.
1144 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1145 BrowserURLHandler::null_handler());
1146 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1147 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1148
[email protected]b3adbd02011-11-30 22:23:271149 // about: handler. Must come before chrome: handler, since it will
1150 // rewrite about: urls to chrome: URLs and then expect chrome: to
1151 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251152 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1153 BrowserURLHandler::null_handler());
1154 // chrome: & friends.
1155 handler->AddHandlerPair(&HandleWebUI,
1156 BrowserURLHandler::null_handler());
1157}
1158
1159void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371160 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301161 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251162 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1163 BrowsingDataRemover::EVERYTHING,
1164 base::Time());
1165 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1166 // BrowsingDataRemover takes care of deleting itself when done.
1167}
1168
1169void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371170 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301171 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251172 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1173 BrowsingDataRemover::EVERYTHING,
1174 base::Time());
[email protected]dceaa912011-09-06 17:17:231175 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251176 remover->Remove(remove_mask);
1177 // BrowsingDataRemover takes care of deleting itself when done.
1178}
1179
[email protected]e1d16eb92011-08-18 23:19:321180FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1181 return download_util::GetDefaultDownloadDirectory();
1182}
1183
[email protected]c9b6eb62011-10-18 20:49:391184std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1185 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1186}
1187
[email protected]e60c0232011-11-11 19:56:351188#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301189int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521190 const CommandLine& command_line) {
1191 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071192 ExtensionCrashHandlerHostLinux* crash_handler =
1193 ExtensionCrashHandlerHostLinux::GetInstance();
1194 return crash_handler->GetDeathSignalSocket();
1195 }
1196
[email protected]718eab62011-10-05 21:16:521197 std::string process_type =
1198 command_line.GetSwitchValueASCII(switches::kProcessType);
1199
1200 if (process_type == switches::kRendererProcess)
1201 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1202
[email protected]b80f68432011-05-02 17:22:301203 if (process_type == switches::kPluginProcess)
1204 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1205
1206 if (process_type == switches::kPpapiPluginProcess)
1207 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1208
1209 if (process_type == switches::kGpuProcess)
1210 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1211
1212 return -1;
1213}
[email protected]e60c0232011-11-11 19:56:351214#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301215
[email protected]4a65826d2011-08-25 16:04:011216#if defined(OS_WIN)
1217const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1218 return chrome::kBrowserResourcesDll;
1219}
1220#endif
1221
[email protected]37a72af2011-06-13 05:42:011222#if defined(USE_NSS)
1223crypto::CryptoModuleBlockingPasswordDelegate*
1224 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1225 const GURL& url) {
1226 return browser::NewCryptoModuleBlockingDialogDelegate(
1227 browser::kCryptoModulePasswordKeygen, url.host());
1228}
1229#endif
1230
[email protected]d977f9c2011-03-14 16:10:261231} // namespace chrome