blob: a37af6fad8d6074480fe3dc625810ddf848d967d [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]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]6e672df2012-01-25 10:39:4725#include "chrome/browser/extensions/api/webrequest/webrequest_api.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]32538d92011-08-25 00:09:2331#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1232#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2833#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0434#include "chrome/browser/notifications/desktop_notification_service.h"
35#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4236#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1237#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0638#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4139#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5040#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4141#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1442#include "chrome/browser/printing/printing_message_filter.h"
43#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3244#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1445#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3346#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4247#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1448#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0449#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4650#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4551#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0352#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4553#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
54#include "chrome/browser/tab_contents/tab_util.h"
55#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5656#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]f3986f82012-01-03 20:00:0657#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3058#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0159#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3060#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0461#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4462#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3463#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1264#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3865#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0966#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2567#include "content/browser/browser_url_handler.h"
[email protected]f3986f82012-01-03 20:00:0668#include "content/browser/child_process_security_policy.h"
69#include "content/browser/gpu/gpu_data_manager.h"
70#include "content/browser/gpu/gpu_process_host.h"
[email protected]97e6c4c2011-05-18 16:08:5171#include "content/browser/plugin_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2672#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4973#include "content/browser/resource_context.h"
[email protected]f9034cf2011-07-21 12:43:4174#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4575#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]5327dfb2011-05-03 17:50:3676#include "content/browser/worker_host/worker_process_host.h"
[email protected]b48c9182011-10-26 18:03:3077#include "content/public/browser/browser_main_parts.h"
[email protected]f3b1a082011-11-18 00:34:3078#include "content/public/browser/render_process_host.h"
[email protected]b6583592012-01-25 19:52:3379#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1980#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1081#include "content/public/browser/web_contents_view.h"
[email protected]c9b6eb62011-10-18 20:49:3982#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3483#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0184#include "net/base/cookie_monster.h"
85#include "net/base/cookie_options.h"
[email protected]f3986f82012-01-03 20:00:0686#include "net/base/network_change_notifier.h"
[email protected]c9b6eb62011-10-18 20:49:3987#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0888#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3689#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2690
[email protected]b48c9182011-10-26 18:03:3091#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3892#include "chrome/browser/chrome_browser_main_win.h"
93#elif defined(OS_MACOSX)
94#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5695#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3096#elif defined(OS_CHROMEOS)
97#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3598#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3099#include "chrome/browser/chrome_browser_main_linux.h"
100#elif defined(OS_POSIX)
101#include "chrome/browser/chrome_browser_main_posix.h"
102#endif
103
[email protected]b48c9182011-10-26 18:03:30104#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31105#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38106#endif
107
[email protected]c7480942011-11-08 19:18:27108#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31109#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27110#endif
111
112#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31113#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
114#endif
115
[email protected]e60c0232011-11-11 19:56:35116#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30117#include "base/linux_util.h"
118#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43119#endif
[email protected]b80f68432011-05-02 17:22:30120
[email protected]080f34f2011-09-20 05:39:26121#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32122#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21123#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45124#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]90580422012-01-12 00:26:22125#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32126#elif defined(OS_MACOSX)
[email protected]8dad546b2012-01-17 21:47:35127#include "chrome/browser/tab_contents/moving_to_content/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32128#endif
129
[email protected]37a72af2011-06-13 05:42:01130#if defined(USE_NSS)
131#include "chrome/browser/ui/crypto_module_password_dialog.h"
132#endif
133
[email protected]c8c77182011-12-21 15:04:47134using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39135using content::BrowserThread;
[email protected]b6583592012-01-25 19:52:33136using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13137using content::WebContents;
[email protected]631bb742011-11-02 11:29:39138
[email protected]c5dbef02011-05-13 05:06:09139namespace {
140
[email protected]b8148ac2011-07-13 22:03:25141// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42142bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37143 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25144 return false;
145
146 // Special case the new tab page. In older versions of Chrome, the new tab
147 // page was hosted at chrome-internal:<blah>. This might be in people's saved
148 // sessions or bookmarks, so we say any URL with that scheme triggers the new
149 // tab page.
150 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
151 // Rewrite it with the proper new tab URL.
152 *url = GURL(chrome::kChromeUINewTabURL);
153 }
154
155 return true;
156}
157
[email protected]8d3132f62011-10-12 07:13:42158// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
159// below. Extension, and isolated apps require different privileges to be
160// granted to their RenderProcessHosts. This classification allows us to make
161// sure URLs are served by hosts with the right set of privileges.
162enum RenderProcessHostPrivilege {
163 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45164 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42165 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45166 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42167};
168
169RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
170 const GURL& url,
171 ExtensionService* service) {
172 // Default to a normal renderer cause it is lower privileged. This should only
173 // occur if the URL on a site instance is either malformed, or uninitialized.
174 // If it is malformed, then there is no need for better privileges anyways.
175 // If it is uninitialized, but eventually settles on being an a scheme other
176 // than normal webrenderer, the navigation logic will correct us out of band
177 // anyways.
178 if (!url.is_valid())
179 return PRIV_NORMAL;
180
181 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44182 const Extension* extension =
183 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45184 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42185 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45186 if (extension && extension->is_hosted_app())
187 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42188
189 return PRIV_EXTENSION;
190 }
191
192 return PRIV_NORMAL;
193}
194
195RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30196 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46197 extensions::ProcessMap* process_map,
198 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46199 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30200 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46201 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21202 return PRIV_NORMAL;
203
[email protected]6f371442011-11-09 06:45:46204 for (std::set<std::string>::iterator iter = extension_ids.begin();
205 iter != extension_ids.end(); ++iter) {
206 const Extension* extension = service->GetExtensionById(*iter, false);
207 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42208 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45209 if (extension && extension->is_hosted_app())
210 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42211 }
212
[email protected]676f6ab2011-10-19 20:23:21213 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42214}
215
[email protected]eec0b33c2011-12-05 22:09:45216bool IsIsolatedAppInProcess(const GURL& site_url,
217 content::RenderProcessHost* process_host,
218 extensions::ProcessMap* process_map,
219 ExtensionService* service) {
220 std::set<std::string> extension_ids =
221 process_map->GetExtensionsInProcess(process_host->GetID());
222 if (extension_ids.empty())
223 return false;
224
225 for (std::set<std::string>::iterator iter = extension_ids.begin();
226 iter != extension_ids.end(); ++iter) {
227 const Extension* extension = service->GetExtensionById(*iter, false);
228 if (extension &&
229 extension->is_storage_isolated() &&
230 extension->url() == site_url)
231 return true;
232 }
233
234 return false;
235}
236
[email protected]6786bf402011-12-03 15:19:45237bool CertMatchesFilter(const net::X509Certificate& cert,
238 const base::DictionaryValue& filter) {
239 // TODO(markusheintz): This is the minimal required filter implementation.
240 // Implement a better matcher.
241
242 // An empty filter matches any client certificate since no requirements are
243 // specified at all.
244 if (filter.empty())
245 return true;
246
247 std::string common_name;
248 if (filter.GetString("ISSUER.CN", &common_name) &&
249 (cert.issuer().common_name == common_name)) {
250 return true;
251 }
252 return false;
253}
254
[email protected]f3986f82012-01-03 20:00:06255// Fills |map| with the per-script font prefs under path |map_name|.
256void FillFontFamilyMap(const PrefService* prefs,
257 const char* map_name,
258 WebPreferences::ScriptFontFamilyMap* map) {
259 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
260 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
261 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
262 std::string font_family = prefs->GetString(pref_name.c_str());
263 if (!font_family.empty())
264 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
265 }
266}
267
[email protected]9dbfff12011-07-01 19:37:07268} // namespace
[email protected]c5dbef02011-05-13 05:06:09269
[email protected]d977f9c2011-03-14 16:10:26270namespace chrome {
271
[email protected]50462bf02011-11-21 19:13:31272content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
273 const content::MainFunctionParams& parameters) {
274 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30275 // Construct the Main browser parts based on the OS type.
276#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31277 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04278#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31279 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30280#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31281 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35282#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31283 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30284#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31285 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04286#else
[email protected]b48c9182011-10-26 18:03:30287 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31288 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30289#endif
290
[email protected]c7480942011-11-08 19:18:27291 // Construct additional browser parts. Stages are called in the order in
292 // which they are added.
[email protected]b48c9182011-10-26 18:03:30293#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31294 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04295#endif
[email protected]c7480942011-11-08 19:18:27296
297#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31298 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27299#endif
300
301#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31302 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27303#endif
304
[email protected]50462bf02011-11-21 19:13:31305 return main_parts;
[email protected]f967b722011-09-07 00:58:04306}
307
[email protected]8643e6d2012-01-18 20:26:10308content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35309 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26310#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35311 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21312#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35313 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22314 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32315#elif defined(OS_MACOSX)
[email protected]8643e6d2012-01-18 20:26:10316 return tab_contents_view_mac::CreateWebContentsView(web_contents);
[email protected]74313b42011-08-24 16:51:32317#else
[email protected]8643e6d2012-01-18 20:26:10318#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32319#endif
320}
321
[email protected]f364d1392011-04-08 21:03:10322void ChromeContentBrowserClient::RenderViewHostCreated(
323 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46324
325 SiteInstance* site_instance = render_view_host->site_instance();
326 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02327 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46328
329 new ChromeRenderViewHostObserver(render_view_host,
330 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10331 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26332}
333
[email protected]f3b1a082011-11-18 00:34:30334void ChromeContentBrowserClient::RenderProcessHostCreated(
335 content::RenderProcessHost* host) {
336 int id = host->GetID();
337 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
338 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02339 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30340 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
341 host->GetChannel()->AddFilter(new PrintingMessageFilter());
342 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02343 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30344 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56345#if defined(OS_MACOSX)
346 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
347#endif
[email protected]f3b1a082011-11-18 00:34:30348 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03349 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38350
[email protected]2ccf45c2011-08-19 23:35:50351 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
352 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07353
354 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56355
356 RendererContentSettingRules rules;
357 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
358 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14359}
360
[email protected]1fd1a502011-03-30 16:55:56361content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
362 return ChromeWebUIFactory::GetInstance();
363}
364
[email protected]3d7474ff2011-07-27 17:47:37365GURL ChromeContentBrowserClient::GetEffectiveURL(
366 content::BrowserContext* browser_context, const GURL& url) {
367 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08368 // Get the effective URL for the given actual URL. If the URL is part of an
369 // installed app, the effective URL is an extension URL with the ID of that
370 // extension as the host. This has the effect of grouping apps together in
371 // a common SiteInstance.
372 if (!profile || !profile->GetExtensionService())
373 return url;
374
[email protected]615d88f2011-12-13 01:47:44375 const Extension* extension = profile->GetExtensionService()->extensions()->
376 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08377 if (!extension)
378 return url;
379
[email protected]15877ca2011-11-18 22:40:52380 // Bookmark apps do not use the hosted app process model, and should be
381 // treated as normal URLs.
382 if (extension->from_bookmark())
383 return url;
384
[email protected]36fb2c7c2011-04-04 15:49:08385 // If the URL is part of an extension's web extent, convert it to an
386 // extension URL.
387 return extension->GetResourceURL(url.path());
388}
389
[email protected]056ad2a2011-07-12 02:13:55390bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37391 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55392 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52393 // Because we expect to use the effective URL, URLs for hosted apps (apart
394 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55395 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
396 return false;
397
[email protected]3d7474ff2011-07-27 17:47:37398 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55399 if (!profile || !profile->GetExtensionService())
400 return false;
401
[email protected]615d88f2011-12-13 01:47:44402 const Extension* extension = profile->GetExtensionService()->extensions()->
403 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55404 if (!extension)
405 return false;
406
407 // If the URL is part of a hosted app that does not have the background
408 // permission, we want to give each instance its own process to improve
409 // responsiveness.
410 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
411 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
412 return false;
413
414 // Hosted apps that have the background permission must use process per site,
415 // since all instances can make synchronous calls to the background window.
416 // Other extensions should use process per site as well.
417 return true;
418}
419
[email protected]0f012df82011-05-19 14:15:29420bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03421 return url == GURL(chrome::kChromeUICrashURL) ||
422 url == GURL(chrome::kChromeUIKillURL) ||
423 url == GURL(chrome::kChromeUIHangURL) ||
424 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29425}
426
[email protected]46fb9442011-12-09 17:57:47427bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
428 return ProfileIOData::IsHandledURL(url);
429}
430
[email protected]2a5221b2011-09-27 23:07:31431bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30432 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31433 const GURL& site_url) {
434 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30435 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42436 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46437 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31438
[email protected]ffa97602011-11-17 17:55:52439 // Don't allow the Task Manager to share a process with anything else.
440 // Otherwise it can affect the renderers it is observing.
441 // Note: we could create another RenderProcessHostPrivilege bucket for
442 // this to allow multiple chrome://tasks instances to share, but that's
443 // a very unlikely case without serious consequences.
444 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
445 return false;
446
[email protected]8d3132f62011-10-12 07:13:42447 // These may be NULL during tests. In that case, just assume any site can
448 // share any host.
[email protected]6f371442011-11-09 06:45:46449 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31450 return true;
451
[email protected]a8c269a2011-10-25 20:17:22452 // Experimental:
453 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
454 // to share a renderer process. (We could allow pages from the same site or
455 // extensions of the same type to share, if we knew what the given process
456 // was dedicated to. Allowing no sharing is simpler for now.) This may
457 // cause resource exhaustion issues if too many sites are open at once.
458 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
459 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
460 return false;
461
[email protected]eec0b33c2011-12-05 22:09:45462 // An isolated app is only allowed to share with the exact same app in order
463 // to provide complete renderer process isolation. This also works around
464 // issue http://crbug.com/85588, where different isolated apps in the same
465 // process would end up using the first app's storage contexts.
466 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42467 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45468 if (privilege_required == PRIV_ISOLATED)
469 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
470
471 // Otherwise, just make sure the process privilege matches the privilege
472 // required by the site.
473 return GetProcessPrivilege(process_host, process_map, service) ==
474 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31475}
476
[email protected]6f371442011-11-09 06:45:46477void ChromeContentBrowserClient::SiteInstanceGotProcess(
478 SiteInstance* site_instance) {
479 CHECK(site_instance->HasProcess());
480
481 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02482 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46483 ExtensionService* service = profile->GetExtensionService();
484 if (!service)
485 return;
486
487 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44488 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33489 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46490 if (!extension)
491 return;
492
[email protected]6bc04fd82011-12-04 02:29:35493 service->process_map()->Insert(extension->id(),
494 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33495 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46496 BrowserThread::PostTask(
497 BrowserThread::IO, FROM_HERE,
498 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
499 profile->GetExtensionInfoMap(),
500 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35501 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33502 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46503}
504
505void ChromeContentBrowserClient::SiteInstanceDeleting(
506 SiteInstance* site_instance) {
507 if (!site_instance->HasProcess())
508 return;
509
510 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02511 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46512 ExtensionService* service = profile->GetExtensionService();
513 if (!service)
514 return;
515
516 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44517 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33518 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46519 if (!extension)
520 return;
521
[email protected]6bc04fd82011-12-04 02:29:35522 service->process_map()->Remove(extension->id(),
523 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33524 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46525 BrowserThread::PostTask(
526 BrowserThread::IO, FROM_HERE,
527 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
528 profile->GetExtensionInfoMap(),
529 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35530 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33531 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46532}
533
[email protected]e3daf3c2011-10-05 21:17:08534bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
535 const GURL& current_url,
536 const GURL& new_url) {
537 if (current_url.is_empty()) {
538 // Always choose a new process when navigating to extension URLs. The
539 // process grouping logic will combine all of a given extension's pages
540 // into the same process.
541 if (new_url.SchemeIs(chrome::kExtensionScheme))
542 return true;
543
544 return false;
545 }
546
547 // Also, we must switch if one is an extension and the other is not the exact
548 // same extension.
549 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
550 new_url.SchemeIs(chrome::kExtensionScheme)) {
551 if (current_url.GetOrigin() != new_url.GetOrigin())
552 return true;
553 }
554
555 return false;
556}
557
[email protected]763ec4ca2011-04-29 15:48:12558std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
559 const std::string& alias_name) {
560 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
561}
562
[email protected]b80f68432011-05-02 17:22:30563void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
564 CommandLine* command_line, int child_process_id) {
565#if defined(USE_LINUX_BREAKPAD)
566 if (IsCrashReporterEnabled()) {
567 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
568 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
569 }
570#elif defined(OS_MACOSX)
571 if (IsCrashReporterEnabled()) {
572 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
573 child_process_logging::GetClientId());
574 }
575#endif // OS_MACOSX
576
[email protected]f1933792011-06-14 00:49:34577 if (logging::DialogsAreSuppressed())
578 command_line->AppendSwitch(switches::kNoErrorDialogs);
579
[email protected]b80f68432011-05-02 17:22:30580 std::string process_type =
581 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17582 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52583 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30584 FilePath user_data_dir =
585 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
586 if (!user_data_dir.empty())
587 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
588#if defined(OS_CHROMEOS)
589 const std::string& login_profile =
590 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
591 if (!login_profile.empty())
592 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
593#endif
594
[email protected]f3b1a082011-11-18 00:34:30595 content::RenderProcessHost* process =
596 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37597 if (process) {
598 Profile* profile = Profile::FromBrowserContext(
599 process->GetBrowserContext());
600 extensions::ProcessMap* process_map =
601 profile->GetExtensionService()->process_map();
602 if (process_map && process_map->Contains(process->GetID()))
603 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30604
[email protected]a8d851f82011-12-21 00:32:37605 PrefService* prefs = profile->GetPrefs();
606 // Currently this pref is only registered if applied via a policy.
607 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
608 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
609 // Turn this policy into a command line switch.
610 command_line->AppendSwitch(switches::kDisable3DAPIs);
611 }
[email protected]718eab62011-10-05 21:16:52612
[email protected]a8d851f82011-12-21 00:32:37613 // Disable client-side phishing detection in the renderer if it is
614 // disabled in the Profile preferences or the browser process.
615 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
616 !g_browser_process->safe_browsing_detection_service()) {
617 command_line->AppendSwitch(
618 switches::kDisableClientSidePhishingDetection);
619 }
[email protected]8c40da62011-07-13 22:58:46620 }
[email protected]47c7ec82012-01-18 03:29:21621 {
622 PrefService* local_state = g_browser_process->local_state();
623 if (local_state &&
624 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
625 command_line->AppendSwitch(switches::kRendererPrintPreview);
626 }
627 }
[email protected]4287a3d2011-06-13 23:56:51628
[email protected]47c7ec82012-01-18 03:29:21629 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51630 static const char* const kSwitchNames[] = {
631 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48632 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18633 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51634 switches::kAllowScriptingGallery,
635 switches::kAppsCheckoutURL,
636 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31637 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51638 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51639 switches::kDomAutomationController,
640 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21641 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51642 switches::kEnableClickToPlay,
643 switches::kEnableCrxlessWebApps,
644 switches::kEnableExperimentalExtensionApis,
645 switches::kEnableInBrowserThumbnailing,
646 switches::kEnableIPCFuzzing,
647 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53648 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51649 switches::kEnableSearchProviderApiV2,
650 switches::kEnableWatchdog,
651 switches::kExperimentalSpellcheckerFeatures,
652 switches::kMemoryProfiling,
653 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04654 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51655 switches::kPpapiFlashArgs,
656 switches::kPpapiFlashInProcess,
657 switches::kPpapiFlashPath,
658 switches::kPpapiFlashVersion,
659 switches::kProfilingAtStart,
660 switches::kProfilingFile,
661 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51662 switches::kSilentDumpOnDCHECK,
663 };
664
665 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
666 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17667 } else if (process_type == switches::kUtilityProcess) {
668 if (browser_command_line.HasSwitch(
669 switches::kEnableExperimentalExtensionApis)) {
670 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
671 }
[email protected]4287a3d2011-06-13 23:56:51672 } else if (process_type == switches::kPluginProcess) {
673 static const char* const kSwitchNames[] = {
674 #if defined(OS_CHROMEOS)
675 switches::kLoginProfile,
676 #endif
677 switches::kMemoryProfiling,
678 switches::kSilentDumpOnDCHECK,
679 switches::kUserDataDir,
680 };
681
682 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
683 arraysize(kSwitchNames));
684 } else if (process_type == switches::kZygoteProcess) {
685 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51686 switches::kUserDataDir, // Make logs go to the right file.
687 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
688 switches::kPpapiFlashInProcess,
689 switches::kPpapiFlashPath,
690 switches::kPpapiFlashVersion,
691 };
692
693 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
694 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30695 }
[email protected]6f08af82011-09-15 01:19:03696
697 // The command line switch kEnableBenchmarking needs to be specified along
698 // with the kEnableStatsTable switch to ensure that the stats table global
699 // is initialized correctly.
700 if (command_line->HasSwitch(switches::kEnableBenchmarking))
701 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30702}
703
704std::string ChromeContentBrowserClient::GetApplicationLocale() {
705 return g_browser_process->GetApplicationLocale();
706}
707
[email protected]597a867b2011-11-18 18:31:20708std::string ChromeContentBrowserClient::GetAcceptLangs(
709 content::BrowserContext* context) {
710 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37711 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08712}
713
[email protected]ac55e292011-06-24 05:16:08714SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22715 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08716 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
717}
718
[email protected]a2176792011-05-08 19:30:49719bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09720 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19721 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09722 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
724 ProfileIOData* io_data =
725 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05726 return io_data->GetCookieSettings()->
727 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49728}
729
[email protected]ed24fad2011-05-10 22:44:01730bool ChromeContentBrowserClient::AllowGetCookie(
731 const GURL& url,
732 const GURL& first_party,
733 const net::CookieList& cookie_list,
734 const content::ResourceContext& context,
735 int render_process_id,
736 int render_view_id) {
737 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32738 ProfileIOData* io_data =
739 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05740 bool allow = io_data->GetCookieSettings()->
741 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01742
[email protected]8093a542011-05-13 07:29:32743 BrowserThread::PostTask(
744 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03745 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
746 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01747 return allow;
748}
749
750bool ChromeContentBrowserClient::AllowSetCookie(
751 const GURL& url,
752 const GURL& first_party,
753 const std::string& cookie_line,
754 const content::ResourceContext& context,
755 int render_process_id,
756 int render_view_id,
757 net::CookieOptions* options) {
758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32759 ProfileIOData* io_data =
760 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01761
[email protected]30fde822011-10-28 09:49:05762 CookieSettings* cookie_settings = io_data->GetCookieSettings();
763 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
764
765 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09766 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01767
[email protected]8093a542011-05-13 07:29:32768 BrowserThread::PostTask(
769 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03770 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
771 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01772 return allow;
773}
774
[email protected]d5a19162011-06-30 18:51:54775bool ChromeContentBrowserClient::AllowSaveLocalState(
776 const content::ResourceContext& context) {
777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
778 ProfileIOData* io_data =
779 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
780 return !io_data->clear_local_state_on_exit()->GetValue();
781}
782
[email protected]5c5a88e2011-11-12 00:45:35783bool ChromeContentBrowserClient::AllowWorkerDatabase(
784 int worker_route_id,
785 const GURL& url,
786 const string16& name,
787 const string16& display_name,
788 unsigned long estimated_size,
789 WorkerProcessHost* worker_process_host) {
790 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
791 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
792 worker_process_host->resource_context()->GetUserData(NULL));
793 CookieSettings* cookie_settings = io_data->GetCookieSettings();
794 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
795
796 // Record access to database for potential display in UI: Find the worker
797 // instance and forward the message to all attached documents.
798 WorkerProcessHost::Instances::const_iterator i;
799 for (i = worker_process_host->instances().begin();
800 i != worker_process_host->instances().end(); ++i) {
801 if (i->worker_route_id() != worker_route_id)
802 continue;
803 const WorkerDocumentSet::DocumentInfoSet& documents =
804 i->worker_document_set()->documents();
805 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
806 documents.begin(); doc != documents.end(); ++doc) {
807 BrowserThread::PostTask(
808 BrowserThread::UI, FROM_HERE,
809 base::Bind(
810 &TabSpecificContentSettings::WebDatabaseAccessed,
811 doc->render_process_id(), doc->render_view_id(),
812 url, name, display_name, !allow));
813 }
814 break;
815 }
816
817 return allow;
818}
819
820bool ChromeContentBrowserClient::AllowWorkerFileSystem(
821 int worker_route_id,
822 const GURL& url,
823 WorkerProcessHost* worker_process_host) {
824 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
825 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
826 worker_process_host->resource_context()->GetUserData(NULL));
827 CookieSettings* cookie_settings = io_data->GetCookieSettings();
828 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
829
830 // Record access to file system for potential display in UI: Find the worker
831 // instance and forward the message to all attached documents.
832 WorkerProcessHost::Instances::const_iterator i;
833 for (i = worker_process_host->instances().begin();
834 i != worker_process_host->instances().end(); ++i) {
835 if (i->worker_route_id() != worker_route_id)
836 continue;
837 const WorkerDocumentSet::DocumentInfoSet& documents =
838 i->worker_document_set()->documents();
839 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
840 documents.begin(); doc != documents.end(); ++doc) {
841 BrowserThread::PostTask(
842 BrowserThread::UI, FROM_HERE,
843 base::Bind(
844 &TabSpecificContentSettings::FileSystemAccessed,
845 doc->render_process_id(), doc->render_view_id(), url, !allow));
846 }
847 break;
848 }
849
850 return allow;
851}
852
[email protected]6133f922011-07-01 21:34:34853net::URLRequestContext*
854ChromeContentBrowserClient::OverrideRequestContextForURL(
855 const GURL& url, const content::ResourceContext& context) {
856 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
857 if (url.SchemeIs(chrome::kExtensionScheme)) {
858 ProfileIOData* io_data =
859 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
860 return io_data->extensions_request_context();
861 }
862
863 return NULL;
864}
865
[email protected]317f96c92011-05-31 06:53:41866QuotaPermissionContext*
867ChromeContentBrowserClient::CreateQuotaPermissionContext() {
868 return new ChromeQuotaPermissionContext();
869}
870
[email protected]a0ce3282011-08-19 20:49:52871void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42872 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42873}
874
[email protected]a0ce3282011-08-19 20:49:52875void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52876 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52877}
878
[email protected]848dd042011-06-04 18:24:03879void ChromeContentBrowserClient::AllowCertificateError(
880 SSLCertErrorHandler* handler,
881 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58882 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41883 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13884 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]f9034cf2011-07-21 12:43:41885 handler->render_process_host_id(),
886 handler->tab_contents_id());
887 if (!tab) {
888 NOTREACHED();
889 return;
890 }
891 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50892 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30893 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09894 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41895 if (prerender_manager->prerender_tracker()->TryCancel(
896 handler->render_process_host_id(),
897 handler->tab_contents_id(),
898 prerender::FINAL_STATUS_SSL_ERROR)) {
899 handler->CancelRequest();
900 return;
901 }
902 }
903
904 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03905 SSLBlockingPage* blocking_page = new SSLBlockingPage(
906 handler, overridable, callback);
907 blocking_page->Show();
908}
909
[email protected]c99c442e2011-08-24 11:37:30910void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45911 int render_process_id,
912 int render_view_id,
913 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13914 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45915 render_process_id, render_view_id);
916 if (!tab) {
917 NOTREACHED();
918 return;
919 }
920
[email protected]6786bf402011-12-03 15:19:45921 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
922 GURL requesting_url("https://" + cert_request_info->host_and_port);
923 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
924 << cert_request_info->host_and_port;
925
[email protected]627e0512011-12-21 22:55:30926 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45927 DCHECK(profile);
928 scoped_ptr<Value> filter(
929 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
930 requesting_url,
931 requesting_url,
932 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
933 std::string(), NULL));
934
935 if (filter.get()) {
936 // Try to automatically select a client certificate.
937 if (filter->IsType(Value::TYPE_DICTIONARY)) {
938 DictionaryValue* filter_dict =
939 static_cast<DictionaryValue*>(filter.get());
940
941 const std::vector<scoped_refptr<net::X509Certificate> >&
942 all_client_certs = cert_request_info->client_certs;
943 for (size_t i = 0; i < all_client_certs.size(); ++i) {
944 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
945 // Use the first certificate that is matched by the filter.
946 handler->CertificateSelected(all_client_certs[i]);
947 return;
948 }
949 }
950 } else {
951 NOTREACHED();
952 }
953 }
954
[email protected]8ec26472011-06-06 16:52:45955 TabContentsWrapper* wrapper =
956 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45957 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13958 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45959 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14960 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45961 handler->CertificateSelected(NULL);
962 return;
963 }
964 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45965}
966
967void ChromeContentBrowserClient::AddNewCertificate(
968 net::URLRequest* request,
969 net::X509Certificate* cert,
970 int render_process_id,
971 int render_view_id) {
972 // The handler will run the UI and delete itself when it's finished.
973 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
974}
975
[email protected]941623e2011-06-07 23:06:04976void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
977 const GURL& source_origin,
978 int callback_context,
979 int render_process_id,
980 int render_view_id) {
981 RenderViewHost* rvh = RenderViewHost::FromID(
982 render_process_id, render_view_id);
983 if (!rvh) {
984 NOTREACHED();
985 return;
986 }
987
[email protected]f3b1a082011-11-18 00:34:30988 content::RenderProcessHost* process = rvh->process();
989 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04990 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37991 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04992 service->RequestPermission(
993 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:13994 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:04995}
996
997WebKit::WebNotificationPresenter::Permission
998 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02999 const GURL& source_origin,
1000 const content::ResourceContext& context,
1001 int render_process_id) {
[email protected]941623e2011-06-07 23:06:041002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1003 ProfileIOData* io_data =
1004 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1005
[email protected]34eec7ffe32011-11-02 23:49:021006 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1007 source_origin, render_process_id,
1008 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041009 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041010
1011 // Fall back to the regular notification preferences, which works on an
1012 // origin basis.
1013 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371014 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041015 WebKit::WebNotificationPresenter::PermissionNotAllowed;
1016}
1017
1018void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171019 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041020 int render_process_id,
1021 int render_view_id,
1022 bool worker) {
1023 RenderViewHost* rvh = RenderViewHost::FromID(
1024 render_process_id, render_view_id);
1025 if (!rvh) {
1026 NOTREACHED();
1027 return;
1028 }
1029
[email protected]f3b1a082011-11-18 00:34:301030 content::RenderProcessHost* process = rvh->process();
1031 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041032 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371033 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041034 service->ShowDesktopNotification(
1035 params, render_process_id, render_view_id,
1036 worker ? DesktopNotificationService::WorkerNotification :
1037 DesktopNotificationService::PageNotification);
1038}
1039
1040void ChromeContentBrowserClient::CancelDesktopNotification(
1041 int render_process_id,
1042 int render_view_id,
1043 int notification_id) {
1044 RenderViewHost* rvh = RenderViewHost::FromID(
1045 render_process_id, render_view_id);
1046 if (!rvh) {
1047 NOTREACHED();
1048 return;
1049 }
1050
[email protected]f3b1a082011-11-18 00:34:301051 content::RenderProcessHost* process = rvh->process();
1052 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041053 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371054 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041055 service->CancelDesktopNotification(
1056 render_process_id, render_view_id, notification_id);
1057}
1058
[email protected]9f3fba52011-06-08 20:37:191059bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021060 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191061 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021062 const content::ResourceContext& context,
1063 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191064 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1065 // If the opener is trying to create a background window but doesn't have
1066 // the appropriate permission, fail the attempt.
1067 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1068 ProfileIOData* io_data =
1069 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021070 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1071 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191072 }
1073 return true;
1074}
1075
1076std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1077 const GURL& url, const content::ResourceContext& context) {
1078 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1079 // Check if it's an extension-created worker, in which case we want to use
1080 // the name of the extension.
1081 ProfileIOData* io_data =
1082 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1083 const Extension* extension =
1084 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1085 return extension ? extension->name() : std::string();
1086}
1087
[email protected]99907362012-01-11 05:41:401088void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1089 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171090}
1091
1092ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1093 return g_browser_process->clipboard();
1094}
1095
[email protected]8f6a3b852011-07-19 16:48:561096MHTMLGenerationManager*
1097 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1098 return g_browser_process->mhtml_generation_manager();
1099}
1100
[email protected]ae6e9912011-07-27 01:18:281101net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1102 return g_browser_process->net_log();
1103}
1104
[email protected]3bc0b562011-08-24 23:51:041105speech_input::SpeechInputManager*
1106 ChromeContentBrowserClient::GetSpeechInputManager() {
1107 return speech_input::ChromeSpeechInputManager::GetInstance();
1108}
1109
[email protected]32538d92011-08-25 00:09:231110AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1111 return new ChromeAccessTokenStore();
1112}
1113
[email protected]dbae6b02011-06-29 23:51:411114bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1115 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1116 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1117}
1118
[email protected]5092c282011-10-29 21:48:371119WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061120 Profile* profile = Profile::FromBrowserContext(
1121 rvh->process()->GetBrowserContext());
1122 PrefService* prefs = profile->GetPrefs();
1123 WebPreferences web_prefs;
1124
1125 web_prefs.standard_font_family =
1126 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
1127 web_prefs.fixed_font_family =
1128 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
1129 web_prefs.serif_font_family =
1130 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
1131 web_prefs.sans_serif_font_family =
1132 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
1133 web_prefs.cursive_font_family =
1134 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
1135 web_prefs.fantasy_font_family =
1136 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1137
1138 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
1139 &web_prefs.standard_font_family_map);
1140 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
1141 &web_prefs.fixed_font_family_map);
1142 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
1143 &web_prefs.serif_font_family_map);
1144 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
1145 &web_prefs.sans_serif_font_family_map);
1146 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
1147 &web_prefs.cursive_font_family_map);
1148 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
1149 &web_prefs.fantasy_font_family_map);
1150
1151 web_prefs.default_font_size =
1152 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
1153 web_prefs.default_fixed_font_size =
1154 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
1155 web_prefs.minimum_font_size =
1156 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
1157 web_prefs.minimum_logical_font_size =
1158 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1159
1160 web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
1161
1162 web_prefs.javascript_can_open_windows_automatically =
1163 prefs->GetBoolean(
1164 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
1165 web_prefs.dom_paste_enabled =
1166 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
1167 web_prefs.shrinks_standalone_images_to_fit =
1168 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1169 const DictionaryValue* inspector_settings =
1170 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1171 if (inspector_settings) {
1172 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1173 iter != inspector_settings->end_keys(); ++iter) {
1174 std::string value;
1175 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
1176 web_prefs.inspector_settings.push_back(
1177 std::make_pair(*iter, value));
1178 }
1179 }
1180 web_prefs.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
1181
1182 { // Command line switches are used for preferences with no user interface.
1183 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1184 web_prefs.developer_extras_enabled = true;
1185 web_prefs.javascript_enabled =
1186 !command_line.HasSwitch(switches::kDisableJavaScript) &&
1187 prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled);
[email protected]f3986f82012-01-03 20:00:061188 web_prefs.web_security_enabled =
1189 !command_line.HasSwitch(switches::kDisableWebSecurity) &&
1190 prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled);
1191 web_prefs.plugins_enabled =
1192 !command_line.HasSwitch(switches::kDisablePlugins) &&
1193 prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled);
1194 web_prefs.java_enabled =
1195 !command_line.HasSwitch(switches::kDisableJava) &&
1196 prefs->GetBoolean(prefs::kWebKitJavaEnabled);
1197 web_prefs.loads_images_automatically =
1198 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
1199 web_prefs.uses_page_cache =
1200 command_line.HasSwitch(switches::kEnableFastback);
1201 web_prefs.remote_fonts_enabled =
1202 !command_line.HasSwitch(switches::kDisableRemoteFonts);
1203 web_prefs.xss_auditor_enabled =
1204 !command_line.HasSwitch(switches::kDisableXSSAuditor);
1205 web_prefs.application_cache_enabled =
1206 !command_line.HasSwitch(switches::kDisableApplicationCache);
1207
1208 web_prefs.local_storage_enabled =
1209 !command_line.HasSwitch(switches::kDisableLocalStorage);
1210 web_prefs.databases_enabled =
1211 !command_line.HasSwitch(switches::kDisableDatabases);
1212 web_prefs.webaudio_enabled =
1213 !command_line.HasSwitch(switches::kDisableWebAudio);
1214 web_prefs.experimental_webgl_enabled =
1215 GpuProcessHost::gpu_enabled() &&
1216 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
1217 !prefs->GetBoolean(prefs::kDisable3DAPIs) &&
1218 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
1219 web_prefs.gl_multisampling_enabled =
1220 !command_line.HasSwitch(switches::kDisableGLMultisampling);
1221 web_prefs.privileged_webgl_extensions_enabled =
1222 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
1223 web_prefs.site_specific_quirks_enabled =
1224 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
1225 web_prefs.allow_file_access_from_file_urls =
1226 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
1227 web_prefs.show_composited_layer_borders =
1228 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
1229 web_prefs.show_composited_layer_tree =
1230 command_line.HasSwitch(switches::kShowCompositedLayerTree);
1231 web_prefs.show_fps_counter =
1232 command_line.HasSwitch(switches::kShowFPSCounter);
1233 web_prefs.accelerated_compositing_enabled =
1234 GpuProcessHost::gpu_enabled() &&
1235 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
1236 web_prefs.threaded_compositing_enabled =
1237 command_line.HasSwitch(switches::kEnableThreadedCompositing);
1238 web_prefs.force_compositing_mode =
1239 command_line.HasSwitch(switches::kForceCompositingMode);
1240 web_prefs.fixed_position_compositing_enabled =
1241 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
1242 web_prefs.allow_webui_compositing =
1243 command_line.HasSwitch(switches::kAllowWebUICompositing);
1244 web_prefs.accelerated_2d_canvas_enabled =
1245 GpuProcessHost::gpu_enabled() &&
1246 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
1247 web_prefs.accelerated_painting_enabled =
1248 GpuProcessHost::gpu_enabled() &&
1249 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
1250 web_prefs.accelerated_filters_enabled =
1251 GpuProcessHost::gpu_enabled() &&
1252 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
1253 web_prefs.accelerated_layers_enabled =
1254 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
1255 web_prefs.composite_to_texture_enabled =
1256 command_line.HasSwitch(switches::kEnableCompositeToTexture);
1257 web_prefs.accelerated_plugins_enabled =
1258 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
1259 web_prefs.accelerated_video_enabled =
1260 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
1261 web_prefs.partial_swap_enabled =
1262 command_line.HasSwitch(switches::kEnablePartialSwap);
1263 web_prefs.memory_info_enabled =
1264 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1265 web_prefs.interactive_form_validation_enabled =
1266 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
1267 web_prefs.fullscreen_enabled =
1268 !command_line.HasSwitch(switches::kDisableFullScreen);
1269 web_prefs.allow_displaying_insecure_content =
1270 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1271 web_prefs.allow_running_insecure_content =
1272 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
1273
1274#if defined(OS_MACOSX)
1275 bool default_enable_scroll_animator = true;
1276#else
1277 // On CrOS, the launcher always passes in the --enable flag.
1278 bool default_enable_scroll_animator = false;
1279#endif
1280 web_prefs.enable_scroll_animator = default_enable_scroll_animator;
1281 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
1282 web_prefs.enable_scroll_animator = true;
1283 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
1284 web_prefs.enable_scroll_animator = false;
1285
1286 // The user stylesheet watcher may not exist in a testing profile.
1287 if (profile->GetUserStyleSheetWatcher()) {
1288 web_prefs.user_style_sheet_enabled = true;
1289 web_prefs.user_style_sheet_location =
1290 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1291 } else {
1292 web_prefs.user_style_sheet_enabled = false;
1293 }
1294
1295 web_prefs.visual_word_movement_enabled =
1296 command_line.HasSwitch(switches::kEnableVisualWordMovement);
1297 web_prefs.unified_textchecker_enabled =
1298 command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures);
1299 web_prefs.per_tile_painting_enabled =
1300 command_line.HasSwitch(switches::kEnablePerTilePainting);
1301 }
1302
1303 { // Certain GPU features might have been blacklisted.
1304 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
1305 DCHECK(gpu_data_manager);
1306 uint32 blacklist_flags = gpu_data_manager->GetGpuFeatureFlags().flags();
1307 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)
1308 web_prefs.accelerated_compositing_enabled = false;
1309 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureWebgl)
1310 web_prefs.experimental_webgl_enabled = false;
1311 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)
1312 web_prefs.accelerated_2d_canvas_enabled = false;
1313 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureMultisampling)
1314 web_prefs.gl_multisampling_enabled = false;
[email protected]dd5d0fb2012-01-18 03:37:571315
1316 // Accelerated video is slower than regular when using a software 3d
1317 // rasterizer.
1318 if (gpu_data_manager->software_rendering())
1319 web_prefs.accelerated_video_enabled = false;
[email protected]f3986f82012-01-03 20:00:061320 }
1321
1322 web_prefs.uses_universal_detector =
1323 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
1324 web_prefs.text_areas_are_resizable =
1325 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
1326 web_prefs.hyperlink_auditing_enabled =
1327 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1328
1329 // Make sure we will set the default_encoding with canonical encoding name.
1330 web_prefs.default_encoding =
1331 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
1332 web_prefs.default_encoding);
1333 if (web_prefs.default_encoding.empty()) {
1334 prefs->ClearPref(prefs::kGlobalDefaultCharset);
1335 web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
1336 }
1337 DCHECK(!web_prefs.default_encoding.empty());
1338
1339 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
1340 rvh->process()->GetID())) {
1341 web_prefs.loads_images_automatically = true;
1342 web_prefs.javascript_enabled = true;
1343 }
1344
1345 web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
1346
1347 ExtensionService* service = profile->GetExtensionService();
1348 if (service) {
1349 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331350 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061351 extension_webkit_preferences::SetPreferences(
1352 extension, rvh->delegate()->GetRenderViewType(), &web_prefs);
1353 }
1354
1355 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
1356 web_prefs.allow_scripts_to_close_windows = true;
1357 } else if (rvh->delegate()->GetRenderViewType() ==
1358 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1359 // Disable all kinds of acceleration for background pages.
1360 // See http://crbug.com/96005 and http://crbug.com/96006
1361 web_prefs.force_compositing_mode = false;
1362 web_prefs.accelerated_compositing_enabled = false;
1363 web_prefs.accelerated_2d_canvas_enabled = false;
1364 web_prefs.accelerated_video_enabled = false;
1365 web_prefs.accelerated_painting_enabled = false;
1366 web_prefs.accelerated_plugins_enabled = false;
1367 }
1368
1369 return web_prefs;
[email protected]181a95ee2011-07-12 19:26:361370}
1371
1372void ChromeContentBrowserClient::UpdateInspectorSetting(
1373 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061374 content::BrowserContext* browser_context =
1375 rvh->process()->GetBrowserContext();
1376 DictionaryPrefUpdate update(
1377 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1378 prefs::kWebKitInspectorSettings);
1379 DictionaryValue* inspector_settings = update.Get();
1380 inspector_settings->SetWithoutPathExpansion(key,
1381 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361382}
1383
1384void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061385 content::BrowserContext* browser_context =
1386 rvh->process()->GetBrowserContext();
1387 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1388 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361389}
1390
[email protected]b8148ac2011-07-13 22:03:251391void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1392 BrowserURLHandler* handler) {
1393 // Add the default URL handlers.
1394 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1395 BrowserURLHandler::null_handler());
1396 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1397 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1398
[email protected]b3adbd02011-11-30 22:23:271399 // about: handler. Must come before chrome: handler, since it will
1400 // rewrite about: urls to chrome: URLs and then expect chrome: to
1401 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251402 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1403 BrowserURLHandler::null_handler());
1404 // chrome: & friends.
1405 handler->AddHandlerPair(&HandleWebUI,
1406 BrowserURLHandler::null_handler());
1407}
1408
1409void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371410 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301411 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251412 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1413 BrowsingDataRemover::EVERYTHING,
1414 base::Time());
1415 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1416 // BrowsingDataRemover takes care of deleting itself when done.
1417}
1418
1419void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371420 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301421 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251422 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1423 BrowsingDataRemover::EVERYTHING,
1424 base::Time());
[email protected]dceaa912011-09-06 17:17:231425 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251426 remover->Remove(remove_mask);
1427 // BrowsingDataRemover takes care of deleting itself when done.
1428}
1429
[email protected]e1d16eb92011-08-18 23:19:321430FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1431 return download_util::GetDefaultDownloadDirectory();
1432}
1433
[email protected]c9b6eb62011-10-18 20:49:391434std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1435 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1436}
1437
[email protected]e60c0232011-11-11 19:56:351438#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301439int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521440 const CommandLine& command_line) {
1441 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071442 ExtensionCrashHandlerHostLinux* crash_handler =
1443 ExtensionCrashHandlerHostLinux::GetInstance();
1444 return crash_handler->GetDeathSignalSocket();
1445 }
1446
[email protected]718eab62011-10-05 21:16:521447 std::string process_type =
1448 command_line.GetSwitchValueASCII(switches::kProcessType);
1449
1450 if (process_type == switches::kRendererProcess)
1451 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1452
[email protected]b80f68432011-05-02 17:22:301453 if (process_type == switches::kPluginProcess)
1454 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1455
1456 if (process_type == switches::kPpapiPluginProcess)
1457 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1458
1459 if (process_type == switches::kGpuProcess)
1460 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1461
1462 return -1;
1463}
[email protected]e60c0232011-11-11 19:56:351464#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301465
[email protected]4a65826d2011-08-25 16:04:011466#if defined(OS_WIN)
1467const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1468 return chrome::kBrowserResourcesDll;
1469}
1470#endif
1471
[email protected]37a72af2011-06-13 05:42:011472#if defined(USE_NSS)
1473crypto::CryptoModuleBlockingPasswordDelegate*
1474 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1475 const GURL& url) {
1476 return browser::NewCryptoModuleBlockingDialogDelegate(
1477 browser::kCryptoModulePasswordKeygen, url.host());
1478}
1479#endif
1480
[email protected]d977f9c2011-03-14 16:10:261481} // namespace chrome