blob: ced30b2b0de1e1383f14e914888dc45ad05f6c6f [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]f1933792011-06-14 00:49:3460#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1261#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3862#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0963#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2564#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0965#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5166#include "content/browser/plugin_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2667#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4968#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0969#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4170#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4571#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1272#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3273#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3674#include "content/browser/worker_host/worker_process_host.h"
[email protected]b48c9182011-10-26 18:03:3075#include "content/public/browser/browser_main_parts.h"
[email protected]f3b1a082011-11-18 00:34:3076#include "content/public/browser/render_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3977#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3478#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0179#include "net/base/cookie_monster.h"
80#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3981#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0882#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2683
[email protected]b48c9182011-10-26 18:03:3084#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3885#include "chrome/browser/chrome_browser_main_win.h"
86#elif defined(OS_MACOSX)
87#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:3088#elif defined(OS_CHROMEOS)
89#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3590#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3091#include "chrome/browser/chrome_browser_main_linux.h"
92#elif defined(OS_POSIX)
93#include "chrome/browser/chrome_browser_main_posix.h"
94#endif
95
[email protected]b48c9182011-10-26 18:03:3096#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:3197#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:3898#endif
99
[email protected]c7480942011-11-08 19:18:27100#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31101#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27102#endif
103
104#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31105#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
106#endif
107
[email protected]e60c0232011-11-11 19:56:35108#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30109#include "base/linux_util.h"
110#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43111#endif
[email protected]b80f68432011-05-02 17:22:30112
[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]9bce7772011-11-16 01:24:45116#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]74313b42011-08-24 16:51:32117#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
118#elif defined(OS_MACOSX)
119#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32120#endif
121
[email protected]37a72af2011-06-13 05:42:01122#if defined(USE_NSS)
123#include "chrome/browser/ui/crypto_module_password_dialog.h"
124#endif
125
[email protected]91ad1472011-10-27 15:09:48126#if defined(USE_AURA)
127#include "content/browser/renderer_host/render_widget_host_view_aura.h"
[email protected]b45937e2011-10-07 19:49:17128#elif defined(OS_WIN)
[email protected]b45937e2011-10-07 19:49:17129#include "content/browser/renderer_host/render_widget_host_view_win.h"
[email protected]c92f4ed2011-10-21 19:50:21130#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17131#include "content/browser/renderer_host/render_widget_host_view_gtk.h"
132#elif defined(OS_MACOSX)
133#include "content/browser/renderer_host/render_widget_host_view_mac.h"
134#endif
135
[email protected]631bb742011-11-02 11:29:39136using content::BrowserThread;
137
[email protected]c5dbef02011-05-13 05:06:09138namespace {
139
[email protected]b8148ac2011-07-13 22:03:25140// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42141bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37142 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25143 return false;
144
145 // Special case the new tab page. In older versions of Chrome, the new tab
146 // page was hosted at chrome-internal:<blah>. This might be in people's saved
147 // sessions or bookmarks, so we say any URL with that scheme triggers the new
148 // tab page.
149 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
150 // Rewrite it with the proper new tab URL.
151 *url = GURL(chrome::kChromeUINewTabURL);
152 }
153
154 return true;
155}
156
[email protected]8d3132f62011-10-12 07:13:42157// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
158// below. Extension, and isolated apps require different privileges to be
159// granted to their RenderProcessHosts. This classification allows us to make
160// sure URLs are served by hosts with the right set of privileges.
161enum RenderProcessHostPrivilege {
162 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45163 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42164 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45165 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42166};
167
168RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
169 const GURL& url,
170 ExtensionService* service) {
171 // Default to a normal renderer cause it is lower privileged. This should only
172 // occur if the URL on a site instance is either malformed, or uninitialized.
173 // If it is malformed, then there is no need for better privileges anyways.
174 // If it is uninitialized, but eventually settles on being an a scheme other
175 // than normal webrenderer, the navigation logic will correct us out of band
176 // anyways.
177 if (!url.is_valid())
178 return PRIV_NORMAL;
179
180 if (url.SchemeIs(chrome::kExtensionScheme)) {
181 const Extension* extension = service->GetExtensionByURL(url);
[email protected]eec0b33c2011-12-05 22:09:45182 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42183 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45184 if (extension && extension->is_hosted_app())
185 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42186
187 return PRIV_EXTENSION;
188 }
189
190 return PRIV_NORMAL;
191}
192
193RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30194 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46195 extensions::ProcessMap* process_map,
196 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46197 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30198 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46199 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21200 return PRIV_NORMAL;
201
[email protected]6f371442011-11-09 06:45:46202 for (std::set<std::string>::iterator iter = extension_ids.begin();
203 iter != extension_ids.end(); ++iter) {
204 const Extension* extension = service->GetExtensionById(*iter, false);
205 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42206 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45207 if (extension && extension->is_hosted_app())
208 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42209 }
210
[email protected]676f6ab2011-10-19 20:23:21211 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42212}
213
[email protected]eec0b33c2011-12-05 22:09:45214bool IsIsolatedAppInProcess(const GURL& site_url,
215 content::RenderProcessHost* process_host,
216 extensions::ProcessMap* process_map,
217 ExtensionService* service) {
218 std::set<std::string> extension_ids =
219 process_map->GetExtensionsInProcess(process_host->GetID());
220 if (extension_ids.empty())
221 return false;
222
223 for (std::set<std::string>::iterator iter = extension_ids.begin();
224 iter != extension_ids.end(); ++iter) {
225 const Extension* extension = service->GetExtensionById(*iter, false);
226 if (extension &&
227 extension->is_storage_isolated() &&
228 extension->url() == site_url)
229 return true;
230 }
231
232 return false;
233}
234
[email protected]6786bf402011-12-03 15:19:45235bool CertMatchesFilter(const net::X509Certificate& cert,
236 const base::DictionaryValue& filter) {
237 // TODO(markusheintz): This is the minimal required filter implementation.
238 // Implement a better matcher.
239
240 // An empty filter matches any client certificate since no requirements are
241 // specified at all.
242 if (filter.empty())
243 return true;
244
245 std::string common_name;
246 if (filter.GetString("ISSUER.CN", &common_name) &&
247 (cert.issuer().common_name == common_name)) {
248 return true;
249 }
250 return false;
251}
252
[email protected]9dbfff12011-07-01 19:37:07253} // namespace
[email protected]c5dbef02011-05-13 05:06:09254
[email protected]d977f9c2011-03-14 16:10:26255namespace chrome {
256
[email protected]50462bf02011-11-21 19:13:31257content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
258 const content::MainFunctionParams& parameters) {
259 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30260 // Construct the Main browser parts based on the OS type.
261#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31262 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04263#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31264 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30265#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31266 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35267#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31268 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30269#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31270 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04271#else
[email protected]b48c9182011-10-26 18:03:30272 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31273 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30274#endif
275
[email protected]c7480942011-11-08 19:18:27276 // Construct additional browser parts. Stages are called in the order in
277 // which they are added.
[email protected]b48c9182011-10-26 18:03:30278#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31279 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04280#endif
[email protected]c7480942011-11-08 19:18:27281
282#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31283 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27284#endif
285
286#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31287 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27288#endif
289
[email protected]50462bf02011-11-21 19:13:31290 return main_parts;
[email protected]f967b722011-09-07 00:58:04291}
292
[email protected]b45937e2011-10-07 19:49:17293RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
294 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48295#if defined(USE_AURA)
296 return new RenderWidgetHostViewAura(widget);
[email protected]b45937e2011-10-07 19:49:17297#elif defined(OS_WIN)
[email protected]b45937e2011-10-07 19:49:17298 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21299#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17300 return new RenderWidgetHostViewGtk(widget);
301#elif defined(OS_MACOSX)
302 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
303#else
304#error Need to create your platform ViewForWidget here.
305#endif
306}
307
[email protected]74313b42011-08-24 16:51:32308TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
309 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26310#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32311 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21312#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45313 return new TabContentsViewGtk(tab_contents,
314 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32315#elif defined(OS_MACOSX)
316 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32317#else
318#error Need to create your platform TabContentsView here.
319#endif
320}
321
[email protected]f364d1392011-04-08 21:03:10322void ChromeContentBrowserClient::RenderViewHostCreated(
323 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46324
325 SiteInstance* site_instance = render_view_host->site_instance();
326 Profile* profile = Profile::FromBrowserContext(
327 site_instance->browsing_instance()->browser_context());
328
329 new ChromeRenderViewHostObserver(render_view_host,
330 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10331 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26332}
333
[email protected]f3b1a082011-11-18 00:34:30334void ChromeContentBrowserClient::RenderProcessHostCreated(
335 content::RenderProcessHost* host) {
336 int id = host->GetID();
337 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
338 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02339 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30340 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
341 host->GetChannel()->AddFilter(new PrintingMessageFilter());
342 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02343 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30344 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
345 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03346 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38347
[email protected]2ccf45c2011-08-19 23:35:50348 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
349 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07350
351 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56352
353 RendererContentSettingRules rules;
354 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
355 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14356}
357
[email protected]97e6c4c2011-05-18 16:08:51358void ChromeContentBrowserClient::PluginProcessHostCreated(
359 PluginProcessHost* host) {
[email protected]f6d2a3e2011-11-17 21:42:40360#if !defined(USE_AURA)
[email protected]97e6c4c2011-05-18 16:08:51361 host->AddFilter(new ChromePluginMessageFilter(host));
[email protected]f6d2a3e2011-11-17 21:42:40362#endif
[email protected]97e6c4c2011-05-18 16:08:51363}
364
[email protected]1fd1a502011-03-30 16:55:56365content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
366 return ChromeWebUIFactory::GetInstance();
367}
368
[email protected]3d7474ff2011-07-27 17:47:37369GURL ChromeContentBrowserClient::GetEffectiveURL(
370 content::BrowserContext* browser_context, const GURL& url) {
371 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08372 // Get the effective URL for the given actual URL. If the URL is part of an
373 // installed app, the effective URL is an extension URL with the ID of that
374 // extension as the host. This has the effect of grouping apps together in
375 // a common SiteInstance.
376 if (!profile || !profile->GetExtensionService())
377 return url;
378
379 const Extension* extension =
380 profile->GetExtensionService()->GetExtensionByWebExtent(url);
381 if (!extension)
382 return url;
383
[email protected]15877ca2011-11-18 22:40:52384 // Bookmark apps do not use the hosted app process model, and should be
385 // treated as normal URLs.
386 if (extension->from_bookmark())
387 return url;
388
[email protected]36fb2c7c2011-04-04 15:49:08389 // If the URL is part of an extension's web extent, convert it to an
390 // extension URL.
391 return extension->GetResourceURL(url.path());
392}
393
[email protected]056ad2a2011-07-12 02:13:55394bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37395 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55396 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52397 // Because we expect to use the effective URL, URLs for hosted apps (apart
398 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55399 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
400 return false;
401
[email protected]3d7474ff2011-07-27 17:47:37402 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55403 if (!profile || !profile->GetExtensionService())
404 return false;
405
406 const Extension* extension =
407 profile->GetExtensionService()->GetExtensionByURL(effective_url);
408 if (!extension)
409 return false;
410
411 // If the URL is part of a hosted app that does not have the background
412 // permission, we want to give each instance its own process to improve
413 // responsiveness.
414 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
415 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
416 return false;
417
418 // Hosted apps that have the background permission must use process per site,
419 // since all instances can make synchronous calls to the background window.
420 // Other extensions should use process per site as well.
421 return true;
422}
423
[email protected]0f012df82011-05-19 14:15:29424bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03425 return url == GURL(chrome::kChromeUICrashURL) ||
426 url == GURL(chrome::kChromeUIKillURL) ||
427 url == GURL(chrome::kChromeUIHangURL) ||
428 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29429}
430
[email protected]2a5221b2011-09-27 23:07:31431bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30432 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31433 const GURL& site_url) {
434 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30435 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42436 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46437 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31438
[email protected]ffa97602011-11-17 17:55:52439 // Don't allow the Task Manager to share a process with anything else.
440 // Otherwise it can affect the renderers it is observing.
441 // Note: we could create another RenderProcessHostPrivilege bucket for
442 // this to allow multiple chrome://tasks instances to share, but that's
443 // a very unlikely case without serious consequences.
444 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
445 return false;
446
[email protected]8d3132f62011-10-12 07:13:42447 // These may be NULL during tests. In that case, just assume any site can
448 // share any host.
[email protected]6f371442011-11-09 06:45:46449 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31450 return true;
451
[email protected]a8c269a2011-10-25 20:17:22452 // Experimental:
453 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
454 // to share a renderer process. (We could allow pages from the same site or
455 // extensions of the same type to share, if we knew what the given process
456 // was dedicated to. Allowing no sharing is simpler for now.) This may
457 // cause resource exhaustion issues if too many sites are open at once.
458 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
459 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
460 return false;
461
[email protected]eec0b33c2011-12-05 22:09:45462 // An isolated app is only allowed to share with the exact same app in order
463 // to provide complete renderer process isolation. This also works around
464 // issue http://crbug.com/85588, where different isolated apps in the same
465 // process would end up using the first app's storage contexts.
466 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42467 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45468 if (privilege_required == PRIV_ISOLATED)
469 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
470
471 // Otherwise, just make sure the process privilege matches the privilege
472 // required by the site.
473 return GetProcessPrivilege(process_host, process_map, service) ==
474 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31475}
476
[email protected]6f371442011-11-09 06:45:46477void ChromeContentBrowserClient::SiteInstanceGotProcess(
478 SiteInstance* site_instance) {
479 CHECK(site_instance->HasProcess());
480
481 Profile* profile = Profile::FromBrowserContext(
482 site_instance->browsing_instance()->browser_context());
483 ExtensionService* service = profile->GetExtensionService();
484 if (!service)
485 return;
486
487 const Extension* extension =
488 service->GetExtensionByURL(site_instance->site());
489 if (!extension)
490 extension = service->GetExtensionByWebExtent(site_instance->site());
491 if (!extension)
492 return;
493
[email protected]6bc04fd82011-12-04 02:29:35494 service->process_map()->Insert(extension->id(),
495 site_instance->GetProcess()->GetID(),
496 site_instance->id());
[email protected]6f371442011-11-09 06:45:46497 BrowserThread::PostTask(
498 BrowserThread::IO, FROM_HERE,
499 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
500 profile->GetExtensionInfoMap(),
501 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35502 site_instance->GetProcess()->GetID(),
503 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46504}
505
506void ChromeContentBrowserClient::SiteInstanceDeleting(
507 SiteInstance* site_instance) {
508 if (!site_instance->HasProcess())
509 return;
510
511 Profile* profile = Profile::FromBrowserContext(
512 site_instance->browsing_instance()->browser_context());
513 ExtensionService* service = profile->GetExtensionService();
514 if (!service)
515 return;
516
517 const Extension* extension =
518 service->GetExtensionByURL(site_instance->site());
519 if (!extension)
520 extension = service->GetExtensionByWebExtent(site_instance->site());
521 if (!extension)
522 return;
523
[email protected]6bc04fd82011-12-04 02:29:35524 service->process_map()->Remove(extension->id(),
525 site_instance->GetProcess()->GetID(),
526 site_instance->id());
[email protected]6f371442011-11-09 06:45:46527 BrowserThread::PostTask(
528 BrowserThread::IO, FROM_HERE,
529 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
530 profile->GetExtensionInfoMap(),
531 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35532 site_instance->GetProcess()->GetID(),
533 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46534}
535
[email protected]e3daf3c2011-10-05 21:17:08536bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
537 const GURL& current_url,
538 const GURL& new_url) {
539 if (current_url.is_empty()) {
540 // Always choose a new process when navigating to extension URLs. The
541 // process grouping logic will combine all of a given extension's pages
542 // into the same process.
543 if (new_url.SchemeIs(chrome::kExtensionScheme))
544 return true;
545
546 return false;
547 }
548
549 // Also, we must switch if one is an extension and the other is not the exact
550 // same extension.
551 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
552 new_url.SchemeIs(chrome::kExtensionScheme)) {
553 if (current_url.GetOrigin() != new_url.GetOrigin())
554 return true;
555 }
556
557 return false;
558}
559
[email protected]763ec4ca2011-04-29 15:48:12560std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
561 const std::string& alias_name) {
562 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
563}
564
[email protected]b80f68432011-05-02 17:22:30565void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
566 CommandLine* command_line, int child_process_id) {
567#if defined(USE_LINUX_BREAKPAD)
568 if (IsCrashReporterEnabled()) {
569 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
570 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
571 }
572#elif defined(OS_MACOSX)
573 if (IsCrashReporterEnabled()) {
574 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
575 child_process_logging::GetClientId());
576 }
577#endif // OS_MACOSX
578
[email protected]f1933792011-06-14 00:49:34579 if (logging::DialogsAreSuppressed())
580 command_line->AppendSwitch(switches::kNoErrorDialogs);
581
[email protected]b80f68432011-05-02 17:22:30582 std::string process_type =
583 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17584 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52585 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30586 FilePath user_data_dir =
587 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
588 if (!user_data_dir.empty())
589 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
590#if defined(OS_CHROMEOS)
591 const std::string& login_profile =
592 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
593 if (!login_profile.empty())
594 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
595#endif
596
[email protected]f3b1a082011-11-18 00:34:30597 content::RenderProcessHost* process =
598 content::RenderProcessHost::FromID(child_process_id);
[email protected]b80f68432011-05-02 17:22:30599
[email protected]f3b1a082011-11-18 00:34:30600 Profile* profile = Profile::FromBrowserContext(
601 process->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46602 extensions::ProcessMap* process_map =
603 profile->GetExtensionService()->process_map();
[email protected]f3b1a082011-11-18 00:34:30604 if (process_map && process_map->Contains(process->GetID()))
[email protected]718eab62011-10-05 21:16:52605 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]718eab62011-10-05 21:16:52606
[email protected]3d7474ff2011-07-27 17:47:37607 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30608 // Currently this pref is only registered if applied via a policy.
609 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
610 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
611 // Turn this policy into a command line switch.
612 command_line->AppendSwitch(switches::kDisable3DAPIs);
613 }
614
615 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46616 // in the Profile preferences or the browser process.
617 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
618 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30619 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46620 }
[email protected]4287a3d2011-06-13 23:56:51621
622 static const char* const kSwitchNames[] = {
623 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48624 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51625 switches::kAllowScriptingGallery,
626 switches::kAppsCheckoutURL,
627 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31628 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51629 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51630 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51631 switches::kDomAutomationController,
632 switches::kDumpHistogramsOnExit,
633 switches::kEnableClickToPlay,
634 switches::kEnableCrxlessWebApps,
635 switches::kEnableExperimentalExtensionApis,
636 switches::kEnableInBrowserThumbnailing,
637 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12638 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51639 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53640 switches::kEnablePlatformApps,
[email protected]5714ee32011-08-18 01:51:24641 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51642 switches::kEnableSearchProviderApiV2,
643 switches::kEnableWatchdog,
644 switches::kExperimentalSpellcheckerFeatures,
645 switches::kMemoryProfiling,
646 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04647 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51648 switches::kPpapiFlashArgs,
649 switches::kPpapiFlashInProcess,
650 switches::kPpapiFlashPath,
651 switches::kPpapiFlashVersion,
652 switches::kProfilingAtStart,
653 switches::kProfilingFile,
654 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51655 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03656 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51657 };
658
659 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
660 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17661 } else if (process_type == switches::kUtilityProcess) {
662 if (browser_command_line.HasSwitch(
663 switches::kEnableExperimentalExtensionApis)) {
664 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
665 }
[email protected]4287a3d2011-06-13 23:56:51666 } else if (process_type == switches::kPluginProcess) {
667 static const char* const kSwitchNames[] = {
668 #if defined(OS_CHROMEOS)
669 switches::kLoginProfile,
670 #endif
671 switches::kMemoryProfiling,
672 switches::kSilentDumpOnDCHECK,
673 switches::kUserDataDir,
674 };
675
676 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
677 arraysize(kSwitchNames));
678 } else if (process_type == switches::kZygoteProcess) {
679 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51680 switches::kUserDataDir, // Make logs go to the right file.
681 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
682 switches::kPpapiFlashInProcess,
683 switches::kPpapiFlashPath,
684 switches::kPpapiFlashVersion,
685 };
686
687 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
688 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30689 }
[email protected]6f08af82011-09-15 01:19:03690
691 // The command line switch kEnableBenchmarking needs to be specified along
692 // with the kEnableStatsTable switch to ensure that the stats table global
693 // is initialized correctly.
694 if (command_line->HasSwitch(switches::kEnableBenchmarking))
695 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30696}
697
698std::string ChromeContentBrowserClient::GetApplicationLocale() {
699 return g_browser_process->GetApplicationLocale();
700}
701
[email protected]597a867b2011-11-18 18:31:20702std::string ChromeContentBrowserClient::GetAcceptLangs(
703 content::BrowserContext* context) {
704 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37705 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08706}
707
[email protected]ac55e292011-06-24 05:16:08708SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22709 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08710 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
711}
712
[email protected]a2176792011-05-08 19:30:49713bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09714 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19715 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09716 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
718 ProfileIOData* io_data =
719 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05720 return io_data->GetCookieSettings()->
721 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49722}
723
[email protected]ed24fad2011-05-10 22:44:01724bool ChromeContentBrowserClient::AllowGetCookie(
725 const GURL& url,
726 const GURL& first_party,
727 const net::CookieList& cookie_list,
728 const content::ResourceContext& context,
729 int render_process_id,
730 int render_view_id) {
731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32732 ProfileIOData* io_data =
733 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05734 bool allow = io_data->GetCookieSettings()->
735 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01736
[email protected]8093a542011-05-13 07:29:32737 BrowserThread::PostTask(
738 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03739 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
740 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01741 return allow;
742}
743
744bool ChromeContentBrowserClient::AllowSetCookie(
745 const GURL& url,
746 const GURL& first_party,
747 const std::string& cookie_line,
748 const content::ResourceContext& context,
749 int render_process_id,
750 int render_view_id,
751 net::CookieOptions* options) {
752 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32753 ProfileIOData* io_data =
754 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01755
[email protected]30fde822011-10-28 09:49:05756 CookieSettings* cookie_settings = io_data->GetCookieSettings();
757 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
758
759 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09760 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01761
[email protected]8093a542011-05-13 07:29:32762 BrowserThread::PostTask(
763 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03764 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
765 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01766 return allow;
767}
768
[email protected]d5a19162011-06-30 18:51:54769bool ChromeContentBrowserClient::AllowSaveLocalState(
770 const content::ResourceContext& context) {
771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
772 ProfileIOData* io_data =
773 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
774 return !io_data->clear_local_state_on_exit()->GetValue();
775}
776
[email protected]5c5a88e2011-11-12 00:45:35777bool ChromeContentBrowserClient::AllowWorkerDatabase(
778 int worker_route_id,
779 const GURL& url,
780 const string16& name,
781 const string16& display_name,
782 unsigned long estimated_size,
783 WorkerProcessHost* worker_process_host) {
784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
785 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
786 worker_process_host->resource_context()->GetUserData(NULL));
787 CookieSettings* cookie_settings = io_data->GetCookieSettings();
788 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
789
790 // Record access to database for potential display in UI: Find the worker
791 // instance and forward the message to all attached documents.
792 WorkerProcessHost::Instances::const_iterator i;
793 for (i = worker_process_host->instances().begin();
794 i != worker_process_host->instances().end(); ++i) {
795 if (i->worker_route_id() != worker_route_id)
796 continue;
797 const WorkerDocumentSet::DocumentInfoSet& documents =
798 i->worker_document_set()->documents();
799 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
800 documents.begin(); doc != documents.end(); ++doc) {
801 BrowserThread::PostTask(
802 BrowserThread::UI, FROM_HERE,
803 base::Bind(
804 &TabSpecificContentSettings::WebDatabaseAccessed,
805 doc->render_process_id(), doc->render_view_id(),
806 url, name, display_name, !allow));
807 }
808 break;
809 }
810
811 return allow;
812}
813
814bool ChromeContentBrowserClient::AllowWorkerFileSystem(
815 int worker_route_id,
816 const GURL& url,
817 WorkerProcessHost* worker_process_host) {
818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
819 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
820 worker_process_host->resource_context()->GetUserData(NULL));
821 CookieSettings* cookie_settings = io_data->GetCookieSettings();
822 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
823
824 // Record access to file system for potential display in UI: Find the worker
825 // instance and forward the message to all attached documents.
826 WorkerProcessHost::Instances::const_iterator i;
827 for (i = worker_process_host->instances().begin();
828 i != worker_process_host->instances().end(); ++i) {
829 if (i->worker_route_id() != worker_route_id)
830 continue;
831 const WorkerDocumentSet::DocumentInfoSet& documents =
832 i->worker_document_set()->documents();
833 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
834 documents.begin(); doc != documents.end(); ++doc) {
835 BrowserThread::PostTask(
836 BrowserThread::UI, FROM_HERE,
837 base::Bind(
838 &TabSpecificContentSettings::FileSystemAccessed,
839 doc->render_process_id(), doc->render_view_id(), url, !allow));
840 }
841 break;
842 }
843
844 return allow;
845}
846
[email protected]6133f922011-07-01 21:34:34847net::URLRequestContext*
848ChromeContentBrowserClient::OverrideRequestContextForURL(
849 const GURL& url, const content::ResourceContext& context) {
850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
851 if (url.SchemeIs(chrome::kExtensionScheme)) {
852 ProfileIOData* io_data =
853 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
854 return io_data->extensions_request_context();
855 }
856
857 return NULL;
858}
859
[email protected]317f96c92011-05-31 06:53:41860QuotaPermissionContext*
861ChromeContentBrowserClient::CreateQuotaPermissionContext() {
862 return new ChromeQuotaPermissionContext();
863}
864
[email protected]a0ce3282011-08-19 20:49:52865void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42866 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42867}
868
[email protected]a0ce3282011-08-19 20:49:52869void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52870 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52871}
872
[email protected]848dd042011-06-04 18:24:03873void ChromeContentBrowserClient::AllowCertificateError(
874 SSLCertErrorHandler* handler,
875 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58876 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41877 // If the tab is being prerendered, cancel the prerender and the request.
878 TabContents* tab = tab_util::GetTabContentsByID(
879 handler->render_process_host_id(),
880 handler->tab_contents_id());
881 if (!tab) {
882 NOTREACHED();
883 return;
884 }
885 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50886 prerender::PrerenderManagerFactory::GetForProfile(
887 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41888 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
889 if (prerender_manager->prerender_tracker()->TryCancel(
890 handler->render_process_host_id(),
891 handler->tab_contents_id(),
892 prerender::FINAL_STATUS_SSL_ERROR)) {
893 handler->CancelRequest();
894 return;
895 }
896 }
897
898 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03899 SSLBlockingPage* blocking_page = new SSLBlockingPage(
900 handler, overridable, callback);
901 blocking_page->Show();
902}
903
[email protected]c99c442e2011-08-24 11:37:30904void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45905 int render_process_id,
906 int render_view_id,
907 SSLClientAuthHandler* handler) {
908 TabContents* tab = tab_util::GetTabContentsByID(
909 render_process_id, render_view_id);
910 if (!tab) {
911 NOTREACHED();
912 return;
913 }
914
[email protected]6786bf402011-12-03 15:19:45915 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
916 GURL requesting_url("https://" + cert_request_info->host_and_port);
917 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
918 << cert_request_info->host_and_port;
919
920 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
921 DCHECK(profile);
922 scoped_ptr<Value> filter(
923 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
924 requesting_url,
925 requesting_url,
926 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
927 std::string(), NULL));
928
929 if (filter.get()) {
930 // Try to automatically select a client certificate.
931 if (filter->IsType(Value::TYPE_DICTIONARY)) {
932 DictionaryValue* filter_dict =
933 static_cast<DictionaryValue*>(filter.get());
934
935 const std::vector<scoped_refptr<net::X509Certificate> >&
936 all_client_certs = cert_request_info->client_certs;
937 for (size_t i = 0; i < all_client_certs.size(); ++i) {
938 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
939 // Use the first certificate that is matched by the filter.
940 handler->CertificateSelected(all_client_certs[i]);
941 return;
942 }
943 }
944 } else {
945 NOTREACHED();
946 }
947 }
948
[email protected]8ec26472011-06-06 16:52:45949 TabContentsWrapper* wrapper =
950 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45951 if (!wrapper) {
952 LOG(ERROR) << " *** No TabcontentsWrapper for: " << tab->GetURL().spec();
953 // If there is no TabContentsWrapper for the given TabContents then we can't
954 // show the user a dialog to select a client certificate. So we simply
955 // cancel the request.
956 handler->CertificateSelected(NULL);
957 return;
958 }
959 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45960}
961
962void ChromeContentBrowserClient::AddNewCertificate(
963 net::URLRequest* request,
964 net::X509Certificate* cert,
965 int render_process_id,
966 int render_view_id) {
967 // The handler will run the UI and delete itself when it's finished.
968 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
969}
970
[email protected]941623e2011-06-07 23:06:04971void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
972 const GURL& source_origin,
973 int callback_context,
974 int render_process_id,
975 int render_view_id) {
976 RenderViewHost* rvh = RenderViewHost::FromID(
977 render_process_id, render_view_id);
978 if (!rvh) {
979 NOTREACHED();
980 return;
981 }
982
[email protected]f3b1a082011-11-18 00:34:30983 content::RenderProcessHost* process = rvh->process();
984 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04985 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37986 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04987 service->RequestPermission(
988 source_origin, render_process_id, render_view_id, callback_context,
989 tab_util::GetTabContentsByID(render_process_id, render_view_id));
990}
991
992WebKit::WebNotificationPresenter::Permission
993 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02994 const GURL& source_origin,
995 const content::ResourceContext& context,
996 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04997 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
998 ProfileIOData* io_data =
999 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1000
[email protected]34eec7ffe32011-11-02 23:49:021001 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1002 source_origin, render_process_id,
1003 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041004 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041005
1006 // Fall back to the regular notification preferences, which works on an
1007 // origin basis.
1008 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371009 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041010 WebKit::WebNotificationPresenter::PermissionNotAllowed;
1011}
1012
1013void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171014 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041015 int render_process_id,
1016 int render_view_id,
1017 bool worker) {
1018 RenderViewHost* rvh = RenderViewHost::FromID(
1019 render_process_id, render_view_id);
1020 if (!rvh) {
1021 NOTREACHED();
1022 return;
1023 }
1024
[email protected]f3b1a082011-11-18 00:34:301025 content::RenderProcessHost* process = rvh->process();
1026 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041027 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371028 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041029 service->ShowDesktopNotification(
1030 params, render_process_id, render_view_id,
1031 worker ? DesktopNotificationService::WorkerNotification :
1032 DesktopNotificationService::PageNotification);
1033}
1034
1035void ChromeContentBrowserClient::CancelDesktopNotification(
1036 int render_process_id,
1037 int render_view_id,
1038 int notification_id) {
1039 RenderViewHost* rvh = RenderViewHost::FromID(
1040 render_process_id, render_view_id);
1041 if (!rvh) {
1042 NOTREACHED();
1043 return;
1044 }
1045
[email protected]f3b1a082011-11-18 00:34:301046 content::RenderProcessHost* process = rvh->process();
1047 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041048 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371049 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041050 service->CancelDesktopNotification(
1051 render_process_id, render_view_id, notification_id);
1052}
1053
[email protected]9f3fba52011-06-08 20:37:191054bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021055 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191056 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021057 const content::ResourceContext& context,
1058 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191059 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1060 // If the opener is trying to create a background window but doesn't have
1061 // the appropriate permission, fail the attempt.
1062 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1063 ProfileIOData* io_data =
1064 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021065 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1066 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191067 }
1068 return true;
1069}
1070
1071std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1072 const GURL& url, const content::ResourceContext& context) {
1073 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1074 // Check if it's an extension-created worker, in which case we want to use
1075 // the name of the extension.
1076 ProfileIOData* io_data =
1077 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1078 const Extension* extension =
1079 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1080 return extension ? extension->name() : std::string();
1081}
1082
[email protected]3cb054e62011-06-13 05:21:171083ResourceDispatcherHost*
1084 ChromeContentBrowserClient::GetResourceDispatcherHost() {
1085 return g_browser_process->resource_dispatcher_host();
1086}
1087
1088ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1089 return g_browser_process->clipboard();
1090}
1091
[email protected]8f6a3b852011-07-19 16:48:561092MHTMLGenerationManager*
1093 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1094 return g_browser_process->mhtml_generation_manager();
1095}
1096
[email protected]ae6e9912011-07-27 01:18:281097net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1098 return g_browser_process->net_log();
1099}
1100
[email protected]3bc0b562011-08-24 23:51:041101speech_input::SpeechInputManager*
1102 ChromeContentBrowserClient::GetSpeechInputManager() {
1103 return speech_input::ChromeSpeechInputManager::GetInstance();
1104}
1105
[email protected]32538d92011-08-25 00:09:231106AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1107 return new ChromeAccessTokenStore();
1108}
1109
[email protected]dbae6b02011-06-29 23:51:411110bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1111 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1112 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1113}
1114
[email protected]5092c282011-10-29 21:48:371115WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
1116 return RenderViewHostDelegateHelper::GetWebkitPrefs(rvh);
[email protected]181a95ee2011-07-12 19:26:361117}
1118
1119void ChromeContentBrowserClient::UpdateInspectorSetting(
1120 RenderViewHost* rvh, const std::string& key, const std::string& value) {
1121 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]f3b1a082011-11-18 00:34:301122 rvh->process()->GetBrowserContext(), key, value);
[email protected]181a95ee2011-07-12 19:26:361123}
1124
1125void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
1126 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]f3b1a082011-11-18 00:34:301127 rvh->process()->GetBrowserContext());
[email protected]181a95ee2011-07-12 19:26:361128}
1129
[email protected]b8148ac2011-07-13 22:03:251130void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1131 BrowserURLHandler* handler) {
1132 // Add the default URL handlers.
1133 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1134 BrowserURLHandler::null_handler());
1135 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1136 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1137
[email protected]b3adbd02011-11-30 22:23:271138 // about: handler. Must come before chrome: handler, since it will
1139 // rewrite about: urls to chrome: URLs and then expect chrome: to
1140 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251141 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1142 BrowserURLHandler::null_handler());
1143 // chrome: & friends.
1144 handler->AddHandlerPair(&HandleWebUI,
1145 BrowserURLHandler::null_handler());
1146}
1147
1148void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371149 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301150 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251151 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1152 BrowsingDataRemover::EVERYTHING,
1153 base::Time());
1154 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1155 // BrowsingDataRemover takes care of deleting itself when done.
1156}
1157
1158void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371159 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301160 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251161 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1162 BrowsingDataRemover::EVERYTHING,
1163 base::Time());
[email protected]dceaa912011-09-06 17:17:231164 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251165 remover->Remove(remove_mask);
1166 // BrowsingDataRemover takes care of deleting itself when done.
1167}
1168
[email protected]e1d16eb92011-08-18 23:19:321169FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1170 return download_util::GetDefaultDownloadDirectory();
1171}
1172
[email protected]c9b6eb62011-10-18 20:49:391173std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1174 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1175}
1176
[email protected]e60c0232011-11-11 19:56:351177#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301178int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521179 const CommandLine& command_line) {
1180 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071181 ExtensionCrashHandlerHostLinux* crash_handler =
1182 ExtensionCrashHandlerHostLinux::GetInstance();
1183 return crash_handler->GetDeathSignalSocket();
1184 }
1185
[email protected]718eab62011-10-05 21:16:521186 std::string process_type =
1187 command_line.GetSwitchValueASCII(switches::kProcessType);
1188
1189 if (process_type == switches::kRendererProcess)
1190 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1191
[email protected]b80f68432011-05-02 17:22:301192 if (process_type == switches::kPluginProcess)
1193 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1194
1195 if (process_type == switches::kPpapiPluginProcess)
1196 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1197
1198 if (process_type == switches::kGpuProcess)
1199 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1200
1201 return -1;
1202}
[email protected]e60c0232011-11-11 19:56:351203#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301204
[email protected]4a65826d2011-08-25 16:04:011205#if defined(OS_WIN)
1206const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1207 return chrome::kBrowserResourcesDll;
1208}
1209#endif
1210
[email protected]37a72af2011-06-13 05:42:011211#if defined(USE_NSS)
1212crypto::CryptoModuleBlockingPasswordDelegate*
1213 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1214 const GURL& url) {
1215 return browser::NewCryptoModuleBlockingDialogDelegate(
1216 browser::kCryptoModulePasswordKeygen, url.host());
1217}
1218#endif
1219
[email protected]d977f9c2011-03-14 16:10:261220} // namespace chrome