blob: 0c3219589e0d2f6487457e4036ba7c995464f1f7 [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]863f70a2012-01-27 02:05:5056#include "chrome/browser/ui/webui/chrome_web_ui_controller_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"
[email protected]d977f9c2011-03-14 16:10:2669#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4970#include "content/browser/resource_context.h"
[email protected]f9034cf2011-07-21 12:43:4171#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4572#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]b48c9182011-10-26 18:03:3073#include "content/public/browser/browser_main_parts.h"
[email protected]f3b1a082011-11-18 00:34:3074#include "content/public/browser/render_process_host.h"
[email protected]b6583592012-01-25 19:52:3375#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1976#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1077#include "content/public/browser/web_contents_view.h"
[email protected]c9b6eb62011-10-18 20:49:3978#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3479#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0180#include "net/base/cookie_monster.h"
81#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3982#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0883#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3684#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2685
[email protected]b48c9182011-10-26 18:03:3086#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3887#include "chrome/browser/chrome_browser_main_win.h"
88#elif defined(OS_MACOSX)
89#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5690#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3091#elif defined(OS_CHROMEOS)
92#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3593#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3094#include "chrome/browser/chrome_browser_main_linux.h"
95#elif defined(OS_POSIX)
96#include "chrome/browser/chrome_browser_main_posix.h"
97#endif
98
[email protected]b48c9182011-10-26 18:03:3099#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31100#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38101#endif
102
[email protected]c7480942011-11-08 19:18:27103#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31104#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27105#endif
106
107#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31108#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
109#endif
110
[email protected]e60c0232011-11-11 19:56:35111#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30112#include "base/linux_util.h"
113#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43114#endif
[email protected]b80f68432011-05-02 17:22:30115
[email protected]080f34f2011-09-20 05:39:26116#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32117#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21118#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45119#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]90580422012-01-12 00:26:22120#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32121#elif defined(OS_MACOSX)
[email protected]cce3ab72012-02-04 18:05:16122#include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h"
[email protected]8dad546b2012-01-17 21:47:35123#include "chrome/browser/tab_contents/moving_to_content/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32124#endif
125
[email protected]37a72af2011-06-13 05:42:01126#if defined(USE_NSS)
127#include "chrome/browser/ui/crypto_module_password_dialog.h"
128#endif
129
[email protected]c8c77182011-12-21 15:04:47130using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39131using content::BrowserThread;
[email protected]b6583592012-01-25 19:52:33132using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13133using content::WebContents;
[email protected]631bb742011-11-02 11:29:39134
[email protected]c5dbef02011-05-13 05:06:09135namespace {
136
[email protected]b8148ac2011-07-13 22:03:25137// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42138bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50139 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
140 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25141 return false;
142
143 // Special case the new tab page. In older versions of Chrome, the new tab
144 // page was hosted at chrome-internal:<blah>. This might be in people's saved
145 // sessions or bookmarks, so we say any URL with that scheme triggers the new
146 // tab page.
147 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
148 // Rewrite it with the proper new tab URL.
149 *url = GURL(chrome::kChromeUINewTabURL);
150 }
151
152 return true;
153}
154
[email protected]8d3132f62011-10-12 07:13:42155// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
156// below. Extension, and isolated apps require different privileges to be
157// granted to their RenderProcessHosts. This classification allows us to make
158// sure URLs are served by hosts with the right set of privileges.
159enum RenderProcessHostPrivilege {
160 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45161 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42162 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45163 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42164};
165
166RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
167 const GURL& url,
168 ExtensionService* service) {
169 // Default to a normal renderer cause it is lower privileged. This should only
170 // occur if the URL on a site instance is either malformed, or uninitialized.
171 // If it is malformed, then there is no need for better privileges anyways.
172 // If it is uninitialized, but eventually settles on being an a scheme other
173 // than normal webrenderer, the navigation logic will correct us out of band
174 // anyways.
175 if (!url.is_valid())
176 return PRIV_NORMAL;
177
178 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44179 const Extension* extension =
180 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45181 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42182 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45183 if (extension && extension->is_hosted_app())
184 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42185
186 return PRIV_EXTENSION;
187 }
188
189 return PRIV_NORMAL;
190}
191
192RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30193 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46194 extensions::ProcessMap* process_map,
195 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46196 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30197 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46198 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21199 return PRIV_NORMAL;
200
[email protected]6f371442011-11-09 06:45:46201 for (std::set<std::string>::iterator iter = extension_ids.begin();
202 iter != extension_ids.end(); ++iter) {
203 const Extension* extension = service->GetExtensionById(*iter, false);
204 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42205 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45206 if (extension && extension->is_hosted_app())
207 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42208 }
209
[email protected]676f6ab2011-10-19 20:23:21210 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42211}
212
[email protected]eec0b33c2011-12-05 22:09:45213bool IsIsolatedAppInProcess(const GURL& site_url,
214 content::RenderProcessHost* process_host,
215 extensions::ProcessMap* process_map,
216 ExtensionService* service) {
217 std::set<std::string> extension_ids =
218 process_map->GetExtensionsInProcess(process_host->GetID());
219 if (extension_ids.empty())
220 return false;
221
222 for (std::set<std::string>::iterator iter = extension_ids.begin();
223 iter != extension_ids.end(); ++iter) {
224 const Extension* extension = service->GetExtensionById(*iter, false);
225 if (extension &&
226 extension->is_storage_isolated() &&
227 extension->url() == site_url)
228 return true;
229 }
230
231 return false;
232}
233
[email protected]6786bf402011-12-03 15:19:45234bool CertMatchesFilter(const net::X509Certificate& cert,
235 const base::DictionaryValue& filter) {
236 // TODO(markusheintz): This is the minimal required filter implementation.
237 // Implement a better matcher.
238
239 // An empty filter matches any client certificate since no requirements are
240 // specified at all.
241 if (filter.empty())
242 return true;
243
244 std::string common_name;
245 if (filter.GetString("ISSUER.CN", &common_name) &&
246 (cert.issuer().common_name == common_name)) {
247 return true;
248 }
249 return false;
250}
251
[email protected]f3986f82012-01-03 20:00:06252// Fills |map| with the per-script font prefs under path |map_name|.
253void FillFontFamilyMap(const PrefService* prefs,
254 const char* map_name,
255 WebPreferences::ScriptFontFamilyMap* map) {
256 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
257 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
258 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
259 std::string font_family = prefs->GetString(pref_name.c_str());
260 if (!font_family.empty())
261 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
262 }
263}
264
[email protected]9dbfff12011-07-01 19:37:07265} // namespace
[email protected]c5dbef02011-05-13 05:06:09266
[email protected]d977f9c2011-03-14 16:10:26267namespace chrome {
268
[email protected]50462bf02011-11-21 19:13:31269content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
270 const content::MainFunctionParams& parameters) {
271 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30272 // Construct the Main browser parts based on the OS type.
273#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31274 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04275#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31276 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30277#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31278 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35279#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31280 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30281#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31282 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04283#else
[email protected]b48c9182011-10-26 18:03:30284 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31285 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30286#endif
287
[email protected]c7480942011-11-08 19:18:27288 // Construct additional browser parts. Stages are called in the order in
289 // which they are added.
[email protected]b48c9182011-10-26 18:03:30290#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31291 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04292#endif
[email protected]c7480942011-11-08 19:18:27293
294#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31295 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27296#endif
297
298#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31299 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27300#endif
301
[email protected]50462bf02011-11-21 19:13:31302 return main_parts;
[email protected]f967b722011-09-07 00:58:04303}
304
[email protected]8643e6d2012-01-18 20:26:10305content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35306 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26307#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35308 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21309#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35310 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22311 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32312#elif defined(OS_MACOSX)
[email protected]cce3ab72012-02-04 18:05:16313 return tab_contents_view_mac::CreateWebContentsView(
314 web_contents,
315 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
316 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]863f70a2012-01-27 02:05:50361content::WebUIControllerFactory*
362 ChromeContentBrowserClient::GetWebUIControllerFactory() {
363 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56364}
365
[email protected]3d7474ff2011-07-27 17:47:37366GURL ChromeContentBrowserClient::GetEffectiveURL(
367 content::BrowserContext* browser_context, const GURL& url) {
368 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08369 // Get the effective URL for the given actual URL. If the URL is part of an
370 // installed app, the effective URL is an extension URL with the ID of that
371 // extension as the host. This has the effect of grouping apps together in
372 // a common SiteInstance.
373 if (!profile || !profile->GetExtensionService())
374 return url;
375
[email protected]615d88f2011-12-13 01:47:44376 const Extension* extension = profile->GetExtensionService()->extensions()->
377 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08378 if (!extension)
379 return url;
380
[email protected]15877ca2011-11-18 22:40:52381 // Bookmark apps do not use the hosted app process model, and should be
382 // treated as normal URLs.
383 if (extension->from_bookmark())
384 return url;
385
[email protected]36fb2c7c2011-04-04 15:49:08386 // If the URL is part of an extension's web extent, convert it to an
387 // extension URL.
388 return extension->GetResourceURL(url.path());
389}
390
[email protected]056ad2a2011-07-12 02:13:55391bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37392 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55393 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52394 // Because we expect to use the effective URL, URLs for hosted apps (apart
395 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55396 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
397 return false;
398
[email protected]3d7474ff2011-07-27 17:47:37399 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55400 if (!profile || !profile->GetExtensionService())
401 return false;
402
[email protected]615d88f2011-12-13 01:47:44403 const Extension* extension = profile->GetExtensionService()->extensions()->
404 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55405 if (!extension)
406 return false;
407
408 // If the URL is part of a hosted app that does not have the background
409 // permission, we want to give each instance its own process to improve
410 // responsiveness.
411 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
412 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
413 return false;
414
415 // Hosted apps that have the background permission must use process per site,
416 // since all instances can make synchronous calls to the background window.
417 // Other extensions should use process per site as well.
418 return true;
419}
420
[email protected]0f012df82011-05-19 14:15:29421bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03422 return url == GURL(chrome::kChromeUICrashURL) ||
423 url == GURL(chrome::kChromeUIKillURL) ||
424 url == GURL(chrome::kChromeUIHangURL) ||
425 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29426}
427
[email protected]46fb9442011-12-09 17:57:47428bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
429 return ProfileIOData::IsHandledURL(url);
430}
431
[email protected]2a5221b2011-09-27 23:07:31432bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30433 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31434 const GURL& site_url) {
435 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30436 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42437 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46438 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31439
[email protected]ffa97602011-11-17 17:55:52440 // Don't allow the Task Manager to share a process with anything else.
441 // Otherwise it can affect the renderers it is observing.
442 // Note: we could create another RenderProcessHostPrivilege bucket for
443 // this to allow multiple chrome://tasks instances to share, but that's
444 // a very unlikely case without serious consequences.
445 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
446 return false;
447
[email protected]8d3132f62011-10-12 07:13:42448 // These may be NULL during tests. In that case, just assume any site can
449 // share any host.
[email protected]6f371442011-11-09 06:45:46450 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31451 return true;
452
[email protected]a8c269a2011-10-25 20:17:22453 // Experimental:
454 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
455 // to share a renderer process. (We could allow pages from the same site or
456 // extensions of the same type to share, if we knew what the given process
457 // was dedicated to. Allowing no sharing is simpler for now.) This may
458 // cause resource exhaustion issues if too many sites are open at once.
459 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
460 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
461 return false;
462
[email protected]eec0b33c2011-12-05 22:09:45463 // An isolated app is only allowed to share with the exact same app in order
464 // to provide complete renderer process isolation. This also works around
465 // issue http://crbug.com/85588, where different isolated apps in the same
466 // process would end up using the first app's storage contexts.
467 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42468 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45469 if (privilege_required == PRIV_ISOLATED)
470 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
471
472 // Otherwise, just make sure the process privilege matches the privilege
473 // required by the site.
474 return GetProcessPrivilege(process_host, process_map, service) ==
475 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31476}
477
[email protected]6f371442011-11-09 06:45:46478void ChromeContentBrowserClient::SiteInstanceGotProcess(
479 SiteInstance* site_instance) {
480 CHECK(site_instance->HasProcess());
481
482 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02483 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46484 ExtensionService* service = profile->GetExtensionService();
485 if (!service)
486 return;
487
488 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44489 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33490 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46491 if (!extension)
492 return;
493
[email protected]6bc04fd82011-12-04 02:29:35494 service->process_map()->Insert(extension->id(),
495 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33496 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46497 BrowserThread::PostTask(
498 BrowserThread::IO, FROM_HERE,
499 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
500 profile->GetExtensionInfoMap(),
501 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35502 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33503 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46504}
505
506void ChromeContentBrowserClient::SiteInstanceDeleting(
507 SiteInstance* site_instance) {
508 if (!site_instance->HasProcess())
509 return;
510
511 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02512 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46513 ExtensionService* service = profile->GetExtensionService();
514 if (!service)
515 return;
516
517 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44518 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33519 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46520 if (!extension)
521 return;
522
[email protected]6bc04fd82011-12-04 02:29:35523 service->process_map()->Remove(extension->id(),
524 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33525 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46526 BrowserThread::PostTask(
527 BrowserThread::IO, FROM_HERE,
528 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
529 profile->GetExtensionInfoMap(),
530 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35531 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33532 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46533}
534
[email protected]e3daf3c2011-10-05 21:17:08535bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
536 const GURL& current_url,
537 const GURL& new_url) {
538 if (current_url.is_empty()) {
539 // Always choose a new process when navigating to extension URLs. The
540 // process grouping logic will combine all of a given extension's pages
541 // into the same process.
542 if (new_url.SchemeIs(chrome::kExtensionScheme))
543 return true;
544
545 return false;
546 }
547
548 // Also, we must switch if one is an extension and the other is not the exact
549 // same extension.
550 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
551 new_url.SchemeIs(chrome::kExtensionScheme)) {
552 if (current_url.GetOrigin() != new_url.GetOrigin())
553 return true;
554 }
555
556 return false;
557}
558
[email protected]763ec4ca2011-04-29 15:48:12559std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
560 const std::string& alias_name) {
561 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
562}
563
[email protected]b80f68432011-05-02 17:22:30564void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
565 CommandLine* command_line, int child_process_id) {
566#if defined(USE_LINUX_BREAKPAD)
567 if (IsCrashReporterEnabled()) {
568 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
569 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
570 }
571#elif defined(OS_MACOSX)
572 if (IsCrashReporterEnabled()) {
573 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
574 child_process_logging::GetClientId());
575 }
576#endif // OS_MACOSX
577
[email protected]f1933792011-06-14 00:49:34578 if (logging::DialogsAreSuppressed())
579 command_line->AppendSwitch(switches::kNoErrorDialogs);
580
[email protected]b80f68432011-05-02 17:22:30581 std::string process_type =
582 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17583 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52584 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30585 FilePath user_data_dir =
586 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
587 if (!user_data_dir.empty())
588 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
589#if defined(OS_CHROMEOS)
590 const std::string& login_profile =
591 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
592 if (!login_profile.empty())
593 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
594#endif
595
[email protected]f3b1a082011-11-18 00:34:30596 content::RenderProcessHost* process =
597 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37598 if (process) {
599 Profile* profile = Profile::FromBrowserContext(
600 process->GetBrowserContext());
601 extensions::ProcessMap* process_map =
602 profile->GetExtensionService()->process_map();
603 if (process_map && process_map->Contains(process->GetID()))
604 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30605
[email protected]a8d851f82011-12-21 00:32:37606 PrefService* prefs = profile->GetPrefs();
607 // Currently this pref is only registered if applied via a policy.
608 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
609 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
610 // Turn this policy into a command line switch.
611 command_line->AppendSwitch(switches::kDisable3DAPIs);
612 }
[email protected]718eab62011-10-05 21:16:52613
[email protected]a8d851f82011-12-21 00:32:37614 // Disable client-side phishing detection in the renderer if it is
615 // disabled in the Profile preferences or the browser process.
616 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
617 !g_browser_process->safe_browsing_detection_service()) {
618 command_line->AppendSwitch(
619 switches::kDisableClientSidePhishingDetection);
620 }
[email protected]8c40da62011-07-13 22:58:46621 }
[email protected]47c7ec82012-01-18 03:29:21622 {
623 PrefService* local_state = g_browser_process->local_state();
624 if (local_state &&
625 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
626 command_line->AppendSwitch(switches::kRendererPrintPreview);
627 }
628 }
[email protected]4287a3d2011-06-13 23:56:51629
[email protected]47c7ec82012-01-18 03:29:21630 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51631 static const char* const kSwitchNames[] = {
632 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48633 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18634 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51635 switches::kAllowScriptingGallery,
636 switches::kAppsCheckoutURL,
637 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31638 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51639 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51640 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21641 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51642 switches::kEnableCrxlessWebApps,
643 switches::kEnableExperimentalExtensionApis,
644 switches::kEnableInBrowserThumbnailing,
645 switches::kEnableIPCFuzzing,
646 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53647 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51648 switches::kEnableSearchProviderApiV2,
649 switches::kEnableWatchdog,
650 switches::kExperimentalSpellcheckerFeatures,
651 switches::kMemoryProfiling,
652 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04653 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51654 switches::kPpapiFlashArgs,
655 switches::kPpapiFlashInProcess,
656 switches::kPpapiFlashPath,
657 switches::kPpapiFlashVersion,
658 switches::kProfilingAtStart,
659 switches::kProfilingFile,
660 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51661 switches::kSilentDumpOnDCHECK,
662 };
663
664 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
665 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17666 } else if (process_type == switches::kUtilityProcess) {
667 if (browser_command_line.HasSwitch(
668 switches::kEnableExperimentalExtensionApis)) {
669 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
670 }
[email protected]4287a3d2011-06-13 23:56:51671 } else if (process_type == switches::kPluginProcess) {
672 static const char* const kSwitchNames[] = {
673 #if defined(OS_CHROMEOS)
674 switches::kLoginProfile,
675 #endif
676 switches::kMemoryProfiling,
677 switches::kSilentDumpOnDCHECK,
678 switches::kUserDataDir,
679 };
680
681 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
682 arraysize(kSwitchNames));
683 } else if (process_type == switches::kZygoteProcess) {
684 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51685 switches::kUserDataDir, // Make logs go to the right file.
686 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
687 switches::kPpapiFlashInProcess,
688 switches::kPpapiFlashPath,
689 switches::kPpapiFlashVersion,
690 };
691
692 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
693 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30694 }
[email protected]6f08af82011-09-15 01:19:03695
696 // The command line switch kEnableBenchmarking needs to be specified along
697 // with the kEnableStatsTable switch to ensure that the stats table global
698 // is initialized correctly.
699 if (command_line->HasSwitch(switches::kEnableBenchmarking))
700 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30701}
702
703std::string ChromeContentBrowserClient::GetApplicationLocale() {
704 return g_browser_process->GetApplicationLocale();
705}
706
[email protected]597a867b2011-11-18 18:31:20707std::string ChromeContentBrowserClient::GetAcceptLangs(
708 content::BrowserContext* context) {
709 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37710 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08711}
712
[email protected]ac55e292011-06-24 05:16:08713SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22714 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08715 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
716}
717
[email protected]a2176792011-05-08 19:30:49718bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09719 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19720 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09721 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32722 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
723 ProfileIOData* io_data =
724 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05725 return io_data->GetCookieSettings()->
726 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49727}
728
[email protected]ed24fad2011-05-10 22:44:01729bool ChromeContentBrowserClient::AllowGetCookie(
730 const GURL& url,
731 const GURL& first_party,
732 const net::CookieList& cookie_list,
733 const content::ResourceContext& context,
734 int render_process_id,
735 int render_view_id) {
736 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32737 ProfileIOData* io_data =
738 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05739 bool allow = io_data->GetCookieSettings()->
740 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01741
[email protected]8093a542011-05-13 07:29:32742 BrowserThread::PostTask(
743 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03744 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
745 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01746 return allow;
747}
748
749bool ChromeContentBrowserClient::AllowSetCookie(
750 const GURL& url,
751 const GURL& first_party,
752 const std::string& cookie_line,
753 const content::ResourceContext& context,
754 int render_process_id,
755 int render_view_id,
756 net::CookieOptions* options) {
757 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32758 ProfileIOData* io_data =
759 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01760
[email protected]30fde822011-10-28 09:49:05761 CookieSettings* cookie_settings = io_data->GetCookieSettings();
762 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
763
764 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09765 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01766
[email protected]8093a542011-05-13 07:29:32767 BrowserThread::PostTask(
768 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03769 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
770 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01771 return allow;
772}
773
[email protected]d5a19162011-06-30 18:51:54774bool ChromeContentBrowserClient::AllowSaveLocalState(
775 const content::ResourceContext& context) {
776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
777 ProfileIOData* io_data =
778 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
779 return !io_data->clear_local_state_on_exit()->GetValue();
780}
781
[email protected]5c5a88e2011-11-12 00:45:35782bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35783 const GURL& url,
784 const string16& name,
785 const string16& display_name,
786 unsigned long estimated_size,
[email protected]62151052012-02-01 18:40:48787 const content::ResourceContext& context,
788 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
790 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
[email protected]62151052012-02-01 18:40:48791 context.GetUserData(NULL));
[email protected]5c5a88e2011-11-12 00:45:35792 CookieSettings* cookie_settings = io_data->GetCookieSettings();
793 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
794
[email protected]62151052012-02-01 18:40:48795 // Record access to database for potential display in UI.
796 std::vector<std::pair<int, int> >::const_iterator i;
797 for (i = render_views.begin(); i != render_views.end(); ++i) {
798 BrowserThread::PostTask(
799 BrowserThread::UI, FROM_HERE,
800 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
801 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35802 }
803
804 return allow;
805}
806
807bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35808 const GURL& url,
[email protected]62151052012-02-01 18:40:48809 const content::ResourceContext& context,
810 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
812 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
[email protected]62151052012-02-01 18:40:48813 context.GetUserData(NULL));
[email protected]5c5a88e2011-11-12 00:45:35814 CookieSettings* cookie_settings = io_data->GetCookieSettings();
815 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
816
[email protected]62151052012-02-01 18:40:48817 // Record access to file system for potential display in UI.
818 std::vector<std::pair<int, int> >::const_iterator i;
819 for (i = render_views.begin(); i != render_views.end(); ++i) {
820 BrowserThread::PostTask(
821 BrowserThread::UI, FROM_HERE,
822 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
823 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35824 }
825
826 return allow;
827}
828
[email protected]6133f922011-07-01 21:34:34829net::URLRequestContext*
830ChromeContentBrowserClient::OverrideRequestContextForURL(
831 const GURL& url, const content::ResourceContext& context) {
832 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
833 if (url.SchemeIs(chrome::kExtensionScheme)) {
834 ProfileIOData* io_data =
835 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
836 return io_data->extensions_request_context();
837 }
838
839 return NULL;
840}
841
[email protected]317f96c92011-05-31 06:53:41842QuotaPermissionContext*
843ChromeContentBrowserClient::CreateQuotaPermissionContext() {
844 return new ChromeQuotaPermissionContext();
845}
846
[email protected]a0ce3282011-08-19 20:49:52847void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42848 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42849}
850
[email protected]a0ce3282011-08-19 20:49:52851void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52852 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52853}
854
[email protected]848dd042011-06-04 18:24:03855void ChromeContentBrowserClient::AllowCertificateError(
856 SSLCertErrorHandler* handler,
857 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58858 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41859 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13860 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]f9034cf2011-07-21 12:43:41861 handler->render_process_host_id(),
862 handler->tab_contents_id());
863 if (!tab) {
864 NOTREACHED();
865 return;
866 }
867 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50868 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30869 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09870 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41871 if (prerender_manager->prerender_tracker()->TryCancel(
872 handler->render_process_host_id(),
873 handler->tab_contents_id(),
874 prerender::FINAL_STATUS_SSL_ERROR)) {
875 handler->CancelRequest();
876 return;
877 }
878 }
879
880 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03881 SSLBlockingPage* blocking_page = new SSLBlockingPage(
882 handler, overridable, callback);
883 blocking_page->Show();
884}
885
[email protected]c99c442e2011-08-24 11:37:30886void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45887 int render_process_id,
888 int render_view_id,
889 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13890 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45891 render_process_id, render_view_id);
892 if (!tab) {
893 NOTREACHED();
894 return;
895 }
896
[email protected]6786bf402011-12-03 15:19:45897 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
898 GURL requesting_url("https://" + cert_request_info->host_and_port);
899 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
900 << cert_request_info->host_and_port;
901
[email protected]627e0512011-12-21 22:55:30902 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45903 DCHECK(profile);
904 scoped_ptr<Value> filter(
905 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
906 requesting_url,
907 requesting_url,
908 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
909 std::string(), NULL));
910
911 if (filter.get()) {
912 // Try to automatically select a client certificate.
913 if (filter->IsType(Value::TYPE_DICTIONARY)) {
914 DictionaryValue* filter_dict =
915 static_cast<DictionaryValue*>(filter.get());
916
917 const std::vector<scoped_refptr<net::X509Certificate> >&
918 all_client_certs = cert_request_info->client_certs;
919 for (size_t i = 0; i < all_client_certs.size(); ++i) {
920 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
921 // Use the first certificate that is matched by the filter.
922 handler->CertificateSelected(all_client_certs[i]);
923 return;
924 }
925 }
926 } else {
927 NOTREACHED();
928 }
929 }
930
[email protected]8ec26472011-06-06 16:52:45931 TabContentsWrapper* wrapper =
932 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45933 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13934 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45935 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14936 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45937 handler->CertificateSelected(NULL);
938 return;
939 }
940 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45941}
942
943void ChromeContentBrowserClient::AddNewCertificate(
944 net::URLRequest* request,
945 net::X509Certificate* cert,
946 int render_process_id,
947 int render_view_id) {
948 // The handler will run the UI and delete itself when it's finished.
949 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
950}
951
[email protected]941623e2011-06-07 23:06:04952void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
953 const GURL& source_origin,
954 int callback_context,
955 int render_process_id,
956 int render_view_id) {
957 RenderViewHost* rvh = RenderViewHost::FromID(
958 render_process_id, render_view_id);
959 if (!rvh) {
960 NOTREACHED();
961 return;
962 }
963
[email protected]f3b1a082011-11-18 00:34:30964 content::RenderProcessHost* process = rvh->process();
965 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04966 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37967 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04968 service->RequestPermission(
969 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:13970 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:04971}
972
973WebKit::WebNotificationPresenter::Permission
974 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02975 const GURL& source_origin,
976 const content::ResourceContext& context,
977 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04978 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
979 ProfileIOData* io_data =
980 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
981
[email protected]34eec7ffe32011-11-02 23:49:02982 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
983 source_origin, render_process_id,
984 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04985 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04986
987 // Fall back to the regular notification preferences, which works on an
988 // origin basis.
989 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:37990 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:04991 WebKit::WebNotificationPresenter::PermissionNotAllowed;
992}
993
994void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:17995 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:04996 int render_process_id,
997 int render_view_id,
998 bool worker) {
999 RenderViewHost* rvh = RenderViewHost::FromID(
1000 render_process_id, render_view_id);
1001 if (!rvh) {
1002 NOTREACHED();
1003 return;
1004 }
1005
[email protected]f3b1a082011-11-18 00:34:301006 content::RenderProcessHost* process = rvh->process();
1007 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041008 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371009 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041010 service->ShowDesktopNotification(
1011 params, render_process_id, render_view_id,
1012 worker ? DesktopNotificationService::WorkerNotification :
1013 DesktopNotificationService::PageNotification);
1014}
1015
1016void ChromeContentBrowserClient::CancelDesktopNotification(
1017 int render_process_id,
1018 int render_view_id,
1019 int notification_id) {
1020 RenderViewHost* rvh = RenderViewHost::FromID(
1021 render_process_id, render_view_id);
1022 if (!rvh) {
1023 NOTREACHED();
1024 return;
1025 }
1026
[email protected]f3b1a082011-11-18 00:34:301027 content::RenderProcessHost* process = rvh->process();
1028 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041029 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371030 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041031 service->CancelDesktopNotification(
1032 render_process_id, render_view_id, notification_id);
1033}
1034
[email protected]9f3fba52011-06-08 20:37:191035bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021036 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191037 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021038 const content::ResourceContext& context,
1039 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1041 // If the opener is trying to create a background window but doesn't have
1042 // the appropriate permission, fail the attempt.
1043 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1044 ProfileIOData* io_data =
1045 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021046 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1047 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191048 }
1049 return true;
1050}
1051
1052std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1053 const GURL& url, const content::ResourceContext& context) {
1054 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1055 // Check if it's an extension-created worker, in which case we want to use
1056 // the name of the extension.
1057 ProfileIOData* io_data =
1058 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1059 const Extension* extension =
1060 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1061 return extension ? extension->name() : std::string();
1062}
1063
[email protected]99907362012-01-11 05:41:401064void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1065 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171066}
1067
1068ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1069 return g_browser_process->clipboard();
1070}
1071
[email protected]8f6a3b852011-07-19 16:48:561072MHTMLGenerationManager*
1073 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1074 return g_browser_process->mhtml_generation_manager();
1075}
1076
[email protected]ae6e9912011-07-27 01:18:281077net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1078 return g_browser_process->net_log();
1079}
1080
[email protected]3bc0b562011-08-24 23:51:041081speech_input::SpeechInputManager*
1082 ChromeContentBrowserClient::GetSpeechInputManager() {
1083 return speech_input::ChromeSpeechInputManager::GetInstance();
1084}
1085
[email protected]32538d92011-08-25 00:09:231086AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1087 return new ChromeAccessTokenStore();
1088}
1089
[email protected]dbae6b02011-06-29 23:51:411090bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1091 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1092 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1093}
1094
[email protected]64d69de42012-02-06 00:19:541095void ChromeContentBrowserClient::OverrideWebkitPrefs(
1096 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061097 Profile* profile = Profile::FromBrowserContext(
1098 rvh->process()->GetBrowserContext());
1099 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061100
[email protected]64d69de42012-02-06 00:19:541101 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061102 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541103 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061104 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541105 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061106 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541107 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061108 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541109 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061110 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541111 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061112 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1113
1114 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541115 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061116 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541117 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061118 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541119 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061120 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541121 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061122 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541123 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061124 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541125 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061126
[email protected]64d69de42012-02-06 00:19:541127 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061128 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541129 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061130 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541131 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061132 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541133 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061134 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1135
[email protected]64d69de42012-02-06 00:19:541136 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061137
[email protected]64d69de42012-02-06 00:19:541138 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061139 prefs->GetBoolean(
1140 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541141 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061142 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541143 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061144 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1145 const DictionaryValue* inspector_settings =
1146 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1147 if (inspector_settings) {
1148 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1149 iter != inspector_settings->end_keys(); ++iter) {
1150 std::string value;
1151 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541152 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061153 std::make_pair(*iter, value));
1154 }
1155 }
[email protected]64d69de42012-02-06 00:19:541156 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061157
[email protected]64d69de42012-02-06 00:19:541158 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1159 web_prefs->javascript_enabled = false;
1160 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1161 web_prefs->web_security_enabled = false;
1162 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1163 web_prefs->plugins_enabled = false;
1164 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1165 web_prefs->java_enabled = false;
1166 web_prefs->loads_images_automatically =
1167 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061168
[email protected]64d69de42012-02-06 00:19:541169 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1170 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061171
[email protected]64d69de42012-02-06 00:19:541172 web_prefs->memory_info_enabled =
1173 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1174 web_prefs->allow_displaying_insecure_content =
1175 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1176 web_prefs->allow_running_insecure_content =
1177 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]f3986f82012-01-03 20:00:061178
[email protected]64d69de42012-02-06 00:19:541179 // The user stylesheet watcher may not exist in a testing profile.
1180 if (profile->GetUserStyleSheetWatcher()) {
1181 web_prefs->user_style_sheet_enabled = true;
1182 web_prefs->user_style_sheet_location =
1183 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1184 } else {
1185 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061186 }
1187
[email protected]64d69de42012-02-06 00:19:541188 web_prefs->unified_textchecker_enabled = CommandLine::ForCurrentProcess()->
1189 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571190
[email protected]64d69de42012-02-06 00:19:541191 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061192 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541193 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061194 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541195 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061196 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1197
1198 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541199 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061200 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541201 web_prefs->default_encoding);
1202 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061203 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541204 web_prefs->default_encoding =
1205 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061206 }
[email protected]64d69de42012-02-06 00:19:541207 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061208
1209 ExtensionService* service = profile->GetExtensionService();
1210 if (service) {
1211 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331212 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061213 extension_webkit_preferences::SetPreferences(
[email protected]64d69de42012-02-06 00:19:541214 extension, rvh->delegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061215 }
1216
1217 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541218 web_prefs->allow_scripts_to_close_windows = true;
[email protected]f3986f82012-01-03 20:00:061219 } else if (rvh->delegate()->GetRenderViewType() ==
1220 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1221 // Disable all kinds of acceleration for background pages.
1222 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541223 web_prefs->force_compositing_mode = false;
1224 web_prefs->accelerated_compositing_enabled = false;
1225 web_prefs->accelerated_2d_canvas_enabled = false;
1226 web_prefs->accelerated_video_enabled = false;
1227 web_prefs->accelerated_painting_enabled = false;
1228 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061229 }
[email protected]181a95ee2011-07-12 19:26:361230}
1231
1232void ChromeContentBrowserClient::UpdateInspectorSetting(
1233 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061234 content::BrowserContext* browser_context =
1235 rvh->process()->GetBrowserContext();
1236 DictionaryPrefUpdate update(
1237 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1238 prefs::kWebKitInspectorSettings);
1239 DictionaryValue* inspector_settings = update.Get();
1240 inspector_settings->SetWithoutPathExpansion(key,
1241 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361242}
1243
1244void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061245 content::BrowserContext* browser_context =
1246 rvh->process()->GetBrowserContext();
1247 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1248 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361249}
1250
[email protected]b8148ac2011-07-13 22:03:251251void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1252 BrowserURLHandler* handler) {
1253 // Add the default URL handlers.
1254 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1255 BrowserURLHandler::null_handler());
1256 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1257 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1258
[email protected]b3adbd02011-11-30 22:23:271259 // about: handler. Must come before chrome: handler, since it will
1260 // rewrite about: urls to chrome: URLs and then expect chrome: to
1261 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251262 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1263 BrowserURLHandler::null_handler());
1264 // chrome: & friends.
1265 handler->AddHandlerPair(&HandleWebUI,
1266 BrowserURLHandler::null_handler());
1267}
1268
1269void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371270 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301271 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251272 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1273 BrowsingDataRemover::EVERYTHING,
1274 base::Time());
1275 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1276 // BrowsingDataRemover takes care of deleting itself when done.
1277}
1278
1279void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371280 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301281 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251282 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1283 BrowsingDataRemover::EVERYTHING,
1284 base::Time());
[email protected]dceaa912011-09-06 17:17:231285 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251286 remover->Remove(remove_mask);
1287 // BrowsingDataRemover takes care of deleting itself when done.
1288}
1289
[email protected]e1d16eb92011-08-18 23:19:321290FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1291 return download_util::GetDefaultDownloadDirectory();
1292}
1293
[email protected]c9b6eb62011-10-18 20:49:391294std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1295 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1296}
1297
[email protected]e60c0232011-11-11 19:56:351298#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301299int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521300 const CommandLine& command_line) {
1301 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071302 ExtensionCrashHandlerHostLinux* crash_handler =
1303 ExtensionCrashHandlerHostLinux::GetInstance();
1304 return crash_handler->GetDeathSignalSocket();
1305 }
1306
[email protected]718eab62011-10-05 21:16:521307 std::string process_type =
1308 command_line.GetSwitchValueASCII(switches::kProcessType);
1309
1310 if (process_type == switches::kRendererProcess)
1311 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1312
[email protected]b80f68432011-05-02 17:22:301313 if (process_type == switches::kPluginProcess)
1314 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1315
1316 if (process_type == switches::kPpapiPluginProcess)
1317 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1318
1319 if (process_type == switches::kGpuProcess)
1320 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1321
1322 return -1;
1323}
[email protected]e60c0232011-11-11 19:56:351324#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301325
[email protected]4a65826d2011-08-25 16:04:011326#if defined(OS_WIN)
1327const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1328 return chrome::kBrowserResourcesDll;
1329}
1330#endif
1331
[email protected]37a72af2011-06-13 05:42:011332#if defined(USE_NSS)
1333crypto::CryptoModuleBlockingPasswordDelegate*
1334 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1335 const GURL& url) {
1336 return browser::NewCryptoModuleBlockingDialogDelegate(
1337 browser::kCryptoModulePasswordKeygen, url.host());
1338}
1339#endif
1340
[email protected]d977f9c2011-03-14 16:10:261341} // namespace chrome