blob: cf64566dd68f2f6641d5fcaa9b3656c4b07a6dcc [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// 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"
[email protected]f3986f82012-01-03 20:00:0612#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3013#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2514#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2316#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1217#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0318#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]97e6c4c2011-05-18 16:08:5119#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4120#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5621#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0522#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4523#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3224#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3225#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0426#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1027#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2628#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2529#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0630#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]39a5b532011-10-22 01:47:0731#include "chrome/browser/extensions/extension_webrequest_api.h"
[email protected]32538d92011-08-25 00:09:2332#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1233#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2834#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0435#include "chrome/browser/notifications/desktop_notification_service.h"
36#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4237#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1238#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0639#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4140#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5041#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4142#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1443#include "chrome/browser/printing/printing_message_filter.h"
44#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3245#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1446#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3347#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4248#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1449#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0450#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4651#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4552#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0353#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4554#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
55#include "chrome/browser/tab_contents/tab_util.h"
56#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5657#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]f3986f82012-01-03 20:00:0658#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3059#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0160#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3061#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0462#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4463#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3464#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1265#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3866#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0967#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2568#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0969#include "content/browser/browsing_instance.h"
[email protected]f3986f82012-01-03 20:00:0670#include "content/browser/child_process_security_policy.h"
71#include "content/browser/gpu/gpu_data_manager.h"
72#include "content/browser/gpu/gpu_process_host.h"
[email protected]97e6c4c2011-05-18 16:08:5173#include "content/browser/plugin_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2674#include "content/browser/renderer_host/render_view_host.h"
[email protected]99907362012-01-11 05:41:4075#include "content/browser/renderer_host/resource_dispatcher_host.h"
[email protected]a2176792011-05-08 19:30:4976#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0977#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4178#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4579#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1280#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3281#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3682#include "content/browser/worker_host/worker_process_host.h"
[email protected]b48c9182011-10-26 18:03:3083#include "content/public/browser/browser_main_parts.h"
[email protected]f3b1a082011-11-18 00:34:3084#include "content/public/browser/render_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3985#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3486#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0187#include "net/base/cookie_monster.h"
88#include "net/base/cookie_options.h"
[email protected]f3986f82012-01-03 20:00:0689#include "net/base/network_change_notifier.h"
[email protected]c9b6eb62011-10-18 20:49:3990#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0891#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3692#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2693
[email protected]b48c9182011-10-26 18:03:3094#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3895#include "chrome/browser/chrome_browser_main_win.h"
96#elif defined(OS_MACOSX)
97#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5698#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3099#elif defined(OS_CHROMEOS)
100#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:35101#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:30102#include "chrome/browser/chrome_browser_main_linux.h"
103#elif defined(OS_POSIX)
104#include "chrome/browser/chrome_browser_main_posix.h"
105#endif
106
[email protected]b48c9182011-10-26 18:03:30107#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31108#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38109#endif
110
[email protected]c7480942011-11-08 19:18:27111#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31112#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27113#endif
114
115#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31116#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
117#endif
118
[email protected]e60c0232011-11-11 19:56:35119#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30120#include "base/linux_util.h"
121#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43122#endif
[email protected]b80f68432011-05-02 17:22:30123
[email protected]080f34f2011-09-20 05:39:26124#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32125#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21126#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45127#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]90580422012-01-12 00:26:22128#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32129#elif defined(OS_MACOSX)
[email protected]8dad546b2012-01-17 21:47:35130#include "chrome/browser/tab_contents/moving_to_content/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32131#endif
132
[email protected]37a72af2011-06-13 05:42:01133#if defined(USE_NSS)
134#include "chrome/browser/ui/crypto_module_password_dialog.h"
135#endif
136
[email protected]c8c77182011-12-21 15:04:47137using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39138using content::BrowserThread;
[email protected]83ff91c2012-01-05 20:54:13139using content::WebContents;
[email protected]631bb742011-11-02 11:29:39140
[email protected]c5dbef02011-05-13 05:06:09141namespace {
142
[email protected]b8148ac2011-07-13 22:03:25143// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42144bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37145 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25146 return false;
147
148 // Special case the new tab page. In older versions of Chrome, the new tab
149 // page was hosted at chrome-internal:<blah>. This might be in people's saved
150 // sessions or bookmarks, so we say any URL with that scheme triggers the new
151 // tab page.
152 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
153 // Rewrite it with the proper new tab URL.
154 *url = GURL(chrome::kChromeUINewTabURL);
155 }
156
157 return true;
158}
159
[email protected]8d3132f62011-10-12 07:13:42160// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
161// below. Extension, and isolated apps require different privileges to be
162// granted to their RenderProcessHosts. This classification allows us to make
163// sure URLs are served by hosts with the right set of privileges.
164enum RenderProcessHostPrivilege {
165 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45166 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42167 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45168 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42169};
170
171RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
172 const GURL& url,
173 ExtensionService* service) {
174 // Default to a normal renderer cause it is lower privileged. This should only
175 // occur if the URL on a site instance is either malformed, or uninitialized.
176 // If it is malformed, then there is no need for better privileges anyways.
177 // If it is uninitialized, but eventually settles on being an a scheme other
178 // than normal webrenderer, the navigation logic will correct us out of band
179 // anyways.
180 if (!url.is_valid())
181 return PRIV_NORMAL;
182
183 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44184 const Extension* extension =
185 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45186 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42187 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45188 if (extension && extension->is_hosted_app())
189 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42190
191 return PRIV_EXTENSION;
192 }
193
194 return PRIV_NORMAL;
195}
196
197RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30198 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46199 extensions::ProcessMap* process_map,
200 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46201 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30202 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46203 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21204 return PRIV_NORMAL;
205
[email protected]6f371442011-11-09 06:45:46206 for (std::set<std::string>::iterator iter = extension_ids.begin();
207 iter != extension_ids.end(); ++iter) {
208 const Extension* extension = service->GetExtensionById(*iter, false);
209 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42210 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45211 if (extension && extension->is_hosted_app())
212 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42213 }
214
[email protected]676f6ab2011-10-19 20:23:21215 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42216}
217
[email protected]eec0b33c2011-12-05 22:09:45218bool IsIsolatedAppInProcess(const GURL& site_url,
219 content::RenderProcessHost* process_host,
220 extensions::ProcessMap* process_map,
221 ExtensionService* service) {
222 std::set<std::string> extension_ids =
223 process_map->GetExtensionsInProcess(process_host->GetID());
224 if (extension_ids.empty())
225 return false;
226
227 for (std::set<std::string>::iterator iter = extension_ids.begin();
228 iter != extension_ids.end(); ++iter) {
229 const Extension* extension = service->GetExtensionById(*iter, false);
230 if (extension &&
231 extension->is_storage_isolated() &&
232 extension->url() == site_url)
233 return true;
234 }
235
236 return false;
237}
238
[email protected]6786bf402011-12-03 15:19:45239bool CertMatchesFilter(const net::X509Certificate& cert,
240 const base::DictionaryValue& filter) {
241 // TODO(markusheintz): This is the minimal required filter implementation.
242 // Implement a better matcher.
243
244 // An empty filter matches any client certificate since no requirements are
245 // specified at all.
246 if (filter.empty())
247 return true;
248
249 std::string common_name;
250 if (filter.GetString("ISSUER.CN", &common_name) &&
251 (cert.issuer().common_name == common_name)) {
252 return true;
253 }
254 return false;
255}
256
[email protected]f3986f82012-01-03 20:00:06257// Fills |map| with the per-script font prefs under path |map_name|.
258void FillFontFamilyMap(const PrefService* prefs,
259 const char* map_name,
260 WebPreferences::ScriptFontFamilyMap* map) {
261 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
262 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
263 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
264 std::string font_family = prefs->GetString(pref_name.c_str());
265 if (!font_family.empty())
266 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
267 }
268}
269
[email protected]9dbfff12011-07-01 19:37:07270} // namespace
[email protected]c5dbef02011-05-13 05:06:09271
[email protected]d977f9c2011-03-14 16:10:26272namespace chrome {
273
[email protected]50462bf02011-11-21 19:13:31274content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
275 const content::MainFunctionParams& parameters) {
276 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30277 // Construct the Main browser parts based on the OS type.
278#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31279 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04280#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31281 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30282#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31283 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35284#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31285 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30286#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31287 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04288#else
[email protected]b48c9182011-10-26 18:03:30289 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31290 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30291#endif
292
[email protected]c7480942011-11-08 19:18:27293 // Construct additional browser parts. Stages are called in the order in
294 // which they are added.
[email protected]b48c9182011-10-26 18:03:30295#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31296 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04297#endif
[email protected]c7480942011-11-08 19:18:27298
299#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31300 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27301#endif
302
303#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31304 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27305#endif
306
[email protected]50462bf02011-11-21 19:13:31307 return main_parts;
[email protected]f967b722011-09-07 00:58:04308}
309
[email protected]74313b42011-08-24 16:51:32310TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
[email protected]8dad546b2012-01-17 21:47:35311 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26312#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35313 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21314#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35315 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22316 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32317#elif defined(OS_MACOSX)
[email protected]8dad546b2012-01-17 21:47:35318 return tab_contents_view_mac::CreateTabContentsView(web_contents);
[email protected]74313b42011-08-24 16:51:32319#else
320#error Need to create your platform TabContentsView here.
321#endif
322}
323
[email protected]f364d1392011-04-08 21:03:10324void ChromeContentBrowserClient::RenderViewHostCreated(
325 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46326
327 SiteInstance* site_instance = render_view_host->site_instance();
328 Profile* profile = Profile::FromBrowserContext(
329 site_instance->browsing_instance()->browser_context());
330
331 new ChromeRenderViewHostObserver(render_view_host,
332 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10333 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26334}
335
[email protected]f3b1a082011-11-18 00:34:30336void ChromeContentBrowserClient::RenderProcessHostCreated(
337 content::RenderProcessHost* host) {
338 int id = host->GetID();
339 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
340 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02341 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30342 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
343 host->GetChannel()->AddFilter(new PrintingMessageFilter());
344 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02345 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30346 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56347#if defined(OS_MACOSX)
348 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
349#endif
[email protected]f3b1a082011-11-18 00:34:30350 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03351 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38352
[email protected]2ccf45c2011-08-19 23:35:50353 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
354 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07355
356 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56357
358 RendererContentSettingRules rules;
359 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
360 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14361}
362
[email protected]97e6c4c2011-05-18 16:08:51363void ChromeContentBrowserClient::PluginProcessHostCreated(
364 PluginProcessHost* host) {
[email protected]f6d2a3e2011-11-17 21:42:40365#if !defined(USE_AURA)
[email protected]97e6c4c2011-05-18 16:08:51366 host->AddFilter(new ChromePluginMessageFilter(host));
[email protected]f6d2a3e2011-11-17 21:42:40367#endif
[email protected]97e6c4c2011-05-18 16:08:51368}
369
[email protected]1fd1a502011-03-30 16:55:56370content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
371 return ChromeWebUIFactory::GetInstance();
372}
373
[email protected]3d7474ff2011-07-27 17:47:37374GURL ChromeContentBrowserClient::GetEffectiveURL(
375 content::BrowserContext* browser_context, const GURL& url) {
376 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08377 // Get the effective URL for the given actual URL. If the URL is part of an
378 // installed app, the effective URL is an extension URL with the ID of that
379 // extension as the host. This has the effect of grouping apps together in
380 // a common SiteInstance.
381 if (!profile || !profile->GetExtensionService())
382 return url;
383
[email protected]615d88f2011-12-13 01:47:44384 const Extension* extension = profile->GetExtensionService()->extensions()->
385 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08386 if (!extension)
387 return url;
388
[email protected]15877ca2011-11-18 22:40:52389 // Bookmark apps do not use the hosted app process model, and should be
390 // treated as normal URLs.
391 if (extension->from_bookmark())
392 return url;
393
[email protected]36fb2c7c2011-04-04 15:49:08394 // If the URL is part of an extension's web extent, convert it to an
395 // extension URL.
396 return extension->GetResourceURL(url.path());
397}
398
[email protected]056ad2a2011-07-12 02:13:55399bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37400 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55401 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52402 // Because we expect to use the effective URL, URLs for hosted apps (apart
403 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55404 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
405 return false;
406
[email protected]3d7474ff2011-07-27 17:47:37407 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55408 if (!profile || !profile->GetExtensionService())
409 return false;
410
[email protected]615d88f2011-12-13 01:47:44411 const Extension* extension = profile->GetExtensionService()->extensions()->
412 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55413 if (!extension)
414 return false;
415
416 // If the URL is part of a hosted app that does not have the background
417 // permission, we want to give each instance its own process to improve
418 // responsiveness.
419 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
420 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
421 return false;
422
423 // Hosted apps that have the background permission must use process per site,
424 // since all instances can make synchronous calls to the background window.
425 // Other extensions should use process per site as well.
426 return true;
427}
428
[email protected]0f012df82011-05-19 14:15:29429bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03430 return url == GURL(chrome::kChromeUICrashURL) ||
431 url == GURL(chrome::kChromeUIKillURL) ||
432 url == GURL(chrome::kChromeUIHangURL) ||
433 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29434}
435
[email protected]46fb9442011-12-09 17:57:47436bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
437 return ProfileIOData::IsHandledURL(url);
438}
439
[email protected]2a5221b2011-09-27 23:07:31440bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30441 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31442 const GURL& site_url) {
443 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30444 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42445 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46446 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31447
[email protected]ffa97602011-11-17 17:55:52448 // Don't allow the Task Manager to share a process with anything else.
449 // Otherwise it can affect the renderers it is observing.
450 // Note: we could create another RenderProcessHostPrivilege bucket for
451 // this to allow multiple chrome://tasks instances to share, but that's
452 // a very unlikely case without serious consequences.
453 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
454 return false;
455
[email protected]8d3132f62011-10-12 07:13:42456 // These may be NULL during tests. In that case, just assume any site can
457 // share any host.
[email protected]6f371442011-11-09 06:45:46458 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31459 return true;
460
[email protected]a8c269a2011-10-25 20:17:22461 // Experimental:
462 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
463 // to share a renderer process. (We could allow pages from the same site or
464 // extensions of the same type to share, if we knew what the given process
465 // was dedicated to. Allowing no sharing is simpler for now.) This may
466 // cause resource exhaustion issues if too many sites are open at once.
467 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
468 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
469 return false;
470
[email protected]eec0b33c2011-12-05 22:09:45471 // An isolated app is only allowed to share with the exact same app in order
472 // to provide complete renderer process isolation. This also works around
473 // issue http://crbug.com/85588, where different isolated apps in the same
474 // process would end up using the first app's storage contexts.
475 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42476 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45477 if (privilege_required == PRIV_ISOLATED)
478 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
479
480 // Otherwise, just make sure the process privilege matches the privilege
481 // required by the site.
482 return GetProcessPrivilege(process_host, process_map, service) ==
483 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31484}
485
[email protected]6f371442011-11-09 06:45:46486void ChromeContentBrowserClient::SiteInstanceGotProcess(
487 SiteInstance* site_instance) {
488 CHECK(site_instance->HasProcess());
489
490 Profile* profile = Profile::FromBrowserContext(
491 site_instance->browsing_instance()->browser_context());
492 ExtensionService* service = profile->GetExtensionService();
493 if (!service)
494 return;
495
496 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44497 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
498 site_instance->site()));
[email protected]6f371442011-11-09 06:45:46499 if (!extension)
500 return;
501
[email protected]6bc04fd82011-12-04 02:29:35502 service->process_map()->Insert(extension->id(),
503 site_instance->GetProcess()->GetID(),
504 site_instance->id());
[email protected]6f371442011-11-09 06:45:46505 BrowserThread::PostTask(
506 BrowserThread::IO, FROM_HERE,
507 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
508 profile->GetExtensionInfoMap(),
509 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35510 site_instance->GetProcess()->GetID(),
511 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46512}
513
514void ChromeContentBrowserClient::SiteInstanceDeleting(
515 SiteInstance* site_instance) {
516 if (!site_instance->HasProcess())
517 return;
518
519 Profile* profile = Profile::FromBrowserContext(
520 site_instance->browsing_instance()->browser_context());
521 ExtensionService* service = profile->GetExtensionService();
522 if (!service)
523 return;
524
525 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44526 service->extensions()->GetExtensionOrAppByURL(
527 ExtensionURLInfo(site_instance->site()));
[email protected]6f371442011-11-09 06:45:46528 if (!extension)
529 return;
530
[email protected]6bc04fd82011-12-04 02:29:35531 service->process_map()->Remove(extension->id(),
532 site_instance->GetProcess()->GetID(),
533 site_instance->id());
[email protected]6f371442011-11-09 06:45:46534 BrowserThread::PostTask(
535 BrowserThread::IO, FROM_HERE,
536 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
537 profile->GetExtensionInfoMap(),
538 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35539 site_instance->GetProcess()->GetID(),
540 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46541}
542
[email protected]e3daf3c2011-10-05 21:17:08543bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
544 const GURL& current_url,
545 const GURL& new_url) {
546 if (current_url.is_empty()) {
547 // Always choose a new process when navigating to extension URLs. The
548 // process grouping logic will combine all of a given extension's pages
549 // into the same process.
550 if (new_url.SchemeIs(chrome::kExtensionScheme))
551 return true;
552
553 return false;
554 }
555
556 // Also, we must switch if one is an extension and the other is not the exact
557 // same extension.
558 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
559 new_url.SchemeIs(chrome::kExtensionScheme)) {
560 if (current_url.GetOrigin() != new_url.GetOrigin())
561 return true;
562 }
563
564 return false;
565}
566
[email protected]763ec4ca2011-04-29 15:48:12567std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
568 const std::string& alias_name) {
569 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
570}
571
[email protected]b80f68432011-05-02 17:22:30572void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
573 CommandLine* command_line, int child_process_id) {
574#if defined(USE_LINUX_BREAKPAD)
575 if (IsCrashReporterEnabled()) {
576 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
577 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
578 }
579#elif defined(OS_MACOSX)
580 if (IsCrashReporterEnabled()) {
581 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
582 child_process_logging::GetClientId());
583 }
584#endif // OS_MACOSX
585
[email protected]f1933792011-06-14 00:49:34586 if (logging::DialogsAreSuppressed())
587 command_line->AppendSwitch(switches::kNoErrorDialogs);
588
[email protected]b80f68432011-05-02 17:22:30589 std::string process_type =
590 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17591 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52592 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30593 FilePath user_data_dir =
594 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
595 if (!user_data_dir.empty())
596 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
597#if defined(OS_CHROMEOS)
598 const std::string& login_profile =
599 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
600 if (!login_profile.empty())
601 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
602#endif
603
[email protected]f3b1a082011-11-18 00:34:30604 content::RenderProcessHost* process =
605 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37606 if (process) {
607 Profile* profile = Profile::FromBrowserContext(
608 process->GetBrowserContext());
609 extensions::ProcessMap* process_map =
610 profile->GetExtensionService()->process_map();
611 if (process_map && process_map->Contains(process->GetID()))
612 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30613
[email protected]a8d851f82011-12-21 00:32:37614 PrefService* prefs = profile->GetPrefs();
615 // Currently this pref is only registered if applied via a policy.
616 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
617 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
618 // Turn this policy into a command line switch.
619 command_line->AppendSwitch(switches::kDisable3DAPIs);
620 }
[email protected]718eab62011-10-05 21:16:52621
[email protected]a8d851f82011-12-21 00:32:37622 // Disable client-side phishing detection in the renderer if it is
623 // disabled in the Profile preferences or the browser process.
624 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
625 !g_browser_process->safe_browsing_detection_service()) {
626 command_line->AppendSwitch(
627 switches::kDisableClientSidePhishingDetection);
628 }
[email protected]8c40da62011-07-13 22:58:46629 }
[email protected]47c7ec82012-01-18 03:29:21630 {
631 PrefService* local_state = g_browser_process->local_state();
632 if (local_state &&
633 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
634 command_line->AppendSwitch(switches::kRendererPrintPreview);
635 }
636 }
[email protected]4287a3d2011-06-13 23:56:51637
[email protected]47c7ec82012-01-18 03:29:21638 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51639 static const char* const kSwitchNames[] = {
640 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48641 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18642 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51643 switches::kAllowScriptingGallery,
644 switches::kAppsCheckoutURL,
645 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31646 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51647 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51648 switches::kDomAutomationController,
649 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21650 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51651 switches::kEnableClickToPlay,
652 switches::kEnableCrxlessWebApps,
653 switches::kEnableExperimentalExtensionApis,
654 switches::kEnableInBrowserThumbnailing,
655 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12656 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51657 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53658 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51659 switches::kEnableSearchProviderApiV2,
660 switches::kEnableWatchdog,
661 switches::kExperimentalSpellcheckerFeatures,
662 switches::kMemoryProfiling,
663 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04664 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51665 switches::kPpapiFlashArgs,
666 switches::kPpapiFlashInProcess,
667 switches::kPpapiFlashPath,
668 switches::kPpapiFlashVersion,
669 switches::kProfilingAtStart,
670 switches::kProfilingFile,
671 switches::kProfilingFlush,
[email protected]47c7ec82012-01-18 03:29:21672 switches::kRendererPrintPreview,
[email protected]4287a3d2011-06-13 23:56:51673 switches::kSilentDumpOnDCHECK,
674 };
675
676 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
677 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17678 } else if (process_type == switches::kUtilityProcess) {
679 if (browser_command_line.HasSwitch(
680 switches::kEnableExperimentalExtensionApis)) {
681 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
682 }
[email protected]4287a3d2011-06-13 23:56:51683 } else if (process_type == switches::kPluginProcess) {
684 static const char* const kSwitchNames[] = {
685 #if defined(OS_CHROMEOS)
686 switches::kLoginProfile,
687 #endif
688 switches::kMemoryProfiling,
689 switches::kSilentDumpOnDCHECK,
690 switches::kUserDataDir,
691 };
692
693 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
694 arraysize(kSwitchNames));
695 } else if (process_type == switches::kZygoteProcess) {
696 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51697 switches::kUserDataDir, // Make logs go to the right file.
698 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
699 switches::kPpapiFlashInProcess,
700 switches::kPpapiFlashPath,
701 switches::kPpapiFlashVersion,
702 };
703
704 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
705 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30706 }
[email protected]6f08af82011-09-15 01:19:03707
708 // The command line switch kEnableBenchmarking needs to be specified along
709 // with the kEnableStatsTable switch to ensure that the stats table global
710 // is initialized correctly.
711 if (command_line->HasSwitch(switches::kEnableBenchmarking))
712 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30713}
714
715std::string ChromeContentBrowserClient::GetApplicationLocale() {
716 return g_browser_process->GetApplicationLocale();
717}
718
[email protected]597a867b2011-11-18 18:31:20719std::string ChromeContentBrowserClient::GetAcceptLangs(
720 content::BrowserContext* context) {
721 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37722 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08723}
724
[email protected]ac55e292011-06-24 05:16:08725SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22726 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08727 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
728}
729
[email protected]a2176792011-05-08 19:30:49730bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09731 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19732 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09733 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
735 ProfileIOData* io_data =
736 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05737 return io_data->GetCookieSettings()->
738 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49739}
740
[email protected]ed24fad2011-05-10 22:44:01741bool ChromeContentBrowserClient::AllowGetCookie(
742 const GURL& url,
743 const GURL& first_party,
744 const net::CookieList& cookie_list,
745 const content::ResourceContext& context,
746 int render_process_id,
747 int render_view_id) {
748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32749 ProfileIOData* io_data =
750 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05751 bool allow = io_data->GetCookieSettings()->
752 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01753
[email protected]8093a542011-05-13 07:29:32754 BrowserThread::PostTask(
755 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03756 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
757 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01758 return allow;
759}
760
761bool ChromeContentBrowserClient::AllowSetCookie(
762 const GURL& url,
763 const GURL& first_party,
764 const std::string& cookie_line,
765 const content::ResourceContext& context,
766 int render_process_id,
767 int render_view_id,
768 net::CookieOptions* options) {
769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32770 ProfileIOData* io_data =
771 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01772
[email protected]30fde822011-10-28 09:49:05773 CookieSettings* cookie_settings = io_data->GetCookieSettings();
774 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
775
776 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09777 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01778
[email protected]8093a542011-05-13 07:29:32779 BrowserThread::PostTask(
780 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03781 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
782 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01783 return allow;
784}
785
[email protected]d5a19162011-06-30 18:51:54786bool ChromeContentBrowserClient::AllowSaveLocalState(
787 const content::ResourceContext& context) {
788 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
789 ProfileIOData* io_data =
790 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
791 return !io_data->clear_local_state_on_exit()->GetValue();
792}
793
[email protected]5c5a88e2011-11-12 00:45:35794bool ChromeContentBrowserClient::AllowWorkerDatabase(
795 int worker_route_id,
796 const GURL& url,
797 const string16& name,
798 const string16& display_name,
799 unsigned long estimated_size,
800 WorkerProcessHost* worker_process_host) {
801 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
802 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
803 worker_process_host->resource_context()->GetUserData(NULL));
804 CookieSettings* cookie_settings = io_data->GetCookieSettings();
805 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
806
807 // Record access to database for potential display in UI: Find the worker
808 // instance and forward the message to all attached documents.
809 WorkerProcessHost::Instances::const_iterator i;
810 for (i = worker_process_host->instances().begin();
811 i != worker_process_host->instances().end(); ++i) {
812 if (i->worker_route_id() != worker_route_id)
813 continue;
814 const WorkerDocumentSet::DocumentInfoSet& documents =
815 i->worker_document_set()->documents();
816 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
817 documents.begin(); doc != documents.end(); ++doc) {
818 BrowserThread::PostTask(
819 BrowserThread::UI, FROM_HERE,
820 base::Bind(
821 &TabSpecificContentSettings::WebDatabaseAccessed,
822 doc->render_process_id(), doc->render_view_id(),
823 url, name, display_name, !allow));
824 }
825 break;
826 }
827
828 return allow;
829}
830
831bool ChromeContentBrowserClient::AllowWorkerFileSystem(
832 int worker_route_id,
833 const GURL& url,
834 WorkerProcessHost* worker_process_host) {
835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
836 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
837 worker_process_host->resource_context()->GetUserData(NULL));
838 CookieSettings* cookie_settings = io_data->GetCookieSettings();
839 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
840
841 // Record access to file system for potential display in UI: Find the worker
842 // instance and forward the message to all attached documents.
843 WorkerProcessHost::Instances::const_iterator i;
844 for (i = worker_process_host->instances().begin();
845 i != worker_process_host->instances().end(); ++i) {
846 if (i->worker_route_id() != worker_route_id)
847 continue;
848 const WorkerDocumentSet::DocumentInfoSet& documents =
849 i->worker_document_set()->documents();
850 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
851 documents.begin(); doc != documents.end(); ++doc) {
852 BrowserThread::PostTask(
853 BrowserThread::UI, FROM_HERE,
854 base::Bind(
855 &TabSpecificContentSettings::FileSystemAccessed,
856 doc->render_process_id(), doc->render_view_id(), url, !allow));
857 }
858 break;
859 }
860
861 return allow;
862}
863
[email protected]6133f922011-07-01 21:34:34864net::URLRequestContext*
865ChromeContentBrowserClient::OverrideRequestContextForURL(
866 const GURL& url, const content::ResourceContext& context) {
867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
868 if (url.SchemeIs(chrome::kExtensionScheme)) {
869 ProfileIOData* io_data =
870 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
871 return io_data->extensions_request_context();
872 }
873
874 return NULL;
875}
876
[email protected]317f96c92011-05-31 06:53:41877QuotaPermissionContext*
878ChromeContentBrowserClient::CreateQuotaPermissionContext() {
879 return new ChromeQuotaPermissionContext();
880}
881
[email protected]a0ce3282011-08-19 20:49:52882void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42883 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42884}
885
[email protected]a0ce3282011-08-19 20:49:52886void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52887 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52888}
889
[email protected]848dd042011-06-04 18:24:03890void ChromeContentBrowserClient::AllowCertificateError(
891 SSLCertErrorHandler* handler,
892 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58893 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41894 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13895 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]f9034cf2011-07-21 12:43:41896 handler->render_process_host_id(),
897 handler->tab_contents_id());
898 if (!tab) {
899 NOTREACHED();
900 return;
901 }
902 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50903 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30904 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09905 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41906 if (prerender_manager->prerender_tracker()->TryCancel(
907 handler->render_process_host_id(),
908 handler->tab_contents_id(),
909 prerender::FINAL_STATUS_SSL_ERROR)) {
910 handler->CancelRequest();
911 return;
912 }
913 }
914
915 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03916 SSLBlockingPage* blocking_page = new SSLBlockingPage(
917 handler, overridable, callback);
918 blocking_page->Show();
919}
920
[email protected]c99c442e2011-08-24 11:37:30921void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45922 int render_process_id,
923 int render_view_id,
924 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13925 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45926 render_process_id, render_view_id);
927 if (!tab) {
928 NOTREACHED();
929 return;
930 }
931
[email protected]6786bf402011-12-03 15:19:45932 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
933 GURL requesting_url("https://" + cert_request_info->host_and_port);
934 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
935 << cert_request_info->host_and_port;
936
[email protected]627e0512011-12-21 22:55:30937 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45938 DCHECK(profile);
939 scoped_ptr<Value> filter(
940 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
941 requesting_url,
942 requesting_url,
943 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
944 std::string(), NULL));
945
946 if (filter.get()) {
947 // Try to automatically select a client certificate.
948 if (filter->IsType(Value::TYPE_DICTIONARY)) {
949 DictionaryValue* filter_dict =
950 static_cast<DictionaryValue*>(filter.get());
951
952 const std::vector<scoped_refptr<net::X509Certificate> >&
953 all_client_certs = cert_request_info->client_certs;
954 for (size_t i = 0; i < all_client_certs.size(); ++i) {
955 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
956 // Use the first certificate that is matched by the filter.
957 handler->CertificateSelected(all_client_certs[i]);
958 return;
959 }
960 }
961 } else {
962 NOTREACHED();
963 }
964 }
965
[email protected]8ec26472011-06-06 16:52:45966 TabContentsWrapper* wrapper =
967 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45968 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13969 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45970 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14971 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45972 handler->CertificateSelected(NULL);
973 return;
974 }
975 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45976}
977
978void ChromeContentBrowserClient::AddNewCertificate(
979 net::URLRequest* request,
980 net::X509Certificate* cert,
981 int render_process_id,
982 int render_view_id) {
983 // The handler will run the UI and delete itself when it's finished.
984 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
985}
986
[email protected]941623e2011-06-07 23:06:04987void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
988 const GURL& source_origin,
989 int callback_context,
990 int render_process_id,
991 int render_view_id) {
992 RenderViewHost* rvh = RenderViewHost::FromID(
993 render_process_id, render_view_id);
994 if (!rvh) {
995 NOTREACHED();
996 return;
997 }
998
[email protected]f3b1a082011-11-18 00:34:30999 content::RenderProcessHost* process = rvh->process();
1000 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041001 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371002 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041003 service->RequestPermission(
1004 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131005 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:041006}
1007
1008WebKit::WebNotificationPresenter::Permission
1009 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021010 const GURL& source_origin,
1011 const content::ResourceContext& context,
1012 int render_process_id) {
[email protected]941623e2011-06-07 23:06:041013 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1014 ProfileIOData* io_data =
1015 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1016
[email protected]34eec7ffe32011-11-02 23:49:021017 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1018 source_origin, render_process_id,
1019 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041020 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041021
1022 // Fall back to the regular notification preferences, which works on an
1023 // origin basis.
1024 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371025 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041026 WebKit::WebNotificationPresenter::PermissionNotAllowed;
1027}
1028
1029void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171030 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041031 int render_process_id,
1032 int render_view_id,
1033 bool worker) {
1034 RenderViewHost* rvh = RenderViewHost::FromID(
1035 render_process_id, render_view_id);
1036 if (!rvh) {
1037 NOTREACHED();
1038 return;
1039 }
1040
[email protected]f3b1a082011-11-18 00:34:301041 content::RenderProcessHost* process = rvh->process();
1042 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041043 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371044 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041045 service->ShowDesktopNotification(
1046 params, render_process_id, render_view_id,
1047 worker ? DesktopNotificationService::WorkerNotification :
1048 DesktopNotificationService::PageNotification);
1049}
1050
1051void ChromeContentBrowserClient::CancelDesktopNotification(
1052 int render_process_id,
1053 int render_view_id,
1054 int notification_id) {
1055 RenderViewHost* rvh = RenderViewHost::FromID(
1056 render_process_id, render_view_id);
1057 if (!rvh) {
1058 NOTREACHED();
1059 return;
1060 }
1061
[email protected]f3b1a082011-11-18 00:34:301062 content::RenderProcessHost* process = rvh->process();
1063 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041064 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371065 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041066 service->CancelDesktopNotification(
1067 render_process_id, render_view_id, notification_id);
1068}
1069
[email protected]9f3fba52011-06-08 20:37:191070bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021071 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191072 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021073 const content::ResourceContext& context,
1074 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1076 // If the opener is trying to create a background window but doesn't have
1077 // the appropriate permission, fail the attempt.
1078 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1079 ProfileIOData* io_data =
1080 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021081 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1082 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191083 }
1084 return true;
1085}
1086
1087std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1088 const GURL& url, const content::ResourceContext& context) {
1089 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1090 // Check if it's an extension-created worker, in which case we want to use
1091 // the name of the extension.
1092 ProfileIOData* io_data =
1093 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1094 const Extension* extension =
1095 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1096 return extension ? extension->name() : std::string();
1097}
1098
[email protected]99907362012-01-11 05:41:401099void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1100 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171101}
1102
1103ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1104 return g_browser_process->clipboard();
1105}
1106
[email protected]8f6a3b852011-07-19 16:48:561107MHTMLGenerationManager*
1108 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1109 return g_browser_process->mhtml_generation_manager();
1110}
1111
[email protected]ae6e9912011-07-27 01:18:281112net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1113 return g_browser_process->net_log();
1114}
1115
[email protected]3bc0b562011-08-24 23:51:041116speech_input::SpeechInputManager*
1117 ChromeContentBrowserClient::GetSpeechInputManager() {
1118 return speech_input::ChromeSpeechInputManager::GetInstance();
1119}
1120
[email protected]32538d92011-08-25 00:09:231121AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1122 return new ChromeAccessTokenStore();
1123}
1124
[email protected]dbae6b02011-06-29 23:51:411125bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1126 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1127 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1128}
1129
[email protected]5092c282011-10-29 21:48:371130WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061131 Profile* profile = Profile::FromBrowserContext(
1132 rvh->process()->GetBrowserContext());
1133 PrefService* prefs = profile->GetPrefs();
1134 WebPreferences web_prefs;
1135
1136 web_prefs.standard_font_family =
1137 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
1138 web_prefs.fixed_font_family =
1139 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
1140 web_prefs.serif_font_family =
1141 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
1142 web_prefs.sans_serif_font_family =
1143 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
1144 web_prefs.cursive_font_family =
1145 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
1146 web_prefs.fantasy_font_family =
1147 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1148
1149 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
1150 &web_prefs.standard_font_family_map);
1151 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
1152 &web_prefs.fixed_font_family_map);
1153 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
1154 &web_prefs.serif_font_family_map);
1155 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
1156 &web_prefs.sans_serif_font_family_map);
1157 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
1158 &web_prefs.cursive_font_family_map);
1159 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
1160 &web_prefs.fantasy_font_family_map);
1161
1162 web_prefs.default_font_size =
1163 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
1164 web_prefs.default_fixed_font_size =
1165 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
1166 web_prefs.minimum_font_size =
1167 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
1168 web_prefs.minimum_logical_font_size =
1169 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1170
1171 web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
1172
1173 web_prefs.javascript_can_open_windows_automatically =
1174 prefs->GetBoolean(
1175 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
1176 web_prefs.dom_paste_enabled =
1177 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
1178 web_prefs.shrinks_standalone_images_to_fit =
1179 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1180 const DictionaryValue* inspector_settings =
1181 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1182 if (inspector_settings) {
1183 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1184 iter != inspector_settings->end_keys(); ++iter) {
1185 std::string value;
1186 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
1187 web_prefs.inspector_settings.push_back(
1188 std::make_pair(*iter, value));
1189 }
1190 }
1191 web_prefs.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
1192
1193 { // Command line switches are used for preferences with no user interface.
1194 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1195 web_prefs.developer_extras_enabled = true;
1196 web_prefs.javascript_enabled =
1197 !command_line.HasSwitch(switches::kDisableJavaScript) &&
1198 prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled);
1199 web_prefs.dart_enabled = !command_line.HasSwitch(switches::kDisableDart);
1200 web_prefs.web_security_enabled =
1201 !command_line.HasSwitch(switches::kDisableWebSecurity) &&
1202 prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled);
1203 web_prefs.plugins_enabled =
1204 !command_line.HasSwitch(switches::kDisablePlugins) &&
1205 prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled);
1206 web_prefs.java_enabled =
1207 !command_line.HasSwitch(switches::kDisableJava) &&
1208 prefs->GetBoolean(prefs::kWebKitJavaEnabled);
1209 web_prefs.loads_images_automatically =
1210 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
1211 web_prefs.uses_page_cache =
1212 command_line.HasSwitch(switches::kEnableFastback);
1213 web_prefs.remote_fonts_enabled =
1214 !command_line.HasSwitch(switches::kDisableRemoteFonts);
1215 web_prefs.xss_auditor_enabled =
1216 !command_line.HasSwitch(switches::kDisableXSSAuditor);
1217 web_prefs.application_cache_enabled =
1218 !command_line.HasSwitch(switches::kDisableApplicationCache);
1219
1220 web_prefs.local_storage_enabled =
1221 !command_line.HasSwitch(switches::kDisableLocalStorage);
1222 web_prefs.databases_enabled =
1223 !command_line.HasSwitch(switches::kDisableDatabases);
1224 web_prefs.webaudio_enabled =
1225 !command_line.HasSwitch(switches::kDisableWebAudio);
1226 web_prefs.experimental_webgl_enabled =
1227 GpuProcessHost::gpu_enabled() &&
1228 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
1229 !prefs->GetBoolean(prefs::kDisable3DAPIs) &&
1230 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
1231 web_prefs.gl_multisampling_enabled =
1232 !command_line.HasSwitch(switches::kDisableGLMultisampling);
1233 web_prefs.privileged_webgl_extensions_enabled =
1234 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
1235 web_prefs.site_specific_quirks_enabled =
1236 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
1237 web_prefs.allow_file_access_from_file_urls =
1238 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
1239 web_prefs.show_composited_layer_borders =
1240 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
1241 web_prefs.show_composited_layer_tree =
1242 command_line.HasSwitch(switches::kShowCompositedLayerTree);
1243 web_prefs.show_fps_counter =
1244 command_line.HasSwitch(switches::kShowFPSCounter);
1245 web_prefs.accelerated_compositing_enabled =
1246 GpuProcessHost::gpu_enabled() &&
1247 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
1248 web_prefs.threaded_compositing_enabled =
1249 command_line.HasSwitch(switches::kEnableThreadedCompositing);
1250 web_prefs.force_compositing_mode =
1251 command_line.HasSwitch(switches::kForceCompositingMode);
1252 web_prefs.fixed_position_compositing_enabled =
1253 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
1254 web_prefs.allow_webui_compositing =
1255 command_line.HasSwitch(switches::kAllowWebUICompositing);
1256 web_prefs.accelerated_2d_canvas_enabled =
1257 GpuProcessHost::gpu_enabled() &&
1258 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
1259 web_prefs.accelerated_painting_enabled =
1260 GpuProcessHost::gpu_enabled() &&
1261 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
1262 web_prefs.accelerated_filters_enabled =
1263 GpuProcessHost::gpu_enabled() &&
1264 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
1265 web_prefs.accelerated_layers_enabled =
1266 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
1267 web_prefs.composite_to_texture_enabled =
1268 command_line.HasSwitch(switches::kEnableCompositeToTexture);
1269 web_prefs.accelerated_plugins_enabled =
1270 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
1271 web_prefs.accelerated_video_enabled =
1272 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
1273 web_prefs.partial_swap_enabled =
1274 command_line.HasSwitch(switches::kEnablePartialSwap);
1275 web_prefs.memory_info_enabled =
1276 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1277 web_prefs.interactive_form_validation_enabled =
1278 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
1279 web_prefs.fullscreen_enabled =
1280 !command_line.HasSwitch(switches::kDisableFullScreen);
1281 web_prefs.allow_displaying_insecure_content =
1282 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1283 web_prefs.allow_running_insecure_content =
1284 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
1285
1286#if defined(OS_MACOSX)
1287 bool default_enable_scroll_animator = true;
1288#else
1289 // On CrOS, the launcher always passes in the --enable flag.
1290 bool default_enable_scroll_animator = false;
1291#endif
1292 web_prefs.enable_scroll_animator = default_enable_scroll_animator;
1293 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
1294 web_prefs.enable_scroll_animator = true;
1295 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
1296 web_prefs.enable_scroll_animator = false;
1297
1298 // The user stylesheet watcher may not exist in a testing profile.
1299 if (profile->GetUserStyleSheetWatcher()) {
1300 web_prefs.user_style_sheet_enabled = true;
1301 web_prefs.user_style_sheet_location =
1302 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1303 } else {
1304 web_prefs.user_style_sheet_enabled = false;
1305 }
1306
1307 web_prefs.visual_word_movement_enabled =
1308 command_line.HasSwitch(switches::kEnableVisualWordMovement);
1309 web_prefs.unified_textchecker_enabled =
1310 command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures);
1311 web_prefs.per_tile_painting_enabled =
1312 command_line.HasSwitch(switches::kEnablePerTilePainting);
1313 }
1314
1315 { // Certain GPU features might have been blacklisted.
1316 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
1317 DCHECK(gpu_data_manager);
1318 uint32 blacklist_flags = gpu_data_manager->GetGpuFeatureFlags().flags();
1319 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)
1320 web_prefs.accelerated_compositing_enabled = false;
1321 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureWebgl)
1322 web_prefs.experimental_webgl_enabled = false;
1323 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)
1324 web_prefs.accelerated_2d_canvas_enabled = false;
1325 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureMultisampling)
1326 web_prefs.gl_multisampling_enabled = false;
1327 }
1328
1329 web_prefs.uses_universal_detector =
1330 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
1331 web_prefs.text_areas_are_resizable =
1332 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
1333 web_prefs.hyperlink_auditing_enabled =
1334 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1335
1336 // Make sure we will set the default_encoding with canonical encoding name.
1337 web_prefs.default_encoding =
1338 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
1339 web_prefs.default_encoding);
1340 if (web_prefs.default_encoding.empty()) {
1341 prefs->ClearPref(prefs::kGlobalDefaultCharset);
1342 web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
1343 }
1344 DCHECK(!web_prefs.default_encoding.empty());
1345
1346 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
1347 rvh->process()->GetID())) {
1348 web_prefs.loads_images_automatically = true;
1349 web_prefs.javascript_enabled = true;
1350 }
1351
1352 web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
1353
1354 ExtensionService* service = profile->GetExtensionService();
1355 if (service) {
1356 const Extension* extension = service->extensions()->GetByID(
1357 rvh->site_instance()->site().host());
1358 extension_webkit_preferences::SetPreferences(
1359 extension, rvh->delegate()->GetRenderViewType(), &web_prefs);
1360 }
1361
1362 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
1363 web_prefs.allow_scripts_to_close_windows = true;
1364 } else if (rvh->delegate()->GetRenderViewType() ==
1365 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1366 // Disable all kinds of acceleration for background pages.
1367 // See http://crbug.com/96005 and http://crbug.com/96006
1368 web_prefs.force_compositing_mode = false;
1369 web_prefs.accelerated_compositing_enabled = false;
1370 web_prefs.accelerated_2d_canvas_enabled = false;
1371 web_prefs.accelerated_video_enabled = false;
1372 web_prefs.accelerated_painting_enabled = false;
1373 web_prefs.accelerated_plugins_enabled = false;
1374 }
1375
1376 return web_prefs;
[email protected]181a95ee2011-07-12 19:26:361377}
1378
1379void ChromeContentBrowserClient::UpdateInspectorSetting(
1380 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061381 content::BrowserContext* browser_context =
1382 rvh->process()->GetBrowserContext();
1383 DictionaryPrefUpdate update(
1384 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1385 prefs::kWebKitInspectorSettings);
1386 DictionaryValue* inspector_settings = update.Get();
1387 inspector_settings->SetWithoutPathExpansion(key,
1388 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361389}
1390
1391void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061392 content::BrowserContext* browser_context =
1393 rvh->process()->GetBrowserContext();
1394 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1395 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361396}
1397
[email protected]b8148ac2011-07-13 22:03:251398void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1399 BrowserURLHandler* handler) {
1400 // Add the default URL handlers.
1401 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1402 BrowserURLHandler::null_handler());
1403 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1404 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1405
[email protected]b3adbd02011-11-30 22:23:271406 // about: handler. Must come before chrome: handler, since it will
1407 // rewrite about: urls to chrome: URLs and then expect chrome: to
1408 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251409 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1410 BrowserURLHandler::null_handler());
1411 // chrome: & friends.
1412 handler->AddHandlerPair(&HandleWebUI,
1413 BrowserURLHandler::null_handler());
1414}
1415
1416void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371417 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301418 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251419 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1420 BrowsingDataRemover::EVERYTHING,
1421 base::Time());
1422 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1423 // BrowsingDataRemover takes care of deleting itself when done.
1424}
1425
1426void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371427 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301428 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251429 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1430 BrowsingDataRemover::EVERYTHING,
1431 base::Time());
[email protected]dceaa912011-09-06 17:17:231432 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251433 remover->Remove(remove_mask);
1434 // BrowsingDataRemover takes care of deleting itself when done.
1435}
1436
[email protected]e1d16eb92011-08-18 23:19:321437FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1438 return download_util::GetDefaultDownloadDirectory();
1439}
1440
[email protected]c9b6eb62011-10-18 20:49:391441std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1442 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1443}
1444
[email protected]e60c0232011-11-11 19:56:351445#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301446int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521447 const CommandLine& command_line) {
1448 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071449 ExtensionCrashHandlerHostLinux* crash_handler =
1450 ExtensionCrashHandlerHostLinux::GetInstance();
1451 return crash_handler->GetDeathSignalSocket();
1452 }
1453
[email protected]718eab62011-10-05 21:16:521454 std::string process_type =
1455 command_line.GetSwitchValueASCII(switches::kProcessType);
1456
1457 if (process_type == switches::kRendererProcess)
1458 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1459
[email protected]b80f68432011-05-02 17:22:301460 if (process_type == switches::kPluginProcess)
1461 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1462
1463 if (process_type == switches::kPpapiPluginProcess)
1464 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1465
1466 if (process_type == switches::kGpuProcess)
1467 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1468
1469 return -1;
1470}
[email protected]e60c0232011-11-11 19:56:351471#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301472
[email protected]4a65826d2011-08-25 16:04:011473#if defined(OS_WIN)
1474const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1475 return chrome::kBrowserResourcesDll;
1476}
1477#endif
1478
[email protected]37a72af2011-06-13 05:42:011479#if defined(USE_NSS)
1480crypto::CryptoModuleBlockingPasswordDelegate*
1481 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1482 const GURL& url) {
1483 return browser::NewCryptoModuleBlockingDialogDelegate(
1484 browser::kCryptoModulePasswordKeygen, url.host());
1485}
1486#endif
1487
[email protected]d977f9c2011-03-14 16:10:261488} // namespace chrome