blob: 344cb0d6fe799cf470d8a76fcafdf44b6c79c24b [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]29699c22012-10-03 23:57:3913#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5714#include "base/prefs/pref_service.h"
[email protected]f4ebe772013-02-02 00:21:3915#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0616#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2518#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3019#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4720#include "chrome/browser/browsing_data/browsing_data_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1222#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4123#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4124#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5625#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0526#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4527#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3228#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0829#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3230#include "chrome/browser/download/download_util.h"
[email protected]24665682013-02-25 20:59:3831#include "chrome/browser/extensions/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1632#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0633#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0434#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3335#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2636#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0837#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2538#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0639#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4940#include "chrome/browser/extensions/message_handler.h"
[email protected]eb4832a2012-12-08 01:57:5241#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2342#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/browser/google/google_util.h"
[email protected]c5dec6292013-01-25 04:54:5244#include "chrome/browser/instant/instant_service.h"
45#include "chrome/browser/instant/instant_service_factory.h"
[email protected]09e9f692013-03-07 23:53:0446#include "chrome/browser/instant/search.h"
[email protected]11158e2d2013-02-01 02:31:5647#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]0c7193742012-11-07 19:05:0348#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2849#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0450#include "chrome/browser/notifications/desktop_notification_service.h"
51#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4252#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5653#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0654#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4155#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5056#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0757#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4158#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1459#include "chrome/browser/printing/printing_message_filter.h"
60#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3261#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0662#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1463#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3364#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3865#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]970c63e2013-03-07 00:25:3067#include "chrome/browser/signin/signin_manager.h"
68#include "chrome/browser/signin/signin_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:0269#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4670#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5871#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0372#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5273#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4574#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5475#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4376#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4477#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5078#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3079#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0680#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1581#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5382#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3083#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0184#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1485#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3086#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2987#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0488#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3889#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4490#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5891#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3492#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1293#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3894#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0995#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4496#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4397#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3098#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3899#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31100#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03101#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59102#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36103#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30104#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33105#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05106#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33107#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19108#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10109#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18111#include "content/public/common/content_descriptors.h"
[email protected]885c0e92012-11-13 20:27:42112#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39113#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23114#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53115#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58116#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34117#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06118#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57119#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38120#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39121#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08122#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36123#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04124#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26125
[email protected]b48c9182011-10-26 18:03:30126#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38127#include "chrome/browser/chrome_browser_main_win.h"
128#elif defined(OS_MACOSX)
129#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56130#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30131#elif defined(OS_CHROMEOS)
132#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49133#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26134#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30135#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09136#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38137#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09138#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39139#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30140#elif defined(OS_POSIX)
141#include "chrome/browser/chrome_browser_main_posix.h"
142#endif
143
[email protected]6653c192012-04-10 22:52:44144#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30145#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12146#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43147#endif
[email protected]b80f68432011-05-02 17:22:30148
[email protected]1e87df32012-09-12 04:53:19149#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
150#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
151#endif
152
[email protected]29699c22012-10-03 23:57:39153#if defined(OS_ANDROID)
154#include "ui/base/ui_base_paths.h"
155#endif
156
[email protected]37a72af2011-06-13 05:42:01157#if defined(USE_NSS)
158#include "chrome/browser/ui/crypto_module_password_dialog.h"
159#endif
160
[email protected]c7abd422012-09-25 00:20:08161using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47162using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03163using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39164using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31165using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59166using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08167using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00168using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11169using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33170using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13171using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06172using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34173using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40174using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25175using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39176
[email protected]c5dbef02011-05-13 05:06:09177namespace {
178
[email protected]e461da2f2012-02-16 19:06:40179const char* kPredefinedAllowedSocketOrigins[] = {
180 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18181 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45182 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
183 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
184 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
185 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35186 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54187 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
188 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
189 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
190 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
191 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
192 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38193 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58194 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
195 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40196};
197
[email protected]f8f93eb2012-09-25 03:06:24198// Returns a copy of the given url with its host set to given host and path set
199// to given path. Other parts of the url will be the same.
200GURL ReplaceURLHostAndPath(const GURL& url,
201 const std::string& host,
202 const std::string& path) {
203 url_canon::Replacements<char> replacements;
204 replacements.SetHost(host.c_str(),
205 url_parse::Component(0, host.length()));
206 replacements.SetPath(path.c_str(),
207 url_parse::Component(0, path.length()));
208 return url.ReplaceComponents(replacements);
209}
210
211// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
212GURL AddUberHost(const GURL& url) {
213 const std::string uber_host = chrome::kChromeUIUberHost;
214 const std::string new_path = url.host() + url.path();
215
216 return ReplaceURLHostAndPath(url, uber_host, new_path);
217}
218
[email protected]045bf7c2012-09-28 20:27:36219// If url->host() is "chrome" and url->path() has characters other than the
220// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
221// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24222bool RemoveUberHost(GURL* url) {
223 if (url->host() != chrome::kChromeUIUberHost)
224 return false;
225
[email protected]045bf7c2012-09-28 20:27:36226 if (url->path().empty() || url->path() == "/")
227 return false;
228
[email protected]f8f93eb2012-09-25 03:06:24229 const std::string old_path = url->path();
230
231 const std::string::size_type separator = old_path.find('/', 1);
232 std::string new_host;
233 std::string new_path;
234 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36235 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24236 } else {
237 new_host = old_path.substr(1, separator - 1);
238 new_path = old_path.substr(separator);
239 }
240
241 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
242
243 return true;
244}
245
[email protected]b8148ac2011-07-13 22:03:25246// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42247bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24248 // Do not handle special URLs such as "about:foo"
249 if (!url->host().empty()) {
250 const GURL chrome_url = AddUberHost(*url);
251
252 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
253 // be called.
254 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
255 browser_context, chrome_url))
256 return true;
257 }
258
[email protected]863f70a2012-01-27 02:05:50259 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
260 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25261 return false;
262
[email protected]fe69558d2012-03-12 11:34:49263#if defined(OS_CHROMEOS)
264 // Special case : in ChromeOS in Guest mode bookmarks and history are
265 // disabled for security reasons. New tab page explains the reasons, so
266 // we redirect user to new tab page.
267 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
268 if (url->SchemeIs(chrome::kChromeUIScheme) &&
269 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
270 url->DomainIs(chrome::kChromeUIHistoryHost))) {
271 // Rewrite with new tab URL
272 *url = GURL(chrome::kChromeUINewTabURL);
273 }
274 }
275#endif
276
[email protected]b8148ac2011-07-13 22:03:25277 // Special case the new tab page. In older versions of Chrome, the new tab
278 // page was hosted at chrome-internal:<blah>. This might be in people's saved
279 // sessions or bookmarks, so we say any URL with that scheme triggers the new
280 // tab page.
281 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
282 // Rewrite it with the proper new tab URL.
283 *url = GURL(chrome::kChromeUINewTabURL);
284 }
285
286 return true;
287}
288
[email protected]f8f93eb2012-09-25 03:06:24289// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
290// "chrome://foo/".
291bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
292 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
293 return false;
294
295 return RemoveUberHost(url);
296}
297
[email protected]8d3132f62011-10-12 07:13:42298// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
299// below. Extension, and isolated apps require different privileges to be
300// granted to their RenderProcessHosts. This classification allows us to make
301// sure URLs are served by hosts with the right set of privileges.
302enum RenderProcessHostPrivilege {
303 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45304 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42305 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45306 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42307};
308
309RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
310 const GURL& url,
311 ExtensionService* service) {
312 // Default to a normal renderer cause it is lower privileged. This should only
313 // occur if the URL on a site instance is either malformed, or uninitialized.
314 // If it is malformed, then there is no need for better privileges anyways.
315 // If it is uninitialized, but eventually settles on being an a scheme other
316 // than normal webrenderer, the navigation logic will correct us out of band
317 // anyways.
318 if (!url.is_valid())
319 return PRIV_NORMAL;
320
[email protected]885c0e92012-11-13 20:27:42321 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44322 const Extension* extension =
323 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45324 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42325 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45326 if (extension && extension->is_hosted_app())
327 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42328
329 return PRIV_EXTENSION;
330 }
331
332 return PRIV_NORMAL;
333}
334
335RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30336 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46337 extensions::ProcessMap* process_map,
338 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46339 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30340 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46341 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21342 return PRIV_NORMAL;
343
[email protected]6f371442011-11-09 06:45:46344 for (std::set<std::string>::iterator iter = extension_ids.begin();
345 iter != extension_ids.end(); ++iter) {
346 const Extension* extension = service->GetExtensionById(*iter, false);
347 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42348 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45349 if (extension && extension->is_hosted_app())
350 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42351 }
352
[email protected]676f6ab2011-10-19 20:23:21353 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42354}
355
[email protected]6786bf402011-12-03 15:19:45356bool CertMatchesFilter(const net::X509Certificate& cert,
357 const base::DictionaryValue& filter) {
358 // TODO(markusheintz): This is the minimal required filter implementation.
359 // Implement a better matcher.
360
361 // An empty filter matches any client certificate since no requirements are
362 // specified at all.
363 if (filter.empty())
364 return true;
365
366 std::string common_name;
367 if (filter.GetString("ISSUER.CN", &common_name) &&
368 (cert.issuer().common_name == common_name)) {
369 return true;
370 }
371 return false;
372}
373
[email protected]f3986f82012-01-03 20:00:06374// Fills |map| with the per-script font prefs under path |map_name|.
375void FillFontFamilyMap(const PrefService* prefs,
376 const char* map_name,
377 WebPreferences::ScriptFontFamilyMap* map) {
378 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
379 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
380 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
381 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23382 if (!font_family.empty())
383 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06384 }
385}
386
[email protected]a1733df2012-06-22 11:24:18387#if defined(OS_POSIX) && !defined(OS_MACOSX)
388int GetCrashSignalFD(const CommandLine& command_line) {
389 if (command_line.HasSwitch(switches::kExtensionProcess)) {
390 ExtensionCrashHandlerHostLinux* crash_handler =
391 ExtensionCrashHandlerHostLinux::GetInstance();
392 return crash_handler->GetDeathSignalSocket();
393 }
394
395 std::string process_type =
396 command_line.GetSwitchValueASCII(switches::kProcessType);
397
398 if (process_type == switches::kRendererProcess)
399 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
400
401 if (process_type == switches::kPluginProcess)
402 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
403
404 if (process_type == switches::kPpapiPluginProcess)
405 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
406
407 if (process_type == switches::kGpuProcess)
408 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
409
410 return -1;
411}
412#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
413
[email protected]7c60f5042013-02-14 03:39:32414// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52415// facilitates grouping process-per-site. The |url| is transformed, for
416// example, from
417//
418// https://www.google.com/search?espv=1&q=tractors
419//
[email protected]7c60f5042013-02-14 03:39:32420// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52421//
422// chrome-search://www.google.com/search?espv=1&q=tractors
423//
424// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32425//
426// If the input is already an effective URL then that same URL is returned.
427GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
428 CHECK(chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
429 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52430
431 if (url.SchemeIs(chrome::kChromeSearchScheme))
432 return url;
433
434 GURL effective_url(url);
435
436 // Replace the scheme with "chrome-search:".
437 url_canon::Replacements<char> replacements;
438 std::string search_scheme(chrome::kChromeSearchScheme);
439 replacements.SetScheme(search_scheme.data(),
440 url_parse::Component(0, search_scheme.length()));
441 effective_url = effective_url.ReplaceComponents(replacements);
442 return effective_url;
443}
444
[email protected]970c63e2013-03-07 00:25:30445GURL GetEffectiveURLForSignin(const GURL& url) {
446 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
447
448 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03449 // Copy the path because the argument to SetPathStr must outlive
450 // the Replacements object.
451 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30452 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03453 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30454 effective_url = effective_url.ReplaceComponents(replacements);
455 return effective_url;
456}
457
[email protected]9dbfff12011-07-01 19:37:07458} // namespace
[email protected]c5dbef02011-05-13 05:06:09459
[email protected]d977f9c2011-03-14 16:10:26460namespace chrome {
461
[email protected]e461da2f2012-02-16 19:06:40462ChromeContentBrowserClient::ChromeContentBrowserClient() {
463 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
464 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40465}
466
467ChromeContentBrowserClient::~ChromeContentBrowserClient() {
468}
469
[email protected]bca18382012-06-25 19:15:23470// static
[email protected]c753f142013-02-10 13:14:04471void ChromeContentBrowserClient::RegisterUserPrefs(
472 PrefRegistrySyncable* registry) {
473 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
474 false,
475 PrefRegistrySyncable::UNSYNCABLE_PREF);
476 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
477 true,
478 PrefRegistrySyncable::UNSYNCABLE_PREF);
479 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
480 false,
481 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23482}
483
[email protected]50462bf02011-11-21 19:13:31484content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
485 const content::MainFunctionParams& parameters) {
486 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30487 // Construct the Main browser parts based on the OS type.
488#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31489 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04490#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31491 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30492#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22493 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26494#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31495 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14496#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09497 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30498#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31499 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04500#else
[email protected]b48c9182011-10-26 18:03:30501 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31502 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30503#endif
504
[email protected]c7480942011-11-08 19:18:27505 // Construct additional browser parts. Stages are called in the order in
506 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22507#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41508 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04509#endif
[email protected]c7480942011-11-08 19:18:27510
511#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41512 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27513#endif
514
[email protected]dc04be7c2012-03-15 23:57:49515#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41516 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49517#endif
518
[email protected]e050ef142012-03-21 01:04:24519#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41520 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24521#endif
522
[email protected]50462bf02011-11-21 19:13:31523 return main_parts;
[email protected]f967b722011-09-07 00:58:04524}
525
[email protected]e94bbcb2012-09-07 05:33:57526std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19527 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57528 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53529 std::string partition_id;
530
531 // The partition ID for webview guest processes is the string value of its
532 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
533 if (site.SchemeIs(chrome::kGuestScheme))
534 partition_id = site.spec();
535
536 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
537 return partition_id;
538}
539
540bool ChromeContentBrowserClient::IsValidStoragePartitionId(
541 content::BrowserContext* browser_context,
542 const std::string& partition_id) {
543 // The default ID is empty and is always valid.
544 if (partition_id.empty())
545 return true;
546
547 return GURL(partition_id).is_valid();
548}
549
550void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
551 content::BrowserContext* browser_context,
552 const GURL& site,
[email protected]14acc642012-11-17 12:20:10553 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53554 std::string* partition_domain,
555 std::string* partition_name,
556 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10557 // Default to the browser-wide storage partition and override based on |site|
558 // below.
559 partition_domain->clear();
560 partition_name->clear();
561 *in_memory = false;
562
[email protected]1bc28312012-11-08 08:31:53563 // For the webview tag, we create special guest processes, which host the
564 // tag content separately from the main application that embeds the tag.
565 // A webview tag can specify both the partition name and whether the storage
566 // for that partition should be persisted. Each tag gets a SiteInstance with
567 // a specially formatted URL, based on the application it is hosted by and
568 // the partition requested by it. The format for that URL is:
569 // chrome-guest://partition_domain/persist?partition_name
570 if (site.SchemeIs(chrome::kGuestScheme)) {
571 // Since guest URLs are only used for packaged apps, there must be an app
572 // id in the URL.
573 CHECK(site.has_host());
574 *partition_domain = site.host();
575 // Since persistence is optional, the path must either be empty or the
576 // literal string.
577 *in_memory = (site.path() != "/persist");
578 // The partition name is user supplied value, which we have encoded when the
579 // URL was created, so it needs to be decoded.
580 *partition_name = net::UnescapeURLComponent(site.query(),
581 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10582 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
583 // If |can_be_default| is false, the caller is stating that the |site|
584 // should be parsed as if it had isolated storage. In particular it is
585 // important to NOT check ExtensionService for the is_storage_isolated()
586 // attribute because this code path is run during Extension uninstall
587 // to do cleanup after the Extension has already been unloaded from the
588 // ExtensionService.
589 bool is_isolated = !can_be_default;
590 if (can_be_default) {
591 const Extension* extension = NULL;
592 Profile* profile = Profile::FromBrowserContext(browser_context);
593 ExtensionService* extension_service =
594 extensions::ExtensionSystem::Get(profile)->extension_service();
595 if (extension_service) {
596 extension = extension_service->extensions()->
597 GetExtensionOrAppByURL(ExtensionURLInfo(site));
598 if (extension && extension->is_storage_isolated()) {
599 is_isolated = true;
600 }
601 }
602 }
[email protected]1bc28312012-11-08 08:31:53603
[email protected]14acc642012-11-17 12:20:10604 if (is_isolated) {
605 CHECK(site.has_host());
606 // For extensions with isolated storage, the the host of the |site| is
607 // the |partition_domain|. The |in_memory| and |partition_name| are only
608 // used in guest schemes so they are cleared here.
609 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53610 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10611 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53612 }
[email protected]d1198fd2012-08-13 22:50:19613 }
614
[email protected]14acc642012-11-17 12:20:10615 // Assert that if |can_be_default| is false, the code above must have found a
616 // non-default partition. If this fails, the caller has a serious logic
617 // error about which StoragePartition they expect to be in and it is not
618 // safe to continue.
619 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44620}
621
[email protected]38b098f2012-03-14 21:11:57622content::WebContentsViewDelegate*
623 ChromeContentBrowserClient::GetWebContentsViewDelegate(
624 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27625 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32626}
627
[email protected]f364d1392011-04-08 21:03:10628void ChromeContentBrowserClient::RenderViewHostCreated(
629 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46630
[email protected]9f76c1e2012-03-05 15:15:58631 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46632 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02633 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46634
635 new ChromeRenderViewHostObserver(render_view_host,
636 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49637 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26638}
639
[email protected]24665682013-02-25 20:59:38640// Check if the extension activity log is enabled for the profile.
641static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
642 extensions::ActivityLog* activity_log =
643 extensions::ActivityLog::GetInstance(profile);
644 return activity_log->IsLogEnabled();
645}
646
[email protected]44703cc72013-01-24 04:56:06647void ChromeContentBrowserClient::GuestWebContentsCreated(
648 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
649 Profile* profile = Profile::FromBrowserContext(
650 embedder_web_contents->GetBrowserContext());
651 ExtensionService* service =
652 extensions::ExtensionSystem::Get(profile)->extension_service();
653 if (!service)
654 return;
655 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
656 const Extension* extension = service->extensions()->
657 GetExtensionOrAppByURL(ExtensionURLInfo(url));
658 if (!extension)
659 return;
660 std::vector<ExtensionMsg_Loaded_Params> extensions;
661 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
662 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
663}
664
[email protected]f3b1a082011-11-18 00:34:30665void ChromeContentBrowserClient::RenderProcessHostCreated(
666 content::RenderProcessHost* host) {
667 int id = host->GetID();
668 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41669 net::URLRequestContextGetter* context =
670 profile->GetRequestContextForRenderProcess(id);
671
[email protected]f3b1a082011-11-18 00:34:30672 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41673 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55674#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30675 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55676#endif
[email protected]658677f2012-06-09 06:04:02677#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08678 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03679#endif
[email protected]f3b1a082011-11-18 00:34:30680 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02681 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30682 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56683#if defined(OS_MACOSX)
684 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
685#endif
[email protected]43535512013-02-20 20:41:41686 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
687 id, profile, context));
[email protected]2736c032012-05-11 18:06:07688 host->GetChannel()->AddFilter(
689 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38690
[email protected]2ccf45c2011-08-19 23:35:50691 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
692 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07693
[email protected]24665682013-02-25 20:59:38694 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
695 IsExtensionActivityLogEnabledForProfile(profile)));
696
[email protected]39a5b532011-10-22 01:47:07697 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56698
699 RendererContentSettingRules rules;
700 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
701 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14702}
703
[email protected]3d7474ff2011-07-27 17:47:37704GURL ChromeContentBrowserClient::GetEffectiveURL(
705 content::BrowserContext* browser_context, const GURL& url) {
706 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52707 if (!profile)
708 return url;
709
[email protected]7c60f5042013-02-14 03:39:32710 // If the input |url| should be assigned to the Instant renderer, make its
711 // effective URL distinct from other URLs on the search provider's domain.
712 if (chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
713 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52714
[email protected]970c63e2013-03-07 00:25:30715 // If the input |url| should be assigned to the Signin renderer, make its
716 // effective URL distinct from other URLs on the signin service's domain.
717 // Note that the signin renderer will be allowed to sign the user in to
718 // Chrome.
719 if (SigninManager::IsWebBasedSigninFlowURL(url))
720 return GetEffectiveURLForSignin(url);
721
[email protected]c5dec6292013-01-25 04:54:52722 // If the input |url| is part of an installed app, the effective URL is an
723 // extension URL with the ID of that extension as the host. This has the
724 // effect of grouping apps together in a common SiteInstance.
725 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13726 extensions::ExtensionSystem::Get(profile)->extension_service();
727 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08728 return url;
729
[email protected]06bdd2b2012-11-30 18:47:13730 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44731 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08732 if (!extension)
733 return url;
734
[email protected]15877ca2011-11-18 22:40:52735 // Bookmark apps do not use the hosted app process model, and should be
736 // treated as normal URLs.
737 if (extension->from_bookmark())
738 return url;
739
[email protected]36fb2c7c2011-04-04 15:49:08740 // If the URL is part of an extension's web extent, convert it to an
741 // extension URL.
742 return extension->GetResourceURL(url.path());
743}
744
[email protected]056ad2a2011-07-12 02:13:55745bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37746 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52747 // Non-extension, non-Instant URLs should generally use
748 // process-per-site-instance. Because we expect to use the effective URL,
749 // URLs for hosted apps (apart from bookmark apps) should have an extension
750 // scheme by now.
751
752 Profile* profile = Profile::FromBrowserContext(browser_context);
753 if (!profile)
754 return false;
755
[email protected]7c60f5042013-02-14 03:39:32756 if (chrome::search::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52757 return true;
758
[email protected]970c63e2013-03-07 00:25:30759 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
760 return true;
761
[email protected]885c0e92012-11-13 20:27:42762 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55763 return false;
764
[email protected]c5dec6292013-01-25 04:54:52765 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13766 extensions::ExtensionSystem::Get(profile)->extension_service();
767 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55768 return false;
769
[email protected]06bdd2b2012-11-30 18:47:13770 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44771 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55772 if (!extension)
773 return false;
774
775 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53776 // permission, or that does not allow JavaScript access to the background
777 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55778 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40779 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06780 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29781 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53782 return false;
783 }
784 }
[email protected]056ad2a2011-07-12 02:13:55785
[email protected]7b54ca02012-03-02 18:06:53786 // Hosted apps that have script access to their background page must use
787 // process per site, since all instances can make synchronous calls to the
788 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55789 return true;
790}
791
[email protected]672c8c12013-03-07 12:30:06792// These are treated as WebUI schemes but do not get WebUI bindings.
793std::vector<std::string>
794ChromeContentBrowserClient::GetAdditionalWebUISchemes() {
795 std::vector<std::string> additional_schemes;
796 additional_schemes.push_back(chrome::kChromeSearchScheme);
797 return additional_schemes;
798}
799
[email protected]6bd30072013-02-08 18:17:11800net::URLRequestContextGetter*
801ChromeContentBrowserClient::CreateRequestContext(
802 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06803 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11804 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06805 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11806}
807
808net::URLRequestContextGetter*
809ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
810 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40811 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11812 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06813 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11814 Profile* profile = Profile::FromBrowserContext(browser_context);
815 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06816 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11817}
818
[email protected]46fb9442011-12-09 17:57:47819bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
820 return ProfileIOData::IsHandledURL(url);
821}
822
[email protected]2a5221b2011-09-27 23:07:31823bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30824 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31825 const GURL& site_url) {
826 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30827 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52828 // This may be NULL during tests. In that case, just assume any site can
829 // share any host.
830 if (!profile)
831 return true;
832
833 InstantService* instant_service =
834 InstantServiceFactory::GetForProfile(profile);
835 if (instant_service &&
836 instant_service->IsInstantProcess(process_host->GetID()))
[email protected]7c60f5042013-02-14 03:39:32837 return chrome::search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]c5dec6292013-01-25 04:54:52838
[email protected]970c63e2013-03-07 00:25:30839 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
840 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
841 return SigninManager::IsWebBasedSigninFlowURL(site_url);
842
[email protected]06bdd2b2012-11-30 18:47:13843 ExtensionService* service =
844 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46845 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31846
[email protected]ffa97602011-11-17 17:55:52847 // Don't allow the Task Manager to share a process with anything else.
848 // Otherwise it can affect the renderers it is observing.
849 // Note: we could create another RenderProcessHostPrivilege bucket for
850 // this to allow multiple chrome://tasks instances to share, but that's
851 // a very unlikely case without serious consequences.
852 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
853 return false;
854
[email protected]8d3132f62011-10-12 07:13:42855 // These may be NULL during tests. In that case, just assume any site can
856 // share any host.
[email protected]6f371442011-11-09 06:45:46857 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31858 return true;
859
[email protected]eec0b33c2011-12-05 22:09:45860 // Otherwise, just make sure the process privilege matches the privilege
861 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57862 RenderProcessHostPrivilege privilege_required =
863 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45864 return GetProcessPrivilege(process_host, process_map, service) ==
865 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31866}
867
[email protected]76411f412012-02-22 18:56:06868// This function is trying to limit the amount of processes used by extensions
869// with background pages. It uses a globally set percentage of processes to
870// run such extensions and if the limit is exceeded, it returns true, to
871// indicate to the content module to group extensions together.
872bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
873 content::BrowserContext* browser_context, const GURL& url) {
874 // It has to be a valid URL for us to check for an extension.
875 if (!url.is_valid())
876 return false;
877
878 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19879 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13880 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06881 if (!service)
882 return false;
883
884 // We have to have a valid extension with background page to proceed.
885 const Extension* extension =
886 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
887 if (!extension)
888 return false;
[email protected]9367eabc2013-03-01 01:29:29889 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06890 return false;
891
892 std::set<int> process_ids;
893 size_t max_process_count =
894 content::RenderProcessHost::GetMaxRendererProcessCount();
895
896 // Go through all profiles to ensure we have total count of extension
897 // processes containing background pages, otherwise one profile can
898 // starve the other.
899 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
900 GetLoadedProfiles();
901 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03902 ExtensionProcessManager* epm =
903 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32904 for (ExtensionProcessManager::const_iterator iter =
905 epm->background_hosts().begin();
906 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13907 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32908 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06909 }
910 }
911
912 if (process_ids.size() >
913 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
914 return true;
915 }
916
917 return false;
918}
919
[email protected]6f371442011-11-09 06:45:46920void ChromeContentBrowserClient::SiteInstanceGotProcess(
921 SiteInstance* site_instance) {
922 CHECK(site_instance->HasProcess());
923
924 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02925 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52926 if (!profile)
927 return;
928
929 // Remember the ID of the Instant process to signal the renderer process
930 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]7c60f5042013-02-14 03:39:32931 if (chrome::search::ShouldAssignURLToInstantRenderer(
932 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52933 InstantService* instant_service =
934 InstantServiceFactory::GetForProfile(profile);
935 if (instant_service)
936 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
937 }
938
[email protected]970c63e2013-03-07 00:25:30939 // We only expect there to be one signin process as we use process-per-site
940 // for signin URLs. The signin process will be cleared from SigninManager
941 // when the renderer is destroyed.
942 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
943 SigninManager* signin_manager =
944 SigninManagerFactory::GetForProfile(profile);
945 if (signin_manager)
946 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
947 }
948
[email protected]06bdd2b2012-11-30 18:47:13949 ExtensionService* service =
950 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46951 if (!service)
952 return;
953
954 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44955 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59956 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46957 if (!extension)
958 return;
959
[email protected]6bc04fd82011-12-04 02:29:35960 service->process_map()->Insert(extension->id(),
961 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33962 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46963 BrowserThread::PostTask(
964 BrowserThread::IO, FROM_HERE,
965 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59966 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46967 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35968 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33969 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46970}
971
972void ChromeContentBrowserClient::SiteInstanceDeleting(
973 SiteInstance* site_instance) {
974 if (!site_instance->HasProcess())
975 return;
976
977 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02978 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13979 ExtensionService* service =
980 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46981 if (!service)
982 return;
983
984 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44985 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59986 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46987 if (!extension)
988 return;
989
[email protected]6bc04fd82011-12-04 02:29:35990 service->process_map()->Remove(extension->id(),
991 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33992 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46993 BrowserThread::PostTask(
994 BrowserThread::IO, FROM_HERE,
995 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59996 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46997 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35998 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33999 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461000}
1001
[email protected]f05763972012-06-06 18:17:261002bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141003 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081004 const GURL& current_url,
1005 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261006 if (current_url.is_empty()) {
1007 // Always choose a new process when navigating to extension URLs. The
1008 // process grouping logic will combine all of a given extension's pages
1009 // into the same process.
[email protected]885c0e92012-11-13 20:27:421010 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261011 return true;
[email protected]e3daf3c2011-10-05 21:17:081012
[email protected]f05763972012-06-06 18:17:261013 return false;
1014 }
1015
1016 // Also, we must switch if one is an extension and the other is not the exact
1017 // same extension.
[email protected]885c0e92012-11-13 20:27:421018 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1019 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261020 if (current_url.GetOrigin() != new_url.GetOrigin())
1021 return true;
1022 }
1023
[email protected]e9841fbd2013-02-22 23:12:141024 // The checks below only matter if we can retrieve which extensions are
1025 // installed.
1026 Profile* profile =
1027 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1028 ExtensionService* service =
1029 extensions::ExtensionSystem::Get(profile)->extension_service();
1030 if (!service)
1031 return false;
1032
1033 // We must swap if the URL is for an extension and we are not using an
1034 // extension process.
1035 const Extension* new_extension =
1036 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1037 // Ignore all hosted apps except the Chrome Web Store, since they do not
1038 // require their own BrowsingInstance (e.g., postMessage is ok).
1039 if (new_extension &&
1040 new_extension->is_hosted_app() &&
1041 new_extension->id() != extension_misc::kWebStoreAppId)
1042 new_extension = NULL;
1043 if (new_extension &&
1044 site_instance->HasProcess() &&
1045 !service->process_map()->Contains(new_extension->id(),
1046 site_instance->GetProcess()->GetID()))
1047 return true;
1048
[email protected]f05763972012-06-06 18:17:261049 return false;
[email protected]e3daf3c2011-10-05 21:17:081050}
1051
[email protected]395045c2012-05-22 15:04:381052bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1053 content::ResourceContext* resource_context, const GURL& current_url,
1054 const GURL& new_url) {
1055 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1056 return extensions::CrossesExtensionProcessBoundary(
1057 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171058 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381059}
1060
[email protected]763ec4ca2011-04-29 15:48:121061std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1062 const std::string& alias_name) {
1063 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1064}
1065
[email protected]b80f68432011-05-02 17:22:301066void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1067 CommandLine* command_line, int child_process_id) {
1068#if defined(USE_LINUX_BREAKPAD)
1069 if (IsCrashReporterEnabled()) {
1070 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1071 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1072 }
1073#elif defined(OS_MACOSX)
1074 if (IsCrashReporterEnabled()) {
1075 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1076 child_process_logging::GetClientId());
1077 }
1078#endif // OS_MACOSX
1079
[email protected]f1933792011-06-14 00:49:341080 if (logging::DialogsAreSuppressed())
1081 command_line->AppendSwitch(switches::kNoErrorDialogs);
1082
[email protected]b80f68432011-05-02 17:22:301083 std::string process_type =
1084 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171085 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:521086 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451087 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301088 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1089 if (!user_data_dir.empty())
1090 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1091#if defined(OS_CHROMEOS)
1092 const std::string& login_profile =
1093 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1094 if (!login_profile.empty())
1095 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1096#endif
1097
[email protected]f3b1a082011-11-18 00:34:301098 content::RenderProcessHost* process =
1099 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371100 if (process) {
1101 Profile* profile = Profile::FromBrowserContext(
1102 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131103 ExtensionService* extension_service =
1104 extensions::ExtensionSystem::Get(profile)->extension_service();
1105 if (extension_service) {
1106 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001107 if (process_map && process_map->Contains(process->GetID()))
1108 command_line->AppendSwitch(switches::kExtensionProcess);
1109 }
[email protected]b80f68432011-05-02 17:22:301110
[email protected]a8d851f82011-12-21 00:32:371111 PrefService* prefs = profile->GetPrefs();
1112 // Currently this pref is only registered if applied via a policy.
1113 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1114 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1115 // Turn this policy into a command line switch.
1116 command_line->AppendSwitch(switches::kDisable3DAPIs);
1117 }
[email protected]718eab62011-10-05 21:16:521118
[email protected]a8d851f82011-12-21 00:32:371119 // Disable client-side phishing detection in the renderer if it is
1120 // disabled in the Profile preferences or the browser process.
1121 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1122 !g_browser_process->safe_browsing_detection_service()) {
1123 command_line->AppendSwitch(
1124 switches::kDisableClientSidePhishingDetection);
1125 }
[email protected]0045b0f42012-07-26 11:52:081126
1127 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211128 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521129
1130 InstantService* instant_service =
1131 InstantServiceFactory::GetForProfile(profile);
1132 if (instant_service &&
1133 instant_service->IsInstantProcess(process->GetID()))
1134 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301135
1136 SigninManager* signin_manager =
1137 SigninManagerFactory::GetForProfile(profile);
1138 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1139 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]47c7ec82012-01-18 03:29:211140 }
[email protected]4287a3d2011-06-13 23:56:511141
[email protected]87552982012-11-02 17:21:401142 if (content::IsThreadedCompositingEnabled())
1143 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1144
[email protected]47c7ec82012-01-18 03:29:211145 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511146 static const char* const kSwitchNames[] = {
1147 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481148 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511149 switches::kAllowScriptingGallery,
1150 switches::kAppsCheckoutURL,
1151 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311152 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511153 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501154 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531155 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111156 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511157 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211158 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511159 switches::kEnableCrxlessWebApps,
1160 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561161 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511162 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511163 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511164 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451165 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481166 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051167 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511168 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511169 switches::kMemoryProfiling,
1170 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371171 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581172 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371173 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511174 switches::kPpapiFlashArgs,
1175 switches::kPpapiFlashInProcess,
1176 switches::kPpapiFlashPath,
1177 switches::kPpapiFlashVersion,
1178 switches::kProfilingAtStart,
1179 switches::kProfilingFile,
1180 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371181 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511182 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291183 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381184 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511185 };
1186
1187 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1188 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171189 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381190 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351191 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381192 switches::kEnableExperimentalExtensionApis,
1193 switches::kWhitelistedExtensionID,
1194 };
1195
1196 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1197 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511198 } else if (process_type == switches::kPluginProcess) {
1199 static const char* const kSwitchNames[] = {
1200 #if defined(OS_CHROMEOS)
1201 switches::kLoginProfile,
1202 #endif
1203 switches::kMemoryProfiling,
1204 switches::kSilentDumpOnDCHECK,
1205 switches::kUserDataDir,
1206 };
1207
1208 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1209 arraysize(kSwitchNames));
1210 } else if (process_type == switches::kZygoteProcess) {
1211 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511212 switches::kUserDataDir, // Make logs go to the right file.
1213 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501214 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511215 switches::kPpapiFlashInProcess,
1216 switches::kPpapiFlashPath,
1217 switches::kPpapiFlashVersion,
1218 };
1219
1220 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1221 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111222 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001223 base::FilePath user_data_dir =
1224 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1225 if (!user_data_dir.empty())
1226 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111227 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1228 // because GPU is expected to be unreliable.
1229 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1230 !command_line->HasSwitch(switches::kDisableBreakpad))
1231 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301232 }
[email protected]6f08af82011-09-15 01:19:031233
1234 // The command line switch kEnableBenchmarking needs to be specified along
1235 // with the kEnableStatsTable switch to ensure that the stats table global
1236 // is initialized correctly.
1237 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1238 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301239}
1240
1241std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431242 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1243 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301244 return g_browser_process->GetApplicationLocale();
1245}
1246
[email protected]597a867b2011-11-18 18:31:201247std::string ChromeContentBrowserClient::GetAcceptLangs(
1248 content::BrowserContext* context) {
1249 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371250 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081251}
1252
[email protected]9ec0f452012-05-31 15:58:531253gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221254 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531255 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081256}
1257
[email protected]a2176792011-05-08 19:30:491258bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091259 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191260 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201261 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201263 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051264 return io_data->GetCookieSettings()->
1265 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491266}
1267
[email protected]ed24fad2011-05-10 22:44:011268bool ChromeContentBrowserClient::AllowGetCookie(
1269 const GURL& url,
1270 const GURL& first_party,
1271 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201272 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011273 int render_process_id,
1274 int render_view_id) {
1275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201276 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051277 bool allow = io_data->GetCookieSettings()->
1278 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011279
[email protected]8093a542011-05-13 07:29:321280 BrowserThread::PostTask(
1281 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031282 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431283 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011284 return allow;
1285}
1286
1287bool ChromeContentBrowserClient::AllowSetCookie(
1288 const GURL& url,
1289 const GURL& first_party,
1290 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201291 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011292 int render_process_id,
1293 int render_view_id,
1294 net::CookieOptions* options) {
1295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201296 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051297 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1298 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1299
[email protected]8093a542011-05-13 07:29:321300 BrowserThread::PostTask(
1301 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031302 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431303 render_view_id, url, first_party, cookie_line, *options,
1304 !allow));
[email protected]ed24fad2011-05-10 22:44:011305 return allow;
1306}
1307
[email protected]d5a19162011-06-30 18:51:541308bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201309 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201311 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431312 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1313 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261314
[email protected]bf510ed2012-06-05 08:31:431315 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1316 // Could we even support per-origin settings?
1317 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541318}
1319
[email protected]5c5a88e2011-11-12 00:45:351320bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351321 const GURL& url,
1322 const string16& name,
1323 const string16& display_name,
1324 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201325 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481326 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201328 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351329 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1330 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1331
[email protected]62151052012-02-01 18:40:481332 // Record access to database for potential display in UI.
1333 std::vector<std::pair<int, int> >::const_iterator i;
1334 for (i = render_views.begin(); i != render_views.end(); ++i) {
1335 BrowserThread::PostTask(
1336 BrowserThread::UI, FROM_HERE,
1337 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1338 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351339 }
1340
1341 return allow;
1342}
1343
1344bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351345 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201346 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481347 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201349 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351350 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1351 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1352
[email protected]62151052012-02-01 18:40:481353 // Record access to file system for potential display in UI.
1354 std::vector<std::pair<int, int> >::const_iterator i;
1355 for (i = render_views.begin(); i != render_views.end(); ++i) {
1356 BrowserThread::PostTask(
1357 BrowserThread::UI, FROM_HERE,
1358 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1359 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351360 }
1361
1362 return allow;
1363}
1364
[email protected]7c5ff9a2012-03-02 07:42:491365bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1366 const GURL& url,
1367 const string16& name,
1368 content::ResourceContext* context,
1369 const std::vector<std::pair<int, int> >& render_views) {
1370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1371 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1372 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1373 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1374
1375 // Record access to IndexedDB for potential display in UI.
1376 std::vector<std::pair<int, int> >::const_iterator i;
1377 for (i = render_views.begin(); i != render_views.end(); ++i) {
1378 BrowserThread::PostTask(
1379 BrowserThread::UI, FROM_HERE,
1380 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1381 i->first, i->second, url, name, !allow));
1382 }
1383
1384 return allow;
1385}
1386
[email protected]6133f922011-07-01 21:34:341387net::URLRequestContext*
1388ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201389 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421391 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201392 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341393 return io_data->extensions_request_context();
1394 }
1395
1396 return NULL;
1397}
1398
[email protected]317f96c92011-05-31 06:53:411399QuotaPermissionContext*
1400ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1401 return new ChromeQuotaPermissionContext();
1402}
1403
[email protected]848dd042011-06-04 18:24:031404void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171405 int render_process_id,
1406 int render_view_id,
1407 int cert_error,
1408 const net::SSLInfo& ssl_info,
1409 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021410 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031411 bool overridable,
[email protected]d9be47702012-05-16 03:41:221412 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171413 const base::Callback<void(bool)>& callback,
1414 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021415 if (resource_type != ResourceType::MAIN_FRAME) {
1416 // A sub-resource has a certificate error. The user doesn't really
1417 // have a context for making the right decision, so block the
1418 // request hard, without an info bar to allow showing the insecure
1419 // content.
1420 *cancel_request = true;
1421 return;
1422 }
1423
[email protected]f9034cf2011-07-21 12:43:411424 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131425 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171426 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411427 if (!tab) {
1428 NOTREACHED();
1429 return;
1430 }
1431 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501432 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301433 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011434 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1435 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411436 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171437 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411438 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171439 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411440 return;
1441 }
1442 }
1443
[email protected]1e87df32012-09-12 04:53:191444#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231445 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1446 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1447 if (captive_portal_tab_helper)
1448 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191449#endif
1450
[email protected]f9034cf2011-07-21 12:43:411451 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221452 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1453 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031454}
1455
[email protected]c99c442e2011-08-24 11:37:301456void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451457 int render_process_id,
1458 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401459 const net::HttpNetworkSession* network_session,
1460 net::SSLCertRequestInfo* cert_request_info,
1461 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131462 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451463 render_process_id, render_view_id);
1464 if (!tab) {
1465 NOTREACHED();
1466 return;
1467 }
1468
[email protected]6786bf402011-12-03 15:19:451469 GURL requesting_url("https://" + cert_request_info->host_and_port);
1470 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1471 << cert_request_info->host_and_port;
1472
[email protected]627e0512011-12-21 22:55:301473 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451474 scoped_ptr<Value> filter(
1475 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1476 requesting_url,
1477 requesting_url,
1478 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1479 std::string(), NULL));
1480
1481 if (filter.get()) {
1482 // Try to automatically select a client certificate.
1483 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1484 DictionaryValue* filter_dict =
1485 static_cast<DictionaryValue*>(filter.get());
1486
1487 const std::vector<scoped_refptr<net::X509Certificate> >&
1488 all_client_certs = cert_request_info->client_certs;
1489 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1490 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1491 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401492 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451493 return;
1494 }
1495 }
1496 } else {
1497 NOTREACHED();
1498 }
1499 }
1500
[email protected]11feec322012-09-18 03:58:521501 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1502 if (!ssl_tab_helper) {
1503 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451504 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141505 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401506 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451507 return;
1508 }
[email protected]11feec322012-09-18 03:58:521509 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401510 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451511}
1512
[email protected]3b455502012-12-11 18:22:581513void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451514 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581515 net::CertificateMimeType cert_type,
1516 const void* cert_data,
1517 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451518 int render_process_id,
1519 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581520 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1521 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451522}
1523
[email protected]dc73a7b2012-03-25 15:27:181524content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561525 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181526}
1527
[email protected]941623e2011-06-07 23:06:041528void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1529 const GURL& source_origin,
1530 int callback_context,
1531 int render_process_id,
1532 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111533#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1535 WebContents* contents =
1536 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1537 if (!contents) {
[email protected]941623e2011-06-07 23:06:041538 NOTREACHED();
1539 return;
1540 }
1541
[email protected]d0d9c3ee2012-06-19 03:07:021542 // Skip showing the infobar if the request comes from an extension, and that
1543 // extension has the 'notify' permission. (If the extension does not have the
1544 // permission, the user will still be prompted.)
1545 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131546 ExtensionService* service =
1547 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021548 const Extension* extension = !service ? NULL :
1549 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1550 source_origin));
[email protected]eb4832a2012-12-08 01:57:521551 RenderViewHost* rvh =
1552 RenderViewHost::FromID(render_process_id, render_view_id);
1553 if (IsExtensionWithPermissionOrSuggestInConsole(
1554 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021555 if (rvh)
1556 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1557 return;
1558 }
1559
1560 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371561 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021562 notifications->RequestPermission(source_origin, render_process_id,
1563 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111564#else
1565 NOTIMPLEMENTED();
1566#endif
[email protected]941623e2011-06-07 23:06:041567}
1568
1569WebKit::WebNotificationPresenter::Permission
1570 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021571 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201572 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021573 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111574#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201576 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021577 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1578 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061579 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041580 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041581
1582 // Fall back to the regular notification preferences, which works on an
1583 // origin basis.
1584 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371585 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041586 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111587#else
1588 return WebKit::WebNotificationPresenter::PermissionAllowed;
1589#endif
[email protected]941623e2011-06-07 23:06:041590}
1591
1592void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171593 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041594 int render_process_id,
1595 int render_view_id,
1596 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111597#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041598 RenderViewHost* rvh = RenderViewHost::FromID(
1599 render_process_id, render_view_id);
1600 if (!rvh) {
1601 NOTREACHED();
1602 return;
1603 }
1604
[email protected]9f76c1e2012-03-05 15:15:581605 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301606 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041607 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371608 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041609 service->ShowDesktopNotification(
1610 params, render_process_id, render_view_id,
1611 worker ? DesktopNotificationService::WorkerNotification :
1612 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111613#else
1614 NOTIMPLEMENTED();
1615#endif
[email protected]941623e2011-06-07 23:06:041616}
1617
1618void ChromeContentBrowserClient::CancelDesktopNotification(
1619 int render_process_id,
1620 int render_view_id,
1621 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111622#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041623 RenderViewHost* rvh = RenderViewHost::FromID(
1624 render_process_id, render_view_id);
1625 if (!rvh) {
1626 NOTREACHED();
1627 return;
1628 }
1629
[email protected]9f76c1e2012-03-05 15:15:581630 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301631 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041632 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371633 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041634 service->CancelDesktopNotification(
1635 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111636#else
1637 NOTIMPLEMENTED();
1638#endif
[email protected]941623e2011-06-07 23:06:041639}
1640
[email protected]9f3fba52011-06-08 20:37:191641bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351642 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021643 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191644 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201645 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011646 int render_process_id,
1647 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011649
1650 *no_javascript_access = false;
1651
[email protected]9f3fba52011-06-08 20:37:191652 // If the opener is trying to create a background window but doesn't have
1653 // the appropriate permission, fail the attempt.
1654 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201655 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531656 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1657
[email protected]03b6d552012-03-29 04:03:011658 if (!map->SecurityOriginHasAPIPermission(
1659 source_origin,
1660 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061661 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011662 return false;
1663 }
1664
[email protected]7b54ca02012-03-02 18:06:531665 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1666 // return a recently installed Extension even if this CanCreateWindow call
1667 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011668 // because the permission check above would have caused an early return
1669 // already. We must use the full URL to find hosted apps, though, and not
1670 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531671 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351672 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291673 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011674 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191675 }
1676 return true;
1677}
1678
1679std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201680 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1682 // Check if it's an extension-created worker, in which case we want to use
1683 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201684 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191685 const Extension* extension =
1686 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1687 return extension ? extension->name() : std::string();
1688}
1689
[email protected]99907362012-01-11 05:41:401690void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1691 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171692}
1693
[email protected]c52b2892012-03-07 11:01:021694content::SpeechRecognitionManagerDelegate*
1695 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321696#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021697 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321698#else
1699 return NULL;
1700#endif
[email protected]66cfec62012-02-24 17:57:511701}
1702
[email protected]ae6e9912011-07-27 01:18:281703net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1704 return g_browser_process->net_log();
1705}
1706
[email protected]32538d92011-08-25 00:09:231707AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1708 return new ChromeAccessTokenStore();
1709}
1710
[email protected]dbae6b02011-06-29 23:51:411711bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011712 return true;
[email protected]dbae6b02011-06-29 23:51:411713}
1714
[email protected]64d69de42012-02-06 00:19:541715void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321716 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061717 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581718 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061719 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061720
[email protected]f3986f82012-01-03 20:00:061721 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541722 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061723 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541724 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061725 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541726 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061727 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541728 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061729 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541730 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061731 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541732 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031733 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1734 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061735
[email protected]64d69de42012-02-06 00:19:541736 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401737 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541738 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401739 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541740 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401741 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541742 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401743 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061744
[email protected]ddf72142012-05-22 04:52:401745 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061746
[email protected]64d69de42012-02-06 00:19:541747 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401748 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541749 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061750 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541751 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061752 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1753 const DictionaryValue* inspector_settings =
1754 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1755 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181756 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1757 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061758 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181759 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541760 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181761 std::make_pair(iter.key(), value));
1762 }
[email protected]f3986f82012-01-03 20:00:061763 }
1764 }
[email protected]64d69de42012-02-06 00:19:541765 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061766
[email protected]ddf72142012-05-22 04:52:401767 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541768 web_prefs->javascript_enabled = false;
1769 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1770 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401771 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541772 web_prefs->plugins_enabled = false;
1773 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1774 web_prefs->java_enabled = false;
1775 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401776 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061777
[email protected]64d69de42012-02-06 00:19:541778 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1779 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061780
[email protected]64d69de42012-02-06 00:19:541781 web_prefs->memory_info_enabled =
1782 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1783 web_prefs->allow_displaying_insecure_content =
1784 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1785 web_prefs->allow_running_insecure_content =
1786 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321787#if defined(OS_ANDROID)
1788 web_prefs->font_scale_factor =
1789 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1790 web_prefs->force_enable_zoom =
1791 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451792#if defined(GOOGLE_TV)
1793 web_prefs->user_gesture_required_for_media_playback = false;
1794#endif
[email protected]d3b935f2012-10-19 23:14:321795#endif
[email protected]9d06d88d2012-02-23 22:37:081796 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061797
[email protected]64d69de42012-02-06 00:19:541798 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151799 UserStyleSheetWatcher* user_style_sheet_watcher =
1800 UserStyleSheetWatcherFactory::GetForProfile(profile);
1801 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541802 web_prefs->user_style_sheet_enabled = true;
1803 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151804 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541805 } else {
1806 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061807 }
1808
[email protected]b7e44ff2012-02-16 03:37:341809 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101810#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031811 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101812 // Mac so it uses NSSpellChecker in the background.
1813 false;
1814#else
[email protected]61806872012-12-12 04:15:361815 true;
[email protected]37b928e2012-05-30 09:01:101816#endif
[email protected]b7e44ff2012-02-16 03:37:341817 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521818 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571819
[email protected]64d69de42012-02-06 00:19:541820 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061821 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541822 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061823 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541824 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061825 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1826
1827 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541828 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061829 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541830 web_prefs->default_encoding);
1831 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401832 prefs->ClearPref(prefs::kDefaultCharset);
1833 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061834 }
[email protected]64d69de42012-02-06 00:19:541835 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061836
[email protected]88ecf66d2012-12-11 22:53:471837 if (content::IsForceCompositingModeEnabled())
1838 web_prefs->force_compositing_mode = true;
1839
[email protected]299d7f12012-05-23 05:31:151840 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1841 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131842 ExtensionService* service =
1843 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061844 if (service) {
[email protected]1bc28312012-11-08 08:31:531845 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1846 const Extension* extension = service->extensions()->GetByID(url.host());
1847 // Ensure that we are only granting extension preferences to URLs with
1848 // the correct scheme. Without this check, chrome-guest:// schemes used by
1849 // webview tags as well as hosts that happen to match the id of an
1850 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421851 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531852 extension_webkit_preferences::SetPreferences(
1853 extension, view_type, web_prefs);
1854 }
[email protected]f3986f82012-01-03 20:00:061855 }
1856
[email protected]299d7f12012-05-23 05:31:151857 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541858 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151859 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061860 // Disable all kinds of acceleration for background pages.
1861 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541862 web_prefs->force_compositing_mode = false;
1863 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061864 }
[email protected]2e21fe292012-03-02 22:52:321865
1866#if defined(FILE_MANAGER_EXTENSION)
1867 // Override the default of suppressing HW compositing for WebUI pages for the
1868 // file manager, which is implemented using WebUI but wants HW acceleration
1869 // for video decode & render.
1870 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1871 web_prefs->accelerated_compositing_enabled = true;
1872 web_prefs->accelerated_2d_canvas_enabled = true;
1873 }
1874#endif
[email protected]181a95ee2011-07-12 19:26:361875}
1876
1877void ChromeContentBrowserClient::UpdateInspectorSetting(
1878 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061879 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581880 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061881 DictionaryPrefUpdate update(
1882 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1883 prefs::kWebKitInspectorSettings);
1884 DictionaryValue* inspector_settings = update.Get();
1885 inspector_settings->SetWithoutPathExpansion(key,
1886 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361887}
1888
1889void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061890 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581891 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061892 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1893 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361894}
1895
[email protected]b8148ac2011-07-13 22:03:251896void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1897 BrowserURLHandler* handler) {
1898 // Add the default URL handlers.
1899 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1900 BrowserURLHandler::null_handler());
1901 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1902 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1903
[email protected]b3adbd02011-11-30 22:23:271904 // about: handler. Must come before chrome: handler, since it will
1905 // rewrite about: urls to chrome: URLs and then expect chrome: to
1906 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251907 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1908 BrowserURLHandler::null_handler());
1909 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241910 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251911}
1912
1913void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371914 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581915 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471916 BrowsingDataRemover* remover =
1917 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551918 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1919 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251920 // BrowsingDataRemover takes care of deleting itself when done.
1921}
1922
1923void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371924 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581925 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471926 BrowsingDataRemover* remover =
1927 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231928 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551929 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251930 // BrowsingDataRemover takes care of deleting itself when done.
1931}
1932
[email protected]650b2d52013-02-10 03:41:451933base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321934 return download_util::GetDefaultDownloadDirectory();
1935}
1936
[email protected]c9b6eb62011-10-18 20:49:391937std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1938 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1939}
1940
[email protected]b7631cc2012-09-15 05:08:381941void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1942 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541943#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381944 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1945 scoped_ptr<ppapi::host::HostFactory>(
1946 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541947#endif
[email protected]b7631cc2012-09-15 05:08:381948}
1949
[email protected]0c7193742012-11-07 19:05:031950content::BrowserPpapiHost*
1951 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1952 int plugin_process_id) {
1953 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1954 while (!iter.Done()) {
1955 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1956 if (host->process() &&
1957 host->process()->GetData().id == plugin_process_id) {
1958 // Found the plugin.
1959 return host->browser_ppapi_host();
1960 }
1961 ++iter;
1962 }
1963 return NULL;
1964}
1965
[email protected]38cd8f7f2012-06-15 22:06:071966bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581967 content::BrowserContext* browser_context,
1968 const GURL& url,
1969 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291970 if (!url.is_valid())
1971 return false;
1972
1973 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421974 if (url.SchemeIs(extensions::kExtensionScheme) &&
1975 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291976 return true;
[email protected]885c0e92012-11-13 20:27:421977 }
[email protected]a658d452012-03-02 12:45:291978
[email protected]9a5940d2012-04-27 19:16:231979 Profile* profile = Profile::FromBrowserContext(browser_context);
1980 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191981 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131982 extensions::ExtensionSystem::Get(profile)->extension_service();
1983 if (extension_service) {
1984 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231985 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1986 }
1987
[email protected]f237c0f2012-03-10 07:49:101988 // Need to check this now and not on construction because otherwise it won't
1989 // work with browser_tests.
1990 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1991 std::string allowed_list =
1992 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231993 if (allowed_list == "*") {
1994 // The wildcard allows socket API only for packaged and platform apps.
1995 return extension &&
[email protected]1d5e58b2013-01-31 08:41:401996 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
1997 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:231998 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:391999 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102000 while (t.GetNext()) {
2001 if (t.token() == host)
2002 return true;
2003 }
2004 }
2005
[email protected]a658d452012-03-02 12:45:292006 if (!extension)
2007 return false;
2008
[email protected]157cc902012-11-02 06:31:582009 extensions::SocketPermission::CheckParam extension_params(
2010 params.type, params.host, params.port);
2011 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2012 &extension_params))
[email protected]a658d452012-03-02 12:45:292013 return true;
2014
2015 return false;
[email protected]e461da2f2012-02-16 19:06:402016}
2017
[email protected]650b2d52013-02-10 03:41:452018base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2019 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142020 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2021 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2022}
2023
[email protected]a28e3302013-02-03 03:50:432024ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2025 WebContents* web_contents) {
2026 return new ChromeSelectFilePolicy(web_contents);
2027}
2028
[email protected]e60c0232011-11-11 19:56:352029#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182030void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2031 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382032 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082033 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392034#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452035 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392036 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2037 DCHECK(!data_path.empty());
2038
2039 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452040 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392041 base::PlatformFile f =
2042 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2043 DCHECK(f != base::kInvalidPlatformFileValue);
2044 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2045 FileDescriptor(f, true)));
2046
[email protected]650b2d52013-02-10 03:41:452047 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392048 data_path.AppendASCII("chrome_100_percent.pak");
2049 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2050 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372051 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392052 FileDescriptor(f, true)));
2053
2054 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452055 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392056 GetLocaleFilePath(locale, false);
2057 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2058 DCHECK(f != base::kInvalidPlatformFileValue);
2059 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2060 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382061
[email protected]650b2d52013-02-10 03:41:452062 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372063 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2064 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2065 DCHECK(f != base::kInvalidPlatformFileValue);
2066 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2067 FileDescriptor(f, true)));
2068
[email protected]40da3e0c2012-10-24 22:03:382069#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432070 if (IsCrashReporterEnabled()) {
2071 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2072 if (f == base::kInvalidPlatformFileValue) {
2073 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2074 "be disabled for this process.";
2075 } else {
2076 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2077 FileDescriptor(f, true)));
2078 }
[email protected]40da3e0c2012-10-24 22:03:382079 }
2080#endif // defined(USE_LINUX_BREAKPAD)
2081
2082#else
2083 int crash_signal_fd = GetCrashSignalFD(command_line);
2084 if (crash_signal_fd >= 0) {
2085 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2086 FileDescriptor(crash_signal_fd,
2087 false)));
2088 }
[email protected]29699c22012-10-03 23:57:392089#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302090}
[email protected]e60c0232011-11-11 19:56:352091#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302092
[email protected]4a65826d2011-08-25 16:04:012093#if defined(OS_WIN)
2094const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2095 return chrome::kBrowserResourcesDll;
2096}
2097#endif
2098
[email protected]37a72af2011-06-13 05:42:012099#if defined(USE_NSS)
2100crypto::CryptoModuleBlockingPasswordDelegate*
2101 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2102 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292103 return chrome::NewCryptoModuleBlockingDialogDelegate(
2104 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012105}
2106#endif
2107
[email protected]e9a32a52012-06-14 23:32:432108void ChromeContentBrowserClient::SetApplicationLocale(
2109 const std::string& locale) {
2110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2111
2112 // This object is guaranteed to outlive all threads so we don't have to
2113 // worry about the lack of refcounting and can just post as Unretained.
2114 //
2115 // The common case is that this function is called early in Chrome startup
2116 // before any threads are created (it will also be called later if the user
2117 // changes the pref). In this case, there will be no threads created and
2118 // posting will fail. When there are no threads, we can just set the string
2119 // without worrying about threadsafety.
2120 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2121 base::Bind(
2122 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2123 base::Unretained(this), locale)))
2124 io_thread_application_locale_ = locale;
2125}
2126
2127void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2128 const std::string& locale) {
2129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2130 io_thread_application_locale_ = locale;
2131}
2132
[email protected]d977f9c2011-03-14 16:10:262133} // namespace chrome