blob: 5c0142a658d6e113de05a93b275e4a0f0c5c02cf [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]117b6b42012-02-29 09:11:0840#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1841#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2842#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0443#include "chrome/browser/notifications/desktop_notification_service.h"
44#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4345#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4246#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0648#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4149#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5050#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0751#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4152#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1453#include "chrome/browser/printing/printing_message_filter.h"
54#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3255#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0656#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1457#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3358#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4259#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1460#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0261#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4662#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0364#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4565#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
66#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5467#include "chrome/browser/toolkit_extra_parts.h"
[email protected]117b6b42012-02-29 09:11:0868#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]b5d73422012-06-02 23:46:4469#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]8ec26472011-06-06 16:52:4570#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.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]c9b6eb62011-10-18 20:49:3996#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3497#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4098#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0699#include "net/cookies/cookie_monster.h"
100#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:39101#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08102#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36103#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04104#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26105
[email protected]b48c9182011-10-26 18:03:30106#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38107#include "chrome/browser/chrome_browser_main_win.h"
108#elif defined(OS_MACOSX)
109#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56110#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30111#elif defined(OS_CHROMEOS)
112#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49113#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26114#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30115#include "chrome/browser/chrome_browser_main_linux.h"
116#elif defined(OS_POSIX)
117#include "chrome/browser/chrome_browser_main_posix.h"
118#endif
119
[email protected]6653c192012-04-10 22:52:44120#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30121#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44122#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43123#endif
[email protected]b80f68432011-05-02 17:22:30124
[email protected]37a72af2011-06-13 05:42:01125#if defined(USE_NSS)
126#include "chrome/browser/ui/crypto_module_password_dialog.h"
127#endif
128
[email protected]c8c77182011-12-21 15:04:47129using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39130using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31131using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59132using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00133using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11134using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33135using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13136using content::WebContents;
[email protected]1c321ee2012-05-21 03:02:34137using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25138using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39139
[email protected]c5dbef02011-05-13 05:06:09140namespace {
141
[email protected]e461da2f2012-02-16 19:06:40142const char* kPredefinedAllowedSocketOrigins[] = {
143 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18144 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45145 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
146 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
147 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
148 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35149 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
150 "cbkkbcmdlboombapidmoeolnmdacpkch" // see crbug.com/129089
[email protected]e461da2f2012-02-16 19:06:40151};
152
[email protected]b8148ac2011-07-13 22:03:25153// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42154bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50155 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
156 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25157 return false;
158
[email protected]fe69558d2012-03-12 11:34:49159#if defined(OS_CHROMEOS)
160 // Special case : in ChromeOS in Guest mode bookmarks and history are
161 // disabled for security reasons. New tab page explains the reasons, so
162 // we redirect user to new tab page.
163 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
164 if (url->SchemeIs(chrome::kChromeUIScheme) &&
165 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
166 url->DomainIs(chrome::kChromeUIHistoryHost))) {
167 // Rewrite with new tab URL
168 *url = GURL(chrome::kChromeUINewTabURL);
169 }
170 }
171#endif
172
[email protected]b8148ac2011-07-13 22:03:25173 // Special case the new tab page. In older versions of Chrome, the new tab
174 // page was hosted at chrome-internal:<blah>. This might be in people's saved
175 // sessions or bookmarks, so we say any URL with that scheme triggers the new
176 // tab page.
177 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
178 // Rewrite it with the proper new tab URL.
179 *url = GURL(chrome::kChromeUINewTabURL);
180 }
181
182 return true;
183}
184
[email protected]8d3132f62011-10-12 07:13:42185// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
186// below. Extension, and isolated apps require different privileges to be
187// granted to their RenderProcessHosts. This classification allows us to make
188// sure URLs are served by hosts with the right set of privileges.
189enum RenderProcessHostPrivilege {
190 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45191 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42192 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45193 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42194};
195
196RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
197 const GURL& url,
198 ExtensionService* service) {
199 // Default to a normal renderer cause it is lower privileged. This should only
200 // occur if the URL on a site instance is either malformed, or uninitialized.
201 // If it is malformed, then there is no need for better privileges anyways.
202 // If it is uninitialized, but eventually settles on being an a scheme other
203 // than normal webrenderer, the navigation logic will correct us out of band
204 // anyways.
205 if (!url.is_valid())
206 return PRIV_NORMAL;
207
208 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44209 const Extension* extension =
210 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45211 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42212 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45213 if (extension && extension->is_hosted_app())
214 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42215
216 return PRIV_EXTENSION;
217 }
218
219 return PRIV_NORMAL;
220}
221
222RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30223 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46224 extensions::ProcessMap* process_map,
225 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46226 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30227 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46228 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21229 return PRIV_NORMAL;
230
[email protected]6f371442011-11-09 06:45:46231 for (std::set<std::string>::iterator iter = extension_ids.begin();
232 iter != extension_ids.end(); ++iter) {
233 const Extension* extension = service->GetExtensionById(*iter, false);
234 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42235 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45236 if (extension && extension->is_hosted_app())
237 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42238 }
239
[email protected]676f6ab2011-10-19 20:23:21240 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42241}
242
[email protected]eec0b33c2011-12-05 22:09:45243bool IsIsolatedAppInProcess(const GURL& site_url,
244 content::RenderProcessHost* process_host,
245 extensions::ProcessMap* process_map,
246 ExtensionService* service) {
247 std::set<std::string> extension_ids =
248 process_map->GetExtensionsInProcess(process_host->GetID());
249 if (extension_ids.empty())
250 return false;
251
252 for (std::set<std::string>::iterator iter = extension_ids.begin();
253 iter != extension_ids.end(); ++iter) {
254 const Extension* extension = service->GetExtensionById(*iter, false);
255 if (extension &&
256 extension->is_storage_isolated() &&
257 extension->url() == site_url)
258 return true;
259 }
260
261 return false;
262}
263
[email protected]6786bf402011-12-03 15:19:45264bool CertMatchesFilter(const net::X509Certificate& cert,
265 const base::DictionaryValue& filter) {
266 // TODO(markusheintz): This is the minimal required filter implementation.
267 // Implement a better matcher.
268
269 // An empty filter matches any client certificate since no requirements are
270 // specified at all.
271 if (filter.empty())
272 return true;
273
274 std::string common_name;
275 if (filter.GetString("ISSUER.CN", &common_name) &&
276 (cert.issuer().common_name == common_name)) {
277 return true;
278 }
279 return false;
280}
281
[email protected]f3986f82012-01-03 20:00:06282// Fills |map| with the per-script font prefs under path |map_name|.
283void FillFontFamilyMap(const PrefService* prefs,
284 const char* map_name,
285 WebPreferences::ScriptFontFamilyMap* map) {
286 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
287 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
288 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
289 std::string font_family = prefs->GetString(pref_name.c_str());
290 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32291 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06292 }
293}
294
[email protected]9dbfff12011-07-01 19:37:07295} // namespace
[email protected]c5dbef02011-05-13 05:06:09296
[email protected]d977f9c2011-03-14 16:10:26297namespace chrome {
298
[email protected]e461da2f2012-02-16 19:06:40299ChromeContentBrowserClient::ChromeContentBrowserClient() {
300 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
301 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40302}
303
304ChromeContentBrowserClient::~ChromeContentBrowserClient() {
305}
306
[email protected]50462bf02011-11-21 19:13:31307content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
308 const content::MainFunctionParams& parameters) {
309 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30310 // Construct the Main browser parts based on the OS type.
311#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31312 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04313#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31314 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30315#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31316 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26317#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31318 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14319#elif defined(OS_ANDROID)
320 // Do nothing for Android.
321 // TODO(klobag): Android initialization should use the
322 // *BrowserMainParts class-hierarchy for setting up custom initialization.
323 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30324#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31325 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04326#else
[email protected]b48c9182011-10-26 18:03:30327 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31328 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30329#endif
330
[email protected]c7480942011-11-08 19:18:27331 // Construct additional browser parts. Stages are called in the order in
332 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22333#if defined(TOOLKIT_GTK)
[email protected]38fc5c82012-05-25 15:45:42334 browser::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04335#endif
[email protected]c7480942011-11-08 19:18:27336
337#if defined(TOOLKIT_VIEWS)
[email protected]c27541f2012-05-24 19:25:54338 browser::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27339#endif
340
[email protected]dc04be7c2012-03-15 23:57:49341#if defined(USE_ASH)
[email protected]38fc5c82012-05-25 15:45:42342 browser::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49343#endif
344
[email protected]e050ef142012-03-21 01:04:24345#if defined(USE_AURA)
[email protected]38fc5c82012-05-25 15:45:42346 browser::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24347#endif
348
[email protected]50462bf02011-11-21 19:13:31349 return main_parts;
[email protected]f967b722011-09-07 00:58:04350}
351
[email protected]38b098f2012-03-14 21:11:57352content::WebContentsView*
353 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57354 WebContents* web_contents,
355 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57356 return NULL;
357}
358
359content::WebContentsViewDelegate*
360 ChromeContentBrowserClient::GetWebContentsViewDelegate(
361 content::WebContents* web_contents) {
[email protected]b5d73422012-06-02 23:46:44362 return browser::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32363}
364
[email protected]f364d1392011-04-08 21:03:10365void ChromeContentBrowserClient::RenderViewHostCreated(
366 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46367
[email protected]9f76c1e2012-03-05 15:15:58368 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46369 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02370 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46371
372 new ChromeRenderViewHostObserver(render_view_host,
373 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10374 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26375}
376
[email protected]f3b1a082011-11-18 00:34:30377void ChromeContentBrowserClient::RenderProcessHostCreated(
378 content::RenderProcessHost* host) {
379 int id = host->GetID();
380 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
381 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02382 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30383 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03384#if !defined(OS_ANDROID)
[email protected]b5b79d72012-05-24 19:42:28385 host->GetChannel()->AddFilter(new PrintingMessageFilter(id));
[email protected]058e5732012-03-01 22:48:03386#endif
[email protected]f3b1a082011-11-18 00:34:30387 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02388 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30389 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56390#if defined(OS_MACOSX)
391 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
392#endif
[email protected]f3b1a082011-11-18 00:34:30393 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03394 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07395 host->GetChannel()->AddFilter(
396 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38397
[email protected]2ccf45c2011-08-19 23:35:50398 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
399 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07400
401 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56402
403 RendererContentSettingRules rules;
404 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
405 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14406}
407
[email protected]e0ada9c2012-03-20 03:54:43408void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
409 content::BrowserChildProcessHost* host) {
410 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
411}
412
[email protected]863f70a2012-01-27 02:05:50413content::WebUIControllerFactory*
414 ChromeContentBrowserClient::GetWebUIControllerFactory() {
415 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56416}
417
[email protected]3d7474ff2011-07-27 17:47:37418GURL ChromeContentBrowserClient::GetEffectiveURL(
419 content::BrowserContext* browser_context, const GURL& url) {
420 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08421 // Get the effective URL for the given actual URL. If the URL is part of an
422 // installed app, the effective URL is an extension URL with the ID of that
423 // extension as the host. This has the effect of grouping apps together in
424 // a common SiteInstance.
425 if (!profile || !profile->GetExtensionService())
426 return url;
427
[email protected]615d88f2011-12-13 01:47:44428 const Extension* extension = profile->GetExtensionService()->extensions()->
429 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08430 if (!extension)
431 return url;
432
[email protected]15877ca2011-11-18 22:40:52433 // Bookmark apps do not use the hosted app process model, and should be
434 // treated as normal URLs.
435 if (extension->from_bookmark())
436 return url;
437
[email protected]36fb2c7c2011-04-04 15:49:08438 // If the URL is part of an extension's web extent, convert it to an
439 // extension URL.
440 return extension->GetResourceURL(url.path());
441}
442
[email protected]056ad2a2011-07-12 02:13:55443bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37444 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55445 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52446 // Because we expect to use the effective URL, URLs for hosted apps (apart
447 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55448 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
449 return false;
450
[email protected]3d7474ff2011-07-27 17:47:37451 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55452 if (!profile || !profile->GetExtensionService())
453 return false;
454
[email protected]615d88f2011-12-13 01:47:44455 const Extension* extension = profile->GetExtensionService()->extensions()->
456 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55457 if (!extension)
458 return false;
459
460 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53461 // permission, or that does not allow JavaScript access to the background
462 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55463 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53464 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
465 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
466 !extension->allow_background_js_access()) {
467 return false;
468 }
469 }
[email protected]056ad2a2011-07-12 02:13:55470
[email protected]7b54ca02012-03-02 18:06:53471 // Hosted apps that have script access to their background page must use
472 // process per site, since all instances can make synchronous calls to the
473 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55474 return true;
475}
476
[email protected]46fb9442011-12-09 17:57:47477bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
478 return ProfileIOData::IsHandledURL(url);
479}
480
[email protected]2a5221b2011-09-27 23:07:31481bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30482 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31483 const GURL& site_url) {
484 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30485 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42486 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46487 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31488
[email protected]ffa97602011-11-17 17:55:52489 // Don't allow the Task Manager to share a process with anything else.
490 // Otherwise it can affect the renderers it is observing.
491 // Note: we could create another RenderProcessHostPrivilege bucket for
492 // this to allow multiple chrome://tasks instances to share, but that's
493 // a very unlikely case without serious consequences.
494 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
495 return false;
496
[email protected]8d3132f62011-10-12 07:13:42497 // These may be NULL during tests. In that case, just assume any site can
498 // share any host.
[email protected]6f371442011-11-09 06:45:46499 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31500 return true;
501
[email protected]a8c269a2011-10-25 20:17:22502 // Experimental:
503 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
504 // to share a renderer process. (We could allow pages from the same site or
505 // extensions of the same type to share, if we knew what the given process
506 // was dedicated to. Allowing no sharing is simpler for now.) This may
507 // cause resource exhaustion issues if too many sites are open at once.
508 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
509 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
510 return false;
511
[email protected]eec0b33c2011-12-05 22:09:45512 // An isolated app is only allowed to share with the exact same app in order
513 // to provide complete renderer process isolation. This also works around
514 // issue http://crbug.com/85588, where different isolated apps in the same
515 // process would end up using the first app's storage contexts.
516 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42517 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45518 if (privilege_required == PRIV_ISOLATED)
519 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
520
521 // Otherwise, just make sure the process privilege matches the privilege
522 // required by the site.
523 return GetProcessPrivilege(process_host, process_map, service) ==
524 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31525}
526
[email protected]76411f412012-02-22 18:56:06527// This function is trying to limit the amount of processes used by extensions
528// with background pages. It uses a globally set percentage of processes to
529// run such extensions and if the limit is exceeded, it returns true, to
530// indicate to the content module to group extensions together.
531bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
532 content::BrowserContext* browser_context, const GURL& url) {
533 // It has to be a valid URL for us to check for an extension.
534 if (!url.is_valid())
535 return false;
536
537 Profile* profile = Profile::FromBrowserContext(browser_context);
538 ExtensionService* service = profile->GetExtensionService();
539 if (!service)
540 return false;
541
542 // We have to have a valid extension with background page to proceed.
543 const Extension* extension =
544 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
545 if (!extension)
546 return false;
547 if (!extension->has_background_page())
548 return false;
549
550 std::set<int> process_ids;
551 size_t max_process_count =
552 content::RenderProcessHost::GetMaxRendererProcessCount();
553
554 // Go through all profiles to ensure we have total count of extension
555 // processes containing background pages, otherwise one profile can
556 // starve the other.
557 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
558 GetLoadedProfiles();
559 for (size_t i = 0; i < profiles.size(); ++i) {
560 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32561 for (ExtensionProcessManager::const_iterator iter =
562 epm->background_hosts().begin();
563 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06564 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32565 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06566 }
567 }
568
569 if (process_ids.size() >
570 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
571 return true;
572 }
573
574 return false;
575}
576
[email protected]6f371442011-11-09 06:45:46577void ChromeContentBrowserClient::SiteInstanceGotProcess(
578 SiteInstance* site_instance) {
579 CHECK(site_instance->HasProcess());
580
581 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02582 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46583 ExtensionService* service = profile->GetExtensionService();
584 if (!service)
585 return;
586
587 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44588 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33589 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46590 if (!extension)
591 return;
592
[email protected]6bc04fd82011-12-04 02:29:35593 service->process_map()->Insert(extension->id(),
594 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33595 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46596 BrowserThread::PostTask(
597 BrowserThread::IO, FROM_HERE,
598 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24599 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46600 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35601 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33602 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46603}
604
605void ChromeContentBrowserClient::SiteInstanceDeleting(
606 SiteInstance* site_instance) {
607 if (!site_instance->HasProcess())
608 return;
609
610 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02611 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46612 ExtensionService* service = profile->GetExtensionService();
613 if (!service)
614 return;
615
616 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44617 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33618 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46619 if (!extension)
620 return;
621
[email protected]6bc04fd82011-12-04 02:29:35622 service->process_map()->Remove(extension->id(),
623 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33624 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46625 BrowserThread::PostTask(
626 BrowserThread::IO, FROM_HERE,
627 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24628 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46629 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35630 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33631 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46632}
633
[email protected]f05763972012-06-06 18:17:26634bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08635 const GURL& current_url,
636 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26637 if (current_url.is_empty()) {
638 // Always choose a new process when navigating to extension URLs. The
639 // process grouping logic will combine all of a given extension's pages
640 // into the same process.
641 if (new_url.SchemeIs(chrome::kExtensionScheme))
642 return true;
[email protected]e3daf3c2011-10-05 21:17:08643
[email protected]f05763972012-06-06 18:17:26644 return false;
645 }
646
647 // Also, we must switch if one is an extension and the other is not the exact
648 // same extension.
649 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
650 new_url.SchemeIs(chrome::kExtensionScheme)) {
651 if (current_url.GetOrigin() != new_url.GetOrigin())
652 return true;
653 }
654
655 return false;
[email protected]e3daf3c2011-10-05 21:17:08656}
657
[email protected]395045c2012-05-22 15:04:38658bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
659 content::ResourceContext* resource_context, const GURL& current_url,
660 const GURL& new_url) {
661 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
662 return extensions::CrossesExtensionProcessBoundary(
663 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17664 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38665}
666
[email protected]763ec4ca2011-04-29 15:48:12667std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
668 const std::string& alias_name) {
669 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
670}
671
[email protected]b80f68432011-05-02 17:22:30672void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
673 CommandLine* command_line, int child_process_id) {
674#if defined(USE_LINUX_BREAKPAD)
675 if (IsCrashReporterEnabled()) {
676 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
677 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
678 }
679#elif defined(OS_MACOSX)
680 if (IsCrashReporterEnabled()) {
681 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
682 child_process_logging::GetClientId());
683 }
684#endif // OS_MACOSX
685
[email protected]f1933792011-06-14 00:49:34686 if (logging::DialogsAreSuppressed())
687 command_line->AppendSwitch(switches::kNoErrorDialogs);
688
[email protected]b80f68432011-05-02 17:22:30689 std::string process_type =
690 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17691 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52692 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30693 FilePath user_data_dir =
694 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
695 if (!user_data_dir.empty())
696 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
697#if defined(OS_CHROMEOS)
698 const std::string& login_profile =
699 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
700 if (!login_profile.empty())
701 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
702#endif
703
[email protected]f3b1a082011-11-18 00:34:30704 content::RenderProcessHost* process =
705 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37706 if (process) {
707 Profile* profile = Profile::FromBrowserContext(
708 process->GetBrowserContext());
709 extensions::ProcessMap* process_map =
710 profile->GetExtensionService()->process_map();
711 if (process_map && process_map->Contains(process->GetID()))
712 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30713
[email protected]a8d851f82011-12-21 00:32:37714 PrefService* prefs = profile->GetPrefs();
715 // Currently this pref is only registered if applied via a policy.
716 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
717 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
718 // Turn this policy into a command line switch.
719 command_line->AppendSwitch(switches::kDisable3DAPIs);
720 }
[email protected]718eab62011-10-05 21:16:52721
[email protected]a8d851f82011-12-21 00:32:37722 // Disable client-side phishing detection in the renderer if it is
723 // disabled in the Profile preferences or the browser process.
724 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
725 !g_browser_process->safe_browsing_detection_service()) {
726 command_line->AppendSwitch(
727 switches::kDisableClientSidePhishingDetection);
728 }
[email protected]8c40da62011-07-13 22:58:46729 }
[email protected]47c7ec82012-01-18 03:29:21730 {
731 PrefService* local_state = g_browser_process->local_state();
732 if (local_state &&
733 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
734 command_line->AppendSwitch(switches::kRendererPrintPreview);
735 }
736 }
[email protected]4287a3d2011-06-13 23:56:51737
[email protected]47c7ec82012-01-18 03:29:21738 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51739 static const char* const kSwitchNames[] = {
740 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48741 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51742 switches::kAllowScriptingGallery,
743 switches::kAppsCheckoutURL,
744 switches::kAppsGalleryURL,
[email protected]b1c4de4c2012-06-08 00:04:56745 switches::kBrowserPlugin,
[email protected]be9d9c82011-07-13 04:17:31746 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51747 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10748 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50749 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53750 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09751 switches::kDisableInBrowserThumbnailing,
[email protected]4287a3d2011-06-13 23:56:51752 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21753 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13754 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51755 switches::kEnableCrxlessWebApps,
756 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:51757 switches::kEnableIPCFuzzing,
758 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05759 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48760 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53761 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51762 switches::kEnableWatchdog,
763 switches::kExperimentalSpellcheckerFeatures,
764 switches::kMemoryProfiling,
765 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37766 switches::kNoJsRandomness,
[email protected]2a6bb0b12011-10-05 19:18:04767 switches::kNoRunningInsecureContent,
[email protected]f45c5f32012-04-18 19:26:37768 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51769 switches::kPpapiFlashArgs,
770 switches::kPpapiFlashInProcess,
771 switches::kPpapiFlashPath,
772 switches::kPpapiFlashVersion,
773 switches::kProfilingAtStart,
774 switches::kProfilingFile,
775 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37776 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51777 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38778 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51779 };
780
781 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
782 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17783 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38784 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35785 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38786 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37787 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38788 switches::kWhitelistedExtensionID,
789 };
790
791 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
792 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51793 } else if (process_type == switches::kPluginProcess) {
794 static const char* const kSwitchNames[] = {
795 #if defined(OS_CHROMEOS)
796 switches::kLoginProfile,
797 #endif
798 switches::kMemoryProfiling,
799 switches::kSilentDumpOnDCHECK,
800 switches::kUserDataDir,
801 };
802
803 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
804 arraysize(kSwitchNames));
805 } else if (process_type == switches::kZygoteProcess) {
806 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51807 switches::kUserDataDir, // Make logs go to the right file.
808 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50809 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13810 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51811 switches::kPpapiFlashInProcess,
812 switches::kPpapiFlashPath,
813 switches::kPpapiFlashVersion,
814 };
815
816 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
817 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11818 } else if (process_type == switches::kGpuProcess) {
819 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
820 // because GPU is expected to be unreliable.
821 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
822 !command_line->HasSwitch(switches::kDisableBreakpad))
823 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30824 }
[email protected]6f08af82011-09-15 01:19:03825
826 // The command line switch kEnableBenchmarking needs to be specified along
827 // with the kEnableStatsTable switch to ensure that the stats table global
828 // is initialized correctly.
829 if (command_line->HasSwitch(switches::kEnableBenchmarking))
830 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30831}
832
833std::string ChromeContentBrowserClient::GetApplicationLocale() {
834 return g_browser_process->GetApplicationLocale();
835}
836
[email protected]597a867b2011-11-18 18:31:20837std::string ChromeContentBrowserClient::GetAcceptLangs(
838 content::BrowserContext* context) {
839 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37840 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08841}
842
[email protected]9ec0f452012-05-31 15:58:53843gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22844 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:53845 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:08846}
847
[email protected]a2176792011-05-08 19:30:49848bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09849 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19850 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20851 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20853 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05854 return io_data->GetCookieSettings()->
855 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49856}
857
[email protected]ed24fad2011-05-10 22:44:01858bool ChromeContentBrowserClient::AllowGetCookie(
859 const GURL& url,
860 const GURL& first_party,
861 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20862 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01863 int render_process_id,
864 int render_view_id) {
865 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20866 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05867 bool allow = io_data->GetCookieSettings()->
868 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01869
[email protected]8093a542011-05-13 07:29:32870 BrowserThread::PostTask(
871 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03872 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43873 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01874 return allow;
875}
876
877bool ChromeContentBrowserClient::AllowSetCookie(
878 const GURL& url,
879 const GURL& first_party,
880 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20881 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01882 int render_process_id,
883 int render_view_id,
884 net::CookieOptions* options) {
885 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20886 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05887 CookieSettings* cookie_settings = io_data->GetCookieSettings();
888 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
889
[email protected]8093a542011-05-13 07:29:32890 BrowserThread::PostTask(
891 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03892 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43893 render_view_id, url, first_party, cookie_line, *options,
894 !allow));
[email protected]ed24fad2011-05-10 22:44:01895 return allow;
896}
897
[email protected]d5a19162011-06-30 18:51:54898bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20899 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20901 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:43902 CookieSettings* cookie_settings = io_data->GetCookieSettings();
903 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:26904
[email protected]bf510ed2012-06-05 08:31:43905 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
906 // Could we even support per-origin settings?
907 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:54908}
909
[email protected]5c5a88e2011-11-12 00:45:35910bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35911 const GURL& url,
912 const string16& name,
913 const string16& display_name,
914 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20915 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48916 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35917 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20918 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35919 CookieSettings* cookie_settings = io_data->GetCookieSettings();
920 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
921
[email protected]62151052012-02-01 18:40:48922 // Record access to database for potential display in UI.
923 std::vector<std::pair<int, int> >::const_iterator i;
924 for (i = render_views.begin(); i != render_views.end(); ++i) {
925 BrowserThread::PostTask(
926 BrowserThread::UI, FROM_HERE,
927 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
928 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35929 }
930
931 return allow;
932}
933
934bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35935 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20936 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48937 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20939 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35940 CookieSettings* cookie_settings = io_data->GetCookieSettings();
941 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
942
[email protected]62151052012-02-01 18:40:48943 // Record access to file system for potential display in UI.
944 std::vector<std::pair<int, int> >::const_iterator i;
945 for (i = render_views.begin(); i != render_views.end(); ++i) {
946 BrowserThread::PostTask(
947 BrowserThread::UI, FROM_HERE,
948 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
949 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35950 }
951
952 return allow;
953}
954
[email protected]7c5ff9a2012-03-02 07:42:49955bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
956 const GURL& url,
957 const string16& name,
958 content::ResourceContext* context,
959 const std::vector<std::pair<int, int> >& render_views) {
960 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
961 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
962 CookieSettings* cookie_settings = io_data->GetCookieSettings();
963 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
964
965 // Record access to IndexedDB for potential display in UI.
966 std::vector<std::pair<int, int> >::const_iterator i;
967 for (i = render_views.begin(); i != render_views.end(); ++i) {
968 BrowserThread::PostTask(
969 BrowserThread::UI, FROM_HERE,
970 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
971 i->first, i->second, url, name, !allow));
972 }
973
974 return allow;
975}
976
[email protected]6133f922011-07-01 21:34:34977net::URLRequestContext*
978ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20979 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34980 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
981 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20982 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34983 return io_data->extensions_request_context();
984 }
985
986 return NULL;
987}
988
[email protected]317f96c92011-05-31 06:53:41989QuotaPermissionContext*
990ChromeContentBrowserClient::CreateQuotaPermissionContext() {
991 return new ChromeQuotaPermissionContext();
992}
993
[email protected]a0ce3282011-08-19 20:49:52994void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42995 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42996}
997
[email protected]a0ce3282011-08-19 20:49:52998void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52999 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521000}
1001
[email protected]848dd042011-06-04 18:24:031002void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171003 int render_process_id,
1004 int render_view_id,
1005 int cert_error,
1006 const net::SSLInfo& ssl_info,
1007 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031008 bool overridable,
[email protected]d9be47702012-05-16 03:41:221009 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171010 const base::Callback<void(bool)>& callback,
1011 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411012 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131013 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171014 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411015 if (!tab) {
1016 NOTREACHED();
1017 return;
1018 }
1019 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501020 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301021 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091022 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411023 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171024 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411025 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171026 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411027 return;
1028 }
1029 }
1030
1031 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221032 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1033 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031034}
1035
[email protected]c99c442e2011-08-24 11:37:301036void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451037 int render_process_id,
1038 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401039 const net::HttpNetworkSession* network_session,
1040 net::SSLCertRequestInfo* cert_request_info,
1041 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131042 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451043 render_process_id, render_view_id);
1044 if (!tab) {
1045 NOTREACHED();
1046 return;
1047 }
1048
[email protected]6786bf402011-12-03 15:19:451049 GURL requesting_url("https://" + cert_request_info->host_and_port);
1050 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1051 << cert_request_info->host_and_port;
1052
[email protected]627e0512011-12-21 22:55:301053 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451054 scoped_ptr<Value> filter(
1055 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1056 requesting_url,
1057 requesting_url,
1058 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1059 std::string(), NULL));
1060
1061 if (filter.get()) {
1062 // Try to automatically select a client certificate.
1063 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1064 DictionaryValue* filter_dict =
1065 static_cast<DictionaryValue*>(filter.get());
1066
1067 const std::vector<scoped_refptr<net::X509Certificate> >&
1068 all_client_certs = cert_request_info->client_certs;
1069 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1070 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1071 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401072 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451073 return;
1074 }
1075 }
1076 } else {
1077 NOTREACHED();
1078 }
1079 }
1080
[email protected]8ec26472011-06-06 16:52:451081 TabContentsWrapper* wrapper =
1082 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451083 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131084 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451085 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141086 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401087 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451088 return;
1089 }
[email protected]7a593db2012-02-13 21:19:401090 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1091 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451092}
1093
1094void ChromeContentBrowserClient::AddNewCertificate(
1095 net::URLRequest* request,
1096 net::X509Certificate* cert,
1097 int render_process_id,
1098 int render_view_id) {
1099 // The handler will run the UI and delete itself when it's finished.
1100 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1101}
1102
[email protected]a93670ab2012-02-24 03:46:391103void ChromeContentBrowserClient::RequestMediaAccessPermission(
1104 const content::MediaStreamRequest* request,
1105 const content::MediaResponseCallback& callback) {
1106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1107
[email protected]117b6b42012-02-29 09:11:081108 WebContents* contents = tab_util::GetWebContentsByID(
1109 request->render_process_id, request->render_view_id);
1110 if (!contents) {
1111 // Abort, if the tab was closed after the request was made but before we
1112 // got to this point.
1113 callback.Run(content::MediaStreamDevices());
1114 return;
1115 }
1116
1117 TabContentsWrapper* tab =
1118 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1119 DCHECK(tab);
1120
1121 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1122 InfoBarDelegate* old_infobar = NULL;
1123 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1124 old_infobar =
[email protected]51d1fc62012-04-28 03:47:531125 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfoBarDelegate();
[email protected]117b6b42012-02-29 09:11:081126 }
1127
[email protected]117b6b42012-02-29 09:11:081128 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1129 request,
1130 callback);
1131 if (old_infobar)
1132 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1133 else
1134 infobar_helper->AddInfoBar(infobar);
[email protected]a93670ab2012-02-24 03:46:391135}
1136
[email protected]dc73a7b2012-03-25 15:27:181137content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1138 return MediaInternals::GetInstance();
1139}
1140
[email protected]941623e2011-06-07 23:06:041141void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1142 const GURL& source_origin,
1143 int callback_context,
1144 int render_process_id,
1145 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111146#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041147 RenderViewHost* rvh = RenderViewHost::FromID(
1148 render_process_id, render_view_id);
1149 if (!rvh) {
1150 NOTREACHED();
1151 return;
1152 }
1153
[email protected]9f76c1e2012-03-05 15:15:581154 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301155 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041156 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371157 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041158 service->RequestPermission(
1159 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131160 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111161#else
1162 NOTIMPLEMENTED();
1163#endif
[email protected]941623e2011-06-07 23:06:041164}
1165
1166WebKit::WebNotificationPresenter::Permission
1167 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021168 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201169 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021170 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111171#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201173 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021174 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1175 source_origin, render_process_id,
1176 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041177 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041178
1179 // Fall back to the regular notification preferences, which works on an
1180 // origin basis.
1181 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371182 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041183 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111184#else
1185 return WebKit::WebNotificationPresenter::PermissionAllowed;
1186#endif
[email protected]941623e2011-06-07 23:06:041187}
1188
1189void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171190 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041191 int render_process_id,
1192 int render_view_id,
1193 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111194#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041195 RenderViewHost* rvh = RenderViewHost::FromID(
1196 render_process_id, render_view_id);
1197 if (!rvh) {
1198 NOTREACHED();
1199 return;
1200 }
1201
[email protected]9f76c1e2012-03-05 15:15:581202 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301203 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041204 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371205 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041206 service->ShowDesktopNotification(
1207 params, render_process_id, render_view_id,
1208 worker ? DesktopNotificationService::WorkerNotification :
1209 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111210#else
1211 NOTIMPLEMENTED();
1212#endif
[email protected]941623e2011-06-07 23:06:041213}
1214
1215void ChromeContentBrowserClient::CancelDesktopNotification(
1216 int render_process_id,
1217 int render_view_id,
1218 int notification_id) {
[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->CancelDesktopNotification(
1232 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111233#else
1234 NOTIMPLEMENTED();
1235#endif
[email protected]941623e2011-06-07 23:06:041236}
1237
[email protected]9f3fba52011-06-08 20:37:191238bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351239 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021240 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191241 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201242 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011243 int render_process_id,
1244 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011246
1247 *no_javascript_access = false;
1248
[email protected]9f3fba52011-06-08 20:37:191249 // If the opener is trying to create a background window but doesn't have
1250 // the appropriate permission, fail the attempt.
1251 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201252 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531253 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1254
[email protected]03b6d552012-03-29 04:03:011255 if (!map->SecurityOriginHasAPIPermission(
1256 source_origin,
1257 render_process_id,
1258 ExtensionAPIPermission::kBackground)) {
1259 return false;
1260 }
1261
[email protected]7b54ca02012-03-02 18:06:531262 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1263 // return a recently installed Extension even if this CanCreateWindow call
1264 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011265 // because the permission check above would have caused an early return
1266 // already. We must use the full URL to find hosted apps, though, and not
1267 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531268 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351269 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531270 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011271 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191272 }
1273 return true;
1274}
1275
1276std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201277 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1279 // Check if it's an extension-created worker, in which case we want to use
1280 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201281 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191282 const Extension* extension =
1283 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1284 return extension ? extension->name() : std::string();
1285}
1286
[email protected]99907362012-01-11 05:41:401287void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1288 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171289}
1290
[email protected]c52b2892012-03-07 11:01:021291content::SpeechRecognitionManagerDelegate*
1292 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321293#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021294 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321295#else
1296 return NULL;
1297#endif
[email protected]66cfec62012-02-24 17:57:511298}
1299
[email protected]ae6e9912011-07-27 01:18:281300net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1301 return g_browser_process->net_log();
1302}
1303
[email protected]32538d92011-08-25 00:09:231304AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1305 return new ChromeAccessTokenStore();
1306}
1307
[email protected]dbae6b02011-06-29 23:51:411308bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1309 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1310 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1311}
1312
[email protected]64d69de42012-02-06 00:19:541313void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321314 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061315 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581316 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061317 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061318
[email protected]f3986f82012-01-03 20:00:061319 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541320 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061321 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541322 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061323 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541324 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061325 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541326 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061327 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541328 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061329 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541330 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061331
[email protected]64d69de42012-02-06 00:19:541332 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401333 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541334 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401335 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541336 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401337 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541338 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401339 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061340
[email protected]ddf72142012-05-22 04:52:401341 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061342
[email protected]64d69de42012-02-06 00:19:541343 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401344 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541345 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061346 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541347 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061348 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1349 const DictionaryValue* inspector_settings =
1350 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1351 if (inspector_settings) {
1352 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1353 iter != inspector_settings->end_keys(); ++iter) {
1354 std::string value;
1355 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541356 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061357 std::make_pair(*iter, value));
1358 }
1359 }
[email protected]64d69de42012-02-06 00:19:541360 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061361
[email protected]ddf72142012-05-22 04:52:401362 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541363 web_prefs->javascript_enabled = false;
1364 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1365 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401366 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541367 web_prefs->plugins_enabled = false;
1368 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1369 web_prefs->java_enabled = false;
1370 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401371 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061372
[email protected]64d69de42012-02-06 00:19:541373 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1374 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061375
[email protected]64d69de42012-02-06 00:19:541376 web_prefs->memory_info_enabled =
1377 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1378 web_prefs->allow_displaying_insecure_content =
1379 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1380 web_prefs->allow_running_insecure_content =
1381 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081382 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061383
[email protected]64d69de42012-02-06 00:19:541384 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151385 UserStyleSheetWatcher* user_style_sheet_watcher =
1386 UserStyleSheetWatcherFactory::GetForProfile(profile);
1387 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541388 web_prefs->user_style_sheet_enabled = true;
1389 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151390 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541391 } else {
1392 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061393 }
1394
[email protected]b7e44ff2012-02-16 03:37:341395 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101396#if defined(OS_MACOSX)
1397 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1398 // Mac so it uses NSSpellChecker in the background.
1399 false;
1400#else
1401 !CommandLine::ForCurrentProcess()->
1402 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1403#endif
[email protected]b7e44ff2012-02-16 03:37:341404 web_prefs->unified_textchecker_enabled =
1405 web_prefs->asynchronous_spell_checking_enabled ||
1406 CommandLine::ForCurrentProcess()->
1407 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571408
[email protected]64d69de42012-02-06 00:19:541409 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061410 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541411 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061412 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541413 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061414 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1415
1416 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541417 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061418 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541419 web_prefs->default_encoding);
1420 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401421 prefs->ClearPref(prefs::kDefaultCharset);
1422 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061423 }
[email protected]64d69de42012-02-06 00:19:541424 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061425
[email protected]299d7f12012-05-23 05:31:151426 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1427 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061428 ExtensionService* service = profile->GetExtensionService();
1429 if (service) {
1430 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581431 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061432 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151433 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061434 }
1435
[email protected]299d7f12012-05-23 05:31:151436 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541437 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151438 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061439 // Disable all kinds of acceleration for background pages.
1440 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541441 web_prefs->force_compositing_mode = false;
1442 web_prefs->accelerated_compositing_enabled = false;
1443 web_prefs->accelerated_2d_canvas_enabled = false;
1444 web_prefs->accelerated_video_enabled = false;
1445 web_prefs->accelerated_painting_enabled = false;
1446 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061447 }
[email protected]2e21fe292012-03-02 22:52:321448
1449#if defined(FILE_MANAGER_EXTENSION)
1450 // Override the default of suppressing HW compositing for WebUI pages for the
1451 // file manager, which is implemented using WebUI but wants HW acceleration
1452 // for video decode & render.
1453 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1454 web_prefs->accelerated_compositing_enabled = true;
1455 web_prefs->accelerated_2d_canvas_enabled = true;
1456 }
1457#endif
[email protected]181a95ee2011-07-12 19:26:361458}
1459
1460void ChromeContentBrowserClient::UpdateInspectorSetting(
1461 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061462 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581463 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061464 DictionaryPrefUpdate update(
1465 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1466 prefs::kWebKitInspectorSettings);
1467 DictionaryValue* inspector_settings = update.Get();
1468 inspector_settings->SetWithoutPathExpansion(key,
1469 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361470}
1471
1472void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061473 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581474 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061475 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1476 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361477}
1478
[email protected]b8148ac2011-07-13 22:03:251479void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1480 BrowserURLHandler* handler) {
1481 // Add the default URL handlers.
1482 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1483 BrowserURLHandler::null_handler());
1484 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1485 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1486
[email protected]b3adbd02011-11-30 22:23:271487 // about: handler. Must come before chrome: handler, since it will
1488 // rewrite about: urls to chrome: URLs and then expect chrome: to
1489 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251490 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1491 BrowserURLHandler::null_handler());
1492 // chrome: & friends.
1493 handler->AddHandlerPair(&HandleWebUI,
1494 BrowserURLHandler::null_handler());
1495}
1496
1497void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371498 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581499 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251500 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1501 BrowsingDataRemover::EVERYTHING,
1502 base::Time());
[email protected]3d4d4cf2012-06-04 10:40:551503 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1504 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251505 // BrowsingDataRemover takes care of deleting itself when done.
1506}
1507
1508void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371509 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581510 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251511 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1512 BrowsingDataRemover::EVERYTHING,
1513 base::Time());
[email protected]dceaa912011-09-06 17:17:231514 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551515 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251516 // BrowsingDataRemover takes care of deleting itself when done.
1517}
1518
[email protected]e1d16eb92011-08-18 23:19:321519FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1520 return download_util::GetDefaultDownloadDirectory();
1521}
1522
[email protected]c9b6eb62011-10-18 20:49:391523std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1524 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1525}
1526
[email protected]a658d452012-03-02 12:45:291527bool ChromeContentBrowserClient::AllowSocketAPI(
1528 content::BrowserContext* browser_context, const GURL& url) {
1529 if (!url.is_valid())
1530 return false;
1531
1532 std::string host = url.host();
1533 if (allowed_socket_origins_.count(host))
1534 return true;
1535
[email protected]9a5940d2012-04-27 19:16:231536 Profile* profile = Profile::FromBrowserContext(browser_context);
1537 const Extension* extension = NULL;
1538 if (profile && profile->GetExtensionService()) {
1539 extension = profile->GetExtensionService()->extensions()->
1540 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1541 }
1542
[email protected]f237c0f2012-03-10 07:49:101543 // Need to check this now and not on construction because otherwise it won't
1544 // work with browser_tests.
1545 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1546 std::string allowed_list =
1547 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231548 if (allowed_list == "*") {
1549 // The wildcard allows socket API only for packaged and platform apps.
1550 return extension &&
1551 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1552 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1553 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101554 StringTokenizer t(allowed_list, ",");
1555 while (t.GetNext()) {
1556 if (t.token() == host)
1557 return true;
1558 }
1559 }
1560
[email protected]a658d452012-03-02 12:45:291561 if (!extension)
1562 return false;
1563
1564 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1565 return true;
1566
1567 return false;
[email protected]e461da2f2012-02-16 19:06:401568}
1569
[email protected]e60c0232011-11-11 19:56:351570#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301571int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521572 const CommandLine& command_line) {
1573 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071574 ExtensionCrashHandlerHostLinux* crash_handler =
1575 ExtensionCrashHandlerHostLinux::GetInstance();
1576 return crash_handler->GetDeathSignalSocket();
1577 }
1578
[email protected]718eab62011-10-05 21:16:521579 std::string process_type =
1580 command_line.GetSwitchValueASCII(switches::kProcessType);
1581
1582 if (process_type == switches::kRendererProcess)
1583 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1584
[email protected]b80f68432011-05-02 17:22:301585 if (process_type == switches::kPluginProcess)
1586 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1587
1588 if (process_type == switches::kPpapiPluginProcess)
1589 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1590
1591 if (process_type == switches::kGpuProcess)
1592 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1593
1594 return -1;
1595}
[email protected]e60c0232011-11-11 19:56:351596#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301597
[email protected]4a65826d2011-08-25 16:04:011598#if defined(OS_WIN)
1599const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1600 return chrome::kBrowserResourcesDll;
1601}
1602#endif
1603
[email protected]37a72af2011-06-13 05:42:011604#if defined(USE_NSS)
1605crypto::CryptoModuleBlockingPasswordDelegate*
1606 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1607 const GURL& url) {
1608 return browser::NewCryptoModuleBlockingDialogDelegate(
1609 browser::kCryptoModulePasswordKeygen, url.host());
1610}
1611#endif
1612
[email protected]d977f9c2011-03-14 16:10:261613} // namespace chrome