blob: 78e9939d38cc003068921a9791fd538180182f71 [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]f4ebe772013-02-02 00:21:3914#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0615#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3016#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2517#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3018#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4719#include "chrome/browser/browsing_data/browsing_data_helper.h"
20#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1221#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0322#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4123#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5624#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0525#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4526#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3227#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0828#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3229#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1630#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0631#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0432#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3333#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2634#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0835#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2536#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0637#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4938#include "chrome/browser/extensions/message_handler.h"
[email protected]eb4832a2012-12-08 01:57:5239#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2340#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1241#include "chrome/browser/google/google_util.h"
[email protected]c5dec6292013-01-25 04:54:5242#include "chrome/browser/instant/instant_service.h"
43#include "chrome/browser/instant/instant_service_factory.h"
[email protected]11158e2d2013-02-01 02:31:5644#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]0c7193742012-11-07 19:05:0345#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2846#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0447#include "chrome/browser/notifications/desktop_notification_service.h"
48#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4249#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5650#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]763ec4ca2011-04-29 15:48:1251#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0652#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4153#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5054#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0755#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4156#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1457#include "chrome/browser/printing/printing_message_filter.h"
58#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3259#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0660#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3362#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3863#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]05fcf982011-04-19 00:44:1464#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c5dec6292013-01-25 04:54:5265#include "chrome/browser/search_engines/template_url_service.h"
66#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]c52b2892012-03-07 11:01:0267#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4668#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5869#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0370#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5271#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4572#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5473#include "chrome/browser/toolkit_extra_parts.h"
[email protected]00ebd5d2013-02-01 03:32:0174#include "chrome/browser/ui/chrome_select_file_policy.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]c5dec6292013-01-25 04:54:52409// TODO(dhollowa): http://crbug.com/170390 This test exists in different places
410// in Chrome. Follow-up to consolidate these various Instant URL checks.
411// Returns true if |url| has the same scheme, host, and path as the instant URL
412// set via --instant-url.
413bool IsForcedInstantURL(const GURL& url) {
414 CommandLine* command_line = CommandLine::ForCurrentProcess();
415 if (command_line->HasSwitch(switches::kInstantURL)) {
416 GURL instant_url(command_line->GetSwitchValueASCII(switches::kInstantURL));
417 if (url.scheme() == instant_url.scheme() &&
418 url.host() == instant_url.host() &&
419 url.path() == instant_url.path()) {
420 return true;
421 }
422 }
423 return false;
424}
425
426// Determines whether the |url| is an Instant url for the default search
427// provider (set for the |profile|).
428// Also returns true if an Instant "effective url" (see below) is passed in.
429bool IsInstantURL(const GURL& url, Profile* profile) {
430 // Handle the command-line URL.
431 if (IsForcedInstantURL(url))
432 return true;
433
434 // A URL of this form has already be determined to be an Instant url,
435 // this is its "effective url". So trivially return true.
436 if (url.SchemeIs(chrome::kChromeSearchScheme))
437 return true;
438
439 TemplateURLService* template_url_service =
440 TemplateURLServiceFactory::GetForProfile(profile);
441 if (!template_url_service)
442 return false;
443
444 TemplateURL* template_url = template_url_service->GetDefaultSearchProvider();
445 if (!template_url)
446 return false;
447
448 if (template_url->instant_url().empty())
449 return false;
450
451 return template_url->IsInstantURL(url);
452}
453
454// Transforms the input |url| into its "effective url". The returned url
455// facilitates grouping process-per-site. The |url| is transformed, for
456// example, from
457//
458// https://www.google.com/search?espv=1&q=tractors
459//
460// to the effective url
461//
462// chrome-search://www.google.com/search?espv=1&q=tractors
463//
464// Notice the scheme change.
465// If the input is already an effective url then that same url is
466// returned.
467GURL GetEffectiveInstantURL(const GURL& url, Profile* profile) {
468 CHECK(IsInstantURL(url, profile)) << "Error granting Instant access.";
469
470 if (url.SchemeIs(chrome::kChromeSearchScheme))
471 return url;
472
473 GURL effective_url(url);
474
475 // Replace the scheme with "chrome-search:".
476 url_canon::Replacements<char> replacements;
477 std::string search_scheme(chrome::kChromeSearchScheme);
478 replacements.SetScheme(search_scheme.data(),
479 url_parse::Component(0, search_scheme.length()));
480 effective_url = effective_url.ReplaceComponents(replacements);
481 return effective_url;
482}
483
[email protected]9dbfff12011-07-01 19:37:07484} // namespace
[email protected]c5dbef02011-05-13 05:06:09485
[email protected]d977f9c2011-03-14 16:10:26486namespace chrome {
487
[email protected]e461da2f2012-02-16 19:06:40488ChromeContentBrowserClient::ChromeContentBrowserClient() {
489 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
490 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40491}
492
493ChromeContentBrowserClient::~ChromeContentBrowserClient() {
494}
495
[email protected]bca18382012-06-25 19:15:23496// static
[email protected]5b199522012-12-22 17:24:44497void ChromeContentBrowserClient::RegisterUserPrefs(PrefServiceSyncable* prefs) {
[email protected]bca18382012-06-25 19:15:23498 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
499 false,
[email protected]5b199522012-12-22 17:24:44500 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23501 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
502 true,
[email protected]5b199522012-12-22 17:24:44503 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23504 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
505 false,
[email protected]5b199522012-12-22 17:24:44506 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23507}
508
[email protected]50462bf02011-11-21 19:13:31509content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
510 const content::MainFunctionParams& parameters) {
511 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30512 // Construct the Main browser parts based on the OS type.
513#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31514 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04515#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31516 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30517#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22518 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26519#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31520 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14521#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09522 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30523#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31524 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04525#else
[email protected]b48c9182011-10-26 18:03:30526 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31527 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30528#endif
529
[email protected]c7480942011-11-08 19:18:27530 // Construct additional browser parts. Stages are called in the order in
531 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22532#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41533 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04534#endif
[email protected]c7480942011-11-08 19:18:27535
536#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41537 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27538#endif
539
[email protected]dc04be7c2012-03-15 23:57:49540#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41541 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49542#endif
543
[email protected]e050ef142012-03-21 01:04:24544#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41545 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24546#endif
547
[email protected]50462bf02011-11-21 19:13:31548 return main_parts;
[email protected]f967b722011-09-07 00:58:04549}
550
[email protected]38b098f2012-03-14 21:11:57551content::WebContentsView*
552 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57553 WebContents* web_contents,
554 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57555 return NULL;
556}
557
[email protected]e94bbcb2012-09-07 05:33:57558std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19559 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57560 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53561 std::string partition_id;
562
563 // The partition ID for webview guest processes is the string value of its
564 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
565 if (site.SchemeIs(chrome::kGuestScheme))
566 partition_id = site.spec();
567
568 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
569 return partition_id;
570}
571
572bool ChromeContentBrowserClient::IsValidStoragePartitionId(
573 content::BrowserContext* browser_context,
574 const std::string& partition_id) {
575 // The default ID is empty and is always valid.
576 if (partition_id.empty())
577 return true;
578
579 return GURL(partition_id).is_valid();
580}
581
582void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
583 content::BrowserContext* browser_context,
584 const GURL& site,
[email protected]14acc642012-11-17 12:20:10585 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53586 std::string* partition_domain,
587 std::string* partition_name,
588 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10589 // Default to the browser-wide storage partition and override based on |site|
590 // below.
591 partition_domain->clear();
592 partition_name->clear();
593 *in_memory = false;
594
[email protected]1bc28312012-11-08 08:31:53595 // For the webview tag, we create special guest processes, which host the
596 // tag content separately from the main application that embeds the tag.
597 // A webview tag can specify both the partition name and whether the storage
598 // for that partition should be persisted. Each tag gets a SiteInstance with
599 // a specially formatted URL, based on the application it is hosted by and
600 // the partition requested by it. The format for that URL is:
601 // chrome-guest://partition_domain/persist?partition_name
602 if (site.SchemeIs(chrome::kGuestScheme)) {
603 // Since guest URLs are only used for packaged apps, there must be an app
604 // id in the URL.
605 CHECK(site.has_host());
606 *partition_domain = site.host();
607 // Since persistence is optional, the path must either be empty or the
608 // literal string.
609 *in_memory = (site.path() != "/persist");
610 // The partition name is user supplied value, which we have encoded when the
611 // URL was created, so it needs to be decoded.
612 *partition_name = net::UnescapeURLComponent(site.query(),
613 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10614 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
615 // If |can_be_default| is false, the caller is stating that the |site|
616 // should be parsed as if it had isolated storage. In particular it is
617 // important to NOT check ExtensionService for the is_storage_isolated()
618 // attribute because this code path is run during Extension uninstall
619 // to do cleanup after the Extension has already been unloaded from the
620 // ExtensionService.
621 bool is_isolated = !can_be_default;
622 if (can_be_default) {
623 const Extension* extension = NULL;
624 Profile* profile = Profile::FromBrowserContext(browser_context);
625 ExtensionService* extension_service =
626 extensions::ExtensionSystem::Get(profile)->extension_service();
627 if (extension_service) {
628 extension = extension_service->extensions()->
629 GetExtensionOrAppByURL(ExtensionURLInfo(site));
630 if (extension && extension->is_storage_isolated()) {
631 is_isolated = true;
632 }
633 }
634 }
[email protected]1bc28312012-11-08 08:31:53635
[email protected]14acc642012-11-17 12:20:10636 if (is_isolated) {
637 CHECK(site.has_host());
638 // For extensions with isolated storage, the the host of the |site| is
639 // the |partition_domain|. The |in_memory| and |partition_name| are only
640 // used in guest schemes so they are cleared here.
641 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53642 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10643 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53644 }
[email protected]d1198fd2012-08-13 22:50:19645 }
646
[email protected]14acc642012-11-17 12:20:10647 // Assert that if |can_be_default| is false, the code above must have found a
648 // non-default partition. If this fails, the caller has a serious logic
649 // error about which StoragePartition they expect to be in and it is not
650 // safe to continue.
651 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44652}
653
[email protected]38b098f2012-03-14 21:11:57654content::WebContentsViewDelegate*
655 ChromeContentBrowserClient::GetWebContentsViewDelegate(
656 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27657 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32658}
659
[email protected]f364d1392011-04-08 21:03:10660void ChromeContentBrowserClient::RenderViewHostCreated(
661 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46662
[email protected]9f76c1e2012-03-05 15:15:58663 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46664 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02665 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46666
667 new ChromeRenderViewHostObserver(render_view_host,
668 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49669 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26670}
671
[email protected]44703cc72013-01-24 04:56:06672void ChromeContentBrowserClient::GuestWebContentsCreated(
673 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
674 Profile* profile = Profile::FromBrowserContext(
675 embedder_web_contents->GetBrowserContext());
676 ExtensionService* service =
677 extensions::ExtensionSystem::Get(profile)->extension_service();
678 if (!service)
679 return;
680 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
681 const Extension* extension = service->extensions()->
682 GetExtensionOrAppByURL(ExtensionURLInfo(url));
683 if (!extension)
684 return;
685 std::vector<ExtensionMsg_Loaded_Params> extensions;
686 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
687 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
688}
689
[email protected]f3b1a082011-11-18 00:34:30690void ChromeContentBrowserClient::RenderProcessHostCreated(
691 content::RenderProcessHost* host) {
692 int id = host->GetID();
693 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
694 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02695 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]ebd71962012-12-20 02:56:55696#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30697 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55698#endif
[email protected]658677f2012-06-09 06:04:02699#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08700 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03701#endif
[email protected]f3b1a082011-11-18 00:34:30702 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02703 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30704 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56705#if defined(OS_MACOSX)
706 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
707#endif
[email protected]f3b1a082011-11-18 00:34:30708 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03709 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07710 host->GetChannel()->AddFilter(
711 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38712
[email protected]2ccf45c2011-08-19 23:35:50713 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
714 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07715
716 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56717
718 RendererContentSettingRules rules;
719 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
720 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14721}
722
[email protected]3d7474ff2011-07-27 17:47:37723GURL ChromeContentBrowserClient::GetEffectiveURL(
724 content::BrowserContext* browser_context, const GURL& url) {
725 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52726 if (!profile)
727 return url;
728
729 // If the input |url| is an Instant url, make its effective url distinct from
730 // other urls on the search provider's domain.
731 if (IsInstantURL(url, profile))
732 return GetEffectiveInstantURL(url, profile);
733
734 // If the input |url| is part of an installed app, the effective URL is an
735 // extension URL with the ID of that extension as the host. This has the
736 // effect of grouping apps together in a common SiteInstance.
737 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13738 extensions::ExtensionSystem::Get(profile)->extension_service();
739 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08740 return url;
741
[email protected]06bdd2b2012-11-30 18:47:13742 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44743 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08744 if (!extension)
745 return url;
746
[email protected]15877ca2011-11-18 22:40:52747 // Bookmark apps do not use the hosted app process model, and should be
748 // treated as normal URLs.
749 if (extension->from_bookmark())
750 return url;
751
[email protected]36fb2c7c2011-04-04 15:49:08752 // If the URL is part of an extension's web extent, convert it to an
753 // extension URL.
754 return extension->GetResourceURL(url.path());
755}
756
[email protected]056ad2a2011-07-12 02:13:55757bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37758 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52759 // Non-extension, non-Instant URLs should generally use
760 // process-per-site-instance. Because we expect to use the effective URL,
761 // URLs for hosted apps (apart from bookmark apps) should have an extension
762 // scheme by now.
763
764 Profile* profile = Profile::FromBrowserContext(browser_context);
765 if (!profile)
766 return false;
767
768 if (IsInstantURL(effective_url, profile))
769 return true;
770
[email protected]885c0e92012-11-13 20:27:42771 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55772 return false;
773
[email protected]c5dec6292013-01-25 04:54:52774 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13775 extensions::ExtensionSystem::Get(profile)->extension_service();
776 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55777 return false;
778
[email protected]06bdd2b2012-11-30 18:47:13779 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44780 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55781 if (!extension)
782 return false;
783
784 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53785 // permission, or that does not allow JavaScript access to the background
786 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55787 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40788 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06789 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53790 !extension->allow_background_js_access()) {
791 return false;
792 }
793 }
[email protected]056ad2a2011-07-12 02:13:55794
[email protected]7b54ca02012-03-02 18:06:53795 // Hosted apps that have script access to their background page must use
796 // process per site, since all instances can make synchronous calls to the
797 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55798 return true;
799}
800
[email protected]46fb9442011-12-09 17:57:47801bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
802 return ProfileIOData::IsHandledURL(url);
803}
804
[email protected]2a5221b2011-09-27 23:07:31805bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30806 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31807 const GURL& site_url) {
808 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30809 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52810 // This may be NULL during tests. In that case, just assume any site can
811 // share any host.
812 if (!profile)
813 return true;
814
815 InstantService* instant_service =
816 InstantServiceFactory::GetForProfile(profile);
817 if (instant_service &&
818 instant_service->IsInstantProcess(process_host->GetID()))
819 return IsInstantURL(site_url, profile);
820
[email protected]06bdd2b2012-11-30 18:47:13821 ExtensionService* service =
822 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46823 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31824
[email protected]ffa97602011-11-17 17:55:52825 // Don't allow the Task Manager to share a process with anything else.
826 // Otherwise it can affect the renderers it is observing.
827 // Note: we could create another RenderProcessHostPrivilege bucket for
828 // this to allow multiple chrome://tasks instances to share, but that's
829 // a very unlikely case without serious consequences.
830 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
831 return false;
832
[email protected]8d3132f62011-10-12 07:13:42833 // These may be NULL during tests. In that case, just assume any site can
834 // share any host.
[email protected]6f371442011-11-09 06:45:46835 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31836 return true;
837
[email protected]eec0b33c2011-12-05 22:09:45838 // Otherwise, just make sure the process privilege matches the privilege
839 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57840 RenderProcessHostPrivilege privilege_required =
841 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45842 return GetProcessPrivilege(process_host, process_map, service) ==
843 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31844}
845
[email protected]76411f412012-02-22 18:56:06846// This function is trying to limit the amount of processes used by extensions
847// with background pages. It uses a globally set percentage of processes to
848// run such extensions and if the limit is exceeded, it returns true, to
849// indicate to the content module to group extensions together.
850bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
851 content::BrowserContext* browser_context, const GURL& url) {
852 // It has to be a valid URL for us to check for an extension.
853 if (!url.is_valid())
854 return false;
855
856 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19857 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13858 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06859 if (!service)
860 return false;
861
862 // We have to have a valid extension with background page to proceed.
863 const Extension* extension =
864 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
865 if (!extension)
866 return false;
867 if (!extension->has_background_page())
868 return false;
869
870 std::set<int> process_ids;
871 size_t max_process_count =
872 content::RenderProcessHost::GetMaxRendererProcessCount();
873
874 // Go through all profiles to ensure we have total count of extension
875 // processes containing background pages, otherwise one profile can
876 // starve the other.
877 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
878 GetLoadedProfiles();
879 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03880 ExtensionProcessManager* epm =
881 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32882 for (ExtensionProcessManager::const_iterator iter =
883 epm->background_hosts().begin();
884 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13885 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32886 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06887 }
888 }
889
890 if (process_ids.size() >
891 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
892 return true;
893 }
894
895 return false;
896}
897
[email protected]6f371442011-11-09 06:45:46898void ChromeContentBrowserClient::SiteInstanceGotProcess(
899 SiteInstance* site_instance) {
900 CHECK(site_instance->HasProcess());
901
902 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02903 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52904 if (!profile)
905 return;
906
907 // Remember the ID of the Instant process to signal the renderer process
908 // on startup in |AppendExtraCommandLineSwitches| below.
909 if (IsInstantURL(site_instance->GetSiteURL(), profile)) {
910 InstantService* instant_service =
911 InstantServiceFactory::GetForProfile(profile);
912 if (instant_service)
913 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
914 }
915
[email protected]06bdd2b2012-11-30 18:47:13916 ExtensionService* service =
917 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46918 if (!service)
919 return;
920
921 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44922 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59923 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46924 if (!extension)
925 return;
926
[email protected]6bc04fd82011-12-04 02:29:35927 service->process_map()->Insert(extension->id(),
928 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33929 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46930 BrowserThread::PostTask(
931 BrowserThread::IO, FROM_HERE,
932 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59933 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46934 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35935 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33936 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46937}
938
939void ChromeContentBrowserClient::SiteInstanceDeleting(
940 SiteInstance* site_instance) {
941 if (!site_instance->HasProcess())
942 return;
943
944 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02945 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13946 ExtensionService* service =
947 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46948 if (!service)
949 return;
950
951 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44952 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59953 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46954 if (!extension)
955 return;
956
[email protected]6bc04fd82011-12-04 02:29:35957 service->process_map()->Remove(extension->id(),
958 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33959 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46960 BrowserThread::PostTask(
961 BrowserThread::IO, FROM_HERE,
962 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59963 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46964 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35965 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33966 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46967}
968
[email protected]f05763972012-06-06 18:17:26969bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08970 const GURL& current_url,
971 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26972 if (current_url.is_empty()) {
973 // Always choose a new process when navigating to extension URLs. The
974 // process grouping logic will combine all of a given extension's pages
975 // into the same process.
[email protected]885c0e92012-11-13 20:27:42976 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:26977 return true;
[email protected]e3daf3c2011-10-05 21:17:08978
[email protected]f05763972012-06-06 18:17:26979 return false;
980 }
981
982 // Also, we must switch if one is an extension and the other is not the exact
983 // same extension.
[email protected]885c0e92012-11-13 20:27:42984 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
985 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:26986 if (current_url.GetOrigin() != new_url.GetOrigin())
987 return true;
988 }
989
990 return false;
[email protected]e3daf3c2011-10-05 21:17:08991}
992
[email protected]395045c2012-05-22 15:04:38993bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
994 content::ResourceContext* resource_context, const GURL& current_url,
995 const GURL& new_url) {
996 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
997 return extensions::CrossesExtensionProcessBoundary(
998 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17999 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381000}
1001
[email protected]763ec4ca2011-04-29 15:48:121002std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1003 const std::string& alias_name) {
1004 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1005}
1006
[email protected]b80f68432011-05-02 17:22:301007void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1008 CommandLine* command_line, int child_process_id) {
1009#if defined(USE_LINUX_BREAKPAD)
1010 if (IsCrashReporterEnabled()) {
1011 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1012 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1013 }
1014#elif defined(OS_MACOSX)
1015 if (IsCrashReporterEnabled()) {
1016 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1017 child_process_logging::GetClientId());
1018 }
1019#endif // OS_MACOSX
1020
[email protected]f1933792011-06-14 00:49:341021 if (logging::DialogsAreSuppressed())
1022 command_line->AppendSwitch(switches::kNoErrorDialogs);
1023
[email protected]b80f68432011-05-02 17:22:301024 std::string process_type =
1025 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171026 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:521027 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301028 FilePath user_data_dir =
1029 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1030 if (!user_data_dir.empty())
1031 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1032#if defined(OS_CHROMEOS)
1033 const std::string& login_profile =
1034 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1035 if (!login_profile.empty())
1036 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1037#endif
1038
[email protected]f3b1a082011-11-18 00:34:301039 content::RenderProcessHost* process =
1040 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371041 if (process) {
1042 Profile* profile = Profile::FromBrowserContext(
1043 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131044 ExtensionService* extension_service =
1045 extensions::ExtensionSystem::Get(profile)->extension_service();
1046 if (extension_service) {
1047 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001048 if (process_map && process_map->Contains(process->GetID()))
1049 command_line->AppendSwitch(switches::kExtensionProcess);
1050 }
[email protected]b80f68432011-05-02 17:22:301051
[email protected]a8d851f82011-12-21 00:32:371052 PrefService* prefs = profile->GetPrefs();
1053 // Currently this pref is only registered if applied via a policy.
1054 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1055 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1056 // Turn this policy into a command line switch.
1057 command_line->AppendSwitch(switches::kDisable3DAPIs);
1058 }
[email protected]718eab62011-10-05 21:16:521059
[email protected]a8d851f82011-12-21 00:32:371060 // Disable client-side phishing detection in the renderer if it is
1061 // disabled in the Profile preferences or the browser process.
1062 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1063 !g_browser_process->safe_browsing_detection_service()) {
1064 command_line->AppendSwitch(
1065 switches::kDisableClientSidePhishingDetection);
1066 }
[email protected]0045b0f42012-07-26 11:52:081067
1068 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211069 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521070
1071 InstantService* instant_service =
1072 InstantServiceFactory::GetForProfile(profile);
1073 if (instant_service &&
1074 instant_service->IsInstantProcess(process->GetID()))
1075 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]47c7ec82012-01-18 03:29:211076 }
[email protected]4287a3d2011-06-13 23:56:511077
[email protected]87552982012-11-02 17:21:401078 if (content::IsThreadedCompositingEnabled())
1079 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1080
[email protected]47c7ec82012-01-18 03:29:211081 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511082 static const char* const kSwitchNames[] = {
1083 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481084 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511085 switches::kAllowScriptingGallery,
1086 switches::kAppsCheckoutURL,
1087 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311088 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511089 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501090 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531091 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111092 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511093 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211094 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511095 switches::kEnableCrxlessWebApps,
1096 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511097 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511098 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511099 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:481100 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051101 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511102 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511103 switches::kMemoryProfiling,
1104 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371105 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581106 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371107 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511108 switches::kPpapiFlashArgs,
1109 switches::kPpapiFlashInProcess,
1110 switches::kPpapiFlashPath,
1111 switches::kPpapiFlashVersion,
1112 switches::kProfilingAtStart,
1113 switches::kProfilingFile,
1114 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371115 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511116 switches::kSilentDumpOnDCHECK,
[email protected]c79d9492012-10-04 19:56:301117 switches::kSpdyProxyOrigin,
[email protected]a446534d2012-02-09 00:07:381118 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511119 };
1120
1121 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1122 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171123 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381124 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351125 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381126 switches::kEnableExperimentalExtensionApis,
1127 switches::kWhitelistedExtensionID,
1128 };
1129
1130 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1131 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511132 } else if (process_type == switches::kPluginProcess) {
1133 static const char* const kSwitchNames[] = {
1134 #if defined(OS_CHROMEOS)
1135 switches::kLoginProfile,
1136 #endif
1137 switches::kMemoryProfiling,
1138 switches::kSilentDumpOnDCHECK,
1139 switches::kUserDataDir,
1140 };
1141
1142 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1143 arraysize(kSwitchNames));
1144 } else if (process_type == switches::kZygoteProcess) {
1145 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511146 switches::kUserDataDir, // Make logs go to the right file.
1147 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501148 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511149 switches::kPpapiFlashInProcess,
1150 switches::kPpapiFlashPath,
1151 switches::kPpapiFlashVersion,
1152 };
1153
1154 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1155 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111156 } else if (process_type == switches::kGpuProcess) {
1157 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1158 // because GPU is expected to be unreliable.
1159 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1160 !command_line->HasSwitch(switches::kDisableBreakpad))
1161 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301162 }
[email protected]6f08af82011-09-15 01:19:031163
1164 // The command line switch kEnableBenchmarking needs to be specified along
1165 // with the kEnableStatsTable switch to ensure that the stats table global
1166 // is initialized correctly.
1167 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1168 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301169}
1170
1171std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431172 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1173 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301174 return g_browser_process->GetApplicationLocale();
1175}
1176
[email protected]597a867b2011-11-18 18:31:201177std::string ChromeContentBrowserClient::GetAcceptLangs(
1178 content::BrowserContext* context) {
1179 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371180 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081181}
1182
[email protected]9ec0f452012-05-31 15:58:531183gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221184 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531185 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081186}
1187
[email protected]a2176792011-05-08 19:30:491188bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091189 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191190 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201191 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201193 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051194 return io_data->GetCookieSettings()->
1195 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491196}
1197
[email protected]ed24fad2011-05-10 22:44:011198bool ChromeContentBrowserClient::AllowGetCookie(
1199 const GURL& url,
1200 const GURL& first_party,
1201 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201202 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011203 int render_process_id,
1204 int render_view_id) {
1205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201206 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051207 bool allow = io_data->GetCookieSettings()->
1208 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011209
[email protected]8093a542011-05-13 07:29:321210 BrowserThread::PostTask(
1211 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031212 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431213 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011214 return allow;
1215}
1216
1217bool ChromeContentBrowserClient::AllowSetCookie(
1218 const GURL& url,
1219 const GURL& first_party,
1220 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201221 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011222 int render_process_id,
1223 int render_view_id,
1224 net::CookieOptions* options) {
1225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201226 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051227 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1228 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1229
[email protected]8093a542011-05-13 07:29:321230 BrowserThread::PostTask(
1231 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031232 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431233 render_view_id, url, first_party, cookie_line, *options,
1234 !allow));
[email protected]ed24fad2011-05-10 22:44:011235 return allow;
1236}
1237
[email protected]d5a19162011-06-30 18:51:541238bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201239 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201241 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431242 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1243 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261244
[email protected]bf510ed2012-06-05 08:31:431245 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1246 // Could we even support per-origin settings?
1247 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541248}
1249
[email protected]5c5a88e2011-11-12 00:45:351250bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351251 const GURL& url,
1252 const string16& name,
1253 const string16& display_name,
1254 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201255 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481256 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351257 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201258 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351259 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1260 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1261
[email protected]62151052012-02-01 18:40:481262 // Record access to database for potential display in UI.
1263 std::vector<std::pair<int, int> >::const_iterator i;
1264 for (i = render_views.begin(); i != render_views.end(); ++i) {
1265 BrowserThread::PostTask(
1266 BrowserThread::UI, FROM_HERE,
1267 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1268 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351269 }
1270
1271 return allow;
1272}
1273
1274bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351275 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201276 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481277 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201279 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351280 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1281 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1282
[email protected]62151052012-02-01 18:40:481283 // Record access to file system for potential display in UI.
1284 std::vector<std::pair<int, int> >::const_iterator i;
1285 for (i = render_views.begin(); i != render_views.end(); ++i) {
1286 BrowserThread::PostTask(
1287 BrowserThread::UI, FROM_HERE,
1288 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1289 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351290 }
1291
1292 return allow;
1293}
1294
[email protected]7c5ff9a2012-03-02 07:42:491295bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1296 const GURL& url,
1297 const string16& name,
1298 content::ResourceContext* context,
1299 const std::vector<std::pair<int, int> >& render_views) {
1300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1301 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1302 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1303 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1304
1305 // Record access to IndexedDB for potential display in UI.
1306 std::vector<std::pair<int, int> >::const_iterator i;
1307 for (i = render_views.begin(); i != render_views.end(); ++i) {
1308 BrowserThread::PostTask(
1309 BrowserThread::UI, FROM_HERE,
1310 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1311 i->first, i->second, url, name, !allow));
1312 }
1313
1314 return allow;
1315}
1316
[email protected]6133f922011-07-01 21:34:341317net::URLRequestContext*
1318ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201319 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421321 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201322 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341323 return io_data->extensions_request_context();
1324 }
1325
1326 return NULL;
1327}
1328
[email protected]317f96c92011-05-31 06:53:411329QuotaPermissionContext*
1330ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1331 return new ChromeQuotaPermissionContext();
1332}
1333
[email protected]848dd042011-06-04 18:24:031334void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171335 int render_process_id,
1336 int render_view_id,
1337 int cert_error,
1338 const net::SSLInfo& ssl_info,
1339 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031340 bool overridable,
[email protected]d9be47702012-05-16 03:41:221341 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171342 const base::Callback<void(bool)>& callback,
1343 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411344 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131345 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171346 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411347 if (!tab) {
1348 NOTREACHED();
1349 return;
1350 }
1351 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501352 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301353 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011354 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1355 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411356 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171357 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411358 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171359 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411360 return;
1361 }
1362 }
1363
[email protected]1e87df32012-09-12 04:53:191364#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231365 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1366 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1367 if (captive_portal_tab_helper)
1368 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191369#endif
1370
[email protected]f9034cf2011-07-21 12:43:411371 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221372 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1373 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031374}
1375
[email protected]c99c442e2011-08-24 11:37:301376void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451377 int render_process_id,
1378 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401379 const net::HttpNetworkSession* network_session,
1380 net::SSLCertRequestInfo* cert_request_info,
1381 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131382 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451383 render_process_id, render_view_id);
1384 if (!tab) {
1385 NOTREACHED();
1386 return;
1387 }
1388
[email protected]6786bf402011-12-03 15:19:451389 GURL requesting_url("https://" + cert_request_info->host_and_port);
1390 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1391 << cert_request_info->host_and_port;
1392
[email protected]627e0512011-12-21 22:55:301393 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451394 scoped_ptr<Value> filter(
1395 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1396 requesting_url,
1397 requesting_url,
1398 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1399 std::string(), NULL));
1400
1401 if (filter.get()) {
1402 // Try to automatically select a client certificate.
1403 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1404 DictionaryValue* filter_dict =
1405 static_cast<DictionaryValue*>(filter.get());
1406
1407 const std::vector<scoped_refptr<net::X509Certificate> >&
1408 all_client_certs = cert_request_info->client_certs;
1409 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1410 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1411 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401412 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451413 return;
1414 }
1415 }
1416 } else {
1417 NOTREACHED();
1418 }
1419 }
1420
[email protected]11feec322012-09-18 03:58:521421 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1422 if (!ssl_tab_helper) {
1423 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451424 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141425 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401426 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451427 return;
1428 }
[email protected]11feec322012-09-18 03:58:521429 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401430 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451431}
1432
[email protected]3b455502012-12-11 18:22:581433void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451434 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581435 net::CertificateMimeType cert_type,
1436 const void* cert_data,
1437 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451438 int render_process_id,
1439 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581440 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1441 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451442}
1443
[email protected]dc73a7b2012-03-25 15:27:181444content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561445 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181446}
1447
[email protected]941623e2011-06-07 23:06:041448void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1449 const GURL& source_origin,
1450 int callback_context,
1451 int render_process_id,
1452 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111453#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1455 WebContents* contents =
1456 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1457 if (!contents) {
[email protected]941623e2011-06-07 23:06:041458 NOTREACHED();
1459 return;
1460 }
1461
[email protected]d0d9c3ee2012-06-19 03:07:021462 // Skip showing the infobar if the request comes from an extension, and that
1463 // extension has the 'notify' permission. (If the extension does not have the
1464 // permission, the user will still be prompted.)
1465 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131466 ExtensionService* service =
1467 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021468 const Extension* extension = !service ? NULL :
1469 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1470 source_origin));
[email protected]eb4832a2012-12-08 01:57:521471 RenderViewHost* rvh =
1472 RenderViewHost::FromID(render_process_id, render_view_id);
1473 if (IsExtensionWithPermissionOrSuggestInConsole(
1474 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021475 if (rvh)
1476 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1477 return;
1478 }
1479
1480 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371481 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021482 notifications->RequestPermission(source_origin, render_process_id,
1483 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111484#else
1485 NOTIMPLEMENTED();
1486#endif
[email protected]941623e2011-06-07 23:06:041487}
1488
1489WebKit::WebNotificationPresenter::Permission
1490 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021491 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201492 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021493 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111494#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201496 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021497 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1498 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061499 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041500 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041501
1502 // Fall back to the regular notification preferences, which works on an
1503 // origin basis.
1504 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371505 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041506 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111507#else
1508 return WebKit::WebNotificationPresenter::PermissionAllowed;
1509#endif
[email protected]941623e2011-06-07 23:06:041510}
1511
1512void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171513 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041514 int render_process_id,
1515 int render_view_id,
1516 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111517#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041518 RenderViewHost* rvh = RenderViewHost::FromID(
1519 render_process_id, render_view_id);
1520 if (!rvh) {
1521 NOTREACHED();
1522 return;
1523 }
1524
[email protected]9f76c1e2012-03-05 15:15:581525 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301526 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041527 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371528 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041529 service->ShowDesktopNotification(
1530 params, render_process_id, render_view_id,
1531 worker ? DesktopNotificationService::WorkerNotification :
1532 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111533#else
1534 NOTIMPLEMENTED();
1535#endif
[email protected]941623e2011-06-07 23:06:041536}
1537
1538void ChromeContentBrowserClient::CancelDesktopNotification(
1539 int render_process_id,
1540 int render_view_id,
1541 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111542#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041543 RenderViewHost* rvh = RenderViewHost::FromID(
1544 render_process_id, render_view_id);
1545 if (!rvh) {
1546 NOTREACHED();
1547 return;
1548 }
1549
[email protected]9f76c1e2012-03-05 15:15:581550 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301551 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041552 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371553 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041554 service->CancelDesktopNotification(
1555 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111556#else
1557 NOTIMPLEMENTED();
1558#endif
[email protected]941623e2011-06-07 23:06:041559}
1560
[email protected]9f3fba52011-06-08 20:37:191561bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351562 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021563 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191564 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201565 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011566 int render_process_id,
1567 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011569
1570 *no_javascript_access = false;
1571
[email protected]9f3fba52011-06-08 20:37:191572 // If the opener is trying to create a background window but doesn't have
1573 // the appropriate permission, fail the attempt.
1574 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201575 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531576 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1577
[email protected]03b6d552012-03-29 04:03:011578 if (!map->SecurityOriginHasAPIPermission(
1579 source_origin,
1580 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061581 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011582 return false;
1583 }
1584
[email protected]7b54ca02012-03-02 18:06:531585 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1586 // return a recently installed Extension even if this CanCreateWindow call
1587 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011588 // because the permission check above would have caused an early return
1589 // already. We must use the full URL to find hosted apps, though, and not
1590 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531591 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351592 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531593 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011594 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191595 }
1596 return true;
1597}
1598
1599std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201600 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1602 // Check if it's an extension-created worker, in which case we want to use
1603 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201604 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191605 const Extension* extension =
1606 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1607 return extension ? extension->name() : std::string();
1608}
1609
[email protected]99907362012-01-11 05:41:401610void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1611 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171612}
1613
[email protected]c52b2892012-03-07 11:01:021614content::SpeechRecognitionManagerDelegate*
1615 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321616#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021617 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321618#else
1619 return NULL;
1620#endif
[email protected]66cfec62012-02-24 17:57:511621}
1622
[email protected]ae6e9912011-07-27 01:18:281623net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1624 return g_browser_process->net_log();
1625}
1626
[email protected]32538d92011-08-25 00:09:231627AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1628 return new ChromeAccessTokenStore();
1629}
1630
[email protected]dbae6b02011-06-29 23:51:411631bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011632 return true;
[email protected]dbae6b02011-06-29 23:51:411633}
1634
[email protected]64d69de42012-02-06 00:19:541635void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321636 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061637 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581638 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061639 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061640
[email protected]f3986f82012-01-03 20:00:061641 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541642 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061643 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541644 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061645 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541646 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061647 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541648 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061649 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541650 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061651 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541652 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031653 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1654 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061655
[email protected]64d69de42012-02-06 00:19:541656 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401657 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541658 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401659 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541660 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401661 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541662 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401663 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061664
[email protected]ddf72142012-05-22 04:52:401665 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061666
[email protected]64d69de42012-02-06 00:19:541667 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401668 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541669 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061670 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541671 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061672 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1673 const DictionaryValue* inspector_settings =
1674 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1675 if (inspector_settings) {
1676 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1677 iter != inspector_settings->end_keys(); ++iter) {
1678 std::string value;
1679 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541680 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061681 std::make_pair(*iter, value));
1682 }
1683 }
[email protected]64d69de42012-02-06 00:19:541684 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061685
[email protected]ddf72142012-05-22 04:52:401686 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541687 web_prefs->javascript_enabled = false;
1688 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1689 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401690 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541691 web_prefs->plugins_enabled = false;
1692 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1693 web_prefs->java_enabled = false;
1694 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401695 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061696
[email protected]64d69de42012-02-06 00:19:541697 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1698 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061699
[email protected]64d69de42012-02-06 00:19:541700 web_prefs->memory_info_enabled =
1701 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1702 web_prefs->allow_displaying_insecure_content =
1703 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1704 web_prefs->allow_running_insecure_content =
1705 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321706#if defined(OS_ANDROID)
1707 web_prefs->font_scale_factor =
1708 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1709 web_prefs->force_enable_zoom =
1710 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1711#endif
[email protected]9d06d88d2012-02-23 22:37:081712 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061713
[email protected]64d69de42012-02-06 00:19:541714 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151715 UserStyleSheetWatcher* user_style_sheet_watcher =
1716 UserStyleSheetWatcherFactory::GetForProfile(profile);
1717 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541718 web_prefs->user_style_sheet_enabled = true;
1719 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151720 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541721 } else {
1722 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061723 }
1724
[email protected]b7e44ff2012-02-16 03:37:341725 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101726#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031727 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101728 // Mac so it uses NSSpellChecker in the background.
1729 false;
1730#else
[email protected]61806872012-12-12 04:15:361731 true;
[email protected]37b928e2012-05-30 09:01:101732#endif
[email protected]b7e44ff2012-02-16 03:37:341733 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521734 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571735
[email protected]64d69de42012-02-06 00:19:541736 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061737 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541738 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061739 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541740 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061741 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1742
1743 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541744 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061745 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541746 web_prefs->default_encoding);
1747 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401748 prefs->ClearPref(prefs::kDefaultCharset);
1749 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061750 }
[email protected]64d69de42012-02-06 00:19:541751 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061752
[email protected]88ecf66d2012-12-11 22:53:471753 if (content::IsForceCompositingModeEnabled())
1754 web_prefs->force_compositing_mode = true;
1755
[email protected]299d7f12012-05-23 05:31:151756 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1757 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131758 ExtensionService* service =
1759 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061760 if (service) {
[email protected]1bc28312012-11-08 08:31:531761 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1762 const Extension* extension = service->extensions()->GetByID(url.host());
1763 // Ensure that we are only granting extension preferences to URLs with
1764 // the correct scheme. Without this check, chrome-guest:// schemes used by
1765 // webview tags as well as hosts that happen to match the id of an
1766 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421767 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531768 extension_webkit_preferences::SetPreferences(
1769 extension, view_type, web_prefs);
1770 }
[email protected]f3986f82012-01-03 20:00:061771 }
1772
[email protected]299d7f12012-05-23 05:31:151773 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541774 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151775 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061776 // Disable all kinds of acceleration for background pages.
1777 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541778 web_prefs->force_compositing_mode = false;
1779 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061780 }
[email protected]2e21fe292012-03-02 22:52:321781
1782#if defined(FILE_MANAGER_EXTENSION)
1783 // Override the default of suppressing HW compositing for WebUI pages for the
1784 // file manager, which is implemented using WebUI but wants HW acceleration
1785 // for video decode & render.
1786 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1787 web_prefs->accelerated_compositing_enabled = true;
1788 web_prefs->accelerated_2d_canvas_enabled = true;
1789 }
1790#endif
[email protected]181a95ee2011-07-12 19:26:361791}
1792
1793void ChromeContentBrowserClient::UpdateInspectorSetting(
1794 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061795 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581796 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061797 DictionaryPrefUpdate update(
1798 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1799 prefs::kWebKitInspectorSettings);
1800 DictionaryValue* inspector_settings = update.Get();
1801 inspector_settings->SetWithoutPathExpansion(key,
1802 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361803}
1804
1805void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061806 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581807 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061808 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1809 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361810}
1811
[email protected]b8148ac2011-07-13 22:03:251812void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1813 BrowserURLHandler* handler) {
1814 // Add the default URL handlers.
1815 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1816 BrowserURLHandler::null_handler());
1817 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1818 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1819
[email protected]b3adbd02011-11-30 22:23:271820 // about: handler. Must come before chrome: handler, since it will
1821 // rewrite about: urls to chrome: URLs and then expect chrome: to
1822 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251823 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1824 BrowserURLHandler::null_handler());
1825 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241826 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251827}
1828
1829void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371830 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581831 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471832 BrowsingDataRemover* remover =
1833 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551834 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1835 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251836 // BrowsingDataRemover takes care of deleting itself when done.
1837}
1838
1839void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371840 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581841 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471842 BrowsingDataRemover* remover =
1843 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231844 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551845 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251846 // BrowsingDataRemover takes care of deleting itself when done.
1847}
1848
[email protected]e1d16eb92011-08-18 23:19:321849FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1850 return download_util::GetDefaultDownloadDirectory();
1851}
1852
[email protected]c9b6eb62011-10-18 20:49:391853std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1854 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1855}
1856
[email protected]b7631cc2012-09-15 05:08:381857void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1858 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541859#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381860 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1861 scoped_ptr<ppapi::host::HostFactory>(
1862 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541863#endif
[email protected]b7631cc2012-09-15 05:08:381864}
1865
[email protected]0c7193742012-11-07 19:05:031866content::BrowserPpapiHost*
1867 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1868 int plugin_process_id) {
1869 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1870 while (!iter.Done()) {
1871 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1872 if (host->process() &&
1873 host->process()->GetData().id == plugin_process_id) {
1874 // Found the plugin.
1875 return host->browser_ppapi_host();
1876 }
1877 ++iter;
1878 }
1879 return NULL;
1880}
1881
[email protected]38cd8f7f2012-06-15 22:06:071882bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581883 content::BrowserContext* browser_context,
1884 const GURL& url,
1885 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291886 if (!url.is_valid())
1887 return false;
1888
1889 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421890 if (url.SchemeIs(extensions::kExtensionScheme) &&
1891 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291892 return true;
[email protected]885c0e92012-11-13 20:27:421893 }
[email protected]a658d452012-03-02 12:45:291894
[email protected]9a5940d2012-04-27 19:16:231895 Profile* profile = Profile::FromBrowserContext(browser_context);
1896 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191897 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131898 extensions::ExtensionSystem::Get(profile)->extension_service();
1899 if (extension_service) {
1900 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231901 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1902 }
1903
[email protected]f237c0f2012-03-10 07:49:101904 // Need to check this now and not on construction because otherwise it won't
1905 // work with browser_tests.
1906 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1907 std::string allowed_list =
1908 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231909 if (allowed_list == "*") {
1910 // The wildcard allows socket API only for packaged and platform apps.
1911 return extension &&
[email protected]1d5e58b2013-01-31 08:41:401912 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
1913 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:231914 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:391915 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:101916 while (t.GetNext()) {
1917 if (t.token() == host)
1918 return true;
1919 }
1920 }
1921
[email protected]a658d452012-03-02 12:45:291922 if (!extension)
1923 return false;
1924
[email protected]157cc902012-11-02 06:31:581925 extensions::SocketPermission::CheckParam extension_params(
1926 params.type, params.host, params.port);
1927 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1928 &extension_params))
[email protected]a658d452012-03-02 12:45:291929 return true;
1930
1931 return false;
[email protected]e461da2f2012-02-16 19:06:401932}
1933
[email protected]a7944aa2012-10-15 10:12:141934FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
1935 FilePath directory;
1936 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
1937 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
1938}
1939
[email protected]00ebd5d2013-02-01 03:32:011940ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
1941 WebContents* web_contents) {
1942 return new ChromeSelectFilePolicy(web_contents);
1943}
1944
[email protected]e60c0232011-11-11 19:56:351945#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181946void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1947 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:381948 int child_process_id,
[email protected]c7abd422012-09-25 00:20:081949 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:391950#if defined(OS_ANDROID)
1951 FilePath data_path;
1952 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
1953 DCHECK(!data_path.empty());
1954
1955 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
1956 FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
1957 base::PlatformFile f =
1958 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
1959 DCHECK(f != base::kInvalidPlatformFileValue);
1960 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
1961 FileDescriptor(f, true)));
1962
1963 FilePath chrome_resources_pak =
1964 data_path.AppendASCII("chrome_100_percent.pak");
1965 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
1966 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:371967 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:391968 FileDescriptor(f, true)));
1969
1970 const std::string locale = GetApplicationLocale();
1971 FilePath locale_pak = ResourceBundle::GetSharedInstance().
1972 GetLocaleFilePath(locale, false);
1973 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
1974 DCHECK(f != base::kInvalidPlatformFileValue);
1975 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
1976 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:381977
[email protected]73592382013-01-18 19:22:371978 FilePath resources_pack_path;
1979 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
1980 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
1981 DCHECK(f != base::kInvalidPlatformFileValue);
1982 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
1983 FileDescriptor(f, true)));
1984
[email protected]40da3e0c2012-10-24 22:03:381985#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:431986 if (IsCrashReporterEnabled()) {
1987 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
1988 if (f == base::kInvalidPlatformFileValue) {
1989 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
1990 "be disabled for this process.";
1991 } else {
1992 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
1993 FileDescriptor(f, true)));
1994 }
[email protected]40da3e0c2012-10-24 22:03:381995 }
1996#endif // defined(USE_LINUX_BREAKPAD)
1997
1998#else
1999 int crash_signal_fd = GetCrashSignalFD(command_line);
2000 if (crash_signal_fd >= 0) {
2001 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2002 FileDescriptor(crash_signal_fd,
2003 false)));
2004 }
[email protected]29699c22012-10-03 23:57:392005#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302006}
[email protected]e60c0232011-11-11 19:56:352007#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302008
[email protected]4a65826d2011-08-25 16:04:012009#if defined(OS_WIN)
2010const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2011 return chrome::kBrowserResourcesDll;
2012}
2013#endif
2014
[email protected]37a72af2011-06-13 05:42:012015#if defined(USE_NSS)
2016crypto::CryptoModuleBlockingPasswordDelegate*
2017 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2018 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292019 return chrome::NewCryptoModuleBlockingDialogDelegate(
2020 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012021}
2022#endif
2023
[email protected]e9a32a52012-06-14 23:32:432024void ChromeContentBrowserClient::SetApplicationLocale(
2025 const std::string& locale) {
2026 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2027
2028 // This object is guaranteed to outlive all threads so we don't have to
2029 // worry about the lack of refcounting and can just post as Unretained.
2030 //
2031 // The common case is that this function is called early in Chrome startup
2032 // before any threads are created (it will also be called later if the user
2033 // changes the pref). In this case, there will be no threads created and
2034 // posting will fail. When there are no threads, we can just set the string
2035 // without worrying about threadsafety.
2036 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2037 base::Bind(
2038 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2039 base::Unretained(this), locale)))
2040 io_thread_application_locale_ = locale;
2041}
2042
2043void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2044 const std::string& locale) {
2045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2046 io_thread_application_locale_ = locale;
2047}
2048
[email protected]d977f9c2011-03-14 16:10:262049} // namespace chrome