blob: d45f4df51a35ffe34f69b4c7e5f045158492940d [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]4abe58d2012-06-08 03:09:0940#include "chrome/browser/gpu_util.h"
[email protected]117b6b42012-02-29 09:11:0841#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1842#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2843#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0444#include "chrome/browser/notifications/desktop_notification_service.h"
45#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4346#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4247#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1248#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0649#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4150#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5051#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0752#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4153#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1454#include "chrome/browser/printing/printing_message_filter.h"
55#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3256#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0657#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3359#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4260#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0262#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4663#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4564#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0365#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4566#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
67#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5468#include "chrome/browser/toolkit_extra_parts.h"
[email protected]b5d73422012-06-02 23:46:4469#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]871dc682012-06-11 19:35:3370#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]863f70a2012-01-27 02:05:5071#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0672#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1573#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5374#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3075#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0176#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3077#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0478#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3879#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4480#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3481#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1282#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3883#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0984#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4385#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3086#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3187#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5988#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3089#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3390#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0591#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3392#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1993#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1094#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4395#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:1896#include "content/public/common/content_descriptors.h"
[email protected]c9b6eb62011-10-18 20:49:3997#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:2398#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4099#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34100#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06101#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:39102#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08103#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36104#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04105#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26106
[email protected]b48c9182011-10-26 18:03:30107#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38108#include "chrome/browser/chrome_browser_main_win.h"
109#elif defined(OS_MACOSX)
110#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56111#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30112#elif defined(OS_CHROMEOS)
113#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49114#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26115#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30116#include "chrome/browser/chrome_browser_main_linux.h"
117#elif defined(OS_POSIX)
118#include "chrome/browser/chrome_browser_main_posix.h"
119#endif
120
[email protected]6653c192012-04-10 22:52:44121#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30122#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12123#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43124#endif
[email protected]b80f68432011-05-02 17:22:30125
[email protected]37a72af2011-06-13 05:42:01126#if defined(USE_NSS)
127#include "chrome/browser/ui/crypto_module_password_dialog.h"
128#endif
129
[email protected]c8c77182011-12-21 15:04:47130using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39131using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31132using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59133using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00134using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11135using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33136using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13137using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06138using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34139using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25140using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39141
[email protected]c5dbef02011-05-13 05:06:09142namespace {
143
[email protected]e461da2f2012-02-16 19:06:40144const char* kPredefinedAllowedSocketOrigins[] = {
145 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18146 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45147 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
148 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
149 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
150 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35151 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54152 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
153 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
154 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
155 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
156 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
157 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
158 "ghbfeebgmiidnnmeobbbaiamklmpbpii" // see crbug.com/134099
[email protected]e461da2f2012-02-16 19:06:40159};
160
[email protected]b8148ac2011-07-13 22:03:25161// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42162bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50163 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
164 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25165 return false;
166
[email protected]fe69558d2012-03-12 11:34:49167#if defined(OS_CHROMEOS)
168 // Special case : in ChromeOS in Guest mode bookmarks and history are
169 // disabled for security reasons. New tab page explains the reasons, so
170 // we redirect user to new tab page.
171 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
172 if (url->SchemeIs(chrome::kChromeUIScheme) &&
173 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
174 url->DomainIs(chrome::kChromeUIHistoryHost))) {
175 // Rewrite with new tab URL
176 *url = GURL(chrome::kChromeUINewTabURL);
177 }
178 }
179#endif
180
[email protected]b8148ac2011-07-13 22:03:25181 // Special case the new tab page. In older versions of Chrome, the new tab
182 // page was hosted at chrome-internal:<blah>. This might be in people's saved
183 // sessions or bookmarks, so we say any URL with that scheme triggers the new
184 // tab page.
185 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
186 // Rewrite it with the proper new tab URL.
187 *url = GURL(chrome::kChromeUINewTabURL);
188 }
189
190 return true;
191}
192
[email protected]8d3132f62011-10-12 07:13:42193// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
194// below. Extension, and isolated apps require different privileges to be
195// granted to their RenderProcessHosts. This classification allows us to make
196// sure URLs are served by hosts with the right set of privileges.
197enum RenderProcessHostPrivilege {
198 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45199 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42200 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45201 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42202};
203
204RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
205 const GURL& url,
206 ExtensionService* service) {
207 // Default to a normal renderer cause it is lower privileged. This should only
208 // occur if the URL on a site instance is either malformed, or uninitialized.
209 // If it is malformed, then there is no need for better privileges anyways.
210 // If it is uninitialized, but eventually settles on being an a scheme other
211 // than normal webrenderer, the navigation logic will correct us out of band
212 // anyways.
213 if (!url.is_valid())
214 return PRIV_NORMAL;
215
216 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44217 const Extension* extension =
218 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45219 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42220 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45221 if (extension && extension->is_hosted_app())
222 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42223
224 return PRIV_EXTENSION;
225 }
226
227 return PRIV_NORMAL;
228}
229
230RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30231 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46232 extensions::ProcessMap* process_map,
233 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46234 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30235 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46236 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21237 return PRIV_NORMAL;
238
[email protected]6f371442011-11-09 06:45:46239 for (std::set<std::string>::iterator iter = extension_ids.begin();
240 iter != extension_ids.end(); ++iter) {
241 const Extension* extension = service->GetExtensionById(*iter, false);
242 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42243 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45244 if (extension && extension->is_hosted_app())
245 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42246 }
247
[email protected]676f6ab2011-10-19 20:23:21248 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42249}
250
[email protected]eec0b33c2011-12-05 22:09:45251bool IsIsolatedAppInProcess(const GURL& site_url,
252 content::RenderProcessHost* process_host,
253 extensions::ProcessMap* process_map,
254 ExtensionService* service) {
255 std::set<std::string> extension_ids =
256 process_map->GetExtensionsInProcess(process_host->GetID());
257 if (extension_ids.empty())
258 return false;
259
260 for (std::set<std::string>::iterator iter = extension_ids.begin();
261 iter != extension_ids.end(); ++iter) {
262 const Extension* extension = service->GetExtensionById(*iter, false);
263 if (extension &&
264 extension->is_storage_isolated() &&
265 extension->url() == site_url)
266 return true;
267 }
268
269 return false;
270}
271
[email protected]6786bf402011-12-03 15:19:45272bool CertMatchesFilter(const net::X509Certificate& cert,
273 const base::DictionaryValue& filter) {
274 // TODO(markusheintz): This is the minimal required filter implementation.
275 // Implement a better matcher.
276
277 // An empty filter matches any client certificate since no requirements are
278 // specified at all.
279 if (filter.empty())
280 return true;
281
282 std::string common_name;
283 if (filter.GetString("ISSUER.CN", &common_name) &&
284 (cert.issuer().common_name == common_name)) {
285 return true;
286 }
287 return false;
288}
289
[email protected]f3986f82012-01-03 20:00:06290// Fills |map| with the per-script font prefs under path |map_name|.
291void FillFontFamilyMap(const PrefService* prefs,
292 const char* map_name,
293 WebPreferences::ScriptFontFamilyMap* map) {
294 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
295 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
296 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
297 std::string font_family = prefs->GetString(pref_name.c_str());
298 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32299 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06300 }
301}
302
[email protected]a1733df2012-06-22 11:24:18303#if defined(OS_POSIX) && !defined(OS_MACOSX)
304int GetCrashSignalFD(const CommandLine& command_line) {
305 if (command_line.HasSwitch(switches::kExtensionProcess)) {
306 ExtensionCrashHandlerHostLinux* crash_handler =
307 ExtensionCrashHandlerHostLinux::GetInstance();
308 return crash_handler->GetDeathSignalSocket();
309 }
310
311 std::string process_type =
312 command_line.GetSwitchValueASCII(switches::kProcessType);
313
314 if (process_type == switches::kRendererProcess)
315 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
316
317 if (process_type == switches::kPluginProcess)
318 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
319
320 if (process_type == switches::kPpapiPluginProcess)
321 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
322
323 if (process_type == switches::kGpuProcess)
324 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
325
326 return -1;
327}
328#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
329
[email protected]9dbfff12011-07-01 19:37:07330} // namespace
[email protected]c5dbef02011-05-13 05:06:09331
[email protected]d977f9c2011-03-14 16:10:26332namespace chrome {
333
[email protected]e461da2f2012-02-16 19:06:40334ChromeContentBrowserClient::ChromeContentBrowserClient() {
335 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
336 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40337}
338
339ChromeContentBrowserClient::~ChromeContentBrowserClient() {
340}
341
[email protected]bca18382012-06-25 19:15:23342// static
343void ChromeContentBrowserClient::RegisterUserPrefs(PrefService* prefs) {
344 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
345 false,
346 PrefService::UNSYNCABLE_PREF);
347 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
348 true,
349 PrefService::UNSYNCABLE_PREF);
350 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
351 false,
352 PrefService::UNSYNCABLE_PREF);
353}
354
[email protected]50462bf02011-11-21 19:13:31355content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
356 const content::MainFunctionParams& parameters) {
357 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30358 // Construct the Main browser parts based on the OS type.
359#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31360 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04361#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31362 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30363#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31364 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26365#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31366 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14367#elif defined(OS_ANDROID)
368 // Do nothing for Android.
369 // TODO(klobag): Android initialization should use the
370 // *BrowserMainParts class-hierarchy for setting up custom initialization.
371 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30372#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31373 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04374#else
[email protected]b48c9182011-10-26 18:03:30375 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31376 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30377#endif
378
[email protected]c7480942011-11-08 19:18:27379 // Construct additional browser parts. Stages are called in the order in
380 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22381#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41382 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04383#endif
[email protected]c7480942011-11-08 19:18:27384
385#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41386 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27387#endif
388
[email protected]dc04be7c2012-03-15 23:57:49389#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41390 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49391#endif
392
[email protected]e050ef142012-03-21 01:04:24393#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41394 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24395#endif
396
[email protected]50462bf02011-11-21 19:13:31397 return main_parts;
[email protected]f967b722011-09-07 00:58:04398}
399
[email protected]38b098f2012-03-14 21:11:57400content::WebContentsView*
401 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57402 WebContents* web_contents,
403 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57404 return NULL;
405}
406
[email protected]d7c7c98a2012-07-12 21:27:44407std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
408 content::BrowserContext* browser_context,
409 int child_process_id) {
410 // In chrome, we use the extension ID as the partition ID. This works well
411 // because the extension ID fits the partition ID pattern and currently only
412 // apps can designate that storage should be isolated.
413 Profile* profile = Profile::FromBrowserContext(browser_context);
414 ExtensionService* extension_service =
415 extensions::ExtensionSystem::Get(profile)->extension_service();
416 if (extension_service) {
417 const extensions::Extension* installed_app = extension_service->
418 GetInstalledAppForRenderer(child_process_id);
419 if (installed_app && installed_app->is_storage_isolated()) {
420 return installed_app->id();
421 }
422 }
423 return std::string();
424}
425
[email protected]38b098f2012-03-14 21:11:57426content::WebContentsViewDelegate*
427 ChromeContentBrowserClient::GetWebContentsViewDelegate(
428 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27429 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32430}
431
[email protected]f364d1392011-04-08 21:03:10432void ChromeContentBrowserClient::RenderViewHostCreated(
433 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46434
[email protected]9f76c1e2012-03-05 15:15:58435 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46436 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02437 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46438
439 new ChromeRenderViewHostObserver(render_view_host,
440 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49441 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26442}
443
[email protected]f3b1a082011-11-18 00:34:30444void ChromeContentBrowserClient::RenderProcessHostCreated(
445 content::RenderProcessHost* host) {
446 int id = host->GetID();
447 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
448 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02449 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30450 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02451#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08452 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03453#endif
[email protected]f3b1a082011-11-18 00:34:30454 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02455 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30456 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56457#if defined(OS_MACOSX)
458 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
459#endif
[email protected]f3b1a082011-11-18 00:34:30460 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03461 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07462 host->GetChannel()->AddFilter(
463 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38464
[email protected]2ccf45c2011-08-19 23:35:50465 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
466 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07467
468 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56469
470 RendererContentSettingRules rules;
471 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
472 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14473}
474
[email protected]e0ada9c2012-03-20 03:54:43475void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
476 content::BrowserChildProcessHost* host) {
477 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
478}
479
[email protected]863f70a2012-01-27 02:05:50480content::WebUIControllerFactory*
481 ChromeContentBrowserClient::GetWebUIControllerFactory() {
482 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56483}
484
[email protected]3d7474ff2011-07-27 17:47:37485GURL ChromeContentBrowserClient::GetEffectiveURL(
486 content::BrowserContext* browser_context, const GURL& url) {
487 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08488 // Get the effective URL for the given actual URL. If the URL is part of an
489 // installed app, the effective URL is an extension URL with the ID of that
490 // extension as the host. This has the effect of grouping apps together in
491 // a common SiteInstance.
492 if (!profile || !profile->GetExtensionService())
493 return url;
494
[email protected]615d88f2011-12-13 01:47:44495 const Extension* extension = profile->GetExtensionService()->extensions()->
496 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08497 if (!extension)
498 return url;
499
[email protected]15877ca2011-11-18 22:40:52500 // Bookmark apps do not use the hosted app process model, and should be
501 // treated as normal URLs.
502 if (extension->from_bookmark())
503 return url;
504
[email protected]36fb2c7c2011-04-04 15:49:08505 // If the URL is part of an extension's web extent, convert it to an
506 // extension URL.
507 return extension->GetResourceURL(url.path());
508}
509
[email protected]056ad2a2011-07-12 02:13:55510bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37511 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55512 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52513 // Because we expect to use the effective URL, URLs for hosted apps (apart
514 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55515 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
516 return false;
517
[email protected]3d7474ff2011-07-27 17:47:37518 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55519 if (!profile || !profile->GetExtensionService())
520 return false;
521
[email protected]615d88f2011-12-13 01:47:44522 const Extension* extension = profile->GetExtensionService()->extensions()->
523 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55524 if (!extension)
525 return false;
526
527 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53528 // permission, or that does not allow JavaScript access to the background
529 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55530 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53531 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06532 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53533 !extension->allow_background_js_access()) {
534 return false;
535 }
536 }
[email protected]056ad2a2011-07-12 02:13:55537
[email protected]7b54ca02012-03-02 18:06:53538 // Hosted apps that have script access to their background page must use
539 // process per site, since all instances can make synchronous calls to the
540 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55541 return true;
542}
543
[email protected]46fb9442011-12-09 17:57:47544bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
545 return ProfileIOData::IsHandledURL(url);
546}
547
[email protected]2a5221b2011-09-27 23:07:31548bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30549 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31550 const GURL& site_url) {
551 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30552 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42553 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46554 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31555
[email protected]ffa97602011-11-17 17:55:52556 // Don't allow the Task Manager to share a process with anything else.
557 // Otherwise it can affect the renderers it is observing.
558 // Note: we could create another RenderProcessHostPrivilege bucket for
559 // this to allow multiple chrome://tasks instances to share, but that's
560 // a very unlikely case without serious consequences.
561 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
562 return false;
563
[email protected]8d3132f62011-10-12 07:13:42564 // These may be NULL during tests. In that case, just assume any site can
565 // share any host.
[email protected]6f371442011-11-09 06:45:46566 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31567 return true;
568
[email protected]a8c269a2011-10-25 20:17:22569 // Experimental:
570 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
571 // to share a renderer process. (We could allow pages from the same site or
572 // extensions of the same type to share, if we knew what the given process
573 // was dedicated to. Allowing no sharing is simpler for now.) This may
574 // cause resource exhaustion issues if too many sites are open at once.
575 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
576 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
577 return false;
578
[email protected]eec0b33c2011-12-05 22:09:45579 // An isolated app is only allowed to share with the exact same app in order
580 // to provide complete renderer process isolation. This also works around
581 // issue http://crbug.com/85588, where different isolated apps in the same
582 // process would end up using the first app's storage contexts.
583 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42584 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45585 if (privilege_required == PRIV_ISOLATED)
586 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
587
588 // Otherwise, just make sure the process privilege matches the privilege
589 // required by the site.
590 return GetProcessPrivilege(process_host, process_map, service) ==
591 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31592}
593
[email protected]76411f412012-02-22 18:56:06594// This function is trying to limit the amount of processes used by extensions
595// with background pages. It uses a globally set percentage of processes to
596// run such extensions and if the limit is exceeded, it returns true, to
597// indicate to the content module to group extensions together.
598bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
599 content::BrowserContext* browser_context, const GURL& url) {
600 // It has to be a valid URL for us to check for an extension.
601 if (!url.is_valid())
602 return false;
603
604 Profile* profile = Profile::FromBrowserContext(browser_context);
605 ExtensionService* service = profile->GetExtensionService();
606 if (!service)
607 return false;
608
609 // We have to have a valid extension with background page to proceed.
610 const Extension* extension =
611 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
612 if (!extension)
613 return false;
614 if (!extension->has_background_page())
615 return false;
616
617 std::set<int> process_ids;
618 size_t max_process_count =
619 content::RenderProcessHost::GetMaxRendererProcessCount();
620
621 // Go through all profiles to ensure we have total count of extension
622 // processes containing background pages, otherwise one profile can
623 // starve the other.
624 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
625 GetLoadedProfiles();
626 for (size_t i = 0; i < profiles.size(); ++i) {
627 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32628 for (ExtensionProcessManager::const_iterator iter =
629 epm->background_hosts().begin();
630 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13631 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32632 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06633 }
634 }
635
636 if (process_ids.size() >
637 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
638 return true;
639 }
640
641 return false;
642}
643
[email protected]6f371442011-11-09 06:45:46644void ChromeContentBrowserClient::SiteInstanceGotProcess(
645 SiteInstance* site_instance) {
646 CHECK(site_instance->HasProcess());
647
648 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02649 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46650 ExtensionService* service = profile->GetExtensionService();
651 if (!service)
652 return;
653
654 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44655 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33656 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46657 if (!extension)
658 return;
659
[email protected]6bc04fd82011-12-04 02:29:35660 service->process_map()->Insert(extension->id(),
661 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33662 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46663 BrowserThread::PostTask(
664 BrowserThread::IO, FROM_HERE,
665 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59666 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46667 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35668 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33669 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46670}
671
672void ChromeContentBrowserClient::SiteInstanceDeleting(
673 SiteInstance* site_instance) {
674 if (!site_instance->HasProcess())
675 return;
676
677 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02678 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46679 ExtensionService* service = profile->GetExtensionService();
680 if (!service)
681 return;
682
683 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44684 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33685 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46686 if (!extension)
687 return;
688
[email protected]6bc04fd82011-12-04 02:29:35689 service->process_map()->Remove(extension->id(),
690 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33691 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46692 BrowserThread::PostTask(
693 BrowserThread::IO, FROM_HERE,
694 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59695 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46696 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35697 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33698 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46699}
700
[email protected]f05763972012-06-06 18:17:26701bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08702 const GURL& current_url,
703 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26704 if (current_url.is_empty()) {
705 // Always choose a new process when navigating to extension URLs. The
706 // process grouping logic will combine all of a given extension's pages
707 // into the same process.
708 if (new_url.SchemeIs(chrome::kExtensionScheme))
709 return true;
[email protected]e3daf3c2011-10-05 21:17:08710
[email protected]f05763972012-06-06 18:17:26711 return false;
712 }
713
714 // Also, we must switch if one is an extension and the other is not the exact
715 // same extension.
716 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
717 new_url.SchemeIs(chrome::kExtensionScheme)) {
718 if (current_url.GetOrigin() != new_url.GetOrigin())
719 return true;
720 }
721
722 return false;
[email protected]e3daf3c2011-10-05 21:17:08723}
724
[email protected]395045c2012-05-22 15:04:38725bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
726 content::ResourceContext* resource_context, const GURL& current_url,
727 const GURL& new_url) {
728 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
729 return extensions::CrossesExtensionProcessBoundary(
730 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17731 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38732}
733
[email protected]763ec4ca2011-04-29 15:48:12734std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
735 const std::string& alias_name) {
736 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
737}
738
[email protected]b80f68432011-05-02 17:22:30739void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
740 CommandLine* command_line, int child_process_id) {
741#if defined(USE_LINUX_BREAKPAD)
742 if (IsCrashReporterEnabled()) {
743 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
744 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
745 }
746#elif defined(OS_MACOSX)
747 if (IsCrashReporterEnabled()) {
748 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
749 child_process_logging::GetClientId());
750 }
751#endif // OS_MACOSX
752
[email protected]f1933792011-06-14 00:49:34753 if (logging::DialogsAreSuppressed())
754 command_line->AppendSwitch(switches::kNoErrorDialogs);
755
[email protected]b80f68432011-05-02 17:22:30756 std::string process_type =
757 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17758 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52759 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30760 FilePath user_data_dir =
761 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
762 if (!user_data_dir.empty())
763 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
764#if defined(OS_CHROMEOS)
765 const std::string& login_profile =
766 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
767 if (!login_profile.empty())
768 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
769#endif
770
[email protected]f3b1a082011-11-18 00:34:30771 content::RenderProcessHost* process =
772 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37773 if (process) {
774 Profile* profile = Profile::FromBrowserContext(
775 process->GetBrowserContext());
776 extensions::ProcessMap* process_map =
777 profile->GetExtensionService()->process_map();
778 if (process_map && process_map->Contains(process->GetID()))
779 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30780
[email protected]a8d851f82011-12-21 00:32:37781 PrefService* prefs = profile->GetPrefs();
782 // Currently this pref is only registered if applied via a policy.
783 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
784 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
785 // Turn this policy into a command line switch.
786 command_line->AppendSwitch(switches::kDisable3DAPIs);
787 }
[email protected]718eab62011-10-05 21:16:52788
[email protected]a8d851f82011-12-21 00:32:37789 // Disable client-side phishing detection in the renderer if it is
790 // disabled in the Profile preferences or the browser process.
791 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
792 !g_browser_process->safe_browsing_detection_service()) {
793 command_line->AppendSwitch(
794 switches::kDisableClientSidePhishingDetection);
795 }
[email protected]0045b0f42012-07-26 11:52:08796
797 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:21798 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]47c7ec82012-01-18 03:29:21799 }
[email protected]4287a3d2011-06-13 23:56:51800
[email protected]47c7ec82012-01-18 03:29:21801 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51802 static const char* const kSwitchNames[] = {
803 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48804 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51805 switches::kAllowScriptingGallery,
806 switches::kAppsCheckoutURL,
807 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31808 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51809 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10810 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50811 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53812 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09813 switches::kDisableInBrowserThumbnailing,
[email protected]4287a3d2011-06-13 23:56:51814 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21815 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13816 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51817 switches::kEnableCrxlessWebApps,
818 switches::kEnableExperimentalExtensionApis,
[email protected]adda89512012-07-26 17:01:54819 switches::kEnableHighDPIPDFPlugin,
[email protected]4287a3d2011-06-13 23:56:51820 switches::kEnableIPCFuzzing,
821 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05822 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48823 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:51824 switches::kEnableWatchdog,
825 switches::kExperimentalSpellcheckerFeatures,
826 switches::kMemoryProfiling,
827 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37828 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:37829 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51830 switches::kPpapiFlashArgs,
831 switches::kPpapiFlashInProcess,
832 switches::kPpapiFlashPath,
833 switches::kPpapiFlashVersion,
834 switches::kProfilingAtStart,
835 switches::kProfilingFile,
836 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37837 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51838 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38839 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51840 };
841
842 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
843 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17844 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38845 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35846 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38847 switches::kEnableExperimentalExtensionApis,
848 switches::kWhitelistedExtensionID,
849 };
850
851 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
852 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51853 } else if (process_type == switches::kPluginProcess) {
854 static const char* const kSwitchNames[] = {
855 #if defined(OS_CHROMEOS)
856 switches::kLoginProfile,
857 #endif
858 switches::kMemoryProfiling,
859 switches::kSilentDumpOnDCHECK,
860 switches::kUserDataDir,
861 };
862
863 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
864 arraysize(kSwitchNames));
865 } else if (process_type == switches::kZygoteProcess) {
866 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51867 switches::kUserDataDir, // Make logs go to the right file.
868 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50869 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13870 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51871 switches::kPpapiFlashInProcess,
872 switches::kPpapiFlashPath,
873 switches::kPpapiFlashVersion,
874 };
875
876 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
877 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11878 } else if (process_type == switches::kGpuProcess) {
879 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
880 // because GPU is expected to be unreliable.
881 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
882 !command_line->HasSwitch(switches::kDisableBreakpad))
883 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30884 }
[email protected]6f08af82011-09-15 01:19:03885
886 // The command line switch kEnableBenchmarking needs to be specified along
887 // with the kEnableStatsTable switch to ensure that the stats table global
888 // is initialized correctly.
889 if (command_line->HasSwitch(switches::kEnableBenchmarking))
890 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30891}
892
893std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:43894 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
895 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:30896 return g_browser_process->GetApplicationLocale();
897}
898
[email protected]597a867b2011-11-18 18:31:20899std::string ChromeContentBrowserClient::GetAcceptLangs(
900 content::BrowserContext* context) {
901 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37902 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08903}
904
[email protected]9ec0f452012-05-31 15:58:53905gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22906 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:53907 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:08908}
909
[email protected]a2176792011-05-08 19:30:49910bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09911 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19912 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20913 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20915 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05916 return io_data->GetCookieSettings()->
917 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49918}
919
[email protected]ed24fad2011-05-10 22:44:01920bool ChromeContentBrowserClient::AllowGetCookie(
921 const GURL& url,
922 const GURL& first_party,
923 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20924 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01925 int render_process_id,
926 int render_view_id) {
927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20928 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05929 bool allow = io_data->GetCookieSettings()->
930 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01931
[email protected]8093a542011-05-13 07:29:32932 BrowserThread::PostTask(
933 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03934 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43935 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01936 return allow;
937}
938
939bool ChromeContentBrowserClient::AllowSetCookie(
940 const GURL& url,
941 const GURL& first_party,
942 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20943 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01944 int render_process_id,
945 int render_view_id,
946 net::CookieOptions* options) {
947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20948 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05949 CookieSettings* cookie_settings = io_data->GetCookieSettings();
950 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
951
[email protected]8093a542011-05-13 07:29:32952 BrowserThread::PostTask(
953 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03954 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43955 render_view_id, url, first_party, cookie_line, *options,
956 !allow));
[email protected]ed24fad2011-05-10 22:44:01957 return allow;
958}
959
[email protected]ea628e32012-08-02 21:50:16960bool ChromeContentBrowserClient::AllowPluginLocalDataAccess(
961 const GURL& document_url,
962 const GURL& plugin_url,
963 content::ResourceContext* context) {
964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
965 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
966 return io_data->GetCookieSettings()->IsReadingCookieAllowed(document_url,
967 plugin_url);
968}
969
970bool ChromeContentBrowserClient::AllowPluginLocalDataSessionOnly(
971 const GURL& url,
972 content::ResourceContext* context) {
973 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
974 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
975 return io_data->GetCookieSettings()->IsCookieSessionOnly(url);
976}
977
[email protected]d5a19162011-06-30 18:51:54978bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20979 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20981 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:43982 CookieSettings* cookie_settings = io_data->GetCookieSettings();
983 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:26984
[email protected]bf510ed2012-06-05 08:31:43985 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
986 // Could we even support per-origin settings?
987 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:54988}
989
[email protected]5c5a88e2011-11-12 00:45:35990bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35991 const GURL& url,
992 const string16& name,
993 const string16& display_name,
994 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20995 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48996 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35997 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20998 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35999 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1000 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1001
[email protected]62151052012-02-01 18:40:481002 // Record access to database for potential display in UI.
1003 std::vector<std::pair<int, int> >::const_iterator i;
1004 for (i = render_views.begin(); i != render_views.end(); ++i) {
1005 BrowserThread::PostTask(
1006 BrowserThread::UI, FROM_HERE,
1007 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1008 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351009 }
1010
1011 return allow;
1012}
1013
1014bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351015 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201016 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481017 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351018 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201019 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351020 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1021 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1022
[email protected]62151052012-02-01 18:40:481023 // Record access to file system for potential display in UI.
1024 std::vector<std::pair<int, int> >::const_iterator i;
1025 for (i = render_views.begin(); i != render_views.end(); ++i) {
1026 BrowserThread::PostTask(
1027 BrowserThread::UI, FROM_HERE,
1028 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1029 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351030 }
1031
1032 return allow;
1033}
1034
[email protected]7c5ff9a2012-03-02 07:42:491035bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1036 const GURL& url,
1037 const string16& name,
1038 content::ResourceContext* context,
1039 const std::vector<std::pair<int, int> >& render_views) {
1040 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1041 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1042 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1043 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1044
1045 // Record access to IndexedDB for potential display in UI.
1046 std::vector<std::pair<int, int> >::const_iterator i;
1047 for (i = render_views.begin(); i != render_views.end(); ++i) {
1048 BrowserThread::PostTask(
1049 BrowserThread::UI, FROM_HERE,
1050 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1051 i->first, i->second, url, name, !allow));
1052 }
1053
1054 return allow;
1055}
1056
[email protected]6133f922011-07-01 21:34:341057net::URLRequestContext*
1058ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201059 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341060 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1061 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201062 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341063 return io_data->extensions_request_context();
1064 }
1065
1066 return NULL;
1067}
1068
[email protected]317f96c92011-05-31 06:53:411069QuotaPermissionContext*
1070ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1071 return new ChromeQuotaPermissionContext();
1072}
1073
[email protected]a0ce3282011-08-19 20:49:521074void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421075 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421076}
1077
[email protected]a0ce3282011-08-19 20:49:521078void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521079 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521080}
1081
[email protected]848dd042011-06-04 18:24:031082void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171083 int render_process_id,
1084 int render_view_id,
1085 int cert_error,
1086 const net::SSLInfo& ssl_info,
1087 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031088 bool overridable,
[email protected]d9be47702012-05-16 03:41:221089 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171090 const base::Callback<void(bool)>& callback,
1091 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411092 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131093 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171094 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411095 if (!tab) {
1096 NOTREACHED();
1097 return;
1098 }
1099 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501100 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301101 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091102 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411103 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171104 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411105 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171106 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411107 return;
1108 }
1109 }
1110
1111 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221112 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1113 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031114}
1115
[email protected]c99c442e2011-08-24 11:37:301116void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451117 int render_process_id,
1118 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401119 const net::HttpNetworkSession* network_session,
1120 net::SSLCertRequestInfo* cert_request_info,
1121 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131122 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451123 render_process_id, render_view_id);
1124 if (!tab) {
1125 NOTREACHED();
1126 return;
1127 }
1128
[email protected]6786bf402011-12-03 15:19:451129 GURL requesting_url("https://" + cert_request_info->host_and_port);
1130 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1131 << cert_request_info->host_and_port;
1132
[email protected]627e0512011-12-21 22:55:301133 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451134 scoped_ptr<Value> filter(
1135 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1136 requesting_url,
1137 requesting_url,
1138 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1139 std::string(), NULL));
1140
1141 if (filter.get()) {
1142 // Try to automatically select a client certificate.
1143 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1144 DictionaryValue* filter_dict =
1145 static_cast<DictionaryValue*>(filter.get());
1146
1147 const std::vector<scoped_refptr<net::X509Certificate> >&
1148 all_client_certs = cert_request_info->client_certs;
1149 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1150 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1151 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401152 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451153 return;
1154 }
1155 }
1156 } else {
1157 NOTREACHED();
1158 }
1159 }
1160
[email protected]871dc682012-06-11 19:35:331161 TabContents* tab_contents = TabContents::FromWebContents(tab);
1162 if (!tab_contents) {
1163 // If there is no TabContents for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451164 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141165 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401166 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451167 return;
1168 }
[email protected]871dc682012-06-11 19:35:331169 tab_contents->ssl_helper()->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401170 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451171}
1172
1173void ChromeContentBrowserClient::AddNewCertificate(
1174 net::URLRequest* request,
1175 net::X509Certificate* cert,
1176 int render_process_id,
1177 int render_view_id) {
1178 // The handler will run the UI and delete itself when it's finished.
1179 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1180}
1181
[email protected]dc73a7b2012-03-25 15:27:181182content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1183 return MediaInternals::GetInstance();
1184}
1185
[email protected]941623e2011-06-07 23:06:041186void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1187 const GURL& source_origin,
1188 int callback_context,
1189 int render_process_id,
1190 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111191#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1193 WebContents* contents =
1194 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1195 if (!contents) {
[email protected]941623e2011-06-07 23:06:041196 NOTREACHED();
1197 return;
1198 }
1199
[email protected]d0d9c3ee2012-06-19 03:07:021200 // Skip showing the infobar if the request comes from an extension, and that
1201 // extension has the 'notify' permission. (If the extension does not have the
1202 // permission, the user will still be prompted.)
1203 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
1204 ExtensionService* service = profile->GetExtensionService();
1205 const Extension* extension = !service ? NULL :
1206 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1207 source_origin));
1208 if (extension &&
[email protected]c2e66e12012-06-27 06:27:061209 extension->HasAPIPermission(APIPermission::kNotification)) {
[email protected]d0d9c3ee2012-06-19 03:07:021210 RenderViewHost* rvh =
1211 RenderViewHost::FromID(render_process_id, render_view_id);
1212 if (rvh)
1213 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1214 return;
1215 }
1216
1217 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371218 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021219 notifications->RequestPermission(source_origin, render_process_id,
1220 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111221#else
1222 NOTIMPLEMENTED();
1223#endif
[email protected]941623e2011-06-07 23:06:041224}
1225
1226WebKit::WebNotificationPresenter::Permission
1227 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021228 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201229 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021230 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111231#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201233 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021234 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1235 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061236 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041237 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041238
1239 // Fall back to the regular notification preferences, which works on an
1240 // origin basis.
1241 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371242 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041243 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111244#else
1245 return WebKit::WebNotificationPresenter::PermissionAllowed;
1246#endif
[email protected]941623e2011-06-07 23:06:041247}
1248
1249void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171250 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041251 int render_process_id,
1252 int render_view_id,
1253 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111254#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041255 RenderViewHost* rvh = RenderViewHost::FromID(
1256 render_process_id, render_view_id);
1257 if (!rvh) {
1258 NOTREACHED();
1259 return;
1260 }
1261
[email protected]9f76c1e2012-03-05 15:15:581262 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301263 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041264 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371265 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041266 service->ShowDesktopNotification(
1267 params, render_process_id, render_view_id,
1268 worker ? DesktopNotificationService::WorkerNotification :
1269 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111270#else
1271 NOTIMPLEMENTED();
1272#endif
[email protected]941623e2011-06-07 23:06:041273}
1274
1275void ChromeContentBrowserClient::CancelDesktopNotification(
1276 int render_process_id,
1277 int render_view_id,
1278 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111279#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041280 RenderViewHost* rvh = RenderViewHost::FromID(
1281 render_process_id, render_view_id);
1282 if (!rvh) {
1283 NOTREACHED();
1284 return;
1285 }
1286
[email protected]9f76c1e2012-03-05 15:15:581287 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301288 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041289 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371290 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041291 service->CancelDesktopNotification(
1292 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111293#else
1294 NOTIMPLEMENTED();
1295#endif
[email protected]941623e2011-06-07 23:06:041296}
1297
[email protected]9f3fba52011-06-08 20:37:191298bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351299 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021300 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191301 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201302 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011303 int render_process_id,
1304 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011306
1307 *no_javascript_access = false;
1308
[email protected]9f3fba52011-06-08 20:37:191309 // If the opener is trying to create a background window but doesn't have
1310 // the appropriate permission, fail the attempt.
1311 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201312 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531313 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1314
[email protected]03b6d552012-03-29 04:03:011315 if (!map->SecurityOriginHasAPIPermission(
1316 source_origin,
1317 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061318 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011319 return false;
1320 }
1321
[email protected]7b54ca02012-03-02 18:06:531322 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1323 // return a recently installed Extension even if this CanCreateWindow call
1324 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011325 // because the permission check above would have caused an early return
1326 // already. We must use the full URL to find hosted apps, though, and not
1327 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531328 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351329 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531330 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011331 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191332 }
1333 return true;
1334}
1335
1336std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201337 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1339 // Check if it's an extension-created worker, in which case we want to use
1340 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201341 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191342 const Extension* extension =
1343 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1344 return extension ? extension->name() : std::string();
1345}
1346
[email protected]99907362012-01-11 05:41:401347void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1348 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171349}
1350
[email protected]c52b2892012-03-07 11:01:021351content::SpeechRecognitionManagerDelegate*
1352 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321353#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021354 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321355#else
1356 return NULL;
1357#endif
[email protected]66cfec62012-02-24 17:57:511358}
1359
[email protected]ae6e9912011-07-27 01:18:281360net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1361 return g_browser_process->net_log();
1362}
1363
[email protected]32538d92011-08-25 00:09:231364AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1365 return new ChromeAccessTokenStore();
1366}
1367
[email protected]dbae6b02011-06-29 23:51:411368bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1369 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1370 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1371}
1372
[email protected]64d69de42012-02-06 00:19:541373void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321374 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061375 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581376 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061377 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061378
[email protected]f3986f82012-01-03 20:00:061379 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541380 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061381 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541382 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061383 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541384 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061385 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541386 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061387 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541388 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061389 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541390 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061391
[email protected]64d69de42012-02-06 00:19:541392 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401393 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541394 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401395 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541396 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401397 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541398 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401399 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061400
[email protected]ddf72142012-05-22 04:52:401401 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061402
[email protected]64d69de42012-02-06 00:19:541403 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401404 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541405 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061406 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541407 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061408 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1409 const DictionaryValue* inspector_settings =
1410 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1411 if (inspector_settings) {
1412 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1413 iter != inspector_settings->end_keys(); ++iter) {
1414 std::string value;
1415 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541416 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061417 std::make_pair(*iter, value));
1418 }
1419 }
[email protected]64d69de42012-02-06 00:19:541420 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061421
[email protected]ddf72142012-05-22 04:52:401422 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541423 web_prefs->javascript_enabled = false;
1424 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1425 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401426 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541427 web_prefs->plugins_enabled = false;
1428 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1429 web_prefs->java_enabled = false;
1430 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401431 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061432
[email protected]64d69de42012-02-06 00:19:541433 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1434 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061435
[email protected]64d69de42012-02-06 00:19:541436 web_prefs->memory_info_enabled =
1437 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1438 web_prefs->allow_displaying_insecure_content =
1439 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1440 web_prefs->allow_running_insecure_content =
1441 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081442 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061443
[email protected]64d69de42012-02-06 00:19:541444 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151445 UserStyleSheetWatcher* user_style_sheet_watcher =
1446 UserStyleSheetWatcherFactory::GetForProfile(profile);
1447 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541448 web_prefs->user_style_sheet_enabled = true;
1449 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151450 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541451 } else {
1452 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061453 }
1454
[email protected]b7e44ff2012-02-16 03:37:341455 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101456#if defined(OS_MACOSX)
1457 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1458 // Mac so it uses NSSpellChecker in the background.
1459 false;
1460#else
1461 !CommandLine::ForCurrentProcess()->
1462 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1463#endif
[email protected]b7e44ff2012-02-16 03:37:341464 web_prefs->unified_textchecker_enabled =
1465 web_prefs->asynchronous_spell_checking_enabled ||
1466 CommandLine::ForCurrentProcess()->
1467 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571468
[email protected]64d69de42012-02-06 00:19:541469 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061470 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541471 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061472 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541473 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061474 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1475
1476 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541477 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061478 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541479 web_prefs->default_encoding);
1480 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401481 prefs->ClearPref(prefs::kDefaultCharset);
1482 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061483 }
[email protected]64d69de42012-02-06 00:19:541484 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061485
[email protected]299d7f12012-05-23 05:31:151486 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1487 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061488 ExtensionService* service = profile->GetExtensionService();
1489 if (service) {
1490 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581491 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061492 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151493 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061494 }
1495
[email protected]a458504b2012-07-23 19:57:061496 if (gpu_util::InForceCompositingModeOrThreadTrial())
[email protected]4abe58d2012-06-08 03:09:091497 web_prefs->force_compositing_mode = true;
1498
[email protected]299d7f12012-05-23 05:31:151499 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541500 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151501 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061502 // Disable all kinds of acceleration for background pages.
1503 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541504 web_prefs->force_compositing_mode = false;
1505 web_prefs->accelerated_compositing_enabled = false;
1506 web_prefs->accelerated_2d_canvas_enabled = false;
1507 web_prefs->accelerated_video_enabled = false;
1508 web_prefs->accelerated_painting_enabled = false;
1509 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061510 }
[email protected]2e21fe292012-03-02 22:52:321511
1512#if defined(FILE_MANAGER_EXTENSION)
1513 // Override the default of suppressing HW compositing for WebUI pages for the
1514 // file manager, which is implemented using WebUI but wants HW acceleration
1515 // for video decode & render.
1516 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1517 web_prefs->accelerated_compositing_enabled = true;
1518 web_prefs->accelerated_2d_canvas_enabled = true;
1519 }
1520#endif
[email protected]181a95ee2011-07-12 19:26:361521}
1522
1523void ChromeContentBrowserClient::UpdateInspectorSetting(
1524 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061525 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581526 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061527 DictionaryPrefUpdate update(
1528 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1529 prefs::kWebKitInspectorSettings);
1530 DictionaryValue* inspector_settings = update.Get();
1531 inspector_settings->SetWithoutPathExpansion(key,
1532 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361533}
1534
1535void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061536 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581537 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061538 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1539 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361540}
1541
[email protected]b8148ac2011-07-13 22:03:251542void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1543 BrowserURLHandler* handler) {
1544 // Add the default URL handlers.
1545 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1546 BrowserURLHandler::null_handler());
1547 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1548 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1549
[email protected]b3adbd02011-11-30 22:23:271550 // about: handler. Must come before chrome: handler, since it will
1551 // rewrite about: urls to chrome: URLs and then expect chrome: to
1552 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251553 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1554 BrowserURLHandler::null_handler());
1555 // chrome: & friends.
1556 handler->AddHandlerPair(&HandleWebUI,
1557 BrowserURLHandler::null_handler());
1558}
1559
1560void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371561 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581562 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251563 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1564 BrowsingDataRemover::EVERYTHING,
1565 base::Time());
[email protected]3d4d4cf2012-06-04 10:40:551566 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1567 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251568 // BrowsingDataRemover takes care of deleting itself when done.
1569}
1570
1571void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371572 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581573 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251574 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1575 BrowsingDataRemover::EVERYTHING,
1576 base::Time());
[email protected]dceaa912011-09-06 17:17:231577 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551578 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251579 // BrowsingDataRemover takes care of deleting itself when done.
1580}
1581
[email protected]e1d16eb92011-08-18 23:19:321582FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1583 return download_util::GetDefaultDownloadDirectory();
1584}
1585
[email protected]c9b6eb62011-10-18 20:49:391586std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1587 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1588}
1589
[email protected]38cd8f7f2012-06-15 22:06:071590bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]a658d452012-03-02 12:45:291591 content::BrowserContext* browser_context, const GURL& url) {
1592 if (!url.is_valid())
1593 return false;
1594
1595 std::string host = url.host();
[email protected]92444942012-06-16 09:05:281596 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host))
[email protected]a658d452012-03-02 12:45:291597 return true;
1598
[email protected]9a5940d2012-04-27 19:16:231599 Profile* profile = Profile::FromBrowserContext(browser_context);
1600 const Extension* extension = NULL;
1601 if (profile && profile->GetExtensionService()) {
1602 extension = profile->GetExtensionService()->extensions()->
1603 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1604 }
1605
[email protected]f237c0f2012-03-10 07:49:101606 // Need to check this now and not on construction because otherwise it won't
1607 // work with browser_tests.
1608 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1609 std::string allowed_list =
1610 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231611 if (allowed_list == "*") {
1612 // The wildcard allows socket API only for packaged and platform apps.
1613 return extension &&
1614 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1615 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1616 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101617 StringTokenizer t(allowed_list, ",");
1618 while (t.GetNext()) {
1619 if (t.token() == host)
1620 return true;
1621 }
1622 }
1623
[email protected]a658d452012-03-02 12:45:291624 if (!extension)
1625 return false;
1626
[email protected]c2e66e12012-06-27 06:27:061627 if (extension->HasAPIPermission(APIPermission::kSocket))
[email protected]a658d452012-03-02 12:45:291628 return true;
1629
1630 return false;
[email protected]e461da2f2012-02-16 19:06:401631}
1632
[email protected]38cd8f7f2012-06-15 22:06:071633bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1634 return CommandLine::ForCurrentProcess()->HasSwitch(
1635 switches::kPpapiFlashInProcess);
1636}
1637
[email protected]e60c0232011-11-11 19:56:351638#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181639void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1640 const CommandLine& command_line,
1641 base::GlobalDescriptors::Mapping* mappings) {
1642 int crash_signal_fd = GetCrashSignalFD(command_line);
1643 if (crash_signal_fd >= 0) {
1644 mappings->push_back(std::pair<base::GlobalDescriptors::Key, int>(
1645 kCrashDumpSignal, crash_signal_fd));
[email protected]9dbfff12011-07-01 19:37:071646 }
[email protected]b80f68432011-05-02 17:22:301647}
[email protected]e60c0232011-11-11 19:56:351648#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301649
[email protected]4a65826d2011-08-25 16:04:011650#if defined(OS_WIN)
1651const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1652 return chrome::kBrowserResourcesDll;
1653}
1654#endif
1655
[email protected]37a72af2011-06-13 05:42:011656#if defined(USE_NSS)
1657crypto::CryptoModuleBlockingPasswordDelegate*
1658 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1659 const GURL& url) {
1660 return browser::NewCryptoModuleBlockingDialogDelegate(
1661 browser::kCryptoModulePasswordKeygen, url.host());
1662}
1663#endif
1664
[email protected]e9a32a52012-06-14 23:32:431665void ChromeContentBrowserClient::SetApplicationLocale(
1666 const std::string& locale) {
1667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1668
1669 // This object is guaranteed to outlive all threads so we don't have to
1670 // worry about the lack of refcounting and can just post as Unretained.
1671 //
1672 // The common case is that this function is called early in Chrome startup
1673 // before any threads are created (it will also be called later if the user
1674 // changes the pref). In this case, there will be no threads created and
1675 // posting will fail. When there are no threads, we can just set the string
1676 // without worrying about threadsafety.
1677 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1678 base::Bind(
1679 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1680 base::Unretained(this), locale)))
1681 io_thread_application_locale_ = locale;
1682}
1683
1684void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1685 const std::string& locale) {
1686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1687 io_thread_application_locale_ = locale;
1688}
1689
[email protected]d977f9c2011-03-14 16:10:261690} // namespace chrome