blob: 1c5efe57c96e212c730268db465e4a0463e6198f [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]6717bf272012-05-11 23:31:25156using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39157
[email protected]c5dbef02011-05-13 05:06:09158namespace {
159
[email protected]e461da2f2012-02-16 19:06:40160const char* kPredefinedAllowedSocketOrigins[] = {
161 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18162 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45163 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
164 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
165 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
166 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
167 "ojoimpklfciegopdfgeenehpalipignm" // Chromoting canary
[email protected]e461da2f2012-02-16 19:06:40168};
169
[email protected]b8148ac2011-07-13 22:03:25170// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42171bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50172 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
173 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25174 return false;
175
[email protected]fe69558d2012-03-12 11:34:49176#if defined(OS_CHROMEOS)
177 // Special case : in ChromeOS in Guest mode bookmarks and history are
178 // disabled for security reasons. New tab page explains the reasons, so
179 // we redirect user to new tab page.
180 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
181 if (url->SchemeIs(chrome::kChromeUIScheme) &&
182 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
183 url->DomainIs(chrome::kChromeUIHistoryHost))) {
184 // Rewrite with new tab URL
185 *url = GURL(chrome::kChromeUINewTabURL);
186 }
187 }
188#endif
189
[email protected]b8148ac2011-07-13 22:03:25190 // Special case the new tab page. In older versions of Chrome, the new tab
191 // page was hosted at chrome-internal:<blah>. This might be in people's saved
192 // sessions or bookmarks, so we say any URL with that scheme triggers the new
193 // tab page.
194 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
195 // Rewrite it with the proper new tab URL.
196 *url = GURL(chrome::kChromeUINewTabURL);
197 }
198
199 return true;
200}
201
[email protected]8d3132f62011-10-12 07:13:42202// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
203// below. Extension, and isolated apps require different privileges to be
204// granted to their RenderProcessHosts. This classification allows us to make
205// sure URLs are served by hosts with the right set of privileges.
206enum RenderProcessHostPrivilege {
207 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45208 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42209 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45210 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42211};
212
213RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
214 const GURL& url,
215 ExtensionService* service) {
216 // Default to a normal renderer cause it is lower privileged. This should only
217 // occur if the URL on a site instance is either malformed, or uninitialized.
218 // If it is malformed, then there is no need for better privileges anyways.
219 // If it is uninitialized, but eventually settles on being an a scheme other
220 // than normal webrenderer, the navigation logic will correct us out of band
221 // anyways.
222 if (!url.is_valid())
223 return PRIV_NORMAL;
224
225 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44226 const Extension* extension =
227 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45228 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42229 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45230 if (extension && extension->is_hosted_app())
231 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42232
233 return PRIV_EXTENSION;
234 }
235
236 return PRIV_NORMAL;
237}
238
239RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30240 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46241 extensions::ProcessMap* process_map,
242 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46243 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30244 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46245 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21246 return PRIV_NORMAL;
247
[email protected]6f371442011-11-09 06:45:46248 for (std::set<std::string>::iterator iter = extension_ids.begin();
249 iter != extension_ids.end(); ++iter) {
250 const Extension* extension = service->GetExtensionById(*iter, false);
251 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42252 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45253 if (extension && extension->is_hosted_app())
254 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42255 }
256
[email protected]676f6ab2011-10-19 20:23:21257 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42258}
259
[email protected]eec0b33c2011-12-05 22:09:45260bool IsIsolatedAppInProcess(const GURL& site_url,
261 content::RenderProcessHost* process_host,
262 extensions::ProcessMap* process_map,
263 ExtensionService* service) {
264 std::set<std::string> extension_ids =
265 process_map->GetExtensionsInProcess(process_host->GetID());
266 if (extension_ids.empty())
267 return false;
268
269 for (std::set<std::string>::iterator iter = extension_ids.begin();
270 iter != extension_ids.end(); ++iter) {
271 const Extension* extension = service->GetExtensionById(*iter, false);
272 if (extension &&
273 extension->is_storage_isolated() &&
274 extension->url() == site_url)
275 return true;
276 }
277
278 return false;
279}
280
[email protected]6786bf402011-12-03 15:19:45281bool CertMatchesFilter(const net::X509Certificate& cert,
282 const base::DictionaryValue& filter) {
283 // TODO(markusheintz): This is the minimal required filter implementation.
284 // Implement a better matcher.
285
286 // An empty filter matches any client certificate since no requirements are
287 // specified at all.
288 if (filter.empty())
289 return true;
290
291 std::string common_name;
292 if (filter.GetString("ISSUER.CN", &common_name) &&
293 (cert.issuer().common_name == common_name)) {
294 return true;
295 }
296 return false;
297}
298
[email protected]f3986f82012-01-03 20:00:06299// Fills |map| with the per-script font prefs under path |map_name|.
300void FillFontFamilyMap(const PrefService* prefs,
301 const char* map_name,
302 WebPreferences::ScriptFontFamilyMap* map) {
303 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
304 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
305 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
306 std::string font_family = prefs->GetString(pref_name.c_str());
307 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32308 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06309 }
310}
311
[email protected]9dbfff12011-07-01 19:37:07312} // namespace
[email protected]c5dbef02011-05-13 05:06:09313
[email protected]d977f9c2011-03-14 16:10:26314namespace chrome {
315
[email protected]e461da2f2012-02-16 19:06:40316ChromeContentBrowserClient::ChromeContentBrowserClient() {
317 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
318 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40319}
320
321ChromeContentBrowserClient::~ChromeContentBrowserClient() {
322}
323
[email protected]50462bf02011-11-21 19:13:31324content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
325 const content::MainFunctionParams& parameters) {
326 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30327 // Construct the Main browser parts based on the OS type.
328#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31329 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04330#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31331 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30332#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31333 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26334#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31335 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14336#elif defined(OS_ANDROID)
337 // Do nothing for Android.
338 // TODO(klobag): Android initialization should use the
339 // *BrowserMainParts class-hierarchy for setting up custom initialization.
340 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30341#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31342 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04343#else
[email protected]b48c9182011-10-26 18:03:30344 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31345 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30346#endif
347
[email protected]c7480942011-11-08 19:18:27348 // Construct additional browser parts. Stages are called in the order in
349 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22350#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31351 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04352#endif
[email protected]c7480942011-11-08 19:18:27353
354#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31355 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27356#endif
357
[email protected]dc04be7c2012-03-15 23:57:49358#if defined(USE_ASH)
359 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
360#endif
361
[email protected]e050ef142012-03-21 01:04:24362#if defined(USE_AURA)
363 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
364#endif
365
[email protected]50462bf02011-11-21 19:13:31366 return main_parts;
[email protected]f967b722011-09-07 00:58:04367}
368
[email protected]38b098f2012-03-14 21:11:57369content::WebContentsView*
370 ChromeContentBrowserClient::OverrideCreateWebContentsView(
371 WebContents* web_contents) {
[email protected]38b098f2012-03-14 21:11:57372 return NULL;
373}
374
375content::WebContentsViewDelegate*
376 ChromeContentBrowserClient::GetWebContentsViewDelegate(
377 content::WebContents* web_contents) {
[email protected]c0d7f792012-04-18 19:16:00378#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13379 return new ChromeWebContentsViewDelegateViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57380#elif defined(TOOLKIT_GTK)
381 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32382#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57383 return
384 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
385 web_contents);
[email protected]74313b42011-08-24 16:51:32386#else
[email protected]38b098f2012-03-14 21:11:57387 return NULL;
[email protected]74313b42011-08-24 16:51:32388#endif
389}
390
[email protected]f364d1392011-04-08 21:03:10391void ChromeContentBrowserClient::RenderViewHostCreated(
392 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46393
[email protected]9f76c1e2012-03-05 15:15:58394 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46395 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02396 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46397
398 new ChromeRenderViewHostObserver(render_view_host,
399 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10400 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26401}
402
[email protected]f3b1a082011-11-18 00:34:30403void ChromeContentBrowserClient::RenderProcessHostCreated(
404 content::RenderProcessHost* host) {
405 int id = host->GetID();
406 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
407 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02408 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30409 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03410#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30411 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03412#endif
[email protected]f3b1a082011-11-18 00:34:30413 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02414 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30415 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56416#if defined(OS_MACOSX)
417 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
418#endif
[email protected]f3b1a082011-11-18 00:34:30419 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03420 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07421 host->GetChannel()->AddFilter(
422 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38423
[email protected]2ccf45c2011-08-19 23:35:50424 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
425 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07426
427 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56428
429 RendererContentSettingRules rules;
430 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
431 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14432}
433
[email protected]e0ada9c2012-03-20 03:54:43434void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
435 content::BrowserChildProcessHost* host) {
436 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
437}
438
[email protected]863f70a2012-01-27 02:05:50439content::WebUIControllerFactory*
440 ChromeContentBrowserClient::GetWebUIControllerFactory() {
441 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56442}
443
[email protected]3d7474ff2011-07-27 17:47:37444GURL ChromeContentBrowserClient::GetEffectiveURL(
445 content::BrowserContext* browser_context, const GURL& url) {
446 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08447 // Get the effective URL for the given actual URL. If the URL is part of an
448 // installed app, the effective URL is an extension URL with the ID of that
449 // extension as the host. This has the effect of grouping apps together in
450 // a common SiteInstance.
451 if (!profile || !profile->GetExtensionService())
452 return url;
453
[email protected]615d88f2011-12-13 01:47:44454 const Extension* extension = profile->GetExtensionService()->extensions()->
455 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08456 if (!extension)
457 return url;
458
[email protected]15877ca2011-11-18 22:40:52459 // Bookmark apps do not use the hosted app process model, and should be
460 // treated as normal URLs.
461 if (extension->from_bookmark())
462 return url;
463
[email protected]36fb2c7c2011-04-04 15:49:08464 // If the URL is part of an extension's web extent, convert it to an
465 // extension URL.
466 return extension->GetResourceURL(url.path());
467}
468
[email protected]056ad2a2011-07-12 02:13:55469bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37470 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55471 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52472 // Because we expect to use the effective URL, URLs for hosted apps (apart
473 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55474 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
475 return false;
476
[email protected]3d7474ff2011-07-27 17:47:37477 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55478 if (!profile || !profile->GetExtensionService())
479 return false;
480
[email protected]615d88f2011-12-13 01:47:44481 const Extension* extension = profile->GetExtensionService()->extensions()->
482 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55483 if (!extension)
484 return false;
485
486 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53487 // permission, or that does not allow JavaScript access to the background
488 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55489 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53490 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
491 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
492 !extension->allow_background_js_access()) {
493 return false;
494 }
495 }
[email protected]056ad2a2011-07-12 02:13:55496
[email protected]7b54ca02012-03-02 18:06:53497 // Hosted apps that have script access to their background page must use
498 // process per site, since all instances can make synchronous calls to the
499 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55500 return true;
501}
502
[email protected]46fb9442011-12-09 17:57:47503bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
504 return ProfileIOData::IsHandledURL(url);
505}
506
[email protected]2a5221b2011-09-27 23:07:31507bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30508 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31509 const GURL& site_url) {
510 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30511 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42512 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46513 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31514
[email protected]ffa97602011-11-17 17:55:52515 // Don't allow the Task Manager to share a process with anything else.
516 // Otherwise it can affect the renderers it is observing.
517 // Note: we could create another RenderProcessHostPrivilege bucket for
518 // this to allow multiple chrome://tasks instances to share, but that's
519 // a very unlikely case without serious consequences.
520 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
521 return false;
522
[email protected]8d3132f62011-10-12 07:13:42523 // These may be NULL during tests. In that case, just assume any site can
524 // share any host.
[email protected]6f371442011-11-09 06:45:46525 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31526 return true;
527
[email protected]a8c269a2011-10-25 20:17:22528 // Experimental:
529 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
530 // to share a renderer process. (We could allow pages from the same site or
531 // extensions of the same type to share, if we knew what the given process
532 // was dedicated to. Allowing no sharing is simpler for now.) This may
533 // cause resource exhaustion issues if too many sites are open at once.
534 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
535 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
536 return false;
537
[email protected]eec0b33c2011-12-05 22:09:45538 // An isolated app is only allowed to share with the exact same app in order
539 // to provide complete renderer process isolation. This also works around
540 // issue http://crbug.com/85588, where different isolated apps in the same
541 // process would end up using the first app's storage contexts.
542 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42543 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45544 if (privilege_required == PRIV_ISOLATED)
545 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
546
547 // Otherwise, just make sure the process privilege matches the privilege
548 // required by the site.
549 return GetProcessPrivilege(process_host, process_map, service) ==
550 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31551}
552
[email protected]76411f412012-02-22 18:56:06553// This function is trying to limit the amount of processes used by extensions
554// with background pages. It uses a globally set percentage of processes to
555// run such extensions and if the limit is exceeded, it returns true, to
556// indicate to the content module to group extensions together.
557bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
558 content::BrowserContext* browser_context, const GURL& url) {
559 // It has to be a valid URL for us to check for an extension.
560 if (!url.is_valid())
561 return false;
562
563 Profile* profile = Profile::FromBrowserContext(browser_context);
564 ExtensionService* service = profile->GetExtensionService();
565 if (!service)
566 return false;
567
568 // We have to have a valid extension with background page to proceed.
569 const Extension* extension =
570 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
571 if (!extension)
572 return false;
573 if (!extension->has_background_page())
574 return false;
575
576 std::set<int> process_ids;
577 size_t max_process_count =
578 content::RenderProcessHost::GetMaxRendererProcessCount();
579
580 // Go through all profiles to ensure we have total count of extension
581 // processes containing background pages, otherwise one profile can
582 // starve the other.
583 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
584 GetLoadedProfiles();
585 for (size_t i = 0; i < profiles.size(); ++i) {
586 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32587 for (ExtensionProcessManager::const_iterator iter =
588 epm->background_hosts().begin();
589 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06590 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32591 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06592 }
593 }
594
595 if (process_ids.size() >
596 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
597 return true;
598 }
599
600 return false;
601}
602
[email protected]6f371442011-11-09 06:45:46603void ChromeContentBrowserClient::SiteInstanceGotProcess(
604 SiteInstance* site_instance) {
605 CHECK(site_instance->HasProcess());
606
607 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02608 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46609 ExtensionService* service = profile->GetExtensionService();
610 if (!service)
611 return;
612
613 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44614 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33615 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46616 if (!extension)
617 return;
618
[email protected]6bc04fd82011-12-04 02:29:35619 service->process_map()->Insert(extension->id(),
620 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33621 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46622 BrowserThread::PostTask(
623 BrowserThread::IO, FROM_HERE,
624 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24625 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46626 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35627 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33628 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46629}
630
631void ChromeContentBrowserClient::SiteInstanceDeleting(
632 SiteInstance* site_instance) {
633 if (!site_instance->HasProcess())
634 return;
635
636 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02637 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46638 ExtensionService* service = profile->GetExtensionService();
639 if (!service)
640 return;
641
642 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44643 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33644 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46645 if (!extension)
646 return;
647
[email protected]6bc04fd82011-12-04 02:29:35648 service->process_map()->Remove(extension->id(),
649 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33650 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46651 BrowserThread::PostTask(
652 BrowserThread::IO, FROM_HERE,
653 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24654 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46655 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35656 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33657 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46658}
659
[email protected]e3daf3c2011-10-05 21:17:08660bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
661 const GURL& current_url,
662 const GURL& new_url) {
663 if (current_url.is_empty()) {
664 // Always choose a new process when navigating to extension URLs. The
665 // process grouping logic will combine all of a given extension's pages
666 // into the same process.
667 if (new_url.SchemeIs(chrome::kExtensionScheme))
668 return true;
669
670 return false;
671 }
672
673 // Also, we must switch if one is an extension and the other is not the exact
674 // same extension.
675 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
676 new_url.SchemeIs(chrome::kExtensionScheme)) {
677 if (current_url.GetOrigin() != new_url.GetOrigin())
678 return true;
679 }
680
681 return false;
682}
683
[email protected]763ec4ca2011-04-29 15:48:12684std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
685 const std::string& alias_name) {
686 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
687}
688
[email protected]b80f68432011-05-02 17:22:30689void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
690 CommandLine* command_line, int child_process_id) {
691#if defined(USE_LINUX_BREAKPAD)
692 if (IsCrashReporterEnabled()) {
693 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
694 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
695 }
696#elif defined(OS_MACOSX)
697 if (IsCrashReporterEnabled()) {
698 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
699 child_process_logging::GetClientId());
700 }
701#endif // OS_MACOSX
702
[email protected]f1933792011-06-14 00:49:34703 if (logging::DialogsAreSuppressed())
704 command_line->AppendSwitch(switches::kNoErrorDialogs);
705
[email protected]b80f68432011-05-02 17:22:30706 std::string process_type =
707 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17708 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52709 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30710 FilePath user_data_dir =
711 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
712 if (!user_data_dir.empty())
713 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
714#if defined(OS_CHROMEOS)
715 const std::string& login_profile =
716 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
717 if (!login_profile.empty())
718 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
719#endif
720
[email protected]f3b1a082011-11-18 00:34:30721 content::RenderProcessHost* process =
722 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37723 if (process) {
724 Profile* profile = Profile::FromBrowserContext(
725 process->GetBrowserContext());
726 extensions::ProcessMap* process_map =
727 profile->GetExtensionService()->process_map();
728 if (process_map && process_map->Contains(process->GetID()))
729 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30730
[email protected]a8d851f82011-12-21 00:32:37731 PrefService* prefs = profile->GetPrefs();
732 // Currently this pref is only registered if applied via a policy.
733 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
734 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
735 // Turn this policy into a command line switch.
736 command_line->AppendSwitch(switches::kDisable3DAPIs);
737 }
[email protected]718eab62011-10-05 21:16:52738
[email protected]a8d851f82011-12-21 00:32:37739 // Disable client-side phishing detection in the renderer if it is
740 // disabled in the Profile preferences or the browser process.
741 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
742 !g_browser_process->safe_browsing_detection_service()) {
743 command_line->AppendSwitch(
744 switches::kDisableClientSidePhishingDetection);
745 }
[email protected]8c40da62011-07-13 22:58:46746 }
[email protected]47c7ec82012-01-18 03:29:21747 {
748 PrefService* local_state = g_browser_process->local_state();
749 if (local_state &&
750 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
751 command_line->AppendSwitch(switches::kRendererPrintPreview);
752 }
753 }
[email protected]4287a3d2011-06-13 23:56:51754
[email protected]47c7ec82012-01-18 03:29:21755 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51756 static const char* const kSwitchNames[] = {
757 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48758 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51759 switches::kAllowScriptingGallery,
760 switches::kAppsCheckoutURL,
761 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31762 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51763 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50764 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53765 switches::kDisableExtensionsResourceWhitelist,
[email protected]4287a3d2011-06-13 23:56:51766 switches::kDumpHistogramsOnExit,
[email protected]8e466dd2012-05-04 19:16:05767 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21768 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13769 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51770 switches::kEnableCrxlessWebApps,
771 switches::kEnableExperimentalExtensionApis,
772 switches::kEnableInBrowserThumbnailing,
773 switches::kEnableIPCFuzzing,
774 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05775 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48776 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53777 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51778 switches::kEnableWatchdog,
779 switches::kExperimentalSpellcheckerFeatures,
780 switches::kMemoryProfiling,
781 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37782 switches::kNoJsRandomness,
[email protected]2a6bb0b12011-10-05 19:18:04783 switches::kNoRunningInsecureContent,
[email protected]f45c5f32012-04-18 19:26:37784 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51785 switches::kPpapiFlashArgs,
786 switches::kPpapiFlashInProcess,
787 switches::kPpapiFlashPath,
788 switches::kPpapiFlashVersion,
789 switches::kProfilingAtStart,
790 switches::kProfilingFile,
791 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37792 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51793 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38794 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51795 };
796
797 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
798 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17799 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38800 static const char* const kSwitchNames[] = {
801 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37802 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38803 switches::kWhitelistedExtensionID,
804 };
805
806 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
807 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51808 } else if (process_type == switches::kPluginProcess) {
809 static const char* const kSwitchNames[] = {
810 #if defined(OS_CHROMEOS)
811 switches::kLoginProfile,
812 #endif
813 switches::kMemoryProfiling,
814 switches::kSilentDumpOnDCHECK,
815 switches::kUserDataDir,
816 };
817
818 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
819 arraysize(kSwitchNames));
820 } else if (process_type == switches::kZygoteProcess) {
821 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51822 switches::kUserDataDir, // Make logs go to the right file.
823 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50824 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13825 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51826 switches::kPpapiFlashInProcess,
827 switches::kPpapiFlashPath,
828 switches::kPpapiFlashVersion,
829 };
830
831 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
832 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11833 } else if (process_type == switches::kGpuProcess) {
834 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
835 // because GPU is expected to be unreliable.
836 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
837 !command_line->HasSwitch(switches::kDisableBreakpad))
838 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30839 }
[email protected]6f08af82011-09-15 01:19:03840
841 // The command line switch kEnableBenchmarking needs to be specified along
842 // with the kEnableStatsTable switch to ensure that the stats table global
843 // is initialized correctly.
844 if (command_line->HasSwitch(switches::kEnableBenchmarking))
845 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30846}
847
848std::string ChromeContentBrowserClient::GetApplicationLocale() {
849 return g_browser_process->GetApplicationLocale();
850}
851
[email protected]597a867b2011-11-18 18:31:20852std::string ChromeContentBrowserClient::GetAcceptLangs(
853 content::BrowserContext* context) {
854 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37855 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08856}
857
[email protected]ac55e292011-06-24 05:16:08858SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22859 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08860 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
861}
862
[email protected]a2176792011-05-08 19:30:49863bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09864 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19865 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20866 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20868 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05869 return io_data->GetCookieSettings()->
870 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49871}
872
[email protected]ed24fad2011-05-10 22:44:01873bool ChromeContentBrowserClient::AllowGetCookie(
874 const GURL& url,
875 const GURL& first_party,
876 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20877 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01878 int render_process_id,
879 int render_view_id) {
880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20881 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05882 bool allow = io_data->GetCookieSettings()->
883 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01884
[email protected]8093a542011-05-13 07:29:32885 BrowserThread::PostTask(
886 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03887 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43888 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01889 return allow;
890}
891
892bool ChromeContentBrowserClient::AllowSetCookie(
893 const GURL& url,
894 const GURL& first_party,
895 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20896 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01897 int render_process_id,
898 int render_view_id,
899 net::CookieOptions* options) {
900 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20901 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05902 CookieSettings* cookie_settings = io_data->GetCookieSettings();
903 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
904
905 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09906 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01907
[email protected]8093a542011-05-13 07:29:32908 BrowserThread::PostTask(
909 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03910 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43911 render_view_id, url, first_party, cookie_line, *options,
912 !allow));
[email protected]ed24fad2011-05-10 22:44:01913 return allow;
914}
915
[email protected]d5a19162011-06-30 18:51:54916bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20917 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20919 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26920
[email protected]f24bd172012-03-31 01:54:59921 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54922}
923
[email protected]5c5a88e2011-11-12 00:45:35924bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35925 const GURL& url,
926 const string16& name,
927 const string16& display_name,
928 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20929 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48930 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20932 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35933 CookieSettings* cookie_settings = io_data->GetCookieSettings();
934 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
935
[email protected]62151052012-02-01 18:40:48936 // Record access to database for potential display in UI.
937 std::vector<std::pair<int, int> >::const_iterator i;
938 for (i = render_views.begin(); i != render_views.end(); ++i) {
939 BrowserThread::PostTask(
940 BrowserThread::UI, FROM_HERE,
941 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
942 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35943 }
944
945 return allow;
946}
947
948bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35949 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20950 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48951 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35952 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20953 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35954 CookieSettings* cookie_settings = io_data->GetCookieSettings();
955 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
956
[email protected]62151052012-02-01 18:40:48957 // Record access to file system for potential display in UI.
958 std::vector<std::pair<int, int> >::const_iterator i;
959 for (i = render_views.begin(); i != render_views.end(); ++i) {
960 BrowserThread::PostTask(
961 BrowserThread::UI, FROM_HERE,
962 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
963 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35964 }
965
966 return allow;
967}
968
[email protected]7c5ff9a2012-03-02 07:42:49969bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
970 const GURL& url,
971 const string16& name,
972 content::ResourceContext* context,
973 const std::vector<std::pair<int, int> >& render_views) {
974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
975 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
976 CookieSettings* cookie_settings = io_data->GetCookieSettings();
977 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
978
979 // Record access to IndexedDB for potential display in UI.
980 std::vector<std::pair<int, int> >::const_iterator i;
981 for (i = render_views.begin(); i != render_views.end(); ++i) {
982 BrowserThread::PostTask(
983 BrowserThread::UI, FROM_HERE,
984 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
985 i->first, i->second, url, name, !allow));
986 }
987
988 return allow;
989}
990
[email protected]6133f922011-07-01 21:34:34991net::URLRequestContext*
992ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20993 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
995 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20996 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34997 return io_data->extensions_request_context();
998 }
999
1000 return NULL;
1001}
1002
[email protected]317f96c92011-05-31 06:53:411003QuotaPermissionContext*
1004ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1005 return new ChromeQuotaPermissionContext();
1006}
1007
[email protected]a0ce3282011-08-19 20:49:521008void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421009 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421010}
1011
[email protected]a0ce3282011-08-19 20:49:521012void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521013 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521014}
1015
[email protected]848dd042011-06-04 18:24:031016void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171017 int render_process_id,
1018 int render_view_id,
1019 int cert_error,
1020 const net::SSLInfo& ssl_info,
1021 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031022 bool overridable,
[email protected]d9be47702012-05-16 03:41:221023 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171024 const base::Callback<void(bool)>& callback,
1025 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411026 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131027 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171028 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411029 if (!tab) {
1030 NOTREACHED();
1031 return;
1032 }
1033 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501034 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301035 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091036 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411037 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171038 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411039 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171040 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411041 return;
1042 }
1043 }
1044
1045 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221046 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1047 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031048}
1049
[email protected]c99c442e2011-08-24 11:37:301050void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451051 int render_process_id,
1052 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401053 const net::HttpNetworkSession* network_session,
1054 net::SSLCertRequestInfo* cert_request_info,
1055 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131056 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451057 render_process_id, render_view_id);
1058 if (!tab) {
1059 NOTREACHED();
1060 return;
1061 }
1062
[email protected]6786bf402011-12-03 15:19:451063 GURL requesting_url("https://" + cert_request_info->host_and_port);
1064 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1065 << cert_request_info->host_and_port;
1066
[email protected]627e0512011-12-21 22:55:301067 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451068 scoped_ptr<Value> filter(
1069 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1070 requesting_url,
1071 requesting_url,
1072 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1073 std::string(), NULL));
1074
1075 if (filter.get()) {
1076 // Try to automatically select a client certificate.
1077 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1078 DictionaryValue* filter_dict =
1079 static_cast<DictionaryValue*>(filter.get());
1080
1081 const std::vector<scoped_refptr<net::X509Certificate> >&
1082 all_client_certs = cert_request_info->client_certs;
1083 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1084 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1085 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401086 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451087 return;
1088 }
1089 }
1090 } else {
1091 NOTREACHED();
1092 }
1093 }
1094
[email protected]8ec26472011-06-06 16:52:451095 TabContentsWrapper* wrapper =
1096 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451097 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131098 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451099 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141100 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401101 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451102 return;
1103 }
[email protected]7a593db2012-02-13 21:19:401104 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1105 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451106}
1107
1108void ChromeContentBrowserClient::AddNewCertificate(
1109 net::URLRequest* request,
1110 net::X509Certificate* cert,
1111 int render_process_id,
1112 int render_view_id) {
1113 // The handler will run the UI and delete itself when it's finished.
1114 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1115}
1116
[email protected]a93670ab2012-02-24 03:46:391117void ChromeContentBrowserClient::RequestMediaAccessPermission(
1118 const content::MediaStreamRequest* request,
1119 const content::MediaResponseCallback& callback) {
1120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1121
[email protected]117b6b42012-02-29 09:11:081122 WebContents* contents = tab_util::GetWebContentsByID(
1123 request->render_process_id, request->render_view_id);
1124 if (!contents) {
1125 // Abort, if the tab was closed after the request was made but before we
1126 // got to this point.
1127 callback.Run(content::MediaStreamDevices());
1128 return;
1129 }
1130
1131 TabContentsWrapper* tab =
1132 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1133 DCHECK(tab);
1134
1135 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1136 InfoBarDelegate* old_infobar = NULL;
1137 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1138 old_infobar =
[email protected]51d1fc62012-04-28 03:47:531139 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfoBarDelegate();
[email protected]117b6b42012-02-29 09:11:081140 }
1141
[email protected]117b6b42012-02-29 09:11:081142 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1143 request,
1144 callback);
1145 if (old_infobar)
1146 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1147 else
1148 infobar_helper->AddInfoBar(infobar);
[email protected]a93670ab2012-02-24 03:46:391149}
1150
[email protected]dc73a7b2012-03-25 15:27:181151content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1152 return MediaInternals::GetInstance();
1153}
1154
[email protected]941623e2011-06-07 23:06:041155void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1156 const GURL& source_origin,
1157 int callback_context,
1158 int render_process_id,
1159 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111160#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041161 RenderViewHost* rvh = RenderViewHost::FromID(
1162 render_process_id, render_view_id);
1163 if (!rvh) {
1164 NOTREACHED();
1165 return;
1166 }
1167
[email protected]9f76c1e2012-03-05 15:15:581168 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301169 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041170 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371171 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041172 service->RequestPermission(
1173 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131174 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111175#else
1176 NOTIMPLEMENTED();
1177#endif
[email protected]941623e2011-06-07 23:06:041178}
1179
1180WebKit::WebNotificationPresenter::Permission
1181 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021182 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201183 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021184 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111185#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201187 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021188 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1189 source_origin, render_process_id,
1190 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041191 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041192
1193 // Fall back to the regular notification preferences, which works on an
1194 // origin basis.
1195 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371196 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041197 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111198#else
1199 return WebKit::WebNotificationPresenter::PermissionAllowed;
1200#endif
[email protected]941623e2011-06-07 23:06:041201}
1202
1203void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171204 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041205 int render_process_id,
1206 int render_view_id,
1207 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111208#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041209 RenderViewHost* rvh = RenderViewHost::FromID(
1210 render_process_id, render_view_id);
1211 if (!rvh) {
1212 NOTREACHED();
1213 return;
1214 }
1215
[email protected]9f76c1e2012-03-05 15:15:581216 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301217 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041218 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371219 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041220 service->ShowDesktopNotification(
1221 params, render_process_id, render_view_id,
1222 worker ? DesktopNotificationService::WorkerNotification :
1223 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111224#else
1225 NOTIMPLEMENTED();
1226#endif
[email protected]941623e2011-06-07 23:06:041227}
1228
1229void ChromeContentBrowserClient::CancelDesktopNotification(
1230 int render_process_id,
1231 int render_view_id,
1232 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111233#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041234 RenderViewHost* rvh = RenderViewHost::FromID(
1235 render_process_id, render_view_id);
1236 if (!rvh) {
1237 NOTREACHED();
1238 return;
1239 }
1240
[email protected]9f76c1e2012-03-05 15:15:581241 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301242 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041243 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371244 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041245 service->CancelDesktopNotification(
1246 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111247#else
1248 NOTIMPLEMENTED();
1249#endif
[email protected]941623e2011-06-07 23:06:041250}
1251
[email protected]9f3fba52011-06-08 20:37:191252bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351253 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021254 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191255 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201256 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011257 int render_process_id,
1258 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011260
1261 *no_javascript_access = false;
1262
[email protected]9f3fba52011-06-08 20:37:191263 // If the opener is trying to create a background window but doesn't have
1264 // the appropriate permission, fail the attempt.
1265 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201266 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531267 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1268
[email protected]03b6d552012-03-29 04:03:011269 if (!map->SecurityOriginHasAPIPermission(
1270 source_origin,
1271 render_process_id,
1272 ExtensionAPIPermission::kBackground)) {
1273 return false;
1274 }
1275
[email protected]7b54ca02012-03-02 18:06:531276 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1277 // return a recently installed Extension even if this CanCreateWindow call
1278 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011279 // because the permission check above would have caused an early return
1280 // already. We must use the full URL to find hosted apps, though, and not
1281 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531282 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351283 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531284 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011285 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191286 }
1287 return true;
1288}
1289
1290std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201291 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1293 // Check if it's an extension-created worker, in which case we want to use
1294 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201295 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191296 const Extension* extension =
1297 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1298 return extension ? extension->name() : std::string();
1299}
1300
[email protected]99907362012-01-11 05:41:401301void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1302 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171303}
1304
[email protected]c52b2892012-03-07 11:01:021305content::SpeechRecognitionManagerDelegate*
1306 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321307#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021308 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321309#else
1310 return NULL;
1311#endif
[email protected]66cfec62012-02-24 17:57:511312}
1313
[email protected]3cb054e62011-06-13 05:21:171314ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1315 return g_browser_process->clipboard();
1316}
1317
[email protected]ae6e9912011-07-27 01:18:281318net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1319 return g_browser_process->net_log();
1320}
1321
[email protected]32538d92011-08-25 00:09:231322AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1323 return new ChromeAccessTokenStore();
1324}
1325
[email protected]dbae6b02011-06-29 23:51:411326bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1327 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1328 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1329}
1330
[email protected]64d69de42012-02-06 00:19:541331void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321332 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061333 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581334 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061335 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061336
[email protected]f3986f82012-01-03 20:00:061337 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541338 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061339 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541340 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061341 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541342 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061343 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541344 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061345 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541346 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061347 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541348 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061349
[email protected]64d69de42012-02-06 00:19:541350 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061351 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541352 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061353 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541354 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061355 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541356 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061357 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1358
[email protected]64d69de42012-02-06 00:19:541359 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061360
[email protected]64d69de42012-02-06 00:19:541361 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061362 prefs->GetBoolean(
1363 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541364 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061365 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541366 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061367 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1368 const DictionaryValue* inspector_settings =
1369 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1370 if (inspector_settings) {
1371 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1372 iter != inspector_settings->end_keys(); ++iter) {
1373 std::string value;
1374 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541375 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061376 std::make_pair(*iter, value));
1377 }
1378 }
[email protected]64d69de42012-02-06 00:19:541379 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061380
[email protected]64d69de42012-02-06 00:19:541381 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1382 web_prefs->javascript_enabled = false;
1383 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1384 web_prefs->web_security_enabled = false;
1385 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1386 web_prefs->plugins_enabled = false;
1387 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1388 web_prefs->java_enabled = false;
1389 web_prefs->loads_images_automatically =
1390 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061391
[email protected]64d69de42012-02-06 00:19:541392 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1393 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061394
[email protected]64d69de42012-02-06 00:19:541395 web_prefs->memory_info_enabled =
1396 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1397 web_prefs->allow_displaying_insecure_content =
1398 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1399 web_prefs->allow_running_insecure_content =
1400 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081401 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061402
[email protected]64d69de42012-02-06 00:19:541403 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151404 UserStyleSheetWatcher* user_style_sheet_watcher =
1405 UserStyleSheetWatcherFactory::GetForProfile(profile);
1406 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541407 web_prefs->user_style_sheet_enabled = true;
1408 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151409 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541410 } else {
1411 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061412 }
1413
[email protected]b7e44ff2012-02-16 03:37:341414 web_prefs->asynchronous_spell_checking_enabled =
[email protected]8e466dd2012-05-04 19:16:051415 CommandLine::ForCurrentProcess()->
1416 HasSwitch(switches::kEnableAsynchronousSpellChecking);
[email protected]b7e44ff2012-02-16 03:37:341417 web_prefs->unified_textchecker_enabled =
1418 web_prefs->asynchronous_spell_checking_enabled ||
1419 CommandLine::ForCurrentProcess()->
1420 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571421
[email protected]64d69de42012-02-06 00:19:541422 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061423 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541424 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061425 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541426 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061427 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1428
1429 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541430 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061431 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541432 web_prefs->default_encoding);
1433 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061434 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541435 web_prefs->default_encoding =
1436 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061437 }
[email protected]64d69de42012-02-06 00:19:541438 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061439
1440 ExtensionService* service = profile->GetExtensionService();
1441 if (service) {
1442 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581443 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061444 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581445 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061446 }
1447
[email protected]9f76c1e2012-03-05 15:15:581448 if (rvh->GetDelegate()->GetRenderViewType() ==
1449 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541450 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581451 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061452 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1453 // Disable all kinds of acceleration for background pages.
1454 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541455 web_prefs->force_compositing_mode = false;
1456 web_prefs->accelerated_compositing_enabled = false;
1457 web_prefs->accelerated_2d_canvas_enabled = false;
1458 web_prefs->accelerated_video_enabled = false;
1459 web_prefs->accelerated_painting_enabled = false;
1460 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061461 }
[email protected]2e21fe292012-03-02 22:52:321462
1463#if defined(FILE_MANAGER_EXTENSION)
1464 // Override the default of suppressing HW compositing for WebUI pages for the
1465 // file manager, which is implemented using WebUI but wants HW acceleration
1466 // for video decode & render.
1467 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1468 web_prefs->accelerated_compositing_enabled = true;
1469 web_prefs->accelerated_2d_canvas_enabled = true;
1470 }
1471#endif
[email protected]181a95ee2011-07-12 19:26:361472}
1473
1474void ChromeContentBrowserClient::UpdateInspectorSetting(
1475 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061476 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581477 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061478 DictionaryPrefUpdate update(
1479 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1480 prefs::kWebKitInspectorSettings);
1481 DictionaryValue* inspector_settings = update.Get();
1482 inspector_settings->SetWithoutPathExpansion(key,
1483 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361484}
1485
1486void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061487 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581488 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061489 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1490 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361491}
1492
[email protected]b8148ac2011-07-13 22:03:251493void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1494 BrowserURLHandler* handler) {
1495 // Add the default URL handlers.
1496 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1497 BrowserURLHandler::null_handler());
1498 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1499 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1500
[email protected]b3adbd02011-11-30 22:23:271501 // about: handler. Must come before chrome: handler, since it will
1502 // rewrite about: urls to chrome: URLs and then expect chrome: to
1503 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251504 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1505 BrowserURLHandler::null_handler());
1506 // chrome: & friends.
1507 handler->AddHandlerPair(&HandleWebUI,
1508 BrowserURLHandler::null_handler());
1509}
1510
1511void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371512 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581513 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251514 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1515 BrowsingDataRemover::EVERYTHING,
1516 base::Time());
1517 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1518 // BrowsingDataRemover takes care of deleting itself when done.
1519}
1520
1521void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371522 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581523 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251524 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1525 BrowsingDataRemover::EVERYTHING,
1526 base::Time());
[email protected]dceaa912011-09-06 17:17:231527 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251528 remover->Remove(remove_mask);
1529 // BrowsingDataRemover takes care of deleting itself when done.
1530}
1531
[email protected]e1d16eb92011-08-18 23:19:321532FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1533 return download_util::GetDefaultDownloadDirectory();
1534}
1535
[email protected]c9b6eb62011-10-18 20:49:391536std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1537 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1538}
1539
[email protected]a658d452012-03-02 12:45:291540bool ChromeContentBrowserClient::AllowSocketAPI(
1541 content::BrowserContext* browser_context, const GURL& url) {
1542 if (!url.is_valid())
1543 return false;
1544
1545 std::string host = url.host();
1546 if (allowed_socket_origins_.count(host))
1547 return true;
1548
[email protected]9a5940d2012-04-27 19:16:231549 Profile* profile = Profile::FromBrowserContext(browser_context);
1550 const Extension* extension = NULL;
1551 if (profile && profile->GetExtensionService()) {
1552 extension = profile->GetExtensionService()->extensions()->
1553 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1554 }
1555
[email protected]f237c0f2012-03-10 07:49:101556 // Need to check this now and not on construction because otherwise it won't
1557 // work with browser_tests.
1558 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1559 std::string allowed_list =
1560 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231561 if (allowed_list == "*") {
1562 // The wildcard allows socket API only for packaged and platform apps.
1563 return extension &&
1564 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1565 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1566 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101567 StringTokenizer t(allowed_list, ",");
1568 while (t.GetNext()) {
1569 if (t.token() == host)
1570 return true;
1571 }
1572 }
1573
[email protected]a658d452012-03-02 12:45:291574 if (!extension)
1575 return false;
1576
1577 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1578 return true;
1579
1580 return false;
[email protected]e461da2f2012-02-16 19:06:401581}
1582
[email protected]e60c0232011-11-11 19:56:351583#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301584int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521585 const CommandLine& command_line) {
1586 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071587 ExtensionCrashHandlerHostLinux* crash_handler =
1588 ExtensionCrashHandlerHostLinux::GetInstance();
1589 return crash_handler->GetDeathSignalSocket();
1590 }
1591
[email protected]718eab62011-10-05 21:16:521592 std::string process_type =
1593 command_line.GetSwitchValueASCII(switches::kProcessType);
1594
1595 if (process_type == switches::kRendererProcess)
1596 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1597
[email protected]b80f68432011-05-02 17:22:301598 if (process_type == switches::kPluginProcess)
1599 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1600
1601 if (process_type == switches::kPpapiPluginProcess)
1602 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1603
1604 if (process_type == switches::kGpuProcess)
1605 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1606
1607 return -1;
1608}
[email protected]e60c0232011-11-11 19:56:351609#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301610
[email protected]4a65826d2011-08-25 16:04:011611#if defined(OS_WIN)
1612const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1613 return chrome::kBrowserResourcesDll;
1614}
1615#endif
1616
[email protected]37a72af2011-06-13 05:42:011617#if defined(USE_NSS)
1618crypto::CryptoModuleBlockingPasswordDelegate*
1619 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1620 const GURL& url) {
1621 return browser::NewCryptoModuleBlockingDialogDelegate(
1622 browser::kCryptoModulePasswordKeygen, url.host());
1623}
1624#endif
1625
[email protected]d977f9c2011-03-14 16:10:261626} // namespace chrome