blob: bbdd8fbd10410e92e41400c34cfa0c2705878767 [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]631bb742011-11-02 11:29:39138using content::BrowserThread;
139
[email protected]c5dbef02011-05-13 05:06:09140namespace {
141
[email protected]b8148ac2011-07-13 22:03:25142// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42143bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37144 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25145 return false;
146
147 // Special case the new tab page. In older versions of Chrome, the new tab
148 // page was hosted at chrome-internal:<blah>. This might be in people's saved
149 // sessions or bookmarks, so we say any URL with that scheme triggers the new
150 // tab page.
151 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
152 // Rewrite it with the proper new tab URL.
153 *url = GURL(chrome::kChromeUINewTabURL);
154 }
155
156 return true;
157}
158
[email protected]8d3132f62011-10-12 07:13:42159// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
160// below. Extension, and isolated apps require different privileges to be
161// granted to their RenderProcessHosts. This classification allows us to make
162// sure URLs are served by hosts with the right set of privileges.
163enum RenderProcessHostPrivilege {
164 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45165 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42166 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45167 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42168};
169
170RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
171 const GURL& url,
172 ExtensionService* service) {
173 // Default to a normal renderer cause it is lower privileged. This should only
174 // occur if the URL on a site instance is either malformed, or uninitialized.
175 // If it is malformed, then there is no need for better privileges anyways.
176 // If it is uninitialized, but eventually settles on being an a scheme other
177 // than normal webrenderer, the navigation logic will correct us out of band
178 // anyways.
179 if (!url.is_valid())
180 return PRIV_NORMAL;
181
182 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44183 const Extension* extension =
184 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45185 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42186 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45187 if (extension && extension->is_hosted_app())
188 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42189
190 return PRIV_EXTENSION;
191 }
192
193 return PRIV_NORMAL;
194}
195
196RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30197 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46198 extensions::ProcessMap* process_map,
199 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46200 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30201 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46202 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21203 return PRIV_NORMAL;
204
[email protected]6f371442011-11-09 06:45:46205 for (std::set<std::string>::iterator iter = extension_ids.begin();
206 iter != extension_ids.end(); ++iter) {
207 const Extension* extension = service->GetExtensionById(*iter, false);
208 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42209 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45210 if (extension && extension->is_hosted_app())
211 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42212 }
213
[email protected]676f6ab2011-10-19 20:23:21214 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42215}
216
[email protected]eec0b33c2011-12-05 22:09:45217bool IsIsolatedAppInProcess(const GURL& site_url,
218 content::RenderProcessHost* process_host,
219 extensions::ProcessMap* process_map,
220 ExtensionService* service) {
221 std::set<std::string> extension_ids =
222 process_map->GetExtensionsInProcess(process_host->GetID());
223 if (extension_ids.empty())
224 return false;
225
226 for (std::set<std::string>::iterator iter = extension_ids.begin();
227 iter != extension_ids.end(); ++iter) {
228 const Extension* extension = service->GetExtensionById(*iter, false);
229 if (extension &&
230 extension->is_storage_isolated() &&
231 extension->url() == site_url)
232 return true;
233 }
234
235 return false;
236}
237
[email protected]6786bf402011-12-03 15:19:45238bool CertMatchesFilter(const net::X509Certificate& cert,
239 const base::DictionaryValue& filter) {
240 // TODO(markusheintz): This is the minimal required filter implementation.
241 // Implement a better matcher.
242
243 // An empty filter matches any client certificate since no requirements are
244 // specified at all.
245 if (filter.empty())
246 return true;
247
248 std::string common_name;
249 if (filter.GetString("ISSUER.CN", &common_name) &&
250 (cert.issuer().common_name == common_name)) {
251 return true;
252 }
253 return false;
254}
255
[email protected]9dbfff12011-07-01 19:37:07256} // namespace
[email protected]c5dbef02011-05-13 05:06:09257
[email protected]d977f9c2011-03-14 16:10:26258namespace chrome {
259
[email protected]50462bf02011-11-21 19:13:31260content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
261 const content::MainFunctionParams& parameters) {
262 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30263 // Construct the Main browser parts based on the OS type.
264#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31265 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04266#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31267 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30268#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31269 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35270#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31271 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30272#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31273 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04274#else
[email protected]b48c9182011-10-26 18:03:30275 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31276 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30277#endif
278
[email protected]c7480942011-11-08 19:18:27279 // Construct additional browser parts. Stages are called in the order in
280 // which they are added.
[email protected]b48c9182011-10-26 18:03:30281#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31282 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04283#endif
[email protected]c7480942011-11-08 19:18:27284
285#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31286 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27287#endif
288
289#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31290 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27291#endif
292
[email protected]50462bf02011-11-21 19:13:31293 return main_parts;
[email protected]f967b722011-09-07 00:58:04294}
295
[email protected]b45937e2011-10-07 19:49:17296RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
297 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48298#if defined(USE_AURA)
299 return new RenderWidgetHostViewAura(widget);
[email protected]b45937e2011-10-07 19:49:17300#elif defined(OS_WIN)
[email protected]b45937e2011-10-07 19:49:17301 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21302#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17303 return new RenderWidgetHostViewGtk(widget);
304#elif defined(OS_MACOSX)
305 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
306#else
307#error Need to create your platform ViewForWidget here.
308#endif
309}
310
[email protected]74313b42011-08-24 16:51:32311TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
312 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26313#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32314 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21315#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45316 return new TabContentsViewGtk(tab_contents,
317 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32318#elif defined(OS_MACOSX)
319 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32320#else
321#error Need to create your platform TabContentsView here.
322#endif
323}
324
[email protected]f364d1392011-04-08 21:03:10325void ChromeContentBrowserClient::RenderViewHostCreated(
326 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46327
328 SiteInstance* site_instance = render_view_host->site_instance();
329 Profile* profile = Profile::FromBrowserContext(
330 site_instance->browsing_instance()->browser_context());
331
332 new ChromeRenderViewHostObserver(render_view_host,
333 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10334 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26335}
336
[email protected]f3b1a082011-11-18 00:34:30337void ChromeContentBrowserClient::RenderProcessHostCreated(
338 content::RenderProcessHost* host) {
339 int id = host->GetID();
340 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
341 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02342 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30343 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
344 host->GetChannel()->AddFilter(new PrintingMessageFilter());
345 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02346 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30347 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56348#if defined(OS_MACOSX)
349 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
350#endif
[email protected]f3b1a082011-11-18 00:34:30351 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03352 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38353
[email protected]2ccf45c2011-08-19 23:35:50354 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
355 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07356
357 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56358
359 RendererContentSettingRules rules;
360 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
361 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14362}
363
[email protected]97e6c4c2011-05-18 16:08:51364void ChromeContentBrowserClient::PluginProcessHostCreated(
365 PluginProcessHost* host) {
[email protected]f6d2a3e2011-11-17 21:42:40366#if !defined(USE_AURA)
[email protected]97e6c4c2011-05-18 16:08:51367 host->AddFilter(new ChromePluginMessageFilter(host));
[email protected]f6d2a3e2011-11-17 21:42:40368#endif
[email protected]97e6c4c2011-05-18 16:08:51369}
370
[email protected]1fd1a502011-03-30 16:55:56371content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
372 return ChromeWebUIFactory::GetInstance();
373}
374
[email protected]3d7474ff2011-07-27 17:47:37375GURL ChromeContentBrowserClient::GetEffectiveURL(
376 content::BrowserContext* browser_context, const GURL& url) {
377 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08378 // Get the effective URL for the given actual URL. If the URL is part of an
379 // installed app, the effective URL is an extension URL with the ID of that
380 // extension as the host. This has the effect of grouping apps together in
381 // a common SiteInstance.
382 if (!profile || !profile->GetExtensionService())
383 return url;
384
[email protected]615d88f2011-12-13 01:47:44385 const Extension* extension = profile->GetExtensionService()->extensions()->
386 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08387 if (!extension)
388 return url;
389
[email protected]15877ca2011-11-18 22:40:52390 // Bookmark apps do not use the hosted app process model, and should be
391 // treated as normal URLs.
392 if (extension->from_bookmark())
393 return url;
394
[email protected]36fb2c7c2011-04-04 15:49:08395 // If the URL is part of an extension's web extent, convert it to an
396 // extension URL.
397 return extension->GetResourceURL(url.path());
398}
399
[email protected]056ad2a2011-07-12 02:13:55400bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37401 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55402 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52403 // Because we expect to use the effective URL, URLs for hosted apps (apart
404 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55405 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
406 return false;
407
[email protected]3d7474ff2011-07-27 17:47:37408 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55409 if (!profile || !profile->GetExtensionService())
410 return false;
411
[email protected]615d88f2011-12-13 01:47:44412 const Extension* extension = profile->GetExtensionService()->extensions()->
413 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55414 if (!extension)
415 return false;
416
417 // If the URL is part of a hosted app that does not have the background
418 // permission, we want to give each instance its own process to improve
419 // responsiveness.
420 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
421 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
422 return false;
423
424 // Hosted apps that have the background permission must use process per site,
425 // since all instances can make synchronous calls to the background window.
426 // Other extensions should use process per site as well.
427 return true;
428}
429
[email protected]0f012df82011-05-19 14:15:29430bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03431 return url == GURL(chrome::kChromeUICrashURL) ||
432 url == GURL(chrome::kChromeUIKillURL) ||
433 url == GURL(chrome::kChromeUIHangURL) ||
434 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29435}
436
[email protected]46fb9442011-12-09 17:57:47437bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
438 return ProfileIOData::IsHandledURL(url);
439}
440
[email protected]2a5221b2011-09-27 23:07:31441bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30442 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31443 const GURL& site_url) {
444 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30445 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42446 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46447 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31448
[email protected]ffa97602011-11-17 17:55:52449 // Don't allow the Task Manager to share a process with anything else.
450 // Otherwise it can affect the renderers it is observing.
451 // Note: we could create another RenderProcessHostPrivilege bucket for
452 // this to allow multiple chrome://tasks instances to share, but that's
453 // a very unlikely case without serious consequences.
454 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
455 return false;
456
[email protected]8d3132f62011-10-12 07:13:42457 // These may be NULL during tests. In that case, just assume any site can
458 // share any host.
[email protected]6f371442011-11-09 06:45:46459 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31460 return true;
461
[email protected]a8c269a2011-10-25 20:17:22462 // Experimental:
463 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
464 // to share a renderer process. (We could allow pages from the same site or
465 // extensions of the same type to share, if we knew what the given process
466 // was dedicated to. Allowing no sharing is simpler for now.) This may
467 // cause resource exhaustion issues if too many sites are open at once.
468 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
469 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
470 return false;
471
[email protected]eec0b33c2011-12-05 22:09:45472 // An isolated app is only allowed to share with the exact same app in order
473 // to provide complete renderer process isolation. This also works around
474 // issue http://crbug.com/85588, where different isolated apps in the same
475 // process would end up using the first app's storage contexts.
476 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42477 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45478 if (privilege_required == PRIV_ISOLATED)
479 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
480
481 // Otherwise, just make sure the process privilege matches the privilege
482 // required by the site.
483 return GetProcessPrivilege(process_host, process_map, service) ==
484 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31485}
486
[email protected]6f371442011-11-09 06:45:46487void ChromeContentBrowserClient::SiteInstanceGotProcess(
488 SiteInstance* site_instance) {
489 CHECK(site_instance->HasProcess());
490
491 Profile* profile = Profile::FromBrowserContext(
492 site_instance->browsing_instance()->browser_context());
493 ExtensionService* service = profile->GetExtensionService();
494 if (!service)
495 return;
496
497 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44498 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
499 site_instance->site()));
[email protected]6f371442011-11-09 06:45:46500 if (!extension)
501 return;
502
[email protected]6bc04fd82011-12-04 02:29:35503 service->process_map()->Insert(extension->id(),
504 site_instance->GetProcess()->GetID(),
505 site_instance->id());
[email protected]6f371442011-11-09 06:45:46506 BrowserThread::PostTask(
507 BrowserThread::IO, FROM_HERE,
508 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
509 profile->GetExtensionInfoMap(),
510 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35511 site_instance->GetProcess()->GetID(),
512 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46513}
514
515void ChromeContentBrowserClient::SiteInstanceDeleting(
516 SiteInstance* site_instance) {
517 if (!site_instance->HasProcess())
518 return;
519
520 Profile* profile = Profile::FromBrowserContext(
521 site_instance->browsing_instance()->browser_context());
522 ExtensionService* service = profile->GetExtensionService();
523 if (!service)
524 return;
525
526 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44527 service->extensions()->GetExtensionOrAppByURL(
528 ExtensionURLInfo(site_instance->site()));
[email protected]6f371442011-11-09 06:45:46529 if (!extension)
530 return;
531
[email protected]6bc04fd82011-12-04 02:29:35532 service->process_map()->Remove(extension->id(),
533 site_instance->GetProcess()->GetID(),
534 site_instance->id());
[email protected]6f371442011-11-09 06:45:46535 BrowserThread::PostTask(
536 BrowserThread::IO, FROM_HERE,
537 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
538 profile->GetExtensionInfoMap(),
539 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35540 site_instance->GetProcess()->GetID(),
541 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46542}
543
[email protected]e3daf3c2011-10-05 21:17:08544bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
545 const GURL& current_url,
546 const GURL& new_url) {
547 if (current_url.is_empty()) {
548 // Always choose a new process when navigating to extension URLs. The
549 // process grouping logic will combine all of a given extension's pages
550 // into the same process.
551 if (new_url.SchemeIs(chrome::kExtensionScheme))
552 return true;
553
554 return false;
555 }
556
557 // Also, we must switch if one is an extension and the other is not the exact
558 // same extension.
559 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
560 new_url.SchemeIs(chrome::kExtensionScheme)) {
561 if (current_url.GetOrigin() != new_url.GetOrigin())
562 return true;
563 }
564
565 return false;
566}
567
[email protected]763ec4ca2011-04-29 15:48:12568std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
569 const std::string& alias_name) {
570 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
571}
572
[email protected]b80f68432011-05-02 17:22:30573void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
574 CommandLine* command_line, int child_process_id) {
575#if defined(USE_LINUX_BREAKPAD)
576 if (IsCrashReporterEnabled()) {
577 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
578 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
579 }
580#elif defined(OS_MACOSX)
581 if (IsCrashReporterEnabled()) {
582 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
583 child_process_logging::GetClientId());
584 }
585#endif // OS_MACOSX
586
[email protected]f1933792011-06-14 00:49:34587 if (logging::DialogsAreSuppressed())
588 command_line->AppendSwitch(switches::kNoErrorDialogs);
589
[email protected]b80f68432011-05-02 17:22:30590 std::string process_type =
591 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17592 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52593 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30594 FilePath user_data_dir =
595 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
596 if (!user_data_dir.empty())
597 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
598#if defined(OS_CHROMEOS)
599 const std::string& login_profile =
600 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
601 if (!login_profile.empty())
602 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
603#endif
604
[email protected]f3b1a082011-11-18 00:34:30605 content::RenderProcessHost* process =
606 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37607 if (process) {
608 Profile* profile = Profile::FromBrowserContext(
609 process->GetBrowserContext());
610 extensions::ProcessMap* process_map =
611 profile->GetExtensionService()->process_map();
612 if (process_map && process_map->Contains(process->GetID()))
613 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30614
[email protected]a8d851f82011-12-21 00:32:37615 PrefService* prefs = profile->GetPrefs();
616 // Currently this pref is only registered if applied via a policy.
617 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
618 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
619 // Turn this policy into a command line switch.
620 command_line->AppendSwitch(switches::kDisable3DAPIs);
621 }
[email protected]718eab62011-10-05 21:16:52622
[email protected]a8d851f82011-12-21 00:32:37623 // Disable client-side phishing detection in the renderer if it is
624 // disabled in the Profile preferences or the browser process.
625 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
626 !g_browser_process->safe_browsing_detection_service()) {
627 command_line->AppendSwitch(
628 switches::kDisableClientSidePhishingDetection);
629 }
[email protected]8c40da62011-07-13 22:58:46630 }
[email protected]4287a3d2011-06-13 23:56:51631
632 static const char* const kSwitchNames[] = {
633 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48634 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18635 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51636 switches::kAllowScriptingGallery,
637 switches::kAppsCheckoutURL,
638 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31639 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51640 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51641 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51642 switches::kDomAutomationController,
643 switches::kDumpHistogramsOnExit,
644 switches::kEnableClickToPlay,
645 switches::kEnableCrxlessWebApps,
646 switches::kEnableExperimentalExtensionApis,
647 switches::kEnableInBrowserThumbnailing,
648 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12649 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51650 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53651 switches::kEnablePlatformApps,
[email protected]5714ee32011-08-18 01:51:24652 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51653 switches::kEnableSearchProviderApiV2,
654 switches::kEnableWatchdog,
655 switches::kExperimentalSpellcheckerFeatures,
656 switches::kMemoryProfiling,
657 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04658 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51659 switches::kPpapiFlashArgs,
660 switches::kPpapiFlashInProcess,
661 switches::kPpapiFlashPath,
662 switches::kPpapiFlashVersion,
663 switches::kProfilingAtStart,
664 switches::kProfilingFile,
665 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51666 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03667 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51668 };
669
670 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
671 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17672 } else if (process_type == switches::kUtilityProcess) {
673 if (browser_command_line.HasSwitch(
674 switches::kEnableExperimentalExtensionApis)) {
675 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
676 }
[email protected]4287a3d2011-06-13 23:56:51677 } else if (process_type == switches::kPluginProcess) {
678 static const char* const kSwitchNames[] = {
679 #if defined(OS_CHROMEOS)
680 switches::kLoginProfile,
681 #endif
682 switches::kMemoryProfiling,
683 switches::kSilentDumpOnDCHECK,
684 switches::kUserDataDir,
685 };
686
687 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
688 arraysize(kSwitchNames));
689 } else if (process_type == switches::kZygoteProcess) {
690 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51691 switches::kUserDataDir, // Make logs go to the right file.
692 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
693 switches::kPpapiFlashInProcess,
694 switches::kPpapiFlashPath,
695 switches::kPpapiFlashVersion,
696 };
697
698 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
699 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30700 }
[email protected]6f08af82011-09-15 01:19:03701
702 // The command line switch kEnableBenchmarking needs to be specified along
703 // with the kEnableStatsTable switch to ensure that the stats table global
704 // is initialized correctly.
705 if (command_line->HasSwitch(switches::kEnableBenchmarking))
706 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30707}
708
709std::string ChromeContentBrowserClient::GetApplicationLocale() {
710 return g_browser_process->GetApplicationLocale();
711}
712
[email protected]597a867b2011-11-18 18:31:20713std::string ChromeContentBrowserClient::GetAcceptLangs(
714 content::BrowserContext* context) {
715 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37716 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08717}
718
[email protected]ac55e292011-06-24 05:16:08719SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22720 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08721 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
722}
723
[email protected]a2176792011-05-08 19:30:49724bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09725 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19726 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09727 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
729 ProfileIOData* io_data =
730 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05731 return io_data->GetCookieSettings()->
732 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49733}
734
[email protected]ed24fad2011-05-10 22:44:01735bool ChromeContentBrowserClient::AllowGetCookie(
736 const GURL& url,
737 const GURL& first_party,
738 const net::CookieList& cookie_list,
739 const content::ResourceContext& context,
740 int render_process_id,
741 int render_view_id) {
742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32743 ProfileIOData* io_data =
744 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05745 bool allow = io_data->GetCookieSettings()->
746 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01747
[email protected]8093a542011-05-13 07:29:32748 BrowserThread::PostTask(
749 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03750 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
751 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01752 return allow;
753}
754
755bool ChromeContentBrowserClient::AllowSetCookie(
756 const GURL& url,
757 const GURL& first_party,
758 const std::string& cookie_line,
759 const content::ResourceContext& context,
760 int render_process_id,
761 int render_view_id,
762 net::CookieOptions* options) {
763 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32764 ProfileIOData* io_data =
765 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01766
[email protected]30fde822011-10-28 09:49:05767 CookieSettings* cookie_settings = io_data->GetCookieSettings();
768 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
769
770 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09771 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01772
[email protected]8093a542011-05-13 07:29:32773 BrowserThread::PostTask(
774 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03775 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
776 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01777 return allow;
778}
779
[email protected]d5a19162011-06-30 18:51:54780bool ChromeContentBrowserClient::AllowSaveLocalState(
781 const content::ResourceContext& context) {
782 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
783 ProfileIOData* io_data =
784 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
785 return !io_data->clear_local_state_on_exit()->GetValue();
786}
787
[email protected]5c5a88e2011-11-12 00:45:35788bool ChromeContentBrowserClient::AllowWorkerDatabase(
789 int worker_route_id,
790 const GURL& url,
791 const string16& name,
792 const string16& display_name,
793 unsigned long estimated_size,
794 WorkerProcessHost* worker_process_host) {
795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
796 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
797 worker_process_host->resource_context()->GetUserData(NULL));
798 CookieSettings* cookie_settings = io_data->GetCookieSettings();
799 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
800
801 // Record access to database for potential display in UI: Find the worker
802 // instance and forward the message to all attached documents.
803 WorkerProcessHost::Instances::const_iterator i;
804 for (i = worker_process_host->instances().begin();
805 i != worker_process_host->instances().end(); ++i) {
806 if (i->worker_route_id() != worker_route_id)
807 continue;
808 const WorkerDocumentSet::DocumentInfoSet& documents =
809 i->worker_document_set()->documents();
810 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
811 documents.begin(); doc != documents.end(); ++doc) {
812 BrowserThread::PostTask(
813 BrowserThread::UI, FROM_HERE,
814 base::Bind(
815 &TabSpecificContentSettings::WebDatabaseAccessed,
816 doc->render_process_id(), doc->render_view_id(),
817 url, name, display_name, !allow));
818 }
819 break;
820 }
821
822 return allow;
823}
824
825bool ChromeContentBrowserClient::AllowWorkerFileSystem(
826 int worker_route_id,
827 const GURL& url,
828 WorkerProcessHost* worker_process_host) {
829 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
830 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
831 worker_process_host->resource_context()->GetUserData(NULL));
832 CookieSettings* cookie_settings = io_data->GetCookieSettings();
833 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
834
835 // Record access to file system for potential display in UI: Find the worker
836 // instance and forward the message to all attached documents.
837 WorkerProcessHost::Instances::const_iterator i;
838 for (i = worker_process_host->instances().begin();
839 i != worker_process_host->instances().end(); ++i) {
840 if (i->worker_route_id() != worker_route_id)
841 continue;
842 const WorkerDocumentSet::DocumentInfoSet& documents =
843 i->worker_document_set()->documents();
844 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
845 documents.begin(); doc != documents.end(); ++doc) {
846 BrowserThread::PostTask(
847 BrowserThread::UI, FROM_HERE,
848 base::Bind(
849 &TabSpecificContentSettings::FileSystemAccessed,
850 doc->render_process_id(), doc->render_view_id(), url, !allow));
851 }
852 break;
853 }
854
855 return allow;
856}
857
[email protected]6133f922011-07-01 21:34:34858net::URLRequestContext*
859ChromeContentBrowserClient::OverrideRequestContextForURL(
860 const GURL& url, const content::ResourceContext& context) {
861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
862 if (url.SchemeIs(chrome::kExtensionScheme)) {
863 ProfileIOData* io_data =
864 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
865 return io_data->extensions_request_context();
866 }
867
868 return NULL;
869}
870
[email protected]317f96c92011-05-31 06:53:41871QuotaPermissionContext*
872ChromeContentBrowserClient::CreateQuotaPermissionContext() {
873 return new ChromeQuotaPermissionContext();
874}
875
[email protected]a0ce3282011-08-19 20:49:52876void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42877 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42878}
879
[email protected]a0ce3282011-08-19 20:49:52880void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52881 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52882}
883
[email protected]848dd042011-06-04 18:24:03884void ChromeContentBrowserClient::AllowCertificateError(
885 SSLCertErrorHandler* handler,
886 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58887 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41888 // If the tab is being prerendered, cancel the prerender and the request.
889 TabContents* tab = tab_util::GetTabContentsByID(
890 handler->render_process_host_id(),
891 handler->tab_contents_id());
892 if (!tab) {
893 NOTREACHED();
894 return;
895 }
896 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50897 prerender::PrerenderManagerFactory::GetForProfile(
898 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41899 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
900 if (prerender_manager->prerender_tracker()->TryCancel(
901 handler->render_process_host_id(),
902 handler->tab_contents_id(),
903 prerender::FINAL_STATUS_SSL_ERROR)) {
904 handler->CancelRequest();
905 return;
906 }
907 }
908
909 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03910 SSLBlockingPage* blocking_page = new SSLBlockingPage(
911 handler, overridable, callback);
912 blocking_page->Show();
913}
914
[email protected]c99c442e2011-08-24 11:37:30915void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45916 int render_process_id,
917 int render_view_id,
918 SSLClientAuthHandler* handler) {
919 TabContents* tab = tab_util::GetTabContentsByID(
920 render_process_id, render_view_id);
921 if (!tab) {
922 NOTREACHED();
923 return;
924 }
925
[email protected]6786bf402011-12-03 15:19:45926 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
927 GURL requesting_url("https://" + cert_request_info->host_and_port);
928 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
929 << cert_request_info->host_and_port;
930
931 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
932 DCHECK(profile);
933 scoped_ptr<Value> filter(
934 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
935 requesting_url,
936 requesting_url,
937 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
938 std::string(), NULL));
939
940 if (filter.get()) {
941 // Try to automatically select a client certificate.
942 if (filter->IsType(Value::TYPE_DICTIONARY)) {
943 DictionaryValue* filter_dict =
944 static_cast<DictionaryValue*>(filter.get());
945
946 const std::vector<scoped_refptr<net::X509Certificate> >&
947 all_client_certs = cert_request_info->client_certs;
948 for (size_t i = 0; i < all_client_certs.size(); ++i) {
949 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
950 // Use the first certificate that is matched by the filter.
951 handler->CertificateSelected(all_client_certs[i]);
952 return;
953 }
954 }
955 } else {
956 NOTREACHED();
957 }
958 }
959
[email protected]8ec26472011-06-06 16:52:45960 TabContentsWrapper* wrapper =
961 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45962 if (!wrapper) {
[email protected]6786bf402011-12-03 15:19:45963 // If there is no TabContentsWrapper for the given TabContents then we can't
964 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14965 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45966 handler->CertificateSelected(NULL);
967 return;
968 }
969 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45970}
971
972void ChromeContentBrowserClient::AddNewCertificate(
973 net::URLRequest* request,
974 net::X509Certificate* cert,
975 int render_process_id,
976 int render_view_id) {
977 // The handler will run the UI and delete itself when it's finished.
978 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
979}
980
[email protected]941623e2011-06-07 23:06:04981void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
982 const GURL& source_origin,
983 int callback_context,
984 int render_process_id,
985 int render_view_id) {
986 RenderViewHost* rvh = RenderViewHost::FromID(
987 render_process_id, render_view_id);
988 if (!rvh) {
989 NOTREACHED();
990 return;
991 }
992
[email protected]f3b1a082011-11-18 00:34:30993 content::RenderProcessHost* process = rvh->process();
994 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04995 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37996 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04997 service->RequestPermission(
998 source_origin, render_process_id, render_view_id, callback_context,
999 tab_util::GetTabContentsByID(render_process_id, render_view_id));
1000}
1001
1002WebKit::WebNotificationPresenter::Permission
1003 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021004 const GURL& source_origin,
1005 const content::ResourceContext& context,
1006 int render_process_id) {
[email protected]941623e2011-06-07 23:06:041007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1008 ProfileIOData* io_data =
1009 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1010
[email protected]34eec7ffe32011-11-02 23:49:021011 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1012 source_origin, render_process_id,
1013 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041014 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041015
1016 // Fall back to the regular notification preferences, which works on an
1017 // origin basis.
1018 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371019 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041020 WebKit::WebNotificationPresenter::PermissionNotAllowed;
1021}
1022
1023void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171024 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041025 int render_process_id,
1026 int render_view_id,
1027 bool worker) {
1028 RenderViewHost* rvh = RenderViewHost::FromID(
1029 render_process_id, render_view_id);
1030 if (!rvh) {
1031 NOTREACHED();
1032 return;
1033 }
1034
[email protected]f3b1a082011-11-18 00:34:301035 content::RenderProcessHost* process = rvh->process();
1036 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041037 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371038 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041039 service->ShowDesktopNotification(
1040 params, render_process_id, render_view_id,
1041 worker ? DesktopNotificationService::WorkerNotification :
1042 DesktopNotificationService::PageNotification);
1043}
1044
1045void ChromeContentBrowserClient::CancelDesktopNotification(
1046 int render_process_id,
1047 int render_view_id,
1048 int notification_id) {
1049 RenderViewHost* rvh = RenderViewHost::FromID(
1050 render_process_id, render_view_id);
1051 if (!rvh) {
1052 NOTREACHED();
1053 return;
1054 }
1055
[email protected]f3b1a082011-11-18 00:34:301056 content::RenderProcessHost* process = rvh->process();
1057 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041058 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371059 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041060 service->CancelDesktopNotification(
1061 render_process_id, render_view_id, notification_id);
1062}
1063
[email protected]9f3fba52011-06-08 20:37:191064bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021065 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191066 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021067 const content::ResourceContext& context,
1068 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191069 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1070 // If the opener is trying to create a background window but doesn't have
1071 // the appropriate permission, fail the attempt.
1072 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1073 ProfileIOData* io_data =
1074 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021075 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1076 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191077 }
1078 return true;
1079}
1080
1081std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1082 const GURL& url, const content::ResourceContext& context) {
1083 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1084 // Check if it's an extension-created worker, in which case we want to use
1085 // the name of the extension.
1086 ProfileIOData* io_data =
1087 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1088 const Extension* extension =
1089 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1090 return extension ? extension->name() : std::string();
1091}
1092
[email protected]3cb054e62011-06-13 05:21:171093ResourceDispatcherHost*
1094 ChromeContentBrowserClient::GetResourceDispatcherHost() {
1095 return g_browser_process->resource_dispatcher_host();
1096}
1097
1098ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1099 return g_browser_process->clipboard();
1100}
1101
[email protected]8f6a3b852011-07-19 16:48:561102MHTMLGenerationManager*
1103 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1104 return g_browser_process->mhtml_generation_manager();
1105}
1106
[email protected]ae6e9912011-07-27 01:18:281107net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1108 return g_browser_process->net_log();
1109}
1110
[email protected]3bc0b562011-08-24 23:51:041111speech_input::SpeechInputManager*
1112 ChromeContentBrowserClient::GetSpeechInputManager() {
1113 return speech_input::ChromeSpeechInputManager::GetInstance();
1114}
1115
[email protected]32538d92011-08-25 00:09:231116AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1117 return new ChromeAccessTokenStore();
1118}
1119
[email protected]dbae6b02011-06-29 23:51:411120bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1121 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1122 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1123}
1124
[email protected]5092c282011-10-29 21:48:371125WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
1126 return RenderViewHostDelegateHelper::GetWebkitPrefs(rvh);
[email protected]181a95ee2011-07-12 19:26:361127}
1128
1129void ChromeContentBrowserClient::UpdateInspectorSetting(
1130 RenderViewHost* rvh, const std::string& key, const std::string& value) {
1131 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]f3b1a082011-11-18 00:34:301132 rvh->process()->GetBrowserContext(), key, value);
[email protected]181a95ee2011-07-12 19:26:361133}
1134
1135void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
1136 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]f3b1a082011-11-18 00:34:301137 rvh->process()->GetBrowserContext());
[email protected]181a95ee2011-07-12 19:26:361138}
1139
[email protected]b8148ac2011-07-13 22:03:251140void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1141 BrowserURLHandler* handler) {
1142 // Add the default URL handlers.
1143 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1144 BrowserURLHandler::null_handler());
1145 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1146 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1147
[email protected]b3adbd02011-11-30 22:23:271148 // about: handler. Must come before chrome: handler, since it will
1149 // rewrite about: urls to chrome: URLs and then expect chrome: to
1150 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251151 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1152 BrowserURLHandler::null_handler());
1153 // chrome: & friends.
1154 handler->AddHandlerPair(&HandleWebUI,
1155 BrowserURLHandler::null_handler());
1156}
1157
1158void ChromeContentBrowserClient::ClearCache(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());
1164 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1165 // BrowsingDataRemover takes care of deleting itself when done.
1166}
1167
1168void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371169 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301170 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251171 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1172 BrowsingDataRemover::EVERYTHING,
1173 base::Time());
[email protected]dceaa912011-09-06 17:17:231174 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251175 remover->Remove(remove_mask);
1176 // BrowsingDataRemover takes care of deleting itself when done.
1177}
1178
[email protected]e1d16eb92011-08-18 23:19:321179FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1180 return download_util::GetDefaultDownloadDirectory();
1181}
1182
[email protected]c9b6eb62011-10-18 20:49:391183std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1184 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1185}
1186
[email protected]e60c0232011-11-11 19:56:351187#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301188int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521189 const CommandLine& command_line) {
1190 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071191 ExtensionCrashHandlerHostLinux* crash_handler =
1192 ExtensionCrashHandlerHostLinux::GetInstance();
1193 return crash_handler->GetDeathSignalSocket();
1194 }
1195
[email protected]718eab62011-10-05 21:16:521196 std::string process_type =
1197 command_line.GetSwitchValueASCII(switches::kProcessType);
1198
1199 if (process_type == switches::kRendererProcess)
1200 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1201
[email protected]b80f68432011-05-02 17:22:301202 if (process_type == switches::kPluginProcess)
1203 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1204
1205 if (process_type == switches::kPpapiPluginProcess)
1206 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1207
1208 if (process_type == switches::kGpuProcess)
1209 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1210
1211 return -1;
1212}
[email protected]e60c0232011-11-11 19:56:351213#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301214
[email protected]4a65826d2011-08-25 16:04:011215#if defined(OS_WIN)
1216const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1217 return chrome::kBrowserResourcesDll;
1218}
1219#endif
1220
[email protected]37a72af2011-06-13 05:42:011221#if defined(USE_NSS)
1222crypto::CryptoModuleBlockingPasswordDelegate*
1223 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1224 const GURL& url) {
1225 return browser::NewCryptoModuleBlockingDialogDelegate(
1226 browser::kCryptoModulePasswordKeygen, url.host());
1227}
1228#endif
1229
[email protected]d977f9c2011-03-14 16:10:261230} // namespace chrome