blob: fa09d6586cfc175c0352b25489085398a6ffdc79 [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]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4718#include "chrome/browser/browsing_data/browsing_data_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1220#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0321#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4122#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5623#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0524#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4525#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3226#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0827#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3228#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1629#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0630#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0431#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0834#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2535#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0636#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4937#include "chrome/browser/extensions/message_handler.h"
[email protected]32538d92011-08-25 00:09:2338#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1239#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0840#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1841#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2842#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0443#include "chrome/browser/notifications/desktop_notification_service.h"
44#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4345#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4246#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0648#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4149#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5050#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0751#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4152#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1453#include "chrome/browser/printing/printing_message_filter.h"
54#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3255#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0656#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1457#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3358#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3859#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]8aa7a412011-11-07 12:33:4260#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0262#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4663#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4564#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0365#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5266#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4567#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5468#include "chrome/browser/toolkit_extra_parts.h"
[email protected]b5d73422012-06-02 23:46:4469#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]871dc682012-06-11 19:35:3370#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]863f70a2012-01-27 02:05:5071#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0672#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1573#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5374#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3075#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0176#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3077#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0478#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3879#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4480#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3481#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1282#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3883#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0984#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4385#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3086#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3887#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3188#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5989#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3090#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3391#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0592#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3393#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1994#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1095#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4396#include "content/public/common/child_process_host.h"
[email protected]b7c4f032012-08-07 16:38:5697#include "content/public/common/compositor_util.h"
[email protected]a1733df2012-06-22 11:24:1898#include "content/public/common/content_descriptors.h"
[email protected]c9b6eb62011-10-18 20:49:3999#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23100#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:40101#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34102#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06103#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38104#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39105#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08106#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36107#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04108#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26109
[email protected]b48c9182011-10-26 18:03:30110#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38111#include "chrome/browser/chrome_browser_main_win.h"
112#elif defined(OS_MACOSX)
113#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56114#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30115#elif defined(OS_CHROMEOS)
116#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49117#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26118#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30119#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09120#elif defined(OS_ANDROID)
121#include "chrome/browser/chrome_browser_main_android.h"
[email protected]b48c9182011-10-26 18:03:30122#elif defined(OS_POSIX)
123#include "chrome/browser/chrome_browser_main_posix.h"
124#endif
125
[email protected]6653c192012-04-10 22:52:44126#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30127#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12128#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43129#endif
[email protected]b80f68432011-05-02 17:22:30130
[email protected]1e87df32012-09-12 04:53:19131#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
132#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
133#endif
134
[email protected]37a72af2011-06-13 05:42:01135#if defined(USE_NSS)
136#include "chrome/browser/ui/crypto_module_password_dialog.h"
137#endif
138
[email protected]c7abd422012-09-25 00:20:08139using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47140using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39141using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31142using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59143using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08144using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00145using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11146using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33147using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13148using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06149using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34150using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25151using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39152
[email protected]c5dbef02011-05-13 05:06:09153namespace {
154
[email protected]e461da2f2012-02-16 19:06:40155const char* kPredefinedAllowedSocketOrigins[] = {
156 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18157 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45158 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
159 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
160 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
161 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35162 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54163 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
164 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
165 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
166 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
167 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
168 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38169 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
170 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514
[email protected]e461da2f2012-02-16 19:06:40171};
172
[email protected]f8f93eb2012-09-25 03:06:24173// Returns a copy of the given url with its host set to given host and path set
174// to given path. Other parts of the url will be the same.
175GURL ReplaceURLHostAndPath(const GURL& url,
176 const std::string& host,
177 const std::string& path) {
178 url_canon::Replacements<char> replacements;
179 replacements.SetHost(host.c_str(),
180 url_parse::Component(0, host.length()));
181 replacements.SetPath(path.c_str(),
182 url_parse::Component(0, path.length()));
183 return url.ReplaceComponents(replacements);
184}
185
186// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
187GURL AddUberHost(const GURL& url) {
188 const std::string uber_host = chrome::kChromeUIUberHost;
189 const std::string new_path = url.host() + url.path();
190
191 return ReplaceURLHostAndPath(url, uber_host, new_path);
192}
193
[email protected]045bf7c2012-09-28 20:27:36194// If url->host() is "chrome" and url->path() has characters other than the
195// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
196// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24197bool RemoveUberHost(GURL* url) {
198 if (url->host() != chrome::kChromeUIUberHost)
199 return false;
200
[email protected]045bf7c2012-09-28 20:27:36201 if (url->path().empty() || url->path() == "/")
202 return false;
203
[email protected]f8f93eb2012-09-25 03:06:24204 const std::string old_path = url->path();
205
206 const std::string::size_type separator = old_path.find('/', 1);
207 std::string new_host;
208 std::string new_path;
209 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36210 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24211 } else {
212 new_host = old_path.substr(1, separator - 1);
213 new_path = old_path.substr(separator);
214 }
215
216 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
217
218 return true;
219}
220
[email protected]b8148ac2011-07-13 22:03:25221// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42222bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24223 // Do not handle special URLs such as "about:foo"
224 if (!url->host().empty()) {
225 const GURL chrome_url = AddUberHost(*url);
226
227 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
228 // be called.
229 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
230 browser_context, chrome_url))
231 return true;
232 }
233
[email protected]863f70a2012-01-27 02:05:50234 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
235 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25236 return false;
237
[email protected]fe69558d2012-03-12 11:34:49238#if defined(OS_CHROMEOS)
239 // Special case : in ChromeOS in Guest mode bookmarks and history are
240 // disabled for security reasons. New tab page explains the reasons, so
241 // we redirect user to new tab page.
242 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
243 if (url->SchemeIs(chrome::kChromeUIScheme) &&
244 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
245 url->DomainIs(chrome::kChromeUIHistoryHost))) {
246 // Rewrite with new tab URL
247 *url = GURL(chrome::kChromeUINewTabURL);
248 }
249 }
250#endif
251
[email protected]b8148ac2011-07-13 22:03:25252 // Special case the new tab page. In older versions of Chrome, the new tab
253 // page was hosted at chrome-internal:<blah>. This might be in people's saved
254 // sessions or bookmarks, so we say any URL with that scheme triggers the new
255 // tab page.
256 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
257 // Rewrite it with the proper new tab URL.
258 *url = GURL(chrome::kChromeUINewTabURL);
259 }
260
261 return true;
262}
263
[email protected]f8f93eb2012-09-25 03:06:24264// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
265// "chrome://foo/".
266bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
267 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
268 return false;
269
270 return RemoveUberHost(url);
271}
272
[email protected]8d3132f62011-10-12 07:13:42273// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
274// below. Extension, and isolated apps require different privileges to be
275// granted to their RenderProcessHosts. This classification allows us to make
276// sure URLs are served by hosts with the right set of privileges.
277enum RenderProcessHostPrivilege {
278 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45279 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42280 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45281 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42282};
283
284RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
285 const GURL& url,
286 ExtensionService* service) {
287 // Default to a normal renderer cause it is lower privileged. This should only
288 // occur if the URL on a site instance is either malformed, or uninitialized.
289 // If it is malformed, then there is no need for better privileges anyways.
290 // If it is uninitialized, but eventually settles on being an a scheme other
291 // than normal webrenderer, the navigation logic will correct us out of band
292 // anyways.
293 if (!url.is_valid())
294 return PRIV_NORMAL;
295
296 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44297 const Extension* extension =
298 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45299 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42300 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45301 if (extension && extension->is_hosted_app())
302 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42303
304 return PRIV_EXTENSION;
305 }
306
307 return PRIV_NORMAL;
308}
309
310RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30311 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46312 extensions::ProcessMap* process_map,
313 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46314 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30315 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46316 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21317 return PRIV_NORMAL;
318
[email protected]6f371442011-11-09 06:45:46319 for (std::set<std::string>::iterator iter = extension_ids.begin();
320 iter != extension_ids.end(); ++iter) {
321 const Extension* extension = service->GetExtensionById(*iter, false);
322 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42323 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45324 if (extension && extension->is_hosted_app())
325 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42326 }
327
[email protected]676f6ab2011-10-19 20:23:21328 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42329}
330
[email protected]6786bf402011-12-03 15:19:45331bool CertMatchesFilter(const net::X509Certificate& cert,
332 const base::DictionaryValue& filter) {
333 // TODO(markusheintz): This is the minimal required filter implementation.
334 // Implement a better matcher.
335
336 // An empty filter matches any client certificate since no requirements are
337 // specified at all.
338 if (filter.empty())
339 return true;
340
341 std::string common_name;
342 if (filter.GetString("ISSUER.CN", &common_name) &&
343 (cert.issuer().common_name == common_name)) {
344 return true;
345 }
346 return false;
347}
348
[email protected]f3986f82012-01-03 20:00:06349// Fills |map| with the per-script font prefs under path |map_name|.
350void FillFontFamilyMap(const PrefService* prefs,
351 const char* map_name,
352 WebPreferences::ScriptFontFamilyMap* map) {
353 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
354 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
355 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
356 std::string font_family = prefs->GetString(pref_name.c_str());
357 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32358 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06359 }
360}
361
[email protected]a1733df2012-06-22 11:24:18362#if defined(OS_POSIX) && !defined(OS_MACOSX)
363int GetCrashSignalFD(const CommandLine& command_line) {
364 if (command_line.HasSwitch(switches::kExtensionProcess)) {
365 ExtensionCrashHandlerHostLinux* crash_handler =
366 ExtensionCrashHandlerHostLinux::GetInstance();
367 return crash_handler->GetDeathSignalSocket();
368 }
369
370 std::string process_type =
371 command_line.GetSwitchValueASCII(switches::kProcessType);
372
373 if (process_type == switches::kRendererProcess)
374 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
375
376 if (process_type == switches::kPluginProcess)
377 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
378
379 if (process_type == switches::kPpapiPluginProcess)
380 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
381
382 if (process_type == switches::kGpuProcess)
383 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
384
385 return -1;
386}
387#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
388
[email protected]9dbfff12011-07-01 19:37:07389} // namespace
[email protected]c5dbef02011-05-13 05:06:09390
[email protected]d977f9c2011-03-14 16:10:26391namespace chrome {
392
[email protected]e461da2f2012-02-16 19:06:40393ChromeContentBrowserClient::ChromeContentBrowserClient() {
394 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
395 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40396}
397
398ChromeContentBrowserClient::~ChromeContentBrowserClient() {
399}
400
[email protected]bca18382012-06-25 19:15:23401// static
402void ChromeContentBrowserClient::RegisterUserPrefs(PrefService* prefs) {
403 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
404 false,
405 PrefService::UNSYNCABLE_PREF);
406 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
407 true,
408 PrefService::UNSYNCABLE_PREF);
409 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
410 false,
411 PrefService::UNSYNCABLE_PREF);
412}
413
[email protected]50462bf02011-11-21 19:13:31414content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
415 const content::MainFunctionParams& parameters) {
416 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30417 // Construct the Main browser parts based on the OS type.
418#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31419 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04420#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31421 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30422#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31423 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26424#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31425 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14426#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09427 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30428#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31429 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04430#else
[email protected]b48c9182011-10-26 18:03:30431 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31432 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30433#endif
434
[email protected]c7480942011-11-08 19:18:27435 // Construct additional browser parts. Stages are called in the order in
436 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22437#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41438 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04439#endif
[email protected]c7480942011-11-08 19:18:27440
441#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41442 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27443#endif
444
[email protected]dc04be7c2012-03-15 23:57:49445#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41446 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49447#endif
448
[email protected]e050ef142012-03-21 01:04:24449#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41450 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24451#endif
452
[email protected]50462bf02011-11-21 19:13:31453 return main_parts;
[email protected]f967b722011-09-07 00:58:04454}
455
[email protected]38b098f2012-03-14 21:11:57456content::WebContentsView*
457 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57458 WebContents* web_contents,
459 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57460 return NULL;
461}
462
[email protected]d7c7c98a2012-07-12 21:27:44463std::string ChromeContentBrowserClient::GetStoragePartitionIdForChildProcess(
464 content::BrowserContext* browser_context,
465 int child_process_id) {
[email protected]d1198fd2012-08-13 22:50:19466 const Extension* extension = NULL;
[email protected]d7c7c98a2012-07-12 21:27:44467 Profile* profile = Profile::FromBrowserContext(browser_context);
468 ExtensionService* extension_service =
469 extensions::ExtensionSystem::Get(profile)->extension_service();
470 if (extension_service) {
[email protected]404fb002012-10-02 21:06:17471 std::set<std::string> extension_ids =
472 extension_service->process_map()->
473 GetExtensionsInProcess(child_process_id);
474 if (!extension_ids.empty())
475 // Since All the apps in a process share the same storage partition,
476 // we can pick any of them to retrieve the storage partition id.
477 extension =
478 extension_service->extensions()->GetByID(*(extension_ids.begin()));
[email protected]d7c7c98a2012-07-12 21:27:44479 }
[email protected]d1198fd2012-08-13 22:50:19480 return GetStoragePartitionIdForExtension(browser_context, extension);
481}
482
[email protected]e94bbcb2012-09-07 05:33:57483std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19484 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57485 const GURL& site) {
[email protected]d1198fd2012-08-13 22:50:19486 const Extension* extension = NULL;
487 Profile* profile = Profile::FromBrowserContext(browser_context);
488 ExtensionService* extension_service =
489 extensions::ExtensionSystem::Get(profile)->extension_service();
490 if (extension_service) {
491 extension = extension_service->extensions()->
[email protected]e94bbcb2012-09-07 05:33:57492 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]d1198fd2012-08-13 22:50:19493 }
494
495 return GetStoragePartitionIdForExtension(browser_context, extension);
496}
497
498bool ChromeContentBrowserClient::IsValidStoragePartitionId(
499 content::BrowserContext* browser_context,
500 const std::string& partition_id) {
501 // The default ID is empty which is always allowed.
502 if (partition_id.empty())
503 return true;
504
505 // If it isn't empty, then it must belong to an extension of some sort. Parse
506 // out the extension ID and make sure it is still installed.
507 Profile* profile = Profile::FromBrowserContext(browser_context);
508 ExtensionService* extension_service =
509 extensions::ExtensionSystem::Get(profile)->extension_service();
510 if (!extension_service) {
511 // No extension service means no storage partitions in Chrome.
512 return false;
513 }
514
515 // See if we can find an extension. The |partition_id| is the extension ID so
516 // no parsing needed to be done.
517 return extension_service->GetExtensionById(partition_id, false) != NULL;
[email protected]d7c7c98a2012-07-12 21:27:44518}
519
[email protected]38b098f2012-03-14 21:11:57520content::WebContentsViewDelegate*
521 ChromeContentBrowserClient::GetWebContentsViewDelegate(
522 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27523 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32524}
525
[email protected]f364d1392011-04-08 21:03:10526void ChromeContentBrowserClient::RenderViewHostCreated(
527 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46528
[email protected]9f76c1e2012-03-05 15:15:58529 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46530 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02531 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46532
533 new ChromeRenderViewHostObserver(render_view_host,
534 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49535 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26536}
537
[email protected]f3b1a082011-11-18 00:34:30538void ChromeContentBrowserClient::RenderProcessHostCreated(
539 content::RenderProcessHost* host) {
540 int id = host->GetID();
541 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
542 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02543 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30544 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02545#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08546 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03547#endif
[email protected]f3b1a082011-11-18 00:34:30548 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02549 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30550 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56551#if defined(OS_MACOSX)
552 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
553#endif
[email protected]f3b1a082011-11-18 00:34:30554 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03555 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07556 host->GetChannel()->AddFilter(
557 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38558
[email protected]2ccf45c2011-08-19 23:35:50559 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
560 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07561
562 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56563
564 RendererContentSettingRules rules;
565 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
566 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14567}
568
[email protected]e0ada9c2012-03-20 03:54:43569void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
570 content::BrowserChildProcessHost* host) {
571 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
572}
573
[email protected]863f70a2012-01-27 02:05:50574content::WebUIControllerFactory*
575 ChromeContentBrowserClient::GetWebUIControllerFactory() {
576 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56577}
578
[email protected]3d7474ff2011-07-27 17:47:37579GURL ChromeContentBrowserClient::GetEffectiveURL(
580 content::BrowserContext* browser_context, const GURL& url) {
581 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08582 // Get the effective URL for the given actual URL. If the URL is part of an
583 // installed app, the effective URL is an extension URL with the ID of that
584 // extension as the host. This has the effect of grouping apps together in
585 // a common SiteInstance.
586 if (!profile || !profile->GetExtensionService())
587 return url;
588
[email protected]615d88f2011-12-13 01:47:44589 const Extension* extension = profile->GetExtensionService()->extensions()->
590 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08591 if (!extension)
592 return url;
593
[email protected]15877ca2011-11-18 22:40:52594 // Bookmark apps do not use the hosted app process model, and should be
595 // treated as normal URLs.
596 if (extension->from_bookmark())
597 return url;
598
[email protected]36fb2c7c2011-04-04 15:49:08599 // If the URL is part of an extension's web extent, convert it to an
600 // extension URL.
601 return extension->GetResourceURL(url.path());
602}
603
[email protected]056ad2a2011-07-12 02:13:55604bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37605 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55606 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52607 // Because we expect to use the effective URL, URLs for hosted apps (apart
608 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55609 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
610 return false;
611
[email protected]3d7474ff2011-07-27 17:47:37612 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55613 if (!profile || !profile->GetExtensionService())
614 return false;
615
[email protected]615d88f2011-12-13 01:47:44616 const Extension* extension = profile->GetExtensionService()->extensions()->
617 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55618 if (!extension)
619 return false;
620
621 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53622 // permission, or that does not allow JavaScript access to the background
623 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55624 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53625 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06626 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53627 !extension->allow_background_js_access()) {
628 return false;
629 }
630 }
[email protected]056ad2a2011-07-12 02:13:55631
[email protected]7b54ca02012-03-02 18:06:53632 // Hosted apps that have script access to their background page must use
633 // process per site, since all instances can make synchronous calls to the
634 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55635 return true;
636}
637
[email protected]46fb9442011-12-09 17:57:47638bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
639 return ProfileIOData::IsHandledURL(url);
640}
641
[email protected]2a5221b2011-09-27 23:07:31642bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30643 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31644 const GURL& site_url) {
645 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30646 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42647 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46648 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31649
[email protected]ffa97602011-11-17 17:55:52650 // Don't allow the Task Manager to share a process with anything else.
651 // Otherwise it can affect the renderers it is observing.
652 // Note: we could create another RenderProcessHostPrivilege bucket for
653 // this to allow multiple chrome://tasks instances to share, but that's
654 // a very unlikely case without serious consequences.
655 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
656 return false;
657
[email protected]8d3132f62011-10-12 07:13:42658 // These may be NULL during tests. In that case, just assume any site can
659 // share any host.
[email protected]6f371442011-11-09 06:45:46660 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31661 return true;
662
[email protected]a8c269a2011-10-25 20:17:22663 // Experimental:
664 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
665 // to share a renderer process. (We could allow pages from the same site or
666 // extensions of the same type to share, if we knew what the given process
667 // was dedicated to. Allowing no sharing is simpler for now.) This may
668 // cause resource exhaustion issues if too many sites are open at once.
669 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
670 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
671 return false;
672
[email protected]eec0b33c2011-12-05 22:09:45673 // Otherwise, just make sure the process privilege matches the privilege
674 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57675 RenderProcessHostPrivilege privilege_required =
676 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45677 return GetProcessPrivilege(process_host, process_map, service) ==
678 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31679}
680
[email protected]76411f412012-02-22 18:56:06681// This function is trying to limit the amount of processes used by extensions
682// with background pages. It uses a globally set percentage of processes to
683// run such extensions and if the limit is exceeded, it returns true, to
684// indicate to the content module to group extensions together.
685bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
686 content::BrowserContext* browser_context, const GURL& url) {
687 // It has to be a valid URL for us to check for an extension.
688 if (!url.is_valid())
689 return false;
690
691 Profile* profile = Profile::FromBrowserContext(browser_context);
692 ExtensionService* service = profile->GetExtensionService();
693 if (!service)
694 return false;
695
696 // We have to have a valid extension with background page to proceed.
697 const Extension* extension =
698 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
699 if (!extension)
700 return false;
701 if (!extension->has_background_page())
702 return false;
703
704 std::set<int> process_ids;
705 size_t max_process_count =
706 content::RenderProcessHost::GetMaxRendererProcessCount();
707
708 // Go through all profiles to ensure we have total count of extension
709 // processes containing background pages, otherwise one profile can
710 // starve the other.
711 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
712 GetLoadedProfiles();
713 for (size_t i = 0; i < profiles.size(); ++i) {
714 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32715 for (ExtensionProcessManager::const_iterator iter =
716 epm->background_hosts().begin();
717 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13718 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32719 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06720 }
721 }
722
723 if (process_ids.size() >
724 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
725 return true;
726 }
727
728 return false;
729}
730
[email protected]6f371442011-11-09 06:45:46731void ChromeContentBrowserClient::SiteInstanceGotProcess(
732 SiteInstance* site_instance) {
733 CHECK(site_instance->HasProcess());
734
735 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02736 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46737 ExtensionService* service = profile->GetExtensionService();
738 if (!service)
739 return;
740
741 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44742 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59743 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46744 if (!extension)
745 return;
746
[email protected]6bc04fd82011-12-04 02:29:35747 service->process_map()->Insert(extension->id(),
748 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33749 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46750 BrowserThread::PostTask(
751 BrowserThread::IO, FROM_HERE,
752 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59753 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46754 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35755 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33756 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46757}
758
759void ChromeContentBrowserClient::SiteInstanceDeleting(
760 SiteInstance* site_instance) {
761 if (!site_instance->HasProcess())
762 return;
763
764 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02765 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46766 ExtensionService* service = profile->GetExtensionService();
767 if (!service)
768 return;
769
770 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44771 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59772 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46773 if (!extension)
774 return;
775
[email protected]6bc04fd82011-12-04 02:29:35776 service->process_map()->Remove(extension->id(),
777 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33778 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46779 BrowserThread::PostTask(
780 BrowserThread::IO, FROM_HERE,
781 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59782 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46783 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35784 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33785 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46786}
787
[email protected]f05763972012-06-06 18:17:26788bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08789 const GURL& current_url,
790 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26791 if (current_url.is_empty()) {
792 // Always choose a new process when navigating to extension URLs. The
793 // process grouping logic will combine all of a given extension's pages
794 // into the same process.
795 if (new_url.SchemeIs(chrome::kExtensionScheme))
796 return true;
[email protected]e3daf3c2011-10-05 21:17:08797
[email protected]f05763972012-06-06 18:17:26798 return false;
799 }
800
801 // Also, we must switch if one is an extension and the other is not the exact
802 // same extension.
803 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
804 new_url.SchemeIs(chrome::kExtensionScheme)) {
805 if (current_url.GetOrigin() != new_url.GetOrigin())
806 return true;
807 }
808
809 return false;
[email protected]e3daf3c2011-10-05 21:17:08810}
811
[email protected]395045c2012-05-22 15:04:38812bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
813 content::ResourceContext* resource_context, const GURL& current_url,
814 const GURL& new_url) {
815 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
816 return extensions::CrossesExtensionProcessBoundary(
817 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17818 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38819}
820
[email protected]763ec4ca2011-04-29 15:48:12821std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
822 const std::string& alias_name) {
823 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
824}
825
[email protected]b80f68432011-05-02 17:22:30826void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
827 CommandLine* command_line, int child_process_id) {
828#if defined(USE_LINUX_BREAKPAD)
829 if (IsCrashReporterEnabled()) {
830 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
831 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
832 }
833#elif defined(OS_MACOSX)
834 if (IsCrashReporterEnabled()) {
835 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
836 child_process_logging::GetClientId());
837 }
838#endif // OS_MACOSX
839
[email protected]f1933792011-06-14 00:49:34840 if (logging::DialogsAreSuppressed())
841 command_line->AppendSwitch(switches::kNoErrorDialogs);
842
[email protected]b80f68432011-05-02 17:22:30843 std::string process_type =
844 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17845 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52846 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30847 FilePath user_data_dir =
848 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
849 if (!user_data_dir.empty())
850 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
851#if defined(OS_CHROMEOS)
852 const std::string& login_profile =
853 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
854 if (!login_profile.empty())
855 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
856#endif
857
[email protected]f3b1a082011-11-18 00:34:30858 content::RenderProcessHost* process =
859 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37860 if (process) {
861 Profile* profile = Profile::FromBrowserContext(
862 process->GetBrowserContext());
[email protected]c8598d42012-09-25 21:17:00863 if (profile->GetExtensionService()) {
864 extensions::ProcessMap* process_map =
865 profile->GetExtensionService()->process_map();
866 if (process_map && process_map->Contains(process->GetID()))
867 command_line->AppendSwitch(switches::kExtensionProcess);
868 }
[email protected]b80f68432011-05-02 17:22:30869
[email protected]a8d851f82011-12-21 00:32:37870 PrefService* prefs = profile->GetPrefs();
871 // Currently this pref is only registered if applied via a policy.
872 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
873 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
874 // Turn this policy into a command line switch.
875 command_line->AppendSwitch(switches::kDisable3DAPIs);
876 }
[email protected]718eab62011-10-05 21:16:52877
[email protected]a8d851f82011-12-21 00:32:37878 // Disable client-side phishing detection in the renderer if it is
879 // disabled in the Profile preferences or the browser process.
880 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
881 !g_browser_process->safe_browsing_detection_service()) {
882 command_line->AppendSwitch(
883 switches::kDisableClientSidePhishingDetection);
884 }
[email protected]0045b0f42012-07-26 11:52:08885
886 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:21887 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]47c7ec82012-01-18 03:29:21888 }
[email protected]4287a3d2011-06-13 23:56:51889
[email protected]47c7ec82012-01-18 03:29:21890 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51891 static const char* const kSwitchNames[] = {
892 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48893 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51894 switches::kAllowScriptingGallery,
895 switches::kAppsCheckoutURL,
896 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31897 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51898 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10899 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50900 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53901 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09902 switches::kDisableInBrowserThumbnailing,
[email protected]b0553c7e2012-09-19 21:36:11903 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:51904 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21905 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13906 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51907 switches::kEnableCrxlessWebApps,
908 switches::kEnableExperimentalExtensionApis,
[email protected]5e92282f2012-08-17 08:11:57909 switches::kEnableFramelessConstrainedDialogs,
[email protected]4287a3d2011-06-13 23:56:51910 switches::kEnableIPCFuzzing,
911 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05912 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48913 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:05914 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:51915 switches::kEnableWatchdog,
916 switches::kExperimentalSpellcheckerFeatures,
917 switches::kMemoryProfiling,
918 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37919 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:37920 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51921 switches::kPpapiFlashArgs,
922 switches::kPpapiFlashInProcess,
923 switches::kPpapiFlashPath,
924 switches::kPpapiFlashVersion,
925 switches::kProfilingAtStart,
926 switches::kProfilingFile,
927 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37928 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51929 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38930 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51931 };
932
933 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
934 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17935 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38936 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35937 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38938 switches::kEnableExperimentalExtensionApis,
939 switches::kWhitelistedExtensionID,
940 };
941
942 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
943 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51944 } else if (process_type == switches::kPluginProcess) {
945 static const char* const kSwitchNames[] = {
946 #if defined(OS_CHROMEOS)
947 switches::kLoginProfile,
948 #endif
949 switches::kMemoryProfiling,
950 switches::kSilentDumpOnDCHECK,
951 switches::kUserDataDir,
952 };
953
954 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
955 arraysize(kSwitchNames));
956 } else if (process_type == switches::kZygoteProcess) {
957 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51958 switches::kUserDataDir, // Make logs go to the right file.
959 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50960 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13961 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51962 switches::kPpapiFlashInProcess,
963 switches::kPpapiFlashPath,
964 switches::kPpapiFlashVersion,
965 };
966
967 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
968 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11969 } else if (process_type == switches::kGpuProcess) {
970 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
971 // because GPU is expected to be unreliable.
972 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
973 !command_line->HasSwitch(switches::kDisableBreakpad))
974 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30975 }
[email protected]6f08af82011-09-15 01:19:03976
977 // The command line switch kEnableBenchmarking needs to be specified along
978 // with the kEnableStatsTable switch to ensure that the stats table global
979 // is initialized correctly.
980 if (command_line->HasSwitch(switches::kEnableBenchmarking))
981 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30982}
983
984std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:43985 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
986 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:30987 return g_browser_process->GetApplicationLocale();
988}
989
[email protected]597a867b2011-11-18 18:31:20990std::string ChromeContentBrowserClient::GetAcceptLangs(
991 content::BrowserContext* context) {
992 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37993 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08994}
995
[email protected]9ec0f452012-05-31 15:58:53996gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22997 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:53998 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:08999}
1000
[email protected]a2176792011-05-08 19:30:491001bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091002 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191003 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201004 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321005 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201006 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051007 return io_data->GetCookieSettings()->
1008 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491009}
1010
[email protected]ed24fad2011-05-10 22:44:011011bool ChromeContentBrowserClient::AllowGetCookie(
1012 const GURL& url,
1013 const GURL& first_party,
1014 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201015 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011016 int render_process_id,
1017 int render_view_id) {
1018 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201019 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051020 bool allow = io_data->GetCookieSettings()->
1021 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011022
[email protected]8093a542011-05-13 07:29:321023 BrowserThread::PostTask(
1024 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031025 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431026 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011027 return allow;
1028}
1029
1030bool ChromeContentBrowserClient::AllowSetCookie(
1031 const GURL& url,
1032 const GURL& first_party,
1033 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201034 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011035 int render_process_id,
1036 int render_view_id,
1037 net::CookieOptions* options) {
1038 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201039 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051040 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1041 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1042
[email protected]8093a542011-05-13 07:29:321043 BrowserThread::PostTask(
1044 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031045 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431046 render_view_id, url, first_party, cookie_line, *options,
1047 !allow));
[email protected]ed24fad2011-05-10 22:44:011048 return allow;
1049}
1050
[email protected]ea628e32012-08-02 21:50:161051bool ChromeContentBrowserClient::AllowPluginLocalDataAccess(
1052 const GURL& document_url,
1053 const GURL& plugin_url,
1054 content::ResourceContext* context) {
1055 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1056 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1057 return io_data->GetCookieSettings()->IsReadingCookieAllowed(document_url,
1058 plugin_url);
1059}
1060
1061bool ChromeContentBrowserClient::AllowPluginLocalDataSessionOnly(
1062 const GURL& url,
1063 content::ResourceContext* context) {
1064 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1065 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1066 return io_data->GetCookieSettings()->IsCookieSessionOnly(url);
1067}
1068
[email protected]d5a19162011-06-30 18:51:541069bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201070 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541071 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201072 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431073 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1074 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261075
[email protected]bf510ed2012-06-05 08:31:431076 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1077 // Could we even support per-origin settings?
1078 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541079}
1080
[email protected]5c5a88e2011-11-12 00:45:351081bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351082 const GURL& url,
1083 const string16& name,
1084 const string16& display_name,
1085 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201086 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481087 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351088 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201089 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351090 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1091 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1092
[email protected]62151052012-02-01 18:40:481093 // Record access to database for potential display in UI.
1094 std::vector<std::pair<int, int> >::const_iterator i;
1095 for (i = render_views.begin(); i != render_views.end(); ++i) {
1096 BrowserThread::PostTask(
1097 BrowserThread::UI, FROM_HERE,
1098 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1099 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351100 }
1101
1102 return allow;
1103}
1104
1105bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351106 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201107 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481108 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201110 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351111 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1112 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1113
[email protected]62151052012-02-01 18:40:481114 // Record access to file system for potential display in UI.
1115 std::vector<std::pair<int, int> >::const_iterator i;
1116 for (i = render_views.begin(); i != render_views.end(); ++i) {
1117 BrowserThread::PostTask(
1118 BrowserThread::UI, FROM_HERE,
1119 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1120 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351121 }
1122
1123 return allow;
1124}
1125
[email protected]7c5ff9a2012-03-02 07:42:491126bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1127 const GURL& url,
1128 const string16& name,
1129 content::ResourceContext* context,
1130 const std::vector<std::pair<int, int> >& render_views) {
1131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1132 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1133 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1134 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1135
1136 // Record access to IndexedDB for potential display in UI.
1137 std::vector<std::pair<int, int> >::const_iterator i;
1138 for (i = render_views.begin(); i != render_views.end(); ++i) {
1139 BrowserThread::PostTask(
1140 BrowserThread::UI, FROM_HERE,
1141 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1142 i->first, i->second, url, name, !allow));
1143 }
1144
1145 return allow;
1146}
1147
[email protected]6133f922011-07-01 21:34:341148net::URLRequestContext*
1149ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201150 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1152 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201153 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341154 return io_data->extensions_request_context();
1155 }
1156
1157 return NULL;
1158}
1159
[email protected]317f96c92011-05-31 06:53:411160QuotaPermissionContext*
1161ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1162 return new ChromeQuotaPermissionContext();
1163}
1164
[email protected]a0ce3282011-08-19 20:49:521165void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421166 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421167}
1168
[email protected]a0ce3282011-08-19 20:49:521169void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521170 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521171}
1172
[email protected]848dd042011-06-04 18:24:031173void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171174 int render_process_id,
1175 int render_view_id,
1176 int cert_error,
1177 const net::SSLInfo& ssl_info,
1178 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031179 bool overridable,
[email protected]d9be47702012-05-16 03:41:221180 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171181 const base::Callback<void(bool)>& callback,
1182 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411183 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131184 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171185 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411186 if (!tab) {
1187 NOTREACHED();
1188 return;
1189 }
1190 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501191 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301192 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091193 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411194 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171195 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411196 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171197 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411198 return;
1199 }
1200 }
1201
[email protected]1e87df32012-09-12 04:53:191202#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231203 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1204 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1205 if (captive_portal_tab_helper)
1206 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191207#endif
1208
[email protected]f9034cf2011-07-21 12:43:411209 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221210 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1211 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031212}
1213
[email protected]c99c442e2011-08-24 11:37:301214void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451215 int render_process_id,
1216 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401217 const net::HttpNetworkSession* network_session,
1218 net::SSLCertRequestInfo* cert_request_info,
1219 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131220 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451221 render_process_id, render_view_id);
1222 if (!tab) {
1223 NOTREACHED();
1224 return;
1225 }
1226
[email protected]6786bf402011-12-03 15:19:451227 GURL requesting_url("https://" + cert_request_info->host_and_port);
1228 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1229 << cert_request_info->host_and_port;
1230
[email protected]627e0512011-12-21 22:55:301231 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451232 scoped_ptr<Value> filter(
1233 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1234 requesting_url,
1235 requesting_url,
1236 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1237 std::string(), NULL));
1238
1239 if (filter.get()) {
1240 // Try to automatically select a client certificate.
1241 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1242 DictionaryValue* filter_dict =
1243 static_cast<DictionaryValue*>(filter.get());
1244
1245 const std::vector<scoped_refptr<net::X509Certificate> >&
1246 all_client_certs = cert_request_info->client_certs;
1247 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1248 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1249 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401250 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451251 return;
1252 }
1253 }
1254 } else {
1255 NOTREACHED();
1256 }
1257 }
1258
[email protected]11feec322012-09-18 03:58:521259 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1260 if (!ssl_tab_helper) {
1261 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451262 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141263 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401264 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451265 return;
1266 }
[email protected]11feec322012-09-18 03:58:521267 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401268 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451269}
1270
1271void ChromeContentBrowserClient::AddNewCertificate(
1272 net::URLRequest* request,
1273 net::X509Certificate* cert,
1274 int render_process_id,
1275 int render_view_id) {
1276 // The handler will run the UI and delete itself when it's finished.
1277 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1278}
1279
[email protected]dc73a7b2012-03-25 15:27:181280content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1281 return MediaInternals::GetInstance();
1282}
1283
[email protected]941623e2011-06-07 23:06:041284void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1285 const GURL& source_origin,
1286 int callback_context,
1287 int render_process_id,
1288 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111289#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1291 WebContents* contents =
1292 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1293 if (!contents) {
[email protected]941623e2011-06-07 23:06:041294 NOTREACHED();
1295 return;
1296 }
1297
[email protected]d0d9c3ee2012-06-19 03:07:021298 // Skip showing the infobar if the request comes from an extension, and that
1299 // extension has the 'notify' permission. (If the extension does not have the
1300 // permission, the user will still be prompted.)
1301 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
1302 ExtensionService* service = profile->GetExtensionService();
1303 const Extension* extension = !service ? NULL :
1304 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1305 source_origin));
1306 if (extension &&
[email protected]c2e66e12012-06-27 06:27:061307 extension->HasAPIPermission(APIPermission::kNotification)) {
[email protected]d0d9c3ee2012-06-19 03:07:021308 RenderViewHost* rvh =
1309 RenderViewHost::FromID(render_process_id, render_view_id);
1310 if (rvh)
1311 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1312 return;
1313 }
1314
1315 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371316 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021317 notifications->RequestPermission(source_origin, render_process_id,
1318 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111319#else
1320 NOTIMPLEMENTED();
1321#endif
[email protected]941623e2011-06-07 23:06:041322}
1323
1324WebKit::WebNotificationPresenter::Permission
1325 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021326 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201327 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021328 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111329#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201331 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021332 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1333 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061334 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041335 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041336
1337 // Fall back to the regular notification preferences, which works on an
1338 // origin basis.
1339 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371340 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041341 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111342#else
1343 return WebKit::WebNotificationPresenter::PermissionAllowed;
1344#endif
[email protected]941623e2011-06-07 23:06:041345}
1346
1347void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171348 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041349 int render_process_id,
1350 int render_view_id,
1351 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111352#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041353 RenderViewHost* rvh = RenderViewHost::FromID(
1354 render_process_id, render_view_id);
1355 if (!rvh) {
1356 NOTREACHED();
1357 return;
1358 }
1359
[email protected]9f76c1e2012-03-05 15:15:581360 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301361 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041362 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371363 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041364 service->ShowDesktopNotification(
1365 params, render_process_id, render_view_id,
1366 worker ? DesktopNotificationService::WorkerNotification :
1367 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111368#else
1369 NOTIMPLEMENTED();
1370#endif
[email protected]941623e2011-06-07 23:06:041371}
1372
1373void ChromeContentBrowserClient::CancelDesktopNotification(
1374 int render_process_id,
1375 int render_view_id,
1376 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111377#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041378 RenderViewHost* rvh = RenderViewHost::FromID(
1379 render_process_id, render_view_id);
1380 if (!rvh) {
1381 NOTREACHED();
1382 return;
1383 }
1384
[email protected]9f76c1e2012-03-05 15:15:581385 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301386 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041387 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371388 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041389 service->CancelDesktopNotification(
1390 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111391#else
1392 NOTIMPLEMENTED();
1393#endif
[email protected]941623e2011-06-07 23:06:041394}
1395
[email protected]9f3fba52011-06-08 20:37:191396bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351397 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021398 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191399 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201400 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011401 int render_process_id,
1402 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011404
1405 *no_javascript_access = false;
1406
[email protected]9f3fba52011-06-08 20:37:191407 // If the opener is trying to create a background window but doesn't have
1408 // the appropriate permission, fail the attempt.
1409 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201410 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531411 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1412
[email protected]03b6d552012-03-29 04:03:011413 if (!map->SecurityOriginHasAPIPermission(
1414 source_origin,
1415 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061416 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011417 return false;
1418 }
1419
[email protected]7b54ca02012-03-02 18:06:531420 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1421 // return a recently installed Extension even if this CanCreateWindow call
1422 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011423 // because the permission check above would have caused an early return
1424 // already. We must use the full URL to find hosted apps, though, and not
1425 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531426 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351427 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531428 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011429 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191430 }
1431 return true;
1432}
1433
1434std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201435 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1437 // Check if it's an extension-created worker, in which case we want to use
1438 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201439 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191440 const Extension* extension =
1441 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1442 return extension ? extension->name() : std::string();
1443}
1444
[email protected]99907362012-01-11 05:41:401445void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1446 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171447}
1448
[email protected]c52b2892012-03-07 11:01:021449content::SpeechRecognitionManagerDelegate*
1450 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321451#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021452 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321453#else
1454 return NULL;
1455#endif
[email protected]66cfec62012-02-24 17:57:511456}
1457
[email protected]ae6e9912011-07-27 01:18:281458net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1459 return g_browser_process->net_log();
1460}
1461
[email protected]32538d92011-08-25 00:09:231462AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1463 return new ChromeAccessTokenStore();
1464}
1465
[email protected]dbae6b02011-06-29 23:51:411466bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1467 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1468 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1469}
1470
[email protected]64d69de42012-02-06 00:19:541471void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321472 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061473 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581474 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061475 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061476
[email protected]f3986f82012-01-03 20:00:061477 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541478 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061479 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541480 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061481 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541482 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061483 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541484 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061485 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541486 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061487 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541488 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061489
[email protected]64d69de42012-02-06 00:19:541490 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401491 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541492 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401493 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541494 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401495 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541496 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401497 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061498
[email protected]ddf72142012-05-22 04:52:401499 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061500
[email protected]64d69de42012-02-06 00:19:541501 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401502 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541503 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061504 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541505 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061506 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1507 const DictionaryValue* inspector_settings =
1508 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1509 if (inspector_settings) {
1510 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1511 iter != inspector_settings->end_keys(); ++iter) {
1512 std::string value;
1513 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541514 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061515 std::make_pair(*iter, value));
1516 }
1517 }
[email protected]64d69de42012-02-06 00:19:541518 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061519
[email protected]ddf72142012-05-22 04:52:401520 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541521 web_prefs->javascript_enabled = false;
1522 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1523 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401524 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541525 web_prefs->plugins_enabled = false;
1526 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1527 web_prefs->java_enabled = false;
1528 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401529 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061530
[email protected]64d69de42012-02-06 00:19:541531 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1532 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061533
[email protected]64d69de42012-02-06 00:19:541534 web_prefs->memory_info_enabled =
1535 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1536 web_prefs->allow_displaying_insecure_content =
1537 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1538 web_prefs->allow_running_insecure_content =
1539 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081540 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061541
[email protected]64d69de42012-02-06 00:19:541542 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151543 UserStyleSheetWatcher* user_style_sheet_watcher =
1544 UserStyleSheetWatcherFactory::GetForProfile(profile);
1545 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541546 web_prefs->user_style_sheet_enabled = true;
1547 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151548 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541549 } else {
1550 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061551 }
1552
[email protected]b7e44ff2012-02-16 03:37:341553 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101554#if defined(OS_MACOSX)
1555 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1556 // Mac so it uses NSSpellChecker in the background.
1557 false;
1558#else
1559 !CommandLine::ForCurrentProcess()->
1560 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1561#endif
[email protected]b7e44ff2012-02-16 03:37:341562 web_prefs->unified_textchecker_enabled =
1563 web_prefs->asynchronous_spell_checking_enabled ||
1564 CommandLine::ForCurrentProcess()->
1565 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571566
[email protected]64d69de42012-02-06 00:19:541567 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061568 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541569 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061570 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541571 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061572 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1573
1574 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541575 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061576 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541577 web_prefs->default_encoding);
1578 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401579 prefs->ClearPref(prefs::kDefaultCharset);
1580 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061581 }
[email protected]64d69de42012-02-06 00:19:541582 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061583
[email protected]299d7f12012-05-23 05:31:151584 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1585 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061586 ExtensionService* service = profile->GetExtensionService();
1587 if (service) {
1588 const Extension* extension = service->extensions()->GetByID(
[email protected]77ab17312012-09-28 15:34:591589 rvh->GetSiteInstance()->GetSiteURL().host());
[email protected]f3986f82012-01-03 20:00:061590 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151591 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061592 }
1593
[email protected]b7c4f032012-08-07 16:38:561594 if (content::IsForceCompositingModeEnabled())
[email protected]4abe58d2012-06-08 03:09:091595 web_prefs->force_compositing_mode = true;
1596
[email protected]299d7f12012-05-23 05:31:151597 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541598 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151599 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061600 // Disable all kinds of acceleration for background pages.
1601 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541602 web_prefs->force_compositing_mode = false;
1603 web_prefs->accelerated_compositing_enabled = false;
1604 web_prefs->accelerated_2d_canvas_enabled = false;
1605 web_prefs->accelerated_video_enabled = false;
1606 web_prefs->accelerated_painting_enabled = false;
1607 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061608 }
[email protected]2e21fe292012-03-02 22:52:321609
1610#if defined(FILE_MANAGER_EXTENSION)
1611 // Override the default of suppressing HW compositing for WebUI pages for the
1612 // file manager, which is implemented using WebUI but wants HW acceleration
1613 // for video decode & render.
1614 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1615 web_prefs->accelerated_compositing_enabled = true;
1616 web_prefs->accelerated_2d_canvas_enabled = true;
1617 }
1618#endif
[email protected]181a95ee2011-07-12 19:26:361619}
1620
1621void ChromeContentBrowserClient::UpdateInspectorSetting(
1622 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061623 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581624 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061625 DictionaryPrefUpdate update(
1626 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1627 prefs::kWebKitInspectorSettings);
1628 DictionaryValue* inspector_settings = update.Get();
1629 inspector_settings->SetWithoutPathExpansion(key,
1630 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361631}
1632
1633void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061634 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581635 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061636 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1637 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361638}
1639
[email protected]b8148ac2011-07-13 22:03:251640void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1641 BrowserURLHandler* handler) {
1642 // Add the default URL handlers.
1643 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1644 BrowserURLHandler::null_handler());
1645 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1646 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1647
[email protected]b3adbd02011-11-30 22:23:271648 // about: handler. Must come before chrome: handler, since it will
1649 // rewrite about: urls to chrome: URLs and then expect chrome: to
1650 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251651 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1652 BrowserURLHandler::null_handler());
1653 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241654 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251655}
1656
1657void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371658 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581659 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471660 BrowsingDataRemover* remover =
1661 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551662 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1663 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251664 // BrowsingDataRemover takes care of deleting itself when done.
1665}
1666
1667void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371668 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581669 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471670 BrowsingDataRemover* remover =
1671 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231672 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551673 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251674 // BrowsingDataRemover takes care of deleting itself when done.
1675}
1676
[email protected]e1d16eb92011-08-18 23:19:321677FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1678 return download_util::GetDefaultDownloadDirectory();
1679}
1680
[email protected]c9b6eb62011-10-18 20:49:391681std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1682 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1683}
1684
[email protected]b7631cc2012-09-15 05:08:381685void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1686 content::BrowserPpapiHost* browser_host) {
1687 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1688 scoped_ptr<ppapi::host::HostFactory>(
1689 new ChromeBrowserPepperHostFactory(browser_host)));
1690}
1691
[email protected]38cd8f7f2012-06-15 22:06:071692bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]a658d452012-03-02 12:45:291693 content::BrowserContext* browser_context, const GURL& url) {
1694 if (!url.is_valid())
1695 return false;
1696
1697 std::string host = url.host();
[email protected]92444942012-06-16 09:05:281698 if (url.SchemeIs(kExtensionScheme) && allowed_socket_origins_.count(host))
[email protected]a658d452012-03-02 12:45:291699 return true;
1700
[email protected]9a5940d2012-04-27 19:16:231701 Profile* profile = Profile::FromBrowserContext(browser_context);
1702 const Extension* extension = NULL;
1703 if (profile && profile->GetExtensionService()) {
1704 extension = profile->GetExtensionService()->extensions()->
1705 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1706 }
1707
[email protected]f237c0f2012-03-10 07:49:101708 // Need to check this now and not on construction because otherwise it won't
1709 // work with browser_tests.
1710 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1711 std::string allowed_list =
1712 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231713 if (allowed_list == "*") {
1714 // The wildcard allows socket API only for packaged and platform apps.
1715 return extension &&
[email protected]c4f459d2012-09-28 04:40:101716 (extension->GetType() == Extension::TYPE_LEGACY_PACKAGED_APP ||
[email protected]9a5940d2012-04-27 19:16:231717 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1718 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101719 StringTokenizer t(allowed_list, ",");
1720 while (t.GetNext()) {
1721 if (t.token() == host)
1722 return true;
1723 }
1724 }
1725
[email protected]a658d452012-03-02 12:45:291726 if (!extension)
1727 return false;
1728
[email protected]c2e66e12012-06-27 06:27:061729 if (extension->HasAPIPermission(APIPermission::kSocket))
[email protected]a658d452012-03-02 12:45:291730 return true;
1731
1732 return false;
[email protected]e461da2f2012-02-16 19:06:401733}
1734
[email protected]38cd8f7f2012-06-15 22:06:071735bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1736 return CommandLine::ForCurrentProcess()->HasSwitch(
1737 switches::kPpapiFlashInProcess);
1738}
1739
[email protected]e60c0232011-11-11 19:56:351740#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181741void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1742 const CommandLine& command_line,
[email protected]c7abd422012-09-25 00:20:081743 std::vector<FileDescriptorInfo>* mappings) {
[email protected]a1733df2012-06-22 11:24:181744 int crash_signal_fd = GetCrashSignalFD(command_line);
1745 if (crash_signal_fd >= 0) {
[email protected]c7abd422012-09-25 00:20:081746 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
1747 FileDescriptor(crash_signal_fd,
1748 false)));
[email protected]9dbfff12011-07-01 19:37:071749 }
[email protected]b80f68432011-05-02 17:22:301750}
[email protected]e60c0232011-11-11 19:56:351751#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301752
[email protected]4a65826d2011-08-25 16:04:011753#if defined(OS_WIN)
1754const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1755 return chrome::kBrowserResourcesDll;
1756}
1757#endif
1758
[email protected]37a72af2011-06-13 05:42:011759#if defined(USE_NSS)
1760crypto::CryptoModuleBlockingPasswordDelegate*
1761 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1762 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:291763 return chrome::NewCryptoModuleBlockingDialogDelegate(
1764 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:011765}
1766#endif
1767
[email protected]e9a32a52012-06-14 23:32:431768void ChromeContentBrowserClient::SetApplicationLocale(
1769 const std::string& locale) {
1770 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1771
1772 // This object is guaranteed to outlive all threads so we don't have to
1773 // worry about the lack of refcounting and can just post as Unretained.
1774 //
1775 // The common case is that this function is called early in Chrome startup
1776 // before any threads are created (it will also be called later if the user
1777 // changes the pref). In this case, there will be no threads created and
1778 // posting will fail. When there are no threads, we can just set the string
1779 // without worrying about threadsafety.
1780 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1781 base::Bind(
1782 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1783 base::Unretained(this), locale)))
1784 io_thread_application_locale_ = locale;
1785}
1786
1787void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1788 const std::string& locale) {
1789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1790 io_thread_application_locale_ = locale;
1791}
1792
[email protected]d1198fd2012-08-13 22:50:191793std::string ChromeContentBrowserClient::GetStoragePartitionIdForExtension(
1794 content::BrowserContext* browser_context, const Extension* extension) {
1795 // In chrome, we use the extension ID as the partition ID. This works well
1796 // because the extension ID fits the partition ID pattern and currently only
1797 // apps can designate that storage should be isolated.
1798 //
1799 // If |extension| is NULL, then the default, empty string, partition id is
1800 // used.
1801 std::string partition_id;
1802 if (extension && extension->is_storage_isolated()) {
1803 partition_id = extension->id();
1804 }
1805
1806 // Enforce that IsValidStoragePartitionId() implementation stays in sync.
1807 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
1808 return partition_id;
1809}
1810
1811
[email protected]d977f9c2011-03-14 16:10:261812} // namespace chrome