blob: 1a178107f830921c4348f2aafd5b7e1e7d14fa60 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4718#include "chrome/browser/browsing_data/browsing_data_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1220#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0321#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4122#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5623#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0524#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4525#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3226#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0827#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3228#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1629#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0630#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0431#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0834#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2535#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0636#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4937#include "chrome/browser/extensions/message_handler.h"
[email protected]32538d92011-08-25 00:09:2338#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1239#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0840#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1841#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2842#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0443#include "chrome/browser/notifications/desktop_notification_service.h"
44#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4345#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4246#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0648#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4149#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5050#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0751#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4152#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1453#include "chrome/browser/printing/printing_message_filter.h"
54#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3255#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0656#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1457#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3358#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3859#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]8aa7a412011-11-07 12:33:4260#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0262#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4663#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4564#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0365#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5266#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4567#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5468#include "chrome/browser/toolkit_extra_parts.h"
[email protected]b5d73422012-06-02 23:46:4469#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]871dc682012-06-11 19:35:3370#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]863f70a2012-01-27 02:05:5071#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0672#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1573#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5374#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3075#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0176#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3077#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0478#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3879#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4480#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3481#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1282#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3883#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0984#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4385#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3086#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3887#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3188#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5989#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3090#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3391#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0592#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3393#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1994#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1095#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4396#include "content/public/common/child_process_host.h"
[email protected]b7c4f032012-08-07 16:38:5697#include "content/public/common/compositor_util.h"
[email protected]a1733df2012-06-22 11:24:1898#include "content/public/common/content_descriptors.h"
[email protected]c9b6eb62011-10-18 20:49:3999#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23100#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:40101#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34102#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06103#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38104#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39105#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08106#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36107#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04108#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26109
[email protected]b48c9182011-10-26 18:03:30110#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38111#include "chrome/browser/chrome_browser_main_win.h"
112#elif defined(OS_MACOSX)
113#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56114#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30115#elif defined(OS_CHROMEOS)
116#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49117#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26118#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30119#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09120#elif defined(OS_ANDROID)
121#include "chrome/browser/chrome_browser_main_android.h"
[email protected]b48c9182011-10-26 18:03:30122#elif defined(OS_POSIX)
123#include "chrome/browser/chrome_browser_main_posix.h"
124#endif
125
[email protected]6653c192012-04-10 22:52:44126#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30127#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12128#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43129#endif
[email protected]b80f68432011-05-02 17:22:30130
[email protected]1e87df32012-09-12 04:53:19131#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
132#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
133#endif
134
[email protected]37a72af2011-06-13 05:42:01135#if defined(USE_NSS)
136#include "chrome/browser/ui/crypto_module_password_dialog.h"
137#endif
138
[email protected]c7abd422012-09-25 00:20:08139using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47140using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39141using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31142using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59143using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08144using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00145using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11146using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33147using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13148using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06149using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34150using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25151using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39152
[email protected]c5dbef02011-05-13 05:06:09153namespace {
154
[email protected]e461da2f2012-02-16 19:06:40155const char* kPredefinedAllowedSocketOrigins[] = {
156 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18157 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45158 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
159 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
160 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
161 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35162 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54163 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
164 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
165 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
166 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
167 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
168 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38169 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
170 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514
[email protected]e461da2f2012-02-16 19:06:40171};
172
[email protected]b8148ac2011-07-13 22:03:25173// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42174bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50175 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
176 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25177 return false;
178
[email protected]fe69558d2012-03-12 11:34:49179#if defined(OS_CHROMEOS)
180 // Special case : in ChromeOS in Guest mode bookmarks and history are
181 // disabled for security reasons. New tab page explains the reasons, so
182 // we redirect user to new tab page.
183 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
184 if (url->SchemeIs(chrome::kChromeUIScheme) &&
185 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
186 url->DomainIs(chrome::kChromeUIHistoryHost))) {
187 // Rewrite with new tab URL
188 *url = GURL(chrome::kChromeUINewTabURL);
189 }
190 }
191#endif
192
[email protected]b8148ac2011-07-13 22:03:25193 // Special case the new tab page. In older versions of Chrome, the new tab
194 // page was hosted at chrome-internal:<blah>. This might be in people's saved
195 // sessions or bookmarks, so we say any URL with that scheme triggers the new
196 // tab page.
197 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
198 // Rewrite it with the proper new tab URL.
199 *url = GURL(chrome::kChromeUINewTabURL);
200 }
201
202 return true;
203}
204
[email protected]8d3132f62011-10-12 07:13:42205// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
206// below. Extension, and isolated apps require different privileges to be
207// granted to their RenderProcessHosts. This classification allows us to make
208// sure URLs are served by hosts with the right set of privileges.
209enum RenderProcessHostPrivilege {
210 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45211 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42212 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45213 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42214};
215
216RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
217 const GURL& url,
218 ExtensionService* service) {
219 // Default to a normal renderer cause it is lower privileged. This should only
220 // occur if the URL on a site instance is either malformed, or uninitialized.
221 // If it is malformed, then there is no need for better privileges anyways.
222 // If it is uninitialized, but eventually settles on being an a scheme other
223 // than normal webrenderer, the navigation logic will correct us out of band
224 // anyways.
225 if (!url.is_valid())
226 return PRIV_NORMAL;
227
228 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44229 const Extension* extension =
230 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45231 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42232 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45233 if (extension && extension->is_hosted_app())
234 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42235
236 return PRIV_EXTENSION;
237 }
238
239 return PRIV_NORMAL;
240}
241
242RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30243 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46244 extensions::ProcessMap* process_map,
245 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46246 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30247 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46248 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21249 return PRIV_NORMAL;
250
[email protected]6f371442011-11-09 06:45:46251 for (std::set<std::string>::iterator iter = extension_ids.begin();
252 iter != extension_ids.end(); ++iter) {
253 const Extension* extension = service->GetExtensionById(*iter, false);
254 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42255 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45256 if (extension && extension->is_hosted_app())
257 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42258 }
259
[email protected]676f6ab2011-10-19 20:23:21260 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42261}
262
[email protected]6786bf402011-12-03 15:19:45263bool CertMatchesFilter(const net::X509Certificate& cert,
264 const base::DictionaryValue& filter) {
265 // TODO(markusheintz): This is the minimal required filter implementation.
266 // Implement a better matcher.
267
268 // An empty filter matches any client certificate since no requirements are
269 // specified at all.
270 if (filter.empty())
271 return true;
272
273 std::string common_name;
274 if (filter.GetString("ISSUER.CN", &common_name) &&
275 (cert.issuer().common_name == common_name)) {
276 return true;
277 }
278 return false;
279}
280
[email protected]f3986f82012-01-03 20:00:06281// Fills |map| with the per-script font prefs under path |map_name|.
282void FillFontFamilyMap(const PrefService* prefs,
283 const char* map_name,
284 WebPreferences::ScriptFontFamilyMap* map) {
285 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
286 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
287 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
288 std::string font_family = prefs->GetString(pref_name.c_str());
289 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32290 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06291 }
292}
293
[email protected]a1733df2012-06-22 11:24:18294#if defined(OS_POSIX) && !defined(OS_MACOSX)
295int GetCrashSignalFD(const CommandLine& command_line) {
296 if (command_line.HasSwitch(switches::kExtensionProcess)) {
297 ExtensionCrashHandlerHostLinux* crash_handler =
298 ExtensionCrashHandlerHostLinux::GetInstance();
299 return crash_handler->GetDeathSignalSocket();
300 }
301
302 std::string process_type =
303 command_line.GetSwitchValueASCII(switches::kProcessType);
304
305 if (process_type == switches::kRendererProcess)
306 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
307
308 if (process_type == switches::kPluginProcess)
309 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
310
311 if (process_type == switches::kPpapiPluginProcess)
312 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
313
314 if (process_type == switches::kGpuProcess)
315 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
316
317 return -1;
318}
319#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
320
[email protected]9dbfff12011-07-01 19:37:07321} // namespace
[email protected]c5dbef02011-05-13 05:06:09322
[email protected]d977f9c2011-03-14 16:10:26323namespace chrome {
324
[email protected]e461da2f2012-02-16 19:06:40325ChromeContentBrowserClient::ChromeContentBrowserClient() {
326 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
327 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40328}
329
330ChromeContentBrowserClient::~ChromeContentBrowserClient() {
331}
332
[email protected]bca18382012-06-25 19:15:23333// static
334void ChromeContentBrowserClient::RegisterUserPrefs(PrefService* prefs) {
335 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
336 false,
337 PrefService::UNSYNCABLE_PREF);
338 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
339 true,
340 PrefService::UNSYNCABLE_PREF);
341 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
342 false,
343 PrefService::UNSYNCABLE_PREF);
344}
345
[email protected]50462bf02011-11-21 19:13:31346content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
347 const content::MainFunctionParams& parameters) {
348 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30349 // Construct the Main browser parts based on the OS type.
350#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31351 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04352#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31353 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30354#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31355 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26356#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31357 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14358#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09359 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30360#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31361 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04362#else
[email protected]b48c9182011-10-26 18:03:30363 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31364 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30365#endif
366
[email protected]c7480942011-11-08 19:18:27367 // Construct additional browser parts. Stages are called in the order in
368 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22369#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41370 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04371#endif
[email protected]c7480942011-11-08 19:18:27372
373#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41374 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27375#endif
376
[email protected]dc04be7c2012-03-15 23:57:49377#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41378 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49379#endif
380
[email protected]e050ef142012-03-21 01:04:24381#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41382 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24383#endif
384
[email protected]50462bf02011-11-21 19:13:31385 return main_parts;
[email protected]f967b722011-09-07 00:58:04386}
387
[email protected]38b098f2012-03-14 21:11:57388content::WebContentsView*
389 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57390 WebContents* web_contents,
391 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57392 return NULL;
393}
394
[email protected]d7c7c98a2012-07-12 21:27:44395std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
396 content::BrowserContext* browser_context,
397 int child_process_id) {
[email protected]d1198fd2012-08-13 22:50:19398 const Extension* extension = NULL;
[email protected]d7c7c98a2012-07-12 21:27:44399 Profile* profile = Profile::FromBrowserContext(browser_context);
400 ExtensionService* extension_service =
401 extensions::ExtensionSystem::Get(profile)->extension_service();
402 if (extension_service) {
[email protected]d1198fd2012-08-13 22:50:19403 extension = extension_service->GetInstalledAppForRenderer(
404 child_process_id);
[email protected]d7c7c98a2012-07-12 21:27:44405 }
[email protected]d1198fd2012-08-13 22:50:19406
407 return GetStoragePartitionIdForExtension(browser_context, extension);
408}
409
[email protected]e94bbcb2012-09-07 05:33:57410std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19411 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57412 const GURL& site) {
[email protected]d1198fd2012-08-13 22:50:19413 const Extension* extension = NULL;
414 Profile* profile = Profile::FromBrowserContext(browser_context);
415 ExtensionService* extension_service =
416 extensions::ExtensionSystem::Get(profile)->extension_service();
417 if (extension_service) {
418 extension = extension_service->extensions()->
[email protected]e94bbcb2012-09-07 05:33:57419 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]d1198fd2012-08-13 22:50:19420 }
421
422 return GetStoragePartitionIdForExtension(browser_context, extension);
423}
424
425bool ChromeContentBrowserClient::IsValidStoragePartitionId(
426 content::BrowserContext* browser_context,
427 const std::string& partition_id) {
428 // The default ID is empty which is always allowed.
429 if (partition_id.empty())
430 return true;
431
432 // If it isn't empty, then it must belong to an extension of some sort. Parse
433 // out the extension ID and make sure it is still installed.
434 Profile* profile = Profile::FromBrowserContext(browser_context);
435 ExtensionService* extension_service =
436 extensions::ExtensionSystem::Get(profile)->extension_service();
437 if (!extension_service) {
438 // No extension service means no storage partitions in Chrome.
439 return false;
440 }
441
442 // See if we can find an extension. The |partition_id| is the extension ID so
443 // no parsing needed to be done.
444 return extension_service->GetExtensionById(partition_id, false) != NULL;
[email protected]d7c7c98a2012-07-12 21:27:44445}
446
[email protected]38b098f2012-03-14 21:11:57447content::WebContentsViewDelegate*
448 ChromeContentBrowserClient::GetWebContentsViewDelegate(
449 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27450 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32451}
452
[email protected]f364d1392011-04-08 21:03:10453void ChromeContentBrowserClient::RenderViewHostCreated(
454 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46455
[email protected]9f76c1e2012-03-05 15:15:58456 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46457 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02458 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46459
460 new ChromeRenderViewHostObserver(render_view_host,
461 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49462 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26463}
464
[email protected]f3b1a082011-11-18 00:34:30465void ChromeContentBrowserClient::RenderProcessHostCreated(
466 content::RenderProcessHost* host) {
467 int id = host->GetID();
468 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
469 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02470 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30471 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02472#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08473 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03474#endif
[email protected]f3b1a082011-11-18 00:34:30475 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02476 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30477 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56478#if defined(OS_MACOSX)
479 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
480#endif
[email protected]f3b1a082011-11-18 00:34:30481 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03482 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07483 host->GetChannel()->AddFilter(
484 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38485
[email protected]2ccf45c2011-08-19 23:35:50486 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
487 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07488
489 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56490
491 RendererContentSettingRules rules;
492 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
493 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14494}
495
[email protected]e0ada9c2012-03-20 03:54:43496void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
497 content::BrowserChildProcessHost* host) {
498 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
499}
500
[email protected]863f70a2012-01-27 02:05:50501content::WebUIControllerFactory*
502 ChromeContentBrowserClient::GetWebUIControllerFactory() {
503 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56504}
505
[email protected]3d7474ff2011-07-27 17:47:37506GURL ChromeContentBrowserClient::GetEffectiveURL(
507 content::BrowserContext* browser_context, const GURL& url) {
508 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08509 // Get the effective URL for the given actual URL. If the URL is part of an
510 // installed app, the effective URL is an extension URL with the ID of that
511 // extension as the host. This has the effect of grouping apps together in
512 // a common SiteInstance.
513 if (!profile || !profile->GetExtensionService())
514 return url;
515
[email protected]615d88f2011-12-13 01:47:44516 const Extension* extension = profile->GetExtensionService()->extensions()->
517 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08518 if (!extension)
519 return url;
520
[email protected]15877ca2011-11-18 22:40:52521 // Bookmark apps do not use the hosted app process model, and should be
522 // treated as normal URLs.
523 if (extension->from_bookmark())
524 return url;
525
[email protected]36fb2c7c2011-04-04 15:49:08526 // If the URL is part of an extension's web extent, convert it to an
527 // extension URL.
528 return extension->GetResourceURL(url.path());
529}
530
[email protected]056ad2a2011-07-12 02:13:55531bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37532 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55533 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52534 // Because we expect to use the effective URL, URLs for hosted apps (apart
535 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55536 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
537 return false;
538
[email protected]3d7474ff2011-07-27 17:47:37539 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55540 if (!profile || !profile->GetExtensionService())
541 return false;
542
[email protected]615d88f2011-12-13 01:47:44543 const Extension* extension = profile->GetExtensionService()->extensions()->
544 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55545 if (!extension)
546 return false;
547
548 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53549 // permission, or that does not allow JavaScript access to the background
550 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55551 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53552 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06553 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53554 !extension->allow_background_js_access()) {
555 return false;
556 }
557 }
[email protected]056ad2a2011-07-12 02:13:55558
[email protected]7b54ca02012-03-02 18:06:53559 // Hosted apps that have script access to their background page must use
560 // process per site, since all instances can make synchronous calls to the
561 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55562 return true;
563}
564
[email protected]46fb9442011-12-09 17:57:47565bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
566 return ProfileIOData::IsHandledURL(url);
567}
568
[email protected]2a5221b2011-09-27 23:07:31569bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30570 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31571 const GURL& site_url) {
572 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30573 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42574 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46575 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31576
[email protected]ffa97602011-11-17 17:55:52577 // Don't allow the Task Manager to share a process with anything else.
578 // Otherwise it can affect the renderers it is observing.
579 // Note: we could create another RenderProcessHostPrivilege bucket for
580 // this to allow multiple chrome://tasks instances to share, but that's
581 // a very unlikely case without serious consequences.
582 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
583 return false;
584
[email protected]8d3132f62011-10-12 07:13:42585 // These may be NULL during tests. In that case, just assume any site can
586 // share any host.
[email protected]6f371442011-11-09 06:45:46587 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31588 return true;
589
[email protected]a8c269a2011-10-25 20:17:22590 // Experimental:
591 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
592 // to share a renderer process. (We could allow pages from the same site or
593 // extensions of the same type to share, if we knew what the given process
594 // was dedicated to. Allowing no sharing is simpler for now.) This may
595 // cause resource exhaustion issues if too many sites are open at once.
596 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
597 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
598 return false;
599
[email protected]eec0b33c2011-12-05 22:09:45600 // Otherwise, just make sure the process privilege matches the privilege
601 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57602 RenderProcessHostPrivilege privilege_required =
603 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45604 return GetProcessPrivilege(process_host, process_map, service) ==
605 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31606}
607
[email protected]76411f412012-02-22 18:56:06608// This function is trying to limit the amount of processes used by extensions
609// with background pages. It uses a globally set percentage of processes to
610// run such extensions and if the limit is exceeded, it returns true, to
611// indicate to the content module to group extensions together.
612bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
613 content::BrowserContext* browser_context, const GURL& url) {
614 // It has to be a valid URL for us to check for an extension.
615 if (!url.is_valid())
616 return false;
617
618 Profile* profile = Profile::FromBrowserContext(browser_context);
619 ExtensionService* service = profile->GetExtensionService();
620 if (!service)
621 return false;
622
623 // We have to have a valid extension with background page to proceed.
624 const Extension* extension =
625 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
626 if (!extension)
627 return false;
628 if (!extension->has_background_page())
629 return false;
630
631 std::set<int> process_ids;
632 size_t max_process_count =
633 content::RenderProcessHost::GetMaxRendererProcessCount();
634
635 // Go through all profiles to ensure we have total count of extension
636 // processes containing background pages, otherwise one profile can
637 // starve the other.
638 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
639 GetLoadedProfiles();
640 for (size_t i = 0; i < profiles.size(); ++i) {
641 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32642 for (ExtensionProcessManager::const_iterator iter =
643 epm->background_hosts().begin();
644 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13645 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32646 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06647 }
648 }
649
650 if (process_ids.size() >
651 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
652 return true;
653 }
654
655 return false;
656}
657
[email protected]6f371442011-11-09 06:45:46658void ChromeContentBrowserClient::SiteInstanceGotProcess(
659 SiteInstance* site_instance) {
660 CHECK(site_instance->HasProcess());
661
662 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02663 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46664 ExtensionService* service = profile->GetExtensionService();
665 if (!service)
666 return;
667
668 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44669 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33670 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46671 if (!extension)
672 return;
673
[email protected]6bc04fd82011-12-04 02:29:35674 service->process_map()->Insert(extension->id(),
675 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33676 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46677 BrowserThread::PostTask(
678 BrowserThread::IO, FROM_HERE,
679 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59680 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46681 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35682 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33683 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46684}
685
686void ChromeContentBrowserClient::SiteInstanceDeleting(
687 SiteInstance* site_instance) {
688 if (!site_instance->HasProcess())
689 return;
690
691 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02692 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46693 ExtensionService* service = profile->GetExtensionService();
694 if (!service)
695 return;
696
697 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44698 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33699 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46700 if (!extension)
701 return;
702
[email protected]6bc04fd82011-12-04 02:29:35703 service->process_map()->Remove(extension->id(),
704 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33705 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46706 BrowserThread::PostTask(
707 BrowserThread::IO, FROM_HERE,
708 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59709 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46710 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35711 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33712 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46713}
714
[email protected]f05763972012-06-06 18:17:26715bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08716 const GURL& current_url,
717 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26718 if (current_url.is_empty()) {
719 // Always choose a new process when navigating to extension URLs. The
720 // process grouping logic will combine all of a given extension's pages
721 // into the same process.
722 if (new_url.SchemeIs(chrome::kExtensionScheme))
723 return true;
[email protected]e3daf3c2011-10-05 21:17:08724
[email protected]f05763972012-06-06 18:17:26725 return false;
726 }
727
728 // Also, we must switch if one is an extension and the other is not the exact
729 // same extension.
730 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
731 new_url.SchemeIs(chrome::kExtensionScheme)) {
732 if (current_url.GetOrigin() != new_url.GetOrigin())
733 return true;
734 }
735
736 return false;
[email protected]e3daf3c2011-10-05 21:17:08737}
738
[email protected]395045c2012-05-22 15:04:38739bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
740 content::ResourceContext* resource_context, const GURL& current_url,
741 const GURL& new_url) {
742 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
743 return extensions::CrossesExtensionProcessBoundary(
744 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17745 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38746}
747
[email protected]763ec4ca2011-04-29 15:48:12748std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
749 const std::string& alias_name) {
750 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
751}
752
[email protected]b80f68432011-05-02 17:22:30753void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
754 CommandLine* command_line, int child_process_id) {
755#if defined(USE_LINUX_BREAKPAD)
756 if (IsCrashReporterEnabled()) {
757 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
758 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
759 }
760#elif defined(OS_MACOSX)
761 if (IsCrashReporterEnabled()) {
762 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
763 child_process_logging::GetClientId());
764 }
765#endif // OS_MACOSX
766
[email protected]f1933792011-06-14 00:49:34767 if (logging::DialogsAreSuppressed())
768 command_line->AppendSwitch(switches::kNoErrorDialogs);
769
[email protected]b80f68432011-05-02 17:22:30770 std::string process_type =
771 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17772 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52773 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30774 FilePath user_data_dir =
775 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
776 if (!user_data_dir.empty())
777 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
778#if defined(OS_CHROMEOS)
779 const std::string& login_profile =
780 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
781 if (!login_profile.empty())
782 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
783#endif
784
[email protected]f3b1a082011-11-18 00:34:30785 content::RenderProcessHost* process =
786 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37787 if (process) {
788 Profile* profile = Profile::FromBrowserContext(
789 process->GetBrowserContext());
790 extensions::ProcessMap* process_map =
791 profile->GetExtensionService()->process_map();
792 if (process_map && process_map->Contains(process->GetID()))
793 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30794
[email protected]a8d851f82011-12-21 00:32:37795 PrefService* prefs = profile->GetPrefs();
796 // Currently this pref is only registered if applied via a policy.
797 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
798 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
799 // Turn this policy into a command line switch.
800 command_line->AppendSwitch(switches::kDisable3DAPIs);
801 }
[email protected]718eab62011-10-05 21:16:52802
[email protected]a8d851f82011-12-21 00:32:37803 // Disable client-side phishing detection in the renderer if it is
804 // disabled in the Profile preferences or the browser process.
805 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
806 !g_browser_process->safe_browsing_detection_service()) {
807 command_line->AppendSwitch(
808 switches::kDisableClientSidePhishingDetection);
809 }
[email protected]0045b0f42012-07-26 11:52:08810
811 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:21812 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]47c7ec82012-01-18 03:29:21813 }
[email protected]4287a3d2011-06-13 23:56:51814
[email protected]47c7ec82012-01-18 03:29:21815 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51816 static const char* const kSwitchNames[] = {
817 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48818 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51819 switches::kAllowScriptingGallery,
820 switches::kAppsCheckoutURL,
821 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31822 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51823 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10824 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50825 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53826 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09827 switches::kDisableInBrowserThumbnailing,
[email protected]b0553c7e2012-09-19 21:36:11828 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:51829 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21830 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13831 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51832 switches::kEnableCrxlessWebApps,
833 switches::kEnableExperimentalExtensionApis,
[email protected]5e92282f2012-08-17 08:11:57834 switches::kEnableFramelessConstrainedDialogs,
[email protected]4287a3d2011-06-13 23:56:51835 switches::kEnableIPCFuzzing,
836 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05837 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48838 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:05839 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:51840 switches::kEnableWatchdog,
841 switches::kExperimentalSpellcheckerFeatures,
842 switches::kMemoryProfiling,
843 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37844 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:37845 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51846 switches::kPpapiFlashArgs,
847 switches::kPpapiFlashInProcess,
848 switches::kPpapiFlashPath,
849 switches::kPpapiFlashVersion,
850 switches::kProfilingAtStart,
851 switches::kProfilingFile,
852 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37853 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51854 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38855 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51856 };
857
858 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
859 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17860 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38861 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35862 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38863 switches::kEnableExperimentalExtensionApis,
864 switches::kWhitelistedExtensionID,
865 };
866
867 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
868 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51869 } else if (process_type == switches::kPluginProcess) {
870 static const char* const kSwitchNames[] = {
871 #if defined(OS_CHROMEOS)
872 switches::kLoginProfile,
873 #endif
874 switches::kMemoryProfiling,
875 switches::kSilentDumpOnDCHECK,
876 switches::kUserDataDir,
877 };
878
879 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
880 arraysize(kSwitchNames));
881 } else if (process_type == switches::kZygoteProcess) {
882 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51883 switches::kUserDataDir, // Make logs go to the right file.
884 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50885 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13886 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51887 switches::kPpapiFlashInProcess,
888 switches::kPpapiFlashPath,
889 switches::kPpapiFlashVersion,
890 };
891
892 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
893 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11894 } else if (process_type == switches::kGpuProcess) {
895 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
896 // because GPU is expected to be unreliable.
897 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
898 !command_line->HasSwitch(switches::kDisableBreakpad))
899 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30900 }
[email protected]6f08af82011-09-15 01:19:03901
902 // The command line switch kEnableBenchmarking needs to be specified along
903 // with the kEnableStatsTable switch to ensure that the stats table global
904 // is initialized correctly.
905 if (command_line->HasSwitch(switches::kEnableBenchmarking))
906 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30907}
908
909std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:43910 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
911 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:30912 return g_browser_process->GetApplicationLocale();
913}
914
[email protected]597a867b2011-11-18 18:31:20915std::string ChromeContentBrowserClient::GetAcceptLangs(
916 content::BrowserContext* context) {
917 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37918 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08919}
920
[email protected]9ec0f452012-05-31 15:58:53921gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22922 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:53923 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:08924}
925
[email protected]a2176792011-05-08 19:30:49926bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09927 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19928 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20929 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32930 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20931 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05932 return io_data->GetCookieSettings()->
933 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49934}
935
[email protected]ed24fad2011-05-10 22:44:01936bool ChromeContentBrowserClient::AllowGetCookie(
937 const GURL& url,
938 const GURL& first_party,
939 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20940 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01941 int render_process_id,
942 int render_view_id) {
943 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20944 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05945 bool allow = io_data->GetCookieSettings()->
946 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01947
[email protected]8093a542011-05-13 07:29:32948 BrowserThread::PostTask(
949 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03950 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43951 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01952 return allow;
953}
954
955bool ChromeContentBrowserClient::AllowSetCookie(
956 const GURL& url,
957 const GURL& first_party,
958 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20959 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01960 int render_process_id,
961 int render_view_id,
962 net::CookieOptions* options) {
963 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20964 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05965 CookieSettings* cookie_settings = io_data->GetCookieSettings();
966 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
967
[email protected]8093a542011-05-13 07:29:32968 BrowserThread::PostTask(
969 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03970 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43971 render_view_id, url, first_party, cookie_line, *options,
972 !allow));
[email protected]ed24fad2011-05-10 22:44:01973 return allow;
974}
975
[email protected]ea628e32012-08-02 21:50:16976bool ChromeContentBrowserClient::AllowPluginLocalDataAccess(
977 const GURL& document_url,
978 const GURL& plugin_url,
979 content::ResourceContext* context) {
980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
981 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
982 return io_data->GetCookieSettings()->IsReadingCookieAllowed(document_url,
983 plugin_url);
984}
985
986bool ChromeContentBrowserClient::AllowPluginLocalDataSessionOnly(
987 const GURL& url,
988 content::ResourceContext* context) {
989 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
990 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
991 return io_data->GetCookieSettings()->IsCookieSessionOnly(url);
992}
993
[email protected]d5a19162011-06-30 18:51:54994bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20995 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54996 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20997 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:43998 CookieSettings* cookie_settings = io_data->GetCookieSettings();
999 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261000
[email protected]bf510ed2012-06-05 08:31:431001 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1002 // Could we even support per-origin settings?
1003 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541004}
1005
[email protected]5c5a88e2011-11-12 00:45:351006bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351007 const GURL& url,
1008 const string16& name,
1009 const string16& display_name,
1010 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201011 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481012 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351013 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201014 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351015 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1016 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1017
[email protected]62151052012-02-01 18:40:481018 // Record access to database for potential display in UI.
1019 std::vector<std::pair<int, int> >::const_iterator i;
1020 for (i = render_views.begin(); i != render_views.end(); ++i) {
1021 BrowserThread::PostTask(
1022 BrowserThread::UI, FROM_HERE,
1023 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1024 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351025 }
1026
1027 return allow;
1028}
1029
1030bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351031 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201032 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481033 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351034 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201035 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351036 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1037 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1038
[email protected]62151052012-02-01 18:40:481039 // Record access to file system for potential display in UI.
1040 std::vector<std::pair<int, int> >::const_iterator i;
1041 for (i = render_views.begin(); i != render_views.end(); ++i) {
1042 BrowserThread::PostTask(
1043 BrowserThread::UI, FROM_HERE,
1044 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1045 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351046 }
1047
1048 return allow;
1049}
1050
[email protected]7c5ff9a2012-03-02 07:42:491051bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1052 const GURL& url,
1053 const string16& name,
1054 content::ResourceContext* context,
1055 const std::vector<std::pair<int, int> >& render_views) {
1056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1057 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1058 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1059 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1060
1061 // Record access to IndexedDB for potential display in UI.
1062 std::vector<std::pair<int, int> >::const_iterator i;
1063 for (i = render_views.begin(); i != render_views.end(); ++i) {
1064 BrowserThread::PostTask(
1065 BrowserThread::UI, FROM_HERE,
1066 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1067 i->first, i->second, url, name, !allow));
1068 }
1069
1070 return allow;
1071}
1072
[email protected]6133f922011-07-01 21:34:341073net::URLRequestContext*
1074ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201075 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341076 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1077 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201078 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341079 return io_data->extensions_request_context();
1080 }
1081
1082 return NULL;
1083}
1084
[email protected]317f96c92011-05-31 06:53:411085QuotaPermissionContext*
1086ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1087 return new ChromeQuotaPermissionContext();
1088}
1089
[email protected]a0ce3282011-08-19 20:49:521090void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421091 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421092}
1093
[email protected]a0ce3282011-08-19 20:49:521094void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521095 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521096}
1097
[email protected]848dd042011-06-04 18:24:031098void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171099 int render_process_id,
1100 int render_view_id,
1101 int cert_error,
1102 const net::SSLInfo& ssl_info,
1103 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031104 bool overridable,
[email protected]d9be47702012-05-16 03:41:221105 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171106 const base::Callback<void(bool)>& callback,
1107 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411108 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131109 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171110 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411111 if (!tab) {
1112 NOTREACHED();
1113 return;
1114 }
1115 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501116 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301117 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091118 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411119 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171120 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411121 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171122 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411123 return;
1124 }
1125 }
1126
[email protected]1e87df32012-09-12 04:53:191127#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231128 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1129 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1130 if (captive_portal_tab_helper)
1131 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191132#endif
1133
[email protected]f9034cf2011-07-21 12:43:411134 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221135 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1136 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031137}
1138
[email protected]c99c442e2011-08-24 11:37:301139void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451140 int render_process_id,
1141 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401142 const net::HttpNetworkSession* network_session,
1143 net::SSLCertRequestInfo* cert_request_info,
1144 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131145 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451146 render_process_id, render_view_id);
1147 if (!tab) {
1148 NOTREACHED();
1149 return;
1150 }
1151
[email protected]6786bf402011-12-03 15:19:451152 GURL requesting_url("https://" + cert_request_info->host_and_port);
1153 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1154 << cert_request_info->host_and_port;
1155
[email protected]627e0512011-12-21 22:55:301156 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451157 scoped_ptr<Value> filter(
1158 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1159 requesting_url,
1160 requesting_url,
1161 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1162 std::string(), NULL));
1163
1164 if (filter.get()) {
1165 // Try to automatically select a client certificate.
1166 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1167 DictionaryValue* filter_dict =
1168 static_cast<DictionaryValue*>(filter.get());
1169
1170 const std::vector<scoped_refptr<net::X509Certificate> >&
1171 all_client_certs = cert_request_info->client_certs;
1172 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1173 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1174 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401175 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451176 return;
1177 }
1178 }
1179 } else {
1180 NOTREACHED();
1181 }
1182 }
1183
[email protected]11feec322012-09-18 03:58:521184 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1185 if (!ssl_tab_helper) {
1186 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451187 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141188 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401189 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451190 return;
1191 }
[email protected]11feec322012-09-18 03:58:521192 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401193 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451194}
1195
1196void ChromeContentBrowserClient::AddNewCertificate(
1197 net::URLRequest* request,
1198 net::X509Certificate* cert,
1199 int render_process_id,
1200 int render_view_id) {
1201 // The handler will run the UI and delete itself when it's finished.
1202 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1203}
1204
[email protected]dc73a7b2012-03-25 15:27:181205content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1206 return MediaInternals::GetInstance();
1207}
1208
[email protected]941623e2011-06-07 23:06:041209void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1210 const GURL& source_origin,
1211 int callback_context,
1212 int render_process_id,
1213 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111214#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1216 WebContents* contents =
1217 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1218 if (!contents) {
[email protected]941623e2011-06-07 23:06:041219 NOTREACHED();
1220 return;
1221 }
1222
[email protected]d0d9c3ee2012-06-19 03:07:021223 // Skip showing the infobar if the request comes from an extension, and that
1224 // extension has the 'notify' permission. (If the extension does not have the
1225 // permission, the user will still be prompted.)
1226 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
1227 ExtensionService* service = profile->GetExtensionService();
1228 const Extension* extension = !service ? NULL :
1229 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1230 source_origin));
1231 if (extension &&
[email protected]c2e66e12012-06-27 06:27:061232 extension->HasAPIPermission(APIPermission::kNotification)) {
[email protected]d0d9c3ee2012-06-19 03:07:021233 RenderViewHost* rvh =
1234 RenderViewHost::FromID(render_process_id, render_view_id);
1235 if (rvh)
1236 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1237 return;
1238 }
1239
1240 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371241 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021242 notifications->RequestPermission(source_origin, render_process_id,
1243 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111244#else
1245 NOTIMPLEMENTED();
1246#endif
[email protected]941623e2011-06-07 23:06:041247}
1248
1249WebKit::WebNotificationPresenter::Permission
1250 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021251 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201252 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021253 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111254#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201256 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021257 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1258 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061259 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041260 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041261
1262 // Fall back to the regular notification preferences, which works on an
1263 // origin basis.
1264 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371265 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041266 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111267#else
1268 return WebKit::WebNotificationPresenter::PermissionAllowed;
1269#endif
[email protected]941623e2011-06-07 23:06:041270}
1271
1272void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171273 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041274 int render_process_id,
1275 int render_view_id,
1276 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111277#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041278 RenderViewHost* rvh = RenderViewHost::FromID(
1279 render_process_id, render_view_id);
1280 if (!rvh) {
1281 NOTREACHED();
1282 return;
1283 }
1284
[email protected]9f76c1e2012-03-05 15:15:581285 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301286 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041287 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371288 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041289 service->ShowDesktopNotification(
1290 params, render_process_id, render_view_id,
1291 worker ? DesktopNotificationService::WorkerNotification :
1292 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111293#else
1294 NOTIMPLEMENTED();
1295#endif
[email protected]941623e2011-06-07 23:06:041296}
1297
1298void ChromeContentBrowserClient::CancelDesktopNotification(
1299 int render_process_id,
1300 int render_view_id,
1301 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111302#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041303 RenderViewHost* rvh = RenderViewHost::FromID(
1304 render_process_id, render_view_id);
1305 if (!rvh) {
1306 NOTREACHED();
1307 return;
1308 }
1309
[email protected]9f76c1e2012-03-05 15:15:581310 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301311 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041312 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371313 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041314 service->CancelDesktopNotification(
1315 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111316#else
1317 NOTIMPLEMENTED();
1318#endif
[email protected]941623e2011-06-07 23:06:041319}
1320
[email protected]9f3fba52011-06-08 20:37:191321bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351322 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021323 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191324 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201325 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011326 int render_process_id,
1327 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011329
1330 *no_javascript_access = false;
1331
[email protected]9f3fba52011-06-08 20:37:191332 // If the opener is trying to create a background window but doesn't have
1333 // the appropriate permission, fail the attempt.
1334 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201335 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531336 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1337
[email protected]03b6d552012-03-29 04:03:011338 if (!map->SecurityOriginHasAPIPermission(
1339 source_origin,
1340 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061341 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011342 return false;
1343 }
1344
[email protected]7b54ca02012-03-02 18:06:531345 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1346 // return a recently installed Extension even if this CanCreateWindow call
1347 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011348 // because the permission check above would have caused an early return
1349 // already. We must use the full URL to find hosted apps, though, and not
1350 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531351 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351352 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531353 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011354 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191355 }
1356 return true;
1357}
1358
1359std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201360 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1362 // Check if it's an extension-created worker, in which case we want to use
1363 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201364 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191365 const Extension* extension =
1366 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1367 return extension ? extension->name() : std::string();
1368}
1369
[email protected]99907362012-01-11 05:41:401370void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1371 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171372}
1373
[email protected]c52b2892012-03-07 11:01:021374content::SpeechRecognitionManagerDelegate*
1375 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321376#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021377 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321378#else
1379 return NULL;
1380#endif
[email protected]66cfec62012-02-24 17:57:511381}
1382
[email protected]ae6e9912011-07-27 01:18:281383net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1384 return g_browser_process->net_log();
1385}
1386
[email protected]32538d92011-08-25 00:09:231387AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1388 return new ChromeAccessTokenStore();
1389}
1390
[email protected]dbae6b02011-06-29 23:51:411391bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1392 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1393 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1394}
1395
[email protected]64d69de42012-02-06 00:19:541396void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321397 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061398 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581399 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061400 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061401
[email protected]f3986f82012-01-03 20:00:061402 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541403 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061404 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541405 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061406 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541407 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061408 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541409 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061410 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541411 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061412 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541413 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061414
[email protected]64d69de42012-02-06 00:19:541415 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401416 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541417 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401418 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541419 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401420 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541421 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401422 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061423
[email protected]ddf72142012-05-22 04:52:401424 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061425
[email protected]64d69de42012-02-06 00:19:541426 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401427 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541428 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061429 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541430 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061431 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1432 const DictionaryValue* inspector_settings =
1433 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1434 if (inspector_settings) {
1435 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1436 iter != inspector_settings->end_keys(); ++iter) {
1437 std::string value;
1438 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541439 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061440 std::make_pair(*iter, value));
1441 }
1442 }
[email protected]64d69de42012-02-06 00:19:541443 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061444
[email protected]ddf72142012-05-22 04:52:401445 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541446 web_prefs->javascript_enabled = false;
1447 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1448 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401449 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541450 web_prefs->plugins_enabled = false;
1451 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1452 web_prefs->java_enabled = false;
1453 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401454 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061455
[email protected]64d69de42012-02-06 00:19:541456 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1457 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061458
[email protected]64d69de42012-02-06 00:19:541459 web_prefs->memory_info_enabled =
1460 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1461 web_prefs->allow_displaying_insecure_content =
1462 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1463 web_prefs->allow_running_insecure_content =
1464 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081465 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061466
[email protected]64d69de42012-02-06 00:19:541467 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151468 UserStyleSheetWatcher* user_style_sheet_watcher =
1469 UserStyleSheetWatcherFactory::GetForProfile(profile);
1470 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541471 web_prefs->user_style_sheet_enabled = true;
1472 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151473 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541474 } else {
1475 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061476 }
1477
[email protected]b7e44ff2012-02-16 03:37:341478 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101479#if defined(OS_MACOSX)
1480 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1481 // Mac so it uses NSSpellChecker in the background.
1482 false;
1483#else
1484 !CommandLine::ForCurrentProcess()->
1485 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1486#endif
[email protected]b7e44ff2012-02-16 03:37:341487 web_prefs->unified_textchecker_enabled =
1488 web_prefs->asynchronous_spell_checking_enabled ||
1489 CommandLine::ForCurrentProcess()->
1490 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571491
[email protected]64d69de42012-02-06 00:19:541492 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061493 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541494 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061495 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541496 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061497 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1498
1499 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541500 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061501 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541502 web_prefs->default_encoding);
1503 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401504 prefs->ClearPref(prefs::kDefaultCharset);
1505 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061506 }
[email protected]64d69de42012-02-06 00:19:541507 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061508
[email protected]299d7f12012-05-23 05:31:151509 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1510 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061511 ExtensionService* service = profile->GetExtensionService();
1512 if (service) {
1513 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581514 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061515 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151516 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061517 }
1518
[email protected]b7c4f032012-08-07 16:38:561519 if (content::IsForceCompositingModeEnabled())
[email protected]4abe58d2012-06-08 03:09:091520 web_prefs->force_compositing_mode = true;
1521
[email protected]299d7f12012-05-23 05:31:151522 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541523 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151524 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061525 // Disable all kinds of acceleration for background pages.
1526 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541527 web_prefs->force_compositing_mode = false;
1528 web_prefs->accelerated_compositing_enabled = false;
1529 web_prefs->accelerated_2d_canvas_enabled = false;
1530 web_prefs->accelerated_video_enabled = false;
1531 web_prefs->accelerated_painting_enabled = false;
1532 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061533 }
[email protected]2e21fe292012-03-02 22:52:321534
1535#if defined(FILE_MANAGER_EXTENSION)
1536 // Override the default of suppressing HW compositing for WebUI pages for the
1537 // file manager, which is implemented using WebUI but wants HW acceleration
1538 // for video decode & render.
1539 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1540 web_prefs->accelerated_compositing_enabled = true;
1541 web_prefs->accelerated_2d_canvas_enabled = true;
1542 }
1543#endif
[email protected]181a95ee2011-07-12 19:26:361544}
1545
1546void ChromeContentBrowserClient::UpdateInspectorSetting(
1547 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061548 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581549 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061550 DictionaryPrefUpdate update(
1551 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1552 prefs::kWebKitInspectorSettings);
1553 DictionaryValue* inspector_settings = update.Get();
1554 inspector_settings->SetWithoutPathExpansion(key,
1555 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361556}
1557
1558void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[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 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1562 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361563}
1564
[email protected]b8148ac2011-07-13 22:03:251565void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1566 BrowserURLHandler* handler) {
1567 // Add the default URL handlers.
1568 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1569 BrowserURLHandler::null_handler());
1570 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1571 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1572
[email protected]b3adbd02011-11-30 22:23:271573 // about: handler. Must come before chrome: handler, since it will
1574 // rewrite about: urls to chrome: URLs and then expect chrome: to
1575 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251576 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1577 BrowserURLHandler::null_handler());
1578 // chrome: & friends.
[email protected]0d441b72012-09-19 20:34:421579 handler->AddHandlerPair(&HandleWebUI,
1580 BrowserURLHandler::null_handler());
[email protected]b8148ac2011-07-13 22:03:251581}
1582
1583void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371584 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581585 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471586 BrowsingDataRemover* remover =
1587 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551588 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1589 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251590 // BrowsingDataRemover takes care of deleting itself when done.
1591}
1592
1593void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371594 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581595 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471596 BrowsingDataRemover* remover =
1597 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231598 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551599 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251600 // BrowsingDataRemover takes care of deleting itself when done.
1601}
1602
[email protected]e1d16eb92011-08-18 23:19:321603FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1604 return download_util::GetDefaultDownloadDirectory();
1605}
1606
[email protected]c9b6eb62011-10-18 20:49:391607std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1608 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1609}
1610
[email protected]b7631cc2012-09-15 05:08:381611void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1612 content::BrowserPpapiHost* browser_host) {
1613 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1614 scoped_ptr<ppapi::host::HostFactory>(
1615 new ChromeBrowserPepperHostFactory(browser_host)));
1616}
1617
[email protected]38cd8f7f2012-06-15 22:06:071618bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]a658d452012-03-02 12:45:291619 content::BrowserContext* browser_context, const GURL& url) {
1620 if (!url.is_valid())
1621 return false;
1622
1623 std::string host = url.host();
[email protected]92444942012-06-16 09:05:281624 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host))
[email protected]a658d452012-03-02 12:45:291625 return true;
1626
[email protected]9a5940d2012-04-27 19:16:231627 Profile* profile = Profile::FromBrowserContext(browser_context);
1628 const Extension* extension = NULL;
1629 if (profile && profile->GetExtensionService()) {
1630 extension = profile->GetExtensionService()->extensions()->
1631 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1632 }
1633
[email protected]f237c0f2012-03-10 07:49:101634 // Need to check this now and not on construction because otherwise it won't
1635 // work with browser_tests.
1636 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1637 std::string allowed_list =
1638 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231639 if (allowed_list == "*") {
1640 // The wildcard allows socket API only for packaged and platform apps.
1641 return extension &&
1642 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1643 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1644 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101645 StringTokenizer t(allowed_list, ",");
1646 while (t.GetNext()) {
1647 if (t.token() == host)
1648 return true;
1649 }
1650 }
1651
[email protected]a658d452012-03-02 12:45:291652 if (!extension)
1653 return false;
1654
[email protected]c2e66e12012-06-27 06:27:061655 if (extension->HasAPIPermission(APIPermission::kSocket))
[email protected]a658d452012-03-02 12:45:291656 return true;
1657
1658 return false;
[email protected]e461da2f2012-02-16 19:06:401659}
1660
[email protected]38cd8f7f2012-06-15 22:06:071661bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1662 return CommandLine::ForCurrentProcess()->HasSwitch(
1663 switches::kPpapiFlashInProcess);
1664}
1665
[email protected]e60c0232011-11-11 19:56:351666#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181667void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1668 const CommandLine& command_line,
[email protected]c7abd422012-09-25 00:20:081669 std::vector<FileDescriptorInfo>* mappings) {
[email protected]a1733df2012-06-22 11:24:181670 int crash_signal_fd = GetCrashSignalFD(command_line);
1671 if (crash_signal_fd >= 0) {
[email protected]c7abd422012-09-25 00:20:081672 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
1673 FileDescriptor(crash_signal_fd,
1674 false)));
[email protected]9dbfff12011-07-01 19:37:071675 }
[email protected]b80f68432011-05-02 17:22:301676}
[email protected]e60c0232011-11-11 19:56:351677#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301678
[email protected]4a65826d2011-08-25 16:04:011679#if defined(OS_WIN)
1680const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1681 return chrome::kBrowserResourcesDll;
1682}
1683#endif
1684
[email protected]37a72af2011-06-13 05:42:011685#if defined(USE_NSS)
1686crypto::CryptoModuleBlockingPasswordDelegate*
1687 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1688 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:291689 return chrome::NewCryptoModuleBlockingDialogDelegate(
1690 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:011691}
1692#endif
1693
[email protected]e9a32a52012-06-14 23:32:431694void ChromeContentBrowserClient::SetApplicationLocale(
1695 const std::string& locale) {
1696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1697
1698 // This object is guaranteed to outlive all threads so we don't have to
1699 // worry about the lack of refcounting and can just post as Unretained.
1700 //
1701 // The common case is that this function is called early in Chrome startup
1702 // before any threads are created (it will also be called later if the user
1703 // changes the pref). In this case, there will be no threads created and
1704 // posting will fail. When there are no threads, we can just set the string
1705 // without worrying about threadsafety.
1706 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1707 base::Bind(
1708 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1709 base::Unretained(this), locale)))
1710 io_thread_application_locale_ = locale;
1711}
1712
1713void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1714 const std::string& locale) {
1715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1716 io_thread_application_locale_ = locale;
1717}
1718
[email protected]d1198fd2012-08-13 22:50:191719std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension(
1720 content::BrowserContext* browser_context, const Extension* extension) {
1721 // In chrome, we use the extension ID as the partition ID. This works well
1722 // because the extension ID fits the partition ID pattern and currently only
1723 // apps can designate that storage should be isolated.
1724 //
1725 // If |extension| is NULL, then the default, empty string, partition id is
1726 // used.
1727 std::string partition_id;
1728 if (extension && extension->is_storage_isolated()) {
1729 partition_id = extension->id();
1730 }
1731
1732 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1733 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1734 return partition_id;
1735}
1736
1737
[email protected]d977f9c2011-03-14 16:10:261738} // namespace chrome