blob: 9735799ef662e9a4e7bd332366e0cd7e4e0f1fc0 [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]3b8f7e32011-07-13 11:52:2318#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1219#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0320#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4121#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5622#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0523#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4524#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3225#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0826#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3227#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1628#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0629#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0430#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1031#include "chrome/browser/extensions/extension_message_handler.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]32538d92011-08-25 00:09:2337#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1238#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0839#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1840#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2841#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0442#include "chrome/browser/notifications/desktop_notification_service.h"
43#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4344#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4245#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0647#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4148#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5049#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0750#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4151#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1452#include "chrome/browser/printing/printing_message_filter.h"
53#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3254#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0655#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1456#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3357#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4258#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1459#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0260#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4661#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4562#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0363#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4564#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
65#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5466#include "chrome/browser/toolkit_extra_parts.h"
[email protected]117b6b42012-02-29 09:11:0867#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4568#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5069#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]299d7f12012-05-23 05:31:1570#include "chrome/browser/view_type_utils.h"
[email protected]f3986f82012-01-03 20:00:0671#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1572#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3073#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0174#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3075#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0476#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3877#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4478#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3479#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1280#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3881#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0982#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4383#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3084#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3185#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5986#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3087#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3388#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0589#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3390#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1991#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1092#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4393#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3994#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3495#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4096#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0697#include "net/cookies/cookie_monster.h"
98#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3999#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08100#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36101#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04102#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26103
[email protected]b48c9182011-10-26 18:03:30104#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38105#include "chrome/browser/chrome_browser_main_win.h"
106#elif defined(OS_MACOSX)
107#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56108#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57109#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30110#elif defined(OS_CHROMEOS)
111#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49112#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26113#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30114#include "chrome/browser/chrome_browser_main_linux.h"
115#elif defined(OS_POSIX)
116#include "chrome/browser/chrome_browser_main_posix.h"
117#endif
118
[email protected]c0d7f792012-04-18 19:16:00119#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13120#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]61e69822012-03-14 22:08:57121#endif
122
[email protected]6653c192012-04-10 22:52:44123#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30124#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44125#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43126#endif
[email protected]b80f68432011-05-02 17:22:30127
[email protected]38b098f2012-03-14 21:11:57128#if defined(TOOLKIT_GTK)
129#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32130#endif
[email protected]37a72af2011-06-13 05:42:01131#if defined(USE_NSS)
132#include "chrome/browser/ui/crypto_module_password_dialog.h"
133#endif
134
[email protected]c8c77182011-12-21 15:04:47135using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39136using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31137using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59138using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00139using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11140using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33141using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13142using content::WebContents;
[email protected]1c321ee2012-05-21 03:02:34143using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25144using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39145
[email protected]c5dbef02011-05-13 05:06:09146namespace {
147
[email protected]e461da2f2012-02-16 19:06:40148const char* kPredefinedAllowedSocketOrigins[] = {
149 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18150 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45151 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
152 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
153 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
154 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35155 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
156 "cbkkbcmdlboombapidmoeolnmdacpkch" // see crbug.com/129089
[email protected]e461da2f2012-02-16 19:06:40157};
158
[email protected]b8148ac2011-07-13 22:03:25159// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42160bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50161 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
162 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25163 return false;
164
[email protected]fe69558d2012-03-12 11:34:49165#if defined(OS_CHROMEOS)
166 // Special case : in ChromeOS in Guest mode bookmarks and history are
167 // disabled for security reasons. New tab page explains the reasons, so
168 // we redirect user to new tab page.
169 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
170 if (url->SchemeIs(chrome::kChromeUIScheme) &&
171 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
172 url->DomainIs(chrome::kChromeUIHistoryHost))) {
173 // Rewrite with new tab URL
174 *url = GURL(chrome::kChromeUINewTabURL);
175 }
176 }
177#endif
178
[email protected]b8148ac2011-07-13 22:03:25179 // Special case the new tab page. In older versions of Chrome, the new tab
180 // page was hosted at chrome-internal:<blah>. This might be in people's saved
181 // sessions or bookmarks, so we say any URL with that scheme triggers the new
182 // tab page.
183 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
184 // Rewrite it with the proper new tab URL.
185 *url = GURL(chrome::kChromeUINewTabURL);
186 }
187
188 return true;
189}
190
[email protected]8d3132f62011-10-12 07:13:42191// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
192// below. Extension, and isolated apps require different privileges to be
193// granted to their RenderProcessHosts. This classification allows us to make
194// sure URLs are served by hosts with the right set of privileges.
195enum RenderProcessHostPrivilege {
196 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45197 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42198 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45199 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42200};
201
202RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
203 const GURL& url,
204 ExtensionService* service) {
205 // Default to a normal renderer cause it is lower privileged. This should only
206 // occur if the URL on a site instance is either malformed, or uninitialized.
207 // If it is malformed, then there is no need for better privileges anyways.
208 // If it is uninitialized, but eventually settles on being an a scheme other
209 // than normal webrenderer, the navigation logic will correct us out of band
210 // anyways.
211 if (!url.is_valid())
212 return PRIV_NORMAL;
213
214 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44215 const Extension* extension =
216 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45217 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42218 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45219 if (extension && extension->is_hosted_app())
220 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42221
222 return PRIV_EXTENSION;
223 }
224
225 return PRIV_NORMAL;
226}
227
228RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30229 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46230 extensions::ProcessMap* process_map,
231 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46232 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30233 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46234 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21235 return PRIV_NORMAL;
236
[email protected]6f371442011-11-09 06:45:46237 for (std::set<std::string>::iterator iter = extension_ids.begin();
238 iter != extension_ids.end(); ++iter) {
239 const Extension* extension = service->GetExtensionById(*iter, false);
240 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42241 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45242 if (extension && extension->is_hosted_app())
243 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42244 }
245
[email protected]676f6ab2011-10-19 20:23:21246 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42247}
248
[email protected]eec0b33c2011-12-05 22:09:45249bool IsIsolatedAppInProcess(const GURL& site_url,
250 content::RenderProcessHost* process_host,
251 extensions::ProcessMap* process_map,
252 ExtensionService* service) {
253 std::set<std::string> extension_ids =
254 process_map->GetExtensionsInProcess(process_host->GetID());
255 if (extension_ids.empty())
256 return false;
257
258 for (std::set<std::string>::iterator iter = extension_ids.begin();
259 iter != extension_ids.end(); ++iter) {
260 const Extension* extension = service->GetExtensionById(*iter, false);
261 if (extension &&
262 extension->is_storage_isolated() &&
263 extension->url() == site_url)
264 return true;
265 }
266
267 return false;
268}
269
[email protected]6786bf402011-12-03 15:19:45270bool CertMatchesFilter(const net::X509Certificate& cert,
271 const base::DictionaryValue& filter) {
272 // TODO(markusheintz): This is the minimal required filter implementation.
273 // Implement a better matcher.
274
275 // An empty filter matches any client certificate since no requirements are
276 // specified at all.
277 if (filter.empty())
278 return true;
279
280 std::string common_name;
281 if (filter.GetString("ISSUER.CN", &common_name) &&
282 (cert.issuer().common_name == common_name)) {
283 return true;
284 }
285 return false;
286}
287
[email protected]f3986f82012-01-03 20:00:06288// Fills |map| with the per-script font prefs under path |map_name|.
289void FillFontFamilyMap(const PrefService* prefs,
290 const char* map_name,
291 WebPreferences::ScriptFontFamilyMap* map) {
292 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
293 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
294 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
295 std::string font_family = prefs->GetString(pref_name.c_str());
296 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32297 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06298 }
299}
300
[email protected]9dbfff12011-07-01 19:37:07301} // namespace
[email protected]c5dbef02011-05-13 05:06:09302
[email protected]d977f9c2011-03-14 16:10:26303namespace chrome {
304
[email protected]e461da2f2012-02-16 19:06:40305ChromeContentBrowserClient::ChromeContentBrowserClient() {
306 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
307 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40308}
309
310ChromeContentBrowserClient::~ChromeContentBrowserClient() {
311}
312
[email protected]50462bf02011-11-21 19:13:31313content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
314 const content::MainFunctionParams& parameters) {
315 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30316 // Construct the Main browser parts based on the OS type.
317#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31318 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04319#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31320 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30321#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31322 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26323#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31324 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14325#elif defined(OS_ANDROID)
326 // Do nothing for Android.
327 // TODO(klobag): Android initialization should use the
328 // *BrowserMainParts class-hierarchy for setting up custom initialization.
329 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30330#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31331 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04332#else
[email protected]b48c9182011-10-26 18:03:30333 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31334 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30335#endif
336
[email protected]c7480942011-11-08 19:18:27337 // Construct additional browser parts. Stages are called in the order in
338 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22339#if defined(TOOLKIT_GTK)
[email protected]38fc5c82012-05-25 15:45:42340 browser::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04341#endif
[email protected]c7480942011-11-08 19:18:27342
343#if defined(TOOLKIT_VIEWS)
[email protected]c27541f2012-05-24 19:25:54344 browser::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27345#endif
346
[email protected]dc04be7c2012-03-15 23:57:49347#if defined(USE_ASH)
[email protected]38fc5c82012-05-25 15:45:42348 browser::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49349#endif
350
[email protected]e050ef142012-03-21 01:04:24351#if defined(USE_AURA)
[email protected]38fc5c82012-05-25 15:45:42352 browser::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24353#endif
354
[email protected]50462bf02011-11-21 19:13:31355 return main_parts;
[email protected]f967b722011-09-07 00:58:04356}
357
[email protected]38b098f2012-03-14 21:11:57358content::WebContentsView*
359 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57360 WebContents* web_contents,
361 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57362 return NULL;
363}
364
365content::WebContentsViewDelegate*
366 ChromeContentBrowserClient::GetWebContentsViewDelegate(
367 content::WebContents* web_contents) {
[email protected]c0d7f792012-04-18 19:16:00368#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13369 return new ChromeWebContentsViewDelegateViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57370#elif defined(TOOLKIT_GTK)
371 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32372#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57373 return
374 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
375 web_contents);
[email protected]74313b42011-08-24 16:51:32376#else
[email protected]38b098f2012-03-14 21:11:57377 return NULL;
[email protected]74313b42011-08-24 16:51:32378#endif
379}
380
[email protected]f364d1392011-04-08 21:03:10381void ChromeContentBrowserClient::RenderViewHostCreated(
382 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46383
[email protected]9f76c1e2012-03-05 15:15:58384 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46385 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02386 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46387
388 new ChromeRenderViewHostObserver(render_view_host,
389 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10390 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26391}
392
[email protected]f3b1a082011-11-18 00:34:30393void ChromeContentBrowserClient::RenderProcessHostCreated(
394 content::RenderProcessHost* host) {
395 int id = host->GetID();
396 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
397 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02398 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30399 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03400#if !defined(OS_ANDROID)
[email protected]b5b79d72012-05-24 19:42:28401 host->GetChannel()->AddFilter(new PrintingMessageFilter(id));
[email protected]058e5732012-03-01 22:48:03402#endif
[email protected]f3b1a082011-11-18 00:34:30403 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02404 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30405 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56406#if defined(OS_MACOSX)
407 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
408#endif
[email protected]f3b1a082011-11-18 00:34:30409 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03410 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07411 host->GetChannel()->AddFilter(
412 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38413
[email protected]2ccf45c2011-08-19 23:35:50414 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
415 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07416
417 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56418
419 RendererContentSettingRules rules;
420 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
421 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14422}
423
[email protected]e0ada9c2012-03-20 03:54:43424void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
425 content::BrowserChildProcessHost* host) {
426 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
427}
428
[email protected]863f70a2012-01-27 02:05:50429content::WebUIControllerFactory*
430 ChromeContentBrowserClient::GetWebUIControllerFactory() {
431 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56432}
433
[email protected]3d7474ff2011-07-27 17:47:37434GURL ChromeContentBrowserClient::GetEffectiveURL(
435 content::BrowserContext* browser_context, const GURL& url) {
436 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08437 // Get the effective URL for the given actual URL. If the URL is part of an
438 // installed app, the effective URL is an extension URL with the ID of that
439 // extension as the host. This has the effect of grouping apps together in
440 // a common SiteInstance.
441 if (!profile || !profile->GetExtensionService())
442 return url;
443
[email protected]615d88f2011-12-13 01:47:44444 const Extension* extension = profile->GetExtensionService()->extensions()->
445 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08446 if (!extension)
447 return url;
448
[email protected]15877ca2011-11-18 22:40:52449 // Bookmark apps do not use the hosted app process model, and should be
450 // treated as normal URLs.
451 if (extension->from_bookmark())
452 return url;
453
[email protected]36fb2c7c2011-04-04 15:49:08454 // If the URL is part of an extension's web extent, convert it to an
455 // extension URL.
456 return extension->GetResourceURL(url.path());
457}
458
[email protected]056ad2a2011-07-12 02:13:55459bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37460 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55461 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52462 // Because we expect to use the effective URL, URLs for hosted apps (apart
463 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55464 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
465 return false;
466
[email protected]3d7474ff2011-07-27 17:47:37467 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55468 if (!profile || !profile->GetExtensionService())
469 return false;
470
[email protected]615d88f2011-12-13 01:47:44471 const Extension* extension = profile->GetExtensionService()->extensions()->
472 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55473 if (!extension)
474 return false;
475
476 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53477 // permission, or that does not allow JavaScript access to the background
478 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55479 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53480 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
481 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
482 !extension->allow_background_js_access()) {
483 return false;
484 }
485 }
[email protected]056ad2a2011-07-12 02:13:55486
[email protected]7b54ca02012-03-02 18:06:53487 // Hosted apps that have script access to their background page must use
488 // process per site, since all instances can make synchronous calls to the
489 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55490 return true;
491}
492
[email protected]46fb9442011-12-09 17:57:47493bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
494 return ProfileIOData::IsHandledURL(url);
495}
496
[email protected]2a5221b2011-09-27 23:07:31497bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30498 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31499 const GURL& site_url) {
500 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30501 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42502 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46503 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31504
[email protected]ffa97602011-11-17 17:55:52505 // Don't allow the Task Manager to share a process with anything else.
506 // Otherwise it can affect the renderers it is observing.
507 // Note: we could create another RenderProcessHostPrivilege bucket for
508 // this to allow multiple chrome://tasks instances to share, but that's
509 // a very unlikely case without serious consequences.
510 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
511 return false;
512
[email protected]8d3132f62011-10-12 07:13:42513 // These may be NULL during tests. In that case, just assume any site can
514 // share any host.
[email protected]6f371442011-11-09 06:45:46515 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31516 return true;
517
[email protected]a8c269a2011-10-25 20:17:22518 // Experimental:
519 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
520 // to share a renderer process. (We could allow pages from the same site or
521 // extensions of the same type to share, if we knew what the given process
522 // was dedicated to. Allowing no sharing is simpler for now.) This may
523 // cause resource exhaustion issues if too many sites are open at once.
524 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
525 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
526 return false;
527
[email protected]eec0b33c2011-12-05 22:09:45528 // An isolated app is only allowed to share with the exact same app in order
529 // to provide complete renderer process isolation. This also works around
530 // issue http://crbug.com/85588, where different isolated apps in the same
531 // process would end up using the first app's storage contexts.
532 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42533 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45534 if (privilege_required == PRIV_ISOLATED)
535 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
536
537 // Otherwise, just make sure the process privilege matches the privilege
538 // required by the site.
539 return GetProcessPrivilege(process_host, process_map, service) ==
540 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31541}
542
[email protected]76411f412012-02-22 18:56:06543// This function is trying to limit the amount of processes used by extensions
544// with background pages. It uses a globally set percentage of processes to
545// run such extensions and if the limit is exceeded, it returns true, to
546// indicate to the content module to group extensions together.
547bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
548 content::BrowserContext* browser_context, const GURL& url) {
549 // It has to be a valid URL for us to check for an extension.
550 if (!url.is_valid())
551 return false;
552
553 Profile* profile = Profile::FromBrowserContext(browser_context);
554 ExtensionService* service = profile->GetExtensionService();
555 if (!service)
556 return false;
557
558 // We have to have a valid extension with background page to proceed.
559 const Extension* extension =
560 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
561 if (!extension)
562 return false;
563 if (!extension->has_background_page())
564 return false;
565
566 std::set<int> process_ids;
567 size_t max_process_count =
568 content::RenderProcessHost::GetMaxRendererProcessCount();
569
570 // Go through all profiles to ensure we have total count of extension
571 // processes containing background pages, otherwise one profile can
572 // starve the other.
573 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
574 GetLoadedProfiles();
575 for (size_t i = 0; i < profiles.size(); ++i) {
576 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32577 for (ExtensionProcessManager::const_iterator iter =
578 epm->background_hosts().begin();
579 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06580 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32581 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06582 }
583 }
584
585 if (process_ids.size() >
586 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
587 return true;
588 }
589
590 return false;
591}
592
[email protected]6f371442011-11-09 06:45:46593void ChromeContentBrowserClient::SiteInstanceGotProcess(
594 SiteInstance* site_instance) {
595 CHECK(site_instance->HasProcess());
596
597 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02598 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46599 ExtensionService* service = profile->GetExtensionService();
600 if (!service)
601 return;
602
603 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44604 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33605 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46606 if (!extension)
607 return;
608
[email protected]6bc04fd82011-12-04 02:29:35609 service->process_map()->Insert(extension->id(),
610 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33611 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46612 BrowserThread::PostTask(
613 BrowserThread::IO, FROM_HERE,
614 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24615 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46616 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35617 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33618 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46619}
620
621void ChromeContentBrowserClient::SiteInstanceDeleting(
622 SiteInstance* site_instance) {
623 if (!site_instance->HasProcess())
624 return;
625
626 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02627 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46628 ExtensionService* service = profile->GetExtensionService();
629 if (!service)
630 return;
631
632 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44633 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33634 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46635 if (!extension)
636 return;
637
[email protected]6bc04fd82011-12-04 02:29:35638 service->process_map()->Remove(extension->id(),
639 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33640 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46641 BrowserThread::PostTask(
642 BrowserThread::IO, FROM_HERE,
643 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24644 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46645 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35646 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33647 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46648}
649
[email protected]e3daf3c2011-10-05 21:17:08650bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
651 const GURL& current_url,
652 const GURL& new_url) {
653 if (current_url.is_empty()) {
654 // Always choose a new process when navigating to extension URLs. The
655 // process grouping logic will combine all of a given extension's pages
656 // into the same process.
657 if (new_url.SchemeIs(chrome::kExtensionScheme))
658 return true;
659
660 return false;
661 }
662
663 // Also, we must switch if one is an extension and the other is not the exact
664 // same extension.
665 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
666 new_url.SchemeIs(chrome::kExtensionScheme)) {
667 if (current_url.GetOrigin() != new_url.GetOrigin())
668 return true;
669 }
670
671 return false;
672}
673
[email protected]395045c2012-05-22 15:04:38674bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
675 content::ResourceContext* resource_context, const GURL& current_url,
676 const GURL& new_url) {
677 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
678 return extensions::CrossesExtensionProcessBoundary(
679 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17680 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38681}
682
[email protected]763ec4ca2011-04-29 15:48:12683std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
684 const std::string& alias_name) {
685 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
686}
687
[email protected]b80f68432011-05-02 17:22:30688void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
689 CommandLine* command_line, int child_process_id) {
690#if defined(USE_LINUX_BREAKPAD)
691 if (IsCrashReporterEnabled()) {
692 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
693 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
694 }
695#elif defined(OS_MACOSX)
696 if (IsCrashReporterEnabled()) {
697 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
698 child_process_logging::GetClientId());
699 }
700#endif // OS_MACOSX
701
[email protected]f1933792011-06-14 00:49:34702 if (logging::DialogsAreSuppressed())
703 command_line->AppendSwitch(switches::kNoErrorDialogs);
704
[email protected]b80f68432011-05-02 17:22:30705 std::string process_type =
706 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17707 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52708 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30709 FilePath user_data_dir =
710 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
711 if (!user_data_dir.empty())
712 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
713#if defined(OS_CHROMEOS)
714 const std::string& login_profile =
715 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
716 if (!login_profile.empty())
717 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
718#endif
719
[email protected]f3b1a082011-11-18 00:34:30720 content::RenderProcessHost* process =
721 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37722 if (process) {
723 Profile* profile = Profile::FromBrowserContext(
724 process->GetBrowserContext());
725 extensions::ProcessMap* process_map =
726 profile->GetExtensionService()->process_map();
727 if (process_map && process_map->Contains(process->GetID()))
728 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30729
[email protected]a8d851f82011-12-21 00:32:37730 PrefService* prefs = profile->GetPrefs();
731 // Currently this pref is only registered if applied via a policy.
732 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
733 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
734 // Turn this policy into a command line switch.
735 command_line->AppendSwitch(switches::kDisable3DAPIs);
736 }
[email protected]718eab62011-10-05 21:16:52737
[email protected]a8d851f82011-12-21 00:32:37738 // Disable client-side phishing detection in the renderer if it is
739 // disabled in the Profile preferences or the browser process.
740 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
741 !g_browser_process->safe_browsing_detection_service()) {
742 command_line->AppendSwitch(
743 switches::kDisableClientSidePhishingDetection);
744 }
[email protected]8c40da62011-07-13 22:58:46745 }
[email protected]47c7ec82012-01-18 03:29:21746 {
747 PrefService* local_state = g_browser_process->local_state();
748 if (local_state &&
749 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
750 command_line->AppendSwitch(switches::kRendererPrintPreview);
751 }
752 }
[email protected]4287a3d2011-06-13 23:56:51753
[email protected]47c7ec82012-01-18 03:29:21754 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51755 static const char* const kSwitchNames[] = {
756 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48757 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51758 switches::kAllowScriptingGallery,
759 switches::kAppsCheckoutURL,
760 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31761 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51762 switches::kDebugPrint,
[email protected]37b928e2012-05-30 09:01:10763 switches::kDisableAsynchronousSpellChecking,
[email protected]382fb0d2012-02-25 00:19:50764 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53765 switches::kDisableExtensionsResourceWhitelist,
[email protected]25900c92012-05-31 07:20:09766 switches::kDisableInBrowserThumbnailing,
[email protected]4287a3d2011-06-13 23:56:51767 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21768 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13769 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51770 switches::kEnableCrxlessWebApps,
771 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:51772 switches::kEnableIPCFuzzing,
773 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05774 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48775 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53776 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51777 switches::kEnableWatchdog,
778 switches::kExperimentalSpellcheckerFeatures,
779 switches::kMemoryProfiling,
780 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37781 switches::kNoJsRandomness,
[email protected]2a6bb0b12011-10-05 19:18:04782 switches::kNoRunningInsecureContent,
[email protected]f45c5f32012-04-18 19:26:37783 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51784 switches::kPpapiFlashArgs,
785 switches::kPpapiFlashInProcess,
786 switches::kPpapiFlashPath,
787 switches::kPpapiFlashVersion,
788 switches::kProfilingAtStart,
789 switches::kProfilingFile,
790 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37791 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51792 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38793 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51794 };
795
796 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
797 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17798 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38799 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:35800 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:38801 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37802 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38803 switches::kWhitelistedExtensionID,
804 };
805
806 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
807 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51808 } else if (process_type == switches::kPluginProcess) {
809 static const char* const kSwitchNames[] = {
810 #if defined(OS_CHROMEOS)
811 switches::kLoginProfile,
812 #endif
813 switches::kMemoryProfiling,
814 switches::kSilentDumpOnDCHECK,
815 switches::kUserDataDir,
816 };
817
818 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
819 arraysize(kSwitchNames));
820 } else if (process_type == switches::kZygoteProcess) {
821 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51822 switches::kUserDataDir, // Make logs go to the right file.
823 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50824 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13825 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51826 switches::kPpapiFlashInProcess,
827 switches::kPpapiFlashPath,
828 switches::kPpapiFlashVersion,
829 };
830
831 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
832 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11833 } else if (process_type == switches::kGpuProcess) {
834 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
835 // because GPU is expected to be unreliable.
836 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
837 !command_line->HasSwitch(switches::kDisableBreakpad))
838 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30839 }
[email protected]6f08af82011-09-15 01:19:03840
841 // The command line switch kEnableBenchmarking needs to be specified along
842 // with the kEnableStatsTable switch to ensure that the stats table global
843 // is initialized correctly.
844 if (command_line->HasSwitch(switches::kEnableBenchmarking))
845 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30846}
847
848std::string ChromeContentBrowserClient::GetApplicationLocale() {
849 return g_browser_process->GetApplicationLocale();
850}
851
[email protected]597a867b2011-11-18 18:31:20852std::string ChromeContentBrowserClient::GetAcceptLangs(
853 content::BrowserContext* context) {
854 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37855 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08856}
857
[email protected]ac55e292011-06-24 05:16:08858SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22859 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08860 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
861}
862
[email protected]a2176792011-05-08 19:30:49863bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09864 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19865 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20866 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20868 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05869 return io_data->GetCookieSettings()->
870 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49871}
872
[email protected]ed24fad2011-05-10 22:44:01873bool ChromeContentBrowserClient::AllowGetCookie(
874 const GURL& url,
875 const GURL& first_party,
876 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20877 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01878 int render_process_id,
879 int render_view_id) {
880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20881 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05882 bool allow = io_data->GetCookieSettings()->
883 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01884
[email protected]8093a542011-05-13 07:29:32885 BrowserThread::PostTask(
886 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03887 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43888 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01889 return allow;
890}
891
892bool ChromeContentBrowserClient::AllowSetCookie(
893 const GURL& url,
894 const GURL& first_party,
895 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20896 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01897 int render_process_id,
898 int render_view_id,
899 net::CookieOptions* options) {
900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20901 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05902 CookieSettings* cookie_settings = io_data->GetCookieSettings();
903 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
904
[email protected]8093a542011-05-13 07:29:32905 BrowserThread::PostTask(
906 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03907 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43908 render_view_id, url, first_party, cookie_line, *options,
909 !allow));
[email protected]ed24fad2011-05-10 22:44:01910 return allow;
911}
912
[email protected]d5a19162011-06-30 18:51:54913bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20914 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20916 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26917
[email protected]f24bd172012-03-31 01:54:59918 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54919}
920
[email protected]5c5a88e2011-11-12 00:45:35921bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35922 const GURL& url,
923 const string16& name,
924 const string16& display_name,
925 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20926 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48927 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20929 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35930 CookieSettings* cookie_settings = io_data->GetCookieSettings();
931 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
932
[email protected]62151052012-02-01 18:40:48933 // Record access to database for potential display in UI.
934 std::vector<std::pair<int, int> >::const_iterator i;
935 for (i = render_views.begin(); i != render_views.end(); ++i) {
936 BrowserThread::PostTask(
937 BrowserThread::UI, FROM_HERE,
938 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
939 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35940 }
941
942 return allow;
943}
944
945bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35946 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20947 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48948 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35949 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20950 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35951 CookieSettings* cookie_settings = io_data->GetCookieSettings();
952 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
953
[email protected]62151052012-02-01 18:40:48954 // Record access to file system for potential display in UI.
955 std::vector<std::pair<int, int> >::const_iterator i;
956 for (i = render_views.begin(); i != render_views.end(); ++i) {
957 BrowserThread::PostTask(
958 BrowserThread::UI, FROM_HERE,
959 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
960 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35961 }
962
963 return allow;
964}
965
[email protected]7c5ff9a2012-03-02 07:42:49966bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
967 const GURL& url,
968 const string16& name,
969 content::ResourceContext* context,
970 const std::vector<std::pair<int, int> >& render_views) {
971 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
972 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
973 CookieSettings* cookie_settings = io_data->GetCookieSettings();
974 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
975
976 // Record access to IndexedDB for potential display in UI.
977 std::vector<std::pair<int, int> >::const_iterator i;
978 for (i = render_views.begin(); i != render_views.end(); ++i) {
979 BrowserThread::PostTask(
980 BrowserThread::UI, FROM_HERE,
981 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
982 i->first, i->second, url, name, !allow));
983 }
984
985 return allow;
986}
987
[email protected]6133f922011-07-01 21:34:34988net::URLRequestContext*
989ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20990 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34991 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
992 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20993 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34994 return io_data->extensions_request_context();
995 }
996
997 return NULL;
998}
999
[email protected]317f96c92011-05-31 06:53:411000QuotaPermissionContext*
1001ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1002 return new ChromeQuotaPermissionContext();
1003}
1004
[email protected]a0ce3282011-08-19 20:49:521005void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421006 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421007}
1008
[email protected]a0ce3282011-08-19 20:49:521009void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521010 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521011}
1012
[email protected]848dd042011-06-04 18:24:031013void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171014 int render_process_id,
1015 int render_view_id,
1016 int cert_error,
1017 const net::SSLInfo& ssl_info,
1018 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031019 bool overridable,
[email protected]d9be47702012-05-16 03:41:221020 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171021 const base::Callback<void(bool)>& callback,
1022 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411023 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131024 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171025 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411026 if (!tab) {
1027 NOTREACHED();
1028 return;
1029 }
1030 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501031 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301032 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091033 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411034 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171035 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411036 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171037 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411038 return;
1039 }
1040 }
1041
1042 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221043 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1044 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031045}
1046
[email protected]c99c442e2011-08-24 11:37:301047void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451048 int render_process_id,
1049 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401050 const net::HttpNetworkSession* network_session,
1051 net::SSLCertRequestInfo* cert_request_info,
1052 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131053 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451054 render_process_id, render_view_id);
1055 if (!tab) {
1056 NOTREACHED();
1057 return;
1058 }
1059
[email protected]6786bf402011-12-03 15:19:451060 GURL requesting_url("https://" + cert_request_info->host_and_port);
1061 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1062 << cert_request_info->host_and_port;
1063
[email protected]627e0512011-12-21 22:55:301064 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451065 scoped_ptr<Value> filter(
1066 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1067 requesting_url,
1068 requesting_url,
1069 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1070 std::string(), NULL));
1071
1072 if (filter.get()) {
1073 // Try to automatically select a client certificate.
1074 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1075 DictionaryValue* filter_dict =
1076 static_cast<DictionaryValue*>(filter.get());
1077
1078 const std::vector<scoped_refptr<net::X509Certificate> >&
1079 all_client_certs = cert_request_info->client_certs;
1080 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1081 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1082 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401083 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451084 return;
1085 }
1086 }
1087 } else {
1088 NOTREACHED();
1089 }
1090 }
1091
[email protected]8ec26472011-06-06 16:52:451092 TabContentsWrapper* wrapper =
1093 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451094 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131095 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451096 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141097 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401098 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451099 return;
1100 }
[email protected]7a593db2012-02-13 21:19:401101 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1102 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451103}
1104
1105void ChromeContentBrowserClient::AddNewCertificate(
1106 net::URLRequest* request,
1107 net::X509Certificate* cert,
1108 int render_process_id,
1109 int render_view_id) {
1110 // The handler will run the UI and delete itself when it's finished.
1111 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1112}
1113
[email protected]a93670ab2012-02-24 03:46:391114void ChromeContentBrowserClient::RequestMediaAccessPermission(
1115 const content::MediaStreamRequest* request,
1116 const content::MediaResponseCallback& callback) {
1117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1118
[email protected]117b6b42012-02-29 09:11:081119 WebContents* contents = tab_util::GetWebContentsByID(
1120 request->render_process_id, request->render_view_id);
1121 if (!contents) {
1122 // Abort, if the tab was closed after the request was made but before we
1123 // got to this point.
1124 callback.Run(content::MediaStreamDevices());
1125 return;
1126 }
1127
1128 TabContentsWrapper* tab =
1129 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1130 DCHECK(tab);
1131
1132 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1133 InfoBarDelegate* old_infobar = NULL;
1134 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1135 old_infobar =
[email protected]51d1fc62012-04-28 03:47:531136 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfoBarDelegate();
[email protected]117b6b42012-02-29 09:11:081137 }
1138
[email protected]117b6b42012-02-29 09:11:081139 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1140 request,
1141 callback);
1142 if (old_infobar)
1143 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1144 else
1145 infobar_helper->AddInfoBar(infobar);
[email protected]a93670ab2012-02-24 03:46:391146}
1147
[email protected]dc73a7b2012-03-25 15:27:181148content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1149 return MediaInternals::GetInstance();
1150}
1151
[email protected]941623e2011-06-07 23:06:041152void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1153 const GURL& source_origin,
1154 int callback_context,
1155 int render_process_id,
1156 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111157#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041158 RenderViewHost* rvh = RenderViewHost::FromID(
1159 render_process_id, render_view_id);
1160 if (!rvh) {
1161 NOTREACHED();
1162 return;
1163 }
1164
[email protected]9f76c1e2012-03-05 15:15:581165 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301166 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041167 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371168 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041169 service->RequestPermission(
1170 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131171 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111172#else
1173 NOTIMPLEMENTED();
1174#endif
[email protected]941623e2011-06-07 23:06:041175}
1176
1177WebKit::WebNotificationPresenter::Permission
1178 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021179 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201180 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021181 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111182#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201184 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021185 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1186 source_origin, render_process_id,
1187 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041188 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041189
1190 // Fall back to the regular notification preferences, which works on an
1191 // origin basis.
1192 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371193 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041194 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111195#else
1196 return WebKit::WebNotificationPresenter::PermissionAllowed;
1197#endif
[email protected]941623e2011-06-07 23:06:041198}
1199
1200void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171201 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041202 int render_process_id,
1203 int render_view_id,
1204 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111205#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041206 RenderViewHost* rvh = RenderViewHost::FromID(
1207 render_process_id, render_view_id);
1208 if (!rvh) {
1209 NOTREACHED();
1210 return;
1211 }
1212
[email protected]9f76c1e2012-03-05 15:15:581213 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301214 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041215 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371216 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041217 service->ShowDesktopNotification(
1218 params, render_process_id, render_view_id,
1219 worker ? DesktopNotificationService::WorkerNotification :
1220 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111221#else
1222 NOTIMPLEMENTED();
1223#endif
[email protected]941623e2011-06-07 23:06:041224}
1225
1226void ChromeContentBrowserClient::CancelDesktopNotification(
1227 int render_process_id,
1228 int render_view_id,
1229 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111230#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041231 RenderViewHost* rvh = RenderViewHost::FromID(
1232 render_process_id, render_view_id);
1233 if (!rvh) {
1234 NOTREACHED();
1235 return;
1236 }
1237
[email protected]9f76c1e2012-03-05 15:15:581238 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301239 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041240 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371241 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041242 service->CancelDesktopNotification(
1243 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111244#else
1245 NOTIMPLEMENTED();
1246#endif
[email protected]941623e2011-06-07 23:06:041247}
1248
[email protected]9f3fba52011-06-08 20:37:191249bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351250 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021251 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191252 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201253 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011254 int render_process_id,
1255 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011257
1258 *no_javascript_access = false;
1259
[email protected]9f3fba52011-06-08 20:37:191260 // If the opener is trying to create a background window but doesn't have
1261 // the appropriate permission, fail the attempt.
1262 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201263 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531264 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1265
[email protected]03b6d552012-03-29 04:03:011266 if (!map->SecurityOriginHasAPIPermission(
1267 source_origin,
1268 render_process_id,
1269 ExtensionAPIPermission::kBackground)) {
1270 return false;
1271 }
1272
[email protected]7b54ca02012-03-02 18:06:531273 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1274 // return a recently installed Extension even if this CanCreateWindow call
1275 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011276 // because the permission check above would have caused an early return
1277 // already. We must use the full URL to find hosted apps, though, and not
1278 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531279 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351280 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531281 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011282 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191283 }
1284 return true;
1285}
1286
1287std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201288 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1290 // Check if it's an extension-created worker, in which case we want to use
1291 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201292 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191293 const Extension* extension =
1294 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1295 return extension ? extension->name() : std::string();
1296}
1297
[email protected]99907362012-01-11 05:41:401298void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1299 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171300}
1301
[email protected]c52b2892012-03-07 11:01:021302content::SpeechRecognitionManagerDelegate*
1303 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321304#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021305 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321306#else
1307 return NULL;
1308#endif
[email protected]66cfec62012-02-24 17:57:511309}
1310
[email protected]ae6e9912011-07-27 01:18:281311net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1312 return g_browser_process->net_log();
1313}
1314
[email protected]32538d92011-08-25 00:09:231315AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1316 return new ChromeAccessTokenStore();
1317}
1318
[email protected]dbae6b02011-06-29 23:51:411319bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1320 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1321 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1322}
1323
[email protected]64d69de42012-02-06 00:19:541324void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321325 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061326 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581327 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061328 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061329
[email protected]f3986f82012-01-03 20:00:061330 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541331 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061332 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541333 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061334 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541335 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061336 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541337 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061338 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541339 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061340 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541341 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061342
[email protected]64d69de42012-02-06 00:19:541343 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401344 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541345 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401346 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541347 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401348 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541349 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401350 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061351
[email protected]ddf72142012-05-22 04:52:401352 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061353
[email protected]64d69de42012-02-06 00:19:541354 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401355 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541356 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061357 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541358 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061359 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1360 const DictionaryValue* inspector_settings =
1361 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1362 if (inspector_settings) {
1363 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1364 iter != inspector_settings->end_keys(); ++iter) {
1365 std::string value;
1366 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541367 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061368 std::make_pair(*iter, value));
1369 }
1370 }
[email protected]64d69de42012-02-06 00:19:541371 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061372
[email protected]ddf72142012-05-22 04:52:401373 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541374 web_prefs->javascript_enabled = false;
1375 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1376 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401377 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541378 web_prefs->plugins_enabled = false;
1379 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1380 web_prefs->java_enabled = false;
1381 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401382 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061383
[email protected]64d69de42012-02-06 00:19:541384 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1385 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061386
[email protected]64d69de42012-02-06 00:19:541387 web_prefs->memory_info_enabled =
1388 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1389 web_prefs->allow_displaying_insecure_content =
1390 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1391 web_prefs->allow_running_insecure_content =
1392 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081393 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061394
[email protected]64d69de42012-02-06 00:19:541395 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151396 UserStyleSheetWatcher* user_style_sheet_watcher =
1397 UserStyleSheetWatcherFactory::GetForProfile(profile);
1398 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541399 web_prefs->user_style_sheet_enabled = true;
1400 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151401 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541402 } else {
1403 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061404 }
1405
[email protected]b7e44ff2012-02-16 03:37:341406 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101407#if defined(OS_MACOSX)
1408 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1409 // Mac so it uses NSSpellChecker in the background.
1410 false;
1411#else
1412 !CommandLine::ForCurrentProcess()->
1413 HasSwitch(switches::kDisableAsynchronousSpellChecking);
1414#endif
[email protected]b7e44ff2012-02-16 03:37:341415 web_prefs->unified_textchecker_enabled =
1416 web_prefs->asynchronous_spell_checking_enabled ||
1417 CommandLine::ForCurrentProcess()->
1418 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571419
[email protected]64d69de42012-02-06 00:19:541420 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061421 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541422 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061423 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541424 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061425 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1426
1427 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541428 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061429 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541430 web_prefs->default_encoding);
1431 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401432 prefs->ClearPref(prefs::kDefaultCharset);
1433 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061434 }
[email protected]64d69de42012-02-06 00:19:541435 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061436
[email protected]299d7f12012-05-23 05:31:151437 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1438 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061439 ExtensionService* service = profile->GetExtensionService();
1440 if (service) {
1441 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581442 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061443 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151444 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061445 }
1446
[email protected]299d7f12012-05-23 05:31:151447 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541448 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151449 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061450 // Disable all kinds of acceleration for background pages.
1451 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541452 web_prefs->force_compositing_mode = false;
1453 web_prefs->accelerated_compositing_enabled = false;
1454 web_prefs->accelerated_2d_canvas_enabled = false;
1455 web_prefs->accelerated_video_enabled = false;
1456 web_prefs->accelerated_painting_enabled = false;
1457 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061458 }
[email protected]2e21fe292012-03-02 22:52:321459
1460#if defined(FILE_MANAGER_EXTENSION)
1461 // Override the default of suppressing HW compositing for WebUI pages for the
1462 // file manager, which is implemented using WebUI but wants HW acceleration
1463 // for video decode & render.
1464 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1465 web_prefs->accelerated_compositing_enabled = true;
1466 web_prefs->accelerated_2d_canvas_enabled = true;
1467 }
1468#endif
[email protected]181a95ee2011-07-12 19:26:361469}
1470
1471void ChromeContentBrowserClient::UpdateInspectorSetting(
1472 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061473 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581474 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061475 DictionaryPrefUpdate update(
1476 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1477 prefs::kWebKitInspectorSettings);
1478 DictionaryValue* inspector_settings = update.Get();
1479 inspector_settings->SetWithoutPathExpansion(key,
1480 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361481}
1482
1483void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061484 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581485 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061486 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1487 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361488}
1489
[email protected]b8148ac2011-07-13 22:03:251490void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1491 BrowserURLHandler* handler) {
1492 // Add the default URL handlers.
1493 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1494 BrowserURLHandler::null_handler());
1495 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1496 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1497
[email protected]b3adbd02011-11-30 22:23:271498 // about: handler. Must come before chrome: handler, since it will
1499 // rewrite about: urls to chrome: URLs and then expect chrome: to
1500 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251501 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1502 BrowserURLHandler::null_handler());
1503 // chrome: & friends.
1504 handler->AddHandlerPair(&HandleWebUI,
1505 BrowserURLHandler::null_handler());
1506}
1507
1508void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371509 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581510 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251511 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1512 BrowsingDataRemover::EVERYTHING,
1513 base::Time());
1514 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1515 // BrowsingDataRemover takes care of deleting itself when done.
1516}
1517
1518void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371519 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581520 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251521 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1522 BrowsingDataRemover::EVERYTHING,
1523 base::Time());
[email protected]dceaa912011-09-06 17:17:231524 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251525 remover->Remove(remove_mask);
1526 // BrowsingDataRemover takes care of deleting itself when done.
1527}
1528
[email protected]e1d16eb92011-08-18 23:19:321529FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1530 return download_util::GetDefaultDownloadDirectory();
1531}
1532
[email protected]c9b6eb62011-10-18 20:49:391533std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1534 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1535}
1536
[email protected]a658d452012-03-02 12:45:291537bool ChromeContentBrowserClient::AllowSocketAPI(
1538 content::BrowserContext* browser_context, const GURL& url) {
1539 if (!url.is_valid())
1540 return false;
1541
1542 std::string host = url.host();
1543 if (allowed_socket_origins_.count(host))
1544 return true;
1545
[email protected]9a5940d2012-04-27 19:16:231546 Profile* profile = Profile::FromBrowserContext(browser_context);
1547 const Extension* extension = NULL;
1548 if (profile && profile->GetExtensionService()) {
1549 extension = profile->GetExtensionService()->extensions()->
1550 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1551 }
1552
[email protected]f237c0f2012-03-10 07:49:101553 // Need to check this now and not on construction because otherwise it won't
1554 // work with browser_tests.
1555 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1556 std::string allowed_list =
1557 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231558 if (allowed_list == "*") {
1559 // The wildcard allows socket API only for packaged and platform apps.
1560 return extension &&
1561 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1562 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1563 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101564 StringTokenizer t(allowed_list, ",");
1565 while (t.GetNext()) {
1566 if (t.token() == host)
1567 return true;
1568 }
1569 }
1570
[email protected]a658d452012-03-02 12:45:291571 if (!extension)
1572 return false;
1573
1574 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1575 return true;
1576
1577 return false;
[email protected]e461da2f2012-02-16 19:06:401578}
1579
[email protected]e60c0232011-11-11 19:56:351580#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301581int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521582 const CommandLine& command_line) {
1583 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071584 ExtensionCrashHandlerHostLinux* crash_handler =
1585 ExtensionCrashHandlerHostLinux::GetInstance();
1586 return crash_handler->GetDeathSignalSocket();
1587 }
1588
[email protected]718eab62011-10-05 21:16:521589 std::string process_type =
1590 command_line.GetSwitchValueASCII(switches::kProcessType);
1591
1592 if (process_type == switches::kRendererProcess)
1593 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1594
[email protected]b80f68432011-05-02 17:22:301595 if (process_type == switches::kPluginProcess)
1596 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1597
1598 if (process_type == switches::kPpapiPluginProcess)
1599 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1600
1601 if (process_type == switches::kGpuProcess)
1602 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1603
1604 return -1;
1605}
[email protected]e60c0232011-11-11 19:56:351606#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301607
[email protected]4a65826d2011-08-25 16:04:011608#if defined(OS_WIN)
1609const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1610 return chrome::kBrowserResourcesDll;
1611}
1612#endif
1613
[email protected]37a72af2011-06-13 05:42:011614#if defined(USE_NSS)
1615crypto::CryptoModuleBlockingPasswordDelegate*
1616 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1617 const GURL& url) {
1618 return browser::NewCryptoModuleBlockingDialogDelegate(
1619 browser::kCryptoModulePasswordKeygen, url.host());
1620}
1621#endif
1622
[email protected]d977f9c2011-03-14 16:10:261623} // namespace chrome