blob: f3b9c54c3f5a6e47f4b99550d83867266964cb11 [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]3d4d4cf2012-06-04 10:40:5518#include "chrome/browser/browsing_data_helper.h"
[email protected]3b8f7e32011-07-13 11:52:2319#include "chrome/browser/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]f364d1392011-04-08 21:03:1032#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]9c1662b2012-03-06 15:44:3333#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2634#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0835#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2536#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0637#include "chrome/browser/extensions/extension_webkit_preferences.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]29b25d092011-06-29 20:57:3498#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4099#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:06100#include "net/cookies/cookie_monster.h"
101#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]6653c192012-04-10 22:52:44123#include "chrome/browser/crash_handler_host_linuxish.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]1c321ee2012-05-21 03:02:34138using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25139using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39140
[email protected]c5dbef02011-05-13 05:06:09141namespace {
142
[email protected]e461da2f2012-02-16 19:06:40143const char* kPredefinedAllowedSocketOrigins[] = {
144 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18145 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45146 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
147 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
148 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
149 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35150 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54151 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
152 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
153 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
154 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
155 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
156 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
157 "ghbfeebgmiidnnmeobbbaiamklmpbpii" // see crbug.com/134099
[email protected]e461da2f2012-02-16 19:06:40158};
159
[email protected]b8148ac2011-07-13 22:03:25160// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42161bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50162 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
163 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25164 return false;
165
[email protected]fe69558d2012-03-12 11:34:49166#if defined(OS_CHROMEOS)
167 // Special case : in ChromeOS in Guest mode bookmarks and history are
168 // disabled for security reasons. New tab page explains the reasons, so
169 // we redirect user to new tab page.
170 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
171 if (url->SchemeIs(chrome::kChromeUIScheme) &&
172 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
173 url->DomainIs(chrome::kChromeUIHistoryHost))) {
174 // Rewrite with new tab URL
175 *url = GURL(chrome::kChromeUINewTabURL);
176 }
177 }
178#endif
179
[email protected]b8148ac2011-07-13 22:03:25180 // Special case the new tab page. In older versions of Chrome, the new tab
181 // page was hosted at chrome-internal:<blah>. This might be in people's saved
182 // sessions or bookmarks, so we say any URL with that scheme triggers the new
183 // tab page.
184 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
185 // Rewrite it with the proper new tab URL.
186 *url = GURL(chrome::kChromeUINewTabURL);
187 }
188
189 return true;
190}
191
[email protected]8d3132f62011-10-12 07:13:42192// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
193// below. Extension, and isolated apps require different privileges to be
194// granted to their RenderProcessHosts. This classification allows us to make
195// sure URLs are served by hosts with the right set of privileges.
196enum RenderProcessHostPrivilege {
197 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45198 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42199 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45200 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42201};
202
203RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
204 const GURL& url,
205 ExtensionService* service) {
206 // Default to a normal renderer cause it is lower privileged. This should only
207 // occur if the URL on a site instance is either malformed, or uninitialized.
208 // If it is malformed, then there is no need for better privileges anyways.
209 // If it is uninitialized, but eventually settles on being an a scheme other
210 // than normal webrenderer, the navigation logic will correct us out of band
211 // anyways.
212 if (!url.is_valid())
213 return PRIV_NORMAL;
214
215 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44216 const Extension* extension =
217 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45218 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42219 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45220 if (extension && extension->is_hosted_app())
221 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42222
223 return PRIV_EXTENSION;
224 }
225
226 return PRIV_NORMAL;
227}
228
229RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30230 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46231 extensions::ProcessMap* process_map,
232 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46233 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30234 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46235 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21236 return PRIV_NORMAL;
237
[email protected]6f371442011-11-09 06:45:46238 for (std::set<std::string>::iterator iter = extension_ids.begin();
239 iter != extension_ids.end(); ++iter) {
240 const Extension* extension = service->GetExtensionById(*iter, false);
241 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42242 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45243 if (extension && extension->is_hosted_app())
244 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42245 }
246
[email protected]676f6ab2011-10-19 20:23:21247 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42248}
249
[email protected]eec0b33c2011-12-05 22:09:45250bool IsIsolatedAppInProcess(const GURL& site_url,
251 content::RenderProcessHost* process_host,
252 extensions::ProcessMap* process_map,
253 ExtensionService* service) {
254 std::set<std::string> extension_ids =
255 process_map->GetExtensionsInProcess(process_host->GetID());
256 if (extension_ids.empty())
257 return false;
258
259 for (std::set<std::string>::iterator iter = extension_ids.begin();
260 iter != extension_ids.end(); ++iter) {
261 const Extension* extension = service->GetExtensionById(*iter, false);
262 if (extension &&
263 extension->is_storage_isolated() &&
264 extension->url() == site_url)
265 return true;
266 }
267
268 return false;
269}
270
[email protected]6786bf402011-12-03 15:19:45271bool CertMatchesFilter(const net::X509Certificate& cert,
272 const base::DictionaryValue& filter) {
273 // TODO(markusheintz): This is the minimal required filter implementation.
274 // Implement a better matcher.
275
276 // An empty filter matches any client certificate since no requirements are
277 // specified at all.
278 if (filter.empty())
279 return true;
280
281 std::string common_name;
282 if (filter.GetString("ISSUER.CN", &common_name) &&
283 (cert.issuer().common_name == common_name)) {
284 return true;
285 }
286 return false;
287}
288
[email protected]f3986f82012-01-03 20:00:06289// Fills |map| with the per-script font prefs under path |map_name|.
290void FillFontFamilyMap(const PrefService* prefs,
291 const char* map_name,
292 WebPreferences::ScriptFontFamilyMap* map) {
293 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
294 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
295 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
296 std::string font_family = prefs->GetString(pref_name.c_str());
297 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32298 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06299 }
300}
301
[email protected]a1733df2012-06-22 11:24:18302#if defined(OS_POSIX) && !defined(OS_MACOSX)
303int GetCrashSignalFD(const CommandLine& command_line) {
304 if (command_line.HasSwitch(switches::kExtensionProcess)) {
305 ExtensionCrashHandlerHostLinux* crash_handler =
306 ExtensionCrashHandlerHostLinux::GetInstance();
307 return crash_handler->GetDeathSignalSocket();
308 }
309
310 std::string process_type =
311 command_line.GetSwitchValueASCII(switches::kProcessType);
312
313 if (process_type == switches::kRendererProcess)
314 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
315
316 if (process_type == switches::kPluginProcess)
317 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
318
319 if (process_type == switches::kPpapiPluginProcess)
320 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
321
322 if (process_type == switches::kGpuProcess)
323 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
324
325 return -1;
326}
327#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
328
[email protected]9dbfff12011-07-01 19:37:07329} // namespace
[email protected]c5dbef02011-05-13 05:06:09330
[email protected]d977f9c2011-03-14 16:10:26331namespace chrome {
332
[email protected]e461da2f2012-02-16 19:06:40333ChromeContentBrowserClient::ChromeContentBrowserClient() {
334 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
335 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40336}
337
338ChromeContentBrowserClient::~ChromeContentBrowserClient() {
339}
340
[email protected]bca18382012-06-25 19:15:23341// static
342void ChromeContentBrowserClient::RegisterUserPrefs(PrefService* prefs) {
343 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
344 false,
345 PrefService::UNSYNCABLE_PREF);
346 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
347 true,
348 PrefService::UNSYNCABLE_PREF);
349 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
350 false,
351 PrefService::UNSYNCABLE_PREF);
352}
353
[email protected]50462bf02011-11-21 19:13:31354content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
355 const content::MainFunctionParams& parameters) {
356 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30357 // Construct the Main browser parts based on the OS type.
358#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31359 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04360#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31361 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30362#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31363 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26364#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31365 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14366#elif defined(OS_ANDROID)
367 // Do nothing for Android.
368 // TODO(klobag): Android initialization should use the
369 // *BrowserMainParts class-hierarchy for setting up custom initialization.
370 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30371#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31372 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04373#else
[email protected]b48c9182011-10-26 18:03:30374 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31375 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30376#endif
377
[email protected]c7480942011-11-08 19:18:27378 // Construct additional browser parts. Stages are called in the order in
379 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22380#if defined(TOOLKIT_GTK)
[email protected]38fc5c82012-05-25 15:45:42381 browser::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04382#endif
[email protected]c7480942011-11-08 19:18:27383
384#if defined(TOOLKIT_VIEWS)
[email protected]c27541f2012-05-24 19:25:54385 browser::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27386#endif
387
[email protected]dc04be7c2012-03-15 23:57:49388#if defined(USE_ASH)
[email protected]38fc5c82012-05-25 15:45:42389 browser::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49390#endif
391
[email protected]e050ef142012-03-21 01:04:24392#if defined(USE_AURA)
[email protected]38fc5c82012-05-25 15:45:42393 browser::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24394#endif
395
[email protected]50462bf02011-11-21 19:13:31396 return main_parts;
[email protected]f967b722011-09-07 00:58:04397}
398
[email protected]38b098f2012-03-14 21:11:57399content::WebContentsView*
400 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57401 WebContents* web_contents,
402 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57403 return NULL;
404}
405
406content::WebContentsViewDelegate*
407 ChromeContentBrowserClient::GetWebContentsViewDelegate(
408 content::WebContents* web_contents) {
[email protected]b5d73422012-06-02 23:46:44409 return browser::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32410}
411
[email protected]f364d1392011-04-08 21:03:10412void ChromeContentBrowserClient::RenderViewHostCreated(
413 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46414
[email protected]9f76c1e2012-03-05 15:15:58415 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46416 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02417 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46418
419 new ChromeRenderViewHostObserver(render_view_host,
420 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10421 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26422}
423
[email protected]f3b1a082011-11-18 00:34:30424void ChromeContentBrowserClient::RenderProcessHostCreated(
425 content::RenderProcessHost* host) {
426 int id = host->GetID();
427 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
428 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02429 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30430 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02431#if defined(ENABLE_PRINTING)
[email protected]b5b79d72012-05-24 19:42:28432 host->GetChannel()->AddFilter(new PrintingMessageFilter(id));
[email protected]058e5732012-03-01 22:48:03433#endif
[email protected]f3b1a082011-11-18 00:34:30434 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02435 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30436 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56437#if defined(OS_MACOSX)
438 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
439#endif
[email protected]f3b1a082011-11-18 00:34:30440 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03441 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07442 host->GetChannel()->AddFilter(
443 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38444
[email protected]2ccf45c2011-08-19 23:35:50445 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
446 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07447
448 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56449
450 RendererContentSettingRules rules;
451 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
452 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14453}
454
[email protected]e0ada9c2012-03-20 03:54:43455void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
456 content::BrowserChildProcessHost* host) {
457 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
458}
459
[email protected]863f70a2012-01-27 02:05:50460content::WebUIControllerFactory*
461 ChromeContentBrowserClient::GetWebUIControllerFactory() {
462 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56463}
464
[email protected]3d7474ff2011-07-27 17:47:37465GURL ChromeContentBrowserClient::GetEffectiveURL(
466 content::BrowserContext* browser_context, const GURL& url) {
467 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08468 // Get the effective URL for the given actual URL. If the URL is part of an
469 // installed app, the effective URL is an extension URL with the ID of that
470 // extension as the host. This has the effect of grouping apps together in
471 // a common SiteInstance.
472 if (!profile || !profile->GetExtensionService())
473 return url;
474
[email protected]615d88f2011-12-13 01:47:44475 const Extension* extension = profile->GetExtensionService()->extensions()->
476 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08477 if (!extension)
478 return url;
479
[email protected]15877ca2011-11-18 22:40:52480 // Bookmark apps do not use the hosted app process model, and should be
481 // treated as normal URLs.
482 if (extension->from_bookmark())
483 return url;
484
[email protected]36fb2c7c2011-04-04 15:49:08485 // If the URL is part of an extension's web extent, convert it to an
486 // extension URL.
487 return extension->GetResourceURL(url.path());
488}
489
[email protected]056ad2a2011-07-12 02:13:55490bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37491 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55492 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52493 // Because we expect to use the effective URL, URLs for hosted apps (apart
494 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55495 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
496 return false;
497
[email protected]3d7474ff2011-07-27 17:47:37498 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55499 if (!profile || !profile->GetExtensionService())
500 return false;
501
[email protected]615d88f2011-12-13 01:47:44502 const Extension* extension = profile->GetExtensionService()->extensions()->
503 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55504 if (!extension)
505 return false;
506
507 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53508 // permission, or that does not allow JavaScript access to the background
509 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55510 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53511 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
512 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
513 !extension->allow_background_js_access()) {
514 return false;
515 }
516 }
[email protected]056ad2a2011-07-12 02:13:55517
[email protected]7b54ca02012-03-02 18:06:53518 // Hosted apps that have script access to their background page must use
519 // process per site, since all instances can make synchronous calls to the
520 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55521 return true;
522}
523
[email protected]46fb9442011-12-09 17:57:47524bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
525 return ProfileIOData::IsHandledURL(url);
526}
527
[email protected]2a5221b2011-09-27 23:07:31528bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30529 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31530 const GURL& site_url) {
531 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30532 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42533 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46534 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31535
[email protected]ffa97602011-11-17 17:55:52536 // Don't allow the Task Manager to share a process with anything else.
537 // Otherwise it can affect the renderers it is observing.
538 // Note: we could create another RenderProcessHostPrivilege bucket for
539 // this to allow multiple chrome://tasks instances to share, but that's
540 // a very unlikely case without serious consequences.
541 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
542 return false;
543
[email protected]8d3132f62011-10-12 07:13:42544 // These may be NULL during tests. In that case, just assume any site can
545 // share any host.
[email protected]6f371442011-11-09 06:45:46546 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31547 return true;
548
[email protected]a8c269a2011-10-25 20:17:22549 // Experimental:
550 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
551 // to share a renderer process. (We could allow pages from the same site or
552 // extensions of the same type to share, if we knew what the given process
553 // was dedicated to. Allowing no sharing is simpler for now.) This may
554 // cause resource exhaustion issues if too many sites are open at once.
555 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
556 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
557 return false;
558
[email protected]eec0b33c2011-12-05 22:09:45559 // An isolated app is only allowed to share with the exact same app in order
560 // to provide complete renderer process isolation. This also works around
561 // issue http://crbug.com/85588, where different isolated apps in the same
562 // process would end up using the first app's storage contexts.
563 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42564 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45565 if (privilege_required == PRIV_ISOLATED)
566 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
567
568 // Otherwise, just make sure the process privilege matches the privilege
569 // required by the site.
570 return GetProcessPrivilege(process_host, process_map, service) ==
571 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31572}
573
[email protected]76411f412012-02-22 18:56:06574// This function is trying to limit the amount of processes used by extensions
575// with background pages. It uses a globally set percentage of processes to
576// run such extensions and if the limit is exceeded, it returns true, to
577// indicate to the content module to group extensions together.
578bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
579 content::BrowserContext* browser_context, const GURL& url) {
580 // It has to be a valid URL for us to check for an extension.
581 if (!url.is_valid())
582 return false;
583
584 Profile* profile = Profile::FromBrowserContext(browser_context);
585 ExtensionService* service = profile->GetExtensionService();
586 if (!service)
587 return false;
588
589 // We have to have a valid extension with background page to proceed.
590 const Extension* extension =
591 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
592 if (!extension)
593 return false;
594 if (!extension->has_background_page())
595 return false;
596
597 std::set<int> process_ids;
598 size_t max_process_count =
599 content::RenderProcessHost::GetMaxRendererProcessCount();
600
601 // Go through all profiles to ensure we have total count of extension
602 // processes containing background pages, otherwise one profile can
603 // starve the other.
604 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
605 GetLoadedProfiles();
606 for (size_t i = 0; i < profiles.size(); ++i) {
607 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32608 for (ExtensionProcessManager::const_iterator iter =
609 epm->background_hosts().begin();
610 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06611 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32612 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06613 }
614 }
615
616 if (process_ids.size() >
617 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
618 return true;
619 }
620
621 return false;
622}
623
[email protected]6f371442011-11-09 06:45:46624void ChromeContentBrowserClient::SiteInstanceGotProcess(
625 SiteInstance* site_instance) {
626 CHECK(site_instance->HasProcess());
627
628 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02629 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46630 ExtensionService* service = profile->GetExtensionService();
631 if (!service)
632 return;
633
634 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44635 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33636 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46637 if (!extension)
638 return;
639
[email protected]6bc04fd82011-12-04 02:29:35640 service->process_map()->Insert(extension->id(),
641 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33642 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46643 BrowserThread::PostTask(
644 BrowserThread::IO, FROM_HERE,
645 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24646 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46647 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35648 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33649 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46650}
651
652void ChromeContentBrowserClient::SiteInstanceDeleting(
653 SiteInstance* site_instance) {
654 if (!site_instance->HasProcess())
655 return;
656
657 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02658 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46659 ExtensionService* service = profile->GetExtensionService();
660 if (!service)
661 return;
662
663 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44664 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33665 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46666 if (!extension)
667 return;
668
[email protected]6bc04fd82011-12-04 02:29:35669 service->process_map()->Remove(extension->id(),
670 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33671 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46672 BrowserThread::PostTask(
673 BrowserThread::IO, FROM_HERE,
674 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24675 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46676 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35677 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33678 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46679}
680
[email protected]f05763972012-06-06 18:17:26681bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08682 const GURL& current_url,
683 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26684 if (current_url.is_empty()) {
685 // Always choose a new process when navigating to extension URLs. The
686 // process grouping logic will combine all of a given extension's pages
687 // into the same process.
688 if (new_url.SchemeIs(chrome::kExtensionScheme))
689 return true;
[email protected]e3daf3c2011-10-05 21:17:08690
[email protected]f05763972012-06-06 18:17:26691 return false;
692 }
693
694 // Also, we must switch if one is an extension and the other is not the exact
695 // same extension.
696 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
697 new_url.SchemeIs(chrome::kExtensionScheme)) {
698 if (current_url.GetOrigin() != new_url.GetOrigin())
699 return true;
700 }
701
702 return false;
[email protected]e3daf3c2011-10-05 21:17:08703}
704
[email protected]395045c2012-05-22 15:04:38705bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
706 content::ResourceContext* resource_context, const GURL& current_url,
707 const GURL& new_url) {
708 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
709 return extensions::CrossesExtensionProcessBoundary(
710 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17711 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38712}
713
[email protected]763ec4ca2011-04-29 15:48:12714std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
715 const std::string& alias_name) {
716 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
717}
718
[email protected]b80f68432011-05-02 17:22:30719void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
720 CommandLine* command_line, int child_process_id) {
721#if defined(USE_LINUX_BREAKPAD)
722 if (IsCrashReporterEnabled()) {
723 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
724 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
725 }
726#elif defined(OS_MACOSX)
727 if (IsCrashReporterEnabled()) {
728 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
729 child_process_logging::GetClientId());
730 }
731#endif // OS_MACOSX
732
[email protected]f1933792011-06-14 00:49:34733 if (logging::DialogsAreSuppressed())
734 command_line->AppendSwitch(switches::kNoErrorDialogs);
735
[email protected]b80f68432011-05-02 17:22:30736 std::string process_type =
737 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17738 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52739 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30740 FilePath user_data_dir =
741 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
742 if (!user_data_dir.empty())
743 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
744#if defined(OS_CHROMEOS)
745 const std::string& login_profile =
746 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
747 if (!login_profile.empty())
748 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
749#endif
750
[email protected]f3b1a082011-11-18 00:34:30751 content::RenderProcessHost* process =
752 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37753 if (process) {
754 Profile* profile = Profile::FromBrowserContext(
755 process->GetBrowserContext());
756 extensions::ProcessMap* process_map =
757 profile->GetExtensionService()->process_map();
758 if (process_map && process_map->Contains(process->GetID()))
759 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30760
[email protected]a8d851f82011-12-21 00:32:37761 PrefService* prefs = profile->GetPrefs();
762 // Currently this pref is only registered if applied via a policy.
763 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
764 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
765 // Turn this policy into a command line switch.
766 command_line->AppendSwitch(switches::kDisable3DAPIs);
767 }
[email protected]718eab62011-10-05 21:16:52768
[email protected]a8d851f82011-12-21 00:32:37769 // Disable client-side phishing detection in the renderer if it is
770 // disabled in the Profile preferences or the browser process.
771 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
772 !g_browser_process->safe_browsing_detection_service()) {
773 command_line->AppendSwitch(
774 switches::kDisableClientSidePhishingDetection);
775 }
[email protected]8c40da62011-07-13 22:58:46776 }
[email protected]47c7ec82012-01-18 03:29:21777 {
778 PrefService* local_state = g_browser_process->local_state();
779 if (local_state &&
780 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
781 command_line->AppendSwitch(switches::kRendererPrintPreview);
782 }
783 }
[email protected]4287a3d2011-06-13 23:56:51784
[email protected]47c7ec82012-01-18 03:29:21785 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51786 static const char* const kSwitchNames[] = {
787 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48788 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51789 switches::kAllowScriptingGallery,
790 switches::kAppsCheckoutURL,
791 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31792 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51793 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10794 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50795 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53796 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09797 switches::kDisableInBrowserThumbnailing,
[email protected]4287a3d2011-06-13 23:56:51798 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21799 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13800 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51801 switches::kEnableCrxlessWebApps,
802 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:51803 switches::kEnableIPCFuzzing,
804 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05805 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48806 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:51807 switches::kEnableWatchdog,
808 switches::kExperimentalSpellcheckerFeatures,
809 switches::kMemoryProfiling,
810 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37811 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:37812 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51813 switches::kPpapiFlashArgs,
814 switches::kPpapiFlashInProcess,
815 switches::kPpapiFlashPath,
816 switches::kPpapiFlashVersion,
817 switches::kProfilingAtStart,
818 switches::kProfilingFile,
819 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37820 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51821 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38822 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51823 };
824
825 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
826 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17827 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38828 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35829 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38830 switches::kEnableExperimentalExtensionApis,
831 switches::kWhitelistedExtensionID,
832 };
833
834 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
835 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51836 } else if (process_type == switches::kPluginProcess) {
837 static const char* const kSwitchNames[] = {
838 #if defined(OS_CHROMEOS)
839 switches::kLoginProfile,
840 #endif
841 switches::kMemoryProfiling,
842 switches::kSilentDumpOnDCHECK,
843 switches::kUserDataDir,
844 };
845
846 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
847 arraysize(kSwitchNames));
848 } else if (process_type == switches::kZygoteProcess) {
849 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51850 switches::kUserDataDir, // Make logs go to the right file.
851 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50852 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13853 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51854 switches::kPpapiFlashInProcess,
855 switches::kPpapiFlashPath,
856 switches::kPpapiFlashVersion,
857 };
858
859 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
860 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11861 } else if (process_type == switches::kGpuProcess) {
862 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
863 // because GPU is expected to be unreliable.
864 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
865 !command_line->HasSwitch(switches::kDisableBreakpad))
866 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30867 }
[email protected]6f08af82011-09-15 01:19:03868
869 // The command line switch kEnableBenchmarking needs to be specified along
870 // with the kEnableStatsTable switch to ensure that the stats table global
871 // is initialized correctly.
872 if (command_line->HasSwitch(switches::kEnableBenchmarking))
873 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30874}
875
876std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:43877 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
878 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:30879 return g_browser_process->GetApplicationLocale();
880}
881
[email protected]597a867b2011-11-18 18:31:20882std::string ChromeContentBrowserClient::GetAcceptLangs(
883 content::BrowserContext* context) {
884 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37885 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08886}
887
[email protected]9ec0f452012-05-31 15:58:53888gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22889 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:53890 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:08891}
892
[email protected]a2176792011-05-08 19:30:49893bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09894 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19895 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20896 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32897 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20898 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05899 return io_data->GetCookieSettings()->
900 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49901}
902
[email protected]ed24fad2011-05-10 22:44:01903bool ChromeContentBrowserClient::AllowGetCookie(
904 const GURL& url,
905 const GURL& first_party,
906 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20907 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01908 int render_process_id,
909 int render_view_id) {
910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20911 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05912 bool allow = io_data->GetCookieSettings()->
913 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01914
[email protected]8093a542011-05-13 07:29:32915 BrowserThread::PostTask(
916 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03917 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43918 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01919 return allow;
920}
921
922bool ChromeContentBrowserClient::AllowSetCookie(
923 const GURL& url,
924 const GURL& first_party,
925 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20926 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01927 int render_process_id,
928 int render_view_id,
929 net::CookieOptions* options) {
930 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20931 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05932 CookieSettings* cookie_settings = io_data->GetCookieSettings();
933 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
934
[email protected]8093a542011-05-13 07:29:32935 BrowserThread::PostTask(
936 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03937 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43938 render_view_id, url, first_party, cookie_line, *options,
939 !allow));
[email protected]ed24fad2011-05-10 22:44:01940 return allow;
941}
942
[email protected]d5a19162011-06-30 18:51:54943bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20944 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20946 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:43947 CookieSettings* cookie_settings = io_data->GetCookieSettings();
948 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:26949
[email protected]bf510ed2012-06-05 08:31:43950 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
951 // Could we even support per-origin settings?
952 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:54953}
954
[email protected]5c5a88e2011-11-12 00:45:35955bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35956 const GURL& url,
957 const string16& name,
958 const string16& display_name,
959 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20960 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48961 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20963 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35964 CookieSettings* cookie_settings = io_data->GetCookieSettings();
965 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
966
[email protected]62151052012-02-01 18:40:48967 // Record access to database for potential display in UI.
968 std::vector<std::pair<int, int> >::const_iterator i;
969 for (i = render_views.begin(); i != render_views.end(); ++i) {
970 BrowserThread::PostTask(
971 BrowserThread::UI, FROM_HERE,
972 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
973 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35974 }
975
976 return allow;
977}
978
979bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35980 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20981 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48982 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20984 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35985 CookieSettings* cookie_settings = io_data->GetCookieSettings();
986 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
987
[email protected]62151052012-02-01 18:40:48988 // Record access to file system for potential display in UI.
989 std::vector<std::pair<int, int> >::const_iterator i;
990 for (i = render_views.begin(); i != render_views.end(); ++i) {
991 BrowserThread::PostTask(
992 BrowserThread::UI, FROM_HERE,
993 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
994 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35995 }
996
997 return allow;
998}
999
[email protected]7c5ff9a2012-03-02 07:42:491000bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1001 const GURL& url,
1002 const string16& name,
1003 content::ResourceContext* context,
1004 const std::vector<std::pair<int, int> >& render_views) {
1005 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1006 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1007 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1008 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1009
1010 // Record access to IndexedDB for potential display in UI.
1011 std::vector<std::pair<int, int> >::const_iterator i;
1012 for (i = render_views.begin(); i != render_views.end(); ++i) {
1013 BrowserThread::PostTask(
1014 BrowserThread::UI, FROM_HERE,
1015 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1016 i->first, i->second, url, name, !allow));
1017 }
1018
1019 return allow;
1020}
1021
[email protected]6133f922011-07-01 21:34:341022net::URLRequestContext*
1023ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201024 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341025 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1026 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201027 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341028 return io_data->extensions_request_context();
1029 }
1030
1031 return NULL;
1032}
1033
[email protected]317f96c92011-05-31 06:53:411034QuotaPermissionContext*
1035ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1036 return new ChromeQuotaPermissionContext();
1037}
1038
[email protected]a0ce3282011-08-19 20:49:521039void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421040 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421041}
1042
[email protected]a0ce3282011-08-19 20:49:521043void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521044 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521045}
1046
[email protected]848dd042011-06-04 18:24:031047void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171048 int render_process_id,
1049 int render_view_id,
1050 int cert_error,
1051 const net::SSLInfo& ssl_info,
1052 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031053 bool overridable,
[email protected]d9be47702012-05-16 03:41:221054 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171055 const base::Callback<void(bool)>& callback,
1056 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411057 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131058 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171059 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411060 if (!tab) {
1061 NOTREACHED();
1062 return;
1063 }
1064 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501065 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301066 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091067 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411068 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171069 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411070 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171071 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411072 return;
1073 }
1074 }
1075
1076 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221077 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1078 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031079}
1080
[email protected]c99c442e2011-08-24 11:37:301081void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451082 int render_process_id,
1083 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401084 const net::HttpNetworkSession* network_session,
1085 net::SSLCertRequestInfo* cert_request_info,
1086 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131087 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451088 render_process_id, render_view_id);
1089 if (!tab) {
1090 NOTREACHED();
1091 return;
1092 }
1093
[email protected]6786bf402011-12-03 15:19:451094 GURL requesting_url("https://" + cert_request_info->host_and_port);
1095 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1096 << cert_request_info->host_and_port;
1097
[email protected]627e0512011-12-21 22:55:301098 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451099 scoped_ptr<Value> filter(
1100 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1101 requesting_url,
1102 requesting_url,
1103 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1104 std::string(), NULL));
1105
1106 if (filter.get()) {
1107 // Try to automatically select a client certificate.
1108 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1109 DictionaryValue* filter_dict =
1110 static_cast<DictionaryValue*>(filter.get());
1111
1112 const std::vector<scoped_refptr<net::X509Certificate> >&
1113 all_client_certs = cert_request_info->client_certs;
1114 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1115 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1116 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401117 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451118 return;
1119 }
1120 }
1121 } else {
1122 NOTREACHED();
1123 }
1124 }
1125
[email protected]871dc682012-06-11 19:35:331126 TabContents* tab_contents = TabContents::FromWebContents(tab);
1127 if (!tab_contents) {
1128 // If there is no TabContents for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451129 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141130 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401131 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451132 return;
1133 }
[email protected]871dc682012-06-11 19:35:331134 tab_contents->ssl_helper()->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401135 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451136}
1137
1138void ChromeContentBrowserClient::AddNewCertificate(
1139 net::URLRequest* request,
1140 net::X509Certificate* cert,
1141 int render_process_id,
1142 int render_view_id) {
1143 // The handler will run the UI and delete itself when it's finished.
1144 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1145}
1146
[email protected]dc73a7b2012-03-25 15:27:181147content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1148 return MediaInternals::GetInstance();
1149}
1150
[email protected]941623e2011-06-07 23:06:041151void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1152 const GURL& source_origin,
1153 int callback_context,
1154 int render_process_id,
1155 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111156#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021157 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1158 WebContents* contents =
1159 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1160 if (!contents) {
[email protected]941623e2011-06-07 23:06:041161 NOTREACHED();
1162 return;
1163 }
1164
[email protected]d0d9c3ee2012-06-19 03:07:021165 // Skip showing the infobar if the request comes from an extension, and that
1166 // extension has the 'notify' permission. (If the extension does not have the
1167 // permission, the user will still be prompted.)
1168 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
1169 ExtensionService* service = profile->GetExtensionService();
1170 const Extension* extension = !service ? NULL :
1171 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1172 source_origin));
1173 if (extension &&
1174 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
1175 RenderViewHost* rvh =
1176 RenderViewHost::FromID(render_process_id, render_view_id);
1177 if (rvh)
1178 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1179 return;
1180 }
1181
1182 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371183 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021184 notifications->RequestPermission(source_origin, render_process_id,
1185 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111186#else
1187 NOTIMPLEMENTED();
1188#endif
[email protected]941623e2011-06-07 23:06:041189}
1190
1191WebKit::WebNotificationPresenter::Permission
1192 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021193 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201194 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021195 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111196#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201198 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021199 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1200 source_origin, render_process_id,
1201 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041202 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041203
1204 // Fall back to the regular notification preferences, which works on an
1205 // origin basis.
1206 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371207 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041208 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111209#else
1210 return WebKit::WebNotificationPresenter::PermissionAllowed;
1211#endif
[email protected]941623e2011-06-07 23:06:041212}
1213
1214void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171215 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041216 int render_process_id,
1217 int render_view_id,
1218 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111219#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041220 RenderViewHost* rvh = RenderViewHost::FromID(
1221 render_process_id, render_view_id);
1222 if (!rvh) {
1223 NOTREACHED();
1224 return;
1225 }
1226
[email protected]9f76c1e2012-03-05 15:15:581227 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301228 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041229 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371230 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041231 service->ShowDesktopNotification(
1232 params, render_process_id, render_view_id,
1233 worker ? DesktopNotificationService::WorkerNotification :
1234 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111235#else
1236 NOTIMPLEMENTED();
1237#endif
[email protected]941623e2011-06-07 23:06:041238}
1239
1240void ChromeContentBrowserClient::CancelDesktopNotification(
1241 int render_process_id,
1242 int render_view_id,
1243 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111244#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041245 RenderViewHost* rvh = RenderViewHost::FromID(
1246 render_process_id, render_view_id);
1247 if (!rvh) {
1248 NOTREACHED();
1249 return;
1250 }
1251
[email protected]9f76c1e2012-03-05 15:15:581252 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301253 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041254 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371255 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041256 service->CancelDesktopNotification(
1257 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111258#else
1259 NOTIMPLEMENTED();
1260#endif
[email protected]941623e2011-06-07 23:06:041261}
1262
[email protected]9f3fba52011-06-08 20:37:191263bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351264 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021265 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191266 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201267 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011268 int render_process_id,
1269 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011271
1272 *no_javascript_access = false;
1273
[email protected]9f3fba52011-06-08 20:37:191274 // If the opener is trying to create a background window but doesn't have
1275 // the appropriate permission, fail the attempt.
1276 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201277 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531278 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1279
[email protected]03b6d552012-03-29 04:03:011280 if (!map->SecurityOriginHasAPIPermission(
1281 source_origin,
1282 render_process_id,
1283 ExtensionAPIPermission::kBackground)) {
1284 return false;
1285 }
1286
[email protected]7b54ca02012-03-02 18:06:531287 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1288 // return a recently installed Extension even if this CanCreateWindow call
1289 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011290 // because the permission check above would have caused an early return
1291 // already. We must use the full URL to find hosted apps, though, and not
1292 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531293 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351294 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531295 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011296 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191297 }
1298 return true;
1299}
1300
1301std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201302 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1304 // Check if it's an extension-created worker, in which case we want to use
1305 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201306 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191307 const Extension* extension =
1308 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1309 return extension ? extension->name() : std::string();
1310}
1311
[email protected]99907362012-01-11 05:41:401312void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1313 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171314}
1315
[email protected]c52b2892012-03-07 11:01:021316content::SpeechRecognitionManagerDelegate*
1317 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321318#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021319 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321320#else
1321 return NULL;
1322#endif
[email protected]66cfec62012-02-24 17:57:511323}
1324
[email protected]ae6e9912011-07-27 01:18:281325net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1326 return g_browser_process->net_log();
1327}
1328
[email protected]32538d92011-08-25 00:09:231329AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1330 return new ChromeAccessTokenStore();
1331}
1332
[email protected]dbae6b02011-06-29 23:51:411333bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1334 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1335 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1336}
1337
[email protected]64d69de42012-02-06 00:19:541338void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321339 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061340 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581341 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061342 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061343
[email protected]f3986f82012-01-03 20:00:061344 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541345 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061346 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541347 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061348 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541349 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061350 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541351 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061352 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541353 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061354 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541355 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061356
[email protected]64d69de42012-02-06 00:19:541357 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401358 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541359 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401360 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541361 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401362 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541363 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401364 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061365
[email protected]ddf72142012-05-22 04:52:401366 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061367
[email protected]64d69de42012-02-06 00:19:541368 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401369 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541370 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061371 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541372 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061373 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1374 const DictionaryValue* inspector_settings =
1375 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1376 if (inspector_settings) {
1377 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1378 iter != inspector_settings->end_keys(); ++iter) {
1379 std::string value;
1380 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541381 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061382 std::make_pair(*iter, value));
1383 }
1384 }
[email protected]64d69de42012-02-06 00:19:541385 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061386
[email protected]ddf72142012-05-22 04:52:401387 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541388 web_prefs->javascript_enabled = false;
1389 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1390 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401391 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541392 web_prefs->plugins_enabled = false;
1393 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1394 web_prefs->java_enabled = false;
1395 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401396 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061397
[email protected]64d69de42012-02-06 00:19:541398 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1399 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061400
[email protected]64d69de42012-02-06 00:19:541401 web_prefs->memory_info_enabled =
1402 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1403 web_prefs->allow_displaying_insecure_content =
1404 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1405 web_prefs->allow_running_insecure_content =
1406 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081407 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061408
[email protected]64d69de42012-02-06 00:19:541409 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151410 UserStyleSheetWatcher* user_style_sheet_watcher =
1411 UserStyleSheetWatcherFactory::GetForProfile(profile);
1412 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541413 web_prefs->user_style_sheet_enabled = true;
1414 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151415 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541416 } else {
1417 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061418 }
1419
[email protected]b7e44ff2012-02-16 03:37:341420 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101421#if defined(OS_MACOSX)
1422 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1423 // Mac so it uses NSSpellChecker in the background.
1424 false;
1425#else
1426 !CommandLine::ForCurrentProcess()->
1427 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1428#endif
[email protected]b7e44ff2012-02-16 03:37:341429 web_prefs->unified_textchecker_enabled =
1430 web_prefs->asynchronous_spell_checking_enabled ||
1431 CommandLine::ForCurrentProcess()->
1432 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571433
[email protected]64d69de42012-02-06 00:19:541434 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061435 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541436 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061437 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541438 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061439 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1440
1441 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541442 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061443 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541444 web_prefs->default_encoding);
1445 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401446 prefs->ClearPref(prefs::kDefaultCharset);
1447 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061448 }
[email protected]64d69de42012-02-06 00:19:541449 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061450
[email protected]299d7f12012-05-23 05:31:151451 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1452 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061453 ExtensionService* service = profile->GetExtensionService();
1454 if (service) {
1455 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581456 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061457 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151458 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061459 }
1460
[email protected]4abe58d2012-06-08 03:09:091461 if (gpu_util::InForceCompositingModeTrial())
1462 web_prefs->force_compositing_mode = true;
1463
[email protected]299d7f12012-05-23 05:31:151464 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541465 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151466 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061467 // Disable all kinds of acceleration for background pages.
1468 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541469 web_prefs->force_compositing_mode = false;
1470 web_prefs->accelerated_compositing_enabled = false;
1471 web_prefs->accelerated_2d_canvas_enabled = false;
1472 web_prefs->accelerated_video_enabled = false;
1473 web_prefs->accelerated_painting_enabled = false;
1474 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061475 }
[email protected]2e21fe292012-03-02 22:52:321476
1477#if defined(FILE_MANAGER_EXTENSION)
1478 // Override the default of suppressing HW compositing for WebUI pages for the
1479 // file manager, which is implemented using WebUI but wants HW acceleration
1480 // for video decode & render.
1481 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1482 web_prefs->accelerated_compositing_enabled = true;
1483 web_prefs->accelerated_2d_canvas_enabled = true;
1484 }
1485#endif
[email protected]181a95ee2011-07-12 19:26:361486}
1487
1488void ChromeContentBrowserClient::UpdateInspectorSetting(
1489 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061490 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581491 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061492 DictionaryPrefUpdate update(
1493 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1494 prefs::kWebKitInspectorSettings);
1495 DictionaryValue* inspector_settings = update.Get();
1496 inspector_settings->SetWithoutPathExpansion(key,
1497 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361498}
1499
1500void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061501 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581502 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061503 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1504 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361505}
1506
[email protected]b8148ac2011-07-13 22:03:251507void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1508 BrowserURLHandler* handler) {
1509 // Add the default URL handlers.
1510 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1511 BrowserURLHandler::null_handler());
1512 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1513 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1514
[email protected]b3adbd02011-11-30 22:23:271515 // about: handler. Must come before chrome: handler, since it will
1516 // rewrite about: urls to chrome: URLs and then expect chrome: to
1517 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251518 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1519 BrowserURLHandler::null_handler());
1520 // chrome: & friends.
1521 handler->AddHandlerPair(&HandleWebUI,
1522 BrowserURLHandler::null_handler());
1523}
1524
1525void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371526 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581527 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251528 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1529 BrowsingDataRemover::EVERYTHING,
1530 base::Time());
[email protected]3d4d4cf2012-06-04 10:40:551531 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1532 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251533 // BrowsingDataRemover takes care of deleting itself when done.
1534}
1535
1536void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371537 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581538 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251539 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1540 BrowsingDataRemover::EVERYTHING,
1541 base::Time());
[email protected]dceaa912011-09-06 17:17:231542 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551543 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251544 // BrowsingDataRemover takes care of deleting itself when done.
1545}
1546
[email protected]e1d16eb92011-08-18 23:19:321547FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1548 return download_util::GetDefaultDownloadDirectory();
1549}
1550
[email protected]c9b6eb62011-10-18 20:49:391551std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1552 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1553}
1554
[email protected]38cd8f7f2012-06-15 22:06:071555bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]a658d452012-03-02 12:45:291556 content::BrowserContext* browser_context, const GURL& url) {
1557 if (!url.is_valid())
1558 return false;
1559
1560 std::string host = url.host();
[email protected]92444942012-06-16 09:05:281561 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host))
[email protected]a658d452012-03-02 12:45:291562 return true;
1563
[email protected]9a5940d2012-04-27 19:16:231564 Profile* profile = Profile::FromBrowserContext(browser_context);
1565 const Extension* extension = NULL;
1566 if (profile && profile->GetExtensionService()) {
1567 extension = profile->GetExtensionService()->extensions()->
1568 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1569 }
1570
[email protected]f237c0f2012-03-10 07:49:101571 // Need to check this now and not on construction because otherwise it won't
1572 // work with browser_tests.
1573 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1574 std::string allowed_list =
1575 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231576 if (allowed_list == "*") {
1577 // The wildcard allows socket API only for packaged and platform apps.
1578 return extension &&
1579 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1580 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1581 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101582 StringTokenizer t(allowed_list, ",");
1583 while (t.GetNext()) {
1584 if (t.token() == host)
1585 return true;
1586 }
1587 }
1588
[email protected]a658d452012-03-02 12:45:291589 if (!extension)
1590 return false;
1591
1592 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1593 return true;
1594
1595 return false;
[email protected]e461da2f2012-02-16 19:06:401596}
1597
[email protected]38cd8f7f2012-06-15 22:06:071598bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1599 return CommandLine::ForCurrentProcess()->HasSwitch(
1600 switches::kPpapiFlashInProcess);
1601}
1602
[email protected]e60c0232011-11-11 19:56:351603#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181604void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1605 const CommandLine& command_line,
1606 base::GlobalDescriptors::Mapping* mappings) {
1607 int crash_signal_fd = GetCrashSignalFD(command_line);
1608 if (crash_signal_fd >= 0) {
1609 mappings->push_back(std::pair<base::GlobalDescriptors::Key, int>(
1610 kCrashDumpSignal, crash_signal_fd));
[email protected]9dbfff12011-07-01 19:37:071611 }
[email protected]b80f68432011-05-02 17:22:301612}
[email protected]e60c0232011-11-11 19:56:351613#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301614
[email protected]4a65826d2011-08-25 16:04:011615#if defined(OS_WIN)
1616const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1617 return chrome::kBrowserResourcesDll;
1618}
1619#endif
1620
[email protected]37a72af2011-06-13 05:42:011621#if defined(USE_NSS)
1622crypto::CryptoModuleBlockingPasswordDelegate*
1623 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1624 const GURL& url) {
1625 return browser::NewCryptoModuleBlockingDialogDelegate(
1626 browser::kCryptoModulePasswordKeygen, url.host());
1627}
1628#endif
1629
[email protected]e9a32a52012-06-14 23:32:431630void ChromeContentBrowserClient::SetApplicationLocale(
1631 const std::string& locale) {
1632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1633
1634 // This object is guaranteed to outlive all threads so we don't have to
1635 // worry about the lack of refcounting and can just post as Unretained.
1636 //
1637 // The common case is that this function is called early in Chrome startup
1638 // before any threads are created (it will also be called later if the user
1639 // changes the pref). In this case, there will be no threads created and
1640 // posting will fail. When there are no threads, we can just set the string
1641 // without worrying about threadsafety.
1642 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1643 base::Bind(
1644 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1645 base::Unretained(this), locale)))
1646 io_thread_application_locale_ = locale;
1647}
1648
1649void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1650 const std::string& locale) {
1651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1652 io_thread_application_locale_ = locale;
1653}
1654
[email protected]d977f9c2011-03-14 16:10:261655} // namespace chrome