blob: d7e8cddd362597fb78f7717a3beeb7f6cac7672d [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]3d4d4cf2012-06-04 10:40:5518#include "chrome/browser/browsing_data_helper.h"
[email protected]3b8f7e32011-07-13 11:52:2319#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1220#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0321#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4122#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5623#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0524#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4525#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3226#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0827#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3228#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1629#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0630#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0431#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1032#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]9c1662b2012-03-06 15:44:3333#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2634#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0835#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2536#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0637#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2338#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1239#include "chrome/browser/google/google_util.h"
[email protected]4abe58d2012-06-08 03:09:0940#include "chrome/browser/gpu_util.h"
[email protected]117b6b42012-02-29 09:11:0841#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1842#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2843#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0444#include "chrome/browser/notifications/desktop_notification_service.h"
45#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4346#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4247#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1248#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0649#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4150#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5051#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0752#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4153#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1454#include "chrome/browser/printing/printing_message_filter.h"
55#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3256#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0657#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3359#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4260#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0262#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4663#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4564#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0365#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4566#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
67#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5468#include "chrome/browser/toolkit_extra_parts.h"
[email protected]117b6b42012-02-29 09:11:0869#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]b5d73422012-06-02 23:46:4470#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]871dc682012-06-11 19:35:3371#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]863f70a2012-01-27 02:05:5072#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0673#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1574#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5375#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3076#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0177#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3078#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0479#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3880#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4481#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3482#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1283#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3884#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0985#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4386#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3087#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3188#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5989#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3090#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3391#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0592#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3393#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1994#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1095#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4396#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3997#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3498#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4099#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:06100#include "net/cookies/cookie_monster.h"
101#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:39102#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08103#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36104#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04105#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26106
[email protected]b48c9182011-10-26 18:03:30107#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38108#include "chrome/browser/chrome_browser_main_win.h"
109#elif defined(OS_MACOSX)
110#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56111#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30112#elif defined(OS_CHROMEOS)
113#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49114#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26115#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30116#include "chrome/browser/chrome_browser_main_linux.h"
117#elif defined(OS_POSIX)
118#include "chrome/browser/chrome_browser_main_posix.h"
119#endif
120
[email protected]6653c192012-04-10 22:52:44121#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30122#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44123#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43124#endif
[email protected]b80f68432011-05-02 17:22:30125
[email protected]37a72af2011-06-13 05:42:01126#if defined(USE_NSS)
127#include "chrome/browser/ui/crypto_module_password_dialog.h"
128#endif
129
[email protected]c8c77182011-12-21 15:04:47130using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39131using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31132using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59133using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00134using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11135using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33136using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13137using content::WebContents;
[email protected]1c321ee2012-05-21 03:02:34138using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25139using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39140
[email protected]c5dbef02011-05-13 05:06:09141namespace {
142
[email protected]e461da2f2012-02-16 19:06:40143const char* kPredefinedAllowedSocketOrigins[] = {
144 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18145 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45146 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
147 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
148 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
149 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35150 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
151 "cbkkbcmdlboombapidmoeolnmdacpkch" // see crbug.com/129089
[email protected]e461da2f2012-02-16 19:06:40152};
153
[email protected]b8148ac2011-07-13 22:03:25154// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42155bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50156 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
157 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25158 return false;
159
[email protected]fe69558d2012-03-12 11:34:49160#if defined(OS_CHROMEOS)
161 // Special case : in ChromeOS in Guest mode bookmarks and history are
162 // disabled for security reasons. New tab page explains the reasons, so
163 // we redirect user to new tab page.
164 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
165 if (url->SchemeIs(chrome::kChromeUIScheme) &&
166 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
167 url->DomainIs(chrome::kChromeUIHistoryHost))) {
168 // Rewrite with new tab URL
169 *url = GURL(chrome::kChromeUINewTabURL);
170 }
171 }
172#endif
173
[email protected]b8148ac2011-07-13 22:03:25174 // Special case the new tab page. In older versions of Chrome, the new tab
175 // page was hosted at chrome-internal:<blah>. This might be in people's saved
176 // sessions or bookmarks, so we say any URL with that scheme triggers the new
177 // tab page.
178 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
179 // Rewrite it with the proper new tab URL.
180 *url = GURL(chrome::kChromeUINewTabURL);
181 }
182
183 return true;
184}
185
[email protected]8d3132f62011-10-12 07:13:42186// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
187// below. Extension, and isolated apps require different privileges to be
188// granted to their RenderProcessHosts. This classification allows us to make
189// sure URLs are served by hosts with the right set of privileges.
190enum RenderProcessHostPrivilege {
191 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45192 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42193 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45194 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42195};
196
197RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
198 const GURL& url,
199 ExtensionService* service) {
200 // Default to a normal renderer cause it is lower privileged. This should only
201 // occur if the URL on a site instance is either malformed, or uninitialized.
202 // If it is malformed, then there is no need for better privileges anyways.
203 // If it is uninitialized, but eventually settles on being an a scheme other
204 // than normal webrenderer, the navigation logic will correct us out of band
205 // anyways.
206 if (!url.is_valid())
207 return PRIV_NORMAL;
208
209 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44210 const Extension* extension =
211 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45212 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42213 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45214 if (extension && extension->is_hosted_app())
215 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42216
217 return PRIV_EXTENSION;
218 }
219
220 return PRIV_NORMAL;
221}
222
223RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30224 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46225 extensions::ProcessMap* process_map,
226 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46227 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30228 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46229 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21230 return PRIV_NORMAL;
231
[email protected]6f371442011-11-09 06:45:46232 for (std::set<std::string>::iterator iter = extension_ids.begin();
233 iter != extension_ids.end(); ++iter) {
234 const Extension* extension = service->GetExtensionById(*iter, false);
235 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42236 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45237 if (extension && extension->is_hosted_app())
238 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42239 }
240
[email protected]676f6ab2011-10-19 20:23:21241 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42242}
243
[email protected]eec0b33c2011-12-05 22:09:45244bool IsIsolatedAppInProcess(const GURL& site_url,
245 content::RenderProcessHost* process_host,
246 extensions::ProcessMap* process_map,
247 ExtensionService* service) {
248 std::set<std::string> extension_ids =
249 process_map->GetExtensionsInProcess(process_host->GetID());
250 if (extension_ids.empty())
251 return false;
252
253 for (std::set<std::string>::iterator iter = extension_ids.begin();
254 iter != extension_ids.end(); ++iter) {
255 const Extension* extension = service->GetExtensionById(*iter, false);
256 if (extension &&
257 extension->is_storage_isolated() &&
258 extension->url() == site_url)
259 return true;
260 }
261
262 return false;
263}
264
[email protected]6786bf402011-12-03 15:19:45265bool CertMatchesFilter(const net::X509Certificate& cert,
266 const base::DictionaryValue& filter) {
267 // TODO(markusheintz): This is the minimal required filter implementation.
268 // Implement a better matcher.
269
270 // An empty filter matches any client certificate since no requirements are
271 // specified at all.
272 if (filter.empty())
273 return true;
274
275 std::string common_name;
276 if (filter.GetString("ISSUER.CN", &common_name) &&
277 (cert.issuer().common_name == common_name)) {
278 return true;
279 }
280 return false;
281}
282
[email protected]f3986f82012-01-03 20:00:06283// Fills |map| with the per-script font prefs under path |map_name|.
284void FillFontFamilyMap(const PrefService* prefs,
285 const char* map_name,
286 WebPreferences::ScriptFontFamilyMap* map) {
287 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
288 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
289 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
290 std::string font_family = prefs->GetString(pref_name.c_str());
291 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32292 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06293 }
294}
295
[email protected]9dbfff12011-07-01 19:37:07296} // namespace
[email protected]c5dbef02011-05-13 05:06:09297
[email protected]d977f9c2011-03-14 16:10:26298namespace chrome {
299
[email protected]e461da2f2012-02-16 19:06:40300ChromeContentBrowserClient::ChromeContentBrowserClient() {
301 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
302 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40303}
304
305ChromeContentBrowserClient::~ChromeContentBrowserClient() {
306}
307
[email protected]50462bf02011-11-21 19:13:31308content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
309 const content::MainFunctionParams& parameters) {
310 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30311 // Construct the Main browser parts based on the OS type.
312#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31313 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04314#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31315 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30316#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31317 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26318#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31319 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14320#elif defined(OS_ANDROID)
321 // Do nothing for Android.
322 // TODO(klobag): Android initialization should use the
323 // *BrowserMainParts class-hierarchy for setting up custom initialization.
324 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30325#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31326 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04327#else
[email protected]b48c9182011-10-26 18:03:30328 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31329 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30330#endif
331
[email protected]c7480942011-11-08 19:18:27332 // Construct additional browser parts. Stages are called in the order in
333 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22334#if defined(TOOLKIT_GTK)
[email protected]38fc5c82012-05-25 15:45:42335 browser::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04336#endif
[email protected]c7480942011-11-08 19:18:27337
338#if defined(TOOLKIT_VIEWS)
[email protected]c27541f2012-05-24 19:25:54339 browser::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27340#endif
341
[email protected]dc04be7c2012-03-15 23:57:49342#if defined(USE_ASH)
[email protected]38fc5c82012-05-25 15:45:42343 browser::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49344#endif
345
[email protected]e050ef142012-03-21 01:04:24346#if defined(USE_AURA)
[email protected]38fc5c82012-05-25 15:45:42347 browser::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24348#endif
349
[email protected]50462bf02011-11-21 19:13:31350 return main_parts;
[email protected]f967b722011-09-07 00:58:04351}
352
[email protected]38b098f2012-03-14 21:11:57353content::WebContentsView*
354 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57355 WebContents* web_contents,
356 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57357 return NULL;
358}
359
360content::WebContentsViewDelegate*
361 ChromeContentBrowserClient::GetWebContentsViewDelegate(
362 content::WebContents* web_contents) {
[email protected]b5d73422012-06-02 23:46:44363 return browser::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32364}
365
[email protected]f364d1392011-04-08 21:03:10366void ChromeContentBrowserClient::RenderViewHostCreated(
367 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46368
[email protected]9f76c1e2012-03-05 15:15:58369 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46370 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02371 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46372
373 new ChromeRenderViewHostObserver(render_view_host,
374 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10375 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26376}
377
[email protected]f3b1a082011-11-18 00:34:30378void ChromeContentBrowserClient::RenderProcessHostCreated(
379 content::RenderProcessHost* host) {
380 int id = host->GetID();
381 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
382 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02383 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30384 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02385#if defined(ENABLE_PRINTING)
[email protected]b5b79d72012-05-24 19:42:28386 host->GetChannel()->AddFilter(new PrintingMessageFilter(id));
[email protected]058e5732012-03-01 22:48:03387#endif
[email protected]f3b1a082011-11-18 00:34:30388 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02389 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30390 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56391#if defined(OS_MACOSX)
392 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
393#endif
[email protected]f3b1a082011-11-18 00:34:30394 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03395 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07396 host->GetChannel()->AddFilter(
397 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38398
[email protected]2ccf45c2011-08-19 23:35:50399 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
400 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07401
402 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56403
404 RendererContentSettingRules rules;
405 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
406 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14407}
408
[email protected]e0ada9c2012-03-20 03:54:43409void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
410 content::BrowserChildProcessHost* host) {
411 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
412}
413
[email protected]863f70a2012-01-27 02:05:50414content::WebUIControllerFactory*
415 ChromeContentBrowserClient::GetWebUIControllerFactory() {
416 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56417}
418
[email protected]3d7474ff2011-07-27 17:47:37419GURL ChromeContentBrowserClient::GetEffectiveURL(
420 content::BrowserContext* browser_context, const GURL& url) {
421 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08422 // Get the effective URL for the given actual URL. If the URL is part of an
423 // installed app, the effective URL is an extension URL with the ID of that
424 // extension as the host. This has the effect of grouping apps together in
425 // a common SiteInstance.
426 if (!profile || !profile->GetExtensionService())
427 return url;
428
[email protected]615d88f2011-12-13 01:47:44429 const Extension* extension = profile->GetExtensionService()->extensions()->
430 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08431 if (!extension)
432 return url;
433
[email protected]15877ca2011-11-18 22:40:52434 // Bookmark apps do not use the hosted app process model, and should be
435 // treated as normal URLs.
436 if (extension->from_bookmark())
437 return url;
438
[email protected]36fb2c7c2011-04-04 15:49:08439 // If the URL is part of an extension's web extent, convert it to an
440 // extension URL.
441 return extension->GetResourceURL(url.path());
442}
443
[email protected]056ad2a2011-07-12 02:13:55444bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37445 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55446 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52447 // Because we expect to use the effective URL, URLs for hosted apps (apart
448 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55449 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
450 return false;
451
[email protected]3d7474ff2011-07-27 17:47:37452 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55453 if (!profile || !profile->GetExtensionService())
454 return false;
455
[email protected]615d88f2011-12-13 01:47:44456 const Extension* extension = profile->GetExtensionService()->extensions()->
457 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55458 if (!extension)
459 return false;
460
461 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53462 // permission, or that does not allow JavaScript access to the background
463 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55464 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53465 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
466 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
467 !extension->allow_background_js_access()) {
468 return false;
469 }
470 }
[email protected]056ad2a2011-07-12 02:13:55471
[email protected]7b54ca02012-03-02 18:06:53472 // Hosted apps that have script access to their background page must use
473 // process per site, since all instances can make synchronous calls to the
474 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55475 return true;
476}
477
[email protected]46fb9442011-12-09 17:57:47478bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
479 return ProfileIOData::IsHandledURL(url);
480}
481
[email protected]2a5221b2011-09-27 23:07:31482bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30483 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31484 const GURL& site_url) {
485 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30486 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42487 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46488 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31489
[email protected]ffa97602011-11-17 17:55:52490 // Don't allow the Task Manager to share a process with anything else.
491 // Otherwise it can affect the renderers it is observing.
492 // Note: we could create another RenderProcessHostPrivilege bucket for
493 // this to allow multiple chrome://tasks instances to share, but that's
494 // a very unlikely case without serious consequences.
495 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
496 return false;
497
[email protected]8d3132f62011-10-12 07:13:42498 // These may be NULL during tests. In that case, just assume any site can
499 // share any host.
[email protected]6f371442011-11-09 06:45:46500 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31501 return true;
502
[email protected]a8c269a2011-10-25 20:17:22503 // Experimental:
504 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
505 // to share a renderer process. (We could allow pages from the same site or
506 // extensions of the same type to share, if we knew what the given process
507 // was dedicated to. Allowing no sharing is simpler for now.) This may
508 // cause resource exhaustion issues if too many sites are open at once.
509 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
510 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
511 return false;
512
[email protected]eec0b33c2011-12-05 22:09:45513 // An isolated app is only allowed to share with the exact same app in order
514 // to provide complete renderer process isolation. This also works around
515 // issue http://crbug.com/85588, where different isolated apps in the same
516 // process would end up using the first app's storage contexts.
517 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42518 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45519 if (privilege_required == PRIV_ISOLATED)
520 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
521
522 // Otherwise, just make sure the process privilege matches the privilege
523 // required by the site.
524 return GetProcessPrivilege(process_host, process_map, service) ==
525 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31526}
527
[email protected]76411f412012-02-22 18:56:06528// This function is trying to limit the amount of processes used by extensions
529// with background pages. It uses a globally set percentage of processes to
530// run such extensions and if the limit is exceeded, it returns true, to
531// indicate to the content module to group extensions together.
532bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
533 content::BrowserContext* browser_context, const GURL& url) {
534 // It has to be a valid URL for us to check for an extension.
535 if (!url.is_valid())
536 return false;
537
538 Profile* profile = Profile::FromBrowserContext(browser_context);
539 ExtensionService* service = profile->GetExtensionService();
540 if (!service)
541 return false;
542
543 // We have to have a valid extension with background page to proceed.
544 const Extension* extension =
545 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
546 if (!extension)
547 return false;
548 if (!extension->has_background_page())
549 return false;
550
551 std::set<int> process_ids;
552 size_t max_process_count =
553 content::RenderProcessHost::GetMaxRendererProcessCount();
554
555 // Go through all profiles to ensure we have total count of extension
556 // processes containing background pages, otherwise one profile can
557 // starve the other.
558 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
559 GetLoadedProfiles();
560 for (size_t i = 0; i < profiles.size(); ++i) {
561 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32562 for (ExtensionProcessManager::const_iterator iter =
563 epm->background_hosts().begin();
564 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06565 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32566 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06567 }
568 }
569
570 if (process_ids.size() >
571 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
572 return true;
573 }
574
575 return false;
576}
577
[email protected]6f371442011-11-09 06:45:46578void ChromeContentBrowserClient::SiteInstanceGotProcess(
579 SiteInstance* site_instance) {
580 CHECK(site_instance->HasProcess());
581
582 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02583 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46584 ExtensionService* service = profile->GetExtensionService();
585 if (!service)
586 return;
587
588 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44589 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33590 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46591 if (!extension)
592 return;
593
[email protected]6bc04fd82011-12-04 02:29:35594 service->process_map()->Insert(extension->id(),
595 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33596 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46597 BrowserThread::PostTask(
598 BrowserThread::IO, FROM_HERE,
599 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24600 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46601 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35602 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33603 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46604}
605
606void ChromeContentBrowserClient::SiteInstanceDeleting(
607 SiteInstance* site_instance) {
608 if (!site_instance->HasProcess())
609 return;
610
611 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02612 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46613 ExtensionService* service = profile->GetExtensionService();
614 if (!service)
615 return;
616
617 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44618 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33619 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46620 if (!extension)
621 return;
622
[email protected]6bc04fd82011-12-04 02:29:35623 service->process_map()->Remove(extension->id(),
624 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33625 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46626 BrowserThread::PostTask(
627 BrowserThread::IO, FROM_HERE,
628 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24629 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46630 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35631 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33632 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46633}
634
[email protected]f05763972012-06-06 18:17:26635bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08636 const GURL& current_url,
637 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26638 if (current_url.is_empty()) {
639 // Always choose a new process when navigating to extension URLs. The
640 // process grouping logic will combine all of a given extension's pages
641 // into the same process.
642 if (new_url.SchemeIs(chrome::kExtensionScheme))
643 return true;
[email protected]e3daf3c2011-10-05 21:17:08644
[email protected]f05763972012-06-06 18:17:26645 return false;
646 }
647
648 // Also, we must switch if one is an extension and the other is not the exact
649 // same extension.
650 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
651 new_url.SchemeIs(chrome::kExtensionScheme)) {
652 if (current_url.GetOrigin() != new_url.GetOrigin())
653 return true;
654 }
655
656 return false;
[email protected]e3daf3c2011-10-05 21:17:08657}
658
[email protected]395045c2012-05-22 15:04:38659bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
660 content::ResourceContext* resource_context, const GURL& current_url,
661 const GURL& new_url) {
662 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
663 return extensions::CrossesExtensionProcessBoundary(
664 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17665 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38666}
667
[email protected]763ec4ca2011-04-29 15:48:12668std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
669 const std::string& alias_name) {
670 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
671}
672
[email protected]b80f68432011-05-02 17:22:30673void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
674 CommandLine* command_line, int child_process_id) {
675#if defined(USE_LINUX_BREAKPAD)
676 if (IsCrashReporterEnabled()) {
677 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
678 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
679 }
680#elif defined(OS_MACOSX)
681 if (IsCrashReporterEnabled()) {
682 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
683 child_process_logging::GetClientId());
684 }
685#endif // OS_MACOSX
686
[email protected]f1933792011-06-14 00:49:34687 if (logging::DialogsAreSuppressed())
688 command_line->AppendSwitch(switches::kNoErrorDialogs);
689
[email protected]b80f68432011-05-02 17:22:30690 std::string process_type =
691 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17692 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52693 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30694 FilePath user_data_dir =
695 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
696 if (!user_data_dir.empty())
697 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
698#if defined(OS_CHROMEOS)
699 const std::string& login_profile =
700 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
701 if (!login_profile.empty())
702 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
703#endif
704
[email protected]f3b1a082011-11-18 00:34:30705 content::RenderProcessHost* process =
706 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37707 if (process) {
708 Profile* profile = Profile::FromBrowserContext(
709 process->GetBrowserContext());
710 extensions::ProcessMap* process_map =
711 profile->GetExtensionService()->process_map();
712 if (process_map && process_map->Contains(process->GetID()))
713 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30714
[email protected]a8d851f82011-12-21 00:32:37715 PrefService* prefs = profile->GetPrefs();
716 // Currently this pref is only registered if applied via a policy.
717 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
718 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
719 // Turn this policy into a command line switch.
720 command_line->AppendSwitch(switches::kDisable3DAPIs);
721 }
[email protected]718eab62011-10-05 21:16:52722
[email protected]a8d851f82011-12-21 00:32:37723 // Disable client-side phishing detection in the renderer if it is
724 // disabled in the Profile preferences or the browser process.
725 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
726 !g_browser_process->safe_browsing_detection_service()) {
727 command_line->AppendSwitch(
728 switches::kDisableClientSidePhishingDetection);
729 }
[email protected]8c40da62011-07-13 22:58:46730 }
[email protected]47c7ec82012-01-18 03:29:21731 {
732 PrefService* local_state = g_browser_process->local_state();
733 if (local_state &&
734 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
735 command_line->AppendSwitch(switches::kRendererPrintPreview);
736 }
737 }
[email protected]4287a3d2011-06-13 23:56:51738
[email protected]47c7ec82012-01-18 03:29:21739 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51740 static const char* const kSwitchNames[] = {
741 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48742 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51743 switches::kAllowScriptingGallery,
744 switches::kAppsCheckoutURL,
745 switches::kAppsGalleryURL,
[email protected]b1c4de4c2012-06-08 00:04:56746 switches::kBrowserPlugin,
[email protected]be9d9c82011-07-13 04:17:31747 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51748 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10749 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50750 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53751 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09752 switches::kDisableInBrowserThumbnailing,
[email protected]4287a3d2011-06-13 23:56:51753 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21754 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13755 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51756 switches::kEnableCrxlessWebApps,
757 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:51758 switches::kEnableIPCFuzzing,
759 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05760 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48761 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53762 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51763 switches::kEnableWatchdog,
764 switches::kExperimentalSpellcheckerFeatures,
765 switches::kMemoryProfiling,
766 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37767 switches::kNoJsRandomness,
[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]871dc682012-06-11 19:35:331081 TabContents* tab_contents = TabContents::FromWebContents(tab);
1082 if (!tab_contents) {
1083 // If there is no TabContents for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451084 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141085 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401086 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451087 return;
1088 }
[email protected]871dc682012-06-11 19:35:331089 tab_contents->ssl_helper()->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401090 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451091}
1092
1093void ChromeContentBrowserClient::AddNewCertificate(
1094 net::URLRequest* request,
1095 net::X509Certificate* cert,
1096 int render_process_id,
1097 int render_view_id) {
1098 // The handler will run the UI and delete itself when it's finished.
1099 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1100}
1101
[email protected]a93670ab2012-02-24 03:46:391102void ChromeContentBrowserClient::RequestMediaAccessPermission(
1103 const content::MediaStreamRequest* request,
1104 const content::MediaResponseCallback& callback) {
1105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1106
[email protected]117b6b42012-02-29 09:11:081107 WebContents* contents = tab_util::GetWebContentsByID(
1108 request->render_process_id, request->render_view_id);
1109 if (!contents) {
1110 // Abort, if the tab was closed after the request was made but before we
1111 // got to this point.
1112 callback.Run(content::MediaStreamDevices());
1113 return;
1114 }
1115
[email protected]871dc682012-06-11 19:35:331116 TabContents* tab = TabContents::FromWebContents(contents);
[email protected]117b6b42012-02-29 09:11:081117 DCHECK(tab);
1118
1119 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1120 InfoBarDelegate* old_infobar = NULL;
1121 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1122 old_infobar =
[email protected]51d1fc62012-04-28 03:47:531123 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfoBarDelegate();
[email protected]117b6b42012-02-29 09:11:081124 }
1125
[email protected]117b6b42012-02-29 09:11:081126 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1127 request,
1128 callback);
1129 if (old_infobar)
1130 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1131 else
1132 infobar_helper->AddInfoBar(infobar);
[email protected]a93670ab2012-02-24 03:46:391133}
1134
[email protected]dc73a7b2012-03-25 15:27:181135content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1136 return MediaInternals::GetInstance();
1137}
1138
[email protected]941623e2011-06-07 23:06:041139void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1140 const GURL& source_origin,
1141 int callback_context,
1142 int render_process_id,
1143 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111144#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041145 RenderViewHost* rvh = RenderViewHost::FromID(
1146 render_process_id, render_view_id);
1147 if (!rvh) {
1148 NOTREACHED();
1149 return;
1150 }
1151
[email protected]9f76c1e2012-03-05 15:15:581152 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301153 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041154 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371155 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041156 service->RequestPermission(
1157 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131158 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111159#else
1160 NOTIMPLEMENTED();
1161#endif
[email protected]941623e2011-06-07 23:06:041162}
1163
1164WebKit::WebNotificationPresenter::Permission
1165 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021166 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201167 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021168 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111169#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201171 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021172 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1173 source_origin, render_process_id,
1174 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041175 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041176
1177 // Fall back to the regular notification preferences, which works on an
1178 // origin basis.
1179 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371180 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041181 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111182#else
1183 return WebKit::WebNotificationPresenter::PermissionAllowed;
1184#endif
[email protected]941623e2011-06-07 23:06:041185}
1186
1187void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171188 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041189 int render_process_id,
1190 int render_view_id,
1191 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111192#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041193 RenderViewHost* rvh = RenderViewHost::FromID(
1194 render_process_id, render_view_id);
1195 if (!rvh) {
1196 NOTREACHED();
1197 return;
1198 }
1199
[email protected]9f76c1e2012-03-05 15:15:581200 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301201 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041202 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371203 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041204 service->ShowDesktopNotification(
1205 params, render_process_id, render_view_id,
1206 worker ? DesktopNotificationService::WorkerNotification :
1207 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111208#else
1209 NOTIMPLEMENTED();
1210#endif
[email protected]941623e2011-06-07 23:06:041211}
1212
1213void ChromeContentBrowserClient::CancelDesktopNotification(
1214 int render_process_id,
1215 int render_view_id,
1216 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111217#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041218 RenderViewHost* rvh = RenderViewHost::FromID(
1219 render_process_id, render_view_id);
1220 if (!rvh) {
1221 NOTREACHED();
1222 return;
1223 }
1224
[email protected]9f76c1e2012-03-05 15:15:581225 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301226 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041227 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371228 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041229 service->CancelDesktopNotification(
1230 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111231#else
1232 NOTIMPLEMENTED();
1233#endif
[email protected]941623e2011-06-07 23:06:041234}
1235
[email protected]9f3fba52011-06-08 20:37:191236bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351237 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021238 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191239 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201240 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011241 int render_process_id,
1242 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011244
1245 *no_javascript_access = false;
1246
[email protected]9f3fba52011-06-08 20:37:191247 // If the opener is trying to create a background window but doesn't have
1248 // the appropriate permission, fail the attempt.
1249 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201250 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531251 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1252
[email protected]03b6d552012-03-29 04:03:011253 if (!map->SecurityOriginHasAPIPermission(
1254 source_origin,
1255 render_process_id,
1256 ExtensionAPIPermission::kBackground)) {
1257 return false;
1258 }
1259
[email protected]7b54ca02012-03-02 18:06:531260 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1261 // return a recently installed Extension even if this CanCreateWindow call
1262 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011263 // because the permission check above would have caused an early return
1264 // already. We must use the full URL to find hosted apps, though, and not
1265 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531266 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351267 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531268 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011269 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191270 }
1271 return true;
1272}
1273
1274std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201275 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1277 // Check if it's an extension-created worker, in which case we want to use
1278 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201279 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191280 const Extension* extension =
1281 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1282 return extension ? extension->name() : std::string();
1283}
1284
[email protected]99907362012-01-11 05:41:401285void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1286 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171287}
1288
[email protected]c52b2892012-03-07 11:01:021289content::SpeechRecognitionManagerDelegate*
1290 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321291#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021292 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321293#else
1294 return NULL;
1295#endif
[email protected]66cfec62012-02-24 17:57:511296}
1297
[email protected]ae6e9912011-07-27 01:18:281298net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1299 return g_browser_process->net_log();
1300}
1301
[email protected]32538d92011-08-25 00:09:231302AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1303 return new ChromeAccessTokenStore();
1304}
1305
[email protected]dbae6b02011-06-29 23:51:411306bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1307 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1308 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1309}
1310
[email protected]64d69de42012-02-06 00:19:541311void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321312 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061313 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581314 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061315 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061316
[email protected]f3986f82012-01-03 20:00:061317 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541318 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061319 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541320 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061321 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541322 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061323 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541324 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061325 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541326 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061327 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541328 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061329
[email protected]64d69de42012-02-06 00:19:541330 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401331 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541332 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401333 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541334 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401335 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541336 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401337 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061338
[email protected]ddf72142012-05-22 04:52:401339 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061340
[email protected]64d69de42012-02-06 00:19:541341 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401342 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541343 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061344 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541345 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061346 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1347 const DictionaryValue* inspector_settings =
1348 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1349 if (inspector_settings) {
1350 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1351 iter != inspector_settings->end_keys(); ++iter) {
1352 std::string value;
1353 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541354 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061355 std::make_pair(*iter, value));
1356 }
1357 }
[email protected]64d69de42012-02-06 00:19:541358 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061359
[email protected]ddf72142012-05-22 04:52:401360 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541361 web_prefs->javascript_enabled = false;
1362 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1363 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401364 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541365 web_prefs->plugins_enabled = false;
1366 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1367 web_prefs->java_enabled = false;
1368 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401369 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061370
[email protected]64d69de42012-02-06 00:19:541371 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1372 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061373
[email protected]64d69de42012-02-06 00:19:541374 web_prefs->memory_info_enabled =
1375 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1376 web_prefs->allow_displaying_insecure_content =
1377 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1378 web_prefs->allow_running_insecure_content =
1379 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081380 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061381
[email protected]64d69de42012-02-06 00:19:541382 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151383 UserStyleSheetWatcher* user_style_sheet_watcher =
1384 UserStyleSheetWatcherFactory::GetForProfile(profile);
1385 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541386 web_prefs->user_style_sheet_enabled = true;
1387 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151388 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541389 } else {
1390 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061391 }
1392
[email protected]b7e44ff2012-02-16 03:37:341393 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101394#if defined(OS_MACOSX)
1395 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1396 // Mac so it uses NSSpellChecker in the background.
1397 false;
1398#else
1399 !CommandLine::ForCurrentProcess()->
1400 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1401#endif
[email protected]b7e44ff2012-02-16 03:37:341402 web_prefs->unified_textchecker_enabled =
1403 web_prefs->asynchronous_spell_checking_enabled ||
1404 CommandLine::ForCurrentProcess()->
1405 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571406
[email protected]64d69de42012-02-06 00:19:541407 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061408 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541409 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061410 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541411 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061412 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1413
1414 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541415 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061416 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541417 web_prefs->default_encoding);
1418 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401419 prefs->ClearPref(prefs::kDefaultCharset);
1420 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061421 }
[email protected]64d69de42012-02-06 00:19:541422 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061423
[email protected]299d7f12012-05-23 05:31:151424 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1425 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061426 ExtensionService* service = profile->GetExtensionService();
1427 if (service) {
1428 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581429 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061430 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151431 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061432 }
1433
[email protected]4abe58d2012-06-08 03:09:091434 if (gpu_util::InForceCompositingModeTrial())
1435 web_prefs->force_compositing_mode = true;
1436
[email protected]299d7f12012-05-23 05:31:151437 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541438 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151439 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061440 // Disable all kinds of acceleration for background pages.
1441 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541442 web_prefs->force_compositing_mode = false;
1443 web_prefs->accelerated_compositing_enabled = false;
1444 web_prefs->accelerated_2d_canvas_enabled = false;
1445 web_prefs->accelerated_video_enabled = false;
1446 web_prefs->accelerated_painting_enabled = false;
1447 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061448 }
[email protected]2e21fe292012-03-02 22:52:321449
1450#if defined(FILE_MANAGER_EXTENSION)
1451 // Override the default of suppressing HW compositing for WebUI pages for the
1452 // file manager, which is implemented using WebUI but wants HW acceleration
1453 // for video decode & render.
1454 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1455 web_prefs->accelerated_compositing_enabled = true;
1456 web_prefs->accelerated_2d_canvas_enabled = true;
1457 }
1458#endif
[email protected]181a95ee2011-07-12 19:26:361459}
1460
1461void ChromeContentBrowserClient::UpdateInspectorSetting(
1462 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061463 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581464 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061465 DictionaryPrefUpdate update(
1466 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1467 prefs::kWebKitInspectorSettings);
1468 DictionaryValue* inspector_settings = update.Get();
1469 inspector_settings->SetWithoutPathExpansion(key,
1470 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361471}
1472
1473void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061474 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581475 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061476 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1477 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361478}
1479
[email protected]b8148ac2011-07-13 22:03:251480void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1481 BrowserURLHandler* handler) {
1482 // Add the default URL handlers.
1483 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1484 BrowserURLHandler::null_handler());
1485 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1486 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1487
[email protected]b3adbd02011-11-30 22:23:271488 // about: handler. Must come before chrome: handler, since it will
1489 // rewrite about: urls to chrome: URLs and then expect chrome: to
1490 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251491 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1492 BrowserURLHandler::null_handler());
1493 // chrome: & friends.
1494 handler->AddHandlerPair(&HandleWebUI,
1495 BrowserURLHandler::null_handler());
1496}
1497
1498void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371499 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581500 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251501 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1502 BrowsingDataRemover::EVERYTHING,
1503 base::Time());
[email protected]3d4d4cf2012-06-04 10:40:551504 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1505 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251506 // BrowsingDataRemover takes care of deleting itself when done.
1507}
1508
1509void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371510 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581511 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251512 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1513 BrowsingDataRemover::EVERYTHING,
1514 base::Time());
[email protected]dceaa912011-09-06 17:17:231515 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551516 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251517 // BrowsingDataRemover takes care of deleting itself when done.
1518}
1519
[email protected]e1d16eb92011-08-18 23:19:321520FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1521 return download_util::GetDefaultDownloadDirectory();
1522}
1523
[email protected]c9b6eb62011-10-18 20:49:391524std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1525 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1526}
1527
[email protected]a658d452012-03-02 12:45:291528bool ChromeContentBrowserClient::AllowSocketAPI(
1529 content::BrowserContext* browser_context, const GURL& url) {
1530 if (!url.is_valid())
1531 return false;
1532
1533 std::string host = url.host();
1534 if (allowed_socket_origins_.count(host))
1535 return true;
1536
[email protected]9a5940d2012-04-27 19:16:231537 Profile* profile = Profile::FromBrowserContext(browser_context);
1538 const Extension* extension = NULL;
1539 if (profile && profile->GetExtensionService()) {
1540 extension = profile->GetExtensionService()->extensions()->
1541 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1542 }
1543
[email protected]f237c0f2012-03-10 07:49:101544 // Need to check this now and not on construction because otherwise it won't
1545 // work with browser_tests.
1546 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1547 std::string allowed_list =
1548 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231549 if (allowed_list == "*") {
1550 // The wildcard allows socket API only for packaged and platform apps.
1551 return extension &&
1552 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1553 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1554 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101555 StringTokenizer t(allowed_list, ",");
1556 while (t.GetNext()) {
1557 if (t.token() == host)
1558 return true;
1559 }
1560 }
1561
[email protected]a658d452012-03-02 12:45:291562 if (!extension)
1563 return false;
1564
1565 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1566 return true;
1567
1568 return false;
[email protected]e461da2f2012-02-16 19:06:401569}
1570
[email protected]e60c0232011-11-11 19:56:351571#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301572int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521573 const CommandLine& command_line) {
1574 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071575 ExtensionCrashHandlerHostLinux* crash_handler =
1576 ExtensionCrashHandlerHostLinux::GetInstance();
1577 return crash_handler->GetDeathSignalSocket();
1578 }
1579
[email protected]718eab62011-10-05 21:16:521580 std::string process_type =
1581 command_line.GetSwitchValueASCII(switches::kProcessType);
1582
1583 if (process_type == switches::kRendererProcess)
1584 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1585
[email protected]b80f68432011-05-02 17:22:301586 if (process_type == switches::kPluginProcess)
1587 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1588
1589 if (process_type == switches::kPpapiPluginProcess)
1590 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1591
1592 if (process_type == switches::kGpuProcess)
1593 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1594
1595 return -1;
1596}
[email protected]e60c0232011-11-11 19:56:351597#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301598
[email protected]4a65826d2011-08-25 16:04:011599#if defined(OS_WIN)
1600const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1601 return chrome::kBrowserResourcesDll;
1602}
1603#endif
1604
[email protected]37a72af2011-06-13 05:42:011605#if defined(USE_NSS)
1606crypto::CryptoModuleBlockingPasswordDelegate*
1607 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1608 const GURL& url) {
1609 return browser::NewCryptoModuleBlockingDialogDelegate(
1610 browser::kCryptoModulePasswordKeygen, url.host());
1611}
1612#endif
1613
[email protected]d977f9c2011-03-14 16:10:261614} // namespace chrome