blob: 2d47e310bce5ff52ff9b45a12e84dbd66630acf5 [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]2b33dcd02012-03-18 01:34:1631#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0632#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0433#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3334#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2635#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0836#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2537#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0638#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4939#include "chrome/browser/extensions/message_handler.h"
[email protected]eb4832a2012-12-08 01:57:5240#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2341#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1242#include "chrome/browser/google/google_util.h"
[email protected]c5dec6292013-01-25 04:54:5243#include "chrome/browser/instant/instant_service.h"
44#include "chrome/browser/instant/instant_service_factory.h"
[email protected]11158e2d2013-02-01 02:31:5645#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]0c7193742012-11-07 19:05:0346#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2847#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0448#include "chrome/browser/notifications/desktop_notification_service.h"
49#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4250#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5651#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]c753f142013-02-10 13:14:0452#include "chrome/browser/prefs/pref_registry_syncable.h"
[email protected]f3986f82012-01-03 20:00:0653#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4154#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5055#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0756#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/printing/printing_message_filter.h"
59#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3260#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0661#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3363#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3864#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0266#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4667#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5868#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0369#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5270#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4571#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5472#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4373#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]7c60f5042013-02-14 03:39:3274#include "chrome/browser/ui/search/search.h"
[email protected]b5d73422012-06-02 23:46:4475#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5076#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0677#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1578#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5379#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3080#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0181#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1482#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3083#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0484#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3885#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4486#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5887#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3488#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1289#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3890#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0991#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4392#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3093#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3894#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3195#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:0396#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:5997#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:3698#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:3099#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33100#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05101#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33102#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19103#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10104#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43105#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18106#include "content/public/common/content_descriptors.h"
[email protected]885c0e92012-11-13 20:27:42107#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39108#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23109#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53110#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58111#include "net/base/mime_util.h"
[email protected]7a593db2012-02-13 21:19:40112#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34113#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06114#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38115#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39116#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08117#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36118#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04119#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26120
[email protected]b48c9182011-10-26 18:03:30121#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38122#include "chrome/browser/chrome_browser_main_win.h"
123#elif defined(OS_MACOSX)
124#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56125#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30126#elif defined(OS_CHROMEOS)
127#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49128#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26129#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30130#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09131#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38132#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09133#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39134#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30135#elif defined(OS_POSIX)
136#include "chrome/browser/chrome_browser_main_posix.h"
137#endif
138
[email protected]6653c192012-04-10 22:52:44139#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30140#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12141#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43142#endif
[email protected]b80f68432011-05-02 17:22:30143
[email protected]1e87df32012-09-12 04:53:19144#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
145#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
146#endif
147
[email protected]29699c22012-10-03 23:57:39148#if defined(OS_ANDROID)
149#include "ui/base/ui_base_paths.h"
150#endif
151
[email protected]37a72af2011-06-13 05:42:01152#if defined(USE_NSS)
153#include "chrome/browser/ui/crypto_module_password_dialog.h"
154#endif
155
[email protected]c7abd422012-09-25 00:20:08156using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47157using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03158using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39159using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31160using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59161using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08162using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00163using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11164using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33165using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13166using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06167using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34168using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40169using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25170using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39171
[email protected]c5dbef02011-05-13 05:06:09172namespace {
173
[email protected]e461da2f2012-02-16 19:06:40174const char* kPredefinedAllowedSocketOrigins[] = {
175 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18176 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45177 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
178 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
179 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
180 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35181 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54182 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
183 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
184 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
185 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
186 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
187 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38188 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58189 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
190 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40191};
192
[email protected]f8f93eb2012-09-25 03:06:24193// Returns a copy of the given url with its host set to given host and path set
194// to given path. Other parts of the url will be the same.
195GURL ReplaceURLHostAndPath(const GURL& url,
196 const std::string& host,
197 const std::string& path) {
198 url_canon::Replacements<char> replacements;
199 replacements.SetHost(host.c_str(),
200 url_parse::Component(0, host.length()));
201 replacements.SetPath(path.c_str(),
202 url_parse::Component(0, path.length()));
203 return url.ReplaceComponents(replacements);
204}
205
206// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
207GURL AddUberHost(const GURL& url) {
208 const std::string uber_host = chrome::kChromeUIUberHost;
209 const std::string new_path = url.host() + url.path();
210
211 return ReplaceURLHostAndPath(url, uber_host, new_path);
212}
213
[email protected]045bf7c2012-09-28 20:27:36214// If url->host() is "chrome" and url->path() has characters other than the
215// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
216// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24217bool RemoveUberHost(GURL* url) {
218 if (url->host() != chrome::kChromeUIUberHost)
219 return false;
220
[email protected]045bf7c2012-09-28 20:27:36221 if (url->path().empty() || url->path() == "/")
222 return false;
223
[email protected]f8f93eb2012-09-25 03:06:24224 const std::string old_path = url->path();
225
226 const std::string::size_type separator = old_path.find('/', 1);
227 std::string new_host;
228 std::string new_path;
229 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36230 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24231 } else {
232 new_host = old_path.substr(1, separator - 1);
233 new_path = old_path.substr(separator);
234 }
235
236 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
237
238 return true;
239}
240
[email protected]b8148ac2011-07-13 22:03:25241// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42242bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24243 // Do not handle special URLs such as "about:foo"
244 if (!url->host().empty()) {
245 const GURL chrome_url = AddUberHost(*url);
246
247 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
248 // be called.
249 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
250 browser_context, chrome_url))
251 return true;
252 }
253
[email protected]863f70a2012-01-27 02:05:50254 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
255 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25256 return false;
257
[email protected]fe69558d2012-03-12 11:34:49258#if defined(OS_CHROMEOS)
259 // Special case : in ChromeOS in Guest mode bookmarks and history are
260 // disabled for security reasons. New tab page explains the reasons, so
261 // we redirect user to new tab page.
262 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
263 if (url->SchemeIs(chrome::kChromeUIScheme) &&
264 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
265 url->DomainIs(chrome::kChromeUIHistoryHost))) {
266 // Rewrite with new tab URL
267 *url = GURL(chrome::kChromeUINewTabURL);
268 }
269 }
270#endif
271
[email protected]b8148ac2011-07-13 22:03:25272 // Special case the new tab page. In older versions of Chrome, the new tab
273 // page was hosted at chrome-internal:<blah>. This might be in people's saved
274 // sessions or bookmarks, so we say any URL with that scheme triggers the new
275 // tab page.
276 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
277 // Rewrite it with the proper new tab URL.
278 *url = GURL(chrome::kChromeUINewTabURL);
279 }
280
281 return true;
282}
283
[email protected]f8f93eb2012-09-25 03:06:24284// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
285// "chrome://foo/".
286bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
287 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
288 return false;
289
290 return RemoveUberHost(url);
291}
292
[email protected]8d3132f62011-10-12 07:13:42293// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
294// below. Extension, and isolated apps require different privileges to be
295// granted to their RenderProcessHosts. This classification allows us to make
296// sure URLs are served by hosts with the right set of privileges.
297enum RenderProcessHostPrivilege {
298 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45299 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42300 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45301 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42302};
303
304RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
305 const GURL& url,
306 ExtensionService* service) {
307 // Default to a normal renderer cause it is lower privileged. This should only
308 // occur if the URL on a site instance is either malformed, or uninitialized.
309 // If it is malformed, then there is no need for better privileges anyways.
310 // If it is uninitialized, but eventually settles on being an a scheme other
311 // than normal webrenderer, the navigation logic will correct us out of band
312 // anyways.
313 if (!url.is_valid())
314 return PRIV_NORMAL;
315
[email protected]885c0e92012-11-13 20:27:42316 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44317 const Extension* extension =
318 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45319 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42320 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45321 if (extension && extension->is_hosted_app())
322 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42323
324 return PRIV_EXTENSION;
325 }
326
327 return PRIV_NORMAL;
328}
329
330RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30331 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46332 extensions::ProcessMap* process_map,
333 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46334 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30335 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46336 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21337 return PRIV_NORMAL;
338
[email protected]6f371442011-11-09 06:45:46339 for (std::set<std::string>::iterator iter = extension_ids.begin();
340 iter != extension_ids.end(); ++iter) {
341 const Extension* extension = service->GetExtensionById(*iter, false);
342 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42343 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45344 if (extension && extension->is_hosted_app())
345 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42346 }
347
[email protected]676f6ab2011-10-19 20:23:21348 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42349}
350
[email protected]6786bf402011-12-03 15:19:45351bool CertMatchesFilter(const net::X509Certificate& cert,
352 const base::DictionaryValue& filter) {
353 // TODO(markusheintz): This is the minimal required filter implementation.
354 // Implement a better matcher.
355
356 // An empty filter matches any client certificate since no requirements are
357 // specified at all.
358 if (filter.empty())
359 return true;
360
361 std::string common_name;
362 if (filter.GetString("ISSUER.CN", &common_name) &&
363 (cert.issuer().common_name == common_name)) {
364 return true;
365 }
366 return false;
367}
368
[email protected]f3986f82012-01-03 20:00:06369// Fills |map| with the per-script font prefs under path |map_name|.
370void FillFontFamilyMap(const PrefService* prefs,
371 const char* map_name,
372 WebPreferences::ScriptFontFamilyMap* map) {
373 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
374 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
375 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
376 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23377 if (!font_family.empty())
378 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06379 }
380}
381
[email protected]a1733df2012-06-22 11:24:18382#if defined(OS_POSIX) && !defined(OS_MACOSX)
383int GetCrashSignalFD(const CommandLine& command_line) {
384 if (command_line.HasSwitch(switches::kExtensionProcess)) {
385 ExtensionCrashHandlerHostLinux* crash_handler =
386 ExtensionCrashHandlerHostLinux::GetInstance();
387 return crash_handler->GetDeathSignalSocket();
388 }
389
390 std::string process_type =
391 command_line.GetSwitchValueASCII(switches::kProcessType);
392
393 if (process_type == switches::kRendererProcess)
394 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
395
396 if (process_type == switches::kPluginProcess)
397 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
398
399 if (process_type == switches::kPpapiPluginProcess)
400 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
401
402 if (process_type == switches::kGpuProcess)
403 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
404
405 return -1;
406}
407#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
408
[email protected]7c60f5042013-02-14 03:39:32409// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52410// facilitates grouping process-per-site. The |url| is transformed, for
411// example, from
412//
413// https://www.google.com/search?espv=1&q=tractors
414//
[email protected]7c60f5042013-02-14 03:39:32415// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52416//
417// chrome-search://www.google.com/search?espv=1&q=tractors
418//
419// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32420//
421// If the input is already an effective URL then that same URL is returned.
422GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
423 CHECK(chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
424 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52425
426 if (url.SchemeIs(chrome::kChromeSearchScheme))
427 return url;
428
429 GURL effective_url(url);
430
431 // Replace the scheme with "chrome-search:".
432 url_canon::Replacements<char> replacements;
433 std::string search_scheme(chrome::kChromeSearchScheme);
434 replacements.SetScheme(search_scheme.data(),
435 url_parse::Component(0, search_scheme.length()));
436 effective_url = effective_url.ReplaceComponents(replacements);
437 return effective_url;
438}
439
[email protected]9dbfff12011-07-01 19:37:07440} // namespace
[email protected]c5dbef02011-05-13 05:06:09441
[email protected]d977f9c2011-03-14 16:10:26442namespace chrome {
443
[email protected]e461da2f2012-02-16 19:06:40444ChromeContentBrowserClient::ChromeContentBrowserClient() {
445 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
446 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40447}
448
449ChromeContentBrowserClient::~ChromeContentBrowserClient() {
450}
451
[email protected]bca18382012-06-25 19:15:23452// static
[email protected]c753f142013-02-10 13:14:04453void ChromeContentBrowserClient::RegisterUserPrefs(
454 PrefRegistrySyncable* registry) {
455 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
456 false,
457 PrefRegistrySyncable::UNSYNCABLE_PREF);
458 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
459 true,
460 PrefRegistrySyncable::UNSYNCABLE_PREF);
461 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
462 false,
463 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23464}
465
[email protected]50462bf02011-11-21 19:13:31466content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
467 const content::MainFunctionParams& parameters) {
468 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30469 // Construct the Main browser parts based on the OS type.
470#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31471 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04472#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31473 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30474#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22475 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26476#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31477 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14478#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09479 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30480#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31481 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04482#else
[email protected]b48c9182011-10-26 18:03:30483 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31484 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30485#endif
486
[email protected]c7480942011-11-08 19:18:27487 // Construct additional browser parts. Stages are called in the order in
488 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22489#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41490 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04491#endif
[email protected]c7480942011-11-08 19:18:27492
493#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41494 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27495#endif
496
[email protected]dc04be7c2012-03-15 23:57:49497#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41498 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49499#endif
500
[email protected]e050ef142012-03-21 01:04:24501#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41502 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24503#endif
504
[email protected]50462bf02011-11-21 19:13:31505 return main_parts;
[email protected]f967b722011-09-07 00:58:04506}
507
[email protected]e94bbcb2012-09-07 05:33:57508std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19509 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57510 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53511 std::string partition_id;
512
513 // The partition ID for webview guest processes is the string value of its
514 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
515 if (site.SchemeIs(chrome::kGuestScheme))
516 partition_id = site.spec();
517
518 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
519 return partition_id;
520}
521
522bool ChromeContentBrowserClient::IsValidStoragePartitionId(
523 content::BrowserContext* browser_context,
524 const std::string& partition_id) {
525 // The default ID is empty and is always valid.
526 if (partition_id.empty())
527 return true;
528
529 return GURL(partition_id).is_valid();
530}
531
532void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
533 content::BrowserContext* browser_context,
534 const GURL& site,
[email protected]14acc642012-11-17 12:20:10535 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53536 std::string* partition_domain,
537 std::string* partition_name,
538 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10539 // Default to the browser-wide storage partition and override based on |site|
540 // below.
541 partition_domain->clear();
542 partition_name->clear();
543 *in_memory = false;
544
[email protected]1bc28312012-11-08 08:31:53545 // For the webview tag, we create special guest processes, which host the
546 // tag content separately from the main application that embeds the tag.
547 // A webview tag can specify both the partition name and whether the storage
548 // for that partition should be persisted. Each tag gets a SiteInstance with
549 // a specially formatted URL, based on the application it is hosted by and
550 // the partition requested by it. The format for that URL is:
551 // chrome-guest://partition_domain/persist?partition_name
552 if (site.SchemeIs(chrome::kGuestScheme)) {
553 // Since guest URLs are only used for packaged apps, there must be an app
554 // id in the URL.
555 CHECK(site.has_host());
556 *partition_domain = site.host();
557 // Since persistence is optional, the path must either be empty or the
558 // literal string.
559 *in_memory = (site.path() != "/persist");
560 // The partition name is user supplied value, which we have encoded when the
561 // URL was created, so it needs to be decoded.
562 *partition_name = net::UnescapeURLComponent(site.query(),
563 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10564 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
565 // If |can_be_default| is false, the caller is stating that the |site|
566 // should be parsed as if it had isolated storage. In particular it is
567 // important to NOT check ExtensionService for the is_storage_isolated()
568 // attribute because this code path is run during Extension uninstall
569 // to do cleanup after the Extension has already been unloaded from the
570 // ExtensionService.
571 bool is_isolated = !can_be_default;
572 if (can_be_default) {
573 const Extension* extension = NULL;
574 Profile* profile = Profile::FromBrowserContext(browser_context);
575 ExtensionService* extension_service =
576 extensions::ExtensionSystem::Get(profile)->extension_service();
577 if (extension_service) {
578 extension = extension_service->extensions()->
579 GetExtensionOrAppByURL(ExtensionURLInfo(site));
580 if (extension && extension->is_storage_isolated()) {
581 is_isolated = true;
582 }
583 }
584 }
[email protected]1bc28312012-11-08 08:31:53585
[email protected]14acc642012-11-17 12:20:10586 if (is_isolated) {
587 CHECK(site.has_host());
588 // For extensions with isolated storage, the the host of the |site| is
589 // the |partition_domain|. The |in_memory| and |partition_name| are only
590 // used in guest schemes so they are cleared here.
591 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53592 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10593 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53594 }
[email protected]d1198fd2012-08-13 22:50:19595 }
596
[email protected]14acc642012-11-17 12:20:10597 // Assert that if |can_be_default| is false, the code above must have found a
598 // non-default partition. If this fails, the caller has a serious logic
599 // error about which StoragePartition they expect to be in and it is not
600 // safe to continue.
601 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44602}
603
[email protected]38b098f2012-03-14 21:11:57604content::WebContentsViewDelegate*
605 ChromeContentBrowserClient::GetWebContentsViewDelegate(
606 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27607 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32608}
609
[email protected]f364d1392011-04-08 21:03:10610void ChromeContentBrowserClient::RenderViewHostCreated(
611 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46612
[email protected]9f76c1e2012-03-05 15:15:58613 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46614 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02615 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46616
617 new ChromeRenderViewHostObserver(render_view_host,
618 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49619 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26620}
621
[email protected]44703cc72013-01-24 04:56:06622void ChromeContentBrowserClient::GuestWebContentsCreated(
623 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
624 Profile* profile = Profile::FromBrowserContext(
625 embedder_web_contents->GetBrowserContext());
626 ExtensionService* service =
627 extensions::ExtensionSystem::Get(profile)->extension_service();
628 if (!service)
629 return;
630 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
631 const Extension* extension = service->extensions()->
632 GetExtensionOrAppByURL(ExtensionURLInfo(url));
633 if (!extension)
634 return;
635 std::vector<ExtensionMsg_Loaded_Params> extensions;
636 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
637 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
638}
639
[email protected]f3b1a082011-11-18 00:34:30640void ChromeContentBrowserClient::RenderProcessHostCreated(
641 content::RenderProcessHost* host) {
642 int id = host->GetID();
643 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41644 net::URLRequestContextGetter* context =
645 profile->GetRequestContextForRenderProcess(id);
646
[email protected]f3b1a082011-11-18 00:34:30647 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41648 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55649#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30650 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55651#endif
[email protected]658677f2012-06-09 06:04:02652#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08653 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03654#endif
[email protected]f3b1a082011-11-18 00:34:30655 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02656 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30657 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56658#if defined(OS_MACOSX)
659 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
660#endif
[email protected]43535512013-02-20 20:41:41661 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
662 id, profile, context));
[email protected]2736c032012-05-11 18:06:07663 host->GetChannel()->AddFilter(
664 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38665
[email protected]2ccf45c2011-08-19 23:35:50666 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
667 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07668
669 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56670
671 RendererContentSettingRules rules;
672 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
673 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14674}
675
[email protected]3d7474ff2011-07-27 17:47:37676GURL ChromeContentBrowserClient::GetEffectiveURL(
677 content::BrowserContext* browser_context, const GURL& url) {
678 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52679 if (!profile)
680 return url;
681
[email protected]7c60f5042013-02-14 03:39:32682 // If the input |url| should be assigned to the Instant renderer, make its
683 // effective URL distinct from other URLs on the search provider's domain.
684 if (chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
685 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52686
687 // If the input |url| is part of an installed app, the effective URL is an
688 // extension URL with the ID of that extension as the host. This has the
689 // effect of grouping apps together in a common SiteInstance.
690 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13691 extensions::ExtensionSystem::Get(profile)->extension_service();
692 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08693 return url;
694
[email protected]06bdd2b2012-11-30 18:47:13695 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44696 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08697 if (!extension)
698 return url;
699
[email protected]15877ca2011-11-18 22:40:52700 // Bookmark apps do not use the hosted app process model, and should be
701 // treated as normal URLs.
702 if (extension->from_bookmark())
703 return url;
704
[email protected]36fb2c7c2011-04-04 15:49:08705 // If the URL is part of an extension's web extent, convert it to an
706 // extension URL.
707 return extension->GetResourceURL(url.path());
708}
709
[email protected]056ad2a2011-07-12 02:13:55710bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37711 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52712 // Non-extension, non-Instant URLs should generally use
713 // process-per-site-instance. Because we expect to use the effective URL,
714 // URLs for hosted apps (apart from bookmark apps) should have an extension
715 // scheme by now.
716
717 Profile* profile = Profile::FromBrowserContext(browser_context);
718 if (!profile)
719 return false;
720
[email protected]7c60f5042013-02-14 03:39:32721 if (chrome::search::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52722 return true;
723
[email protected]885c0e92012-11-13 20:27:42724 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55725 return false;
726
[email protected]c5dec6292013-01-25 04:54:52727 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13728 extensions::ExtensionSystem::Get(profile)->extension_service();
729 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55730 return false;
731
[email protected]06bdd2b2012-11-30 18:47:13732 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44733 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55734 if (!extension)
735 return false;
736
737 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53738 // permission, or that does not allow JavaScript access to the background
739 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55740 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40741 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06742 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53743 !extension->allow_background_js_access()) {
744 return false;
745 }
746 }
[email protected]056ad2a2011-07-12 02:13:55747
[email protected]7b54ca02012-03-02 18:06:53748 // Hosted apps that have script access to their background page must use
749 // process per site, since all instances can make synchronous calls to the
750 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55751 return true;
752}
753
[email protected]6bd30072013-02-08 18:17:11754net::URLRequestContextGetter*
755ChromeContentBrowserClient::CreateRequestContext(
756 content::BrowserContext* browser_context,
757 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
758 blob_protocol_handler,
759 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
760 file_system_protocol_handler,
761 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
762 developer_protocol_handler,
763 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
764 chrome_protocol_handler,
765 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
766 chrome_devtools_protocol_handler) {
767 Profile* profile = Profile::FromBrowserContext(browser_context);
768 return profile->CreateRequestContext(blob_protocol_handler.Pass(),
769 file_system_protocol_handler.Pass(),
770 developer_protocol_handler.Pass(),
771 chrome_protocol_handler.Pass(),
772 chrome_devtools_protocol_handler.Pass());
773}
774
775net::URLRequestContextGetter*
776ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
777 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40778 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11779 bool in_memory,
780 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
781 blob_protocol_handler,
782 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
783 file_system_protocol_handler,
784 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
785 developer_protocol_handler,
786 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
787 chrome_protocol_handler,
788 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
789 chrome_devtools_protocol_handler) {
790 Profile* profile = Profile::FromBrowserContext(browser_context);
791 return profile->CreateRequestContextForStoragePartition(
792 partition_path,
793 in_memory,
794 blob_protocol_handler.Pass(),
795 file_system_protocol_handler.Pass(),
796 developer_protocol_handler.Pass(),
797 chrome_protocol_handler.Pass(),
798 chrome_devtools_protocol_handler.Pass());
799}
800
[email protected]46fb9442011-12-09 17:57:47801bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
802 return ProfileIOData::IsHandledURL(url);
803}
804
[email protected]2a5221b2011-09-27 23:07:31805bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30806 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31807 const GURL& site_url) {
808 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30809 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52810 // This may be NULL during tests. In that case, just assume any site can
811 // share any host.
812 if (!profile)
813 return true;
814
815 InstantService* instant_service =
816 InstantServiceFactory::GetForProfile(profile);
817 if (instant_service &&
818 instant_service->IsInstantProcess(process_host->GetID()))
[email protected]7c60f5042013-02-14 03:39:32819 return chrome::search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]c5dec6292013-01-25 04:54:52820
[email protected]06bdd2b2012-11-30 18:47:13821 ExtensionService* service =
822 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46823 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31824
[email protected]ffa97602011-11-17 17:55:52825 // Don't allow the Task Manager to share a process with anything else.
826 // Otherwise it can affect the renderers it is observing.
827 // Note: we could create another RenderProcessHostPrivilege bucket for
828 // this to allow multiple chrome://tasks instances to share, but that's
829 // a very unlikely case without serious consequences.
830 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
831 return false;
832
[email protected]8d3132f62011-10-12 07:13:42833 // These may be NULL during tests. In that case, just assume any site can
834 // share any host.
[email protected]6f371442011-11-09 06:45:46835 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31836 return true;
837
[email protected]eec0b33c2011-12-05 22:09:45838 // Otherwise, just make sure the process privilege matches the privilege
839 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57840 RenderProcessHostPrivilege privilege_required =
841 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45842 return GetProcessPrivilege(process_host, process_map, service) ==
843 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31844}
845
[email protected]76411f412012-02-22 18:56:06846// This function is trying to limit the amount of processes used by extensions
847// with background pages. It uses a globally set percentage of processes to
848// run such extensions and if the limit is exceeded, it returns true, to
849// indicate to the content module to group extensions together.
850bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
851 content::BrowserContext* browser_context, const GURL& url) {
852 // It has to be a valid URL for us to check for an extension.
853 if (!url.is_valid())
854 return false;
855
856 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19857 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13858 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06859 if (!service)
860 return false;
861
862 // We have to have a valid extension with background page to proceed.
863 const Extension* extension =
864 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
865 if (!extension)
866 return false;
867 if (!extension->has_background_page())
868 return false;
869
870 std::set<int> process_ids;
871 size_t max_process_count =
872 content::RenderProcessHost::GetMaxRendererProcessCount();
873
874 // Go through all profiles to ensure we have total count of extension
875 // processes containing background pages, otherwise one profile can
876 // starve the other.
877 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
878 GetLoadedProfiles();
879 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03880 ExtensionProcessManager* epm =
881 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32882 for (ExtensionProcessManager::const_iterator iter =
883 epm->background_hosts().begin();
884 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13885 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32886 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06887 }
888 }
889
890 if (process_ids.size() >
891 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
892 return true;
893 }
894
895 return false;
896}
897
[email protected]6f371442011-11-09 06:45:46898void ChromeContentBrowserClient::SiteInstanceGotProcess(
899 SiteInstance* site_instance) {
900 CHECK(site_instance->HasProcess());
901
902 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02903 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52904 if (!profile)
905 return;
906
907 // Remember the ID of the Instant process to signal the renderer process
908 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]7c60f5042013-02-14 03:39:32909 if (chrome::search::ShouldAssignURLToInstantRenderer(
910 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52911 InstantService* instant_service =
912 InstantServiceFactory::GetForProfile(profile);
913 if (instant_service)
914 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
915 }
916
[email protected]06bdd2b2012-11-30 18:47:13917 ExtensionService* service =
918 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46919 if (!service)
920 return;
921
922 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44923 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59924 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46925 if (!extension)
926 return;
927
[email protected]6bc04fd82011-12-04 02:29:35928 service->process_map()->Insert(extension->id(),
929 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33930 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46931 BrowserThread::PostTask(
932 BrowserThread::IO, FROM_HERE,
933 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59934 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46935 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35936 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33937 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46938}
939
940void ChromeContentBrowserClient::SiteInstanceDeleting(
941 SiteInstance* site_instance) {
942 if (!site_instance->HasProcess())
943 return;
944
945 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02946 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13947 ExtensionService* service =
948 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46949 if (!service)
950 return;
951
952 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44953 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59954 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46955 if (!extension)
956 return;
957
[email protected]6bc04fd82011-12-04 02:29:35958 service->process_map()->Remove(extension->id(),
959 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33960 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46961 BrowserThread::PostTask(
962 BrowserThread::IO, FROM_HERE,
963 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59964 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46965 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35966 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33967 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46968}
969
[email protected]f05763972012-06-06 18:17:26970bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:14971 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:08972 const GURL& current_url,
973 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26974 if (current_url.is_empty()) {
975 // Always choose a new process when navigating to extension URLs. The
976 // process grouping logic will combine all of a given extension's pages
977 // into the same process.
[email protected]885c0e92012-11-13 20:27:42978 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:26979 return true;
[email protected]e3daf3c2011-10-05 21:17:08980
[email protected]f05763972012-06-06 18:17:26981 return false;
982 }
983
984 // Also, we must switch if one is an extension and the other is not the exact
985 // same extension.
[email protected]885c0e92012-11-13 20:27:42986 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
987 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:26988 if (current_url.GetOrigin() != new_url.GetOrigin())
989 return true;
990 }
991
[email protected]e9841fbd2013-02-22 23:12:14992 // The checks below only matter if we can retrieve which extensions are
993 // installed.
994 Profile* profile =
995 Profile::FromBrowserContext(site_instance->GetBrowserContext());
996 ExtensionService* service =
997 extensions::ExtensionSystem::Get(profile)->extension_service();
998 if (!service)
999 return false;
1000
1001 // We must swap if the URL is for an extension and we are not using an
1002 // extension process.
1003 const Extension* new_extension =
1004 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1005 // Ignore all hosted apps except the Chrome Web Store, since they do not
1006 // require their own BrowsingInstance (e.g., postMessage is ok).
1007 if (new_extension &&
1008 new_extension->is_hosted_app() &&
1009 new_extension->id() != extension_misc::kWebStoreAppId)
1010 new_extension = NULL;
1011 if (new_extension &&
1012 site_instance->HasProcess() &&
1013 !service->process_map()->Contains(new_extension->id(),
1014 site_instance->GetProcess()->GetID()))
1015 return true;
1016
[email protected]f05763972012-06-06 18:17:261017 return false;
[email protected]e3daf3c2011-10-05 21:17:081018}
1019
[email protected]395045c2012-05-22 15:04:381020bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1021 content::ResourceContext* resource_context, const GURL& current_url,
1022 const GURL& new_url) {
1023 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1024 return extensions::CrossesExtensionProcessBoundary(
1025 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171026 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381027}
1028
[email protected]763ec4ca2011-04-29 15:48:121029std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1030 const std::string& alias_name) {
1031 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1032}
1033
[email protected]b80f68432011-05-02 17:22:301034void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1035 CommandLine* command_line, int child_process_id) {
1036#if defined(USE_LINUX_BREAKPAD)
1037 if (IsCrashReporterEnabled()) {
1038 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1039 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1040 }
1041#elif defined(OS_MACOSX)
1042 if (IsCrashReporterEnabled()) {
1043 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1044 child_process_logging::GetClientId());
1045 }
1046#endif // OS_MACOSX
1047
[email protected]f1933792011-06-14 00:49:341048 if (logging::DialogsAreSuppressed())
1049 command_line->AppendSwitch(switches::kNoErrorDialogs);
1050
[email protected]b80f68432011-05-02 17:22:301051 std::string process_type =
1052 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171053 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:521054 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451055 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301056 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1057 if (!user_data_dir.empty())
1058 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1059#if defined(OS_CHROMEOS)
1060 const std::string& login_profile =
1061 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1062 if (!login_profile.empty())
1063 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1064#endif
1065
[email protected]f3b1a082011-11-18 00:34:301066 content::RenderProcessHost* process =
1067 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371068 if (process) {
1069 Profile* profile = Profile::FromBrowserContext(
1070 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131071 ExtensionService* extension_service =
1072 extensions::ExtensionSystem::Get(profile)->extension_service();
1073 if (extension_service) {
1074 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001075 if (process_map && process_map->Contains(process->GetID()))
1076 command_line->AppendSwitch(switches::kExtensionProcess);
1077 }
[email protected]b80f68432011-05-02 17:22:301078
[email protected]a8d851f82011-12-21 00:32:371079 PrefService* prefs = profile->GetPrefs();
1080 // Currently this pref is only registered if applied via a policy.
1081 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1082 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1083 // Turn this policy into a command line switch.
1084 command_line->AppendSwitch(switches::kDisable3DAPIs);
1085 }
[email protected]718eab62011-10-05 21:16:521086
[email protected]a8d851f82011-12-21 00:32:371087 // Disable client-side phishing detection in the renderer if it is
1088 // disabled in the Profile preferences or the browser process.
1089 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1090 !g_browser_process->safe_browsing_detection_service()) {
1091 command_line->AppendSwitch(
1092 switches::kDisableClientSidePhishingDetection);
1093 }
[email protected]0045b0f42012-07-26 11:52:081094
1095 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211096 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521097
1098 InstantService* instant_service =
1099 InstantServiceFactory::GetForProfile(profile);
1100 if (instant_service &&
1101 instant_service->IsInstantProcess(process->GetID()))
1102 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]47c7ec82012-01-18 03:29:211103 }
[email protected]4287a3d2011-06-13 23:56:511104
[email protected]87552982012-11-02 17:21:401105 if (content::IsThreadedCompositingEnabled())
1106 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1107
[email protected]47c7ec82012-01-18 03:29:211108 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511109 static const char* const kSwitchNames[] = {
1110 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481111 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511112 switches::kAllowScriptingGallery,
1113 switches::kAppsCheckoutURL,
1114 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311115 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511116 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501117 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531118 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111119 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511120 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211121 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511122 switches::kEnableCrxlessWebApps,
1123 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561124 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511125 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511126 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511127 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451128 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481129 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051130 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511131 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511132 switches::kMemoryProfiling,
1133 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371134 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581135 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371136 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511137 switches::kPpapiFlashArgs,
1138 switches::kPpapiFlashInProcess,
1139 switches::kPpapiFlashPath,
1140 switches::kPpapiFlashVersion,
1141 switches::kProfilingAtStart,
1142 switches::kProfilingFile,
1143 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371144 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511145 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291146 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381147 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511148 };
1149
1150 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1151 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171152 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381153 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351154 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381155 switches::kEnableExperimentalExtensionApis,
1156 switches::kWhitelistedExtensionID,
1157 };
1158
1159 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1160 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511161 } else if (process_type == switches::kPluginProcess) {
1162 static const char* const kSwitchNames[] = {
1163 #if defined(OS_CHROMEOS)
1164 switches::kLoginProfile,
1165 #endif
1166 switches::kMemoryProfiling,
1167 switches::kSilentDumpOnDCHECK,
1168 switches::kUserDataDir,
1169 };
1170
1171 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1172 arraysize(kSwitchNames));
1173 } else if (process_type == switches::kZygoteProcess) {
1174 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511175 switches::kUserDataDir, // Make logs go to the right file.
1176 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501177 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511178 switches::kPpapiFlashInProcess,
1179 switches::kPpapiFlashPath,
1180 switches::kPpapiFlashVersion,
1181 };
1182
1183 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1184 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111185 } else if (process_type == switches::kGpuProcess) {
1186 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1187 // because GPU is expected to be unreliable.
1188 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1189 !command_line->HasSwitch(switches::kDisableBreakpad))
1190 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301191 }
[email protected]6f08af82011-09-15 01:19:031192
1193 // The command line switch kEnableBenchmarking needs to be specified along
1194 // with the kEnableStatsTable switch to ensure that the stats table global
1195 // is initialized correctly.
1196 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1197 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301198}
1199
1200std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431201 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1202 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301203 return g_browser_process->GetApplicationLocale();
1204}
1205
[email protected]597a867b2011-11-18 18:31:201206std::string ChromeContentBrowserClient::GetAcceptLangs(
1207 content::BrowserContext* context) {
1208 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371209 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081210}
1211
[email protected]9ec0f452012-05-31 15:58:531212gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221213 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531214 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081215}
1216
[email protected]a2176792011-05-08 19:30:491217bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091218 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191219 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201220 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201222 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051223 return io_data->GetCookieSettings()->
1224 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491225}
1226
[email protected]ed24fad2011-05-10 22:44:011227bool ChromeContentBrowserClient::AllowGetCookie(
1228 const GURL& url,
1229 const GURL& first_party,
1230 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201231 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011232 int render_process_id,
1233 int render_view_id) {
1234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201235 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051236 bool allow = io_data->GetCookieSettings()->
1237 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011238
[email protected]8093a542011-05-13 07:29:321239 BrowserThread::PostTask(
1240 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031241 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431242 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011243 return allow;
1244}
1245
1246bool ChromeContentBrowserClient::AllowSetCookie(
1247 const GURL& url,
1248 const GURL& first_party,
1249 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201250 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011251 int render_process_id,
1252 int render_view_id,
1253 net::CookieOptions* options) {
1254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201255 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051256 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1257 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1258
[email protected]8093a542011-05-13 07:29:321259 BrowserThread::PostTask(
1260 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031261 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431262 render_view_id, url, first_party, cookie_line, *options,
1263 !allow));
[email protected]ed24fad2011-05-10 22:44:011264 return allow;
1265}
1266
[email protected]d5a19162011-06-30 18:51:541267bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201268 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201270 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431271 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1272 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261273
[email protected]bf510ed2012-06-05 08:31:431274 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1275 // Could we even support per-origin settings?
1276 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541277}
1278
[email protected]5c5a88e2011-11-12 00:45:351279bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351280 const GURL& url,
1281 const string16& name,
1282 const string16& display_name,
1283 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201284 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481285 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201287 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351288 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1289 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1290
[email protected]62151052012-02-01 18:40:481291 // Record access to database for potential display in UI.
1292 std::vector<std::pair<int, int> >::const_iterator i;
1293 for (i = render_views.begin(); i != render_views.end(); ++i) {
1294 BrowserThread::PostTask(
1295 BrowserThread::UI, FROM_HERE,
1296 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1297 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351298 }
1299
1300 return allow;
1301}
1302
1303bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351304 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201305 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481306 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201308 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351309 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1310 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1311
[email protected]62151052012-02-01 18:40:481312 // Record access to file system for potential display in UI.
1313 std::vector<std::pair<int, int> >::const_iterator i;
1314 for (i = render_views.begin(); i != render_views.end(); ++i) {
1315 BrowserThread::PostTask(
1316 BrowserThread::UI, FROM_HERE,
1317 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1318 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351319 }
1320
1321 return allow;
1322}
1323
[email protected]7c5ff9a2012-03-02 07:42:491324bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1325 const GURL& url,
1326 const string16& name,
1327 content::ResourceContext* context,
1328 const std::vector<std::pair<int, int> >& render_views) {
1329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1330 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1331 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1332 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1333
1334 // Record access to IndexedDB for potential display in UI.
1335 std::vector<std::pair<int, int> >::const_iterator i;
1336 for (i = render_views.begin(); i != render_views.end(); ++i) {
1337 BrowserThread::PostTask(
1338 BrowserThread::UI, FROM_HERE,
1339 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1340 i->first, i->second, url, name, !allow));
1341 }
1342
1343 return allow;
1344}
1345
[email protected]6133f922011-07-01 21:34:341346net::URLRequestContext*
1347ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201348 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421350 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201351 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341352 return io_data->extensions_request_context();
1353 }
1354
1355 return NULL;
1356}
1357
[email protected]317f96c92011-05-31 06:53:411358QuotaPermissionContext*
1359ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1360 return new ChromeQuotaPermissionContext();
1361}
1362
[email protected]848dd042011-06-04 18:24:031363void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171364 int render_process_id,
1365 int render_view_id,
1366 int cert_error,
1367 const net::SSLInfo& ssl_info,
1368 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031369 bool overridable,
[email protected]d9be47702012-05-16 03:41:221370 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171371 const base::Callback<void(bool)>& callback,
1372 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411373 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131374 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171375 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411376 if (!tab) {
1377 NOTREACHED();
1378 return;
1379 }
1380 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501381 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301382 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011383 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1384 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411385 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171386 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411387 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171388 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411389 return;
1390 }
1391 }
1392
[email protected]1e87df32012-09-12 04:53:191393#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231394 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1395 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1396 if (captive_portal_tab_helper)
1397 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191398#endif
1399
[email protected]f9034cf2011-07-21 12:43:411400 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221401 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1402 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031403}
1404
[email protected]c99c442e2011-08-24 11:37:301405void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451406 int render_process_id,
1407 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401408 const net::HttpNetworkSession* network_session,
1409 net::SSLCertRequestInfo* cert_request_info,
1410 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131411 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451412 render_process_id, render_view_id);
1413 if (!tab) {
1414 NOTREACHED();
1415 return;
1416 }
1417
[email protected]6786bf402011-12-03 15:19:451418 GURL requesting_url("https://" + cert_request_info->host_and_port);
1419 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1420 << cert_request_info->host_and_port;
1421
[email protected]627e0512011-12-21 22:55:301422 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451423 scoped_ptr<Value> filter(
1424 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1425 requesting_url,
1426 requesting_url,
1427 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1428 std::string(), NULL));
1429
1430 if (filter.get()) {
1431 // Try to automatically select a client certificate.
1432 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1433 DictionaryValue* filter_dict =
1434 static_cast<DictionaryValue*>(filter.get());
1435
1436 const std::vector<scoped_refptr<net::X509Certificate> >&
1437 all_client_certs = cert_request_info->client_certs;
1438 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1439 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1440 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401441 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451442 return;
1443 }
1444 }
1445 } else {
1446 NOTREACHED();
1447 }
1448 }
1449
[email protected]11feec322012-09-18 03:58:521450 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1451 if (!ssl_tab_helper) {
1452 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451453 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141454 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401455 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451456 return;
1457 }
[email protected]11feec322012-09-18 03:58:521458 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401459 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451460}
1461
[email protected]3b455502012-12-11 18:22:581462void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451463 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581464 net::CertificateMimeType cert_type,
1465 const void* cert_data,
1466 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451467 int render_process_id,
1468 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581469 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1470 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451471}
1472
[email protected]dc73a7b2012-03-25 15:27:181473content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561474 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181475}
1476
[email protected]941623e2011-06-07 23:06:041477void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1478 const GURL& source_origin,
1479 int callback_context,
1480 int render_process_id,
1481 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111482#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1484 WebContents* contents =
1485 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1486 if (!contents) {
[email protected]941623e2011-06-07 23:06:041487 NOTREACHED();
1488 return;
1489 }
1490
[email protected]d0d9c3ee2012-06-19 03:07:021491 // Skip showing the infobar if the request comes from an extension, and that
1492 // extension has the 'notify' permission. (If the extension does not have the
1493 // permission, the user will still be prompted.)
1494 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131495 ExtensionService* service =
1496 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021497 const Extension* extension = !service ? NULL :
1498 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1499 source_origin));
[email protected]eb4832a2012-12-08 01:57:521500 RenderViewHost* rvh =
1501 RenderViewHost::FromID(render_process_id, render_view_id);
1502 if (IsExtensionWithPermissionOrSuggestInConsole(
1503 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021504 if (rvh)
1505 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1506 return;
1507 }
1508
1509 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371510 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021511 notifications->RequestPermission(source_origin, render_process_id,
1512 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111513#else
1514 NOTIMPLEMENTED();
1515#endif
[email protected]941623e2011-06-07 23:06:041516}
1517
1518WebKit::WebNotificationPresenter::Permission
1519 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021520 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201521 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021522 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111523#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201525 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021526 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1527 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061528 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041529 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041530
1531 // Fall back to the regular notification preferences, which works on an
1532 // origin basis.
1533 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371534 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041535 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111536#else
1537 return WebKit::WebNotificationPresenter::PermissionAllowed;
1538#endif
[email protected]941623e2011-06-07 23:06:041539}
1540
1541void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171542 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041543 int render_process_id,
1544 int render_view_id,
1545 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111546#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041547 RenderViewHost* rvh = RenderViewHost::FromID(
1548 render_process_id, render_view_id);
1549 if (!rvh) {
1550 NOTREACHED();
1551 return;
1552 }
1553
[email protected]9f76c1e2012-03-05 15:15:581554 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301555 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041556 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371557 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041558 service->ShowDesktopNotification(
1559 params, render_process_id, render_view_id,
1560 worker ? DesktopNotificationService::WorkerNotification :
1561 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111562#else
1563 NOTIMPLEMENTED();
1564#endif
[email protected]941623e2011-06-07 23:06:041565}
1566
1567void ChromeContentBrowserClient::CancelDesktopNotification(
1568 int render_process_id,
1569 int render_view_id,
1570 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111571#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041572 RenderViewHost* rvh = RenderViewHost::FromID(
1573 render_process_id, render_view_id);
1574 if (!rvh) {
1575 NOTREACHED();
1576 return;
1577 }
1578
[email protected]9f76c1e2012-03-05 15:15:581579 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301580 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041581 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371582 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041583 service->CancelDesktopNotification(
1584 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111585#else
1586 NOTIMPLEMENTED();
1587#endif
[email protected]941623e2011-06-07 23:06:041588}
1589
[email protected]9f3fba52011-06-08 20:37:191590bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351591 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021592 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191593 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201594 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011595 int render_process_id,
1596 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011598
1599 *no_javascript_access = false;
1600
[email protected]9f3fba52011-06-08 20:37:191601 // If the opener is trying to create a background window but doesn't have
1602 // the appropriate permission, fail the attempt.
1603 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201604 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531605 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1606
[email protected]03b6d552012-03-29 04:03:011607 if (!map->SecurityOriginHasAPIPermission(
1608 source_origin,
1609 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061610 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011611 return false;
1612 }
1613
[email protected]7b54ca02012-03-02 18:06:531614 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1615 // return a recently installed Extension even if this CanCreateWindow call
1616 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011617 // because the permission check above would have caused an early return
1618 // already. We must use the full URL to find hosted apps, though, and not
1619 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531620 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351621 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531622 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011623 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191624 }
1625 return true;
1626}
1627
1628std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201629 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1631 // Check if it's an extension-created worker, in which case we want to use
1632 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201633 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191634 const Extension* extension =
1635 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1636 return extension ? extension->name() : std::string();
1637}
1638
[email protected]99907362012-01-11 05:41:401639void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1640 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171641}
1642
[email protected]c52b2892012-03-07 11:01:021643content::SpeechRecognitionManagerDelegate*
1644 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321645#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021646 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321647#else
1648 return NULL;
1649#endif
[email protected]66cfec62012-02-24 17:57:511650}
1651
[email protected]ae6e9912011-07-27 01:18:281652net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1653 return g_browser_process->net_log();
1654}
1655
[email protected]32538d92011-08-25 00:09:231656AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1657 return new ChromeAccessTokenStore();
1658}
1659
[email protected]dbae6b02011-06-29 23:51:411660bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011661 return true;
[email protected]dbae6b02011-06-29 23:51:411662}
1663
[email protected]64d69de42012-02-06 00:19:541664void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321665 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061666 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581667 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061668 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061669
[email protected]f3986f82012-01-03 20:00:061670 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541671 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061672 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541673 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061674 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541675 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061676 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541677 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061678 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541679 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061680 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541681 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031682 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1683 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061684
[email protected]64d69de42012-02-06 00:19:541685 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401686 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541687 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401688 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541689 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401690 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541691 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401692 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061693
[email protected]ddf72142012-05-22 04:52:401694 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061695
[email protected]64d69de42012-02-06 00:19:541696 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401697 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541698 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061699 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541700 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061701 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1702 const DictionaryValue* inspector_settings =
1703 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1704 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181705 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1706 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061707 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181708 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541709 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181710 std::make_pair(iter.key(), value));
1711 }
[email protected]f3986f82012-01-03 20:00:061712 }
1713 }
[email protected]64d69de42012-02-06 00:19:541714 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061715
[email protected]ddf72142012-05-22 04:52:401716 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541717 web_prefs->javascript_enabled = false;
1718 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1719 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401720 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541721 web_prefs->plugins_enabled = false;
1722 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1723 web_prefs->java_enabled = false;
1724 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401725 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061726
[email protected]64d69de42012-02-06 00:19:541727 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1728 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061729
[email protected]64d69de42012-02-06 00:19:541730 web_prefs->memory_info_enabled =
1731 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1732 web_prefs->allow_displaying_insecure_content =
1733 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1734 web_prefs->allow_running_insecure_content =
1735 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321736#if defined(OS_ANDROID)
1737 web_prefs->font_scale_factor =
1738 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1739 web_prefs->force_enable_zoom =
1740 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1741#endif
[email protected]9d06d88d2012-02-23 22:37:081742 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061743
[email protected]64d69de42012-02-06 00:19:541744 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151745 UserStyleSheetWatcher* user_style_sheet_watcher =
1746 UserStyleSheetWatcherFactory::GetForProfile(profile);
1747 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541748 web_prefs->user_style_sheet_enabled = true;
1749 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151750 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541751 } else {
1752 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061753 }
1754
[email protected]b7e44ff2012-02-16 03:37:341755 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101756#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031757 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101758 // Mac so it uses NSSpellChecker in the background.
1759 false;
1760#else
[email protected]61806872012-12-12 04:15:361761 true;
[email protected]37b928e2012-05-30 09:01:101762#endif
[email protected]b7e44ff2012-02-16 03:37:341763 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521764 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571765
[email protected]64d69de42012-02-06 00:19:541766 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061767 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541768 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061769 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541770 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061771 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1772
1773 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541774 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061775 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541776 web_prefs->default_encoding);
1777 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401778 prefs->ClearPref(prefs::kDefaultCharset);
1779 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061780 }
[email protected]64d69de42012-02-06 00:19:541781 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061782
[email protected]88ecf66d2012-12-11 22:53:471783 if (content::IsForceCompositingModeEnabled())
1784 web_prefs->force_compositing_mode = true;
1785
[email protected]299d7f12012-05-23 05:31:151786 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1787 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131788 ExtensionService* service =
1789 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061790 if (service) {
[email protected]1bc28312012-11-08 08:31:531791 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1792 const Extension* extension = service->extensions()->GetByID(url.host());
1793 // Ensure that we are only granting extension preferences to URLs with
1794 // the correct scheme. Without this check, chrome-guest:// schemes used by
1795 // webview tags as well as hosts that happen to match the id of an
1796 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421797 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531798 extension_webkit_preferences::SetPreferences(
1799 extension, view_type, web_prefs);
1800 }
[email protected]f3986f82012-01-03 20:00:061801 }
1802
[email protected]299d7f12012-05-23 05:31:151803 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541804 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151805 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061806 // Disable all kinds of acceleration for background pages.
1807 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541808 web_prefs->force_compositing_mode = false;
1809 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061810 }
[email protected]2e21fe292012-03-02 22:52:321811
1812#if defined(FILE_MANAGER_EXTENSION)
1813 // Override the default of suppressing HW compositing for WebUI pages for the
1814 // file manager, which is implemented using WebUI but wants HW acceleration
1815 // for video decode & render.
1816 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1817 web_prefs->accelerated_compositing_enabled = true;
1818 web_prefs->accelerated_2d_canvas_enabled = true;
1819 }
1820#endif
[email protected]181a95ee2011-07-12 19:26:361821}
1822
1823void ChromeContentBrowserClient::UpdateInspectorSetting(
1824 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061825 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581826 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061827 DictionaryPrefUpdate update(
1828 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1829 prefs::kWebKitInspectorSettings);
1830 DictionaryValue* inspector_settings = update.Get();
1831 inspector_settings->SetWithoutPathExpansion(key,
1832 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361833}
1834
1835void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061836 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581837 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061838 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1839 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361840}
1841
[email protected]b8148ac2011-07-13 22:03:251842void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1843 BrowserURLHandler* handler) {
1844 // Add the default URL handlers.
1845 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1846 BrowserURLHandler::null_handler());
1847 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1848 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1849
[email protected]b3adbd02011-11-30 22:23:271850 // about: handler. Must come before chrome: handler, since it will
1851 // rewrite about: urls to chrome: URLs and then expect chrome: to
1852 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251853 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1854 BrowserURLHandler::null_handler());
1855 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241856 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251857}
1858
1859void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371860 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581861 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471862 BrowsingDataRemover* remover =
1863 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551864 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1865 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251866 // BrowsingDataRemover takes care of deleting itself when done.
1867}
1868
1869void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371870 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581871 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471872 BrowsingDataRemover* remover =
1873 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231874 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551875 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251876 // BrowsingDataRemover takes care of deleting itself when done.
1877}
1878
[email protected]650b2d52013-02-10 03:41:451879base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321880 return download_util::GetDefaultDownloadDirectory();
1881}
1882
[email protected]c9b6eb62011-10-18 20:49:391883std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1884 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1885}
1886
[email protected]b7631cc2012-09-15 05:08:381887void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1888 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541889#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381890 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1891 scoped_ptr<ppapi::host::HostFactory>(
1892 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541893#endif
[email protected]b7631cc2012-09-15 05:08:381894}
1895
[email protected]0c7193742012-11-07 19:05:031896content::BrowserPpapiHost*
1897 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1898 int plugin_process_id) {
1899 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1900 while (!iter.Done()) {
1901 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1902 if (host->process() &&
1903 host->process()->GetData().id == plugin_process_id) {
1904 // Found the plugin.
1905 return host->browser_ppapi_host();
1906 }
1907 ++iter;
1908 }
1909 return NULL;
1910}
1911
[email protected]38cd8f7f2012-06-15 22:06:071912bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581913 content::BrowserContext* browser_context,
1914 const GURL& url,
1915 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291916 if (!url.is_valid())
1917 return false;
1918
1919 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421920 if (url.SchemeIs(extensions::kExtensionScheme) &&
1921 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291922 return true;
[email protected]885c0e92012-11-13 20:27:421923 }
[email protected]a658d452012-03-02 12:45:291924
[email protected]9a5940d2012-04-27 19:16:231925 Profile* profile = Profile::FromBrowserContext(browser_context);
1926 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191927 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131928 extensions::ExtensionSystem::Get(profile)->extension_service();
1929 if (extension_service) {
1930 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231931 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1932 }
1933
[email protected]f237c0f2012-03-10 07:49:101934 // Need to check this now and not on construction because otherwise it won't
1935 // work with browser_tests.
1936 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1937 std::string allowed_list =
1938 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231939 if (allowed_list == "*") {
1940 // The wildcard allows socket API only for packaged and platform apps.
1941 return extension &&
[email protected]1d5e58b2013-01-31 08:41:401942 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
1943 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:231944 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:391945 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:101946 while (t.GetNext()) {
1947 if (t.token() == host)
1948 return true;
1949 }
1950 }
1951
[email protected]a658d452012-03-02 12:45:291952 if (!extension)
1953 return false;
1954
[email protected]157cc902012-11-02 06:31:581955 extensions::SocketPermission::CheckParam extension_params(
1956 params.type, params.host, params.port);
1957 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1958 &extension_params))
[email protected]a658d452012-03-02 12:45:291959 return true;
1960
1961 return false;
[email protected]e461da2f2012-02-16 19:06:401962}
1963
[email protected]650b2d52013-02-10 03:41:451964base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
1965 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:141966 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
1967 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
1968}
1969
[email protected]a28e3302013-02-03 03:50:431970ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
1971 WebContents* web_contents) {
1972 return new ChromeSelectFilePolicy(web_contents);
1973}
1974
[email protected]e60c0232011-11-11 19:56:351975#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181976void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1977 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:381978 int child_process_id,
[email protected]c7abd422012-09-25 00:20:081979 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:391980#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:451981 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:391982 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
1983 DCHECK(!data_path.empty());
1984
1985 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:451986 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:391987 base::PlatformFile f =
1988 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
1989 DCHECK(f != base::kInvalidPlatformFileValue);
1990 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
1991 FileDescriptor(f, true)));
1992
[email protected]650b2d52013-02-10 03:41:451993 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:391994 data_path.AppendASCII("chrome_100_percent.pak");
1995 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
1996 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:371997 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:391998 FileDescriptor(f, true)));
1999
2000 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452001 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392002 GetLocaleFilePath(locale, false);
2003 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2004 DCHECK(f != base::kInvalidPlatformFileValue);
2005 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2006 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382007
[email protected]650b2d52013-02-10 03:41:452008 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372009 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2010 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2011 DCHECK(f != base::kInvalidPlatformFileValue);
2012 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2013 FileDescriptor(f, true)));
2014
[email protected]40da3e0c2012-10-24 22:03:382015#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432016 if (IsCrashReporterEnabled()) {
2017 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2018 if (f == base::kInvalidPlatformFileValue) {
2019 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2020 "be disabled for this process.";
2021 } else {
2022 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2023 FileDescriptor(f, true)));
2024 }
[email protected]40da3e0c2012-10-24 22:03:382025 }
2026#endif // defined(USE_LINUX_BREAKPAD)
2027
2028#else
2029 int crash_signal_fd = GetCrashSignalFD(command_line);
2030 if (crash_signal_fd >= 0) {
2031 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2032 FileDescriptor(crash_signal_fd,
2033 false)));
2034 }
[email protected]29699c22012-10-03 23:57:392035#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302036}
[email protected]e60c0232011-11-11 19:56:352037#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302038
[email protected]4a65826d2011-08-25 16:04:012039#if defined(OS_WIN)
2040const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2041 return chrome::kBrowserResourcesDll;
2042}
2043#endif
2044
[email protected]37a72af2011-06-13 05:42:012045#if defined(USE_NSS)
2046crypto::CryptoModuleBlockingPasswordDelegate*
2047 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2048 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292049 return chrome::NewCryptoModuleBlockingDialogDelegate(
2050 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012051}
2052#endif
2053
[email protected]e9a32a52012-06-14 23:32:432054void ChromeContentBrowserClient::SetApplicationLocale(
2055 const std::string& locale) {
2056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2057
2058 // This object is guaranteed to outlive all threads so we don't have to
2059 // worry about the lack of refcounting and can just post as Unretained.
2060 //
2061 // The common case is that this function is called early in Chrome startup
2062 // before any threads are created (it will also be called later if the user
2063 // changes the pref). In this case, there will be no threads created and
2064 // posting will fail. When there are no threads, we can just set the string
2065 // without worrying about threadsafety.
2066 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2067 base::Bind(
2068 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2069 base::Unretained(this), locale)))
2070 io_thread_application_locale_ = locale;
2071}
2072
2073void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2074 const std::string& locale) {
2075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2076 io_thread_application_locale_ = locale;
2077}
2078
[email protected]d977f9c2011-03-14 16:10:262079} // namespace chrome