blob: a1bc1a4ba52e4312c1a41dc8716d70988cf448a2 [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]9ec0f452012-05-31 15:58:5382#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3083#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0184#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1485#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1386#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3087#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2988#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0489#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3890#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4491#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5892#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3493#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1294#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3895#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0996#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4497#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4398#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3099#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38100#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31101#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03102#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59103#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36104#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30105#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33106#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05107#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33108#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19109#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10110#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43111#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18112#include "content/public/common/content_descriptors.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]eec0b33c2011-12-05 22:09:45326 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);
349 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) {
430 CHECK(chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
431 << "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));
600 if (extension && extension->is_storage_isolated()) {
601 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.
714 if (chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
715 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]7c60f5042013-02-14 03:39:32758 if (chrome::search::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
835 InstantService* instant_service =
836 InstantServiceFactory::GetForProfile(profile);
837 if (instant_service &&
838 instant_service->IsInstantProcess(process_host->GetID()))
[email protected]7c60f5042013-02-14 03:39:32839 return chrome::search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]c5dec6292013-01-25 04:54:52840
[email protected]970c63e2013-03-07 00:25:30841 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
842 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
843 return SigninManager::IsWebBasedSigninFlowURL(site_url);
844
[email protected]06bdd2b2012-11-30 18:47:13845 ExtensionService* service =
846 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46847 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31848
[email protected]ffa97602011-11-17 17:55:52849 // Don't allow the Task Manager to share a process with anything else.
850 // Otherwise it can affect the renderers it is observing.
851 // Note: we could create another RenderProcessHostPrivilege bucket for
852 // this to allow multiple chrome://tasks instances to share, but that's
853 // a very unlikely case without serious consequences.
854 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
855 return false;
856
[email protected]8d3132f62011-10-12 07:13:42857 // These may be NULL during tests. In that case, just assume any site can
858 // share any host.
[email protected]6f371442011-11-09 06:45:46859 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31860 return true;
861
[email protected]eec0b33c2011-12-05 22:09:45862 // Otherwise, just make sure the process privilege matches the privilege
863 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57864 RenderProcessHostPrivilege privilege_required =
865 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45866 return GetProcessPrivilege(process_host, process_map, service) ==
867 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31868}
869
[email protected]76411f412012-02-22 18:56:06870// This function is trying to limit the amount of processes used by extensions
871// with background pages. It uses a globally set percentage of processes to
872// run such extensions and if the limit is exceeded, it returns true, to
873// indicate to the content module to group extensions together.
874bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
875 content::BrowserContext* browser_context, const GURL& url) {
876 // It has to be a valid URL for us to check for an extension.
877 if (!url.is_valid())
878 return false;
879
880 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19881 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13882 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06883 if (!service)
884 return false;
885
886 // We have to have a valid extension with background page to proceed.
887 const Extension* extension =
888 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
889 if (!extension)
890 return false;
[email protected]9367eabc2013-03-01 01:29:29891 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06892 return false;
893
894 std::set<int> process_ids;
895 size_t max_process_count =
896 content::RenderProcessHost::GetMaxRendererProcessCount();
897
898 // Go through all profiles to ensure we have total count of extension
899 // processes containing background pages, otherwise one profile can
900 // starve the other.
901 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
902 GetLoadedProfiles();
903 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03904 ExtensionProcessManager* epm =
905 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32906 for (ExtensionProcessManager::const_iterator iter =
907 epm->background_hosts().begin();
908 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13909 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32910 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06911 }
912 }
913
914 if (process_ids.size() >
915 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
916 return true;
917 }
918
919 return false;
920}
921
[email protected]6f371442011-11-09 06:45:46922void ChromeContentBrowserClient::SiteInstanceGotProcess(
923 SiteInstance* site_instance) {
924 CHECK(site_instance->HasProcess());
925
926 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02927 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52928 if (!profile)
929 return;
930
931 // Remember the ID of the Instant process to signal the renderer process
932 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]7c60f5042013-02-14 03:39:32933 if (chrome::search::ShouldAssignURLToInstantRenderer(
934 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52935 InstantService* instant_service =
936 InstantServiceFactory::GetForProfile(profile);
937 if (instant_service)
938 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
939 }
940
[email protected]970c63e2013-03-07 00:25:30941 // We only expect there to be one signin process as we use process-per-site
942 // for signin URLs. The signin process will be cleared from SigninManager
943 // when the renderer is destroyed.
944 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
945 SigninManager* signin_manager =
946 SigninManagerFactory::GetForProfile(profile);
947 if (signin_manager)
948 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
949 }
950
[email protected]06bdd2b2012-11-30 18:47:13951 ExtensionService* service =
952 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46953 if (!service)
954 return;
955
956 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44957 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59958 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46959 if (!extension)
960 return;
961
[email protected]6bc04fd82011-12-04 02:29:35962 service->process_map()->Insert(extension->id(),
963 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33964 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46965 BrowserThread::PostTask(
966 BrowserThread::IO, FROM_HERE,
967 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59968 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46969 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35970 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33971 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46972}
973
974void ChromeContentBrowserClient::SiteInstanceDeleting(
975 SiteInstance* site_instance) {
976 if (!site_instance->HasProcess())
977 return;
978
979 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02980 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13981 ExtensionService* service =
982 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46983 if (!service)
984 return;
985
986 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44987 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59988 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46989 if (!extension)
990 return;
991
[email protected]6bc04fd82011-12-04 02:29:35992 service->process_map()->Remove(extension->id(),
993 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33994 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46995 BrowserThread::PostTask(
996 BrowserThread::IO, FROM_HERE,
997 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59998 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46999 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351000 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331001 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461002}
1003
[email protected]f05763972012-06-06 18:17:261004bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141005 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081006 const GURL& current_url,
1007 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261008 if (current_url.is_empty()) {
1009 // Always choose a new process when navigating to extension URLs. The
1010 // process grouping logic will combine all of a given extension's pages
1011 // into the same process.
[email protected]885c0e92012-11-13 20:27:421012 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261013 return true;
[email protected]e3daf3c2011-10-05 21:17:081014
[email protected]f05763972012-06-06 18:17:261015 return false;
1016 }
1017
1018 // Also, we must switch if one is an extension and the other is not the exact
1019 // same extension.
[email protected]885c0e92012-11-13 20:27:421020 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1021 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261022 if (current_url.GetOrigin() != new_url.GetOrigin())
1023 return true;
1024 }
1025
[email protected]e9841fbd2013-02-22 23:12:141026 // The checks below only matter if we can retrieve which extensions are
1027 // installed.
1028 Profile* profile =
1029 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1030 ExtensionService* service =
1031 extensions::ExtensionSystem::Get(profile)->extension_service();
1032 if (!service)
1033 return false;
1034
1035 // We must swap if the URL is for an extension and we are not using an
1036 // extension process.
1037 const Extension* new_extension =
1038 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1039 // Ignore all hosted apps except the Chrome Web Store, since they do not
1040 // require their own BrowsingInstance (e.g., postMessage is ok).
1041 if (new_extension &&
1042 new_extension->is_hosted_app() &&
1043 new_extension->id() != extension_misc::kWebStoreAppId)
1044 new_extension = NULL;
1045 if (new_extension &&
1046 site_instance->HasProcess() &&
1047 !service->process_map()->Contains(new_extension->id(),
1048 site_instance->GetProcess()->GetID()))
1049 return true;
1050
[email protected]f05763972012-06-06 18:17:261051 return false;
[email protected]e3daf3c2011-10-05 21:17:081052}
1053
[email protected]395045c2012-05-22 15:04:381054bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1055 content::ResourceContext* resource_context, const GURL& current_url,
1056 const GURL& new_url) {
1057 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1058 return extensions::CrossesExtensionProcessBoundary(
1059 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171060 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381061}
1062
[email protected]763ec4ca2011-04-29 15:48:121063std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1064 const std::string& alias_name) {
1065 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1066}
1067
[email protected]b80f68432011-05-02 17:22:301068void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1069 CommandLine* command_line, int child_process_id) {
1070#if defined(USE_LINUX_BREAKPAD)
1071 if (IsCrashReporterEnabled()) {
1072 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1073 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1074 }
1075#elif defined(OS_MACOSX)
1076 if (IsCrashReporterEnabled()) {
1077 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1078 child_process_logging::GetClientId());
1079 }
1080#endif // OS_MACOSX
1081
[email protected]f1933792011-06-14 00:49:341082 if (logging::DialogsAreSuppressed())
1083 command_line->AppendSwitch(switches::kNoErrorDialogs);
1084
[email protected]b80f68432011-05-02 17:22:301085 std::string process_type =
1086 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171087 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321088
1089 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1090 command_line->AppendSwitch(switches::kChromeFrame);
1091
[email protected]718eab62011-10-05 21:16:521092 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451093 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301094 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1095 if (!user_data_dir.empty())
1096 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1097#if defined(OS_CHROMEOS)
1098 const std::string& login_profile =
1099 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1100 if (!login_profile.empty())
1101 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1102#endif
1103
[email protected]f3b1a082011-11-18 00:34:301104 content::RenderProcessHost* process =
1105 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371106 if (process) {
1107 Profile* profile = Profile::FromBrowserContext(
1108 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131109 ExtensionService* extension_service =
1110 extensions::ExtensionSystem::Get(profile)->extension_service();
1111 if (extension_service) {
1112 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001113 if (process_map && process_map->Contains(process->GetID()))
1114 command_line->AppendSwitch(switches::kExtensionProcess);
1115 }
[email protected]b80f68432011-05-02 17:22:301116
[email protected]a8d851f82011-12-21 00:32:371117 PrefService* prefs = profile->GetPrefs();
1118 // Currently this pref is only registered if applied via a policy.
1119 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1120 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1121 // Turn this policy into a command line switch.
1122 command_line->AppendSwitch(switches::kDisable3DAPIs);
1123 }
[email protected]718eab62011-10-05 21:16:521124
[email protected]a8d851f82011-12-21 00:32:371125 // Disable client-side phishing detection in the renderer if it is
1126 // disabled in the Profile preferences or the browser process.
1127 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1128 !g_browser_process->safe_browsing_detection_service()) {
1129 command_line->AppendSwitch(
1130 switches::kDisableClientSidePhishingDetection);
1131 }
[email protected]0045b0f42012-07-26 11:52:081132
1133 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211134 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521135
1136 InstantService* instant_service =
1137 InstantServiceFactory::GetForProfile(profile);
1138 if (instant_service &&
1139 instant_service->IsInstantProcess(process->GetID()))
1140 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301141
1142 SigninManager* signin_manager =
1143 SigninManagerFactory::GetForProfile(profile);
1144 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1145 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]47c7ec82012-01-18 03:29:211146 }
[email protected]4287a3d2011-06-13 23:56:511147
[email protected]87552982012-11-02 17:21:401148 if (content::IsThreadedCompositingEnabled())
1149 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1150
[email protected]47c7ec82012-01-18 03:29:211151 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511152 static const char* const kSwitchNames[] = {
1153 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481154 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511155 switches::kAllowScriptingGallery,
1156 switches::kAppsCheckoutURL,
1157 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311158 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511159 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501160 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531161 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111162 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511163 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211164 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511165 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561166 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511167 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511168 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511169 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451170 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481171 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051172 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511173 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291174 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511175 switches::kMemoryProfiling,
1176 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371177 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581178 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371179 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511180 switches::kPpapiFlashArgs,
1181 switches::kPpapiFlashInProcess,
1182 switches::kPpapiFlashPath,
1183 switches::kPpapiFlashVersion,
1184 switches::kProfilingAtStart,
1185 switches::kProfilingFile,
1186 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371187 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511188 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291189 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381190 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511191 };
1192
1193 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1194 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171195 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381196 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351197 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381198 switches::kEnableExperimentalExtensionApis,
1199 switches::kWhitelistedExtensionID,
1200 };
1201
1202 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1203 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511204 } else if (process_type == switches::kPluginProcess) {
1205 static const char* const kSwitchNames[] = {
1206 #if defined(OS_CHROMEOS)
1207 switches::kLoginProfile,
1208 #endif
1209 switches::kMemoryProfiling,
1210 switches::kSilentDumpOnDCHECK,
1211 switches::kUserDataDir,
1212 };
1213
1214 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1215 arraysize(kSwitchNames));
1216 } else if (process_type == switches::kZygoteProcess) {
1217 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511218 switches::kUserDataDir, // Make logs go to the right file.
1219 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501220 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511221 switches::kPpapiFlashInProcess,
1222 switches::kPpapiFlashPath,
1223 switches::kPpapiFlashVersion,
1224 };
1225
1226 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1227 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111228 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001229 base::FilePath user_data_dir =
1230 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1231 if (!user_data_dir.empty())
1232 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111233 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1234 // because GPU is expected to be unreliable.
1235 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1236 !command_line->HasSwitch(switches::kDisableBreakpad))
1237 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301238 }
[email protected]6f08af82011-09-15 01:19:031239
1240 // The command line switch kEnableBenchmarking needs to be specified along
1241 // with the kEnableStatsTable switch to ensure that the stats table global
1242 // is initialized correctly.
1243 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1244 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301245}
1246
1247std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431248 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1249 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301250 return g_browser_process->GetApplicationLocale();
1251}
1252
[email protected]597a867b2011-11-18 18:31:201253std::string ChromeContentBrowserClient::GetAcceptLangs(
1254 content::BrowserContext* context) {
1255 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371256 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081257}
1258
[email protected]9ec0f452012-05-31 15:58:531259gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221260 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531261 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081262}
1263
[email protected]a2176792011-05-08 19:30:491264bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091265 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191266 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201267 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201269 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051270 return io_data->GetCookieSettings()->
1271 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491272}
1273
[email protected]ed24fad2011-05-10 22:44:011274bool ChromeContentBrowserClient::AllowGetCookie(
1275 const GURL& url,
1276 const GURL& first_party,
1277 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201278 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011279 int render_process_id,
1280 int render_view_id) {
1281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201282 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051283 bool allow = io_data->GetCookieSettings()->
1284 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011285
[email protected]8093a542011-05-13 07:29:321286 BrowserThread::PostTask(
1287 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031288 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431289 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011290 return allow;
1291}
1292
1293bool ChromeContentBrowserClient::AllowSetCookie(
1294 const GURL& url,
1295 const GURL& first_party,
1296 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201297 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011298 int render_process_id,
1299 int render_view_id,
1300 net::CookieOptions* options) {
1301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201302 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051303 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1304 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1305
[email protected]8093a542011-05-13 07:29:321306 BrowserThread::PostTask(
1307 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031308 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431309 render_view_id, url, first_party, cookie_line, *options,
1310 !allow));
[email protected]ed24fad2011-05-10 22:44:011311 return allow;
1312}
1313
[email protected]d5a19162011-06-30 18:51:541314bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201315 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201317 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431318 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1319 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261320
[email protected]bf510ed2012-06-05 08:31:431321 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1322 // Could we even support per-origin settings?
1323 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541324}
1325
[email protected]5c5a88e2011-11-12 00:45:351326bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351327 const GURL& url,
1328 const string16& name,
1329 const string16& display_name,
1330 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201331 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481332 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201334 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351335 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1336 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1337
[email protected]62151052012-02-01 18:40:481338 // Record access to database for potential display in UI.
1339 std::vector<std::pair<int, int> >::const_iterator i;
1340 for (i = render_views.begin(); i != render_views.end(); ++i) {
1341 BrowserThread::PostTask(
1342 BrowserThread::UI, FROM_HERE,
1343 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1344 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351345 }
1346
1347 return allow;
1348}
1349
1350bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351351 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201352 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481353 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201355 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351356 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1357 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1358
[email protected]62151052012-02-01 18:40:481359 // Record access to file system for potential display in UI.
1360 std::vector<std::pair<int, int> >::const_iterator i;
1361 for (i = render_views.begin(); i != render_views.end(); ++i) {
1362 BrowserThread::PostTask(
1363 BrowserThread::UI, FROM_HERE,
1364 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1365 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351366 }
1367
1368 return allow;
1369}
1370
[email protected]7c5ff9a2012-03-02 07:42:491371bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1372 const GURL& url,
1373 const string16& name,
1374 content::ResourceContext* context,
1375 const std::vector<std::pair<int, int> >& render_views) {
1376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1377 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1378 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1379 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1380
1381 // Record access to IndexedDB for potential display in UI.
1382 std::vector<std::pair<int, int> >::const_iterator i;
1383 for (i = render_views.begin(); i != render_views.end(); ++i) {
1384 BrowserThread::PostTask(
1385 BrowserThread::UI, FROM_HERE,
1386 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1387 i->first, i->second, url, name, !allow));
1388 }
1389
1390 return allow;
1391}
1392
[email protected]6133f922011-07-01 21:34:341393net::URLRequestContext*
1394ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201395 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421397 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201398 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341399 return io_data->extensions_request_context();
1400 }
1401
1402 return NULL;
1403}
1404
[email protected]317f96c92011-05-31 06:53:411405QuotaPermissionContext*
1406ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1407 return new ChromeQuotaPermissionContext();
1408}
1409
[email protected]848dd042011-06-04 18:24:031410void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171411 int render_process_id,
1412 int render_view_id,
1413 int cert_error,
1414 const net::SSLInfo& ssl_info,
1415 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021416 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031417 bool overridable,
[email protected]d9be47702012-05-16 03:41:221418 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171419 const base::Callback<void(bool)>& callback,
1420 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021421 if (resource_type != ResourceType::MAIN_FRAME) {
1422 // A sub-resource has a certificate error. The user doesn't really
1423 // have a context for making the right decision, so block the
1424 // request hard, without an info bar to allow showing the insecure
1425 // content.
1426 *cancel_request = true;
1427 return;
1428 }
1429
[email protected]f9034cf2011-07-21 12:43:411430 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131431 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171432 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411433 if (!tab) {
1434 NOTREACHED();
1435 return;
1436 }
1437 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501438 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301439 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011440 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1441 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411442 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171443 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411444 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171445 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411446 return;
1447 }
1448 }
1449
[email protected]1e87df32012-09-12 04:53:191450#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231451 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1452 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1453 if (captive_portal_tab_helper)
1454 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191455#endif
1456
[email protected]f9034cf2011-07-21 12:43:411457 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221458 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1459 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031460}
1461
[email protected]c99c442e2011-08-24 11:37:301462void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451463 int render_process_id,
1464 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401465 const net::HttpNetworkSession* network_session,
1466 net::SSLCertRequestInfo* cert_request_info,
1467 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131468 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451469 render_process_id, render_view_id);
1470 if (!tab) {
1471 NOTREACHED();
1472 return;
1473 }
1474
[email protected]6786bf402011-12-03 15:19:451475 GURL requesting_url("https://" + cert_request_info->host_and_port);
1476 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1477 << cert_request_info->host_and_port;
1478
[email protected]627e0512011-12-21 22:55:301479 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451480 scoped_ptr<Value> filter(
1481 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1482 requesting_url,
1483 requesting_url,
1484 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1485 std::string(), NULL));
1486
1487 if (filter.get()) {
1488 // Try to automatically select a client certificate.
1489 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1490 DictionaryValue* filter_dict =
1491 static_cast<DictionaryValue*>(filter.get());
1492
1493 const std::vector<scoped_refptr<net::X509Certificate> >&
1494 all_client_certs = cert_request_info->client_certs;
1495 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1496 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1497 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401498 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451499 return;
1500 }
1501 }
1502 } else {
1503 NOTREACHED();
1504 }
1505 }
1506
[email protected]11feec322012-09-18 03:58:521507 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1508 if (!ssl_tab_helper) {
1509 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451510 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141511 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401512 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451513 return;
1514 }
[email protected]11feec322012-09-18 03:58:521515 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401516 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451517}
1518
[email protected]3b455502012-12-11 18:22:581519void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451520 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581521 net::CertificateMimeType cert_type,
1522 const void* cert_data,
1523 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451524 int render_process_id,
1525 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581526 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1527 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451528}
1529
[email protected]dc73a7b2012-03-25 15:27:181530content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561531 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181532}
1533
[email protected]941623e2011-06-07 23:06:041534void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1535 const GURL& source_origin,
1536 int callback_context,
1537 int render_process_id,
1538 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111539#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1541 WebContents* contents =
1542 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1543 if (!contents) {
[email protected]941623e2011-06-07 23:06:041544 NOTREACHED();
1545 return;
1546 }
1547
[email protected]d0d9c3ee2012-06-19 03:07:021548 // Skip showing the infobar if the request comes from an extension, and that
1549 // extension has the 'notify' permission. (If the extension does not have the
1550 // permission, the user will still be prompted.)
1551 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131552 ExtensionService* service =
1553 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021554 const Extension* extension = !service ? NULL :
1555 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1556 source_origin));
[email protected]eb4832a2012-12-08 01:57:521557 RenderViewHost* rvh =
1558 RenderViewHost::FromID(render_process_id, render_view_id);
1559 if (IsExtensionWithPermissionOrSuggestInConsole(
1560 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021561 if (rvh)
1562 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1563 return;
1564 }
1565
1566 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371567 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021568 notifications->RequestPermission(source_origin, render_process_id,
1569 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111570#else
1571 NOTIMPLEMENTED();
1572#endif
[email protected]941623e2011-06-07 23:06:041573}
1574
1575WebKit::WebNotificationPresenter::Permission
1576 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021577 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201578 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021579 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111580#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201582 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021583 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1584 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061585 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041586 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041587
1588 // Fall back to the regular notification preferences, which works on an
1589 // origin basis.
1590 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371591 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041592 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111593#else
1594 return WebKit::WebNotificationPresenter::PermissionAllowed;
1595#endif
[email protected]941623e2011-06-07 23:06:041596}
1597
1598void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171599 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041600 int render_process_id,
1601 int render_view_id,
1602 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111603#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041604 RenderViewHost* rvh = RenderViewHost::FromID(
1605 render_process_id, render_view_id);
1606 if (!rvh) {
1607 NOTREACHED();
1608 return;
1609 }
1610
[email protected]9f76c1e2012-03-05 15:15:581611 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301612 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041613 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371614 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041615 service->ShowDesktopNotification(
1616 params, render_process_id, render_view_id,
1617 worker ? DesktopNotificationService::WorkerNotification :
1618 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111619#else
1620 NOTIMPLEMENTED();
1621#endif
[email protected]941623e2011-06-07 23:06:041622}
1623
1624void ChromeContentBrowserClient::CancelDesktopNotification(
1625 int render_process_id,
1626 int render_view_id,
1627 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111628#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041629 RenderViewHost* rvh = RenderViewHost::FromID(
1630 render_process_id, render_view_id);
1631 if (!rvh) {
1632 NOTREACHED();
1633 return;
1634 }
1635
[email protected]9f76c1e2012-03-05 15:15:581636 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301637 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041638 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371639 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041640 service->CancelDesktopNotification(
1641 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111642#else
1643 NOTIMPLEMENTED();
1644#endif
[email protected]941623e2011-06-07 23:06:041645}
1646
[email protected]9f3fba52011-06-08 20:37:191647bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351648 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021649 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191650 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201651 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011652 int render_process_id,
1653 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011655
1656 *no_javascript_access = false;
1657
[email protected]9f3fba52011-06-08 20:37:191658 // If the opener is trying to create a background window but doesn't have
1659 // the appropriate permission, fail the attempt.
1660 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201661 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531662 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1663
[email protected]03b6d552012-03-29 04:03:011664 if (!map->SecurityOriginHasAPIPermission(
1665 source_origin,
1666 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061667 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011668 return false;
1669 }
1670
[email protected]7b54ca02012-03-02 18:06:531671 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1672 // return a recently installed Extension even if this CanCreateWindow call
1673 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011674 // because the permission check above would have caused an early return
1675 // already. We must use the full URL to find hosted apps, though, and not
1676 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531677 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351678 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291679 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011680 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191681 }
1682 return true;
1683}
1684
1685std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201686 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1688 // Check if it's an extension-created worker, in which case we want to use
1689 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201690 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191691 const Extension* extension =
1692 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1693 return extension ? extension->name() : std::string();
1694}
1695
[email protected]99907362012-01-11 05:41:401696void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1697 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171698}
1699
[email protected]c52b2892012-03-07 11:01:021700content::SpeechRecognitionManagerDelegate*
1701 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321702#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021703 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321704#else
1705 return NULL;
1706#endif
[email protected]66cfec62012-02-24 17:57:511707}
1708
[email protected]ae6e9912011-07-27 01:18:281709net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1710 return g_browser_process->net_log();
1711}
1712
[email protected]32538d92011-08-25 00:09:231713AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1714 return new ChromeAccessTokenStore();
1715}
1716
[email protected]dbae6b02011-06-29 23:51:411717bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011718 return true;
[email protected]dbae6b02011-06-29 23:51:411719}
1720
[email protected]64d69de42012-02-06 00:19:541721void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321722 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061723 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581724 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061725 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061726
[email protected]f3986f82012-01-03 20:00:061727 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541728 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061729 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541730 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061731 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541732 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061733 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541734 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061735 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541736 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061737 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541738 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031739 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1740 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061741
[email protected]64d69de42012-02-06 00:19:541742 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401743 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541744 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401745 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541746 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401747 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541748 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401749 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061750
[email protected]ddf72142012-05-22 04:52:401751 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061752
[email protected]64d69de42012-02-06 00:19:541753 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401754 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541755 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061756 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541757 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061758 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1759 const DictionaryValue* inspector_settings =
1760 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1761 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181762 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1763 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061764 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181765 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541766 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181767 std::make_pair(iter.key(), value));
1768 }
[email protected]f3986f82012-01-03 20:00:061769 }
1770 }
[email protected]64d69de42012-02-06 00:19:541771 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061772
[email protected]ddf72142012-05-22 04:52:401773 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541774 web_prefs->javascript_enabled = false;
1775 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1776 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401777 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541778 web_prefs->plugins_enabled = false;
1779 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1780 web_prefs->java_enabled = false;
1781 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401782 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061783
[email protected]64d69de42012-02-06 00:19:541784 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1785 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061786
[email protected]64d69de42012-02-06 00:19:541787 web_prefs->memory_info_enabled =
1788 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1789 web_prefs->allow_displaying_insecure_content =
1790 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1791 web_prefs->allow_running_insecure_content =
1792 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321793#if defined(OS_ANDROID)
1794 web_prefs->font_scale_factor =
1795 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1796 web_prefs->force_enable_zoom =
1797 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451798#if defined(GOOGLE_TV)
1799 web_prefs->user_gesture_required_for_media_playback = false;
1800#endif
[email protected]d3b935f2012-10-19 23:14:321801#endif
[email protected]9d06d88d2012-02-23 22:37:081802 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061803
[email protected]64d69de42012-02-06 00:19:541804 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151805 UserStyleSheetWatcher* user_style_sheet_watcher =
1806 UserStyleSheetWatcherFactory::GetForProfile(profile);
1807 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541808 web_prefs->user_style_sheet_enabled = true;
1809 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151810 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541811 } else {
1812 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061813 }
1814
[email protected]b7e44ff2012-02-16 03:37:341815 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101816#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031817 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101818 // Mac so it uses NSSpellChecker in the background.
1819 false;
1820#else
[email protected]61806872012-12-12 04:15:361821 true;
[email protected]37b928e2012-05-30 09:01:101822#endif
[email protected]b7e44ff2012-02-16 03:37:341823 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521824 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571825
[email protected]64d69de42012-02-06 00:19:541826 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061827 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541828 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061829 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541830 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061831 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1832
1833 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541834 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061835 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541836 web_prefs->default_encoding);
1837 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401838 prefs->ClearPref(prefs::kDefaultCharset);
1839 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061840 }
[email protected]64d69de42012-02-06 00:19:541841 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061842
[email protected]88ecf66d2012-12-11 22:53:471843 if (content::IsForceCompositingModeEnabled())
1844 web_prefs->force_compositing_mode = true;
1845
[email protected]299d7f12012-05-23 05:31:151846 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1847 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131848 ExtensionService* service =
1849 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061850 if (service) {
[email protected]1bc28312012-11-08 08:31:531851 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1852 const Extension* extension = service->extensions()->GetByID(url.host());
1853 // Ensure that we are only granting extension preferences to URLs with
1854 // the correct scheme. Without this check, chrome-guest:// schemes used by
1855 // webview tags as well as hosts that happen to match the id of an
1856 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421857 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531858 extension_webkit_preferences::SetPreferences(
1859 extension, view_type, web_prefs);
1860 }
[email protected]f3986f82012-01-03 20:00:061861 }
1862
[email protected]299d7f12012-05-23 05:31:151863 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541864 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151865 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061866 // Disable all kinds of acceleration for background pages.
1867 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541868 web_prefs->force_compositing_mode = false;
1869 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061870 }
[email protected]2e21fe292012-03-02 22:52:321871
1872#if defined(FILE_MANAGER_EXTENSION)
1873 // Override the default of suppressing HW compositing for WebUI pages for the
1874 // file manager, which is implemented using WebUI but wants HW acceleration
1875 // for video decode & render.
1876 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1877 web_prefs->accelerated_compositing_enabled = true;
1878 web_prefs->accelerated_2d_canvas_enabled = true;
1879 }
1880#endif
[email protected]181a95ee2011-07-12 19:26:361881}
1882
1883void ChromeContentBrowserClient::UpdateInspectorSetting(
1884 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061885 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581886 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061887 DictionaryPrefUpdate update(
1888 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1889 prefs::kWebKitInspectorSettings);
1890 DictionaryValue* inspector_settings = update.Get();
1891 inspector_settings->SetWithoutPathExpansion(key,
1892 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361893}
1894
1895void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061896 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581897 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061898 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1899 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361900}
1901
[email protected]b8148ac2011-07-13 22:03:251902void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1903 BrowserURLHandler* handler) {
1904 // Add the default URL handlers.
1905 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1906 BrowserURLHandler::null_handler());
1907 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1908 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1909
[email protected]b3adbd02011-11-30 22:23:271910 // about: handler. Must come before chrome: handler, since it will
1911 // rewrite about: urls to chrome: URLs and then expect chrome: to
1912 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251913 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1914 BrowserURLHandler::null_handler());
1915 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241916 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251917}
1918
1919void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371920 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581921 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471922 BrowsingDataRemover* remover =
1923 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551924 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1925 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251926 // BrowsingDataRemover takes care of deleting itself when done.
1927}
1928
1929void ChromeContentBrowserClient::ClearCookies(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]dceaa912011-09-06 17:17:231934 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551935 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251936 // BrowsingDataRemover takes care of deleting itself when done.
1937}
1938
[email protected]650b2d52013-02-10 03:41:451939base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321940 return download_util::GetDefaultDownloadDirectory();
1941}
1942
[email protected]c9b6eb62011-10-18 20:49:391943std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1944 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1945}
1946
[email protected]b7631cc2012-09-15 05:08:381947void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1948 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541949#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381950 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1951 scoped_ptr<ppapi::host::HostFactory>(
1952 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541953#endif
[email protected]b7631cc2012-09-15 05:08:381954}
1955
[email protected]0c7193742012-11-07 19:05:031956content::BrowserPpapiHost*
1957 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1958 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:131959 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:031960 while (!iter.Done()) {
1961 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1962 if (host->process() &&
1963 host->process()->GetData().id == plugin_process_id) {
1964 // Found the plugin.
1965 return host->browser_ppapi_host();
1966 }
1967 ++iter;
1968 }
1969 return NULL;
1970}
1971
[email protected]38cd8f7f2012-06-15 22:06:071972bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581973 content::BrowserContext* browser_context,
1974 const GURL& url,
1975 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291976 if (!url.is_valid())
1977 return false;
1978
1979 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421980 if (url.SchemeIs(extensions::kExtensionScheme) &&
1981 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291982 return true;
[email protected]885c0e92012-11-13 20:27:421983 }
[email protected]a658d452012-03-02 12:45:291984
[email protected]9a5940d2012-04-27 19:16:231985 Profile* profile = Profile::FromBrowserContext(browser_context);
1986 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191987 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131988 extensions::ExtensionSystem::Get(profile)->extension_service();
1989 if (extension_service) {
1990 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231991 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1992 }
1993
[email protected]f237c0f2012-03-10 07:49:101994 // Need to check this now and not on construction because otherwise it won't
1995 // work with browser_tests.
1996 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1997 std::string allowed_list =
1998 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231999 if (allowed_list == "*") {
2000 // The wildcard allows socket API only for packaged and platform apps.
2001 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402002 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2003 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232004 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392005 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102006 while (t.GetNext()) {
2007 if (t.token() == host)
2008 return true;
2009 }
2010 }
2011
[email protected]a658d452012-03-02 12:45:292012 if (!extension)
2013 return false;
2014
[email protected]157cc902012-11-02 06:31:582015 extensions::SocketPermission::CheckParam extension_params(
2016 params.type, params.host, params.port);
2017 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2018 &extension_params))
[email protected]a658d452012-03-02 12:45:292019 return true;
2020
2021 return false;
[email protected]e461da2f2012-02-16 19:06:402022}
2023
[email protected]650b2d52013-02-10 03:41:452024base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2025 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142026 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2027 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2028}
2029
[email protected]a28e3302013-02-03 03:50:432030ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2031 WebContents* web_contents) {
2032 return new ChromeSelectFilePolicy(web_contents);
2033}
2034
[email protected]e60c0232011-11-11 19:56:352035#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182036void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2037 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382038 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082039 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392040#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452041 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392042 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2043 DCHECK(!data_path.empty());
2044
2045 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452046 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392047 base::PlatformFile f =
2048 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2049 DCHECK(f != base::kInvalidPlatformFileValue);
2050 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2051 FileDescriptor(f, true)));
2052
[email protected]650b2d52013-02-10 03:41:452053 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392054 data_path.AppendASCII("chrome_100_percent.pak");
2055 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2056 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372057 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392058 FileDescriptor(f, true)));
2059
2060 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452061 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392062 GetLocaleFilePath(locale, false);
2063 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2064 DCHECK(f != base::kInvalidPlatformFileValue);
2065 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2066 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382067
[email protected]650b2d52013-02-10 03:41:452068 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372069 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2070 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2071 DCHECK(f != base::kInvalidPlatformFileValue);
2072 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2073 FileDescriptor(f, true)));
2074
[email protected]40da3e0c2012-10-24 22:03:382075#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432076 if (IsCrashReporterEnabled()) {
2077 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2078 if (f == base::kInvalidPlatformFileValue) {
2079 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2080 "be disabled for this process.";
2081 } else {
2082 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2083 FileDescriptor(f, true)));
2084 }
[email protected]40da3e0c2012-10-24 22:03:382085 }
2086#endif // defined(USE_LINUX_BREAKPAD)
2087
2088#else
2089 int crash_signal_fd = GetCrashSignalFD(command_line);
2090 if (crash_signal_fd >= 0) {
2091 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2092 FileDescriptor(crash_signal_fd,
2093 false)));
2094 }
[email protected]29699c22012-10-03 23:57:392095#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302096}
[email protected]e60c0232011-11-11 19:56:352097#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302098
[email protected]4a65826d2011-08-25 16:04:012099#if defined(OS_WIN)
2100const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2101 return chrome::kBrowserResourcesDll;
2102}
[email protected]34f48682013-03-20 00:30:182103
2104void ChromeContentBrowserClient::PreSpawnRenderer(
2105 sandbox::TargetPolicy* policy,
2106 bool* success) {
2107 // This code is duplicated in nacl_exe_win_64.cc.
2108 // Allow the server side of a pipe restricted to the "chrome.nacl."
2109 // namespace so that it cannot impersonate other system or other chrome
2110 // service pipes.
2111 sandbox::ResultCode result = policy->AddRule(
2112 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2113 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2114 L"\\\\.\\pipe\\chrome.nacl.*");
2115 if (result != sandbox::SBOX_ALL_OK) {
2116 *success = false;
2117 return;
2118 }
2119
2120 // Renderers need to send named pipe handles and shared memory
2121 // segment handles to NaCl loader processes.
2122 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2123 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2124 L"File");
2125 if (result != sandbox::SBOX_ALL_OK) {
2126 *success = false;
2127 return;
2128 }
2129}
[email protected]4a65826d2011-08-25 16:04:012130#endif
2131
[email protected]37a72af2011-06-13 05:42:012132#if defined(USE_NSS)
2133crypto::CryptoModuleBlockingPasswordDelegate*
2134 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2135 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292136 return chrome::NewCryptoModuleBlockingDialogDelegate(
2137 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012138}
2139#endif
2140
[email protected]e9a32a52012-06-14 23:32:432141void ChromeContentBrowserClient::SetApplicationLocale(
2142 const std::string& locale) {
2143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2144
2145 // This object is guaranteed to outlive all threads so we don't have to
2146 // worry about the lack of refcounting and can just post as Unretained.
2147 //
2148 // The common case is that this function is called early in Chrome startup
2149 // before any threads are created (it will also be called later if the user
2150 // changes the pref). In this case, there will be no threads created and
2151 // posting will fail. When there are no threads, we can just set the string
2152 // without worrying about threadsafety.
2153 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2154 base::Bind(
2155 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2156 base::Unretained(this), locale)))
2157 io_thread_application_locale_ = locale;
2158}
2159
2160void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2161 const std::string& locale) {
2162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2163 io_thread_application_locale_ = locale;
2164}
2165
[email protected]d977f9c2011-03-14 16:10:262166} // namespace chrome