blob: 7d52975570876db9451e6286ff71ec380dd0d091 [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]8aa7a412011-11-07 12:33:4259#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1460#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0261#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4662#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0364#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4565#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
66#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5467#include "chrome/browser/toolkit_extra_parts.h"
[email protected]b5d73422012-06-02 23:46:4468#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]871dc682012-06-11 19:35:3369#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]863f70a2012-01-27 02:05:5070#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0671#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1572#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5373#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3074#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0175#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3076#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0477#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3878#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4479#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3480#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1281#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3882#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0983#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4384#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3085#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3186#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5987#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3088#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3389#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0590#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3391#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1992#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1093#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4394#include "content/public/common/child_process_host.h"
[email protected]b7c4f032012-08-07 16:38:5695#include "content/public/common/compositor_util.h"
[email protected]a1733df2012-06-22 11:24:1896#include "content/public/common/content_descriptors.h"
[email protected]c9b6eb62011-10-18 20:49:3997#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:2398#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4099#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34100#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06101#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:39102#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08103#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36104#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04105#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26106
[email protected]b48c9182011-10-26 18:03:30107#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38108#include "chrome/browser/chrome_browser_main_win.h"
109#elif defined(OS_MACOSX)
110#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56111#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30112#elif defined(OS_CHROMEOS)
113#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49114#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26115#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30116#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09117#elif defined(OS_ANDROID)
118#include "chrome/browser/chrome_browser_main_android.h"
[email protected]b48c9182011-10-26 18:03:30119#elif defined(OS_POSIX)
120#include "chrome/browser/chrome_browser_main_posix.h"
121#endif
122
[email protected]6653c192012-04-10 22:52:44123#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30124#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12125#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43126#endif
[email protected]b80f68432011-05-02 17:22:30127
[email protected]37a72af2011-06-13 05:42:01128#if defined(USE_NSS)
129#include "chrome/browser/ui/crypto_module_password_dialog.h"
130#endif
131
[email protected]c8c77182011-12-21 15:04:47132using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39133using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31134using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59135using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00136using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11137using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33138using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13139using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06140using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34141using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25142using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39143
[email protected]c5dbef02011-05-13 05:06:09144namespace {
145
[email protected]e461da2f2012-02-16 19:06:40146const char* kPredefinedAllowedSocketOrigins[] = {
147 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18148 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45149 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
150 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
151 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
152 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35153 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54154 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
155 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
156 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
157 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
158 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
159 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38160 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
161 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514
[email protected]e461da2f2012-02-16 19:06:40162};
163
[email protected]b8148ac2011-07-13 22:03:25164// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42165bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50166 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
167 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25168 return false;
169
[email protected]fe69558d2012-03-12 11:34:49170#if defined(OS_CHROMEOS)
171 // Special case : in ChromeOS in Guest mode bookmarks and history are
172 // disabled for security reasons. New tab page explains the reasons, so
173 // we redirect user to new tab page.
174 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
175 if (url->SchemeIs(chrome::kChromeUIScheme) &&
176 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
177 url->DomainIs(chrome::kChromeUIHistoryHost))) {
178 // Rewrite with new tab URL
179 *url = GURL(chrome::kChromeUINewTabURL);
180 }
181 }
182#endif
183
[email protected]b8148ac2011-07-13 22:03:25184 // Special case the new tab page. In older versions of Chrome, the new tab
185 // page was hosted at chrome-internal:<blah>. This might be in people's saved
186 // sessions or bookmarks, so we say any URL with that scheme triggers the new
187 // tab page.
188 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
189 // Rewrite it with the proper new tab URL.
190 *url = GURL(chrome::kChromeUINewTabURL);
191 }
192
193 return true;
194}
195
[email protected]8d3132f62011-10-12 07:13:42196// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
197// below. Extension, and isolated apps require different privileges to be
198// granted to their RenderProcessHosts. This classification allows us to make
199// sure URLs are served by hosts with the right set of privileges.
200enum RenderProcessHostPrivilege {
201 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45202 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42203 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45204 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42205};
206
207RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
208 const GURL& url,
209 ExtensionService* service) {
210 // Default to a normal renderer cause it is lower privileged. This should only
211 // occur if the URL on a site instance is either malformed, or uninitialized.
212 // If it is malformed, then there is no need for better privileges anyways.
213 // If it is uninitialized, but eventually settles on being an a scheme other
214 // than normal webrenderer, the navigation logic will correct us out of band
215 // anyways.
216 if (!url.is_valid())
217 return PRIV_NORMAL;
218
219 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44220 const Extension* extension =
221 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45222 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42223 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45224 if (extension && extension->is_hosted_app())
225 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42226
227 return PRIV_EXTENSION;
228 }
229
230 return PRIV_NORMAL;
231}
232
233RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30234 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46235 extensions::ProcessMap* process_map,
236 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46237 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30238 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46239 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21240 return PRIV_NORMAL;
241
[email protected]6f371442011-11-09 06:45:46242 for (std::set<std::string>::iterator iter = extension_ids.begin();
243 iter != extension_ids.end(); ++iter) {
244 const Extension* extension = service->GetExtensionById(*iter, false);
245 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42246 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45247 if (extension && extension->is_hosted_app())
248 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42249 }
250
[email protected]676f6ab2011-10-19 20:23:21251 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42252}
253
[email protected]eec0b33c2011-12-05 22:09:45254bool IsIsolatedAppInProcess(const GURL& site_url,
255 content::RenderProcessHost* process_host,
256 extensions::ProcessMap* process_map,
257 ExtensionService* service) {
258 std::set<std::string> extension_ids =
259 process_map->GetExtensionsInProcess(process_host->GetID());
260 if (extension_ids.empty())
261 return false;
262
263 for (std::set<std::string>::iterator iter = extension_ids.begin();
264 iter != extension_ids.end(); ++iter) {
265 const Extension* extension = service->GetExtensionById(*iter, false);
266 if (extension &&
267 extension->is_storage_isolated() &&
268 extension->url() == site_url)
269 return true;
270 }
271
272 return false;
273}
274
[email protected]6786bf402011-12-03 15:19:45275bool CertMatchesFilter(const net::X509Certificate& cert,
276 const base::DictionaryValue& filter) {
277 // TODO(markusheintz): This is the minimal required filter implementation.
278 // Implement a better matcher.
279
280 // An empty filter matches any client certificate since no requirements are
281 // specified at all.
282 if (filter.empty())
283 return true;
284
285 std::string common_name;
286 if (filter.GetString("ISSUER.CN", &common_name) &&
287 (cert.issuer().common_name == common_name)) {
288 return true;
289 }
290 return false;
291}
292
[email protected]f3986f82012-01-03 20:00:06293// Fills |map| with the per-script font prefs under path |map_name|.
294void FillFontFamilyMap(const PrefService* prefs,
295 const char* map_name,
296 WebPreferences::ScriptFontFamilyMap* map) {
297 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
298 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
299 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
300 std::string font_family = prefs->GetString(pref_name.c_str());
301 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32302 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06303 }
304}
305
[email protected]a1733df2012-06-22 11:24:18306#if defined(OS_POSIX) && !defined(OS_MACOSX)
307int GetCrashSignalFD(const CommandLine& command_line) {
308 if (command_line.HasSwitch(switches::kExtensionProcess)) {
309 ExtensionCrashHandlerHostLinux* crash_handler =
310 ExtensionCrashHandlerHostLinux::GetInstance();
311 return crash_handler->GetDeathSignalSocket();
312 }
313
314 std::string process_type =
315 command_line.GetSwitchValueASCII(switches::kProcessType);
316
317 if (process_type == switches::kRendererProcess)
318 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
319
320 if (process_type == switches::kPluginProcess)
321 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
322
323 if (process_type == switches::kPpapiPluginProcess)
324 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
325
326 if (process_type == switches::kGpuProcess)
327 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
328
329 return -1;
330}
331#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
332
[email protected]9dbfff12011-07-01 19:37:07333} // namespace
[email protected]c5dbef02011-05-13 05:06:09334
[email protected]d977f9c2011-03-14 16:10:26335namespace chrome {
336
[email protected]e461da2f2012-02-16 19:06:40337ChromeContentBrowserClient::ChromeContentBrowserClient() {
338 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
339 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40340}
341
342ChromeContentBrowserClient::~ChromeContentBrowserClient() {
343}
344
[email protected]bca18382012-06-25 19:15:23345// static
346void ChromeContentBrowserClient::RegisterUserPrefs(PrefService* prefs) {
347 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
348 false,
349 PrefService::UNSYNCABLE_PREF);
350 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
351 true,
352 PrefService::UNSYNCABLE_PREF);
353 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
354 false,
355 PrefService::UNSYNCABLE_PREF);
356}
357
[email protected]50462bf02011-11-21 19:13:31358content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
359 const content::MainFunctionParams& parameters) {
360 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30361 // Construct the Main browser parts based on the OS type.
362#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31363 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04364#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31365 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30366#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31367 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26368#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31369 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14370#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09371 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30372#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31373 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04374#else
[email protected]b48c9182011-10-26 18:03:30375 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31376 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30377#endif
378
[email protected]c7480942011-11-08 19:18:27379 // Construct additional browser parts. Stages are called in the order in
380 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22381#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41382 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04383#endif
[email protected]c7480942011-11-08 19:18:27384
385#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41386 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27387#endif
388
[email protected]dc04be7c2012-03-15 23:57:49389#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41390 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49391#endif
392
[email protected]e050ef142012-03-21 01:04:24393#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41394 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24395#endif
396
[email protected]50462bf02011-11-21 19:13:31397 return main_parts;
[email protected]f967b722011-09-07 00:58:04398}
399
[email protected]38b098f2012-03-14 21:11:57400content::WebContentsView*
401 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57402 WebContents* web_contents,
403 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57404 return NULL;
405}
406
[email protected]d7c7c98a2012-07-12 21:27:44407std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
408 content::BrowserContext* browser_context,
409 int child_process_id) {
[email protected]d1198fd2012-08-13 22:50:19410 const Extension* extension = NULL;
[email protected]d7c7c98a2012-07-12 21:27:44411 Profile* profile = Profile::FromBrowserContext(browser_context);
412 ExtensionService* extension_service =
413 extensions::ExtensionSystem::Get(profile)->extension_service();
414 if (extension_service) {
[email protected]d1198fd2012-08-13 22:50:19415 extension = extension_service->GetInstalledAppForRenderer(
416 child_process_id);
[email protected]d7c7c98a2012-07-12 21:27:44417 }
[email protected]d1198fd2012-08-13 22:50:19418
419 return GetStoragePartitionIdForExtension(browser_context, extension);
420}
421
422std::string ChromeContentBrowserClient::GetStoragePartitionIdForSiteInstance(
423 content::BrowserContext* browser_context,
424 SiteInstance* instance) {
425 const Extension* extension = NULL;
426 Profile* profile = Profile::FromBrowserContext(browser_context);
427 ExtensionService* extension_service =
428 extensions::ExtensionSystem::Get(profile)->extension_service();
429 if (extension_service) {
430 extension = extension_service->extensions()->
431 GetExtensionOrAppByURL(ExtensionURLInfo(instance->GetSite()));
432 }
433
434 return GetStoragePartitionIdForExtension(browser_context, extension);
435}
436
437bool ChromeContentBrowserClient::IsValidStoragePartitionId(
438 content::BrowserContext* browser_context,
439 const std::string& partition_id) {
440 // The default ID is empty which is always allowed.
441 if (partition_id.empty())
442 return true;
443
444 // If it isn't empty, then it must belong to an extension of some sort. Parse
445 // out the extension ID and make sure it is still installed.
446 Profile* profile = Profile::FromBrowserContext(browser_context);
447 ExtensionService* extension_service =
448 extensions::ExtensionSystem::Get(profile)->extension_service();
449 if (!extension_service) {
450 // No extension service means no storage partitions in Chrome.
451 return false;
452 }
453
454 // See if we can find an extension. The |partition_id| is the extension ID so
455 // no parsing needed to be done.
456 return extension_service->GetExtensionById(partition_id, false) != NULL;
[email protected]d7c7c98a2012-07-12 21:27:44457}
458
[email protected]38b098f2012-03-14 21:11:57459content::WebContentsViewDelegate*
460 ChromeContentBrowserClient::GetWebContentsViewDelegate(
461 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27462 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32463}
464
[email protected]f364d1392011-04-08 21:03:10465void ChromeContentBrowserClient::RenderViewHostCreated(
466 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46467
[email protected]9f76c1e2012-03-05 15:15:58468 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46469 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02470 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46471
472 new ChromeRenderViewHostObserver(render_view_host,
473 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49474 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26475}
476
[email protected]f3b1a082011-11-18 00:34:30477void ChromeContentBrowserClient::RenderProcessHostCreated(
478 content::RenderProcessHost* host) {
479 int id = host->GetID();
480 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
481 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02482 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30483 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02484#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08485 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03486#endif
[email protected]f3b1a082011-11-18 00:34:30487 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02488 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30489 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56490#if defined(OS_MACOSX)
491 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
492#endif
[email protected]f3b1a082011-11-18 00:34:30493 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03494 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07495 host->GetChannel()->AddFilter(
496 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38497
[email protected]2ccf45c2011-08-19 23:35:50498 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
499 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07500
501 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56502
503 RendererContentSettingRules rules;
504 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
505 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14506}
507
[email protected]e0ada9c2012-03-20 03:54:43508void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
509 content::BrowserChildProcessHost* host) {
510 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
511}
512
[email protected]863f70a2012-01-27 02:05:50513content::WebUIControllerFactory*
514 ChromeContentBrowserClient::GetWebUIControllerFactory() {
515 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56516}
517
[email protected]3d7474ff2011-07-27 17:47:37518GURL ChromeContentBrowserClient::GetEffectiveURL(
519 content::BrowserContext* browser_context, const GURL& url) {
520 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08521 // Get the effective URL for the given actual URL. If the URL is part of an
522 // installed app, the effective URL is an extension URL with the ID of that
523 // extension as the host. This has the effect of grouping apps together in
524 // a common SiteInstance.
525 if (!profile || !profile->GetExtensionService())
526 return url;
527
[email protected]615d88f2011-12-13 01:47:44528 const Extension* extension = profile->GetExtensionService()->extensions()->
529 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08530 if (!extension)
531 return url;
532
[email protected]15877ca2011-11-18 22:40:52533 // Bookmark apps do not use the hosted app process model, and should be
534 // treated as normal URLs.
535 if (extension->from_bookmark())
536 return url;
537
[email protected]36fb2c7c2011-04-04 15:49:08538 // If the URL is part of an extension's web extent, convert it to an
539 // extension URL.
540 return extension->GetResourceURL(url.path());
541}
542
[email protected]056ad2a2011-07-12 02:13:55543bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37544 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55545 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52546 // Because we expect to use the effective URL, URLs for hosted apps (apart
547 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55548 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
549 return false;
550
[email protected]3d7474ff2011-07-27 17:47:37551 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55552 if (!profile || !profile->GetExtensionService())
553 return false;
554
[email protected]615d88f2011-12-13 01:47:44555 const Extension* extension = profile->GetExtensionService()->extensions()->
556 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55557 if (!extension)
558 return false;
559
560 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53561 // permission, or that does not allow JavaScript access to the background
562 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55563 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53564 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06565 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53566 !extension->allow_background_js_access()) {
567 return false;
568 }
569 }
[email protected]056ad2a2011-07-12 02:13:55570
[email protected]7b54ca02012-03-02 18:06:53571 // Hosted apps that have script access to their background page must use
572 // process per site, since all instances can make synchronous calls to the
573 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55574 return true;
575}
576
[email protected]46fb9442011-12-09 17:57:47577bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
578 return ProfileIOData::IsHandledURL(url);
579}
580
[email protected]2a5221b2011-09-27 23:07:31581bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30582 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31583 const GURL& site_url) {
584 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30585 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42586 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46587 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31588
[email protected]ffa97602011-11-17 17:55:52589 // Don't allow the Task Manager to share a process with anything else.
590 // Otherwise it can affect the renderers it is observing.
591 // Note: we could create another RenderProcessHostPrivilege bucket for
592 // this to allow multiple chrome://tasks instances to share, but that's
593 // a very unlikely case without serious consequences.
594 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
595 return false;
596
[email protected]8d3132f62011-10-12 07:13:42597 // These may be NULL during tests. In that case, just assume any site can
598 // share any host.
[email protected]6f371442011-11-09 06:45:46599 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31600 return true;
601
[email protected]a8c269a2011-10-25 20:17:22602 // Experimental:
603 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
604 // to share a renderer process. (We could allow pages from the same site or
605 // extensions of the same type to share, if we knew what the given process
606 // was dedicated to. Allowing no sharing is simpler for now.) This may
607 // cause resource exhaustion issues if too many sites are open at once.
608 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
609 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
610 return false;
611
[email protected]eec0b33c2011-12-05 22:09:45612 // An isolated app is only allowed to share with the exact same app in order
613 // to provide complete renderer process isolation. This also works around
614 // issue http://crbug.com/85588, where different isolated apps in the same
615 // process would end up using the first app's storage contexts.
616 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42617 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45618 if (privilege_required == PRIV_ISOLATED)
619 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
620
621 // Otherwise, just make sure the process privilege matches the privilege
622 // required by the site.
623 return GetProcessPrivilege(process_host, process_map, service) ==
624 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31625}
626
[email protected]76411f412012-02-22 18:56:06627// This function is trying to limit the amount of processes used by extensions
628// with background pages. It uses a globally set percentage of processes to
629// run such extensions and if the limit is exceeded, it returns true, to
630// indicate to the content module to group extensions together.
631bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
632 content::BrowserContext* browser_context, const GURL& url) {
633 // It has to be a valid URL for us to check for an extension.
634 if (!url.is_valid())
635 return false;
636
637 Profile* profile = Profile::FromBrowserContext(browser_context);
638 ExtensionService* service = profile->GetExtensionService();
639 if (!service)
640 return false;
641
642 // We have to have a valid extension with background page to proceed.
643 const Extension* extension =
644 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
645 if (!extension)
646 return false;
647 if (!extension->has_background_page())
648 return false;
649
650 std::set<int> process_ids;
651 size_t max_process_count =
652 content::RenderProcessHost::GetMaxRendererProcessCount();
653
654 // Go through all profiles to ensure we have total count of extension
655 // processes containing background pages, otherwise one profile can
656 // starve the other.
657 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
658 GetLoadedProfiles();
659 for (size_t i = 0; i < profiles.size(); ++i) {
660 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32661 for (ExtensionProcessManager::const_iterator iter =
662 epm->background_hosts().begin();
663 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13664 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32665 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06666 }
667 }
668
669 if (process_ids.size() >
670 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
671 return true;
672 }
673
674 return false;
675}
676
[email protected]6f371442011-11-09 06:45:46677void ChromeContentBrowserClient::SiteInstanceGotProcess(
678 SiteInstance* site_instance) {
679 CHECK(site_instance->HasProcess());
680
681 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02682 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46683 ExtensionService* service = profile->GetExtensionService();
684 if (!service)
685 return;
686
687 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44688 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33689 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46690 if (!extension)
691 return;
692
[email protected]6bc04fd82011-12-04 02:29:35693 service->process_map()->Insert(extension->id(),
694 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33695 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46696 BrowserThread::PostTask(
697 BrowserThread::IO, FROM_HERE,
698 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59699 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46700 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35701 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33702 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46703}
704
705void ChromeContentBrowserClient::SiteInstanceDeleting(
706 SiteInstance* site_instance) {
707 if (!site_instance->HasProcess())
708 return;
709
710 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02711 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46712 ExtensionService* service = profile->GetExtensionService();
713 if (!service)
714 return;
715
716 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44717 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33718 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46719 if (!extension)
720 return;
721
[email protected]6bc04fd82011-12-04 02:29:35722 service->process_map()->Remove(extension->id(),
723 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33724 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46725 BrowserThread::PostTask(
726 BrowserThread::IO, FROM_HERE,
727 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59728 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46729 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35730 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33731 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46732}
733
[email protected]f05763972012-06-06 18:17:26734bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08735 const GURL& current_url,
736 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26737 if (current_url.is_empty()) {
738 // Always choose a new process when navigating to extension URLs. The
739 // process grouping logic will combine all of a given extension's pages
740 // into the same process.
741 if (new_url.SchemeIs(chrome::kExtensionScheme))
742 return true;
[email protected]e3daf3c2011-10-05 21:17:08743
[email protected]f05763972012-06-06 18:17:26744 return false;
745 }
746
747 // Also, we must switch if one is an extension and the other is not the exact
748 // same extension.
749 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
750 new_url.SchemeIs(chrome::kExtensionScheme)) {
751 if (current_url.GetOrigin() != new_url.GetOrigin())
752 return true;
753 }
754
755 return false;
[email protected]e3daf3c2011-10-05 21:17:08756}
757
[email protected]395045c2012-05-22 15:04:38758bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
759 content::ResourceContext* resource_context, const GURL& current_url,
760 const GURL& new_url) {
761 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
762 return extensions::CrossesExtensionProcessBoundary(
763 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17764 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38765}
766
[email protected]763ec4ca2011-04-29 15:48:12767std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
768 const std::string& alias_name) {
769 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
770}
771
[email protected]b80f68432011-05-02 17:22:30772void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
773 CommandLine* command_line, int child_process_id) {
774#if defined(USE_LINUX_BREAKPAD)
775 if (IsCrashReporterEnabled()) {
776 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
777 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
778 }
779#elif defined(OS_MACOSX)
780 if (IsCrashReporterEnabled()) {
781 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
782 child_process_logging::GetClientId());
783 }
784#endif // OS_MACOSX
785
[email protected]f1933792011-06-14 00:49:34786 if (logging::DialogsAreSuppressed())
787 command_line->AppendSwitch(switches::kNoErrorDialogs);
788
[email protected]b80f68432011-05-02 17:22:30789 std::string process_type =
790 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17791 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52792 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30793 FilePath user_data_dir =
794 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
795 if (!user_data_dir.empty())
796 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
797#if defined(OS_CHROMEOS)
798 const std::string& login_profile =
799 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
800 if (!login_profile.empty())
801 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
802#endif
803
[email protected]f3b1a082011-11-18 00:34:30804 content::RenderProcessHost* process =
805 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37806 if (process) {
807 Profile* profile = Profile::FromBrowserContext(
808 process->GetBrowserContext());
809 extensions::ProcessMap* process_map =
810 profile->GetExtensionService()->process_map();
811 if (process_map && process_map->Contains(process->GetID()))
812 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30813
[email protected]a8d851f82011-12-21 00:32:37814 PrefService* prefs = profile->GetPrefs();
815 // Currently this pref is only registered if applied via a policy.
816 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
817 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
818 // Turn this policy into a command line switch.
819 command_line->AppendSwitch(switches::kDisable3DAPIs);
820 }
[email protected]718eab62011-10-05 21:16:52821
[email protected]a8d851f82011-12-21 00:32:37822 // Disable client-side phishing detection in the renderer if it is
823 // disabled in the Profile preferences or the browser process.
824 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
825 !g_browser_process->safe_browsing_detection_service()) {
826 command_line->AppendSwitch(
827 switches::kDisableClientSidePhishingDetection);
828 }
[email protected]0045b0f42012-07-26 11:52:08829
830 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:21831 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]47c7ec82012-01-18 03:29:21832 }
[email protected]4287a3d2011-06-13 23:56:51833
[email protected]47c7ec82012-01-18 03:29:21834 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51835 static const char* const kSwitchNames[] = {
836 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48837 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51838 switches::kAllowScriptingGallery,
839 switches::kAppsCheckoutURL,
840 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31841 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51842 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10843 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50844 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53845 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09846 switches::kDisableInBrowserThumbnailing,
[email protected]4287a3d2011-06-13 23:56:51847 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21848 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13849 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51850 switches::kEnableCrxlessWebApps,
851 switches::kEnableExperimentalExtensionApis,
[email protected]5e92282f2012-08-17 08:11:57852 switches::kEnableFramelessConstrainedDialogs,
[email protected]4287a3d2011-06-13 23:56:51853 switches::kEnableIPCFuzzing,
854 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05855 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48856 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:05857 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:51858 switches::kEnableWatchdog,
859 switches::kExperimentalSpellcheckerFeatures,
860 switches::kMemoryProfiling,
861 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37862 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:37863 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51864 switches::kPpapiFlashArgs,
865 switches::kPpapiFlashInProcess,
866 switches::kPpapiFlashPath,
867 switches::kPpapiFlashVersion,
868 switches::kProfilingAtStart,
869 switches::kProfilingFile,
870 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37871 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51872 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38873 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51874 };
875
876 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
877 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17878 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38879 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35880 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38881 switches::kEnableExperimentalExtensionApis,
882 switches::kWhitelistedExtensionID,
883 };
884
885 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
886 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51887 } else if (process_type == switches::kPluginProcess) {
888 static const char* const kSwitchNames[] = {
889 #if defined(OS_CHROMEOS)
890 switches::kLoginProfile,
891 #endif
892 switches::kMemoryProfiling,
893 switches::kSilentDumpOnDCHECK,
894 switches::kUserDataDir,
895 };
896
897 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
898 arraysize(kSwitchNames));
899 } else if (process_type == switches::kZygoteProcess) {
900 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51901 switches::kUserDataDir, // Make logs go to the right file.
902 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50903 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13904 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51905 switches::kPpapiFlashInProcess,
906 switches::kPpapiFlashPath,
907 switches::kPpapiFlashVersion,
908 };
909
910 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
911 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11912 } else if (process_type == switches::kGpuProcess) {
913 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
914 // because GPU is expected to be unreliable.
915 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
916 !command_line->HasSwitch(switches::kDisableBreakpad))
917 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30918 }
[email protected]6f08af82011-09-15 01:19:03919
920 // The command line switch kEnableBenchmarking needs to be specified along
921 // with the kEnableStatsTable switch to ensure that the stats table global
922 // is initialized correctly.
923 if (command_line->HasSwitch(switches::kEnableBenchmarking))
924 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30925}
926
927std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:43928 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
929 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:30930 return g_browser_process->GetApplicationLocale();
931}
932
[email protected]597a867b2011-11-18 18:31:20933std::string ChromeContentBrowserClient::GetAcceptLangs(
934 content::BrowserContext* context) {
935 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37936 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08937}
938
[email protected]9ec0f452012-05-31 15:58:53939gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22940 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:53941 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:08942}
943
[email protected]a2176792011-05-08 19:30:49944bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09945 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19946 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20947 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20949 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05950 return io_data->GetCookieSettings()->
951 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49952}
953
[email protected]ed24fad2011-05-10 22:44:01954bool ChromeContentBrowserClient::AllowGetCookie(
955 const GURL& url,
956 const GURL& first_party,
957 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20958 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01959 int render_process_id,
960 int render_view_id) {
961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20962 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05963 bool allow = io_data->GetCookieSettings()->
964 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01965
[email protected]8093a542011-05-13 07:29:32966 BrowserThread::PostTask(
967 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03968 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43969 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01970 return allow;
971}
972
973bool ChromeContentBrowserClient::AllowSetCookie(
974 const GURL& url,
975 const GURL& first_party,
976 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20977 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01978 int render_process_id,
979 int render_view_id,
980 net::CookieOptions* options) {
981 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20982 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05983 CookieSettings* cookie_settings = io_data->GetCookieSettings();
984 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
985
[email protected]8093a542011-05-13 07:29:32986 BrowserThread::PostTask(
987 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03988 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43989 render_view_id, url, first_party, cookie_line, *options,
990 !allow));
[email protected]ed24fad2011-05-10 22:44:01991 return allow;
992}
993
[email protected]ea628e32012-08-02 21:50:16994bool ChromeContentBrowserClient::AllowPluginLocalDataAccess(
995 const GURL& document_url,
996 const GURL& plugin_url,
997 content::ResourceContext* context) {
998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
999 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1000 return io_data->GetCookieSettings()->IsReadingCookieAllowed(document_url,
1001 plugin_url);
1002}
1003
1004bool ChromeContentBrowserClient::AllowPluginLocalDataSessionOnly(
1005 const GURL& url,
1006 content::ResourceContext* context) {
1007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1008 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1009 return io_data->GetCookieSettings()->IsCookieSessionOnly(url);
1010}
1011
[email protected]d5a19162011-06-30 18:51:541012bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201013 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541014 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201015 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431016 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1017 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261018
[email protected]bf510ed2012-06-05 08:31:431019 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1020 // Could we even support per-origin settings?
1021 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541022}
1023
[email protected]5c5a88e2011-11-12 00:45:351024bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351025 const GURL& url,
1026 const string16& name,
1027 const string16& display_name,
1028 unsigned long estimated_size,
[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 database 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::WebDatabaseAccessed,
1042 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351043 }
1044
1045 return allow;
1046}
1047
1048bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351049 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201050 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481051 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351052 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201053 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351054 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1055 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1056
[email protected]62151052012-02-01 18:40:481057 // Record access to file system for potential display in UI.
1058 std::vector<std::pair<int, int> >::const_iterator i;
1059 for (i = render_views.begin(); i != render_views.end(); ++i) {
1060 BrowserThread::PostTask(
1061 BrowserThread::UI, FROM_HERE,
1062 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1063 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351064 }
1065
1066 return allow;
1067}
1068
[email protected]7c5ff9a2012-03-02 07:42:491069bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1070 const GURL& url,
1071 const string16& name,
1072 content::ResourceContext* context,
1073 const std::vector<std::pair<int, int> >& render_views) {
1074 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1075 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1076 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1077 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1078
1079 // Record access to IndexedDB for potential display in UI.
1080 std::vector<std::pair<int, int> >::const_iterator i;
1081 for (i = render_views.begin(); i != render_views.end(); ++i) {
1082 BrowserThread::PostTask(
1083 BrowserThread::UI, FROM_HERE,
1084 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1085 i->first, i->second, url, name, !allow));
1086 }
1087
1088 return allow;
1089}
1090
[email protected]6133f922011-07-01 21:34:341091net::URLRequestContext*
1092ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201093 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341094 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1095 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201096 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341097 return io_data->extensions_request_context();
1098 }
1099
1100 return NULL;
1101}
1102
[email protected]317f96c92011-05-31 06:53:411103QuotaPermissionContext*
1104ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1105 return new ChromeQuotaPermissionContext();
1106}
1107
[email protected]a0ce3282011-08-19 20:49:521108void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421109 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421110}
1111
[email protected]a0ce3282011-08-19 20:49:521112void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521113 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521114}
1115
[email protected]848dd042011-06-04 18:24:031116void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171117 int render_process_id,
1118 int render_view_id,
1119 int cert_error,
1120 const net::SSLInfo& ssl_info,
1121 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031122 bool overridable,
[email protected]d9be47702012-05-16 03:41:221123 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171124 const base::Callback<void(bool)>& callback,
1125 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411126 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131127 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171128 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411129 if (!tab) {
1130 NOTREACHED();
1131 return;
1132 }
1133 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501134 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301135 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091136 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411137 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171138 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411139 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171140 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411141 return;
1142 }
1143 }
1144
1145 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221146 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1147 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031148}
1149
[email protected]c99c442e2011-08-24 11:37:301150void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451151 int render_process_id,
1152 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401153 const net::HttpNetworkSession* network_session,
1154 net::SSLCertRequestInfo* cert_request_info,
1155 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131156 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451157 render_process_id, render_view_id);
1158 if (!tab) {
1159 NOTREACHED();
1160 return;
1161 }
1162
[email protected]6786bf402011-12-03 15:19:451163 GURL requesting_url("https://" + cert_request_info->host_and_port);
1164 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1165 << cert_request_info->host_and_port;
1166
[email protected]627e0512011-12-21 22:55:301167 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451168 scoped_ptr<Value> filter(
1169 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1170 requesting_url,
1171 requesting_url,
1172 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1173 std::string(), NULL));
1174
1175 if (filter.get()) {
1176 // Try to automatically select a client certificate.
1177 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1178 DictionaryValue* filter_dict =
1179 static_cast<DictionaryValue*>(filter.get());
1180
1181 const std::vector<scoped_refptr<net::X509Certificate> >&
1182 all_client_certs = cert_request_info->client_certs;
1183 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1184 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1185 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401186 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451187 return;
1188 }
1189 }
1190 } else {
1191 NOTREACHED();
1192 }
1193 }
1194
[email protected]871dc682012-06-11 19:35:331195 TabContents* tab_contents = TabContents::FromWebContents(tab);
1196 if (!tab_contents) {
1197 // If there is no TabContents for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451198 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141199 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401200 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451201 return;
1202 }
[email protected]871dc682012-06-11 19:35:331203 tab_contents->ssl_helper()->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401204 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451205}
1206
1207void ChromeContentBrowserClient::AddNewCertificate(
1208 net::URLRequest* request,
1209 net::X509Certificate* cert,
1210 int render_process_id,
1211 int render_view_id) {
1212 // The handler will run the UI and delete itself when it's finished.
1213 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1214}
1215
[email protected]dc73a7b2012-03-25 15:27:181216content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1217 return MediaInternals::GetInstance();
1218}
1219
[email protected]941623e2011-06-07 23:06:041220void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1221 const GURL& source_origin,
1222 int callback_context,
1223 int render_process_id,
1224 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111225#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1227 WebContents* contents =
1228 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1229 if (!contents) {
[email protected]941623e2011-06-07 23:06:041230 NOTREACHED();
1231 return;
1232 }
1233
[email protected]d0d9c3ee2012-06-19 03:07:021234 // Skip showing the infobar if the request comes from an extension, and that
1235 // extension has the 'notify' permission. (If the extension does not have the
1236 // permission, the user will still be prompted.)
1237 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
1238 ExtensionService* service = profile->GetExtensionService();
1239 const Extension* extension = !service ? NULL :
1240 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1241 source_origin));
1242 if (extension &&
[email protected]c2e66e12012-06-27 06:27:061243 extension->HasAPIPermission(APIPermission::kNotification)) {
[email protected]d0d9c3ee2012-06-19 03:07:021244 RenderViewHost* rvh =
1245 RenderViewHost::FromID(render_process_id, render_view_id);
1246 if (rvh)
1247 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1248 return;
1249 }
1250
1251 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371252 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021253 notifications->RequestPermission(source_origin, render_process_id,
1254 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111255#else
1256 NOTIMPLEMENTED();
1257#endif
[email protected]941623e2011-06-07 23:06:041258}
1259
1260WebKit::WebNotificationPresenter::Permission
1261 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021262 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201263 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021264 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111265#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201267 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021268 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1269 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061270 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041271 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041272
1273 // Fall back to the regular notification preferences, which works on an
1274 // origin basis.
1275 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371276 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041277 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111278#else
1279 return WebKit::WebNotificationPresenter::PermissionAllowed;
1280#endif
[email protected]941623e2011-06-07 23:06:041281}
1282
1283void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171284 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041285 int render_process_id,
1286 int render_view_id,
1287 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111288#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041289 RenderViewHost* rvh = RenderViewHost::FromID(
1290 render_process_id, render_view_id);
1291 if (!rvh) {
1292 NOTREACHED();
1293 return;
1294 }
1295
[email protected]9f76c1e2012-03-05 15:15:581296 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301297 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041298 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371299 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041300 service->ShowDesktopNotification(
1301 params, render_process_id, render_view_id,
1302 worker ? DesktopNotificationService::WorkerNotification :
1303 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111304#else
1305 NOTIMPLEMENTED();
1306#endif
[email protected]941623e2011-06-07 23:06:041307}
1308
1309void ChromeContentBrowserClient::CancelDesktopNotification(
1310 int render_process_id,
1311 int render_view_id,
1312 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111313#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041314 RenderViewHost* rvh = RenderViewHost::FromID(
1315 render_process_id, render_view_id);
1316 if (!rvh) {
1317 NOTREACHED();
1318 return;
1319 }
1320
[email protected]9f76c1e2012-03-05 15:15:581321 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301322 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041323 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371324 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041325 service->CancelDesktopNotification(
1326 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111327#else
1328 NOTIMPLEMENTED();
1329#endif
[email protected]941623e2011-06-07 23:06:041330}
1331
[email protected]9f3fba52011-06-08 20:37:191332bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351333 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021334 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191335 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201336 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011337 int render_process_id,
1338 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011340
1341 *no_javascript_access = false;
1342
[email protected]9f3fba52011-06-08 20:37:191343 // If the opener is trying to create a background window but doesn't have
1344 // the appropriate permission, fail the attempt.
1345 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201346 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531347 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1348
[email protected]03b6d552012-03-29 04:03:011349 if (!map->SecurityOriginHasAPIPermission(
1350 source_origin,
1351 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061352 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011353 return false;
1354 }
1355
[email protected]7b54ca02012-03-02 18:06:531356 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1357 // return a recently installed Extension even if this CanCreateWindow call
1358 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011359 // because the permission check above would have caused an early return
1360 // already. We must use the full URL to find hosted apps, though, and not
1361 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531362 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351363 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531364 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011365 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191366 }
1367 return true;
1368}
1369
1370std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201371 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1373 // Check if it's an extension-created worker, in which case we want to use
1374 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201375 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191376 const Extension* extension =
1377 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1378 return extension ? extension->name() : std::string();
1379}
1380
[email protected]99907362012-01-11 05:41:401381void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1382 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171383}
1384
[email protected]c52b2892012-03-07 11:01:021385content::SpeechRecognitionManagerDelegate*
1386 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321387#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021388 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321389#else
1390 return NULL;
1391#endif
[email protected]66cfec62012-02-24 17:57:511392}
1393
[email protected]ae6e9912011-07-27 01:18:281394net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1395 return g_browser_process->net_log();
1396}
1397
[email protected]32538d92011-08-25 00:09:231398AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1399 return new ChromeAccessTokenStore();
1400}
1401
[email protected]dbae6b02011-06-29 23:51:411402bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1403 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1404 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1405}
1406
[email protected]64d69de42012-02-06 00:19:541407void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321408 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061409 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581410 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061411 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061412
[email protected]f3986f82012-01-03 20:00:061413 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541414 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061415 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541416 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061417 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541418 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061419 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541420 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061421 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541422 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061423 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541424 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061425
[email protected]64d69de42012-02-06 00:19:541426 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401427 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541428 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401429 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541430 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401431 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541432 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401433 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061434
[email protected]ddf72142012-05-22 04:52:401435 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061436
[email protected]64d69de42012-02-06 00:19:541437 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401438 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541439 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061440 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541441 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061442 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1443 const DictionaryValue* inspector_settings =
1444 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1445 if (inspector_settings) {
1446 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1447 iter != inspector_settings->end_keys(); ++iter) {
1448 std::string value;
1449 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541450 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061451 std::make_pair(*iter, value));
1452 }
1453 }
[email protected]64d69de42012-02-06 00:19:541454 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061455
[email protected]ddf72142012-05-22 04:52:401456 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541457 web_prefs->javascript_enabled = false;
1458 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1459 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401460 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541461 web_prefs->plugins_enabled = false;
1462 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1463 web_prefs->java_enabled = false;
1464 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401465 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061466
[email protected]64d69de42012-02-06 00:19:541467 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1468 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061469
[email protected]64d69de42012-02-06 00:19:541470 web_prefs->memory_info_enabled =
1471 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1472 web_prefs->allow_displaying_insecure_content =
1473 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1474 web_prefs->allow_running_insecure_content =
1475 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081476 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061477
[email protected]64d69de42012-02-06 00:19:541478 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151479 UserStyleSheetWatcher* user_style_sheet_watcher =
1480 UserStyleSheetWatcherFactory::GetForProfile(profile);
1481 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541482 web_prefs->user_style_sheet_enabled = true;
1483 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151484 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541485 } else {
1486 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061487 }
1488
[email protected]b7e44ff2012-02-16 03:37:341489 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101490#if defined(OS_MACOSX)
1491 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1492 // Mac so it uses NSSpellChecker in the background.
1493 false;
1494#else
1495 !CommandLine::ForCurrentProcess()->
1496 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1497#endif
[email protected]b7e44ff2012-02-16 03:37:341498 web_prefs->unified_textchecker_enabled =
1499 web_prefs->asynchronous_spell_checking_enabled ||
1500 CommandLine::ForCurrentProcess()->
1501 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571502
[email protected]64d69de42012-02-06 00:19:541503 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061504 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541505 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061506 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541507 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061508 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1509
1510 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541511 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061512 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541513 web_prefs->default_encoding);
1514 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401515 prefs->ClearPref(prefs::kDefaultCharset);
1516 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061517 }
[email protected]64d69de42012-02-06 00:19:541518 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061519
[email protected]299d7f12012-05-23 05:31:151520 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1521 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061522 ExtensionService* service = profile->GetExtensionService();
1523 if (service) {
1524 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581525 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061526 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151527 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061528 }
1529
[email protected]b7c4f032012-08-07 16:38:561530 if (content::IsForceCompositingModeEnabled())
[email protected]4abe58d2012-06-08 03:09:091531 web_prefs->force_compositing_mode = true;
1532
[email protected]299d7f12012-05-23 05:31:151533 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541534 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151535 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061536 // Disable all kinds of acceleration for background pages.
1537 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541538 web_prefs->force_compositing_mode = false;
1539 web_prefs->accelerated_compositing_enabled = false;
1540 web_prefs->accelerated_2d_canvas_enabled = false;
1541 web_prefs->accelerated_video_enabled = false;
1542 web_prefs->accelerated_painting_enabled = false;
1543 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061544 }
[email protected]2e21fe292012-03-02 22:52:321545
1546#if defined(FILE_MANAGER_EXTENSION)
1547 // Override the default of suppressing HW compositing for WebUI pages for the
1548 // file manager, which is implemented using WebUI but wants HW acceleration
1549 // for video decode & render.
1550 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1551 web_prefs->accelerated_compositing_enabled = true;
1552 web_prefs->accelerated_2d_canvas_enabled = true;
1553 }
1554#endif
[email protected]181a95ee2011-07-12 19:26:361555}
1556
1557void ChromeContentBrowserClient::UpdateInspectorSetting(
1558 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061559 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581560 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061561 DictionaryPrefUpdate update(
1562 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1563 prefs::kWebKitInspectorSettings);
1564 DictionaryValue* inspector_settings = update.Get();
1565 inspector_settings->SetWithoutPathExpansion(key,
1566 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361567}
1568
1569void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061570 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581571 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061572 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1573 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361574}
1575
[email protected]b8148ac2011-07-13 22:03:251576void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1577 BrowserURLHandler* handler) {
1578 // Add the default URL handlers.
1579 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1580 BrowserURLHandler::null_handler());
1581 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1582 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1583
[email protected]b3adbd02011-11-30 22:23:271584 // about: handler. Must come before chrome: handler, since it will
1585 // rewrite about: urls to chrome: URLs and then expect chrome: to
1586 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251587 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1588 BrowserURLHandler::null_handler());
1589 // chrome: & friends.
1590 handler->AddHandlerPair(&HandleWebUI,
1591 BrowserURLHandler::null_handler());
1592}
1593
1594void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371595 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581596 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471597 BrowsingDataRemover* remover =
1598 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551599 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1600 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251601 // BrowsingDataRemover takes care of deleting itself when done.
1602}
1603
1604void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371605 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581606 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471607 BrowsingDataRemover* remover =
1608 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231609 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551610 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251611 // BrowsingDataRemover takes care of deleting itself when done.
1612}
1613
[email protected]e1d16eb92011-08-18 23:19:321614FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1615 return download_util::GetDefaultDownloadDirectory();
1616}
1617
[email protected]c9b6eb62011-10-18 20:49:391618std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1619 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1620}
1621
[email protected]38cd8f7f2012-06-15 22:06:071622bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]a658d452012-03-02 12:45:291623 content::BrowserContext* browser_context, const GURL& url) {
1624 if (!url.is_valid())
1625 return false;
1626
1627 std::string host = url.host();
[email protected]92444942012-06-16 09:05:281628 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host))
[email protected]a658d452012-03-02 12:45:291629 return true;
1630
[email protected]9a5940d2012-04-27 19:16:231631 Profile* profile = Profile::FromBrowserContext(browser_context);
1632 const Extension* extension = NULL;
1633 if (profile && profile->GetExtensionService()) {
1634 extension = profile->GetExtensionService()->extensions()->
1635 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1636 }
1637
[email protected]f237c0f2012-03-10 07:49:101638 // Need to check this now and not on construction because otherwise it won't
1639 // work with browser_tests.
1640 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1641 std::string allowed_list =
1642 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231643 if (allowed_list == "*") {
1644 // The wildcard allows socket API only for packaged and platform apps.
1645 return extension &&
1646 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1647 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1648 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101649 StringTokenizer t(allowed_list, ",");
1650 while (t.GetNext()) {
1651 if (t.token() == host)
1652 return true;
1653 }
1654 }
1655
[email protected]a658d452012-03-02 12:45:291656 if (!extension)
1657 return false;
1658
[email protected]c2e66e12012-06-27 06:27:061659 if (extension->HasAPIPermission(APIPermission::kSocket))
[email protected]a658d452012-03-02 12:45:291660 return true;
1661
1662 return false;
[email protected]e461da2f2012-02-16 19:06:401663}
1664
[email protected]38cd8f7f2012-06-15 22:06:071665bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1666 return CommandLine::ForCurrentProcess()->HasSwitch(
1667 switches::kPpapiFlashInProcess);
1668}
1669
[email protected]e60c0232011-11-11 19:56:351670#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181671void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1672 const CommandLine& command_line,
1673 base::GlobalDescriptors::Mapping* mappings) {
1674 int crash_signal_fd = GetCrashSignalFD(command_line);
1675 if (crash_signal_fd >= 0) {
1676 mappings->push_back(std::pair<base::GlobalDescriptors::Key, int>(
1677 kCrashDumpSignal, crash_signal_fd));
[email protected]9dbfff12011-07-01 19:37:071678 }
[email protected]b80f68432011-05-02 17:22:301679}
[email protected]e60c0232011-11-11 19:56:351680#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301681
[email protected]4a65826d2011-08-25 16:04:011682#if defined(OS_WIN)
1683const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1684 return chrome::kBrowserResourcesDll;
1685}
1686#endif
1687
[email protected]37a72af2011-06-13 05:42:011688#if defined(USE_NSS)
1689crypto::CryptoModuleBlockingPasswordDelegate*
1690 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1691 const GURL& url) {
1692 return browser::NewCryptoModuleBlockingDialogDelegate(
1693 browser::kCryptoModulePasswordKeygen, url.host());
1694}
1695#endif
1696
[email protected]e9a32a52012-06-14 23:32:431697void ChromeContentBrowserClient::SetApplicationLocale(
1698 const std::string& locale) {
1699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1700
1701 // This object is guaranteed to outlive all threads so we don't have to
1702 // worry about the lack of refcounting and can just post as Unretained.
1703 //
1704 // The common case is that this function is called early in Chrome startup
1705 // before any threads are created (it will also be called later if the user
1706 // changes the pref). In this case, there will be no threads created and
1707 // posting will fail. When there are no threads, we can just set the string
1708 // without worrying about threadsafety.
1709 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1710 base::Bind(
1711 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1712 base::Unretained(this), locale)))
1713 io_thread_application_locale_ = locale;
1714}
1715
1716void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1717 const std::string& locale) {
1718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1719 io_thread_application_locale_ = locale;
1720}
1721
[email protected]d1198fd2012-08-13 22:50:191722std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension(
1723 content::BrowserContext* browser_context, const Extension* extension) {
1724 // In chrome, we use the extension ID as the partition ID. This works well
1725 // because the extension ID fits the partition ID pattern and currently only
1726 // apps can designate that storage should be isolated.
1727 //
1728 // If |extension| is NULL, then the default, empty string, partition id is
1729 // used.
1730 std::string partition_id;
1731 if (extension && extension->is_storage_isolated()) {
1732 partition_id = extension->id();
1733 }
1734
1735 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1736 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1737 return partition_id;
1738}
1739
1740
[email protected]d977f9c2011-03-14 16:10:261741} // namespace chrome