blob: e1908ecd0cfaf524fefaf5a55872100f4c988ffa [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]38b098f2012-03-14 21:11:57508content::WebContentsView*
509 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57510 WebContents* web_contents,
511 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57512 return NULL;
513}
514
[email protected]e94bbcb2012-09-07 05:33:57515std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19516 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57517 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53518 std::string partition_id;
519
520 // The partition ID for webview guest processes is the string value of its
521 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
522 if (site.SchemeIs(chrome::kGuestScheme))
523 partition_id = site.spec();
524
525 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
526 return partition_id;
527}
528
529bool ChromeContentBrowserClient::IsValidStoragePartitionId(
530 content::BrowserContext* browser_context,
531 const std::string& partition_id) {
532 // The default ID is empty and is always valid.
533 if (partition_id.empty())
534 return true;
535
536 return GURL(partition_id).is_valid();
537}
538
539void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
540 content::BrowserContext* browser_context,
541 const GURL& site,
[email protected]14acc642012-11-17 12:20:10542 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53543 std::string* partition_domain,
544 std::string* partition_name,
545 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10546 // Default to the browser-wide storage partition and override based on |site|
547 // below.
548 partition_domain->clear();
549 partition_name->clear();
550 *in_memory = false;
551
[email protected]1bc28312012-11-08 08:31:53552 // For the webview tag, we create special guest processes, which host the
553 // tag content separately from the main application that embeds the tag.
554 // A webview tag can specify both the partition name and whether the storage
555 // for that partition should be persisted. Each tag gets a SiteInstance with
556 // a specially formatted URL, based on the application it is hosted by and
557 // the partition requested by it. The format for that URL is:
558 // chrome-guest://partition_domain/persist?partition_name
559 if (site.SchemeIs(chrome::kGuestScheme)) {
560 // Since guest URLs are only used for packaged apps, there must be an app
561 // id in the URL.
562 CHECK(site.has_host());
563 *partition_domain = site.host();
564 // Since persistence is optional, the path must either be empty or the
565 // literal string.
566 *in_memory = (site.path() != "/persist");
567 // The partition name is user supplied value, which we have encoded when the
568 // URL was created, so it needs to be decoded.
569 *partition_name = net::UnescapeURLComponent(site.query(),
570 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10571 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
572 // If |can_be_default| is false, the caller is stating that the |site|
573 // should be parsed as if it had isolated storage. In particular it is
574 // important to NOT check ExtensionService for the is_storage_isolated()
575 // attribute because this code path is run during Extension uninstall
576 // to do cleanup after the Extension has already been unloaded from the
577 // ExtensionService.
578 bool is_isolated = !can_be_default;
579 if (can_be_default) {
580 const Extension* extension = NULL;
581 Profile* profile = Profile::FromBrowserContext(browser_context);
582 ExtensionService* extension_service =
583 extensions::ExtensionSystem::Get(profile)->extension_service();
584 if (extension_service) {
585 extension = extension_service->extensions()->
586 GetExtensionOrAppByURL(ExtensionURLInfo(site));
587 if (extension && extension->is_storage_isolated()) {
588 is_isolated = true;
589 }
590 }
591 }
[email protected]1bc28312012-11-08 08:31:53592
[email protected]14acc642012-11-17 12:20:10593 if (is_isolated) {
594 CHECK(site.has_host());
595 // For extensions with isolated storage, the the host of the |site| is
596 // the |partition_domain|. The |in_memory| and |partition_name| are only
597 // used in guest schemes so they are cleared here.
598 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53599 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10600 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53601 }
[email protected]d1198fd2012-08-13 22:50:19602 }
603
[email protected]14acc642012-11-17 12:20:10604 // Assert that if |can_be_default| is false, the code above must have found a
605 // non-default partition. If this fails, the caller has a serious logic
606 // error about which StoragePartition they expect to be in and it is not
607 // safe to continue.
608 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44609}
610
[email protected]38b098f2012-03-14 21:11:57611content::WebContentsViewDelegate*
612 ChromeContentBrowserClient::GetWebContentsViewDelegate(
613 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27614 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32615}
616
[email protected]f364d1392011-04-08 21:03:10617void ChromeContentBrowserClient::RenderViewHostCreated(
618 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46619
[email protected]9f76c1e2012-03-05 15:15:58620 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46621 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02622 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46623
624 new ChromeRenderViewHostObserver(render_view_host,
625 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49626 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26627}
628
[email protected]44703cc72013-01-24 04:56:06629void ChromeContentBrowserClient::GuestWebContentsCreated(
630 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
631 Profile* profile = Profile::FromBrowserContext(
632 embedder_web_contents->GetBrowserContext());
633 ExtensionService* service =
634 extensions::ExtensionSystem::Get(profile)->extension_service();
635 if (!service)
636 return;
637 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
638 const Extension* extension = service->extensions()->
639 GetExtensionOrAppByURL(ExtensionURLInfo(url));
640 if (!extension)
641 return;
642 std::vector<ExtensionMsg_Loaded_Params> extensions;
643 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
644 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
645}
646
[email protected]f3b1a082011-11-18 00:34:30647void ChromeContentBrowserClient::RenderProcessHostCreated(
648 content::RenderProcessHost* host) {
649 int id = host->GetID();
650 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41651 net::URLRequestContextGetter* context =
652 profile->GetRequestContextForRenderProcess(id);
653
[email protected]f3b1a082011-11-18 00:34:30654 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41655 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55656#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30657 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55658#endif
[email protected]658677f2012-06-09 06:04:02659#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08660 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03661#endif
[email protected]f3b1a082011-11-18 00:34:30662 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02663 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30664 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56665#if defined(OS_MACOSX)
666 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
667#endif
[email protected]43535512013-02-20 20:41:41668 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
669 id, profile, context));
[email protected]2736c032012-05-11 18:06:07670 host->GetChannel()->AddFilter(
671 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38672
[email protected]2ccf45c2011-08-19 23:35:50673 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
674 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07675
676 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56677
678 RendererContentSettingRules rules;
679 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
680 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14681}
682
[email protected]3d7474ff2011-07-27 17:47:37683GURL ChromeContentBrowserClient::GetEffectiveURL(
684 content::BrowserContext* browser_context, const GURL& url) {
685 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52686 if (!profile)
687 return url;
688
[email protected]7c60f5042013-02-14 03:39:32689 // If the input |url| should be assigned to the Instant renderer, make its
690 // effective URL distinct from other URLs on the search provider's domain.
691 if (chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
692 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52693
694 // If the input |url| is part of an installed app, the effective URL is an
695 // extension URL with the ID of that extension as the host. This has the
696 // effect of grouping apps together in a common SiteInstance.
697 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13698 extensions::ExtensionSystem::Get(profile)->extension_service();
699 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08700 return url;
701
[email protected]06bdd2b2012-11-30 18:47:13702 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44703 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08704 if (!extension)
705 return url;
706
[email protected]15877ca2011-11-18 22:40:52707 // Bookmark apps do not use the hosted app process model, and should be
708 // treated as normal URLs.
709 if (extension->from_bookmark())
710 return url;
711
[email protected]36fb2c7c2011-04-04 15:49:08712 // If the URL is part of an extension's web extent, convert it to an
713 // extension URL.
714 return extension->GetResourceURL(url.path());
715}
716
[email protected]056ad2a2011-07-12 02:13:55717bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37718 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52719 // Non-extension, non-Instant URLs should generally use
720 // process-per-site-instance. Because we expect to use the effective URL,
721 // URLs for hosted apps (apart from bookmark apps) should have an extension
722 // scheme by now.
723
724 Profile* profile = Profile::FromBrowserContext(browser_context);
725 if (!profile)
726 return false;
727
[email protected]7c60f5042013-02-14 03:39:32728 if (chrome::search::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52729 return true;
730
[email protected]885c0e92012-11-13 20:27:42731 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55732 return false;
733
[email protected]c5dec6292013-01-25 04:54:52734 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13735 extensions::ExtensionSystem::Get(profile)->extension_service();
736 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55737 return false;
738
[email protected]06bdd2b2012-11-30 18:47:13739 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44740 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55741 if (!extension)
742 return false;
743
744 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53745 // permission, or that does not allow JavaScript access to the background
746 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55747 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40748 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06749 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53750 !extension->allow_background_js_access()) {
751 return false;
752 }
753 }
[email protected]056ad2a2011-07-12 02:13:55754
[email protected]7b54ca02012-03-02 18:06:53755 // Hosted apps that have script access to their background page must use
756 // process per site, since all instances can make synchronous calls to the
757 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55758 return true;
759}
760
[email protected]6bd30072013-02-08 18:17:11761net::URLRequestContextGetter*
762ChromeContentBrowserClient::CreateRequestContext(
763 content::BrowserContext* browser_context,
764 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
765 blob_protocol_handler,
766 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
767 file_system_protocol_handler,
768 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
769 developer_protocol_handler,
770 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
771 chrome_protocol_handler,
772 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
773 chrome_devtools_protocol_handler) {
774 Profile* profile = Profile::FromBrowserContext(browser_context);
775 return profile->CreateRequestContext(blob_protocol_handler.Pass(),
776 file_system_protocol_handler.Pass(),
777 developer_protocol_handler.Pass(),
778 chrome_protocol_handler.Pass(),
779 chrome_devtools_protocol_handler.Pass());
780}
781
782net::URLRequestContextGetter*
783ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
784 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40785 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11786 bool in_memory,
787 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
788 blob_protocol_handler,
789 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
790 file_system_protocol_handler,
791 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
792 developer_protocol_handler,
793 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
794 chrome_protocol_handler,
795 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
796 chrome_devtools_protocol_handler) {
797 Profile* profile = Profile::FromBrowserContext(browser_context);
798 return profile->CreateRequestContextForStoragePartition(
799 partition_path,
800 in_memory,
801 blob_protocol_handler.Pass(),
802 file_system_protocol_handler.Pass(),
803 developer_protocol_handler.Pass(),
804 chrome_protocol_handler.Pass(),
805 chrome_devtools_protocol_handler.Pass());
806}
807
[email protected]46fb9442011-12-09 17:57:47808bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
809 return ProfileIOData::IsHandledURL(url);
810}
811
[email protected]2a5221b2011-09-27 23:07:31812bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30813 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31814 const GURL& site_url) {
815 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30816 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52817 // This may be NULL during tests. In that case, just assume any site can
818 // share any host.
819 if (!profile)
820 return true;
821
822 InstantService* instant_service =
823 InstantServiceFactory::GetForProfile(profile);
824 if (instant_service &&
825 instant_service->IsInstantProcess(process_host->GetID()))
[email protected]7c60f5042013-02-14 03:39:32826 return chrome::search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]c5dec6292013-01-25 04:54:52827
[email protected]06bdd2b2012-11-30 18:47:13828 ExtensionService* service =
829 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46830 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31831
[email protected]ffa97602011-11-17 17:55:52832 // Don't allow the Task Manager to share a process with anything else.
833 // Otherwise it can affect the renderers it is observing.
834 // Note: we could create another RenderProcessHostPrivilege bucket for
835 // this to allow multiple chrome://tasks instances to share, but that's
836 // a very unlikely case without serious consequences.
837 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
838 return false;
839
[email protected]8d3132f62011-10-12 07:13:42840 // These may be NULL during tests. In that case, just assume any site can
841 // share any host.
[email protected]6f371442011-11-09 06:45:46842 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31843 return true;
844
[email protected]eec0b33c2011-12-05 22:09:45845 // Otherwise, just make sure the process privilege matches the privilege
846 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57847 RenderProcessHostPrivilege privilege_required =
848 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45849 return GetProcessPrivilege(process_host, process_map, service) ==
850 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31851}
852
[email protected]76411f412012-02-22 18:56:06853// This function is trying to limit the amount of processes used by extensions
854// with background pages. It uses a globally set percentage of processes to
855// run such extensions and if the limit is exceeded, it returns true, to
856// indicate to the content module to group extensions together.
857bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
858 content::BrowserContext* browser_context, const GURL& url) {
859 // It has to be a valid URL for us to check for an extension.
860 if (!url.is_valid())
861 return false;
862
863 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19864 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13865 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06866 if (!service)
867 return false;
868
869 // We have to have a valid extension with background page to proceed.
870 const Extension* extension =
871 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
872 if (!extension)
873 return false;
874 if (!extension->has_background_page())
875 return false;
876
877 std::set<int> process_ids;
878 size_t max_process_count =
879 content::RenderProcessHost::GetMaxRendererProcessCount();
880
881 // Go through all profiles to ensure we have total count of extension
882 // processes containing background pages, otherwise one profile can
883 // starve the other.
884 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
885 GetLoadedProfiles();
886 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03887 ExtensionProcessManager* epm =
888 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32889 for (ExtensionProcessManager::const_iterator iter =
890 epm->background_hosts().begin();
891 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13892 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32893 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06894 }
895 }
896
897 if (process_ids.size() >
898 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
899 return true;
900 }
901
902 return false;
903}
904
[email protected]6f371442011-11-09 06:45:46905void ChromeContentBrowserClient::SiteInstanceGotProcess(
906 SiteInstance* site_instance) {
907 CHECK(site_instance->HasProcess());
908
909 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02910 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52911 if (!profile)
912 return;
913
914 // Remember the ID of the Instant process to signal the renderer process
915 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]7c60f5042013-02-14 03:39:32916 if (chrome::search::ShouldAssignURLToInstantRenderer(
917 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52918 InstantService* instant_service =
919 InstantServiceFactory::GetForProfile(profile);
920 if (instant_service)
921 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
922 }
923
[email protected]06bdd2b2012-11-30 18:47:13924 ExtensionService* service =
925 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46926 if (!service)
927 return;
928
929 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44930 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59931 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46932 if (!extension)
933 return;
934
[email protected]6bc04fd82011-12-04 02:29:35935 service->process_map()->Insert(extension->id(),
936 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33937 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46938 BrowserThread::PostTask(
939 BrowserThread::IO, FROM_HERE,
940 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59941 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46942 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35943 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33944 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46945}
946
947void ChromeContentBrowserClient::SiteInstanceDeleting(
948 SiteInstance* site_instance) {
949 if (!site_instance->HasProcess())
950 return;
951
952 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02953 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13954 ExtensionService* service =
955 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46956 if (!service)
957 return;
958
959 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44960 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59961 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46962 if (!extension)
963 return;
964
[email protected]6bc04fd82011-12-04 02:29:35965 service->process_map()->Remove(extension->id(),
966 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33967 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46968 BrowserThread::PostTask(
969 BrowserThread::IO, FROM_HERE,
970 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59971 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46972 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35973 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33974 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46975}
976
[email protected]f05763972012-06-06 18:17:26977bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08978 const GURL& current_url,
979 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26980 if (current_url.is_empty()) {
981 // Always choose a new process when navigating to extension URLs. The
982 // process grouping logic will combine all of a given extension's pages
983 // into the same process.
[email protected]885c0e92012-11-13 20:27:42984 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:26985 return true;
[email protected]e3daf3c2011-10-05 21:17:08986
[email protected]f05763972012-06-06 18:17:26987 return false;
988 }
989
990 // Also, we must switch if one is an extension and the other is not the exact
991 // same extension.
[email protected]885c0e92012-11-13 20:27:42992 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
993 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:26994 if (current_url.GetOrigin() != new_url.GetOrigin())
995 return true;
996 }
997
998 return false;
[email protected]e3daf3c2011-10-05 21:17:08999}
1000
[email protected]395045c2012-05-22 15:04:381001bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1002 content::ResourceContext* resource_context, const GURL& current_url,
1003 const GURL& new_url) {
1004 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1005 return extensions::CrossesExtensionProcessBoundary(
1006 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171007 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381008}
1009
[email protected]763ec4ca2011-04-29 15:48:121010std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1011 const std::string& alias_name) {
1012 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1013}
1014
[email protected]b80f68432011-05-02 17:22:301015void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1016 CommandLine* command_line, int child_process_id) {
1017#if defined(USE_LINUX_BREAKPAD)
1018 if (IsCrashReporterEnabled()) {
1019 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1020 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1021 }
1022#elif defined(OS_MACOSX)
1023 if (IsCrashReporterEnabled()) {
1024 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1025 child_process_logging::GetClientId());
1026 }
1027#endif // OS_MACOSX
1028
[email protected]f1933792011-06-14 00:49:341029 if (logging::DialogsAreSuppressed())
1030 command_line->AppendSwitch(switches::kNoErrorDialogs);
1031
[email protected]b80f68432011-05-02 17:22:301032 std::string process_type =
1033 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171034 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:521035 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451036 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301037 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1038 if (!user_data_dir.empty())
1039 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1040#if defined(OS_CHROMEOS)
1041 const std::string& login_profile =
1042 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1043 if (!login_profile.empty())
1044 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1045#endif
1046
[email protected]f3b1a082011-11-18 00:34:301047 content::RenderProcessHost* process =
1048 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371049 if (process) {
1050 Profile* profile = Profile::FromBrowserContext(
1051 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131052 ExtensionService* extension_service =
1053 extensions::ExtensionSystem::Get(profile)->extension_service();
1054 if (extension_service) {
1055 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001056 if (process_map && process_map->Contains(process->GetID()))
1057 command_line->AppendSwitch(switches::kExtensionProcess);
1058 }
[email protected]b80f68432011-05-02 17:22:301059
[email protected]a8d851f82011-12-21 00:32:371060 PrefService* prefs = profile->GetPrefs();
1061 // Currently this pref is only registered if applied via a policy.
1062 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1063 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1064 // Turn this policy into a command line switch.
1065 command_line->AppendSwitch(switches::kDisable3DAPIs);
1066 }
[email protected]718eab62011-10-05 21:16:521067
[email protected]a8d851f82011-12-21 00:32:371068 // Disable client-side phishing detection in the renderer if it is
1069 // disabled in the Profile preferences or the browser process.
1070 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1071 !g_browser_process->safe_browsing_detection_service()) {
1072 command_line->AppendSwitch(
1073 switches::kDisableClientSidePhishingDetection);
1074 }
[email protected]0045b0f42012-07-26 11:52:081075
1076 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211077 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521078
1079 InstantService* instant_service =
1080 InstantServiceFactory::GetForProfile(profile);
1081 if (instant_service &&
1082 instant_service->IsInstantProcess(process->GetID()))
1083 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]47c7ec82012-01-18 03:29:211084 }
[email protected]4287a3d2011-06-13 23:56:511085
[email protected]87552982012-11-02 17:21:401086 if (content::IsThreadedCompositingEnabled())
1087 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1088
[email protected]47c7ec82012-01-18 03:29:211089 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511090 static const char* const kSwitchNames[] = {
1091 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481092 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511093 switches::kAllowScriptingGallery,
1094 switches::kAppsCheckoutURL,
1095 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311096 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511097 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501098 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531099 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111100 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511101 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211102 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511103 switches::kEnableCrxlessWebApps,
1104 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561105 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511106 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511107 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511108 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:481109 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051110 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511111 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511112 switches::kMemoryProfiling,
1113 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371114 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581115 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371116 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511117 switches::kPpapiFlashArgs,
1118 switches::kPpapiFlashInProcess,
1119 switches::kPpapiFlashPath,
1120 switches::kPpapiFlashVersion,
1121 switches::kProfilingAtStart,
1122 switches::kProfilingFile,
1123 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371124 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511125 switches::kSilentDumpOnDCHECK,
[email protected]c79d9492012-10-04 19:56:301126 switches::kSpdyProxyOrigin,
[email protected]a446534d2012-02-09 00:07:381127 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511128 };
1129
1130 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1131 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171132 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381133 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351134 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381135 switches::kEnableExperimentalExtensionApis,
1136 switches::kWhitelistedExtensionID,
1137 };
1138
1139 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1140 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511141 } else if (process_type == switches::kPluginProcess) {
1142 static const char* const kSwitchNames[] = {
1143 #if defined(OS_CHROMEOS)
1144 switches::kLoginProfile,
1145 #endif
1146 switches::kMemoryProfiling,
1147 switches::kSilentDumpOnDCHECK,
1148 switches::kUserDataDir,
1149 };
1150
1151 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1152 arraysize(kSwitchNames));
1153 } else if (process_type == switches::kZygoteProcess) {
1154 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511155 switches::kUserDataDir, // Make logs go to the right file.
1156 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501157 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511158 switches::kPpapiFlashInProcess,
1159 switches::kPpapiFlashPath,
1160 switches::kPpapiFlashVersion,
1161 };
1162
1163 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1164 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111165 } else if (process_type == switches::kGpuProcess) {
1166 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1167 // because GPU is expected to be unreliable.
1168 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1169 !command_line->HasSwitch(switches::kDisableBreakpad))
1170 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301171 }
[email protected]6f08af82011-09-15 01:19:031172
1173 // The command line switch kEnableBenchmarking needs to be specified along
1174 // with the kEnableStatsTable switch to ensure that the stats table global
1175 // is initialized correctly.
1176 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1177 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301178}
1179
1180std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431181 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1182 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301183 return g_browser_process->GetApplicationLocale();
1184}
1185
[email protected]597a867b2011-11-18 18:31:201186std::string ChromeContentBrowserClient::GetAcceptLangs(
1187 content::BrowserContext* context) {
1188 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371189 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081190}
1191
[email protected]9ec0f452012-05-31 15:58:531192gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221193 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531194 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081195}
1196
[email protected]a2176792011-05-08 19:30:491197bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091198 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191199 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201200 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201202 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051203 return io_data->GetCookieSettings()->
1204 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491205}
1206
[email protected]ed24fad2011-05-10 22:44:011207bool ChromeContentBrowserClient::AllowGetCookie(
1208 const GURL& url,
1209 const GURL& first_party,
1210 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201211 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011212 int render_process_id,
1213 int render_view_id) {
1214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201215 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051216 bool allow = io_data->GetCookieSettings()->
1217 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011218
[email protected]8093a542011-05-13 07:29:321219 BrowserThread::PostTask(
1220 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031221 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431222 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011223 return allow;
1224}
1225
1226bool ChromeContentBrowserClient::AllowSetCookie(
1227 const GURL& url,
1228 const GURL& first_party,
1229 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201230 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011231 int render_process_id,
1232 int render_view_id,
1233 net::CookieOptions* options) {
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 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1237 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1238
[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::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431242 render_view_id, url, first_party, cookie_line, *options,
1243 !allow));
[email protected]ed24fad2011-05-10 22:44:011244 return allow;
1245}
1246
[email protected]d5a19162011-06-30 18:51:541247bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201248 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201250 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431251 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1252 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261253
[email protected]bf510ed2012-06-05 08:31:431254 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1255 // Could we even support per-origin settings?
1256 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541257}
1258
[email protected]5c5a88e2011-11-12 00:45:351259bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351260 const GURL& url,
1261 const string16& name,
1262 const string16& display_name,
1263 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201264 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481265 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201267 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351268 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1269 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1270
[email protected]62151052012-02-01 18:40:481271 // Record access to database for potential display in UI.
1272 std::vector<std::pair<int, int> >::const_iterator i;
1273 for (i = render_views.begin(); i != render_views.end(); ++i) {
1274 BrowserThread::PostTask(
1275 BrowserThread::UI, FROM_HERE,
1276 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1277 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351278 }
1279
1280 return allow;
1281}
1282
1283bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351284 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201285 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481286 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201288 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351289 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1290 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1291
[email protected]62151052012-02-01 18:40:481292 // Record access to file system for potential display in UI.
1293 std::vector<std::pair<int, int> >::const_iterator i;
1294 for (i = render_views.begin(); i != render_views.end(); ++i) {
1295 BrowserThread::PostTask(
1296 BrowserThread::UI, FROM_HERE,
1297 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1298 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351299 }
1300
1301 return allow;
1302}
1303
[email protected]7c5ff9a2012-03-02 07:42:491304bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1305 const GURL& url,
1306 const string16& name,
1307 content::ResourceContext* context,
1308 const std::vector<std::pair<int, int> >& render_views) {
1309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1310 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1311 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1312 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1313
1314 // Record access to IndexedDB for potential display in UI.
1315 std::vector<std::pair<int, int> >::const_iterator i;
1316 for (i = render_views.begin(); i != render_views.end(); ++i) {
1317 BrowserThread::PostTask(
1318 BrowserThread::UI, FROM_HERE,
1319 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1320 i->first, i->second, url, name, !allow));
1321 }
1322
1323 return allow;
1324}
1325
[email protected]6133f922011-07-01 21:34:341326net::URLRequestContext*
1327ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201328 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421330 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201331 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341332 return io_data->extensions_request_context();
1333 }
1334
1335 return NULL;
1336}
1337
[email protected]317f96c92011-05-31 06:53:411338QuotaPermissionContext*
1339ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1340 return new ChromeQuotaPermissionContext();
1341}
1342
[email protected]848dd042011-06-04 18:24:031343void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171344 int render_process_id,
1345 int render_view_id,
1346 int cert_error,
1347 const net::SSLInfo& ssl_info,
1348 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031349 bool overridable,
[email protected]d9be47702012-05-16 03:41:221350 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171351 const base::Callback<void(bool)>& callback,
1352 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411353 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131354 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171355 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411356 if (!tab) {
1357 NOTREACHED();
1358 return;
1359 }
1360 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501361 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301362 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011363 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1364 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411365 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171366 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411367 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171368 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411369 return;
1370 }
1371 }
1372
[email protected]1e87df32012-09-12 04:53:191373#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231374 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1375 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1376 if (captive_portal_tab_helper)
1377 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191378#endif
1379
[email protected]f9034cf2011-07-21 12:43:411380 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221381 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1382 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031383}
1384
[email protected]c99c442e2011-08-24 11:37:301385void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451386 int render_process_id,
1387 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401388 const net::HttpNetworkSession* network_session,
1389 net::SSLCertRequestInfo* cert_request_info,
1390 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131391 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451392 render_process_id, render_view_id);
1393 if (!tab) {
1394 NOTREACHED();
1395 return;
1396 }
1397
[email protected]6786bf402011-12-03 15:19:451398 GURL requesting_url("https://" + cert_request_info->host_and_port);
1399 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1400 << cert_request_info->host_and_port;
1401
[email protected]627e0512011-12-21 22:55:301402 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451403 scoped_ptr<Value> filter(
1404 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1405 requesting_url,
1406 requesting_url,
1407 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1408 std::string(), NULL));
1409
1410 if (filter.get()) {
1411 // Try to automatically select a client certificate.
1412 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1413 DictionaryValue* filter_dict =
1414 static_cast<DictionaryValue*>(filter.get());
1415
1416 const std::vector<scoped_refptr<net::X509Certificate> >&
1417 all_client_certs = cert_request_info->client_certs;
1418 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1419 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1420 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401421 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451422 return;
1423 }
1424 }
1425 } else {
1426 NOTREACHED();
1427 }
1428 }
1429
[email protected]11feec322012-09-18 03:58:521430 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1431 if (!ssl_tab_helper) {
1432 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451433 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141434 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401435 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451436 return;
1437 }
[email protected]11feec322012-09-18 03:58:521438 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401439 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451440}
1441
[email protected]3b455502012-12-11 18:22:581442void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451443 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581444 net::CertificateMimeType cert_type,
1445 const void* cert_data,
1446 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451447 int render_process_id,
1448 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581449 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1450 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451451}
1452
[email protected]dc73a7b2012-03-25 15:27:181453content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561454 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181455}
1456
[email protected]941623e2011-06-07 23:06:041457void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1458 const GURL& source_origin,
1459 int callback_context,
1460 int render_process_id,
1461 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111462#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1464 WebContents* contents =
1465 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1466 if (!contents) {
[email protected]941623e2011-06-07 23:06:041467 NOTREACHED();
1468 return;
1469 }
1470
[email protected]d0d9c3ee2012-06-19 03:07:021471 // Skip showing the infobar if the request comes from an extension, and that
1472 // extension has the 'notify' permission. (If the extension does not have the
1473 // permission, the user will still be prompted.)
1474 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131475 ExtensionService* service =
1476 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021477 const Extension* extension = !service ? NULL :
1478 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1479 source_origin));
[email protected]eb4832a2012-12-08 01:57:521480 RenderViewHost* rvh =
1481 RenderViewHost::FromID(render_process_id, render_view_id);
1482 if (IsExtensionWithPermissionOrSuggestInConsole(
1483 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021484 if (rvh)
1485 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1486 return;
1487 }
1488
1489 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371490 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021491 notifications->RequestPermission(source_origin, render_process_id,
1492 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111493#else
1494 NOTIMPLEMENTED();
1495#endif
[email protected]941623e2011-06-07 23:06:041496}
1497
1498WebKit::WebNotificationPresenter::Permission
1499 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021500 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201501 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021502 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111503#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201505 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021506 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1507 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061508 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041509 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041510
1511 // Fall back to the regular notification preferences, which works on an
1512 // origin basis.
1513 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371514 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041515 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111516#else
1517 return WebKit::WebNotificationPresenter::PermissionAllowed;
1518#endif
[email protected]941623e2011-06-07 23:06:041519}
1520
1521void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171522 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041523 int render_process_id,
1524 int render_view_id,
1525 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111526#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041527 RenderViewHost* rvh = RenderViewHost::FromID(
1528 render_process_id, render_view_id);
1529 if (!rvh) {
1530 NOTREACHED();
1531 return;
1532 }
1533
[email protected]9f76c1e2012-03-05 15:15:581534 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301535 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041536 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371537 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041538 service->ShowDesktopNotification(
1539 params, render_process_id, render_view_id,
1540 worker ? DesktopNotificationService::WorkerNotification :
1541 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111542#else
1543 NOTIMPLEMENTED();
1544#endif
[email protected]941623e2011-06-07 23:06:041545}
1546
1547void ChromeContentBrowserClient::CancelDesktopNotification(
1548 int render_process_id,
1549 int render_view_id,
1550 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111551#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041552 RenderViewHost* rvh = RenderViewHost::FromID(
1553 render_process_id, render_view_id);
1554 if (!rvh) {
1555 NOTREACHED();
1556 return;
1557 }
1558
[email protected]9f76c1e2012-03-05 15:15:581559 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301560 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041561 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371562 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041563 service->CancelDesktopNotification(
1564 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111565#else
1566 NOTIMPLEMENTED();
1567#endif
[email protected]941623e2011-06-07 23:06:041568}
1569
[email protected]9f3fba52011-06-08 20:37:191570bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351571 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021572 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191573 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201574 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011575 int render_process_id,
1576 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011578
1579 *no_javascript_access = false;
1580
[email protected]9f3fba52011-06-08 20:37:191581 // If the opener is trying to create a background window but doesn't have
1582 // the appropriate permission, fail the attempt.
1583 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201584 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531585 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1586
[email protected]03b6d552012-03-29 04:03:011587 if (!map->SecurityOriginHasAPIPermission(
1588 source_origin,
1589 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061590 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011591 return false;
1592 }
1593
[email protected]7b54ca02012-03-02 18:06:531594 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1595 // return a recently installed Extension even if this CanCreateWindow call
1596 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011597 // because the permission check above would have caused an early return
1598 // already. We must use the full URL to find hosted apps, though, and not
1599 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531600 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351601 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531602 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011603 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191604 }
1605 return true;
1606}
1607
1608std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201609 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1611 // Check if it's an extension-created worker, in which case we want to use
1612 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201613 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191614 const Extension* extension =
1615 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1616 return extension ? extension->name() : std::string();
1617}
1618
[email protected]99907362012-01-11 05:41:401619void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1620 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171621}
1622
[email protected]c52b2892012-03-07 11:01:021623content::SpeechRecognitionManagerDelegate*
1624 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321625#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021626 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321627#else
1628 return NULL;
1629#endif
[email protected]66cfec62012-02-24 17:57:511630}
1631
[email protected]ae6e9912011-07-27 01:18:281632net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1633 return g_browser_process->net_log();
1634}
1635
[email protected]32538d92011-08-25 00:09:231636AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1637 return new ChromeAccessTokenStore();
1638}
1639
[email protected]dbae6b02011-06-29 23:51:411640bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011641 return true;
[email protected]dbae6b02011-06-29 23:51:411642}
1643
[email protected]64d69de42012-02-06 00:19:541644void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321645 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061646 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581647 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061648 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061649
[email protected]f3986f82012-01-03 20:00:061650 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541651 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061652 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541653 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061654 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541655 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061656 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541657 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061658 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541659 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061660 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541661 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031662 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1663 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061664
[email protected]64d69de42012-02-06 00:19:541665 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401666 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541667 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401668 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541669 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401670 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541671 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401672 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061673
[email protected]ddf72142012-05-22 04:52:401674 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061675
[email protected]64d69de42012-02-06 00:19:541676 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401677 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541678 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061679 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541680 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061681 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1682 const DictionaryValue* inspector_settings =
1683 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1684 if (inspector_settings) {
1685 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1686 iter != inspector_settings->end_keys(); ++iter) {
1687 std::string value;
1688 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541689 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061690 std::make_pair(*iter, value));
1691 }
1692 }
[email protected]64d69de42012-02-06 00:19:541693 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061694
[email protected]ddf72142012-05-22 04:52:401695 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541696 web_prefs->javascript_enabled = false;
1697 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1698 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401699 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541700 web_prefs->plugins_enabled = false;
1701 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1702 web_prefs->java_enabled = false;
1703 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401704 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061705
[email protected]64d69de42012-02-06 00:19:541706 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1707 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061708
[email protected]64d69de42012-02-06 00:19:541709 web_prefs->memory_info_enabled =
1710 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1711 web_prefs->allow_displaying_insecure_content =
1712 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1713 web_prefs->allow_running_insecure_content =
1714 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321715#if defined(OS_ANDROID)
1716 web_prefs->font_scale_factor =
1717 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1718 web_prefs->force_enable_zoom =
1719 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1720#endif
[email protected]9d06d88d2012-02-23 22:37:081721 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061722
[email protected]64d69de42012-02-06 00:19:541723 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151724 UserStyleSheetWatcher* user_style_sheet_watcher =
1725 UserStyleSheetWatcherFactory::GetForProfile(profile);
1726 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541727 web_prefs->user_style_sheet_enabled = true;
1728 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151729 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541730 } else {
1731 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061732 }
1733
[email protected]b7e44ff2012-02-16 03:37:341734 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101735#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031736 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101737 // Mac so it uses NSSpellChecker in the background.
1738 false;
1739#else
[email protected]61806872012-12-12 04:15:361740 true;
[email protected]37b928e2012-05-30 09:01:101741#endif
[email protected]b7e44ff2012-02-16 03:37:341742 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521743 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571744
[email protected]64d69de42012-02-06 00:19:541745 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061746 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541747 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061748 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541749 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061750 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1751
1752 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541753 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061754 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541755 web_prefs->default_encoding);
1756 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401757 prefs->ClearPref(prefs::kDefaultCharset);
1758 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061759 }
[email protected]64d69de42012-02-06 00:19:541760 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061761
[email protected]88ecf66d2012-12-11 22:53:471762 if (content::IsForceCompositingModeEnabled())
1763 web_prefs->force_compositing_mode = true;
1764
[email protected]299d7f12012-05-23 05:31:151765 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1766 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131767 ExtensionService* service =
1768 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061769 if (service) {
[email protected]1bc28312012-11-08 08:31:531770 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1771 const Extension* extension = service->extensions()->GetByID(url.host());
1772 // Ensure that we are only granting extension preferences to URLs with
1773 // the correct scheme. Without this check, chrome-guest:// schemes used by
1774 // webview tags as well as hosts that happen to match the id of an
1775 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421776 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531777 extension_webkit_preferences::SetPreferences(
1778 extension, view_type, web_prefs);
1779 }
[email protected]f3986f82012-01-03 20:00:061780 }
1781
[email protected]299d7f12012-05-23 05:31:151782 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541783 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151784 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061785 // Disable all kinds of acceleration for background pages.
1786 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541787 web_prefs->force_compositing_mode = false;
1788 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061789 }
[email protected]2e21fe292012-03-02 22:52:321790
1791#if defined(FILE_MANAGER_EXTENSION)
1792 // Override the default of suppressing HW compositing for WebUI pages for the
1793 // file manager, which is implemented using WebUI but wants HW acceleration
1794 // for video decode & render.
1795 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1796 web_prefs->accelerated_compositing_enabled = true;
1797 web_prefs->accelerated_2d_canvas_enabled = true;
1798 }
1799#endif
[email protected]181a95ee2011-07-12 19:26:361800}
1801
1802void ChromeContentBrowserClient::UpdateInspectorSetting(
1803 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061804 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581805 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061806 DictionaryPrefUpdate update(
1807 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1808 prefs::kWebKitInspectorSettings);
1809 DictionaryValue* inspector_settings = update.Get();
1810 inspector_settings->SetWithoutPathExpansion(key,
1811 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361812}
1813
1814void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061815 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581816 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061817 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1818 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361819}
1820
[email protected]b8148ac2011-07-13 22:03:251821void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1822 BrowserURLHandler* handler) {
1823 // Add the default URL handlers.
1824 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1825 BrowserURLHandler::null_handler());
1826 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1827 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1828
[email protected]b3adbd02011-11-30 22:23:271829 // about: handler. Must come before chrome: handler, since it will
1830 // rewrite about: urls to chrome: URLs and then expect chrome: to
1831 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251832 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1833 BrowserURLHandler::null_handler());
1834 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241835 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251836}
1837
1838void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371839 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581840 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471841 BrowsingDataRemover* remover =
1842 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551843 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1844 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251845 // BrowsingDataRemover takes care of deleting itself when done.
1846}
1847
1848void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371849 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581850 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471851 BrowsingDataRemover* remover =
1852 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231853 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551854 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251855 // BrowsingDataRemover takes care of deleting itself when done.
1856}
1857
[email protected]650b2d52013-02-10 03:41:451858base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321859 return download_util::GetDefaultDownloadDirectory();
1860}
1861
[email protected]c9b6eb62011-10-18 20:49:391862std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1863 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1864}
1865
[email protected]b7631cc2012-09-15 05:08:381866void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1867 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541868#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381869 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1870 scoped_ptr<ppapi::host::HostFactory>(
1871 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541872#endif
[email protected]b7631cc2012-09-15 05:08:381873}
1874
[email protected]0c7193742012-11-07 19:05:031875content::BrowserPpapiHost*
1876 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1877 int plugin_process_id) {
1878 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1879 while (!iter.Done()) {
1880 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1881 if (host->process() &&
1882 host->process()->GetData().id == plugin_process_id) {
1883 // Found the plugin.
1884 return host->browser_ppapi_host();
1885 }
1886 ++iter;
1887 }
1888 return NULL;
1889}
1890
[email protected]38cd8f7f2012-06-15 22:06:071891bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581892 content::BrowserContext* browser_context,
1893 const GURL& url,
1894 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291895 if (!url.is_valid())
1896 return false;
1897
1898 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421899 if (url.SchemeIs(extensions::kExtensionScheme) &&
1900 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291901 return true;
[email protected]885c0e92012-11-13 20:27:421902 }
[email protected]a658d452012-03-02 12:45:291903
[email protected]9a5940d2012-04-27 19:16:231904 Profile* profile = Profile::FromBrowserContext(browser_context);
1905 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191906 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131907 extensions::ExtensionSystem::Get(profile)->extension_service();
1908 if (extension_service) {
1909 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231910 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1911 }
1912
[email protected]f237c0f2012-03-10 07:49:101913 // Need to check this now and not on construction because otherwise it won't
1914 // work with browser_tests.
1915 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1916 std::string allowed_list =
1917 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231918 if (allowed_list == "*") {
1919 // The wildcard allows socket API only for packaged and platform apps.
1920 return extension &&
[email protected]1d5e58b2013-01-31 08:41:401921 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
1922 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:231923 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:391924 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:101925 while (t.GetNext()) {
1926 if (t.token() == host)
1927 return true;
1928 }
1929 }
1930
[email protected]a658d452012-03-02 12:45:291931 if (!extension)
1932 return false;
1933
[email protected]157cc902012-11-02 06:31:581934 extensions::SocketPermission::CheckParam extension_params(
1935 params.type, params.host, params.port);
1936 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1937 &extension_params))
[email protected]a658d452012-03-02 12:45:291938 return true;
1939
1940 return false;
[email protected]e461da2f2012-02-16 19:06:401941}
1942
[email protected]650b2d52013-02-10 03:41:451943base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
1944 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:141945 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
1946 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
1947}
1948
[email protected]a28e3302013-02-03 03:50:431949ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
1950 WebContents* web_contents) {
1951 return new ChromeSelectFilePolicy(web_contents);
1952}
1953
[email protected]e60c0232011-11-11 19:56:351954#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181955void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1956 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:381957 int child_process_id,
[email protected]c7abd422012-09-25 00:20:081958 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:391959#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:451960 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:391961 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
1962 DCHECK(!data_path.empty());
1963
1964 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:451965 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:391966 base::PlatformFile f =
1967 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
1968 DCHECK(f != base::kInvalidPlatformFileValue);
1969 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
1970 FileDescriptor(f, true)));
1971
[email protected]650b2d52013-02-10 03:41:451972 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:391973 data_path.AppendASCII("chrome_100_percent.pak");
1974 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
1975 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:371976 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:391977 FileDescriptor(f, true)));
1978
1979 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:451980 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:391981 GetLocaleFilePath(locale, false);
1982 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
1983 DCHECK(f != base::kInvalidPlatformFileValue);
1984 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
1985 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:381986
[email protected]650b2d52013-02-10 03:41:451987 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:371988 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
1989 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
1990 DCHECK(f != base::kInvalidPlatformFileValue);
1991 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
1992 FileDescriptor(f, true)));
1993
[email protected]40da3e0c2012-10-24 22:03:381994#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:431995 if (IsCrashReporterEnabled()) {
1996 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
1997 if (f == base::kInvalidPlatformFileValue) {
1998 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
1999 "be disabled for this process.";
2000 } else {
2001 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2002 FileDescriptor(f, true)));
2003 }
[email protected]40da3e0c2012-10-24 22:03:382004 }
2005#endif // defined(USE_LINUX_BREAKPAD)
2006
2007#else
2008 int crash_signal_fd = GetCrashSignalFD(command_line);
2009 if (crash_signal_fd >= 0) {
2010 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2011 FileDescriptor(crash_signal_fd,
2012 false)));
2013 }
[email protected]29699c22012-10-03 23:57:392014#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302015}
[email protected]e60c0232011-11-11 19:56:352016#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302017
[email protected]4a65826d2011-08-25 16:04:012018#if defined(OS_WIN)
2019const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2020 return chrome::kBrowserResourcesDll;
2021}
2022#endif
2023
[email protected]37a72af2011-06-13 05:42:012024#if defined(USE_NSS)
2025crypto::CryptoModuleBlockingPasswordDelegate*
2026 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2027 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292028 return chrome::NewCryptoModuleBlockingDialogDelegate(
2029 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012030}
2031#endif
2032
[email protected]e9a32a52012-06-14 23:32:432033void ChromeContentBrowserClient::SetApplicationLocale(
2034 const std::string& locale) {
2035 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2036
2037 // This object is guaranteed to outlive all threads so we don't have to
2038 // worry about the lack of refcounting and can just post as Unretained.
2039 //
2040 // The common case is that this function is called early in Chrome startup
2041 // before any threads are created (it will also be called later if the user
2042 // changes the pref). In this case, there will be no threads created and
2043 // posting will fail. When there are no threads, we can just set the string
2044 // without worrying about threadsafety.
2045 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2046 base::Bind(
2047 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2048 base::Unretained(this), locale)))
2049 io_thread_application_locale_ = locale;
2050}
2051
2052void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2053 const std::string& locale) {
2054 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2055 io_thread_application_locale_ = locale;
2056}
2057
[email protected]d977f9c2011-03-14 16:10:262058} // namespace chrome