blob: 15cc0afab0f0ad8fe39f3cc7026bd820c52cd4d7 [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>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4718#include "chrome/browser/browsing_data/browsing_data_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1220#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0321#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4122#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5623#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0524#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4525#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3226#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0827#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3228#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1629#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0630#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0431#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0834#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2535#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0636#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4937#include "chrome/browser/extensions/message_handler.h"
[email protected]32538d92011-08-25 00:09:2338#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1239#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0840#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1841#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2842#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0443#include "chrome/browser/notifications/desktop_notification_service.h"
44#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4345#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4246#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0648#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4149#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5050#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0751#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4152#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1453#include "chrome/browser/printing/printing_message_filter.h"
54#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3255#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0656#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1457#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3358#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3859#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]8aa7a412011-11-07 12:33:4260#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0262#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4663#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4564#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0365#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4566#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
67#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5468#include "chrome/browser/toolkit_extra_parts.h"
[email protected]b5d73422012-06-02 23:46:4469#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]871dc682012-06-11 19:35:3370#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]863f70a2012-01-27 02:05:5071#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0672#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1573#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5374#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3075#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0176#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3077#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0478#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3879#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4480#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3481#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1282#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3883#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0984#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4385#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3086#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3887#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3188#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5989#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3090#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3391#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0592#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3393#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1994#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1095#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4396#include "content/public/common/child_process_host.h"
[email protected]b7c4f032012-08-07 16:38:5697#include "content/public/common/compositor_util.h"
[email protected]a1733df2012-06-22 11:24:1898#include "content/public/common/content_descriptors.h"
[email protected]c9b6eb62011-10-18 20:49:3999#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23100#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:40101#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34102#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06103#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38104#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39105#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08106#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36107#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04108#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26109
[email protected]b48c9182011-10-26 18:03:30110#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38111#include "chrome/browser/chrome_browser_main_win.h"
112#elif defined(OS_MACOSX)
113#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56114#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30115#elif defined(OS_CHROMEOS)
116#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49117#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26118#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30119#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09120#elif defined(OS_ANDROID)
121#include "chrome/browser/chrome_browser_main_android.h"
[email protected]b48c9182011-10-26 18:03:30122#elif defined(OS_POSIX)
123#include "chrome/browser/chrome_browser_main_posix.h"
124#endif
125
[email protected]6653c192012-04-10 22:52:44126#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30127#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12128#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43129#endif
[email protected]b80f68432011-05-02 17:22:30130
[email protected]1e87df32012-09-12 04:53:19131#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
132#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
133#endif
134
[email protected]37a72af2011-06-13 05:42:01135#if defined(USE_NSS)
136#include "chrome/browser/ui/crypto_module_password_dialog.h"
137#endif
138
[email protected]c8c77182011-12-21 15:04:47139using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39140using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31141using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59142using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00143using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11144using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33145using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13146using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06147using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34148using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25149using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39150
[email protected]c5dbef02011-05-13 05:06:09151namespace {
152
[email protected]e461da2f2012-02-16 19:06:40153const char* kPredefinedAllowedSocketOrigins[] = {
154 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18155 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45156 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
157 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
158 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
159 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35160 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54161 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
162 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
163 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
164 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
165 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
166 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38167 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
168 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514
[email protected]e461da2f2012-02-16 19:06:40169};
170
[email protected]b8148ac2011-07-13 22:03:25171// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42172bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50173 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
174 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25175 return false;
176
[email protected]fe69558d2012-03-12 11:34:49177#if defined(OS_CHROMEOS)
178 // Special case : in ChromeOS in Guest mode bookmarks and history are
179 // disabled for security reasons. New tab page explains the reasons, so
180 // we redirect user to new tab page.
181 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
182 if (url->SchemeIs(chrome::kChromeUIScheme) &&
183 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
184 url->DomainIs(chrome::kChromeUIHistoryHost))) {
185 // Rewrite with new tab URL
186 *url = GURL(chrome::kChromeUINewTabURL);
187 }
188 }
189#endif
190
[email protected]b8148ac2011-07-13 22:03:25191 // Special case the new tab page. In older versions of Chrome, the new tab
192 // page was hosted at chrome-internal:<blah>. This might be in people's saved
193 // sessions or bookmarks, so we say any URL with that scheme triggers the new
194 // tab page.
195 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
196 // Rewrite it with the proper new tab URL.
197 *url = GURL(chrome::kChromeUINewTabURL);
198 }
199
200 return true;
201}
202
[email protected]8d3132f62011-10-12 07:13:42203// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
204// below. Extension, and isolated apps require different privileges to be
205// granted to their RenderProcessHosts. This classification allows us to make
206// sure URLs are served by hosts with the right set of privileges.
207enum RenderProcessHostPrivilege {
208 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45209 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42210 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45211 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42212};
213
214RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
215 const GURL& url,
216 ExtensionService* service) {
217 // Default to a normal renderer cause it is lower privileged. This should only
218 // occur if the URL on a site instance is either malformed, or uninitialized.
219 // If it is malformed, then there is no need for better privileges anyways.
220 // If it is uninitialized, but eventually settles on being an a scheme other
221 // than normal webrenderer, the navigation logic will correct us out of band
222 // anyways.
223 if (!url.is_valid())
224 return PRIV_NORMAL;
225
226 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44227 const Extension* extension =
228 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45229 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42230 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45231 if (extension && extension->is_hosted_app())
232 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42233
234 return PRIV_EXTENSION;
235 }
236
237 return PRIV_NORMAL;
238}
239
240RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30241 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46242 extensions::ProcessMap* process_map,
243 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46244 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30245 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46246 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21247 return PRIV_NORMAL;
248
[email protected]6f371442011-11-09 06:45:46249 for (std::set<std::string>::iterator iter = extension_ids.begin();
250 iter != extension_ids.end(); ++iter) {
251 const Extension* extension = service->GetExtensionById(*iter, false);
252 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42253 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45254 if (extension && extension->is_hosted_app())
255 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42256 }
257
[email protected]676f6ab2011-10-19 20:23:21258 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42259}
260
[email protected]6786bf402011-12-03 15:19:45261bool CertMatchesFilter(const net::X509Certificate& cert,
262 const base::DictionaryValue& filter) {
263 // TODO(markusheintz): This is the minimal required filter implementation.
264 // Implement a better matcher.
265
266 // An empty filter matches any client certificate since no requirements are
267 // specified at all.
268 if (filter.empty())
269 return true;
270
271 std::string common_name;
272 if (filter.GetString("ISSUER.CN", &common_name) &&
273 (cert.issuer().common_name == common_name)) {
274 return true;
275 }
276 return false;
277}
278
[email protected]f3986f82012-01-03 20:00:06279// Fills |map| with the per-script font prefs under path |map_name|.
280void FillFontFamilyMap(const PrefService* prefs,
281 const char* map_name,
282 WebPreferences::ScriptFontFamilyMap* map) {
283 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
284 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
285 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
286 std::string font_family = prefs->GetString(pref_name.c_str());
287 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32288 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06289 }
290}
291
[email protected]a1733df2012-06-22 11:24:18292#if defined(OS_POSIX) && !defined(OS_MACOSX)
293int GetCrashSignalFD(const CommandLine& command_line) {
294 if (command_line.HasSwitch(switches::kExtensionProcess)) {
295 ExtensionCrashHandlerHostLinux* crash_handler =
296 ExtensionCrashHandlerHostLinux::GetInstance();
297 return crash_handler->GetDeathSignalSocket();
298 }
299
300 std::string process_type =
301 command_line.GetSwitchValueASCII(switches::kProcessType);
302
303 if (process_type == switches::kRendererProcess)
304 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
305
306 if (process_type == switches::kPluginProcess)
307 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
308
309 if (process_type == switches::kPpapiPluginProcess)
310 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
311
312 if (process_type == switches::kGpuProcess)
313 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
314
315 return -1;
316}
317#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
318
[email protected]9dbfff12011-07-01 19:37:07319} // namespace
[email protected]c5dbef02011-05-13 05:06:09320
[email protected]d977f9c2011-03-14 16:10:26321namespace chrome {
322
[email protected]e461da2f2012-02-16 19:06:40323ChromeContentBrowserClient::ChromeContentBrowserClient() {
324 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
325 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40326}
327
328ChromeContentBrowserClient::~ChromeContentBrowserClient() {
329}
330
[email protected]bca18382012-06-25 19:15:23331// static
332void ChromeContentBrowserClient::RegisterUserPrefs(PrefService* prefs) {
333 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
334 false,
335 PrefService::UNSYNCABLE_PREF);
336 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
337 true,
338 PrefService::UNSYNCABLE_PREF);
339 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
340 false,
341 PrefService::UNSYNCABLE_PREF);
342}
343
[email protected]50462bf02011-11-21 19:13:31344content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
345 const content::MainFunctionParams& parameters) {
346 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30347 // Construct the Main browser parts based on the OS type.
348#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31349 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04350#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31351 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30352#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31353 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26354#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31355 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14356#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09357 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30358#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31359 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04360#else
[email protected]b48c9182011-10-26 18:03:30361 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31362 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30363#endif
364
[email protected]c7480942011-11-08 19:18:27365 // Construct additional browser parts. Stages are called in the order in
366 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22367#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41368 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04369#endif
[email protected]c7480942011-11-08 19:18:27370
371#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41372 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27373#endif
374
[email protected]dc04be7c2012-03-15 23:57:49375#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41376 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49377#endif
378
[email protected]e050ef142012-03-21 01:04:24379#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41380 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24381#endif
382
[email protected]50462bf02011-11-21 19:13:31383 return main_parts;
[email protected]f967b722011-09-07 00:58:04384}
385
[email protected]38b098f2012-03-14 21:11:57386content::WebContentsView*
387 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57388 WebContents* web_contents,
389 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57390 return NULL;
391}
392
[email protected]d7c7c98a2012-07-12 21:27:44393std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
394 content::BrowserContext* browser_context,
395 int child_process_id) {
[email protected]d1198fd2012-08-13 22:50:19396 const Extension* extension = NULL;
[email protected]d7c7c98a2012-07-12 21:27:44397 Profile* profile = Profile::FromBrowserContext(browser_context);
398 ExtensionService* extension_service =
399 extensions::ExtensionSystem::Get(profile)->extension_service();
400 if (extension_service) {
[email protected]d1198fd2012-08-13 22:50:19401 extension = extension_service->GetInstalledAppForRenderer(
402 child_process_id);
[email protected]d7c7c98a2012-07-12 21:27:44403 }
[email protected]d1198fd2012-08-13 22:50:19404
405 return GetStoragePartitionIdForExtension(browser_context, extension);
406}
407
[email protected]e94bbcb2012-09-07 05:33:57408std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19409 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57410 const GURL& site) {
[email protected]d1198fd2012-08-13 22:50:19411 const Extension* extension = NULL;
412 Profile* profile = Profile::FromBrowserContext(browser_context);
413 ExtensionService* extension_service =
414 extensions::ExtensionSystem::Get(profile)->extension_service();
415 if (extension_service) {
416 extension = extension_service->extensions()->
[email protected]e94bbcb2012-09-07 05:33:57417 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]d1198fd2012-08-13 22:50:19418 }
419
420 return GetStoragePartitionIdForExtension(browser_context, extension);
421}
422
423bool ChromeContentBrowserClient::IsValidStoragePartitionId(
424 content::BrowserContext* browser_context,
425 const std::string& partition_id) {
426 // The default ID is empty which is always allowed.
427 if (partition_id.empty())
428 return true;
429
430 // If it isn't empty, then it must belong to an extension of some sort. Parse
431 // out the extension ID and make sure it is still installed.
432 Profile* profile = Profile::FromBrowserContext(browser_context);
433 ExtensionService* extension_service =
434 extensions::ExtensionSystem::Get(profile)->extension_service();
435 if (!extension_service) {
436 // No extension service means no storage partitions in Chrome.
437 return false;
438 }
439
440 // See if we can find an extension. The |partition_id| is the extension ID so
441 // no parsing needed to be done.
442 return extension_service->GetExtensionById(partition_id, false) != NULL;
[email protected]d7c7c98a2012-07-12 21:27:44443}
444
[email protected]38b098f2012-03-14 21:11:57445content::WebContentsViewDelegate*
446 ChromeContentBrowserClient::GetWebContentsViewDelegate(
447 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27448 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32449}
450
[email protected]f364d1392011-04-08 21:03:10451void ChromeContentBrowserClient::RenderViewHostCreated(
452 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46453
[email protected]9f76c1e2012-03-05 15:15:58454 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46455 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02456 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46457
458 new ChromeRenderViewHostObserver(render_view_host,
459 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49460 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26461}
462
[email protected]f3b1a082011-11-18 00:34:30463void ChromeContentBrowserClient::RenderProcessHostCreated(
464 content::RenderProcessHost* host) {
465 int id = host->GetID();
466 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
467 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02468 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30469 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02470#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08471 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03472#endif
[email protected]f3b1a082011-11-18 00:34:30473 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02474 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30475 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56476#if defined(OS_MACOSX)
477 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
478#endif
[email protected]f3b1a082011-11-18 00:34:30479 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03480 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07481 host->GetChannel()->AddFilter(
482 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38483
[email protected]2ccf45c2011-08-19 23:35:50484 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
485 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07486
487 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56488
489 RendererContentSettingRules rules;
490 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
491 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14492}
493
[email protected]e0ada9c2012-03-20 03:54:43494void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
495 content::BrowserChildProcessHost* host) {
496 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
497}
498
[email protected]863f70a2012-01-27 02:05:50499content::WebUIControllerFactory*
500 ChromeContentBrowserClient::GetWebUIControllerFactory() {
501 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56502}
503
[email protected]3d7474ff2011-07-27 17:47:37504GURL ChromeContentBrowserClient::GetEffectiveURL(
505 content::BrowserContext* browser_context, const GURL& url) {
506 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08507 // Get the effective URL for the given actual URL. If the URL is part of an
508 // installed app, the effective URL is an extension URL with the ID of that
509 // extension as the host. This has the effect of grouping apps together in
510 // a common SiteInstance.
511 if (!profile || !profile->GetExtensionService())
512 return url;
513
[email protected]615d88f2011-12-13 01:47:44514 const Extension* extension = profile->GetExtensionService()->extensions()->
515 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08516 if (!extension)
517 return url;
518
[email protected]15877ca2011-11-18 22:40:52519 // Bookmark apps do not use the hosted app process model, and should be
520 // treated as normal URLs.
521 if (extension->from_bookmark())
522 return url;
523
[email protected]36fb2c7c2011-04-04 15:49:08524 // If the URL is part of an extension's web extent, convert it to an
525 // extension URL.
526 return extension->GetResourceURL(url.path());
527}
528
[email protected]056ad2a2011-07-12 02:13:55529bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37530 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55531 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52532 // Because we expect to use the effective URL, URLs for hosted apps (apart
533 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55534 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
535 return false;
536
[email protected]3d7474ff2011-07-27 17:47:37537 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55538 if (!profile || !profile->GetExtensionService())
539 return false;
540
[email protected]615d88f2011-12-13 01:47:44541 const Extension* extension = profile->GetExtensionService()->extensions()->
542 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55543 if (!extension)
544 return false;
545
546 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53547 // permission, or that does not allow JavaScript access to the background
548 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55549 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53550 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06551 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53552 !extension->allow_background_js_access()) {
553 return false;
554 }
555 }
[email protected]056ad2a2011-07-12 02:13:55556
[email protected]7b54ca02012-03-02 18:06:53557 // Hosted apps that have script access to their background page must use
558 // process per site, since all instances can make synchronous calls to the
559 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55560 return true;
561}
562
[email protected]46fb9442011-12-09 17:57:47563bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
564 return ProfileIOData::IsHandledURL(url);
565}
566
[email protected]2a5221b2011-09-27 23:07:31567bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30568 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31569 const GURL& site_url) {
570 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30571 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42572 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46573 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31574
[email protected]ffa97602011-11-17 17:55:52575 // Don't allow the Task Manager to share a process with anything else.
576 // Otherwise it can affect the renderers it is observing.
577 // Note: we could create another RenderProcessHostPrivilege bucket for
578 // this to allow multiple chrome://tasks instances to share, but that's
579 // a very unlikely case without serious consequences.
580 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
581 return false;
582
[email protected]8d3132f62011-10-12 07:13:42583 // These may be NULL during tests. In that case, just assume any site can
584 // share any host.
[email protected]6f371442011-11-09 06:45:46585 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31586 return true;
587
[email protected]a8c269a2011-10-25 20:17:22588 // Experimental:
589 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
590 // to share a renderer process. (We could allow pages from the same site or
591 // extensions of the same type to share, if we knew what the given process
592 // was dedicated to. Allowing no sharing is simpler for now.) This may
593 // cause resource exhaustion issues if too many sites are open at once.
594 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
595 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
596 return false;
597
[email protected]eec0b33c2011-12-05 22:09:45598 // Otherwise, just make sure the process privilege matches the privilege
599 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57600 RenderProcessHostPrivilege privilege_required =
601 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45602 return GetProcessPrivilege(process_host, process_map, service) ==
603 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31604}
605
[email protected]76411f412012-02-22 18:56:06606// This function is trying to limit the amount of processes used by extensions
607// with background pages. It uses a globally set percentage of processes to
608// run such extensions and if the limit is exceeded, it returns true, to
609// indicate to the content module to group extensions together.
610bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
611 content::BrowserContext* browser_context, const GURL& url) {
612 // It has to be a valid URL for us to check for an extension.
613 if (!url.is_valid())
614 return false;
615
616 Profile* profile = Profile::FromBrowserContext(browser_context);
617 ExtensionService* service = profile->GetExtensionService();
618 if (!service)
619 return false;
620
621 // We have to have a valid extension with background page to proceed.
622 const Extension* extension =
623 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
624 if (!extension)
625 return false;
626 if (!extension->has_background_page())
627 return false;
628
629 std::set<int> process_ids;
630 size_t max_process_count =
631 content::RenderProcessHost::GetMaxRendererProcessCount();
632
633 // Go through all profiles to ensure we have total count of extension
634 // processes containing background pages, otherwise one profile can
635 // starve the other.
636 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
637 GetLoadedProfiles();
638 for (size_t i = 0; i < profiles.size(); ++i) {
639 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32640 for (ExtensionProcessManager::const_iterator iter =
641 epm->background_hosts().begin();
642 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13643 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32644 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06645 }
646 }
647
648 if (process_ids.size() >
649 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
650 return true;
651 }
652
653 return false;
654}
655
[email protected]6f371442011-11-09 06:45:46656void ChromeContentBrowserClient::SiteInstanceGotProcess(
657 SiteInstance* site_instance) {
658 CHECK(site_instance->HasProcess());
659
660 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02661 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46662 ExtensionService* service = profile->GetExtensionService();
663 if (!service)
664 return;
665
666 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44667 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33668 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46669 if (!extension)
670 return;
671
[email protected]6bc04fd82011-12-04 02:29:35672 service->process_map()->Insert(extension->id(),
673 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33674 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46675 BrowserThread::PostTask(
676 BrowserThread::IO, FROM_HERE,
677 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59678 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46679 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35680 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33681 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46682}
683
684void ChromeContentBrowserClient::SiteInstanceDeleting(
685 SiteInstance* site_instance) {
686 if (!site_instance->HasProcess())
687 return;
688
689 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02690 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46691 ExtensionService* service = profile->GetExtensionService();
692 if (!service)
693 return;
694
695 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44696 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33697 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46698 if (!extension)
699 return;
700
[email protected]6bc04fd82011-12-04 02:29:35701 service->process_map()->Remove(extension->id(),
702 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33703 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46704 BrowserThread::PostTask(
705 BrowserThread::IO, FROM_HERE,
706 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59707 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46708 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35709 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33710 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46711}
712
[email protected]f05763972012-06-06 18:17:26713bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08714 const GURL& current_url,
715 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26716 if (current_url.is_empty()) {
717 // Always choose a new process when navigating to extension URLs. The
718 // process grouping logic will combine all of a given extension's pages
719 // into the same process.
720 if (new_url.SchemeIs(chrome::kExtensionScheme))
721 return true;
[email protected]e3daf3c2011-10-05 21:17:08722
[email protected]f05763972012-06-06 18:17:26723 return false;
724 }
725
726 // Also, we must switch if one is an extension and the other is not the exact
727 // same extension.
728 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
729 new_url.SchemeIs(chrome::kExtensionScheme)) {
730 if (current_url.GetOrigin() != new_url.GetOrigin())
731 return true;
732 }
733
734 return false;
[email protected]e3daf3c2011-10-05 21:17:08735}
736
[email protected]395045c2012-05-22 15:04:38737bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
738 content::ResourceContext* resource_context, const GURL& current_url,
739 const GURL& new_url) {
740 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
741 return extensions::CrossesExtensionProcessBoundary(
742 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17743 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38744}
745
[email protected]763ec4ca2011-04-29 15:48:12746std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
747 const std::string& alias_name) {
748 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
749}
750
[email protected]b80f68432011-05-02 17:22:30751void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
752 CommandLine* command_line, int child_process_id) {
753#if defined(USE_LINUX_BREAKPAD)
754 if (IsCrashReporterEnabled()) {
755 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
756 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
757 }
758#elif defined(OS_MACOSX)
759 if (IsCrashReporterEnabled()) {
760 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
761 child_process_logging::GetClientId());
762 }
763#endif // OS_MACOSX
764
[email protected]f1933792011-06-14 00:49:34765 if (logging::DialogsAreSuppressed())
766 command_line->AppendSwitch(switches::kNoErrorDialogs);
767
[email protected]b80f68432011-05-02 17:22:30768 std::string process_type =
769 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17770 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52771 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30772 FilePath user_data_dir =
773 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
774 if (!user_data_dir.empty())
775 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
776#if defined(OS_CHROMEOS)
777 const std::string& login_profile =
778 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
779 if (!login_profile.empty())
780 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
781#endif
782
[email protected]f3b1a082011-11-18 00:34:30783 content::RenderProcessHost* process =
784 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37785 if (process) {
786 Profile* profile = Profile::FromBrowserContext(
787 process->GetBrowserContext());
788 extensions::ProcessMap* process_map =
789 profile->GetExtensionService()->process_map();
790 if (process_map && process_map->Contains(process->GetID()))
791 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30792
[email protected]a8d851f82011-12-21 00:32:37793 PrefService* prefs = profile->GetPrefs();
794 // Currently this pref is only registered if applied via a policy.
795 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
796 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
797 // Turn this policy into a command line switch.
798 command_line->AppendSwitch(switches::kDisable3DAPIs);
799 }
[email protected]718eab62011-10-05 21:16:52800
[email protected]a8d851f82011-12-21 00:32:37801 // Disable client-side phishing detection in the renderer if it is
802 // disabled in the Profile preferences or the browser process.
803 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
804 !g_browser_process->safe_browsing_detection_service()) {
805 command_line->AppendSwitch(
806 switches::kDisableClientSidePhishingDetection);
807 }
[email protected]0045b0f42012-07-26 11:52:08808
809 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:21810 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]47c7ec82012-01-18 03:29:21811 }
[email protected]4287a3d2011-06-13 23:56:51812
[email protected]47c7ec82012-01-18 03:29:21813 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51814 static const char* const kSwitchNames[] = {
815 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48816 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51817 switches::kAllowScriptingGallery,
818 switches::kAppsCheckoutURL,
819 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31820 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51821 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10822 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50823 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53824 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09825 switches::kDisableInBrowserThumbnailing,
[email protected]4287a3d2011-06-13 23:56:51826 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21827 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13828 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51829 switches::kEnableCrxlessWebApps,
830 switches::kEnableExperimentalExtensionApis,
[email protected]5e92282f2012-08-17 08:11:57831 switches::kEnableFramelessConstrainedDialogs,
[email protected]4287a3d2011-06-13 23:56:51832 switches::kEnableIPCFuzzing,
833 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05834 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48835 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:05836 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:51837 switches::kEnableWatchdog,
838 switches::kExperimentalSpellcheckerFeatures,
839 switches::kMemoryProfiling,
840 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37841 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:37842 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51843 switches::kPpapiFlashArgs,
844 switches::kPpapiFlashInProcess,
845 switches::kPpapiFlashPath,
846 switches::kPpapiFlashVersion,
847 switches::kProfilingAtStart,
848 switches::kProfilingFile,
849 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37850 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51851 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38852 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51853 };
854
855 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
856 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17857 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38858 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35859 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38860 switches::kEnableExperimentalExtensionApis,
861 switches::kWhitelistedExtensionID,
862 };
863
864 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
865 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51866 } else if (process_type == switches::kPluginProcess) {
867 static const char* const kSwitchNames[] = {
868 #if defined(OS_CHROMEOS)
869 switches::kLoginProfile,
870 #endif
871 switches::kMemoryProfiling,
872 switches::kSilentDumpOnDCHECK,
873 switches::kUserDataDir,
874 };
875
876 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
877 arraysize(kSwitchNames));
878 } else if (process_type == switches::kZygoteProcess) {
879 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51880 switches::kUserDataDir, // Make logs go to the right file.
881 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50882 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13883 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51884 switches::kPpapiFlashInProcess,
885 switches::kPpapiFlashPath,
886 switches::kPpapiFlashVersion,
887 };
888
889 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
890 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11891 } else if (process_type == switches::kGpuProcess) {
892 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
893 // because GPU is expected to be unreliable.
894 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
895 !command_line->HasSwitch(switches::kDisableBreakpad))
896 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30897 }
[email protected]6f08af82011-09-15 01:19:03898
899 // The command line switch kEnableBenchmarking needs to be specified along
900 // with the kEnableStatsTable switch to ensure that the stats table global
901 // is initialized correctly.
902 if (command_line->HasSwitch(switches::kEnableBenchmarking))
903 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30904}
905
906std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:43907 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
908 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:30909 return g_browser_process->GetApplicationLocale();
910}
911
[email protected]597a867b2011-11-18 18:31:20912std::string ChromeContentBrowserClient::GetAcceptLangs(
913 content::BrowserContext* context) {
914 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37915 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08916}
917
[email protected]9ec0f452012-05-31 15:58:53918gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22919 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:53920 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:08921}
922
[email protected]a2176792011-05-08 19:30:49923bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09924 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19925 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20926 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20928 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05929 return io_data->GetCookieSettings()->
930 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49931}
932
[email protected]ed24fad2011-05-10 22:44:01933bool ChromeContentBrowserClient::AllowGetCookie(
934 const GURL& url,
935 const GURL& first_party,
936 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20937 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01938 int render_process_id,
939 int render_view_id) {
940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20941 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05942 bool allow = io_data->GetCookieSettings()->
943 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01944
[email protected]8093a542011-05-13 07:29:32945 BrowserThread::PostTask(
946 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03947 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43948 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01949 return allow;
950}
951
952bool ChromeContentBrowserClient::AllowSetCookie(
953 const GURL& url,
954 const GURL& first_party,
955 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20956 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01957 int render_process_id,
958 int render_view_id,
959 net::CookieOptions* options) {
960 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20961 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05962 CookieSettings* cookie_settings = io_data->GetCookieSettings();
963 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
964
[email protected]8093a542011-05-13 07:29:32965 BrowserThread::PostTask(
966 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03967 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43968 render_view_id, url, first_party, cookie_line, *options,
969 !allow));
[email protected]ed24fad2011-05-10 22:44:01970 return allow;
971}
972
[email protected]ea628e32012-08-02 21:50:16973bool ChromeContentBrowserClient::AllowPluginLocalDataAccess(
974 const GURL& document_url,
975 const GURL& plugin_url,
976 content::ResourceContext* context) {
977 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
978 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
979 return io_data->GetCookieSettings()->IsReadingCookieAllowed(document_url,
980 plugin_url);
981}
982
983bool ChromeContentBrowserClient::AllowPluginLocalDataSessionOnly(
984 const GURL& url,
985 content::ResourceContext* context) {
986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
987 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
988 return io_data->GetCookieSettings()->IsCookieSessionOnly(url);
989}
990
[email protected]d5a19162011-06-30 18:51:54991bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20992 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54993 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20994 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:43995 CookieSettings* cookie_settings = io_data->GetCookieSettings();
996 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:26997
[email protected]bf510ed2012-06-05 08:31:43998 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
999 // Could we even support per-origin settings?
1000 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541001}
1002
[email protected]5c5a88e2011-11-12 00:45:351003bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351004 const GURL& url,
1005 const string16& name,
1006 const string16& display_name,
1007 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201008 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481009 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351010 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201011 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351012 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1013 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1014
[email protected]62151052012-02-01 18:40:481015 // Record access to database for potential display in UI.
1016 std::vector<std::pair<int, int> >::const_iterator i;
1017 for (i = render_views.begin(); i != render_views.end(); ++i) {
1018 BrowserThread::PostTask(
1019 BrowserThread::UI, FROM_HERE,
1020 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1021 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351022 }
1023
1024 return allow;
1025}
1026
1027bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351028 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201029 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481030 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351031 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201032 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351033 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1034 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1035
[email protected]62151052012-02-01 18:40:481036 // Record access to file system for potential display in UI.
1037 std::vector<std::pair<int, int> >::const_iterator i;
1038 for (i = render_views.begin(); i != render_views.end(); ++i) {
1039 BrowserThread::PostTask(
1040 BrowserThread::UI, FROM_HERE,
1041 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1042 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351043 }
1044
1045 return allow;
1046}
1047
[email protected]7c5ff9a2012-03-02 07:42:491048bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1049 const GURL& url,
1050 const string16& name,
1051 content::ResourceContext* context,
1052 const std::vector<std::pair<int, int> >& render_views) {
1053 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1054 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1055 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1056 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1057
1058 // Record access to IndexedDB for potential display in UI.
1059 std::vector<std::pair<int, int> >::const_iterator i;
1060 for (i = render_views.begin(); i != render_views.end(); ++i) {
1061 BrowserThread::PostTask(
1062 BrowserThread::UI, FROM_HERE,
1063 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1064 i->first, i->second, url, name, !allow));
1065 }
1066
1067 return allow;
1068}
1069
[email protected]6133f922011-07-01 21:34:341070net::URLRequestContext*
1071ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201072 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341073 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1074 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201075 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341076 return io_data->extensions_request_context();
1077 }
1078
1079 return NULL;
1080}
1081
[email protected]317f96c92011-05-31 06:53:411082QuotaPermissionContext*
1083ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1084 return new ChromeQuotaPermissionContext();
1085}
1086
[email protected]a0ce3282011-08-19 20:49:521087void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421088 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421089}
1090
[email protected]a0ce3282011-08-19 20:49:521091void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521092 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521093}
1094
[email protected]848dd042011-06-04 18:24:031095void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171096 int render_process_id,
1097 int render_view_id,
1098 int cert_error,
1099 const net::SSLInfo& ssl_info,
1100 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031101 bool overridable,
[email protected]d9be47702012-05-16 03:41:221102 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171103 const base::Callback<void(bool)>& callback,
1104 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411105 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131106 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171107 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411108 if (!tab) {
1109 NOTREACHED();
1110 return;
1111 }
1112 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501113 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301114 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091115 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411116 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171117 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411118 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171119 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411120 return;
1121 }
1122 }
1123
[email protected]1e87df32012-09-12 04:53:191124#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
1125 TabContents* tab_contents = TabContents::FromWebContents(tab);
1126 if (tab_contents)
1127 tab_contents->captive_portal_tab_helper()->OnSSLCertError(ssl_info);
1128#endif
1129
[email protected]f9034cf2011-07-21 12:43:411130 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221131 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1132 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031133}
1134
[email protected]c99c442e2011-08-24 11:37:301135void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451136 int render_process_id,
1137 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401138 const net::HttpNetworkSession* network_session,
1139 net::SSLCertRequestInfo* cert_request_info,
1140 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131141 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451142 render_process_id, render_view_id);
1143 if (!tab) {
1144 NOTREACHED();
1145 return;
1146 }
1147
[email protected]6786bf402011-12-03 15:19:451148 GURL requesting_url("https://" + cert_request_info->host_and_port);
1149 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1150 << cert_request_info->host_and_port;
1151
[email protected]627e0512011-12-21 22:55:301152 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451153 scoped_ptr<Value> filter(
1154 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1155 requesting_url,
1156 requesting_url,
1157 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1158 std::string(), NULL));
1159
1160 if (filter.get()) {
1161 // Try to automatically select a client certificate.
1162 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1163 DictionaryValue* filter_dict =
1164 static_cast<DictionaryValue*>(filter.get());
1165
1166 const std::vector<scoped_refptr<net::X509Certificate> >&
1167 all_client_certs = cert_request_info->client_certs;
1168 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1169 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1170 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401171 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451172 return;
1173 }
1174 }
1175 } else {
1176 NOTREACHED();
1177 }
1178 }
1179
[email protected]871dc682012-06-11 19:35:331180 TabContents* tab_contents = TabContents::FromWebContents(tab);
1181 if (!tab_contents) {
1182 // If there is no TabContents for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451183 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141184 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401185 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451186 return;
1187 }
[email protected]871dc682012-06-11 19:35:331188 tab_contents->ssl_helper()->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401189 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451190}
1191
1192void ChromeContentBrowserClient::AddNewCertificate(
1193 net::URLRequest* request,
1194 net::X509Certificate* cert,
1195 int render_process_id,
1196 int render_view_id) {
1197 // The handler will run the UI and delete itself when it's finished.
1198 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1199}
1200
[email protected]dc73a7b2012-03-25 15:27:181201content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1202 return MediaInternals::GetInstance();
1203}
1204
[email protected]941623e2011-06-07 23:06:041205void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1206 const GURL& source_origin,
1207 int callback_context,
1208 int render_process_id,
1209 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111210#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1212 WebContents* contents =
1213 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1214 if (!contents) {
[email protected]941623e2011-06-07 23:06:041215 NOTREACHED();
1216 return;
1217 }
1218
[email protected]d0d9c3ee2012-06-19 03:07:021219 // Skip showing the infobar if the request comes from an extension, and that
1220 // extension has the 'notify' permission. (If the extension does not have the
1221 // permission, the user will still be prompted.)
1222 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
1223 ExtensionService* service = profile->GetExtensionService();
1224 const Extension* extension = !service ? NULL :
1225 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1226 source_origin));
1227 if (extension &&
[email protected]c2e66e12012-06-27 06:27:061228 extension->HasAPIPermission(APIPermission::kNotification)) {
[email protected]d0d9c3ee2012-06-19 03:07:021229 RenderViewHost* rvh =
1230 RenderViewHost::FromID(render_process_id, render_view_id);
1231 if (rvh)
1232 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1233 return;
1234 }
1235
1236 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371237 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021238 notifications->RequestPermission(source_origin, render_process_id,
1239 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111240#else
1241 NOTIMPLEMENTED();
1242#endif
[email protected]941623e2011-06-07 23:06:041243}
1244
1245WebKit::WebNotificationPresenter::Permission
1246 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021247 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201248 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021249 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111250#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201252 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021253 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1254 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061255 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041256 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041257
1258 // Fall back to the regular notification preferences, which works on an
1259 // origin basis.
1260 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371261 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041262 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111263#else
1264 return WebKit::WebNotificationPresenter::PermissionAllowed;
1265#endif
[email protected]941623e2011-06-07 23:06:041266}
1267
1268void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171269 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041270 int render_process_id,
1271 int render_view_id,
1272 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111273#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041274 RenderViewHost* rvh = RenderViewHost::FromID(
1275 render_process_id, render_view_id);
1276 if (!rvh) {
1277 NOTREACHED();
1278 return;
1279 }
1280
[email protected]9f76c1e2012-03-05 15:15:581281 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301282 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041283 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371284 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041285 service->ShowDesktopNotification(
1286 params, render_process_id, render_view_id,
1287 worker ? DesktopNotificationService::WorkerNotification :
1288 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111289#else
1290 NOTIMPLEMENTED();
1291#endif
[email protected]941623e2011-06-07 23:06:041292}
1293
1294void ChromeContentBrowserClient::CancelDesktopNotification(
1295 int render_process_id,
1296 int render_view_id,
1297 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111298#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041299 RenderViewHost* rvh = RenderViewHost::FromID(
1300 render_process_id, render_view_id);
1301 if (!rvh) {
1302 NOTREACHED();
1303 return;
1304 }
1305
[email protected]9f76c1e2012-03-05 15:15:581306 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301307 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041308 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371309 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041310 service->CancelDesktopNotification(
1311 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111312#else
1313 NOTIMPLEMENTED();
1314#endif
[email protected]941623e2011-06-07 23:06:041315}
1316
[email protected]9f3fba52011-06-08 20:37:191317bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351318 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021319 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191320 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201321 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011322 int render_process_id,
1323 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011325
1326 *no_javascript_access = false;
1327
[email protected]9f3fba52011-06-08 20:37:191328 // If the opener is trying to create a background window but doesn't have
1329 // the appropriate permission, fail the attempt.
1330 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201331 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531332 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1333
[email protected]03b6d552012-03-29 04:03:011334 if (!map->SecurityOriginHasAPIPermission(
1335 source_origin,
1336 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061337 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011338 return false;
1339 }
1340
[email protected]7b54ca02012-03-02 18:06:531341 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1342 // return a recently installed Extension even if this CanCreateWindow call
1343 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011344 // because the permission check above would have caused an early return
1345 // already. We must use the full URL to find hosted apps, though, and not
1346 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531347 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351348 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531349 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011350 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191351 }
1352 return true;
1353}
1354
1355std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201356 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1358 // Check if it's an extension-created worker, in which case we want to use
1359 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201360 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191361 const Extension* extension =
1362 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1363 return extension ? extension->name() : std::string();
1364}
1365
[email protected]99907362012-01-11 05:41:401366void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1367 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171368}
1369
[email protected]c52b2892012-03-07 11:01:021370content::SpeechRecognitionManagerDelegate*
1371 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321372#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021373 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321374#else
1375 return NULL;
1376#endif
[email protected]66cfec62012-02-24 17:57:511377}
1378
[email protected]ae6e9912011-07-27 01:18:281379net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1380 return g_browser_process->net_log();
1381}
1382
[email protected]32538d92011-08-25 00:09:231383AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1384 return new ChromeAccessTokenStore();
1385}
1386
[email protected]dbae6b02011-06-29 23:51:411387bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1388 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1389 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1390}
1391
[email protected]64d69de42012-02-06 00:19:541392void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321393 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061394 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581395 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061396 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061397
[email protected]f3986f82012-01-03 20:00:061398 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541399 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061400 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541401 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061402 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541403 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061404 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541405 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061406 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541407 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061408 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541409 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061410
[email protected]64d69de42012-02-06 00:19:541411 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401412 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541413 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401414 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541415 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401416 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541417 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401418 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061419
[email protected]ddf72142012-05-22 04:52:401420 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061421
[email protected]64d69de42012-02-06 00:19:541422 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401423 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541424 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061425 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541426 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061427 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1428 const DictionaryValue* inspector_settings =
1429 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1430 if (inspector_settings) {
1431 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1432 iter != inspector_settings->end_keys(); ++iter) {
1433 std::string value;
1434 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541435 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061436 std::make_pair(*iter, value));
1437 }
1438 }
[email protected]64d69de42012-02-06 00:19:541439 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061440
[email protected]ddf72142012-05-22 04:52:401441 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541442 web_prefs->javascript_enabled = false;
1443 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1444 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401445 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541446 web_prefs->plugins_enabled = false;
1447 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1448 web_prefs->java_enabled = false;
1449 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401450 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061451
[email protected]64d69de42012-02-06 00:19:541452 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1453 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061454
[email protected]64d69de42012-02-06 00:19:541455 web_prefs->memory_info_enabled =
1456 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1457 web_prefs->allow_displaying_insecure_content =
1458 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1459 web_prefs->allow_running_insecure_content =
1460 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081461 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061462
[email protected]64d69de42012-02-06 00:19:541463 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151464 UserStyleSheetWatcher* user_style_sheet_watcher =
1465 UserStyleSheetWatcherFactory::GetForProfile(profile);
1466 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541467 web_prefs->user_style_sheet_enabled = true;
1468 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151469 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541470 } else {
1471 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061472 }
1473
[email protected]b7e44ff2012-02-16 03:37:341474 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101475#if defined(OS_MACOSX)
1476 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1477 // Mac so it uses NSSpellChecker in the background.
1478 false;
1479#else
1480 !CommandLine::ForCurrentProcess()->
1481 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1482#endif
[email protected]b7e44ff2012-02-16 03:37:341483 web_prefs->unified_textchecker_enabled =
1484 web_prefs->asynchronous_spell_checking_enabled ||
1485 CommandLine::ForCurrentProcess()->
1486 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571487
[email protected]64d69de42012-02-06 00:19:541488 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061489 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541490 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061491 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541492 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061493 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1494
1495 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541496 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061497 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541498 web_prefs->default_encoding);
1499 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401500 prefs->ClearPref(prefs::kDefaultCharset);
1501 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061502 }
[email protected]64d69de42012-02-06 00:19:541503 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061504
[email protected]299d7f12012-05-23 05:31:151505 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1506 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061507 ExtensionService* service = profile->GetExtensionService();
1508 if (service) {
1509 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581510 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061511 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151512 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061513 }
1514
[email protected]b7c4f032012-08-07 16:38:561515 if (content::IsForceCompositingModeEnabled())
[email protected]4abe58d2012-06-08 03:09:091516 web_prefs->force_compositing_mode = true;
1517
[email protected]299d7f12012-05-23 05:31:151518 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541519 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151520 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061521 // Disable all kinds of acceleration for background pages.
1522 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541523 web_prefs->force_compositing_mode = false;
1524 web_prefs->accelerated_compositing_enabled = false;
1525 web_prefs->accelerated_2d_canvas_enabled = false;
1526 web_prefs->accelerated_video_enabled = false;
1527 web_prefs->accelerated_painting_enabled = false;
1528 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061529 }
[email protected]2e21fe292012-03-02 22:52:321530
1531#if defined(FILE_MANAGER_EXTENSION)
1532 // Override the default of suppressing HW compositing for WebUI pages for the
1533 // file manager, which is implemented using WebUI but wants HW acceleration
1534 // for video decode & render.
1535 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1536 web_prefs->accelerated_compositing_enabled = true;
1537 web_prefs->accelerated_2d_canvas_enabled = true;
1538 }
1539#endif
[email protected]181a95ee2011-07-12 19:26:361540}
1541
1542void ChromeContentBrowserClient::UpdateInspectorSetting(
1543 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061544 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581545 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061546 DictionaryPrefUpdate update(
1547 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1548 prefs::kWebKitInspectorSettings);
1549 DictionaryValue* inspector_settings = update.Get();
1550 inspector_settings->SetWithoutPathExpansion(key,
1551 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361552}
1553
1554void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061555 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581556 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061557 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1558 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361559}
1560
[email protected]b8148ac2011-07-13 22:03:251561void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1562 BrowserURLHandler* handler) {
1563 // Add the default URL handlers.
1564 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1565 BrowserURLHandler::null_handler());
1566 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1567 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1568
[email protected]b3adbd02011-11-30 22:23:271569 // about: handler. Must come before chrome: handler, since it will
1570 // rewrite about: urls to chrome: URLs and then expect chrome: to
1571 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251572 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1573 BrowserURLHandler::null_handler());
1574 // chrome: & friends.
1575 handler->AddHandlerPair(&HandleWebUI,
1576 BrowserURLHandler::null_handler());
1577}
1578
1579void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371580 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581581 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471582 BrowsingDataRemover* remover =
1583 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551584 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1585 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251586 // BrowsingDataRemover takes care of deleting itself when done.
1587}
1588
1589void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371590 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581591 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471592 BrowsingDataRemover* remover =
1593 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231594 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551595 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251596 // BrowsingDataRemover takes care of deleting itself when done.
1597}
1598
[email protected]e1d16eb92011-08-18 23:19:321599FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1600 return download_util::GetDefaultDownloadDirectory();
1601}
1602
[email protected]c9b6eb62011-10-18 20:49:391603std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1604 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1605}
1606
[email protected]b7631cc2012-09-15 05:08:381607void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1608 content::BrowserPpapiHost* browser_host) {
1609 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1610 scoped_ptr<ppapi::host::HostFactory>(
1611 new ChromeBrowserPepperHostFactory(browser_host)));
1612}
1613
[email protected]38cd8f7f2012-06-15 22:06:071614bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]a658d452012-03-02 12:45:291615 content::BrowserContext* browser_context, const GURL& url) {
1616 if (!url.is_valid())
1617 return false;
1618
1619 std::string host = url.host();
[email protected]92444942012-06-16 09:05:281620 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host))
[email protected]a658d452012-03-02 12:45:291621 return true;
1622
[email protected]9a5940d2012-04-27 19:16:231623 Profile* profile = Profile::FromBrowserContext(browser_context);
1624 const Extension* extension = NULL;
1625 if (profile && profile->GetExtensionService()) {
1626 extension = profile->GetExtensionService()->extensions()->
1627 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1628 }
1629
[email protected]f237c0f2012-03-10 07:49:101630 // Need to check this now and not on construction because otherwise it won't
1631 // work with browser_tests.
1632 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1633 std::string allowed_list =
1634 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231635 if (allowed_list == "*") {
1636 // The wildcard allows socket API only for packaged and platform apps.
1637 return extension &&
1638 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1639 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1640 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101641 StringTokenizer t(allowed_list, ",");
1642 while (t.GetNext()) {
1643 if (t.token() == host)
1644 return true;
1645 }
1646 }
1647
[email protected]a658d452012-03-02 12:45:291648 if (!extension)
1649 return false;
1650
[email protected]c2e66e12012-06-27 06:27:061651 if (extension->HasAPIPermission(APIPermission::kSocket))
[email protected]a658d452012-03-02 12:45:291652 return true;
1653
1654 return false;
[email protected]e461da2f2012-02-16 19:06:401655}
1656
[email protected]38cd8f7f2012-06-15 22:06:071657bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1658 return CommandLine::ForCurrentProcess()->HasSwitch(
1659 switches::kPpapiFlashInProcess);
1660}
1661
[email protected]e60c0232011-11-11 19:56:351662#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181663void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1664 const CommandLine& command_line,
1665 base::GlobalDescriptors::Mapping* mappings) {
1666 int crash_signal_fd = GetCrashSignalFD(command_line);
1667 if (crash_signal_fd >= 0) {
1668 mappings->push_back(std::pair<base::GlobalDescriptors::Key, int>(
1669 kCrashDumpSignal, crash_signal_fd));
[email protected]9dbfff12011-07-01 19:37:071670 }
[email protected]b80f68432011-05-02 17:22:301671}
[email protected]e60c0232011-11-11 19:56:351672#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301673
[email protected]4a65826d2011-08-25 16:04:011674#if defined(OS_WIN)
1675const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1676 return chrome::kBrowserResourcesDll;
1677}
1678#endif
1679
[email protected]37a72af2011-06-13 05:42:011680#if defined(USE_NSS)
1681crypto::CryptoModuleBlockingPasswordDelegate*
1682 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1683 const GURL& url) {
1684 return browser::NewCryptoModuleBlockingDialogDelegate(
1685 browser::kCryptoModulePasswordKeygen, url.host());
1686}
1687#endif
1688
[email protected]e9a32a52012-06-14 23:32:431689void ChromeContentBrowserClient::SetApplicationLocale(
1690 const std::string& locale) {
1691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1692
1693 // This object is guaranteed to outlive all threads so we don't have to
1694 // worry about the lack of refcounting and can just post as Unretained.
1695 //
1696 // The common case is that this function is called early in Chrome startup
1697 // before any threads are created (it will also be called later if the user
1698 // changes the pref). In this case, there will be no threads created and
1699 // posting will fail. When there are no threads, we can just set the string
1700 // without worrying about threadsafety.
1701 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1702 base::Bind(
1703 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1704 base::Unretained(this), locale)))
1705 io_thread_application_locale_ = locale;
1706}
1707
1708void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1709 const std::string& locale) {
1710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1711 io_thread_application_locale_ = locale;
1712}
1713
[email protected]d1198fd2012-08-13 22:50:191714std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension(
1715 content::BrowserContext* browser_context, const Extension* extension) {
1716 // In chrome, we use the extension ID as the partition ID. This works well
1717 // because the extension ID fits the partition ID pattern and currently only
1718 // apps can designate that storage should be isolated.
1719 //
1720 // If |extension| is NULL, then the default, empty string, partition id is
1721 // used.
1722 std::string partition_id;
1723 if (extension && extension->is_storage_isolated()) {
1724 partition_id = extension->id();
1725 }
1726
1727 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1728 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1729 return partition_id;
1730}
1731
1732
[email protected]d977f9c2011-03-14 16:10:261733} // namespace chrome