blob: 0ab32b79fa36fd93006761acd826a5ca9fe829cd [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]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]f4ebe772013-02-02 00:21:3916#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0617#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3018#include "chrome/app/breakpad_mac.h"
[email protected]056efdc2013-04-06 00:14:5319#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2520#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3021#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4722#include "chrome/browser/browsing_data/browsing_data_helper.h"
23#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4125#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4126#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5627#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0528#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4529#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3230#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0831#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3232#include "chrome/browser/download/download_util.h"
[email protected]24665682013-02-25 20:59:3833#include "chrome/browser/extensions/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1634#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0635#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0436#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3337#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2638#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0839#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2540#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0641#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5242#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2343#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1244#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5645#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0446#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0347#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2848#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0449#include "chrome/browser/notifications/desktop_notification_service.h"
50#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4251#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5652#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0653#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4154#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5055#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0756#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/printing/printing_message_filter.h"
59#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3260#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0661#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3863#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4364#include "chrome/browser/search/instant_service.h"
65#include "chrome/browser/search/instant_service_factory.h"
66#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0268#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3369#include "chrome/browser/speech/tts_message_filter.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]1352ca92013-04-30 02:30:2782#include "chrome/browser/validation_message_message_filter.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]561e33d52013-04-03 06:58:4392#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]157cc902012-11-02 06:31:5893#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3494#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1295#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3896#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0997#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4498#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4399#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30100#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38101#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31102#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03103#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59104#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36105#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30106#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33107#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05108#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33109#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19110#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10111#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43112#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18113#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23114#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42115#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39116#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23117#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53118#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58119#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34120#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06121#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57122#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38123#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39124#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08125#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36126#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04127#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26128
[email protected]b48c9182011-10-26 18:03:30129#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38130#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18131#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38132#elif defined(OS_MACOSX)
133#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56134#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30135#elif defined(OS_CHROMEOS)
136#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49137#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]931d1042013-04-05 17:50:44138#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26139#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30140#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09141#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38142#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09143#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39144#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30145#elif defined(OS_POSIX)
146#include "chrome/browser/chrome_browser_main_posix.h"
147#endif
148
[email protected]6653c192012-04-10 22:52:44149#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30150#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12151#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43152#endif
[email protected]b80f68432011-05-02 17:22:30153
[email protected]1e87df32012-09-12 04:53:19154#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
155#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
156#endif
157
[email protected]16dc42452013-04-09 04:37:19158#if defined(ENABLE_MESSAGE_CENTER)
159#include "ui/message_center/message_center_util.h"
160#endif
161
[email protected]29699c22012-10-03 23:57:39162#if defined(OS_ANDROID)
163#include "ui/base/ui_base_paths.h"
164#endif
165
[email protected]37a72af2011-06-13 05:42:01166#if defined(USE_NSS)
167#include "chrome/browser/ui/crypto_module_password_dialog.h"
168#endif
169
[email protected]d5bcd06f2013-04-21 08:07:24170#if !defined(OS_CHROMEOS)
171#include "chrome/browser/signin/signin_manager.h"
172#include "chrome/browser/signin/signin_manager_factory.h"
173#endif
174
[email protected]02250952013-04-24 23:52:53175#if !defined(OS_ANDROID)
176#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
177#endif
178
[email protected]c7abd422012-09-25 00:20:08179using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47180using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03181using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39182using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31183using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59184using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08185using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00186using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11187using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33188using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13189using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06190using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34191using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40192using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39193
[email protected]c5dbef02011-05-13 05:06:09194namespace {
195
[email protected]eabbfb12013-04-05 23:28:35196// Cached version of the locale so we can return the locale on the I/O
197// thread.
198base::LazyInstance<std::string> g_io_thread_application_locale;
199
[email protected]e461da2f2012-02-16 19:06:40200const char* kPredefinedAllowedSocketOrigins[] = {
201 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18202 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45203 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
204 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
205 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
206 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35207 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54208 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
209 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
210 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
211 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
212 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
213 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38214 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58215 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
216 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40217};
218
[email protected]f8f93eb2012-09-25 03:06:24219// Returns a copy of the given url with its host set to given host and path set
220// to given path. Other parts of the url will be the same.
221GURL ReplaceURLHostAndPath(const GURL& url,
222 const std::string& host,
223 const std::string& path) {
224 url_canon::Replacements<char> replacements;
225 replacements.SetHost(host.c_str(),
226 url_parse::Component(0, host.length()));
227 replacements.SetPath(path.c_str(),
228 url_parse::Component(0, path.length()));
229 return url.ReplaceComponents(replacements);
230}
231
232// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
233GURL AddUberHost(const GURL& url) {
234 const std::string uber_host = chrome::kChromeUIUberHost;
235 const std::string new_path = url.host() + url.path();
236
237 return ReplaceURLHostAndPath(url, uber_host, new_path);
238}
239
[email protected]045bf7c2012-09-28 20:27:36240// If url->host() is "chrome" and url->path() has characters other than the
241// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
242// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24243bool RemoveUberHost(GURL* url) {
244 if (url->host() != chrome::kChromeUIUberHost)
245 return false;
246
[email protected]045bf7c2012-09-28 20:27:36247 if (url->path().empty() || url->path() == "/")
248 return false;
249
[email protected]f8f93eb2012-09-25 03:06:24250 const std::string old_path = url->path();
251
252 const std::string::size_type separator = old_path.find('/', 1);
253 std::string new_host;
254 std::string new_path;
255 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36256 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24257 } else {
258 new_host = old_path.substr(1, separator - 1);
259 new_path = old_path.substr(separator);
260 }
261
262 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
263
264 return true;
265}
266
[email protected]b8148ac2011-07-13 22:03:25267// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42268bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24269 // Do not handle special URLs such as "about:foo"
270 if (!url->host().empty()) {
271 const GURL chrome_url = AddUberHost(*url);
272
273 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
274 // be called.
275 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
276 browser_context, chrome_url))
277 return true;
278 }
279
[email protected]863f70a2012-01-27 02:05:50280 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
281 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25282 return false;
283
[email protected]fe69558d2012-03-12 11:34:49284#if defined(OS_CHROMEOS)
285 // Special case : in ChromeOS in Guest mode bookmarks and history are
286 // disabled for security reasons. New tab page explains the reasons, so
287 // we redirect user to new tab page.
288 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
289 if (url->SchemeIs(chrome::kChromeUIScheme) &&
290 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
291 url->DomainIs(chrome::kChromeUIHistoryHost))) {
292 // Rewrite with new tab URL
293 *url = GURL(chrome::kChromeUINewTabURL);
294 }
295 }
296#endif
297
[email protected]b8148ac2011-07-13 22:03:25298 // Special case the new tab page. In older versions of Chrome, the new tab
299 // page was hosted at chrome-internal:<blah>. This might be in people's saved
300 // sessions or bookmarks, so we say any URL with that scheme triggers the new
301 // tab page.
302 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
303 // Rewrite it with the proper new tab URL.
304 *url = GURL(chrome::kChromeUINewTabURL);
305 }
306
307 return true;
308}
309
[email protected]f8f93eb2012-09-25 03:06:24310// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
311// "chrome://foo/".
312bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
313 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
314 return false;
315
316 return RemoveUberHost(url);
317}
318
[email protected]8d3132f62011-10-12 07:13:42319// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
320// below. Extension, and isolated apps require different privileges to be
321// granted to their RenderProcessHosts. This classification allows us to make
322// sure URLs are served by hosts with the right set of privileges.
323enum RenderProcessHostPrivilege {
324 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45325 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42326 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45327 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42328};
329
330RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
331 const GURL& url,
332 ExtensionService* service) {
333 // Default to a normal renderer cause it is lower privileged. This should only
334 // occur if the URL on a site instance is either malformed, or uninitialized.
335 // If it is malformed, then there is no need for better privileges anyways.
336 // If it is uninitialized, but eventually settles on being an a scheme other
337 // than normal webrenderer, the navigation logic will correct us out of band
338 // anyways.
339 if (!url.is_valid())
340 return PRIV_NORMAL;
341
[email protected]885c0e92012-11-13 20:27:42342 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44343 const Extension* extension =
344 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43345 if (extension &&
346 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42347 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45348 if (extension && extension->is_hosted_app())
349 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42350
351 return PRIV_EXTENSION;
352 }
353
354 return PRIV_NORMAL;
355}
356
357RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30358 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46359 extensions::ProcessMap* process_map,
360 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46361 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30362 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46363 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21364 return PRIV_NORMAL;
365
[email protected]6f371442011-11-09 06:45:46366 for (std::set<std::string>::iterator iter = extension_ids.begin();
367 iter != extension_ids.end(); ++iter) {
368 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43369 if (extension &&
370 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42371 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45372 if (extension && extension->is_hosted_app())
373 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42374 }
375
[email protected]676f6ab2011-10-19 20:23:21376 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42377}
378
[email protected]6786bf402011-12-03 15:19:45379bool CertMatchesFilter(const net::X509Certificate& cert,
380 const base::DictionaryValue& filter) {
381 // TODO(markusheintz): This is the minimal required filter implementation.
382 // Implement a better matcher.
383
384 // An empty filter matches any client certificate since no requirements are
385 // specified at all.
386 if (filter.empty())
387 return true;
388
389 std::string common_name;
390 if (filter.GetString("ISSUER.CN", &common_name) &&
391 (cert.issuer().common_name == common_name)) {
392 return true;
393 }
394 return false;
395}
396
[email protected]f3986f82012-01-03 20:00:06397// Fills |map| with the per-script font prefs under path |map_name|.
398void FillFontFamilyMap(const PrefService* prefs,
399 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53400 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06401 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
402 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
403 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
404 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23405 if (!font_family.empty())
406 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06407 }
408}
409
[email protected]a1733df2012-06-22 11:24:18410#if defined(OS_POSIX) && !defined(OS_MACOSX)
411int GetCrashSignalFD(const CommandLine& command_line) {
412 if (command_line.HasSwitch(switches::kExtensionProcess)) {
413 ExtensionCrashHandlerHostLinux* crash_handler =
414 ExtensionCrashHandlerHostLinux::GetInstance();
415 return crash_handler->GetDeathSignalSocket();
416 }
417
418 std::string process_type =
419 command_line.GetSwitchValueASCII(switches::kProcessType);
420
421 if (process_type == switches::kRendererProcess)
422 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
423
424 if (process_type == switches::kPluginProcess)
425 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
426
427 if (process_type == switches::kPpapiPluginProcess)
428 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
429
430 if (process_type == switches::kGpuProcess)
431 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
432
433 return -1;
434}
435#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
436
[email protected]d5bcd06f2013-04-21 08:07:24437#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30438GURL GetEffectiveURLForSignin(const GURL& url) {
439 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
440
441 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03442 // Copy the path because the argument to SetPathStr must outlive
443 // the Replacements object.
444 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30445 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03446 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30447 effective_url = effective_url.ReplaceComponents(replacements);
448 return effective_url;
449}
[email protected]d5bcd06f2013-04-21 08:07:24450#endif
[email protected]970c63e2013-03-07 00:25:30451
[email protected]eabbfb12013-04-05 23:28:35452void SetApplicationLocaleOnIOThread(const std::string& locale) {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
454 g_io_thread_application_locale.Get() = locale;
455}
456
[email protected]9dbfff12011-07-01 19:37:07457} // namespace
[email protected]c5dbef02011-05-13 05:06:09458
[email protected]d977f9c2011-03-14 16:10:26459namespace chrome {
460
[email protected]e461da2f2012-02-16 19:06:40461ChromeContentBrowserClient::ChromeContentBrowserClient() {
462 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
463 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40464}
465
466ChromeContentBrowserClient::~ChromeContentBrowserClient() {
467}
468
[email protected]bca18382012-06-25 19:15:23469// static
[email protected]c753f142013-02-10 13:14:04470void ChromeContentBrowserClient::RegisterUserPrefs(
471 PrefRegistrySyncable* registry) {
472 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
473 false,
474 PrefRegistrySyncable::UNSYNCABLE_PREF);
475 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
476 true,
477 PrefRegistrySyncable::UNSYNCABLE_PREF);
478 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
479 false,
480 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23481}
482
[email protected]eabbfb12013-04-05 23:28:35483// static
484void ChromeContentBrowserClient::SetApplicationLocale(
485 const std::string& locale) {
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
487
488 // This object is guaranteed to outlive all threads so we don't have to
489 // worry about the lack of refcounting and can just post as Unretained.
490 //
491 // The common case is that this function is called early in Chrome startup
492 // before any threads are created (it will also be called later if the user
493 // changes the pref). In this case, there will be no threads created and
494 // posting will fail. When there are no threads, we can just set the string
495 // without worrying about threadsafety.
496 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
497 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
498 g_io_thread_application_locale.Get() = locale;
499 }
500}
501
[email protected]50462bf02011-11-21 19:13:31502content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
503 const content::MainFunctionParams& parameters) {
504 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30505 // Construct the Main browser parts based on the OS type.
506#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31507 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04508#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31509 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30510#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22511 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26512#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31513 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14514#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09515 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30516#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31517 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04518#else
[email protected]b48c9182011-10-26 18:03:30519 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31520 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30521#endif
522
[email protected]c7480942011-11-08 19:18:27523 // Construct additional browser parts. Stages are called in the order in
524 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22525#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41526 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04527#endif
[email protected]c7480942011-11-08 19:18:27528
529#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41530 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27531#endif
532
[email protected]dc04be7c2012-03-15 23:57:49533#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41534 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49535#endif
536
[email protected]e050ef142012-03-21 01:04:24537#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41538 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24539#endif
540
[email protected]95132f52013-04-12 02:19:04541 chrome::AddMetricsExtraParts(main_parts);
542
[email protected]50462bf02011-11-21 19:13:31543 return main_parts;
[email protected]f967b722011-09-07 00:58:04544}
545
[email protected]e94bbcb2012-09-07 05:33:57546std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19547 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57548 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53549 std::string partition_id;
550
551 // The partition ID for webview guest processes is the string value of its
552 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
553 if (site.SchemeIs(chrome::kGuestScheme))
554 partition_id = site.spec();
555
[email protected]056efdc2013-04-06 00:14:53556 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53557 return partition_id;
558}
559
560bool ChromeContentBrowserClient::IsValidStoragePartitionId(
561 content::BrowserContext* browser_context,
562 const std::string& partition_id) {
563 // The default ID is empty and is always valid.
564 if (partition_id.empty())
565 return true;
566
567 return GURL(partition_id).is_valid();
568}
569
570void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
571 content::BrowserContext* browser_context,
572 const GURL& site,
[email protected]14acc642012-11-17 12:20:10573 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53574 std::string* partition_domain,
575 std::string* partition_name,
576 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10577 // Default to the browser-wide storage partition and override based on |site|
578 // below.
579 partition_domain->clear();
580 partition_name->clear();
581 *in_memory = false;
582
[email protected]1bc28312012-11-08 08:31:53583 // For the webview tag, we create special guest processes, which host the
584 // tag content separately from the main application that embeds the tag.
585 // A webview tag can specify both the partition name and whether the storage
586 // for that partition should be persisted. Each tag gets a SiteInstance with
587 // a specially formatted URL, based on the application it is hosted by and
588 // the partition requested by it. The format for that URL is:
589 // chrome-guest://partition_domain/persist?partition_name
590 if (site.SchemeIs(chrome::kGuestScheme)) {
591 // Since guest URLs are only used for packaged apps, there must be an app
592 // id in the URL.
593 CHECK(site.has_host());
594 *partition_domain = site.host();
595 // Since persistence is optional, the path must either be empty or the
596 // literal string.
597 *in_memory = (site.path() != "/persist");
598 // The partition name is user supplied value, which we have encoded when the
599 // URL was created, so it needs to be decoded.
600 *partition_name = net::UnescapeURLComponent(site.query(),
601 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10602 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
603 // If |can_be_default| is false, the caller is stating that the |site|
604 // should be parsed as if it had isolated storage. In particular it is
605 // important to NOT check ExtensionService for the is_storage_isolated()
606 // attribute because this code path is run during Extension uninstall
607 // to do cleanup after the Extension has already been unloaded from the
608 // ExtensionService.
609 bool is_isolated = !can_be_default;
610 if (can_be_default) {
611 const Extension* extension = NULL;
612 Profile* profile = Profile::FromBrowserContext(browser_context);
613 ExtensionService* extension_service =
614 extensions::ExtensionSystem::Get(profile)->extension_service();
615 if (extension_service) {
616 extension = extension_service->extensions()->
617 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43618 if (extension &&
619 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10620 is_isolated = true;
621 }
622 }
623 }
[email protected]1bc28312012-11-08 08:31:53624
[email protected]14acc642012-11-17 12:20:10625 if (is_isolated) {
626 CHECK(site.has_host());
627 // For extensions with isolated storage, the the host of the |site| is
628 // the |partition_domain|. The |in_memory| and |partition_name| are only
629 // used in guest schemes so they are cleared here.
630 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53631 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10632 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53633 }
[email protected]d1198fd2012-08-13 22:50:19634 }
635
[email protected]14acc642012-11-17 12:20:10636 // Assert that if |can_be_default| is false, the code above must have found a
637 // non-default partition. If this fails, the caller has a serious logic
638 // error about which StoragePartition they expect to be in and it is not
639 // safe to continue.
640 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44641}
642
[email protected]38b098f2012-03-14 21:11:57643content::WebContentsViewDelegate*
644 ChromeContentBrowserClient::GetWebContentsViewDelegate(
645 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27646 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32647}
648
[email protected]24665682013-02-25 20:59:38649// Check if the extension activity log is enabled for the profile.
650static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
651 extensions::ActivityLog* activity_log =
652 extensions::ActivityLog::GetInstance(profile);
653 return activity_log->IsLogEnabled();
654}
655
[email protected]44703cc72013-01-24 04:56:06656void ChromeContentBrowserClient::GuestWebContentsCreated(
657 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
658 Profile* profile = Profile::FromBrowserContext(
659 embedder_web_contents->GetBrowserContext());
660 ExtensionService* service =
661 extensions::ExtensionSystem::Get(profile)->extension_service();
662 if (!service)
663 return;
664 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
665 const Extension* extension = service->extensions()->
666 GetExtensionOrAppByURL(ExtensionURLInfo(url));
667 if (!extension)
668 return;
669 std::vector<ExtensionMsg_Loaded_Params> extensions;
670 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
671 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
672}
673
[email protected]f3b1a082011-11-18 00:34:30674void ChromeContentBrowserClient::RenderProcessHostCreated(
675 content::RenderProcessHost* host) {
676 int id = host->GetID();
677 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41678 net::URLRequestContextGetter* context =
679 profile->GetRequestContextForRenderProcess(id);
680
[email protected]f3b1a082011-11-18 00:34:30681 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41682 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55683#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30684 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55685#endif
[email protected]658677f2012-06-09 06:04:02686#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08687 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03688#endif
[email protected]f3b1a082011-11-18 00:34:30689 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02690 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30691 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56692#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21693 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56694#endif
[email protected]43535512013-02-20 20:41:41695 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
696 id, profile, context));
[email protected]2736c032012-05-11 18:06:07697 host->GetChannel()->AddFilter(
698 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27699 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33700#if !defined(OS_ANDROID)
701 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
702#endif
[email protected]3e69bc82011-05-26 23:22:38703
[email protected]2ccf45c2011-08-19 23:35:50704 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
705 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07706
[email protected]24665682013-02-25 20:59:38707 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
708 IsExtensionActivityLogEnabledForProfile(profile)));
709
[email protected]39a5b532011-10-22 01:47:07710 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56711
712 RendererContentSettingRules rules;
713 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
714 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14715}
716
[email protected]95c95552013-05-03 04:21:22717GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
718 content::BrowserContext* browser_context,
719 const GURL& url,
720 bool is_renderer_initiated,
721 content::SiteInstance* current_instance) {
722 Profile* profile = Profile::FromBrowserContext(browser_context);
723 if (!profile)
724 return url;
725
726 // Only return the privileged instant URL if we are entering from a browser-
727 // initiated navigation or if we are already in the instant process.
728 bool is_instant_process = false;
729 int process_id = current_instance->GetProcess()->GetID();
730 InstantService* instant_service =
731 InstantServiceFactory::GetForProfile(profile);
732 if (instant_service)
733 is_instant_process = instant_service->IsInstantProcess(process_id);
734
735 DCHECK_EQ(is_instant_process,
736 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
737 if (!is_renderer_initiated || is_instant_process) {
738 // If the input |url| should be assigned to the Instant renderer, make its
739 // privileged URL distinct from other URLs on the search provider's domain.
740 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
741 return chrome::GetPrivilegedURLForInstant(url, profile);
742 }
743
744 return url;
745}
746
[email protected]3d7474ff2011-07-27 17:47:37747GURL ChromeContentBrowserClient::GetEffectiveURL(
748 content::BrowserContext* browser_context, const GURL& url) {
749 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52750 if (!profile)
751 return url;
752
[email protected]d5bcd06f2013-04-21 08:07:24753#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30754 // If the input |url| should be assigned to the Signin renderer, make its
755 // effective URL distinct from other URLs on the signin service's domain.
756 // Note that the signin renderer will be allowed to sign the user in to
757 // Chrome.
758 if (SigninManager::IsWebBasedSigninFlowURL(url))
759 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24760#endif
[email protected]970c63e2013-03-07 00:25:30761
[email protected]c5dec6292013-01-25 04:54:52762 // If the input |url| is part of an installed app, the effective URL is an
763 // extension URL with the ID of that extension as the host. This has the
764 // effect of grouping apps together in a common SiteInstance.
765 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13766 extensions::ExtensionSystem::Get(profile)->extension_service();
767 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08768 return url;
769
[email protected]06bdd2b2012-11-30 18:47:13770 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44771 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08772 if (!extension)
773 return url;
774
[email protected]15877ca2011-11-18 22:40:52775 // Bookmark apps do not use the hosted app process model, and should be
776 // treated as normal URLs.
777 if (extension->from_bookmark())
778 return url;
779
[email protected]36fb2c7c2011-04-04 15:49:08780 // If the URL is part of an extension's web extent, convert it to an
781 // extension URL.
782 return extension->GetResourceURL(url.path());
783}
784
[email protected]056ad2a2011-07-12 02:13:55785bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37786 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52787 // Non-extension, non-Instant URLs should generally use
788 // process-per-site-instance. Because we expect to use the effective URL,
789 // URLs for hosted apps (apart from bookmark apps) should have an extension
790 // scheme by now.
791
792 Profile* profile = Profile::FromBrowserContext(browser_context);
793 if (!profile)
794 return false;
795
[email protected]165fe422013-03-27 06:34:03796 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52797 return true;
798
[email protected]d5bcd06f2013-04-21 08:07:24799#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30800 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
801 return true;
[email protected]d5bcd06f2013-04-21 08:07:24802#endif
[email protected]970c63e2013-03-07 00:25:30803
[email protected]885c0e92012-11-13 20:27:42804 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55805 return false;
806
[email protected]c5dec6292013-01-25 04:54:52807 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13808 extensions::ExtensionSystem::Get(profile)->extension_service();
809 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55810 return false;
811
[email protected]06bdd2b2012-11-30 18:47:13812 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44813 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55814 if (!extension)
815 return false;
816
817 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53818 // permission, or that does not allow JavaScript access to the background
819 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55820 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40821 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06822 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29823 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53824 return false;
825 }
826 }
[email protected]056ad2a2011-07-12 02:13:55827
[email protected]7b54ca02012-03-02 18:06:53828 // Hosted apps that have script access to their background page must use
829 // process per site, since all instances can make synchronous calls to the
830 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55831 return true;
832}
833
[email protected]672c8c12013-03-07 12:30:06834// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41835void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
836 std::vector<std::string>* additional_schemes) {
837 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06838}
839
[email protected]6bd30072013-02-08 18:17:11840net::URLRequestContextGetter*
841ChromeContentBrowserClient::CreateRequestContext(
842 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06843 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11844 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06845 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11846}
847
848net::URLRequestContextGetter*
849ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
850 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40851 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11852 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06853 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11854 Profile* profile = Profile::FromBrowserContext(browser_context);
855 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06856 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11857}
858
[email protected]46fb9442011-12-09 17:57:47859bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
860 return ProfileIOData::IsHandledURL(url);
861}
862
[email protected]2a5221b2011-09-27 23:07:31863bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30864 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31865 const GURL& site_url) {
866 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30867 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52868 // This may be NULL during tests. In that case, just assume any site can
869 // share any host.
870 if (!profile)
871 return true;
872
[email protected]d43f99fe2013-04-03 00:20:14873 // Instant URLs should only be in the instant process and instant process
874 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52875 InstantService* instant_service =
876 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14877 if (instant_service) {
878 bool is_instant_process = instant_service->IsInstantProcess(
879 process_host->GetID());
880 bool should_be_in_instant_process =
881 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
882 if (is_instant_process || should_be_in_instant_process)
883 return is_instant_process && should_be_in_instant_process;
884 }
[email protected]c5dec6292013-01-25 04:54:52885
[email protected]d5bcd06f2013-04-21 08:07:24886#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30887 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
888 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
889 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24890#endif
[email protected]970c63e2013-03-07 00:25:30891
[email protected]06bdd2b2012-11-30 18:47:13892 ExtensionService* service =
893 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46894 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31895
[email protected]ffa97602011-11-17 17:55:52896 // Don't allow the Task Manager to share a process with anything else.
897 // Otherwise it can affect the renderers it is observing.
898 // Note: we could create another RenderProcessHostPrivilege bucket for
899 // this to allow multiple chrome://tasks instances to share, but that's
900 // a very unlikely case without serious consequences.
901 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
902 return false;
903
[email protected]8d3132f62011-10-12 07:13:42904 // These may be NULL during tests. In that case, just assume any site can
905 // share any host.
[email protected]6f371442011-11-09 06:45:46906 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31907 return true;
908
[email protected]eec0b33c2011-12-05 22:09:45909 // Otherwise, just make sure the process privilege matches the privilege
910 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57911 RenderProcessHostPrivilege privilege_required =
912 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45913 return GetProcessPrivilege(process_host, process_map, service) ==
914 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31915}
916
[email protected]76411f412012-02-22 18:56:06917// This function is trying to limit the amount of processes used by extensions
918// with background pages. It uses a globally set percentage of processes to
919// run such extensions and if the limit is exceeded, it returns true, to
920// indicate to the content module to group extensions together.
921bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
922 content::BrowserContext* browser_context, const GURL& url) {
923 // It has to be a valid URL for us to check for an extension.
924 if (!url.is_valid())
925 return false;
926
927 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19928 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13929 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06930 if (!service)
931 return false;
932
933 // We have to have a valid extension with background page to proceed.
934 const Extension* extension =
935 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
936 if (!extension)
937 return false;
[email protected]9367eabc2013-03-01 01:29:29938 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06939 return false;
940
941 std::set<int> process_ids;
942 size_t max_process_count =
943 content::RenderProcessHost::GetMaxRendererProcessCount();
944
945 // Go through all profiles to ensure we have total count of extension
946 // processes containing background pages, otherwise one profile can
947 // starve the other.
948 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
949 GetLoadedProfiles();
950 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03951 ExtensionProcessManager* epm =
952 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32953 for (ExtensionProcessManager::const_iterator iter =
954 epm->background_hosts().begin();
955 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13956 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32957 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06958 }
959 }
960
961 if (process_ids.size() >
962 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
963 return true;
964 }
965
966 return false;
967}
968
[email protected]6f371442011-11-09 06:45:46969void ChromeContentBrowserClient::SiteInstanceGotProcess(
970 SiteInstance* site_instance) {
971 CHECK(site_instance->HasProcess());
972
973 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02974 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52975 if (!profile)
976 return;
977
978 // Remember the ID of the Instant process to signal the renderer process
979 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:03980 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:32981 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52982 InstantService* instant_service =
983 InstantServiceFactory::GetForProfile(profile);
984 if (instant_service)
985 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
986 }
987
[email protected]d5bcd06f2013-04-21 08:07:24988#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30989 // We only expect there to be one signin process as we use process-per-site
990 // for signin URLs. The signin process will be cleared from SigninManager
991 // when the renderer is destroyed.
992 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
993 SigninManager* signin_manager =
994 SigninManagerFactory::GetForProfile(profile);
995 if (signin_manager)
996 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
997 }
[email protected]d5bcd06f2013-04-21 08:07:24998#endif
[email protected]970c63e2013-03-07 00:25:30999
[email protected]06bdd2b2012-11-30 18:47:131000 ExtensionService* service =
1001 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461002 if (!service)
1003 return;
1004
1005 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441006 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591007 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461008 if (!extension)
1009 return;
1010
[email protected]6bc04fd82011-12-04 02:29:351011 service->process_map()->Insert(extension->id(),
1012 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331013 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461014 BrowserThread::PostTask(
1015 BrowserThread::IO, FROM_HERE,
1016 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591017 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461018 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351019 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331020 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461021}
1022
1023void ChromeContentBrowserClient::SiteInstanceDeleting(
1024 SiteInstance* site_instance) {
1025 if (!site_instance->HasProcess())
1026 return;
1027
1028 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021029 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131030 ExtensionService* service =
1031 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461032 if (!service)
1033 return;
1034
1035 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441036 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591037 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461038 if (!extension)
1039 return;
1040
[email protected]6bc04fd82011-12-04 02:29:351041 service->process_map()->Remove(extension->id(),
1042 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331043 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461044 BrowserThread::PostTask(
1045 BrowserThread::IO, FROM_HERE,
1046 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591047 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461048 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351049 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331050 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461051}
1052
[email protected]f05763972012-06-06 18:17:261053bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141054 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081055 const GURL& current_url,
1056 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261057 if (current_url.is_empty()) {
1058 // Always choose a new process when navigating to extension URLs. The
1059 // process grouping logic will combine all of a given extension's pages
1060 // into the same process.
[email protected]885c0e92012-11-13 20:27:421061 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261062 return true;
[email protected]e3daf3c2011-10-05 21:17:081063
[email protected]f05763972012-06-06 18:17:261064 return false;
1065 }
1066
1067 // Also, we must switch if one is an extension and the other is not the exact
1068 // same extension.
[email protected]885c0e92012-11-13 20:27:421069 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1070 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261071 if (current_url.GetOrigin() != new_url.GetOrigin())
1072 return true;
1073 }
1074
[email protected]e9841fbd2013-02-22 23:12:141075 // The checks below only matter if we can retrieve which extensions are
1076 // installed.
1077 Profile* profile =
1078 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1079 ExtensionService* service =
1080 extensions::ExtensionSystem::Get(profile)->extension_service();
1081 if (!service)
1082 return false;
1083
1084 // We must swap if the URL is for an extension and we are not using an
1085 // extension process.
1086 const Extension* new_extension =
1087 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1088 // Ignore all hosted apps except the Chrome Web Store, since they do not
1089 // require their own BrowsingInstance (e.g., postMessage is ok).
1090 if (new_extension &&
1091 new_extension->is_hosted_app() &&
1092 new_extension->id() != extension_misc::kWebStoreAppId)
1093 new_extension = NULL;
1094 if (new_extension &&
1095 site_instance->HasProcess() &&
1096 !service->process_map()->Contains(new_extension->id(),
1097 site_instance->GetProcess()->GetID()))
1098 return true;
1099
[email protected]f05763972012-06-06 18:17:261100 return false;
[email protected]e3daf3c2011-10-05 21:17:081101}
1102
[email protected]395045c2012-05-22 15:04:381103bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1104 content::ResourceContext* resource_context, const GURL& current_url,
1105 const GURL& new_url) {
1106 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1107 return extensions::CrossesExtensionProcessBoundary(
1108 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171109 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381110}
1111
[email protected]763ec4ca2011-04-29 15:48:121112std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1113 const std::string& alias_name) {
1114 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1115}
1116
[email protected]b80f68432011-05-02 17:22:301117void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1118 CommandLine* command_line, int child_process_id) {
1119#if defined(USE_LINUX_BREAKPAD)
1120 if (IsCrashReporterEnabled()) {
1121 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1122 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1123 }
1124#elif defined(OS_MACOSX)
1125 if (IsCrashReporterEnabled()) {
1126 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1127 child_process_logging::GetClientId());
1128 }
1129#endif // OS_MACOSX
1130
[email protected]f1933792011-06-14 00:49:341131 if (logging::DialogsAreSuppressed())
1132 command_line->AppendSwitch(switches::kNoErrorDialogs);
1133
[email protected]b80f68432011-05-02 17:22:301134 std::string process_type =
1135 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171136 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321137
1138 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1139 command_line->AppendSwitch(switches::kChromeFrame);
1140
[email protected]718eab62011-10-05 21:16:521141 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451142 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301143 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1144 if (!user_data_dir.empty())
1145 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1146#if defined(OS_CHROMEOS)
1147 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441148 browser_command_line.GetSwitchValueASCII(
1149 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301150 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441151 command_line->AppendSwitchASCII(
1152 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301153#endif
1154
[email protected]f3b1a082011-11-18 00:34:301155 content::RenderProcessHost* process =
1156 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371157 if (process) {
1158 Profile* profile = Profile::FromBrowserContext(
1159 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131160 ExtensionService* extension_service =
1161 extensions::ExtensionSystem::Get(profile)->extension_service();
1162 if (extension_service) {
1163 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001164 if (process_map && process_map->Contains(process->GetID()))
1165 command_line->AppendSwitch(switches::kExtensionProcess);
1166 }
[email protected]b80f68432011-05-02 17:22:301167
[email protected]a8d851f82011-12-21 00:32:371168 PrefService* prefs = profile->GetPrefs();
1169 // Currently this pref is only registered if applied via a policy.
1170 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1171 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1172 // Turn this policy into a command line switch.
1173 command_line->AppendSwitch(switches::kDisable3DAPIs);
1174 }
[email protected]718eab62011-10-05 21:16:521175
[email protected]a8d851f82011-12-21 00:32:371176 // Disable client-side phishing detection in the renderer if it is
1177 // disabled in the Profile preferences or the browser process.
1178 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1179 !g_browser_process->safe_browsing_detection_service()) {
1180 command_line->AppendSwitch(
1181 switches::kDisableClientSidePhishingDetection);
1182 }
[email protected]0045b0f42012-07-26 11:52:081183
1184 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211185 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521186
1187 InstantService* instant_service =
1188 InstantServiceFactory::GetForProfile(profile);
1189 if (instant_service &&
1190 instant_service->IsInstantProcess(process->GetID()))
1191 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301192
[email protected]d5bcd06f2013-04-21 08:07:241193#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301194 SigninManager* signin_manager =
1195 SigninManagerFactory::GetForProfile(profile);
1196 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1197 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241198#endif
[email protected]47c7ec82012-01-18 03:29:211199 }
[email protected]4287a3d2011-06-13 23:56:511200
[email protected]87552982012-11-02 17:21:401201 if (content::IsThreadedCompositingEnabled())
1202 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1203
[email protected]16dc42452013-04-09 04:37:191204#if defined(ENABLE_MESSAGE_CENTER)
1205 if (message_center::IsRichNotificationEnabled())
1206 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
1207#endif
1208
[email protected]47c7ec82012-01-18 03:29:211209 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511210 static const char* const kSwitchNames[] = {
[email protected]e217c5632013-04-12 19:11:481211 autofill::switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511212 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481213 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511214 switches::kAllowScriptingGallery,
1215 switches::kAppsCheckoutURL,
1216 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311217 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511218 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501219 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531220 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111221 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531222 switches::kEnableAdview,
1223 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211224 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511225 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511226 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511227 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511228 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451229 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481230 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051231 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511232 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291233 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511234 switches::kMemoryProfiling,
1235 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371236 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371237 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511238 switches::kPpapiFlashArgs,
1239 switches::kPpapiFlashInProcess,
1240 switches::kPpapiFlashPath,
1241 switches::kPpapiFlashVersion,
1242 switches::kProfilingAtStart,
1243 switches::kProfilingFile,
1244 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371245 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511246 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291247 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381248 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511249 };
1250
1251 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1252 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171253 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381254 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351255 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381256 switches::kEnableExperimentalExtensionApis,
1257 switches::kWhitelistedExtensionID,
1258 };
1259
1260 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1261 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511262 } else if (process_type == switches::kPluginProcess) {
1263 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441264#if defined(OS_CHROMEOS)
1265 chromeos::switches::kLoginProfile,
1266#endif
[email protected]4287a3d2011-06-13 23:56:511267 switches::kMemoryProfiling,
1268 switches::kSilentDumpOnDCHECK,
1269 switches::kUserDataDir,
1270 };
1271
1272 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1273 arraysize(kSwitchNames));
1274 } else if (process_type == switches::kZygoteProcess) {
1275 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511276 switches::kUserDataDir, // Make logs go to the right file.
1277 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501278 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511279 switches::kPpapiFlashInProcess,
1280 switches::kPpapiFlashPath,
1281 switches::kPpapiFlashVersion,
1282 };
1283
1284 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1285 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111286 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001287 base::FilePath user_data_dir =
1288 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1289 if (!user_data_dir.empty())
1290 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111291 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1292 // because GPU is expected to be unreliable.
1293 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1294 !command_line->HasSwitch(switches::kDisableBreakpad))
1295 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301296 }
[email protected]6f08af82011-09-15 01:19:031297
1298 // The command line switch kEnableBenchmarking needs to be specified along
1299 // with the kEnableStatsTable switch to ensure that the stats table global
1300 // is initialized correctly.
1301 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1302 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301303}
1304
1305std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431306 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351307 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301308 return g_browser_process->GetApplicationLocale();
1309}
1310
[email protected]597a867b2011-11-18 18:31:201311std::string ChromeContentBrowserClient::GetAcceptLangs(
1312 content::BrowserContext* context) {
1313 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371314 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081315}
1316
[email protected]9ec0f452012-05-31 15:58:531317gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221318 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531319 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081320}
1321
[email protected]a2176792011-05-08 19:30:491322bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091323 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191324 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201325 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201327 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051328 return io_data->GetCookieSettings()->
1329 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491330}
1331
[email protected]ed24fad2011-05-10 22:44:011332bool ChromeContentBrowserClient::AllowGetCookie(
1333 const GURL& url,
1334 const GURL& first_party,
1335 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201336 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011337 int render_process_id,
1338 int render_view_id) {
1339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201340 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051341 bool allow = io_data->GetCookieSettings()->
1342 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011343
[email protected]8093a542011-05-13 07:29:321344 BrowserThread::PostTask(
1345 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031346 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431347 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011348 return allow;
1349}
1350
1351bool ChromeContentBrowserClient::AllowSetCookie(
1352 const GURL& url,
1353 const GURL& first_party,
1354 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201355 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011356 int render_process_id,
1357 int render_view_id,
1358 net::CookieOptions* options) {
1359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201360 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051361 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1362 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1363
[email protected]8093a542011-05-13 07:29:321364 BrowserThread::PostTask(
1365 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031366 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431367 render_view_id, url, first_party, cookie_line, *options,
1368 !allow));
[email protected]ed24fad2011-05-10 22:44:011369 return allow;
1370}
1371
[email protected]d5a19162011-06-30 18:51:541372bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201373 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201375 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431376 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1377 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261378
[email protected]bf510ed2012-06-05 08:31:431379 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1380 // Could we even support per-origin settings?
1381 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541382}
1383
[email protected]5c5a88e2011-11-12 00:45:351384bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351385 const GURL& url,
1386 const string16& name,
1387 const string16& display_name,
1388 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201389 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481390 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201392 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351393 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1394 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1395
[email protected]62151052012-02-01 18:40:481396 // Record access to database for potential display in UI.
1397 std::vector<std::pair<int, int> >::const_iterator i;
1398 for (i = render_views.begin(); i != render_views.end(); ++i) {
1399 BrowserThread::PostTask(
1400 BrowserThread::UI, FROM_HERE,
1401 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1402 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351403 }
1404
1405 return allow;
1406}
1407
1408bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351409 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201410 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481411 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201413 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351414 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1415 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1416
[email protected]62151052012-02-01 18:40:481417 // Record access to file system for potential display in UI.
1418 std::vector<std::pair<int, int> >::const_iterator i;
1419 for (i = render_views.begin(); i != render_views.end(); ++i) {
1420 BrowserThread::PostTask(
1421 BrowserThread::UI, FROM_HERE,
1422 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1423 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351424 }
1425
1426 return allow;
1427}
1428
[email protected]7c5ff9a2012-03-02 07:42:491429bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1430 const GURL& url,
1431 const string16& name,
1432 content::ResourceContext* context,
1433 const std::vector<std::pair<int, int> >& render_views) {
1434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1435 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1436 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1437 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1438
1439 // Record access to IndexedDB for potential display in UI.
1440 std::vector<std::pair<int, int> >::const_iterator i;
1441 for (i = render_views.begin(); i != render_views.end(); ++i) {
1442 BrowserThread::PostTask(
1443 BrowserThread::UI, FROM_HERE,
1444 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1445 i->first, i->second, url, name, !allow));
1446 }
1447
1448 return allow;
1449}
1450
[email protected]6133f922011-07-01 21:34:341451net::URLRequestContext*
1452ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201453 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421455 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201456 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341457 return io_data->extensions_request_context();
1458 }
1459
1460 return NULL;
1461}
1462
[email protected]317f96c92011-05-31 06:53:411463QuotaPermissionContext*
1464ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1465 return new ChromeQuotaPermissionContext();
1466}
1467
[email protected]848dd042011-06-04 18:24:031468void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171469 int render_process_id,
1470 int render_view_id,
1471 int cert_error,
1472 const net::SSLInfo& ssl_info,
1473 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021474 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031475 bool overridable,
[email protected]d9be47702012-05-16 03:41:221476 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171477 const base::Callback<void(bool)>& callback,
1478 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021479 if (resource_type != ResourceType::MAIN_FRAME) {
1480 // A sub-resource has a certificate error. The user doesn't really
1481 // have a context for making the right decision, so block the
1482 // request hard, without an info bar to allow showing the insecure
1483 // content.
1484 *cancel_request = true;
1485 return;
1486 }
1487
[email protected]f9034cf2011-07-21 12:43:411488 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131489 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171490 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411491 if (!tab) {
1492 NOTREACHED();
1493 return;
1494 }
1495 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501496 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301497 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011498 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1499 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411500 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171501 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411502 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171503 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411504 return;
1505 }
1506 }
1507
[email protected]1e87df32012-09-12 04:53:191508#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231509 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1510 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1511 if (captive_portal_tab_helper)
1512 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191513#endif
1514
[email protected]f9034cf2011-07-21 12:43:411515 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221516 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1517 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031518}
1519
[email protected]c99c442e2011-08-24 11:37:301520void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451521 int render_process_id,
1522 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401523 const net::HttpNetworkSession* network_session,
1524 net::SSLCertRequestInfo* cert_request_info,
1525 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131526 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451527 render_process_id, render_view_id);
1528 if (!tab) {
1529 NOTREACHED();
1530 return;
1531 }
1532
[email protected]6786bf402011-12-03 15:19:451533 GURL requesting_url("https://" + cert_request_info->host_and_port);
1534 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1535 << cert_request_info->host_and_port;
1536
[email protected]627e0512011-12-21 22:55:301537 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451538 scoped_ptr<Value> filter(
1539 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1540 requesting_url,
1541 requesting_url,
1542 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1543 std::string(), NULL));
1544
1545 if (filter.get()) {
1546 // Try to automatically select a client certificate.
1547 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1548 DictionaryValue* filter_dict =
1549 static_cast<DictionaryValue*>(filter.get());
1550
1551 const std::vector<scoped_refptr<net::X509Certificate> >&
1552 all_client_certs = cert_request_info->client_certs;
1553 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1554 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1555 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401556 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451557 return;
1558 }
1559 }
1560 } else {
1561 NOTREACHED();
1562 }
1563 }
1564
[email protected]11feec322012-09-18 03:58:521565 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1566 if (!ssl_tab_helper) {
1567 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451568 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141569 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401570 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451571 return;
1572 }
[email protected]11feec322012-09-18 03:58:521573 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401574 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451575}
1576
[email protected]3b455502012-12-11 18:22:581577void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451578 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581579 net::CertificateMimeType cert_type,
1580 const void* cert_data,
1581 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451582 int render_process_id,
1583 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581584 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1585 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451586}
1587
[email protected]dc73a7b2012-03-25 15:27:181588content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561589 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181590}
1591
[email protected]941623e2011-06-07 23:06:041592void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1593 const GURL& source_origin,
1594 int callback_context,
1595 int render_process_id,
1596 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111597#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1599 WebContents* contents =
1600 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1601 if (!contents) {
[email protected]941623e2011-06-07 23:06:041602 NOTREACHED();
1603 return;
1604 }
1605
[email protected]d0d9c3ee2012-06-19 03:07:021606 // Skip showing the infobar if the request comes from an extension, and that
1607 // extension has the 'notify' permission. (If the extension does not have the
1608 // permission, the user will still be prompted.)
1609 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011610 ExtensionInfoMap* extension_info_map =
1611 extensions::ExtensionSystem::Get(profile)->info_map();
1612 DesktopNotificationService* notification_service =
1613 DesktopNotificationServiceFactory::GetForProfile(profile);
1614 const Extension* extension = NULL;
1615 if (extension_info_map) {
1616 ExtensionSet extensions;
1617 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1618 source_origin, render_process_id,
1619 extensions::APIPermission::kNotification, &extensions);
1620 for (ExtensionSet::const_iterator iter = extensions.begin();
1621 iter != extensions.end(); ++iter) {
1622 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1623 extension = *iter;
1624 break;
1625 }
1626 }
1627 }
[email protected]eb4832a2012-12-08 01:57:521628 RenderViewHost* rvh =
1629 RenderViewHost::FromID(render_process_id, render_view_id);
1630 if (IsExtensionWithPermissionOrSuggestInConsole(
1631 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021632 if (rvh)
1633 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1634 return;
1635 }
1636
[email protected]c7cd5942013-04-30 03:31:011637 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021638 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111639#else
1640 NOTIMPLEMENTED();
1641#endif
[email protected]941623e2011-06-07 23:06:041642}
1643
1644WebKit::WebNotificationPresenter::Permission
1645 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021646 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201647 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021648 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111649#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201651 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041652
[email protected]c7cd5942013-04-30 03:31:011653 DesktopNotificationService* notification_service =
1654 io_data->GetNotificationService();
1655 if (notification_service) {
1656 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1657 ExtensionSet extensions;
1658 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1659 source_origin, render_process_id,
1660 extensions::APIPermission::kNotification, &extensions);
1661 for (ExtensionSet::const_iterator iter = extensions.begin();
1662 iter != extensions.end(); ++iter) {
1663 if (notification_service->IsExtensionEnabled((*iter)->id()))
1664 return WebKit::WebNotificationPresenter::PermissionAllowed;
1665 }
1666
1667 return notification_service->HasPermission(source_origin);
1668 }
1669
1670 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111671#else
1672 return WebKit::WebNotificationPresenter::PermissionAllowed;
1673#endif
[email protected]941623e2011-06-07 23:06:041674}
1675
1676void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171677 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041678 int render_process_id,
1679 int render_view_id,
1680 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111681#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041682 RenderViewHost* rvh = RenderViewHost::FromID(
1683 render_process_id, render_view_id);
1684 if (!rvh) {
1685 NOTREACHED();
1686 return;
1687 }
1688
[email protected]9f76c1e2012-03-05 15:15:581689 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301690 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041691 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371692 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041693 service->ShowDesktopNotification(
1694 params, render_process_id, render_view_id,
1695 worker ? DesktopNotificationService::WorkerNotification :
1696 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111697#else
1698 NOTIMPLEMENTED();
1699#endif
[email protected]941623e2011-06-07 23:06:041700}
1701
1702void ChromeContentBrowserClient::CancelDesktopNotification(
1703 int render_process_id,
1704 int render_view_id,
1705 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111706#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041707 RenderViewHost* rvh = RenderViewHost::FromID(
1708 render_process_id, render_view_id);
1709 if (!rvh) {
1710 NOTREACHED();
1711 return;
1712 }
1713
[email protected]9f76c1e2012-03-05 15:15:581714 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301715 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041716 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371717 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041718 service->CancelDesktopNotification(
1719 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111720#else
1721 NOTIMPLEMENTED();
1722#endif
[email protected]941623e2011-06-07 23:06:041723}
1724
[email protected]9f3fba52011-06-08 20:37:191725bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351726 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021727 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191728 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201729 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011730 int render_process_id,
1731 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191732 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011733
1734 *no_javascript_access = false;
1735
[email protected]9f3fba52011-06-08 20:37:191736 // If the opener is trying to create a background window but doesn't have
1737 // the appropriate permission, fail the attempt.
1738 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201739 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531740 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1741
[email protected]03b6d552012-03-29 04:03:011742 if (!map->SecurityOriginHasAPIPermission(
1743 source_origin,
1744 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061745 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011746 return false;
1747 }
1748
[email protected]7b54ca02012-03-02 18:06:531749 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1750 // return a recently installed Extension even if this CanCreateWindow call
1751 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011752 // because the permission check above would have caused an early return
1753 // already. We must use the full URL to find hosted apps, though, and not
1754 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531755 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351756 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291757 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011758 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191759 }
[email protected]056efdc2013-04-06 00:14:531760
1761 // No new browser window (popup or tab) in app mode.
1762 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1763 chrome::IsRunningInForcedAppMode()) {
1764 return false;
1765 }
1766
[email protected]9f3fba52011-06-08 20:37:191767 return true;
1768}
1769
1770std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201771 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191772 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1773 // Check if it's an extension-created worker, in which case we want to use
1774 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201775 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191776 const Extension* extension =
1777 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1778 return extension ? extension->name() : std::string();
1779}
1780
[email protected]99907362012-01-11 05:41:401781void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1782 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171783}
1784
[email protected]7a06d282013-05-03 04:39:331785// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021786content::SpeechRecognitionManagerDelegate*
1787 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321788#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021789 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321790#else
1791 return NULL;
1792#endif
[email protected]66cfec62012-02-24 17:57:511793}
1794
[email protected]ae6e9912011-07-27 01:18:281795net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1796 return g_browser_process->net_log();
1797}
1798
[email protected]32538d92011-08-25 00:09:231799AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1800 return new ChromeAccessTokenStore();
1801}
1802
[email protected]dbae6b02011-06-29 23:51:411803bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011804 return true;
[email protected]dbae6b02011-06-29 23:51:411805}
1806
[email protected]64d69de42012-02-06 00:19:541807void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321808 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061809 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581810 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061811 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061812
[email protected]f3986f82012-01-03 20:00:061813 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541814 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061815 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541816 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061817 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541818 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061819 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541820 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061821 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541822 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061823 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541824 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031825 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1826 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061827
[email protected]64d69de42012-02-06 00:19:541828 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401829 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541830 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401831 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541832 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401833 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541834 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401835 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061836
[email protected]ddf72142012-05-22 04:52:401837 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061838
[email protected]64d69de42012-02-06 00:19:541839 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401840 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541841 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061842 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541843 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061844 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1845 const DictionaryValue* inspector_settings =
1846 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1847 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181848 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1849 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061850 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181851 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541852 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181853 std::make_pair(iter.key(), value));
1854 }
[email protected]f3986f82012-01-03 20:00:061855 }
1856 }
[email protected]64d69de42012-02-06 00:19:541857 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061858
[email protected]ddf72142012-05-22 04:52:401859 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541860 web_prefs->javascript_enabled = false;
1861 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1862 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401863 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541864 web_prefs->plugins_enabled = false;
1865 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1866 web_prefs->java_enabled = false;
1867 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401868 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061869
[email protected]64d69de42012-02-06 00:19:541870 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1871 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061872
[email protected]64d69de42012-02-06 00:19:541873 web_prefs->memory_info_enabled =
1874 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1875 web_prefs->allow_displaying_insecure_content =
1876 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1877 web_prefs->allow_running_insecure_content =
1878 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321879#if defined(OS_ANDROID)
1880 web_prefs->font_scale_factor =
1881 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1882 web_prefs->force_enable_zoom =
1883 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451884#if defined(GOOGLE_TV)
1885 web_prefs->user_gesture_required_for_media_playback = false;
1886#endif
[email protected]d3b935f2012-10-19 23:14:321887#endif
[email protected]9d06d88d2012-02-23 22:37:081888 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061889
[email protected]46f8e742013-05-03 18:37:141890#if defined(OS_ANDROID)
1891 web_prefs->user_style_sheet_enabled = false;
1892#else
[email protected]64d69de42012-02-06 00:19:541893 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151894 UserStyleSheetWatcher* user_style_sheet_watcher =
1895 UserStyleSheetWatcherFactory::GetForProfile(profile);
1896 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541897 web_prefs->user_style_sheet_enabled = true;
1898 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151899 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541900 } else {
1901 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061902 }
[email protected]46f8e742013-05-03 18:37:141903#endif
[email protected]f3986f82012-01-03 20:00:061904
[email protected]cfadadd2013-04-03 04:43:021905 web_prefs->asynchronous_spell_checking_enabled = true;
1906 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571907
[email protected]64d69de42012-02-06 00:19:541908 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061909 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541910 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061911 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541912 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061913 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1914
1915 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541916 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061917 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541918 web_prefs->default_encoding);
1919 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401920 prefs->ClearPref(prefs::kDefaultCharset);
1921 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061922 }
[email protected]64d69de42012-02-06 00:19:541923 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061924
[email protected]88ecf66d2012-12-11 22:53:471925 if (content::IsForceCompositingModeEnabled())
1926 web_prefs->force_compositing_mode = true;
1927
[email protected]299d7f12012-05-23 05:31:151928 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231929 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131930 ExtensionService* service =
1931 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061932 if (service) {
[email protected]1bc28312012-11-08 08:31:531933 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1934 const Extension* extension = service->extensions()->GetByID(url.host());
1935 // Ensure that we are only granting extension preferences to URLs with
1936 // the correct scheme. Without this check, chrome-guest:// schemes used by
1937 // webview tags as well as hosts that happen to match the id of an
1938 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421939 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531940 extension_webkit_preferences::SetPreferences(
1941 extension, view_type, web_prefs);
1942 }
[email protected]f3986f82012-01-03 20:00:061943 }
1944
[email protected]cb2edf22013-04-01 20:25:231945 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541946 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231947 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061948 // Disable all kinds of acceleration for background pages.
1949 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541950 web_prefs->force_compositing_mode = false;
1951 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061952 }
[email protected]2e21fe292012-03-02 22:52:321953
1954#if defined(FILE_MANAGER_EXTENSION)
1955 // Override the default of suppressing HW compositing for WebUI pages for the
1956 // file manager, which is implemented using WebUI but wants HW acceleration
1957 // for video decode & render.
1958 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1959 web_prefs->accelerated_compositing_enabled = true;
1960 web_prefs->accelerated_2d_canvas_enabled = true;
1961 }
1962#endif
[email protected]181a95ee2011-07-12 19:26:361963}
1964
1965void ChromeContentBrowserClient::UpdateInspectorSetting(
1966 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061967 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581968 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061969 DictionaryPrefUpdate update(
1970 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1971 prefs::kWebKitInspectorSettings);
1972 DictionaryValue* inspector_settings = update.Get();
1973 inspector_settings->SetWithoutPathExpansion(key,
1974 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361975}
1976
[email protected]b8148ac2011-07-13 22:03:251977void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1978 BrowserURLHandler* handler) {
1979 // Add the default URL handlers.
1980 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1981 BrowserURLHandler::null_handler());
1982 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1983 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1984
[email protected]b3adbd02011-11-30 22:23:271985 // about: handler. Must come before chrome: handler, since it will
1986 // rewrite about: urls to chrome: URLs and then expect chrome: to
1987 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251988 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1989 BrowserURLHandler::null_handler());
1990 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241991 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251992}
1993
1994void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371995 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581996 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471997 BrowsingDataRemover* remover =
1998 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551999 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2000 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252001 // BrowsingDataRemover takes care of deleting itself when done.
2002}
2003
2004void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372005 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582006 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472007 BrowsingDataRemover* remover =
2008 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232009 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552010 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252011 // BrowsingDataRemover takes care of deleting itself when done.
2012}
2013
[email protected]650b2d52013-02-10 03:41:452014base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322015 return download_util::GetDefaultDownloadDirectory();
2016}
2017
[email protected]c9b6eb62011-10-18 20:49:392018std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2019 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2020}
2021
[email protected]b7631cc2012-09-15 05:08:382022void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2023 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542024#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382025 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2026 scoped_ptr<ppapi::host::HostFactory>(
2027 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542028#endif
[email protected]b7631cc2012-09-15 05:08:382029}
2030
[email protected]0c7193742012-11-07 19:05:032031content::BrowserPpapiHost*
2032 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2033 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132034 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032035 while (!iter.Done()) {
2036 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2037 if (host->process() &&
2038 host->process()->GetData().id == plugin_process_id) {
2039 // Found the plugin.
2040 return host->browser_ppapi_host();
2041 }
2042 ++iter;
2043 }
2044 return NULL;
2045}
2046
[email protected]7b38b192013-03-23 18:39:312047bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2048 content::BrowserContext* browser_context, const GURL& site_url) {
2049 if (CommandLine::ForCurrentProcess()->HasSwitch(
2050 switches::kEnableBrowserPluginForAllViewTypes))
2051 return true;
2052
2053 Profile* profile = Profile::FromBrowserContext(browser_context);
2054 ExtensionService* service =
2055 extensions::ExtensionSystem::Get(profile)->extension_service();
2056 if (!service)
2057 return false;
2058
2059 const Extension* extension = service->extensions()->
2060 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2061 if (!extension)
2062 return false;
2063
[email protected]c2d2f102013-04-29 16:42:582064 return extension->HasAPIPermission(APIPermission::kWebView) ||
2065 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312066}
2067
[email protected]38cd8f7f2012-06-15 22:06:072068bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582069 content::BrowserContext* browser_context,
2070 const GURL& url,
2071 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292072 if (!url.is_valid())
2073 return false;
2074
2075 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422076 if (url.SchemeIs(extensions::kExtensionScheme) &&
2077 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:292078 return true;
[email protected]885c0e92012-11-13 20:27:422079 }
[email protected]a658d452012-03-02 12:45:292080
[email protected]9a5940d2012-04-27 19:16:232081 Profile* profile = Profile::FromBrowserContext(browser_context);
2082 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192083 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132084 extensions::ExtensionSystem::Get(profile)->extension_service();
2085 if (extension_service) {
2086 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232087 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2088 }
2089
[email protected]f237c0f2012-03-10 07:49:102090 // Need to check this now and not on construction because otherwise it won't
2091 // work with browser_tests.
2092 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2093 std::string allowed_list =
2094 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232095 if (allowed_list == "*") {
2096 // The wildcard allows socket API only for packaged and platform apps.
2097 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402098 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2099 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232100 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392101 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102102 while (t.GetNext()) {
2103 if (t.token() == host)
2104 return true;
2105 }
2106 }
2107
[email protected]a658d452012-03-02 12:45:292108 if (!extension)
2109 return false;
2110
[email protected]157cc902012-11-02 06:31:582111 extensions::SocketPermission::CheckParam extension_params(
2112 params.type, params.host, params.port);
2113 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2114 &extension_params))
[email protected]a658d452012-03-02 12:45:292115 return true;
2116
2117 return false;
[email protected]e461da2f2012-02-16 19:06:402118}
2119
[email protected]650b2d52013-02-10 03:41:452120base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2121 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142122 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2123 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2124}
2125
[email protected]a28e3302013-02-03 03:50:432126ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2127 WebContents* web_contents) {
2128 return new ChromeSelectFilePolicy(web_contents);
2129}
2130
[email protected]7d9424702013-04-14 13:14:162131void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2132 std::vector<std::string>* additional_allowed_schemes) {
2133 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2134 additional_allowed_schemes);
2135 additional_allowed_schemes->push_back(kChromeUIScheme);
2136 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2137}
2138
[email protected]02250952013-04-24 23:52:532139void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2140 const base::FilePath& storage_partition_path,
2141 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2142#if !defined(OS_ANDROID)
2143 additional_providers->push_back(new MediaFileSystemMountPointProvider(
2144 storage_partition_path));
2145#endif
2146}
2147
[email protected]e60c0232011-11-11 19:56:352148#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182149void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2150 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382151 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082152 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392153#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452154 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392155 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2156 DCHECK(!data_path.empty());
2157
2158 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452159 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392160 base::PlatformFile f =
2161 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2162 DCHECK(f != base::kInvalidPlatformFileValue);
2163 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2164 FileDescriptor(f, true)));
2165
[email protected]650b2d52013-02-10 03:41:452166 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392167 data_path.AppendASCII("chrome_100_percent.pak");
2168 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2169 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372170 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392171 FileDescriptor(f, true)));
2172
2173 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452174 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392175 GetLocaleFilePath(locale, false);
2176 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2177 DCHECK(f != base::kInvalidPlatformFileValue);
2178 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2179 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382180
[email protected]650b2d52013-02-10 03:41:452181 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372182 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2183 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2184 DCHECK(f != base::kInvalidPlatformFileValue);
2185 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2186 FileDescriptor(f, true)));
2187
[email protected]40da3e0c2012-10-24 22:03:382188#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432189 if (IsCrashReporterEnabled()) {
2190 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2191 if (f == base::kInvalidPlatformFileValue) {
2192 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2193 "be disabled for this process.";
2194 } else {
2195 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2196 FileDescriptor(f, true)));
2197 }
[email protected]40da3e0c2012-10-24 22:03:382198 }
2199#endif // defined(USE_LINUX_BREAKPAD)
2200
2201#else
2202 int crash_signal_fd = GetCrashSignalFD(command_line);
2203 if (crash_signal_fd >= 0) {
2204 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2205 FileDescriptor(crash_signal_fd,
2206 false)));
2207 }
[email protected]29699c22012-10-03 23:57:392208#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302209}
[email protected]e60c0232011-11-11 19:56:352210#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302211
[email protected]4a65826d2011-08-25 16:04:012212#if defined(OS_WIN)
2213const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2214 return chrome::kBrowserResourcesDll;
2215}
[email protected]34f48682013-03-20 00:30:182216
2217void ChromeContentBrowserClient::PreSpawnRenderer(
2218 sandbox::TargetPolicy* policy,
2219 bool* success) {
2220 // This code is duplicated in nacl_exe_win_64.cc.
2221 // Allow the server side of a pipe restricted to the "chrome.nacl."
2222 // namespace so that it cannot impersonate other system or other chrome
2223 // service pipes.
2224 sandbox::ResultCode result = policy->AddRule(
2225 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2226 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2227 L"\\\\.\\pipe\\chrome.nacl.*");
2228 if (result != sandbox::SBOX_ALL_OK) {
2229 *success = false;
2230 return;
2231 }
2232
2233 // Renderers need to send named pipe handles and shared memory
2234 // segment handles to NaCl loader processes.
2235 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2236 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2237 L"File");
2238 if (result != sandbox::SBOX_ALL_OK) {
2239 *success = false;
2240 return;
2241 }
2242}
[email protected]4a65826d2011-08-25 16:04:012243#endif
2244
[email protected]37a72af2011-06-13 05:42:012245#if defined(USE_NSS)
2246crypto::CryptoModuleBlockingPasswordDelegate*
2247 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2248 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292249 return chrome::NewCryptoModuleBlockingDialogDelegate(
2250 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012251}
2252#endif
2253
[email protected]d977f9c2011-03-14 16:10:262254} // namespace chrome