blob: 3da75825d26d5e463a446921cfce5f1deb1d6c44 [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]29699c22012-10-03 23:57:3913#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5714#include "base/prefs/pref_service.h"
[email protected]f4ebe772013-02-02 00:21:3915#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0616#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2518#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3019#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4720#include "chrome/browser/browsing_data/browsing_data_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1222#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4123#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4124#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5625#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0526#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4527#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3228#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0829#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3230#include "chrome/browser/download/download_util.h"
[email protected]24665682013-02-25 20:59:3831#include "chrome/browser/extensions/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1632#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0633#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0434#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3335#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2636#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0837#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2538#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0639#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4940#include "chrome/browser/extensions/message_handler.h"
[email protected]eb4832a2012-12-08 01:57:5241#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2342#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5644#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]0c7193742012-11-07 19:05:0345#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2846#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0447#include "chrome/browser/notifications/desktop_notification_service.h"
48#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4249#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5650#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0651#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4152#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5053#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0754#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4155#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1456#include "chrome/browser/printing/printing_message_filter.h"
57#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3258#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0659#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1460#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3361#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3862#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4363#include "chrome/browser/search/instant_service.h"
64#include "chrome/browser/search/instant_service_factory.h"
65#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]970c63e2013-03-07 00:25:3067#include "chrome/browser/signin/signin_manager.h"
68#include "chrome/browser/signin/signin_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:0269#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4670#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5871#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0372#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5273#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4574#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5475#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4376#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4477#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5078#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3079#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0680#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1581#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3082#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0183#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1484#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1385#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3086#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2987#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0488#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3889#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4490#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5891#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3492#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1293#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3894#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0995#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4496#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4397#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3098#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3899#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31100#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03101#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59102#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36103#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30104#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33105#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05106#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33107#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19108#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10109#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18111#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23112#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42113#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39114#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23115#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53116#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58117#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34118#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06119#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57120#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38121#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39122#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08123#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36124#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04125#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26126
[email protected]b48c9182011-10-26 18:03:30127#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38128#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18129#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38130#elif defined(OS_MACOSX)
131#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56132#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30133#elif defined(OS_CHROMEOS)
134#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49135#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26136#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30137#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09138#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38139#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09140#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39141#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30142#elif defined(OS_POSIX)
143#include "chrome/browser/chrome_browser_main_posix.h"
144#endif
145
[email protected]6653c192012-04-10 22:52:44146#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30147#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12148#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43149#endif
[email protected]b80f68432011-05-02 17:22:30150
[email protected]1e87df32012-09-12 04:53:19151#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
152#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
153#endif
154
[email protected]29699c22012-10-03 23:57:39155#if defined(OS_ANDROID)
156#include "ui/base/ui_base_paths.h"
157#endif
158
[email protected]37a72af2011-06-13 05:42:01159#if defined(USE_NSS)
160#include "chrome/browser/ui/crypto_module_password_dialog.h"
161#endif
162
[email protected]c7abd422012-09-25 00:20:08163using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47164using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03165using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39166using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31167using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59168using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08169using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00170using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11171using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33172using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13173using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06174using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34175using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40176using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25177using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39178
[email protected]c5dbef02011-05-13 05:06:09179namespace {
180
[email protected]e461da2f2012-02-16 19:06:40181const char* kPredefinedAllowedSocketOrigins[] = {
182 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18183 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45184 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
185 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
186 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
187 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35188 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54189 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
190 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
191 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
192 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
193 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
194 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38195 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58196 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
197 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40198};
199
[email protected]f8f93eb2012-09-25 03:06:24200// Returns a copy of the given url with its host set to given host and path set
201// to given path. Other parts of the url will be the same.
202GURL ReplaceURLHostAndPath(const GURL& url,
203 const std::string& host,
204 const std::string& path) {
205 url_canon::Replacements<char> replacements;
206 replacements.SetHost(host.c_str(),
207 url_parse::Component(0, host.length()));
208 replacements.SetPath(path.c_str(),
209 url_parse::Component(0, path.length()));
210 return url.ReplaceComponents(replacements);
211}
212
213// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
214GURL AddUberHost(const GURL& url) {
215 const std::string uber_host = chrome::kChromeUIUberHost;
216 const std::string new_path = url.host() + url.path();
217
218 return ReplaceURLHostAndPath(url, uber_host, new_path);
219}
220
[email protected]045bf7c2012-09-28 20:27:36221// If url->host() is "chrome" and url->path() has characters other than the
222// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
223// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24224bool RemoveUberHost(GURL* url) {
225 if (url->host() != chrome::kChromeUIUberHost)
226 return false;
227
[email protected]045bf7c2012-09-28 20:27:36228 if (url->path().empty() || url->path() == "/")
229 return false;
230
[email protected]f8f93eb2012-09-25 03:06:24231 const std::string old_path = url->path();
232
233 const std::string::size_type separator = old_path.find('/', 1);
234 std::string new_host;
235 std::string new_path;
236 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36237 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24238 } else {
239 new_host = old_path.substr(1, separator - 1);
240 new_path = old_path.substr(separator);
241 }
242
243 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
244
245 return true;
246}
247
[email protected]b8148ac2011-07-13 22:03:25248// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42249bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24250 // Do not handle special URLs such as "about:foo"
251 if (!url->host().empty()) {
252 const GURL chrome_url = AddUberHost(*url);
253
254 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
255 // be called.
256 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
257 browser_context, chrome_url))
258 return true;
259 }
260
[email protected]863f70a2012-01-27 02:05:50261 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
262 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25263 return false;
264
[email protected]fe69558d2012-03-12 11:34:49265#if defined(OS_CHROMEOS)
266 // Special case : in ChromeOS in Guest mode bookmarks and history are
267 // disabled for security reasons. New tab page explains the reasons, so
268 // we redirect user to new tab page.
269 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
270 if (url->SchemeIs(chrome::kChromeUIScheme) &&
271 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
272 url->DomainIs(chrome::kChromeUIHistoryHost))) {
273 // Rewrite with new tab URL
274 *url = GURL(chrome::kChromeUINewTabURL);
275 }
276 }
277#endif
278
[email protected]b8148ac2011-07-13 22:03:25279 // Special case the new tab page. In older versions of Chrome, the new tab
280 // page was hosted at chrome-internal:<blah>. This might be in people's saved
281 // sessions or bookmarks, so we say any URL with that scheme triggers the new
282 // tab page.
283 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
284 // Rewrite it with the proper new tab URL.
285 *url = GURL(chrome::kChromeUINewTabURL);
286 }
287
288 return true;
289}
290
[email protected]f8f93eb2012-09-25 03:06:24291// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
292// "chrome://foo/".
293bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
294 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
295 return false;
296
297 return RemoveUberHost(url);
298}
299
[email protected]8d3132f62011-10-12 07:13:42300// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
301// below. Extension, and isolated apps require different privileges to be
302// granted to their RenderProcessHosts. This classification allows us to make
303// sure URLs are served by hosts with the right set of privileges.
304enum RenderProcessHostPrivilege {
305 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45306 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42307 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45308 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42309};
310
311RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
312 const GURL& url,
313 ExtensionService* service) {
314 // Default to a normal renderer cause it is lower privileged. This should only
315 // occur if the URL on a site instance is either malformed, or uninitialized.
316 // If it is malformed, then there is no need for better privileges anyways.
317 // If it is uninitialized, but eventually settles on being an a scheme other
318 // than normal webrenderer, the navigation logic will correct us out of band
319 // anyways.
320 if (!url.is_valid())
321 return PRIV_NORMAL;
322
[email protected]885c0e92012-11-13 20:27:42323 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44324 const Extension* extension =
325 service->extensions()->GetByID(url.host());
[email protected]c86a8262013-03-31 07:58:57326 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42327 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45328 if (extension && extension->is_hosted_app())
329 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42330
331 return PRIV_EXTENSION;
332 }
333
334 return PRIV_NORMAL;
335}
336
337RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30338 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46339 extensions::ProcessMap* process_map,
340 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46341 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30342 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46343 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21344 return PRIV_NORMAL;
345
[email protected]6f371442011-11-09 06:45:46346 for (std::set<std::string>::iterator iter = extension_ids.begin();
347 iter != extension_ids.end(); ++iter) {
348 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]c86a8262013-03-31 07:58:57349 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42350 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45351 if (extension && extension->is_hosted_app())
352 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42353 }
354
[email protected]676f6ab2011-10-19 20:23:21355 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42356}
357
[email protected]6786bf402011-12-03 15:19:45358bool CertMatchesFilter(const net::X509Certificate& cert,
359 const base::DictionaryValue& filter) {
360 // TODO(markusheintz): This is the minimal required filter implementation.
361 // Implement a better matcher.
362
363 // An empty filter matches any client certificate since no requirements are
364 // specified at all.
365 if (filter.empty())
366 return true;
367
368 std::string common_name;
369 if (filter.GetString("ISSUER.CN", &common_name) &&
370 (cert.issuer().common_name == common_name)) {
371 return true;
372 }
373 return false;
374}
375
[email protected]f3986f82012-01-03 20:00:06376// Fills |map| with the per-script font prefs under path |map_name|.
377void FillFontFamilyMap(const PrefService* prefs,
378 const char* map_name,
379 WebPreferences::ScriptFontFamilyMap* map) {
380 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
381 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
382 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
383 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23384 if (!font_family.empty())
385 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06386 }
387}
388
[email protected]a1733df2012-06-22 11:24:18389#if defined(OS_POSIX) && !defined(OS_MACOSX)
390int GetCrashSignalFD(const CommandLine& command_line) {
391 if (command_line.HasSwitch(switches::kExtensionProcess)) {
392 ExtensionCrashHandlerHostLinux* crash_handler =
393 ExtensionCrashHandlerHostLinux::GetInstance();
394 return crash_handler->GetDeathSignalSocket();
395 }
396
397 std::string process_type =
398 command_line.GetSwitchValueASCII(switches::kProcessType);
399
400 if (process_type == switches::kRendererProcess)
401 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
402
403 if (process_type == switches::kPluginProcess)
404 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
405
406 if (process_type == switches::kPpapiPluginProcess)
407 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
408
409 if (process_type == switches::kGpuProcess)
410 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
411
412 return -1;
413}
414#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
415
[email protected]7c60f5042013-02-14 03:39:32416// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52417// facilitates grouping process-per-site. The |url| is transformed, for
418// example, from
419//
420// https://www.google.com/search?espv=1&q=tractors
421//
[email protected]7c60f5042013-02-14 03:39:32422// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52423//
424// chrome-search://www.google.com/search?espv=1&q=tractors
425//
426// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32427//
428// If the input is already an effective URL then that same URL is returned.
429GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
[email protected]165fe422013-03-27 06:34:03430 CHECK(chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32431 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52432
433 if (url.SchemeIs(chrome::kChromeSearchScheme))
434 return url;
435
436 GURL effective_url(url);
437
438 // Replace the scheme with "chrome-search:".
439 url_canon::Replacements<char> replacements;
440 std::string search_scheme(chrome::kChromeSearchScheme);
441 replacements.SetScheme(search_scheme.data(),
442 url_parse::Component(0, search_scheme.length()));
443 effective_url = effective_url.ReplaceComponents(replacements);
444 return effective_url;
445}
446
[email protected]970c63e2013-03-07 00:25:30447GURL GetEffectiveURLForSignin(const GURL& url) {
448 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
449
450 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03451 // Copy the path because the argument to SetPathStr must outlive
452 // the Replacements object.
453 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30454 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03455 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30456 effective_url = effective_url.ReplaceComponents(replacements);
457 return effective_url;
458}
459
[email protected]9dbfff12011-07-01 19:37:07460} // namespace
[email protected]c5dbef02011-05-13 05:06:09461
[email protected]d977f9c2011-03-14 16:10:26462namespace chrome {
463
[email protected]e461da2f2012-02-16 19:06:40464ChromeContentBrowserClient::ChromeContentBrowserClient() {
465 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
466 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40467}
468
469ChromeContentBrowserClient::~ChromeContentBrowserClient() {
470}
471
[email protected]bca18382012-06-25 19:15:23472// static
[email protected]c753f142013-02-10 13:14:04473void ChromeContentBrowserClient::RegisterUserPrefs(
474 PrefRegistrySyncable* registry) {
475 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
476 false,
477 PrefRegistrySyncable::UNSYNCABLE_PREF);
478 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
479 true,
480 PrefRegistrySyncable::UNSYNCABLE_PREF);
481 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
482 false,
483 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23484}
485
[email protected]50462bf02011-11-21 19:13:31486content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
487 const content::MainFunctionParams& parameters) {
488 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30489 // Construct the Main browser parts based on the OS type.
490#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31491 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04492#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31493 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30494#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22495 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26496#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31497 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14498#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09499 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30500#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31501 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04502#else
[email protected]b48c9182011-10-26 18:03:30503 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31504 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30505#endif
506
[email protected]c7480942011-11-08 19:18:27507 // Construct additional browser parts. Stages are called in the order in
508 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22509#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41510 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04511#endif
[email protected]c7480942011-11-08 19:18:27512
513#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41514 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27515#endif
516
[email protected]dc04be7c2012-03-15 23:57:49517#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41518 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49519#endif
520
[email protected]e050ef142012-03-21 01:04:24521#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41522 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24523#endif
524
[email protected]50462bf02011-11-21 19:13:31525 return main_parts;
[email protected]f967b722011-09-07 00:58:04526}
527
[email protected]e94bbcb2012-09-07 05:33:57528std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19529 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57530 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53531 std::string partition_id;
532
533 // The partition ID for webview guest processes is the string value of its
534 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
535 if (site.SchemeIs(chrome::kGuestScheme))
536 partition_id = site.spec();
537
538 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
539 return partition_id;
540}
541
542bool ChromeContentBrowserClient::IsValidStoragePartitionId(
543 content::BrowserContext* browser_context,
544 const std::string& partition_id) {
545 // The default ID is empty and is always valid.
546 if (partition_id.empty())
547 return true;
548
549 return GURL(partition_id).is_valid();
550}
551
552void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
553 content::BrowserContext* browser_context,
554 const GURL& site,
[email protected]14acc642012-11-17 12:20:10555 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53556 std::string* partition_domain,
557 std::string* partition_name,
558 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10559 // Default to the browser-wide storage partition and override based on |site|
560 // below.
561 partition_domain->clear();
562 partition_name->clear();
563 *in_memory = false;
564
[email protected]1bc28312012-11-08 08:31:53565 // For the webview tag, we create special guest processes, which host the
566 // tag content separately from the main application that embeds the tag.
567 // A webview tag can specify both the partition name and whether the storage
568 // for that partition should be persisted. Each tag gets a SiteInstance with
569 // a specially formatted URL, based on the application it is hosted by and
570 // the partition requested by it. The format for that URL is:
571 // chrome-guest://partition_domain/persist?partition_name
572 if (site.SchemeIs(chrome::kGuestScheme)) {
573 // Since guest URLs are only used for packaged apps, there must be an app
574 // id in the URL.
575 CHECK(site.has_host());
576 *partition_domain = site.host();
577 // Since persistence is optional, the path must either be empty or the
578 // literal string.
579 *in_memory = (site.path() != "/persist");
580 // The partition name is user supplied value, which we have encoded when the
581 // URL was created, so it needs to be decoded.
582 *partition_name = net::UnescapeURLComponent(site.query(),
583 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10584 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
585 // If |can_be_default| is false, the caller is stating that the |site|
586 // should be parsed as if it had isolated storage. In particular it is
587 // important to NOT check ExtensionService for the is_storage_isolated()
588 // attribute because this code path is run during Extension uninstall
589 // to do cleanup after the Extension has already been unloaded from the
590 // ExtensionService.
591 bool is_isolated = !can_be_default;
592 if (can_be_default) {
593 const Extension* extension = NULL;
594 Profile* profile = Profile::FromBrowserContext(browser_context);
595 ExtensionService* extension_service =
596 extensions::ExtensionSystem::Get(profile)->extension_service();
597 if (extension_service) {
598 extension = extension_service->extensions()->
599 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]c86a8262013-03-31 07:58:57600 if (extension && extension->is_storage_isolated()) {
[email protected]14acc642012-11-17 12:20:10601 is_isolated = true;
602 }
603 }
604 }
[email protected]1bc28312012-11-08 08:31:53605
[email protected]14acc642012-11-17 12:20:10606 if (is_isolated) {
607 CHECK(site.has_host());
608 // For extensions with isolated storage, the the host of the |site| is
609 // the |partition_domain|. The |in_memory| and |partition_name| are only
610 // used in guest schemes so they are cleared here.
611 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53612 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10613 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53614 }
[email protected]d1198fd2012-08-13 22:50:19615 }
616
[email protected]14acc642012-11-17 12:20:10617 // Assert that if |can_be_default| is false, the code above must have found a
618 // non-default partition. If this fails, the caller has a serious logic
619 // error about which StoragePartition they expect to be in and it is not
620 // safe to continue.
621 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44622}
623
[email protected]38b098f2012-03-14 21:11:57624content::WebContentsViewDelegate*
625 ChromeContentBrowserClient::GetWebContentsViewDelegate(
626 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27627 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32628}
629
[email protected]f364d1392011-04-08 21:03:10630void ChromeContentBrowserClient::RenderViewHostCreated(
631 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46632
[email protected]9f76c1e2012-03-05 15:15:58633 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46634 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02635 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46636
637 new ChromeRenderViewHostObserver(render_view_host,
638 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49639 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26640}
641
[email protected]24665682013-02-25 20:59:38642// Check if the extension activity log is enabled for the profile.
643static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
644 extensions::ActivityLog* activity_log =
645 extensions::ActivityLog::GetInstance(profile);
646 return activity_log->IsLogEnabled();
647}
648
[email protected]44703cc72013-01-24 04:56:06649void ChromeContentBrowserClient::GuestWebContentsCreated(
650 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
651 Profile* profile = Profile::FromBrowserContext(
652 embedder_web_contents->GetBrowserContext());
653 ExtensionService* service =
654 extensions::ExtensionSystem::Get(profile)->extension_service();
655 if (!service)
656 return;
657 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
658 const Extension* extension = service->extensions()->
659 GetExtensionOrAppByURL(ExtensionURLInfo(url));
660 if (!extension)
661 return;
662 std::vector<ExtensionMsg_Loaded_Params> extensions;
663 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
664 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
665}
666
[email protected]f3b1a082011-11-18 00:34:30667void ChromeContentBrowserClient::RenderProcessHostCreated(
668 content::RenderProcessHost* host) {
669 int id = host->GetID();
670 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41671 net::URLRequestContextGetter* context =
672 profile->GetRequestContextForRenderProcess(id);
673
[email protected]f3b1a082011-11-18 00:34:30674 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41675 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55676#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30677 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55678#endif
[email protected]658677f2012-06-09 06:04:02679#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08680 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03681#endif
[email protected]f3b1a082011-11-18 00:34:30682 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02683 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30684 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56685#if defined(OS_MACOSX)
686 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
687#endif
[email protected]43535512013-02-20 20:41:41688 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
689 id, profile, context));
[email protected]2736c032012-05-11 18:06:07690 host->GetChannel()->AddFilter(
691 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38692
[email protected]2ccf45c2011-08-19 23:35:50693 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
694 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07695
[email protected]24665682013-02-25 20:59:38696 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
697 IsExtensionActivityLogEnabledForProfile(profile)));
698
[email protected]39a5b532011-10-22 01:47:07699 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56700
701 RendererContentSettingRules rules;
702 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
703 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14704}
705
[email protected]3d7474ff2011-07-27 17:47:37706GURL ChromeContentBrowserClient::GetEffectiveURL(
707 content::BrowserContext* browser_context, const GURL& url) {
708 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52709 if (!profile)
710 return url;
711
[email protected]7c60f5042013-02-14 03:39:32712 // If the input |url| should be assigned to the Instant renderer, make its
713 // effective URL distinct from other URLs on the search provider's domain.
[email protected]165fe422013-03-27 06:34:03714 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32715 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52716
[email protected]970c63e2013-03-07 00:25:30717 // If the input |url| should be assigned to the Signin renderer, make its
718 // effective URL distinct from other URLs on the signin service's domain.
719 // Note that the signin renderer will be allowed to sign the user in to
720 // Chrome.
721 if (SigninManager::IsWebBasedSigninFlowURL(url))
722 return GetEffectiveURLForSignin(url);
723
[email protected]c5dec6292013-01-25 04:54:52724 // If the input |url| is part of an installed app, the effective URL is an
725 // extension URL with the ID of that extension as the host. This has the
726 // effect of grouping apps together in a common SiteInstance.
727 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13728 extensions::ExtensionSystem::Get(profile)->extension_service();
729 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08730 return url;
731
[email protected]06bdd2b2012-11-30 18:47:13732 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44733 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08734 if (!extension)
735 return url;
736
[email protected]15877ca2011-11-18 22:40:52737 // Bookmark apps do not use the hosted app process model, and should be
738 // treated as normal URLs.
739 if (extension->from_bookmark())
740 return url;
741
[email protected]36fb2c7c2011-04-04 15:49:08742 // If the URL is part of an extension's web extent, convert it to an
743 // extension URL.
744 return extension->GetResourceURL(url.path());
745}
746
[email protected]056ad2a2011-07-12 02:13:55747bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37748 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52749 // Non-extension, non-Instant URLs should generally use
750 // process-per-site-instance. Because we expect to use the effective URL,
751 // URLs for hosted apps (apart from bookmark apps) should have an extension
752 // scheme by now.
753
754 Profile* profile = Profile::FromBrowserContext(browser_context);
755 if (!profile)
756 return false;
757
[email protected]165fe422013-03-27 06:34:03758 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52759 return true;
760
[email protected]970c63e2013-03-07 00:25:30761 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
762 return true;
763
[email protected]885c0e92012-11-13 20:27:42764 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55765 return false;
766
[email protected]c5dec6292013-01-25 04:54:52767 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13768 extensions::ExtensionSystem::Get(profile)->extension_service();
769 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55770 return false;
771
[email protected]06bdd2b2012-11-30 18:47:13772 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44773 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55774 if (!extension)
775 return false;
776
777 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53778 // permission, or that does not allow JavaScript access to the background
779 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55780 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40781 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06782 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29783 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53784 return false;
785 }
786 }
[email protected]056ad2a2011-07-12 02:13:55787
[email protected]7b54ca02012-03-02 18:06:53788 // Hosted apps that have script access to their background page must use
789 // process per site, since all instances can make synchronous calls to the
790 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55791 return true;
792}
793
[email protected]672c8c12013-03-07 12:30:06794// These are treated as WebUI schemes but do not get WebUI bindings.
795std::vector<std::string>
796ChromeContentBrowserClient::GetAdditionalWebUISchemes() {
797 std::vector<std::string> additional_schemes;
798 additional_schemes.push_back(chrome::kChromeSearchScheme);
799 return additional_schemes;
800}
801
[email protected]6bd30072013-02-08 18:17:11802net::URLRequestContextGetter*
803ChromeContentBrowserClient::CreateRequestContext(
804 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06805 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11806 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06807 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11808}
809
810net::URLRequestContextGetter*
811ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
812 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40813 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11814 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06815 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11816 Profile* profile = Profile::FromBrowserContext(browser_context);
817 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06818 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11819}
820
[email protected]46fb9442011-12-09 17:57:47821bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
822 return ProfileIOData::IsHandledURL(url);
823}
824
[email protected]2a5221b2011-09-27 23:07:31825bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30826 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31827 const GURL& site_url) {
828 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30829 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52830 // This may be NULL during tests. In that case, just assume any site can
831 // share any host.
832 if (!profile)
833 return true;
834
[email protected]d43f99fe2013-04-03 00:20:14835 // Instant URLs should only be in the instant process and instant process
836 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52837 InstantService* instant_service =
838 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14839 if (instant_service) {
840 bool is_instant_process = instant_service->IsInstantProcess(
841 process_host->GetID());
842 bool should_be_in_instant_process =
843 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
844 if (is_instant_process || should_be_in_instant_process)
845 return is_instant_process && should_be_in_instant_process;
846 }
[email protected]c5dec6292013-01-25 04:54:52847
[email protected]970c63e2013-03-07 00:25:30848 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
849 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
850 return SigninManager::IsWebBasedSigninFlowURL(site_url);
851
[email protected]06bdd2b2012-11-30 18:47:13852 ExtensionService* service =
853 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46854 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31855
[email protected]ffa97602011-11-17 17:55:52856 // Don't allow the Task Manager to share a process with anything else.
857 // Otherwise it can affect the renderers it is observing.
858 // Note: we could create another RenderProcessHostPrivilege bucket for
859 // this to allow multiple chrome://tasks instances to share, but that's
860 // a very unlikely case without serious consequences.
861 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
862 return false;
863
[email protected]8d3132f62011-10-12 07:13:42864 // These may be NULL during tests. In that case, just assume any site can
865 // share any host.
[email protected]6f371442011-11-09 06:45:46866 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31867 return true;
868
[email protected]eec0b33c2011-12-05 22:09:45869 // Otherwise, just make sure the process privilege matches the privilege
870 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57871 RenderProcessHostPrivilege privilege_required =
872 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45873 return GetProcessPrivilege(process_host, process_map, service) ==
874 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31875}
876
[email protected]76411f412012-02-22 18:56:06877// This function is trying to limit the amount of processes used by extensions
878// with background pages. It uses a globally set percentage of processes to
879// run such extensions and if the limit is exceeded, it returns true, to
880// indicate to the content module to group extensions together.
881bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
882 content::BrowserContext* browser_context, const GURL& url) {
883 // It has to be a valid URL for us to check for an extension.
884 if (!url.is_valid())
885 return false;
886
887 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19888 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13889 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06890 if (!service)
891 return false;
892
893 // We have to have a valid extension with background page to proceed.
894 const Extension* extension =
895 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
896 if (!extension)
897 return false;
[email protected]9367eabc2013-03-01 01:29:29898 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06899 return false;
900
901 std::set<int> process_ids;
902 size_t max_process_count =
903 content::RenderProcessHost::GetMaxRendererProcessCount();
904
905 // Go through all profiles to ensure we have total count of extension
906 // processes containing background pages, otherwise one profile can
907 // starve the other.
908 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
909 GetLoadedProfiles();
910 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03911 ExtensionProcessManager* epm =
912 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32913 for (ExtensionProcessManager::const_iterator iter =
914 epm->background_hosts().begin();
915 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13916 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32917 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06918 }
919 }
920
921 if (process_ids.size() >
922 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
923 return true;
924 }
925
926 return false;
927}
928
[email protected]6f371442011-11-09 06:45:46929void ChromeContentBrowserClient::SiteInstanceGotProcess(
930 SiteInstance* site_instance) {
931 CHECK(site_instance->HasProcess());
932
933 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02934 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52935 if (!profile)
936 return;
937
938 // Remember the ID of the Instant process to signal the renderer process
939 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:03940 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:32941 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52942 InstantService* instant_service =
943 InstantServiceFactory::GetForProfile(profile);
944 if (instant_service)
945 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
946 }
947
[email protected]970c63e2013-03-07 00:25:30948 // We only expect there to be one signin process as we use process-per-site
949 // for signin URLs. The signin process will be cleared from SigninManager
950 // when the renderer is destroyed.
951 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
952 SigninManager* signin_manager =
953 SigninManagerFactory::GetForProfile(profile);
954 if (signin_manager)
955 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
956 }
957
[email protected]06bdd2b2012-11-30 18:47:13958 ExtensionService* service =
959 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46960 if (!service)
961 return;
962
963 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44964 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59965 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46966 if (!extension)
967 return;
968
[email protected]6bc04fd82011-12-04 02:29:35969 service->process_map()->Insert(extension->id(),
970 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33971 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46972 BrowserThread::PostTask(
973 BrowserThread::IO, FROM_HERE,
974 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59975 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46976 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35977 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33978 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46979}
980
981void ChromeContentBrowserClient::SiteInstanceDeleting(
982 SiteInstance* site_instance) {
983 if (!site_instance->HasProcess())
984 return;
985
986 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02987 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13988 ExtensionService* service =
989 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46990 if (!service)
991 return;
992
993 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44994 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59995 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46996 if (!extension)
997 return;
998
[email protected]6bc04fd82011-12-04 02:29:35999 service->process_map()->Remove(extension->id(),
1000 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331001 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461002 BrowserThread::PostTask(
1003 BrowserThread::IO, FROM_HERE,
1004 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591005 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461006 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351007 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331008 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461009}
1010
[email protected]f05763972012-06-06 18:17:261011bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141012 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081013 const GURL& current_url,
1014 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261015 if (current_url.is_empty()) {
1016 // Always choose a new process when navigating to extension URLs. The
1017 // process grouping logic will combine all of a given extension's pages
1018 // into the same process.
[email protected]885c0e92012-11-13 20:27:421019 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261020 return true;
[email protected]e3daf3c2011-10-05 21:17:081021
[email protected]f05763972012-06-06 18:17:261022 return false;
1023 }
1024
1025 // Also, we must switch if one is an extension and the other is not the exact
1026 // same extension.
[email protected]885c0e92012-11-13 20:27:421027 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1028 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261029 if (current_url.GetOrigin() != new_url.GetOrigin())
1030 return true;
1031 }
1032
[email protected]e9841fbd2013-02-22 23:12:141033 // The checks below only matter if we can retrieve which extensions are
1034 // installed.
1035 Profile* profile =
1036 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1037 ExtensionService* service =
1038 extensions::ExtensionSystem::Get(profile)->extension_service();
1039 if (!service)
1040 return false;
1041
1042 // We must swap if the URL is for an extension and we are not using an
1043 // extension process.
1044 const Extension* new_extension =
1045 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1046 // Ignore all hosted apps except the Chrome Web Store, since they do not
1047 // require their own BrowsingInstance (e.g., postMessage is ok).
1048 if (new_extension &&
1049 new_extension->is_hosted_app() &&
1050 new_extension->id() != extension_misc::kWebStoreAppId)
1051 new_extension = NULL;
1052 if (new_extension &&
1053 site_instance->HasProcess() &&
1054 !service->process_map()->Contains(new_extension->id(),
1055 site_instance->GetProcess()->GetID()))
1056 return true;
1057
[email protected]f05763972012-06-06 18:17:261058 return false;
[email protected]e3daf3c2011-10-05 21:17:081059}
1060
[email protected]395045c2012-05-22 15:04:381061bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1062 content::ResourceContext* resource_context, const GURL& current_url,
1063 const GURL& new_url) {
1064 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1065 return extensions::CrossesExtensionProcessBoundary(
1066 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171067 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381068}
1069
[email protected]763ec4ca2011-04-29 15:48:121070std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1071 const std::string& alias_name) {
1072 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1073}
1074
[email protected]b80f68432011-05-02 17:22:301075void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1076 CommandLine* command_line, int child_process_id) {
1077#if defined(USE_LINUX_BREAKPAD)
1078 if (IsCrashReporterEnabled()) {
1079 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1080 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1081 }
1082#elif defined(OS_MACOSX)
1083 if (IsCrashReporterEnabled()) {
1084 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1085 child_process_logging::GetClientId());
1086 }
1087#endif // OS_MACOSX
1088
[email protected]f1933792011-06-14 00:49:341089 if (logging::DialogsAreSuppressed())
1090 command_line->AppendSwitch(switches::kNoErrorDialogs);
1091
[email protected]b80f68432011-05-02 17:22:301092 std::string process_type =
1093 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171094 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321095
1096 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1097 command_line->AppendSwitch(switches::kChromeFrame);
1098
[email protected]718eab62011-10-05 21:16:521099 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451100 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301101 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1102 if (!user_data_dir.empty())
1103 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1104#if defined(OS_CHROMEOS)
1105 const std::string& login_profile =
1106 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1107 if (!login_profile.empty())
1108 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1109#endif
1110
[email protected]f3b1a082011-11-18 00:34:301111 content::RenderProcessHost* process =
1112 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371113 if (process) {
1114 Profile* profile = Profile::FromBrowserContext(
1115 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131116 ExtensionService* extension_service =
1117 extensions::ExtensionSystem::Get(profile)->extension_service();
1118 if (extension_service) {
1119 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001120 if (process_map && process_map->Contains(process->GetID()))
1121 command_line->AppendSwitch(switches::kExtensionProcess);
1122 }
[email protected]b80f68432011-05-02 17:22:301123
[email protected]a8d851f82011-12-21 00:32:371124 PrefService* prefs = profile->GetPrefs();
1125 // Currently this pref is only registered if applied via a policy.
1126 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1127 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1128 // Turn this policy into a command line switch.
1129 command_line->AppendSwitch(switches::kDisable3DAPIs);
1130 }
[email protected]718eab62011-10-05 21:16:521131
[email protected]a8d851f82011-12-21 00:32:371132 // Disable client-side phishing detection in the renderer if it is
1133 // disabled in the Profile preferences or the browser process.
1134 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1135 !g_browser_process->safe_browsing_detection_service()) {
1136 command_line->AppendSwitch(
1137 switches::kDisableClientSidePhishingDetection);
1138 }
[email protected]0045b0f42012-07-26 11:52:081139
1140 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211141 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521142
1143 InstantService* instant_service =
1144 InstantServiceFactory::GetForProfile(profile);
1145 if (instant_service &&
1146 instant_service->IsInstantProcess(process->GetID()))
1147 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301148
1149 SigninManager* signin_manager =
1150 SigninManagerFactory::GetForProfile(profile);
1151 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1152 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]47c7ec82012-01-18 03:29:211153 }
[email protected]4287a3d2011-06-13 23:56:511154
[email protected]87552982012-11-02 17:21:401155 if (content::IsThreadedCompositingEnabled())
1156 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1157
[email protected]47c7ec82012-01-18 03:29:211158 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511159 static const char* const kSwitchNames[] = {
[email protected]8f96cef2013-04-01 16:51:131160 switches::kAllowRequestOSFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511161 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481162 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511163 switches::kAllowScriptingGallery,
1164 switches::kAppsCheckoutURL,
1165 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311166 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511167 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501168 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531169 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111170 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511171 switches::kDumpHistogramsOnExit,
[email protected]e9cddd52013-03-23 17:37:531172 switches::kEnableAdview,
1173 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211174 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511175 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561176 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511177 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511178 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511179 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451180 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481181 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051182 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511183 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291184 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511185 switches::kMemoryProfiling,
1186 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371187 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581188 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371189 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511190 switches::kPpapiFlashArgs,
1191 switches::kPpapiFlashInProcess,
1192 switches::kPpapiFlashPath,
1193 switches::kPpapiFlashVersion,
1194 switches::kProfilingAtStart,
1195 switches::kProfilingFile,
1196 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371197 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511198 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291199 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381200 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511201 };
1202
1203 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1204 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171205 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381206 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351207 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381208 switches::kEnableExperimentalExtensionApis,
1209 switches::kWhitelistedExtensionID,
1210 };
1211
1212 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1213 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511214 } else if (process_type == switches::kPluginProcess) {
1215 static const char* const kSwitchNames[] = {
1216 #if defined(OS_CHROMEOS)
1217 switches::kLoginProfile,
1218 #endif
1219 switches::kMemoryProfiling,
1220 switches::kSilentDumpOnDCHECK,
1221 switches::kUserDataDir,
1222 };
1223
1224 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1225 arraysize(kSwitchNames));
1226 } else if (process_type == switches::kZygoteProcess) {
1227 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511228 switches::kUserDataDir, // Make logs go to the right file.
1229 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501230 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511231 switches::kPpapiFlashInProcess,
1232 switches::kPpapiFlashPath,
1233 switches::kPpapiFlashVersion,
1234 };
1235
1236 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1237 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111238 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001239 base::FilePath user_data_dir =
1240 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1241 if (!user_data_dir.empty())
1242 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111243 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1244 // because GPU is expected to be unreliable.
1245 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1246 !command_line->HasSwitch(switches::kDisableBreakpad))
1247 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301248 }
[email protected]6f08af82011-09-15 01:19:031249
1250 // The command line switch kEnableBenchmarking needs to be specified along
1251 // with the kEnableStatsTable switch to ensure that the stats table global
1252 // is initialized correctly.
1253 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1254 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301255}
1256
1257std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431258 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1259 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301260 return g_browser_process->GetApplicationLocale();
1261}
1262
[email protected]597a867b2011-11-18 18:31:201263std::string ChromeContentBrowserClient::GetAcceptLangs(
1264 content::BrowserContext* context) {
1265 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371266 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081267}
1268
[email protected]9ec0f452012-05-31 15:58:531269gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221270 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531271 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081272}
1273
[email protected]a2176792011-05-08 19:30:491274bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091275 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191276 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201277 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201279 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051280 return io_data->GetCookieSettings()->
1281 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491282}
1283
[email protected]ed24fad2011-05-10 22:44:011284bool ChromeContentBrowserClient::AllowGetCookie(
1285 const GURL& url,
1286 const GURL& first_party,
1287 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201288 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011289 int render_process_id,
1290 int render_view_id) {
1291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201292 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051293 bool allow = io_data->GetCookieSettings()->
1294 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011295
[email protected]8093a542011-05-13 07:29:321296 BrowserThread::PostTask(
1297 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031298 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431299 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011300 return allow;
1301}
1302
1303bool ChromeContentBrowserClient::AllowSetCookie(
1304 const GURL& url,
1305 const GURL& first_party,
1306 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201307 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011308 int render_process_id,
1309 int render_view_id,
1310 net::CookieOptions* options) {
1311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201312 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051313 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1314 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1315
[email protected]8093a542011-05-13 07:29:321316 BrowserThread::PostTask(
1317 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031318 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431319 render_view_id, url, first_party, cookie_line, *options,
1320 !allow));
[email protected]ed24fad2011-05-10 22:44:011321 return allow;
1322}
1323
[email protected]d5a19162011-06-30 18:51:541324bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201325 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201327 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431328 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1329 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261330
[email protected]bf510ed2012-06-05 08:31:431331 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1332 // Could we even support per-origin settings?
1333 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541334}
1335
[email protected]5c5a88e2011-11-12 00:45:351336bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351337 const GURL& url,
1338 const string16& name,
1339 const string16& display_name,
1340 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201341 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481342 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201344 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351345 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1346 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1347
[email protected]62151052012-02-01 18:40:481348 // Record access to database for potential display in UI.
1349 std::vector<std::pair<int, int> >::const_iterator i;
1350 for (i = render_views.begin(); i != render_views.end(); ++i) {
1351 BrowserThread::PostTask(
1352 BrowserThread::UI, FROM_HERE,
1353 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1354 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351355 }
1356
1357 return allow;
1358}
1359
1360bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351361 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201362 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481363 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201365 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351366 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1367 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1368
[email protected]62151052012-02-01 18:40:481369 // Record access to file system for potential display in UI.
1370 std::vector<std::pair<int, int> >::const_iterator i;
1371 for (i = render_views.begin(); i != render_views.end(); ++i) {
1372 BrowserThread::PostTask(
1373 BrowserThread::UI, FROM_HERE,
1374 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1375 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351376 }
1377
1378 return allow;
1379}
1380
[email protected]7c5ff9a2012-03-02 07:42:491381bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1382 const GURL& url,
1383 const string16& name,
1384 content::ResourceContext* context,
1385 const std::vector<std::pair<int, int> >& render_views) {
1386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1387 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1388 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1389 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1390
1391 // Record access to IndexedDB for potential display in UI.
1392 std::vector<std::pair<int, int> >::const_iterator i;
1393 for (i = render_views.begin(); i != render_views.end(); ++i) {
1394 BrowserThread::PostTask(
1395 BrowserThread::UI, FROM_HERE,
1396 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1397 i->first, i->second, url, name, !allow));
1398 }
1399
1400 return allow;
1401}
1402
[email protected]6133f922011-07-01 21:34:341403net::URLRequestContext*
1404ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201405 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421407 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201408 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341409 return io_data->extensions_request_context();
1410 }
1411
1412 return NULL;
1413}
1414
[email protected]317f96c92011-05-31 06:53:411415QuotaPermissionContext*
1416ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1417 return new ChromeQuotaPermissionContext();
1418}
1419
[email protected]848dd042011-06-04 18:24:031420void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171421 int render_process_id,
1422 int render_view_id,
1423 int cert_error,
1424 const net::SSLInfo& ssl_info,
1425 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021426 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031427 bool overridable,
[email protected]d9be47702012-05-16 03:41:221428 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171429 const base::Callback<void(bool)>& callback,
1430 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021431 if (resource_type != ResourceType::MAIN_FRAME) {
1432 // A sub-resource has a certificate error. The user doesn't really
1433 // have a context for making the right decision, so block the
1434 // request hard, without an info bar to allow showing the insecure
1435 // content.
1436 *cancel_request = true;
1437 return;
1438 }
1439
[email protected]f9034cf2011-07-21 12:43:411440 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131441 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171442 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411443 if (!tab) {
1444 NOTREACHED();
1445 return;
1446 }
1447 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501448 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301449 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011450 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1451 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411452 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171453 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411454 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171455 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411456 return;
1457 }
1458 }
1459
[email protected]1e87df32012-09-12 04:53:191460#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231461 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1462 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1463 if (captive_portal_tab_helper)
1464 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191465#endif
1466
[email protected]f9034cf2011-07-21 12:43:411467 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221468 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1469 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031470}
1471
[email protected]c99c442e2011-08-24 11:37:301472void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451473 int render_process_id,
1474 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401475 const net::HttpNetworkSession* network_session,
1476 net::SSLCertRequestInfo* cert_request_info,
1477 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131478 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451479 render_process_id, render_view_id);
1480 if (!tab) {
1481 NOTREACHED();
1482 return;
1483 }
1484
[email protected]6786bf402011-12-03 15:19:451485 GURL requesting_url("https://" + cert_request_info->host_and_port);
1486 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1487 << cert_request_info->host_and_port;
1488
[email protected]627e0512011-12-21 22:55:301489 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451490 scoped_ptr<Value> filter(
1491 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1492 requesting_url,
1493 requesting_url,
1494 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1495 std::string(), NULL));
1496
1497 if (filter.get()) {
1498 // Try to automatically select a client certificate.
1499 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1500 DictionaryValue* filter_dict =
1501 static_cast<DictionaryValue*>(filter.get());
1502
1503 const std::vector<scoped_refptr<net::X509Certificate> >&
1504 all_client_certs = cert_request_info->client_certs;
1505 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1506 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1507 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401508 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451509 return;
1510 }
1511 }
1512 } else {
1513 NOTREACHED();
1514 }
1515 }
1516
[email protected]11feec322012-09-18 03:58:521517 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1518 if (!ssl_tab_helper) {
1519 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451520 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141521 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401522 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451523 return;
1524 }
[email protected]11feec322012-09-18 03:58:521525 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401526 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451527}
1528
[email protected]3b455502012-12-11 18:22:581529void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451530 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581531 net::CertificateMimeType cert_type,
1532 const void* cert_data,
1533 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451534 int render_process_id,
1535 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581536 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1537 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451538}
1539
[email protected]dc73a7b2012-03-25 15:27:181540content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561541 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181542}
1543
[email protected]941623e2011-06-07 23:06:041544void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1545 const GURL& source_origin,
1546 int callback_context,
1547 int render_process_id,
1548 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111549#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1551 WebContents* contents =
1552 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1553 if (!contents) {
[email protected]941623e2011-06-07 23:06:041554 NOTREACHED();
1555 return;
1556 }
1557
[email protected]d0d9c3ee2012-06-19 03:07:021558 // Skip showing the infobar if the request comes from an extension, and that
1559 // extension has the 'notify' permission. (If the extension does not have the
1560 // permission, the user will still be prompted.)
1561 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131562 ExtensionService* service =
1563 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021564 const Extension* extension = !service ? NULL :
1565 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1566 source_origin));
[email protected]eb4832a2012-12-08 01:57:521567 RenderViewHost* rvh =
1568 RenderViewHost::FromID(render_process_id, render_view_id);
1569 if (IsExtensionWithPermissionOrSuggestInConsole(
1570 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021571 if (rvh)
1572 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1573 return;
1574 }
1575
1576 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371577 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021578 notifications->RequestPermission(source_origin, render_process_id,
1579 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111580#else
1581 NOTIMPLEMENTED();
1582#endif
[email protected]941623e2011-06-07 23:06:041583}
1584
1585WebKit::WebNotificationPresenter::Permission
1586 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021587 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201588 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021589 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111590#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201592 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021593 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1594 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061595 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041596 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041597
1598 // Fall back to the regular notification preferences, which works on an
1599 // origin basis.
1600 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371601 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041602 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111603#else
1604 return WebKit::WebNotificationPresenter::PermissionAllowed;
1605#endif
[email protected]941623e2011-06-07 23:06:041606}
1607
1608void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171609 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041610 int render_process_id,
1611 int render_view_id,
1612 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111613#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041614 RenderViewHost* rvh = RenderViewHost::FromID(
1615 render_process_id, render_view_id);
1616 if (!rvh) {
1617 NOTREACHED();
1618 return;
1619 }
1620
[email protected]9f76c1e2012-03-05 15:15:581621 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301622 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041623 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371624 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041625 service->ShowDesktopNotification(
1626 params, render_process_id, render_view_id,
1627 worker ? DesktopNotificationService::WorkerNotification :
1628 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111629#else
1630 NOTIMPLEMENTED();
1631#endif
[email protected]941623e2011-06-07 23:06:041632}
1633
1634void ChromeContentBrowserClient::CancelDesktopNotification(
1635 int render_process_id,
1636 int render_view_id,
1637 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111638#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041639 RenderViewHost* rvh = RenderViewHost::FromID(
1640 render_process_id, render_view_id);
1641 if (!rvh) {
1642 NOTREACHED();
1643 return;
1644 }
1645
[email protected]9f76c1e2012-03-05 15:15:581646 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301647 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041648 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371649 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041650 service->CancelDesktopNotification(
1651 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111652#else
1653 NOTIMPLEMENTED();
1654#endif
[email protected]941623e2011-06-07 23:06:041655}
1656
[email protected]9f3fba52011-06-08 20:37:191657bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351658 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021659 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191660 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201661 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011662 int render_process_id,
1663 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011665
1666 *no_javascript_access = false;
1667
[email protected]9f3fba52011-06-08 20:37:191668 // If the opener is trying to create a background window but doesn't have
1669 // the appropriate permission, fail the attempt.
1670 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201671 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531672 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1673
[email protected]03b6d552012-03-29 04:03:011674 if (!map->SecurityOriginHasAPIPermission(
1675 source_origin,
1676 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061677 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011678 return false;
1679 }
1680
[email protected]7b54ca02012-03-02 18:06:531681 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1682 // return a recently installed Extension even if this CanCreateWindow call
1683 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011684 // because the permission check above would have caused an early return
1685 // already. We must use the full URL to find hosted apps, though, and not
1686 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531687 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351688 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291689 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011690 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191691 }
1692 return true;
1693}
1694
1695std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201696 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1698 // Check if it's an extension-created worker, in which case we want to use
1699 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201700 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191701 const Extension* extension =
1702 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1703 return extension ? extension->name() : std::string();
1704}
1705
[email protected]99907362012-01-11 05:41:401706void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1707 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171708}
1709
[email protected]c52b2892012-03-07 11:01:021710content::SpeechRecognitionManagerDelegate*
1711 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321712#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021713 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321714#else
1715 return NULL;
1716#endif
[email protected]66cfec62012-02-24 17:57:511717}
1718
[email protected]ae6e9912011-07-27 01:18:281719net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1720 return g_browser_process->net_log();
1721}
1722
[email protected]32538d92011-08-25 00:09:231723AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1724 return new ChromeAccessTokenStore();
1725}
1726
[email protected]dbae6b02011-06-29 23:51:411727bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011728 return true;
[email protected]dbae6b02011-06-29 23:51:411729}
1730
[email protected]64d69de42012-02-06 00:19:541731void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321732 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061733 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581734 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061735 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061736
[email protected]f3986f82012-01-03 20:00:061737 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541738 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061739 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541740 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061741 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541742 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061743 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541744 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061745 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541746 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061747 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541748 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031749 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1750 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061751
[email protected]64d69de42012-02-06 00:19:541752 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401753 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541754 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401755 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541756 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401757 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541758 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401759 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061760
[email protected]ddf72142012-05-22 04:52:401761 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061762
[email protected]64d69de42012-02-06 00:19:541763 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401764 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541765 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061766 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541767 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061768 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1769 const DictionaryValue* inspector_settings =
1770 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1771 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181772 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1773 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061774 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181775 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541776 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181777 std::make_pair(iter.key(), value));
1778 }
[email protected]f3986f82012-01-03 20:00:061779 }
1780 }
[email protected]64d69de42012-02-06 00:19:541781 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061782
[email protected]ddf72142012-05-22 04:52:401783 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541784 web_prefs->javascript_enabled = false;
1785 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1786 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401787 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541788 web_prefs->plugins_enabled = false;
1789 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1790 web_prefs->java_enabled = false;
1791 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401792 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061793
[email protected]64d69de42012-02-06 00:19:541794 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1795 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061796
[email protected]64d69de42012-02-06 00:19:541797 web_prefs->memory_info_enabled =
1798 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1799 web_prefs->allow_displaying_insecure_content =
1800 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1801 web_prefs->allow_running_insecure_content =
1802 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321803#if defined(OS_ANDROID)
1804 web_prefs->font_scale_factor =
1805 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1806 web_prefs->force_enable_zoom =
1807 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451808#if defined(GOOGLE_TV)
1809 web_prefs->user_gesture_required_for_media_playback = false;
1810#endif
[email protected]d3b935f2012-10-19 23:14:321811#endif
[email protected]9d06d88d2012-02-23 22:37:081812 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061813
[email protected]64d69de42012-02-06 00:19:541814 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151815 UserStyleSheetWatcher* user_style_sheet_watcher =
1816 UserStyleSheetWatcherFactory::GetForProfile(profile);
1817 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541818 web_prefs->user_style_sheet_enabled = true;
1819 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151820 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541821 } else {
1822 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061823 }
1824
[email protected]b7e44ff2012-02-16 03:37:341825 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101826#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031827 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101828 // Mac so it uses NSSpellChecker in the background.
1829 false;
1830#else
[email protected]61806872012-12-12 04:15:361831 true;
[email protected]37b928e2012-05-30 09:01:101832#endif
[email protected]b7e44ff2012-02-16 03:37:341833 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521834 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571835
[email protected]64d69de42012-02-06 00:19:541836 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061837 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541838 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061839 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541840 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061841 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1842
1843 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541844 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061845 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541846 web_prefs->default_encoding);
1847 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401848 prefs->ClearPref(prefs::kDefaultCharset);
1849 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061850 }
[email protected]64d69de42012-02-06 00:19:541851 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061852
[email protected]88ecf66d2012-12-11 22:53:471853 if (content::IsForceCompositingModeEnabled())
1854 web_prefs->force_compositing_mode = true;
1855
[email protected]299d7f12012-05-23 05:31:151856 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231857 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131858 ExtensionService* service =
1859 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061860 if (service) {
[email protected]1bc28312012-11-08 08:31:531861 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1862 const Extension* extension = service->extensions()->GetByID(url.host());
1863 // Ensure that we are only granting extension preferences to URLs with
1864 // the correct scheme. Without this check, chrome-guest:// schemes used by
1865 // webview tags as well as hosts that happen to match the id of an
1866 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421867 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531868 extension_webkit_preferences::SetPreferences(
1869 extension, view_type, web_prefs);
1870 }
[email protected]f3986f82012-01-03 20:00:061871 }
1872
[email protected]cb2edf22013-04-01 20:25:231873 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541874 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231875 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061876 // Disable all kinds of acceleration for background pages.
1877 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541878 web_prefs->force_compositing_mode = false;
1879 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061880 }
[email protected]2e21fe292012-03-02 22:52:321881
1882#if defined(FILE_MANAGER_EXTENSION)
1883 // Override the default of suppressing HW compositing for WebUI pages for the
1884 // file manager, which is implemented using WebUI but wants HW acceleration
1885 // for video decode & render.
1886 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1887 web_prefs->accelerated_compositing_enabled = true;
1888 web_prefs->accelerated_2d_canvas_enabled = true;
1889 }
1890#endif
[email protected]181a95ee2011-07-12 19:26:361891}
1892
1893void ChromeContentBrowserClient::UpdateInspectorSetting(
1894 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061895 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581896 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061897 DictionaryPrefUpdate update(
1898 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1899 prefs::kWebKitInspectorSettings);
1900 DictionaryValue* inspector_settings = update.Get();
1901 inspector_settings->SetWithoutPathExpansion(key,
1902 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361903}
1904
1905void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061906 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581907 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061908 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1909 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361910}
1911
[email protected]b8148ac2011-07-13 22:03:251912void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1913 BrowserURLHandler* handler) {
1914 // Add the default URL handlers.
1915 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1916 BrowserURLHandler::null_handler());
1917 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1918 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1919
[email protected]b3adbd02011-11-30 22:23:271920 // about: handler. Must come before chrome: handler, since it will
1921 // rewrite about: urls to chrome: URLs and then expect chrome: to
1922 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251923 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1924 BrowserURLHandler::null_handler());
1925 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241926 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251927}
1928
1929void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371930 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581931 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471932 BrowsingDataRemover* remover =
1933 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551934 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1935 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251936 // BrowsingDataRemover takes care of deleting itself when done.
1937}
1938
1939void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371940 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581941 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471942 BrowsingDataRemover* remover =
1943 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231944 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551945 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251946 // BrowsingDataRemover takes care of deleting itself when done.
1947}
1948
[email protected]650b2d52013-02-10 03:41:451949base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321950 return download_util::GetDefaultDownloadDirectory();
1951}
1952
[email protected]c9b6eb62011-10-18 20:49:391953std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1954 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1955}
1956
[email protected]b7631cc2012-09-15 05:08:381957void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1958 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541959#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381960 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1961 scoped_ptr<ppapi::host::HostFactory>(
1962 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541963#endif
[email protected]b7631cc2012-09-15 05:08:381964}
1965
[email protected]0c7193742012-11-07 19:05:031966content::BrowserPpapiHost*
1967 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1968 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:131969 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:031970 while (!iter.Done()) {
1971 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1972 if (host->process() &&
1973 host->process()->GetData().id == plugin_process_id) {
1974 // Found the plugin.
1975 return host->browser_ppapi_host();
1976 }
1977 ++iter;
1978 }
1979 return NULL;
1980}
1981
[email protected]7b38b192013-03-23 18:39:311982bool ChromeContentBrowserClient::SupportsBrowserPlugin(
1983 content::BrowserContext* browser_context, const GURL& site_url) {
1984 if (CommandLine::ForCurrentProcess()->HasSwitch(
1985 switches::kEnableBrowserPluginForAllViewTypes))
1986 return true;
1987
1988 Profile* profile = Profile::FromBrowserContext(browser_context);
1989 ExtensionService* service =
1990 extensions::ExtensionSystem::Get(profile)->extension_service();
1991 if (!service)
1992 return false;
1993
1994 const Extension* extension = service->extensions()->
1995 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
1996 if (!extension)
1997 return false;
1998
1999 return extension->HasAPIPermission(APIPermission::kWebView);
2000}
2001
[email protected]38cd8f7f2012-06-15 22:06:072002bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582003 content::BrowserContext* browser_context,
2004 const GURL& url,
2005 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292006 if (!url.is_valid())
2007 return false;
2008
2009 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422010 if (url.SchemeIs(extensions::kExtensionScheme) &&
2011 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:292012 return true;
[email protected]885c0e92012-11-13 20:27:422013 }
[email protected]a658d452012-03-02 12:45:292014
[email protected]9a5940d2012-04-27 19:16:232015 Profile* profile = Profile::FromBrowserContext(browser_context);
2016 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192017 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132018 extensions::ExtensionSystem::Get(profile)->extension_service();
2019 if (extension_service) {
2020 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232021 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2022 }
2023
[email protected]f237c0f2012-03-10 07:49:102024 // Need to check this now and not on construction because otherwise it won't
2025 // work with browser_tests.
2026 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2027 std::string allowed_list =
2028 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232029 if (allowed_list == "*") {
2030 // The wildcard allows socket API only for packaged and platform apps.
2031 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402032 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2033 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232034 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392035 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102036 while (t.GetNext()) {
2037 if (t.token() == host)
2038 return true;
2039 }
2040 }
2041
[email protected]a658d452012-03-02 12:45:292042 if (!extension)
2043 return false;
2044
[email protected]157cc902012-11-02 06:31:582045 extensions::SocketPermission::CheckParam extension_params(
2046 params.type, params.host, params.port);
2047 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2048 &extension_params))
[email protected]a658d452012-03-02 12:45:292049 return true;
2050
2051 return false;
[email protected]e461da2f2012-02-16 19:06:402052}
2053
[email protected]650b2d52013-02-10 03:41:452054base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2055 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142056 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2057 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2058}
2059
[email protected]a28e3302013-02-03 03:50:432060ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2061 WebContents* web_contents) {
2062 return new ChromeSelectFilePolicy(web_contents);
2063}
2064
[email protected]e60c0232011-11-11 19:56:352065#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182066void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2067 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382068 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082069 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392070#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452071 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392072 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2073 DCHECK(!data_path.empty());
2074
2075 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452076 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392077 base::PlatformFile f =
2078 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2079 DCHECK(f != base::kInvalidPlatformFileValue);
2080 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2081 FileDescriptor(f, true)));
2082
[email protected]650b2d52013-02-10 03:41:452083 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392084 data_path.AppendASCII("chrome_100_percent.pak");
2085 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2086 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372087 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392088 FileDescriptor(f, true)));
2089
2090 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452091 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392092 GetLocaleFilePath(locale, false);
2093 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2094 DCHECK(f != base::kInvalidPlatformFileValue);
2095 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2096 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382097
[email protected]650b2d52013-02-10 03:41:452098 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372099 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2100 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2101 DCHECK(f != base::kInvalidPlatformFileValue);
2102 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2103 FileDescriptor(f, true)));
2104
[email protected]40da3e0c2012-10-24 22:03:382105#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432106 if (IsCrashReporterEnabled()) {
2107 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2108 if (f == base::kInvalidPlatformFileValue) {
2109 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2110 "be disabled for this process.";
2111 } else {
2112 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2113 FileDescriptor(f, true)));
2114 }
[email protected]40da3e0c2012-10-24 22:03:382115 }
2116#endif // defined(USE_LINUX_BREAKPAD)
2117
2118#else
2119 int crash_signal_fd = GetCrashSignalFD(command_line);
2120 if (crash_signal_fd >= 0) {
2121 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2122 FileDescriptor(crash_signal_fd,
2123 false)));
2124 }
[email protected]29699c22012-10-03 23:57:392125#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302126}
[email protected]e60c0232011-11-11 19:56:352127#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302128
[email protected]4a65826d2011-08-25 16:04:012129#if defined(OS_WIN)
2130const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2131 return chrome::kBrowserResourcesDll;
2132}
[email protected]34f48682013-03-20 00:30:182133
2134void ChromeContentBrowserClient::PreSpawnRenderer(
2135 sandbox::TargetPolicy* policy,
2136 bool* success) {
2137 // This code is duplicated in nacl_exe_win_64.cc.
2138 // Allow the server side of a pipe restricted to the "chrome.nacl."
2139 // namespace so that it cannot impersonate other system or other chrome
2140 // service pipes.
2141 sandbox::ResultCode result = policy->AddRule(
2142 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2143 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2144 L"\\\\.\\pipe\\chrome.nacl.*");
2145 if (result != sandbox::SBOX_ALL_OK) {
2146 *success = false;
2147 return;
2148 }
2149
2150 // Renderers need to send named pipe handles and shared memory
2151 // segment handles to NaCl loader processes.
2152 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2153 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2154 L"File");
2155 if (result != sandbox::SBOX_ALL_OK) {
2156 *success = false;
2157 return;
2158 }
2159}
[email protected]4a65826d2011-08-25 16:04:012160#endif
2161
[email protected]37a72af2011-06-13 05:42:012162#if defined(USE_NSS)
2163crypto::CryptoModuleBlockingPasswordDelegate*
2164 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2165 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292166 return chrome::NewCryptoModuleBlockingDialogDelegate(
2167 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012168}
2169#endif
2170
[email protected]e9a32a52012-06-14 23:32:432171void ChromeContentBrowserClient::SetApplicationLocale(
2172 const std::string& locale) {
2173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2174
2175 // This object is guaranteed to outlive all threads so we don't have to
2176 // worry about the lack of refcounting and can just post as Unretained.
2177 //
2178 // The common case is that this function is called early in Chrome startup
2179 // before any threads are created (it will also be called later if the user
2180 // changes the pref). In this case, there will be no threads created and
2181 // posting will fail. When there are no threads, we can just set the string
2182 // without worrying about threadsafety.
2183 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2184 base::Bind(
2185 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2186 base::Unretained(this), locale)))
2187 io_thread_application_locale_ = locale;
2188}
2189
2190void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2191 const std::string& locale) {
2192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2193 io_thread_application_locale_ = locale;
2194}
2195
[email protected]d977f9c2011-03-14 16:10:262196} // namespace chrome