blob: c031d11bc89523e46b1e784acb01df79e182f383 [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]117b6b42012-02-29 09:11:0866#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4567#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5068#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0669#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1570#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3071#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0172#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3073#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0474#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4475#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3476#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1277#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3878#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0979#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4380#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3081#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3182#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5983#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3084#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3385#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0586#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3387#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1988#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1089#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4390#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3991#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3492#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4093#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0694#include "net/cookies/cookie_monster.h"
95#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3996#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0897#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3698#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:0499#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26100
[email protected]b48c9182011-10-26 18:03:30101#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38102#include "chrome/browser/chrome_browser_main_win.h"
103#elif defined(OS_MACOSX)
104#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56105#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57106#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30107#elif defined(OS_CHROMEOS)
108#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49109#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26110#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30111#include "chrome/browser/chrome_browser_main_linux.h"
112#elif defined(OS_POSIX)
113#include "chrome/browser/chrome_browser_main_posix.h"
114#endif
115
[email protected]c0d7f792012-04-18 19:16:00116#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13117#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]61e69822012-03-14 22:08:57118#endif
119
[email protected]a13283cc2012-04-05 00:21:22120#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31121#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38122#endif
123
[email protected]c7480942011-11-08 19:18:27124#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31125#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27126#endif
127
128#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31129#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
130#endif
131
[email protected]dc04be7c2012-03-15 23:57:49132#if defined(USE_ASH)
133#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
134#endif
135
[email protected]6653c192012-04-10 22:52:44136#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30137#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44138#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43139#endif
[email protected]b80f68432011-05-02 17:22:30140
[email protected]38b098f2012-03-14 21:11:57141#if defined(TOOLKIT_GTK)
142#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32143#endif
[email protected]37a72af2011-06-13 05:42:01144#if defined(USE_NSS)
145#include "chrome/browser/ui/crypto_module_password_dialog.h"
146#endif
147
[email protected]c8c77182011-12-21 15:04:47148using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39149using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31150using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59151using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00152using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11153using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33154using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13155using content::WebContents;
[email protected]1c321ee2012-05-21 03:02:34156using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25157using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39158
[email protected]c5dbef02011-05-13 05:06:09159namespace {
160
[email protected]e461da2f2012-02-16 19:06:40161const char* kPredefinedAllowedSocketOrigins[] = {
162 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18163 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45164 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
165 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
166 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
167 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
168 "ojoimpklfciegopdfgeenehpalipignm" // Chromoting canary
[email protected]e461da2f2012-02-16 19:06:40169};
170
[email protected]b8148ac2011-07-13 22:03:25171// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42172bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50173 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
174 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25175 return false;
176
[email protected]fe69558d2012-03-12 11:34:49177#if defined(OS_CHROMEOS)
178 // Special case : in ChromeOS in Guest mode bookmarks and history are
179 // disabled for security reasons. New tab page explains the reasons, so
180 // we redirect user to new tab page.
181 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
182 if (url->SchemeIs(chrome::kChromeUIScheme) &&
183 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
184 url->DomainIs(chrome::kChromeUIHistoryHost))) {
185 // Rewrite with new tab URL
186 *url = GURL(chrome::kChromeUINewTabURL);
187 }
188 }
189#endif
190
[email protected]b8148ac2011-07-13 22:03:25191 // Special case the new tab page. In older versions of Chrome, the new tab
192 // page was hosted at chrome-internal:<blah>. This might be in people's saved
193 // sessions or bookmarks, so we say any URL with that scheme triggers the new
194 // tab page.
195 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
196 // Rewrite it with the proper new tab URL.
197 *url = GURL(chrome::kChromeUINewTabURL);
198 }
199
200 return true;
201}
202
[email protected]8d3132f62011-10-12 07:13:42203// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
204// below. Extension, and isolated apps require different privileges to be
205// granted to their RenderProcessHosts. This classification allows us to make
206// sure URLs are served by hosts with the right set of privileges.
207enum RenderProcessHostPrivilege {
208 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45209 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42210 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45211 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42212};
213
214RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
215 const GURL& url,
216 ExtensionService* service) {
217 // Default to a normal renderer cause it is lower privileged. This should only
218 // occur if the URL on a site instance is either malformed, or uninitialized.
219 // If it is malformed, then there is no need for better privileges anyways.
220 // If it is uninitialized, but eventually settles on being an a scheme other
221 // than normal webrenderer, the navigation logic will correct us out of band
222 // anyways.
223 if (!url.is_valid())
224 return PRIV_NORMAL;
225
226 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44227 const Extension* extension =
228 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45229 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42230 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45231 if (extension && extension->is_hosted_app())
232 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42233
234 return PRIV_EXTENSION;
235 }
236
237 return PRIV_NORMAL;
238}
239
240RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30241 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46242 extensions::ProcessMap* process_map,
243 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46244 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30245 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46246 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21247 return PRIV_NORMAL;
248
[email protected]6f371442011-11-09 06:45:46249 for (std::set<std::string>::iterator iter = extension_ids.begin();
250 iter != extension_ids.end(); ++iter) {
251 const Extension* extension = service->GetExtensionById(*iter, false);
252 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42253 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45254 if (extension && extension->is_hosted_app())
255 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42256 }
257
[email protected]676f6ab2011-10-19 20:23:21258 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42259}
260
[email protected]eec0b33c2011-12-05 22:09:45261bool IsIsolatedAppInProcess(const GURL& site_url,
262 content::RenderProcessHost* process_host,
263 extensions::ProcessMap* process_map,
264 ExtensionService* service) {
265 std::set<std::string> extension_ids =
266 process_map->GetExtensionsInProcess(process_host->GetID());
267 if (extension_ids.empty())
268 return false;
269
270 for (std::set<std::string>::iterator iter = extension_ids.begin();
271 iter != extension_ids.end(); ++iter) {
272 const Extension* extension = service->GetExtensionById(*iter, false);
273 if (extension &&
274 extension->is_storage_isolated() &&
275 extension->url() == site_url)
276 return true;
277 }
278
279 return false;
280}
281
[email protected]6786bf402011-12-03 15:19:45282bool CertMatchesFilter(const net::X509Certificate& cert,
283 const base::DictionaryValue& filter) {
284 // TODO(markusheintz): This is the minimal required filter implementation.
285 // Implement a better matcher.
286
287 // An empty filter matches any client certificate since no requirements are
288 // specified at all.
289 if (filter.empty())
290 return true;
291
292 std::string common_name;
293 if (filter.GetString("ISSUER.CN", &common_name) &&
294 (cert.issuer().common_name == common_name)) {
295 return true;
296 }
297 return false;
298}
299
[email protected]f3986f82012-01-03 20:00:06300// Fills |map| with the per-script font prefs under path |map_name|.
301void FillFontFamilyMap(const PrefService* prefs,
302 const char* map_name,
303 WebPreferences::ScriptFontFamilyMap* map) {
304 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
305 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
306 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
307 std::string font_family = prefs->GetString(pref_name.c_str());
308 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32309 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06310 }
311}
312
[email protected]9dbfff12011-07-01 19:37:07313} // namespace
[email protected]c5dbef02011-05-13 05:06:09314
[email protected]d977f9c2011-03-14 16:10:26315namespace chrome {
316
[email protected]e461da2f2012-02-16 19:06:40317ChromeContentBrowserClient::ChromeContentBrowserClient() {
318 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
319 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40320}
321
322ChromeContentBrowserClient::~ChromeContentBrowserClient() {
323}
324
[email protected]50462bf02011-11-21 19:13:31325content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
326 const content::MainFunctionParams& parameters) {
327 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30328 // Construct the Main browser parts based on the OS type.
329#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31330 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04331#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31332 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30333#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31334 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26335#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31336 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14337#elif defined(OS_ANDROID)
338 // Do nothing for Android.
339 // TODO(klobag): Android initialization should use the
340 // *BrowserMainParts class-hierarchy for setting up custom initialization.
341 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30342#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31343 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04344#else
[email protected]b48c9182011-10-26 18:03:30345 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31346 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30347#endif
348
[email protected]c7480942011-11-08 19:18:27349 // Construct additional browser parts. Stages are called in the order in
350 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22351#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31352 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04353#endif
[email protected]c7480942011-11-08 19:18:27354
355#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31356 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27357#endif
358
[email protected]dc04be7c2012-03-15 23:57:49359#if defined(USE_ASH)
360 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
361#endif
362
[email protected]e050ef142012-03-21 01:04:24363#if defined(USE_AURA)
364 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
365#endif
366
[email protected]50462bf02011-11-21 19:13:31367 return main_parts;
[email protected]f967b722011-09-07 00:58:04368}
369
[email protected]38b098f2012-03-14 21:11:57370content::WebContentsView*
371 ChromeContentBrowserClient::OverrideCreateWebContentsView(
372 WebContents* web_contents) {
[email protected]38b098f2012-03-14 21:11:57373 return NULL;
374}
375
376content::WebContentsViewDelegate*
377 ChromeContentBrowserClient::GetWebContentsViewDelegate(
378 content::WebContents* web_contents) {
[email protected]c0d7f792012-04-18 19:16:00379#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13380 return new ChromeWebContentsViewDelegateViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57381#elif defined(TOOLKIT_GTK)
382 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32383#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57384 return
385 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
386 web_contents);
[email protected]74313b42011-08-24 16:51:32387#else
[email protected]38b098f2012-03-14 21:11:57388 return NULL;
[email protected]74313b42011-08-24 16:51:32389#endif
390}
391
[email protected]f364d1392011-04-08 21:03:10392void ChromeContentBrowserClient::RenderViewHostCreated(
393 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46394
[email protected]9f76c1e2012-03-05 15:15:58395 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46396 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02397 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46398
399 new ChromeRenderViewHostObserver(render_view_host,
400 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10401 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26402}
403
[email protected]f3b1a082011-11-18 00:34:30404void ChromeContentBrowserClient::RenderProcessHostCreated(
405 content::RenderProcessHost* host) {
406 int id = host->GetID();
407 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
408 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02409 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30410 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03411#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30412 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03413#endif
[email protected]f3b1a082011-11-18 00:34:30414 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02415 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30416 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56417#if defined(OS_MACOSX)
418 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
419#endif
[email protected]f3b1a082011-11-18 00:34:30420 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03421 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07422 host->GetChannel()->AddFilter(
423 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38424
[email protected]2ccf45c2011-08-19 23:35:50425 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
426 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07427
428 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56429
430 RendererContentSettingRules rules;
431 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
432 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14433}
434
[email protected]e0ada9c2012-03-20 03:54:43435void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
436 content::BrowserChildProcessHost* host) {
437 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
438}
439
[email protected]863f70a2012-01-27 02:05:50440content::WebUIControllerFactory*
441 ChromeContentBrowserClient::GetWebUIControllerFactory() {
442 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56443}
444
[email protected]3d7474ff2011-07-27 17:47:37445GURL ChromeContentBrowserClient::GetEffectiveURL(
446 content::BrowserContext* browser_context, const GURL& url) {
447 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08448 // Get the effective URL for the given actual URL. If the URL is part of an
449 // installed app, the effective URL is an extension URL with the ID of that
450 // extension as the host. This has the effect of grouping apps together in
451 // a common SiteInstance.
452 if (!profile || !profile->GetExtensionService())
453 return url;
454
[email protected]615d88f2011-12-13 01:47:44455 const Extension* extension = profile->GetExtensionService()->extensions()->
456 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08457 if (!extension)
458 return url;
459
[email protected]15877ca2011-11-18 22:40:52460 // Bookmark apps do not use the hosted app process model, and should be
461 // treated as normal URLs.
462 if (extension->from_bookmark())
463 return url;
464
[email protected]36fb2c7c2011-04-04 15:49:08465 // If the URL is part of an extension's web extent, convert it to an
466 // extension URL.
467 return extension->GetResourceURL(url.path());
468}
469
[email protected]056ad2a2011-07-12 02:13:55470bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37471 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55472 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52473 // Because we expect to use the effective URL, URLs for hosted apps (apart
474 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55475 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
476 return false;
477
[email protected]3d7474ff2011-07-27 17:47:37478 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55479 if (!profile || !profile->GetExtensionService())
480 return false;
481
[email protected]615d88f2011-12-13 01:47:44482 const Extension* extension = profile->GetExtensionService()->extensions()->
483 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55484 if (!extension)
485 return false;
486
487 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53488 // permission, or that does not allow JavaScript access to the background
489 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55490 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53491 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
492 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
493 !extension->allow_background_js_access()) {
494 return false;
495 }
496 }
[email protected]056ad2a2011-07-12 02:13:55497
[email protected]7b54ca02012-03-02 18:06:53498 // Hosted apps that have script access to their background page must use
499 // process per site, since all instances can make synchronous calls to the
500 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55501 return true;
502}
503
[email protected]46fb9442011-12-09 17:57:47504bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
505 return ProfileIOData::IsHandledURL(url);
506}
507
[email protected]2a5221b2011-09-27 23:07:31508bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30509 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31510 const GURL& site_url) {
511 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30512 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42513 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46514 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31515
[email protected]ffa97602011-11-17 17:55:52516 // Don't allow the Task Manager to share a process with anything else.
517 // Otherwise it can affect the renderers it is observing.
518 // Note: we could create another RenderProcessHostPrivilege bucket for
519 // this to allow multiple chrome://tasks instances to share, but that's
520 // a very unlikely case without serious consequences.
521 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
522 return false;
523
[email protected]8d3132f62011-10-12 07:13:42524 // These may be NULL during tests. In that case, just assume any site can
525 // share any host.
[email protected]6f371442011-11-09 06:45:46526 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31527 return true;
528
[email protected]a8c269a2011-10-25 20:17:22529 // Experimental:
530 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
531 // to share a renderer process. (We could allow pages from the same site or
532 // extensions of the same type to share, if we knew what the given process
533 // was dedicated to. Allowing no sharing is simpler for now.) This may
534 // cause resource exhaustion issues if too many sites are open at once.
535 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
536 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
537 return false;
538
[email protected]eec0b33c2011-12-05 22:09:45539 // An isolated app is only allowed to share with the exact same app in order
540 // to provide complete renderer process isolation. This also works around
541 // issue http://crbug.com/85588, where different isolated apps in the same
542 // process would end up using the first app's storage contexts.
543 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42544 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45545 if (privilege_required == PRIV_ISOLATED)
546 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
547
548 // Otherwise, just make sure the process privilege matches the privilege
549 // required by the site.
550 return GetProcessPrivilege(process_host, process_map, service) ==
551 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31552}
553
[email protected]76411f412012-02-22 18:56:06554// This function is trying to limit the amount of processes used by extensions
555// with background pages. It uses a globally set percentage of processes to
556// run such extensions and if the limit is exceeded, it returns true, to
557// indicate to the content module to group extensions together.
558bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
559 content::BrowserContext* browser_context, const GURL& url) {
560 // It has to be a valid URL for us to check for an extension.
561 if (!url.is_valid())
562 return false;
563
564 Profile* profile = Profile::FromBrowserContext(browser_context);
565 ExtensionService* service = profile->GetExtensionService();
566 if (!service)
567 return false;
568
569 // We have to have a valid extension with background page to proceed.
570 const Extension* extension =
571 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
572 if (!extension)
573 return false;
574 if (!extension->has_background_page())
575 return false;
576
577 std::set<int> process_ids;
578 size_t max_process_count =
579 content::RenderProcessHost::GetMaxRendererProcessCount();
580
581 // Go through all profiles to ensure we have total count of extension
582 // processes containing background pages, otherwise one profile can
583 // starve the other.
584 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
585 GetLoadedProfiles();
586 for (size_t i = 0; i < profiles.size(); ++i) {
587 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32588 for (ExtensionProcessManager::const_iterator iter =
589 epm->background_hosts().begin();
590 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06591 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32592 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06593 }
594 }
595
596 if (process_ids.size() >
597 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
598 return true;
599 }
600
601 return false;
602}
603
[email protected]6f371442011-11-09 06:45:46604void ChromeContentBrowserClient::SiteInstanceGotProcess(
605 SiteInstance* site_instance) {
606 CHECK(site_instance->HasProcess());
607
608 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02609 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46610 ExtensionService* service = profile->GetExtensionService();
611 if (!service)
612 return;
613
614 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44615 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33616 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46617 if (!extension)
618 return;
619
[email protected]6bc04fd82011-12-04 02:29:35620 service->process_map()->Insert(extension->id(),
621 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33622 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46623 BrowserThread::PostTask(
624 BrowserThread::IO, FROM_HERE,
625 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24626 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46627 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35628 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33629 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46630}
631
632void ChromeContentBrowserClient::SiteInstanceDeleting(
633 SiteInstance* site_instance) {
634 if (!site_instance->HasProcess())
635 return;
636
637 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02638 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46639 ExtensionService* service = profile->GetExtensionService();
640 if (!service)
641 return;
642
643 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44644 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33645 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46646 if (!extension)
647 return;
648
[email protected]6bc04fd82011-12-04 02:29:35649 service->process_map()->Remove(extension->id(),
650 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33651 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46652 BrowserThread::PostTask(
653 BrowserThread::IO, FROM_HERE,
654 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24655 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46656 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35657 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33658 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46659}
660
[email protected]e3daf3c2011-10-05 21:17:08661bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
662 const GURL& current_url,
663 const GURL& new_url) {
664 if (current_url.is_empty()) {
665 // Always choose a new process when navigating to extension URLs. The
666 // process grouping logic will combine all of a given extension's pages
667 // into the same process.
668 if (new_url.SchemeIs(chrome::kExtensionScheme))
669 return true;
670
671 return false;
672 }
673
674 // Also, we must switch if one is an extension and the other is not the exact
675 // same extension.
676 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
677 new_url.SchemeIs(chrome::kExtensionScheme)) {
678 if (current_url.GetOrigin() != new_url.GetOrigin())
679 return true;
680 }
681
682 return false;
683}
684
[email protected]763ec4ca2011-04-29 15:48:12685std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
686 const std::string& alias_name) {
687 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
688}
689
[email protected]b80f68432011-05-02 17:22:30690void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
691 CommandLine* command_line, int child_process_id) {
692#if defined(USE_LINUX_BREAKPAD)
693 if (IsCrashReporterEnabled()) {
694 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
695 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
696 }
697#elif defined(OS_MACOSX)
698 if (IsCrashReporterEnabled()) {
699 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
700 child_process_logging::GetClientId());
701 }
702#endif // OS_MACOSX
703
[email protected]f1933792011-06-14 00:49:34704 if (logging::DialogsAreSuppressed())
705 command_line->AppendSwitch(switches::kNoErrorDialogs);
706
[email protected]b80f68432011-05-02 17:22:30707 std::string process_type =
708 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17709 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52710 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30711 FilePath user_data_dir =
712 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
713 if (!user_data_dir.empty())
714 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
715#if defined(OS_CHROMEOS)
716 const std::string& login_profile =
717 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
718 if (!login_profile.empty())
719 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
720#endif
721
[email protected]f3b1a082011-11-18 00:34:30722 content::RenderProcessHost* process =
723 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37724 if (process) {
725 Profile* profile = Profile::FromBrowserContext(
726 process->GetBrowserContext());
727 extensions::ProcessMap* process_map =
728 profile->GetExtensionService()->process_map();
729 if (process_map && process_map->Contains(process->GetID()))
730 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30731
[email protected]a8d851f82011-12-21 00:32:37732 PrefService* prefs = profile->GetPrefs();
733 // Currently this pref is only registered if applied via a policy.
734 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
735 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
736 // Turn this policy into a command line switch.
737 command_line->AppendSwitch(switches::kDisable3DAPIs);
738 }
[email protected]718eab62011-10-05 21:16:52739
[email protected]a8d851f82011-12-21 00:32:37740 // Disable client-side phishing detection in the renderer if it is
741 // disabled in the Profile preferences or the browser process.
742 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
743 !g_browser_process->safe_browsing_detection_service()) {
744 command_line->AppendSwitch(
745 switches::kDisableClientSidePhishingDetection);
746 }
[email protected]8c40da62011-07-13 22:58:46747 }
[email protected]47c7ec82012-01-18 03:29:21748 {
749 PrefService* local_state = g_browser_process->local_state();
750 if (local_state &&
751 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
752 command_line->AppendSwitch(switches::kRendererPrintPreview);
753 }
754 }
[email protected]4287a3d2011-06-13 23:56:51755
[email protected]47c7ec82012-01-18 03:29:21756 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51757 static const char* const kSwitchNames[] = {
758 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48759 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51760 switches::kAllowScriptingGallery,
761 switches::kAppsCheckoutURL,
762 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31763 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51764 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50765 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53766 switches::kDisableExtensionsResourceWhitelist,
[email protected]4287a3d2011-06-13 23:56:51767 switches::kDumpHistogramsOnExit,
[email protected]8e466dd2012-05-04 19:16:05768 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21769 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13770 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51771 switches::kEnableCrxlessWebApps,
772 switches::kEnableExperimentalExtensionApis,
773 switches::kEnableInBrowserThumbnailing,
774 switches::kEnableIPCFuzzing,
775 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05776 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48777 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53778 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51779 switches::kEnableWatchdog,
780 switches::kExperimentalSpellcheckerFeatures,
781 switches::kMemoryProfiling,
782 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37783 switches::kNoJsRandomness,
[email protected]2a6bb0b12011-10-05 19:18:04784 switches::kNoRunningInsecureContent,
[email protected]f45c5f32012-04-18 19:26:37785 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51786 switches::kPpapiFlashArgs,
787 switches::kPpapiFlashInProcess,
788 switches::kPpapiFlashPath,
789 switches::kPpapiFlashVersion,
790 switches::kProfilingAtStart,
791 switches::kProfilingFile,
792 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37793 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51794 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38795 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51796 };
797
798 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
799 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17800 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38801 static const char* const kSwitchNames[] = {
802 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37803 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38804 switches::kWhitelistedExtensionID,
805 };
806
807 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
808 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51809 } else if (process_type == switches::kPluginProcess) {
810 static const char* const kSwitchNames[] = {
811 #if defined(OS_CHROMEOS)
812 switches::kLoginProfile,
813 #endif
814 switches::kMemoryProfiling,
815 switches::kSilentDumpOnDCHECK,
816 switches::kUserDataDir,
817 };
818
819 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
820 arraysize(kSwitchNames));
821 } else if (process_type == switches::kZygoteProcess) {
822 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51823 switches::kUserDataDir, // Make logs go to the right file.
824 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50825 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13826 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51827 switches::kPpapiFlashInProcess,
828 switches::kPpapiFlashPath,
829 switches::kPpapiFlashVersion,
830 };
831
832 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
833 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11834 } else if (process_type == switches::kGpuProcess) {
835 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
836 // because GPU is expected to be unreliable.
837 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
838 !command_line->HasSwitch(switches::kDisableBreakpad))
839 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30840 }
[email protected]6f08af82011-09-15 01:19:03841
842 // The command line switch kEnableBenchmarking needs to be specified along
843 // with the kEnableStatsTable switch to ensure that the stats table global
844 // is initialized correctly.
845 if (command_line->HasSwitch(switches::kEnableBenchmarking))
846 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30847}
848
849std::string ChromeContentBrowserClient::GetApplicationLocale() {
850 return g_browser_process->GetApplicationLocale();
851}
852
[email protected]597a867b2011-11-18 18:31:20853std::string ChromeContentBrowserClient::GetAcceptLangs(
854 content::BrowserContext* context) {
855 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37856 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08857}
858
[email protected]ac55e292011-06-24 05:16:08859SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22860 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08861 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
862}
863
[email protected]a2176792011-05-08 19:30:49864bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09865 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19866 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20867 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20869 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05870 return io_data->GetCookieSettings()->
871 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49872}
873
[email protected]ed24fad2011-05-10 22:44:01874bool ChromeContentBrowserClient::AllowGetCookie(
875 const GURL& url,
876 const GURL& first_party,
877 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20878 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01879 int render_process_id,
880 int render_view_id) {
881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20882 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05883 bool allow = io_data->GetCookieSettings()->
884 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01885
[email protected]8093a542011-05-13 07:29:32886 BrowserThread::PostTask(
887 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03888 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43889 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01890 return allow;
891}
892
893bool ChromeContentBrowserClient::AllowSetCookie(
894 const GURL& url,
895 const GURL& first_party,
896 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20897 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01898 int render_process_id,
899 int render_view_id,
900 net::CookieOptions* options) {
901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20902 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05903 CookieSettings* cookie_settings = io_data->GetCookieSettings();
904 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
905
906 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09907 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01908
[email protected]8093a542011-05-13 07:29:32909 BrowserThread::PostTask(
910 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03911 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43912 render_view_id, url, first_party, cookie_line, *options,
913 !allow));
[email protected]ed24fad2011-05-10 22:44:01914 return allow;
915}
916
[email protected]d5a19162011-06-30 18:51:54917bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20918 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20920 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26921
[email protected]f24bd172012-03-31 01:54:59922 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54923}
924
[email protected]5c5a88e2011-11-12 00:45:35925bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35926 const GURL& url,
927 const string16& name,
928 const string16& display_name,
929 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20930 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48931 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20933 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35934 CookieSettings* cookie_settings = io_data->GetCookieSettings();
935 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
936
[email protected]62151052012-02-01 18:40:48937 // Record access to database for potential display in UI.
938 std::vector<std::pair<int, int> >::const_iterator i;
939 for (i = render_views.begin(); i != render_views.end(); ++i) {
940 BrowserThread::PostTask(
941 BrowserThread::UI, FROM_HERE,
942 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
943 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35944 }
945
946 return allow;
947}
948
949bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35950 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20951 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48952 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35953 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20954 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35955 CookieSettings* cookie_settings = io_data->GetCookieSettings();
956 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
957
[email protected]62151052012-02-01 18:40:48958 // Record access to file system for potential display in UI.
959 std::vector<std::pair<int, int> >::const_iterator i;
960 for (i = render_views.begin(); i != render_views.end(); ++i) {
961 BrowserThread::PostTask(
962 BrowserThread::UI, FROM_HERE,
963 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
964 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35965 }
966
967 return allow;
968}
969
[email protected]7c5ff9a2012-03-02 07:42:49970bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
971 const GURL& url,
972 const string16& name,
973 content::ResourceContext* context,
974 const std::vector<std::pair<int, int> >& render_views) {
975 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
976 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
977 CookieSettings* cookie_settings = io_data->GetCookieSettings();
978 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
979
980 // Record access to IndexedDB for potential display in UI.
981 std::vector<std::pair<int, int> >::const_iterator i;
982 for (i = render_views.begin(); i != render_views.end(); ++i) {
983 BrowserThread::PostTask(
984 BrowserThread::UI, FROM_HERE,
985 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
986 i->first, i->second, url, name, !allow));
987 }
988
989 return allow;
990}
991
[email protected]6133f922011-07-01 21:34:34992net::URLRequestContext*
993ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20994 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34995 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
996 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20997 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34998 return io_data->extensions_request_context();
999 }
1000
1001 return NULL;
1002}
1003
[email protected]317f96c92011-05-31 06:53:411004QuotaPermissionContext*
1005ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1006 return new ChromeQuotaPermissionContext();
1007}
1008
[email protected]a0ce3282011-08-19 20:49:521009void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421010 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421011}
1012
[email protected]a0ce3282011-08-19 20:49:521013void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521014 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521015}
1016
[email protected]848dd042011-06-04 18:24:031017void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171018 int render_process_id,
1019 int render_view_id,
1020 int cert_error,
1021 const net::SSLInfo& ssl_info,
1022 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031023 bool overridable,
[email protected]d9be47702012-05-16 03:41:221024 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171025 const base::Callback<void(bool)>& callback,
1026 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411027 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131028 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171029 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411030 if (!tab) {
1031 NOTREACHED();
1032 return;
1033 }
1034 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501035 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301036 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091037 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411038 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171039 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411040 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171041 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411042 return;
1043 }
1044 }
1045
1046 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221047 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1048 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031049}
1050
[email protected]c99c442e2011-08-24 11:37:301051void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451052 int render_process_id,
1053 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401054 const net::HttpNetworkSession* network_session,
1055 net::SSLCertRequestInfo* cert_request_info,
1056 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131057 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451058 render_process_id, render_view_id);
1059 if (!tab) {
1060 NOTREACHED();
1061 return;
1062 }
1063
[email protected]6786bf402011-12-03 15:19:451064 GURL requesting_url("https://" + cert_request_info->host_and_port);
1065 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1066 << cert_request_info->host_and_port;
1067
[email protected]627e0512011-12-21 22:55:301068 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451069 scoped_ptr<Value> filter(
1070 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1071 requesting_url,
1072 requesting_url,
1073 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1074 std::string(), NULL));
1075
1076 if (filter.get()) {
1077 // Try to automatically select a client certificate.
1078 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1079 DictionaryValue* filter_dict =
1080 static_cast<DictionaryValue*>(filter.get());
1081
1082 const std::vector<scoped_refptr<net::X509Certificate> >&
1083 all_client_certs = cert_request_info->client_certs;
1084 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1085 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1086 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401087 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451088 return;
1089 }
1090 }
1091 } else {
1092 NOTREACHED();
1093 }
1094 }
1095
[email protected]8ec26472011-06-06 16:52:451096 TabContentsWrapper* wrapper =
1097 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451098 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131099 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451100 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141101 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401102 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451103 return;
1104 }
[email protected]7a593db2012-02-13 21:19:401105 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1106 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451107}
1108
1109void ChromeContentBrowserClient::AddNewCertificate(
1110 net::URLRequest* request,
1111 net::X509Certificate* cert,
1112 int render_process_id,
1113 int render_view_id) {
1114 // The handler will run the UI and delete itself when it's finished.
1115 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1116}
1117
[email protected]a93670ab2012-02-24 03:46:391118void ChromeContentBrowserClient::RequestMediaAccessPermission(
1119 const content::MediaStreamRequest* request,
1120 const content::MediaResponseCallback& callback) {
1121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1122
[email protected]117b6b42012-02-29 09:11:081123 WebContents* contents = tab_util::GetWebContentsByID(
1124 request->render_process_id, request->render_view_id);
1125 if (!contents) {
1126 // Abort, if the tab was closed after the request was made but before we
1127 // got to this point.
1128 callback.Run(content::MediaStreamDevices());
1129 return;
1130 }
1131
1132 TabContentsWrapper* tab =
1133 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1134 DCHECK(tab);
1135
1136 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1137 InfoBarDelegate* old_infobar = NULL;
1138 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1139 old_infobar =
[email protected]51d1fc62012-04-28 03:47:531140 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfoBarDelegate();
[email protected]117b6b42012-02-29 09:11:081141 }
1142
[email protected]117b6b42012-02-29 09:11:081143 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1144 request,
1145 callback);
1146 if (old_infobar)
1147 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1148 else
1149 infobar_helper->AddInfoBar(infobar);
[email protected]a93670ab2012-02-24 03:46:391150}
1151
[email protected]dc73a7b2012-03-25 15:27:181152content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1153 return MediaInternals::GetInstance();
1154}
1155
[email protected]941623e2011-06-07 23:06:041156void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1157 const GURL& source_origin,
1158 int callback_context,
1159 int render_process_id,
1160 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111161#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041162 RenderViewHost* rvh = RenderViewHost::FromID(
1163 render_process_id, render_view_id);
1164 if (!rvh) {
1165 NOTREACHED();
1166 return;
1167 }
1168
[email protected]9f76c1e2012-03-05 15:15:581169 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301170 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041171 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371172 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041173 service->RequestPermission(
1174 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131175 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111176#else
1177 NOTIMPLEMENTED();
1178#endif
[email protected]941623e2011-06-07 23:06:041179}
1180
1181WebKit::WebNotificationPresenter::Permission
1182 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021183 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201184 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021185 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111186#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201188 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021189 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1190 source_origin, render_process_id,
1191 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041192 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041193
1194 // Fall back to the regular notification preferences, which works on an
1195 // origin basis.
1196 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371197 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041198 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111199#else
1200 return WebKit::WebNotificationPresenter::PermissionAllowed;
1201#endif
[email protected]941623e2011-06-07 23:06:041202}
1203
1204void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171205 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041206 int render_process_id,
1207 int render_view_id,
1208 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111209#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041210 RenderViewHost* rvh = RenderViewHost::FromID(
1211 render_process_id, render_view_id);
1212 if (!rvh) {
1213 NOTREACHED();
1214 return;
1215 }
1216
[email protected]9f76c1e2012-03-05 15:15:581217 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301218 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041219 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371220 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041221 service->ShowDesktopNotification(
1222 params, render_process_id, render_view_id,
1223 worker ? DesktopNotificationService::WorkerNotification :
1224 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111225#else
1226 NOTIMPLEMENTED();
1227#endif
[email protected]941623e2011-06-07 23:06:041228}
1229
1230void ChromeContentBrowserClient::CancelDesktopNotification(
1231 int render_process_id,
1232 int render_view_id,
1233 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111234#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041235 RenderViewHost* rvh = RenderViewHost::FromID(
1236 render_process_id, render_view_id);
1237 if (!rvh) {
1238 NOTREACHED();
1239 return;
1240 }
1241
[email protected]9f76c1e2012-03-05 15:15:581242 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301243 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041244 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371245 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041246 service->CancelDesktopNotification(
1247 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111248#else
1249 NOTIMPLEMENTED();
1250#endif
[email protected]941623e2011-06-07 23:06:041251}
1252
[email protected]9f3fba52011-06-08 20:37:191253bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351254 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021255 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191256 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201257 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011258 int render_process_id,
1259 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011261
1262 *no_javascript_access = false;
1263
[email protected]9f3fba52011-06-08 20:37:191264 // If the opener is trying to create a background window but doesn't have
1265 // the appropriate permission, fail the attempt.
1266 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201267 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531268 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1269
[email protected]03b6d552012-03-29 04:03:011270 if (!map->SecurityOriginHasAPIPermission(
1271 source_origin,
1272 render_process_id,
1273 ExtensionAPIPermission::kBackground)) {
1274 return false;
1275 }
1276
[email protected]7b54ca02012-03-02 18:06:531277 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1278 // return a recently installed Extension even if this CanCreateWindow call
1279 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011280 // because the permission check above would have caused an early return
1281 // already. We must use the full URL to find hosted apps, though, and not
1282 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531283 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351284 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531285 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011286 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191287 }
1288 return true;
1289}
1290
1291std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201292 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1294 // Check if it's an extension-created worker, in which case we want to use
1295 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201296 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191297 const Extension* extension =
1298 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1299 return extension ? extension->name() : std::string();
1300}
1301
[email protected]99907362012-01-11 05:41:401302void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1303 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171304}
1305
[email protected]c52b2892012-03-07 11:01:021306content::SpeechRecognitionManagerDelegate*
1307 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321308#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021309 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321310#else
1311 return NULL;
1312#endif
[email protected]66cfec62012-02-24 17:57:511313}
1314
[email protected]3cb054e62011-06-13 05:21:171315ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1316 return g_browser_process->clipboard();
1317}
1318
[email protected]ae6e9912011-07-27 01:18:281319net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1320 return g_browser_process->net_log();
1321}
1322
[email protected]32538d92011-08-25 00:09:231323AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1324 return new ChromeAccessTokenStore();
1325}
1326
[email protected]dbae6b02011-06-29 23:51:411327bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1328 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1329 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1330}
1331
[email protected]64d69de42012-02-06 00:19:541332void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321333 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061334 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581335 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061336 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061337
[email protected]f3986f82012-01-03 20:00:061338 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541339 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061340 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541341 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061342 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541343 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061344 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541345 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061346 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541347 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061348 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541349 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061350
[email protected]64d69de42012-02-06 00:19:541351 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061352 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541353 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061354 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541355 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061356 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541357 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061358 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1359
[email protected]64d69de42012-02-06 00:19:541360 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061361
[email protected]64d69de42012-02-06 00:19:541362 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061363 prefs->GetBoolean(
1364 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541365 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061366 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541367 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061368 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1369 const DictionaryValue* inspector_settings =
1370 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1371 if (inspector_settings) {
1372 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1373 iter != inspector_settings->end_keys(); ++iter) {
1374 std::string value;
1375 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541376 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061377 std::make_pair(*iter, value));
1378 }
1379 }
[email protected]64d69de42012-02-06 00:19:541380 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061381
[email protected]64d69de42012-02-06 00:19:541382 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1383 web_prefs->javascript_enabled = false;
1384 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1385 web_prefs->web_security_enabled = false;
1386 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1387 web_prefs->plugins_enabled = false;
1388 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1389 web_prefs->java_enabled = false;
1390 web_prefs->loads_images_automatically =
1391 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061392
[email protected]64d69de42012-02-06 00:19:541393 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1394 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061395
[email protected]64d69de42012-02-06 00:19:541396 web_prefs->memory_info_enabled =
1397 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1398 web_prefs->allow_displaying_insecure_content =
1399 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1400 web_prefs->allow_running_insecure_content =
1401 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081402 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061403
[email protected]64d69de42012-02-06 00:19:541404 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151405 UserStyleSheetWatcher* user_style_sheet_watcher =
1406 UserStyleSheetWatcherFactory::GetForProfile(profile);
1407 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541408 web_prefs->user_style_sheet_enabled = true;
1409 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151410 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541411 } else {
1412 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061413 }
1414
[email protected]b7e44ff2012-02-16 03:37:341415 web_prefs->asynchronous_spell_checking_enabled =
[email protected]8e466dd2012-05-04 19:16:051416 CommandLine::ForCurrentProcess()->
1417 HasSwitch(switches::kEnableAsynchronousSpellChecking);
[email protected]b7e44ff2012-02-16 03:37:341418 web_prefs->unified_textchecker_enabled =
1419 web_prefs->asynchronous_spell_checking_enabled ||
1420 CommandLine::ForCurrentProcess()->
1421 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571422
[email protected]64d69de42012-02-06 00:19:541423 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061424 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541425 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061426 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541427 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061428 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1429
1430 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541431 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061432 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541433 web_prefs->default_encoding);
1434 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061435 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541436 web_prefs->default_encoding =
1437 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061438 }
[email protected]64d69de42012-02-06 00:19:541439 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061440
1441 ExtensionService* service = profile->GetExtensionService();
1442 if (service) {
1443 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581444 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061445 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581446 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061447 }
1448
[email protected]9f76c1e2012-03-05 15:15:581449 if (rvh->GetDelegate()->GetRenderViewType() ==
1450 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541451 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581452 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061453 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1454 // Disable all kinds of acceleration for background pages.
1455 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541456 web_prefs->force_compositing_mode = false;
1457 web_prefs->accelerated_compositing_enabled = false;
1458 web_prefs->accelerated_2d_canvas_enabled = false;
1459 web_prefs->accelerated_video_enabled = false;
1460 web_prefs->accelerated_painting_enabled = false;
1461 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061462 }
[email protected]2e21fe292012-03-02 22:52:321463
1464#if defined(FILE_MANAGER_EXTENSION)
1465 // Override the default of suppressing HW compositing for WebUI pages for the
1466 // file manager, which is implemented using WebUI but wants HW acceleration
1467 // for video decode & render.
1468 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1469 web_prefs->accelerated_compositing_enabled = true;
1470 web_prefs->accelerated_2d_canvas_enabled = true;
1471 }
1472#endif
[email protected]181a95ee2011-07-12 19:26:361473}
1474
1475void ChromeContentBrowserClient::UpdateInspectorSetting(
1476 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061477 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581478 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061479 DictionaryPrefUpdate update(
1480 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1481 prefs::kWebKitInspectorSettings);
1482 DictionaryValue* inspector_settings = update.Get();
1483 inspector_settings->SetWithoutPathExpansion(key,
1484 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361485}
1486
1487void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061488 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581489 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061490 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1491 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361492}
1493
[email protected]b8148ac2011-07-13 22:03:251494void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1495 BrowserURLHandler* handler) {
1496 // Add the default URL handlers.
1497 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1498 BrowserURLHandler::null_handler());
1499 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1500 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1501
[email protected]b3adbd02011-11-30 22:23:271502 // about: handler. Must come before chrome: handler, since it will
1503 // rewrite about: urls to chrome: URLs and then expect chrome: to
1504 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251505 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1506 BrowserURLHandler::null_handler());
1507 // chrome: & friends.
1508 handler->AddHandlerPair(&HandleWebUI,
1509 BrowserURLHandler::null_handler());
1510}
1511
1512void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371513 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581514 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251515 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1516 BrowsingDataRemover::EVERYTHING,
1517 base::Time());
1518 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1519 // BrowsingDataRemover takes care of deleting itself when done.
1520}
1521
1522void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371523 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581524 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251525 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1526 BrowsingDataRemover::EVERYTHING,
1527 base::Time());
[email protected]dceaa912011-09-06 17:17:231528 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251529 remover->Remove(remove_mask);
1530 // BrowsingDataRemover takes care of deleting itself when done.
1531}
1532
[email protected]e1d16eb92011-08-18 23:19:321533FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1534 return download_util::GetDefaultDownloadDirectory();
1535}
1536
[email protected]c9b6eb62011-10-18 20:49:391537std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1538 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1539}
1540
[email protected]a658d452012-03-02 12:45:291541bool ChromeContentBrowserClient::AllowSocketAPI(
1542 content::BrowserContext* browser_context, const GURL& url) {
1543 if (!url.is_valid())
1544 return false;
1545
1546 std::string host = url.host();
1547 if (allowed_socket_origins_.count(host))
1548 return true;
1549
[email protected]9a5940d2012-04-27 19:16:231550 Profile* profile = Profile::FromBrowserContext(browser_context);
1551 const Extension* extension = NULL;
1552 if (profile && profile->GetExtensionService()) {
1553 extension = profile->GetExtensionService()->extensions()->
1554 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1555 }
1556
[email protected]f237c0f2012-03-10 07:49:101557 // Need to check this now and not on construction because otherwise it won't
1558 // work with browser_tests.
1559 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1560 std::string allowed_list =
1561 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231562 if (allowed_list == "*") {
1563 // The wildcard allows socket API only for packaged and platform apps.
1564 return extension &&
1565 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1566 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1567 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101568 StringTokenizer t(allowed_list, ",");
1569 while (t.GetNext()) {
1570 if (t.token() == host)
1571 return true;
1572 }
1573 }
1574
[email protected]a658d452012-03-02 12:45:291575 if (!extension)
1576 return false;
1577
1578 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1579 return true;
1580
1581 return false;
[email protected]e461da2f2012-02-16 19:06:401582}
1583
[email protected]e60c0232011-11-11 19:56:351584#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301585int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521586 const CommandLine& command_line) {
1587 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071588 ExtensionCrashHandlerHostLinux* crash_handler =
1589 ExtensionCrashHandlerHostLinux::GetInstance();
1590 return crash_handler->GetDeathSignalSocket();
1591 }
1592
[email protected]718eab62011-10-05 21:16:521593 std::string process_type =
1594 command_line.GetSwitchValueASCII(switches::kProcessType);
1595
1596 if (process_type == switches::kRendererProcess)
1597 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1598
[email protected]b80f68432011-05-02 17:22:301599 if (process_type == switches::kPluginProcess)
1600 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1601
1602 if (process_type == switches::kPpapiPluginProcess)
1603 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1604
1605 if (process_type == switches::kGpuProcess)
1606 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1607
1608 return -1;
1609}
[email protected]e60c0232011-11-11 19:56:351610#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301611
[email protected]4a65826d2011-08-25 16:04:011612#if defined(OS_WIN)
1613const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1614 return chrome::kBrowserResourcesDll;
1615}
1616#endif
1617
[email protected]37a72af2011-06-13 05:42:011618#if defined(USE_NSS)
1619crypto::CryptoModuleBlockingPasswordDelegate*
1620 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1621 const GURL& url) {
1622 return browser::NewCryptoModuleBlockingDialogDelegate(
1623 browser::kCryptoModulePasswordKeygen, url.host());
1624}
1625#endif
1626
[email protected]d977f9c2011-03-14 16:10:261627} // namespace chrome