blob: d4f27a747fafd3264b4d2d6641912c159aabad5f [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]f9034cf2011-07-21 12:43:4150#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1451#include "chrome/browser/printing/printing_message_filter.h"
52#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3253#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0654#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1455#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3356#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4257#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0259#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4660#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4561#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0362#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
64#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0865#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4566#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5067#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0668#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1569#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3070#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0171#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3072#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0473#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4474#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3475#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1276#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3877#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0978#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4379#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3080#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3181#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5982#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3083#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3384#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0585#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3386#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1987#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1088#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4389#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3990#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3491#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4092#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0693#include "net/cookies/cookie_monster.h"
94#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3995#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0896#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3697#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:0498#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:2699
[email protected]b48c9182011-10-26 18:03:30100#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38101#include "chrome/browser/chrome_browser_main_win.h"
102#elif defined(OS_MACOSX)
103#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56104#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57105#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30106#elif defined(OS_CHROMEOS)
107#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49108#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26109#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30110#include "chrome/browser/chrome_browser_main_linux.h"
111#elif defined(OS_POSIX)
112#include "chrome/browser/chrome_browser_main_posix.h"
113#endif
114
[email protected]c0d7f792012-04-18 19:16:00115#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13116#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]61e69822012-03-14 22:08:57117#endif
118
[email protected]a13283cc2012-04-05 00:21:22119#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31120#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38121#endif
122
[email protected]c7480942011-11-08 19:18:27123#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31124#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27125#endif
126
127#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31128#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
129#endif
130
[email protected]dc04be7c2012-03-15 23:57:49131#if defined(USE_ASH)
132#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
133#endif
134
[email protected]6653c192012-04-10 22:52:44135#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30136#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44137#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43138#endif
[email protected]b80f68432011-05-02 17:22:30139
[email protected]38b098f2012-03-14 21:11:57140#if defined(TOOLKIT_GTK)
141#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32142#endif
[email protected]37a72af2011-06-13 05:42:01143#if defined(USE_NSS)
144#include "chrome/browser/ui/crypto_module_password_dialog.h"
145#endif
146
[email protected]c8c77182011-12-21 15:04:47147using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39148using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31149using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59150using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00151using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11152using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33153using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13154using content::WebContents;
[email protected]631bb742011-11-02 11:29:39155
[email protected]c5dbef02011-05-13 05:06:09156namespace {
157
[email protected]e461da2f2012-02-16 19:06:40158const char* kPredefinedAllowedSocketOrigins[] = {
159 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18160 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45161 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
162 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
163 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
164 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
165 "ojoimpklfciegopdfgeenehpalipignm" // Chromoting canary
[email protected]e461da2f2012-02-16 19:06:40166};
167
[email protected]b8148ac2011-07-13 22:03:25168// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42169bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50170 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
171 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25172 return false;
173
[email protected]fe69558d2012-03-12 11:34:49174#if defined(OS_CHROMEOS)
175 // Special case : in ChromeOS in Guest mode bookmarks and history are
176 // disabled for security reasons. New tab page explains the reasons, so
177 // we redirect user to new tab page.
178 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
179 if (url->SchemeIs(chrome::kChromeUIScheme) &&
180 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
181 url->DomainIs(chrome::kChromeUIHistoryHost))) {
182 // Rewrite with new tab URL
183 *url = GURL(chrome::kChromeUINewTabURL);
184 }
185 }
186#endif
187
[email protected]b8148ac2011-07-13 22:03:25188 // Special case the new tab page. In older versions of Chrome, the new tab
189 // page was hosted at chrome-internal:<blah>. This might be in people's saved
190 // sessions or bookmarks, so we say any URL with that scheme triggers the new
191 // tab page.
192 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
193 // Rewrite it with the proper new tab URL.
194 *url = GURL(chrome::kChromeUINewTabURL);
195 }
196
197 return true;
198}
199
[email protected]8d3132f62011-10-12 07:13:42200// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
201// below. Extension, and isolated apps require different privileges to be
202// granted to their RenderProcessHosts. This classification allows us to make
203// sure URLs are served by hosts with the right set of privileges.
204enum RenderProcessHostPrivilege {
205 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45206 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42207 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45208 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42209};
210
211RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
212 const GURL& url,
213 ExtensionService* service) {
214 // Default to a normal renderer cause it is lower privileged. This should only
215 // occur if the URL on a site instance is either malformed, or uninitialized.
216 // If it is malformed, then there is no need for better privileges anyways.
217 // If it is uninitialized, but eventually settles on being an a scheme other
218 // than normal webrenderer, the navigation logic will correct us out of band
219 // anyways.
220 if (!url.is_valid())
221 return PRIV_NORMAL;
222
223 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44224 const Extension* extension =
225 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45226 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42227 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45228 if (extension && extension->is_hosted_app())
229 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42230
231 return PRIV_EXTENSION;
232 }
233
234 return PRIV_NORMAL;
235}
236
237RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30238 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46239 extensions::ProcessMap* process_map,
240 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46241 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30242 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46243 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21244 return PRIV_NORMAL;
245
[email protected]6f371442011-11-09 06:45:46246 for (std::set<std::string>::iterator iter = extension_ids.begin();
247 iter != extension_ids.end(); ++iter) {
248 const Extension* extension = service->GetExtensionById(*iter, false);
249 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42250 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45251 if (extension && extension->is_hosted_app())
252 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42253 }
254
[email protected]676f6ab2011-10-19 20:23:21255 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42256}
257
[email protected]eec0b33c2011-12-05 22:09:45258bool IsIsolatedAppInProcess(const GURL& site_url,
259 content::RenderProcessHost* process_host,
260 extensions::ProcessMap* process_map,
261 ExtensionService* service) {
262 std::set<std::string> extension_ids =
263 process_map->GetExtensionsInProcess(process_host->GetID());
264 if (extension_ids.empty())
265 return false;
266
267 for (std::set<std::string>::iterator iter = extension_ids.begin();
268 iter != extension_ids.end(); ++iter) {
269 const Extension* extension = service->GetExtensionById(*iter, false);
270 if (extension &&
271 extension->is_storage_isolated() &&
272 extension->url() == site_url)
273 return true;
274 }
275
276 return false;
277}
278
[email protected]6786bf402011-12-03 15:19:45279bool CertMatchesFilter(const net::X509Certificate& cert,
280 const base::DictionaryValue& filter) {
281 // TODO(markusheintz): This is the minimal required filter implementation.
282 // Implement a better matcher.
283
284 // An empty filter matches any client certificate since no requirements are
285 // specified at all.
286 if (filter.empty())
287 return true;
288
289 std::string common_name;
290 if (filter.GetString("ISSUER.CN", &common_name) &&
291 (cert.issuer().common_name == common_name)) {
292 return true;
293 }
294 return false;
295}
296
[email protected]f3986f82012-01-03 20:00:06297// Fills |map| with the per-script font prefs under path |map_name|.
298void FillFontFamilyMap(const PrefService* prefs,
299 const char* map_name,
300 WebPreferences::ScriptFontFamilyMap* map) {
301 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
302 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
303 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
304 std::string font_family = prefs->GetString(pref_name.c_str());
305 if (!font_family.empty())
306 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
307 }
308}
309
[email protected]9dbfff12011-07-01 19:37:07310} // namespace
[email protected]c5dbef02011-05-13 05:06:09311
[email protected]d977f9c2011-03-14 16:10:26312namespace chrome {
313
[email protected]e461da2f2012-02-16 19:06:40314ChromeContentBrowserClient::ChromeContentBrowserClient() {
315 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
316 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40317}
318
319ChromeContentBrowserClient::~ChromeContentBrowserClient() {
320}
321
[email protected]50462bf02011-11-21 19:13:31322content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
323 const content::MainFunctionParams& parameters) {
324 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30325 // Construct the Main browser parts based on the OS type.
326#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31327 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04328#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31329 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30330#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31331 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26332#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31333 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14334#elif defined(OS_ANDROID)
335 // Do nothing for Android.
336 // TODO(klobag): Android initialization should use the
337 // *BrowserMainParts class-hierarchy for setting up custom initialization.
338 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30339#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31340 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04341#else
[email protected]b48c9182011-10-26 18:03:30342 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31343 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30344#endif
345
[email protected]c7480942011-11-08 19:18:27346 // Construct additional browser parts. Stages are called in the order in
347 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22348#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31349 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04350#endif
[email protected]c7480942011-11-08 19:18:27351
352#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31353 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27354#endif
355
[email protected]dc04be7c2012-03-15 23:57:49356#if defined(USE_ASH)
357 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
358#endif
359
[email protected]e050ef142012-03-21 01:04:24360#if defined(USE_AURA)
361 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
362#endif
363
[email protected]50462bf02011-11-21 19:13:31364 return main_parts;
[email protected]f967b722011-09-07 00:58:04365}
366
[email protected]38b098f2012-03-14 21:11:57367content::WebContentsView*
368 ChromeContentBrowserClient::OverrideCreateWebContentsView(
369 WebContents* web_contents) {
[email protected]38b098f2012-03-14 21:11:57370 return NULL;
371}
372
373content::WebContentsViewDelegate*
374 ChromeContentBrowserClient::GetWebContentsViewDelegate(
375 content::WebContents* web_contents) {
[email protected]c0d7f792012-04-18 19:16:00376#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13377 return new ChromeWebContentsViewDelegateViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57378#elif defined(TOOLKIT_GTK)
379 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32380#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57381 return
382 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
383 web_contents);
[email protected]74313b42011-08-24 16:51:32384#else
[email protected]38b098f2012-03-14 21:11:57385 return NULL;
[email protected]74313b42011-08-24 16:51:32386#endif
387}
388
[email protected]f364d1392011-04-08 21:03:10389void ChromeContentBrowserClient::RenderViewHostCreated(
390 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46391
[email protected]9f76c1e2012-03-05 15:15:58392 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46393 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02394 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46395
396 new ChromeRenderViewHostObserver(render_view_host,
397 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10398 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26399}
400
[email protected]f3b1a082011-11-18 00:34:30401void ChromeContentBrowserClient::RenderProcessHostCreated(
402 content::RenderProcessHost* host) {
403 int id = host->GetID();
404 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
405 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02406 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30407 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03408#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30409 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03410#endif
[email protected]f3b1a082011-11-18 00:34:30411 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02412 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30413 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56414#if defined(OS_MACOSX)
415 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
416#endif
[email protected]f3b1a082011-11-18 00:34:30417 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03418 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38419
[email protected]2ccf45c2011-08-19 23:35:50420 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
421 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07422
423 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56424
425 RendererContentSettingRules rules;
426 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
427 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14428}
429
[email protected]e0ada9c2012-03-20 03:54:43430void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
431 content::BrowserChildProcessHost* host) {
432 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
433}
434
[email protected]863f70a2012-01-27 02:05:50435content::WebUIControllerFactory*
436 ChromeContentBrowserClient::GetWebUIControllerFactory() {
437 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56438}
439
[email protected]3d7474ff2011-07-27 17:47:37440GURL ChromeContentBrowserClient::GetEffectiveURL(
441 content::BrowserContext* browser_context, const GURL& url) {
442 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08443 // Get the effective URL for the given actual URL. If the URL is part of an
444 // installed app, the effective URL is an extension URL with the ID of that
445 // extension as the host. This has the effect of grouping apps together in
446 // a common SiteInstance.
447 if (!profile || !profile->GetExtensionService())
448 return url;
449
[email protected]615d88f2011-12-13 01:47:44450 const Extension* extension = profile->GetExtensionService()->extensions()->
451 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08452 if (!extension)
453 return url;
454
[email protected]15877ca2011-11-18 22:40:52455 // Bookmark apps do not use the hosted app process model, and should be
456 // treated as normal URLs.
457 if (extension->from_bookmark())
458 return url;
459
[email protected]36fb2c7c2011-04-04 15:49:08460 // If the URL is part of an extension's web extent, convert it to an
461 // extension URL.
462 return extension->GetResourceURL(url.path());
463}
464
[email protected]056ad2a2011-07-12 02:13:55465bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37466 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55467 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52468 // Because we expect to use the effective URL, URLs for hosted apps (apart
469 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55470 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
471 return false;
472
[email protected]3d7474ff2011-07-27 17:47:37473 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55474 if (!profile || !profile->GetExtensionService())
475 return false;
476
[email protected]615d88f2011-12-13 01:47:44477 const Extension* extension = profile->GetExtensionService()->extensions()->
478 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55479 if (!extension)
480 return false;
481
482 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53483 // permission, or that does not allow JavaScript access to the background
484 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55485 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53486 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
487 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
488 !extension->allow_background_js_access()) {
489 return false;
490 }
491 }
[email protected]056ad2a2011-07-12 02:13:55492
[email protected]7b54ca02012-03-02 18:06:53493 // Hosted apps that have script access to their background page must use
494 // process per site, since all instances can make synchronous calls to the
495 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55496 return true;
497}
498
[email protected]46fb9442011-12-09 17:57:47499bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
500 return ProfileIOData::IsHandledURL(url);
501}
502
[email protected]2a5221b2011-09-27 23:07:31503bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30504 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31505 const GURL& site_url) {
506 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30507 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42508 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46509 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31510
[email protected]ffa97602011-11-17 17:55:52511 // Don't allow the Task Manager to share a process with anything else.
512 // Otherwise it can affect the renderers it is observing.
513 // Note: we could create another RenderProcessHostPrivilege bucket for
514 // this to allow multiple chrome://tasks instances to share, but that's
515 // a very unlikely case without serious consequences.
516 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
517 return false;
518
[email protected]8d3132f62011-10-12 07:13:42519 // These may be NULL during tests. In that case, just assume any site can
520 // share any host.
[email protected]6f371442011-11-09 06:45:46521 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31522 return true;
523
[email protected]a8c269a2011-10-25 20:17:22524 // Experimental:
525 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
526 // to share a renderer process. (We could allow pages from the same site or
527 // extensions of the same type to share, if we knew what the given process
528 // was dedicated to. Allowing no sharing is simpler for now.) This may
529 // cause resource exhaustion issues if too many sites are open at once.
530 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
531 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
532 return false;
533
[email protected]eec0b33c2011-12-05 22:09:45534 // An isolated app is only allowed to share with the exact same app in order
535 // to provide complete renderer process isolation. This also works around
536 // issue http://crbug.com/85588, where different isolated apps in the same
537 // process would end up using the first app's storage contexts.
538 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42539 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45540 if (privilege_required == PRIV_ISOLATED)
541 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
542
543 // Otherwise, just make sure the process privilege matches the privilege
544 // required by the site.
545 return GetProcessPrivilege(process_host, process_map, service) ==
546 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31547}
548
[email protected]76411f412012-02-22 18:56:06549// This function is trying to limit the amount of processes used by extensions
550// with background pages. It uses a globally set percentage of processes to
551// run such extensions and if the limit is exceeded, it returns true, to
552// indicate to the content module to group extensions together.
553bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
554 content::BrowserContext* browser_context, const GURL& url) {
555 // It has to be a valid URL for us to check for an extension.
556 if (!url.is_valid())
557 return false;
558
559 Profile* profile = Profile::FromBrowserContext(browser_context);
560 ExtensionService* service = profile->GetExtensionService();
561 if (!service)
562 return false;
563
564 // We have to have a valid extension with background page to proceed.
565 const Extension* extension =
566 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
567 if (!extension)
568 return false;
569 if (!extension->has_background_page())
570 return false;
571
572 std::set<int> process_ids;
573 size_t max_process_count =
574 content::RenderProcessHost::GetMaxRendererProcessCount();
575
576 // Go through all profiles to ensure we have total count of extension
577 // processes containing background pages, otherwise one profile can
578 // starve the other.
579 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
580 GetLoadedProfiles();
581 for (size_t i = 0; i < profiles.size(); ++i) {
582 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32583 for (ExtensionProcessManager::const_iterator iter =
584 epm->background_hosts().begin();
585 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06586 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32587 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06588 }
589 }
590
591 if (process_ids.size() >
592 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
593 return true;
594 }
595
596 return false;
597}
598
[email protected]6f371442011-11-09 06:45:46599void ChromeContentBrowserClient::SiteInstanceGotProcess(
600 SiteInstance* site_instance) {
601 CHECK(site_instance->HasProcess());
602
603 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02604 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46605 ExtensionService* service = profile->GetExtensionService();
606 if (!service)
607 return;
608
609 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44610 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33611 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46612 if (!extension)
613 return;
614
[email protected]6bc04fd82011-12-04 02:29:35615 service->process_map()->Insert(extension->id(),
616 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33617 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46618 BrowserThread::PostTask(
619 BrowserThread::IO, FROM_HERE,
620 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24621 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46622 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35623 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33624 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46625}
626
627void ChromeContentBrowserClient::SiteInstanceDeleting(
628 SiteInstance* site_instance) {
629 if (!site_instance->HasProcess())
630 return;
631
632 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02633 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46634 ExtensionService* service = profile->GetExtensionService();
635 if (!service)
636 return;
637
638 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44639 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33640 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46641 if (!extension)
642 return;
643
[email protected]6bc04fd82011-12-04 02:29:35644 service->process_map()->Remove(extension->id(),
645 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33646 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46647 BrowserThread::PostTask(
648 BrowserThread::IO, FROM_HERE,
649 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24650 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46651 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35652 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33653 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46654}
655
[email protected]e3daf3c2011-10-05 21:17:08656bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
657 const GURL& current_url,
658 const GURL& new_url) {
659 if (current_url.is_empty()) {
660 // Always choose a new process when navigating to extension URLs. The
661 // process grouping logic will combine all of a given extension's pages
662 // into the same process.
663 if (new_url.SchemeIs(chrome::kExtensionScheme))
664 return true;
665
666 return false;
667 }
668
669 // Also, we must switch if one is an extension and the other is not the exact
670 // same extension.
671 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
672 new_url.SchemeIs(chrome::kExtensionScheme)) {
673 if (current_url.GetOrigin() != new_url.GetOrigin())
674 return true;
675 }
676
677 return false;
678}
679
[email protected]763ec4ca2011-04-29 15:48:12680std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
681 const std::string& alias_name) {
682 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
683}
684
[email protected]b80f68432011-05-02 17:22:30685void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
686 CommandLine* command_line, int child_process_id) {
687#if defined(USE_LINUX_BREAKPAD)
688 if (IsCrashReporterEnabled()) {
689 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
690 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
691 }
692#elif defined(OS_MACOSX)
693 if (IsCrashReporterEnabled()) {
694 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
695 child_process_logging::GetClientId());
696 }
697#endif // OS_MACOSX
698
[email protected]f1933792011-06-14 00:49:34699 if (logging::DialogsAreSuppressed())
700 command_line->AppendSwitch(switches::kNoErrorDialogs);
701
[email protected]b80f68432011-05-02 17:22:30702 std::string process_type =
703 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17704 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52705 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30706 FilePath user_data_dir =
707 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
708 if (!user_data_dir.empty())
709 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
710#if defined(OS_CHROMEOS)
711 const std::string& login_profile =
712 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
713 if (!login_profile.empty())
714 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
715#endif
716
[email protected]f3b1a082011-11-18 00:34:30717 content::RenderProcessHost* process =
718 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37719 if (process) {
720 Profile* profile = Profile::FromBrowserContext(
721 process->GetBrowserContext());
722 extensions::ProcessMap* process_map =
723 profile->GetExtensionService()->process_map();
724 if (process_map && process_map->Contains(process->GetID()))
725 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30726
[email protected]a8d851f82011-12-21 00:32:37727 PrefService* prefs = profile->GetPrefs();
728 // Currently this pref is only registered if applied via a policy.
729 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
730 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
731 // Turn this policy into a command line switch.
732 command_line->AppendSwitch(switches::kDisable3DAPIs);
733 }
[email protected]718eab62011-10-05 21:16:52734
[email protected]a8d851f82011-12-21 00:32:37735 // Disable client-side phishing detection in the renderer if it is
736 // disabled in the Profile preferences or the browser process.
737 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
738 !g_browser_process->safe_browsing_detection_service()) {
739 command_line->AppendSwitch(
740 switches::kDisableClientSidePhishingDetection);
741 }
[email protected]8c40da62011-07-13 22:58:46742 }
[email protected]47c7ec82012-01-18 03:29:21743 {
744 PrefService* local_state = g_browser_process->local_state();
745 if (local_state &&
746 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
747 command_line->AppendSwitch(switches::kRendererPrintPreview);
748 }
749 }
[email protected]4287a3d2011-06-13 23:56:51750
[email protected]47c7ec82012-01-18 03:29:21751 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51752 static const char* const kSwitchNames[] = {
753 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48754 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51755 switches::kAllowScriptingGallery,
756 switches::kAppsCheckoutURL,
757 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31758 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51759 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50760 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51761 switches::kDumpHistogramsOnExit,
[email protected]8e466dd2012-05-04 19:16:05762 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21763 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13764 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51765 switches::kEnableCrxlessWebApps,
766 switches::kEnableExperimentalExtensionApis,
767 switches::kEnableInBrowserThumbnailing,
768 switches::kEnableIPCFuzzing,
769 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05770 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48771 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53772 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51773 switches::kEnableWatchdog,
774 switches::kExperimentalSpellcheckerFeatures,
775 switches::kMemoryProfiling,
776 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37777 switches::kNoJsRandomness,
[email protected]2a6bb0b12011-10-05 19:18:04778 switches::kNoRunningInsecureContent,
[email protected]f45c5f32012-04-18 19:26:37779 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51780 switches::kPpapiFlashArgs,
781 switches::kPpapiFlashInProcess,
782 switches::kPpapiFlashPath,
783 switches::kPpapiFlashVersion,
784 switches::kProfilingAtStart,
785 switches::kProfilingFile,
786 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37787 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51788 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38789 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51790 };
791
792 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
793 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17794 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38795 static const char* const kSwitchNames[] = {
796 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37797 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38798 switches::kWhitelistedExtensionID,
799 };
800
801 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
802 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51803 } else if (process_type == switches::kPluginProcess) {
804 static const char* const kSwitchNames[] = {
805 #if defined(OS_CHROMEOS)
806 switches::kLoginProfile,
807 #endif
808 switches::kMemoryProfiling,
809 switches::kSilentDumpOnDCHECK,
810 switches::kUserDataDir,
811 };
812
813 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
814 arraysize(kSwitchNames));
815 } else if (process_type == switches::kZygoteProcess) {
816 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51817 switches::kUserDataDir, // Make logs go to the right file.
818 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50819 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13820 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51821 switches::kPpapiFlashInProcess,
822 switches::kPpapiFlashPath,
823 switches::kPpapiFlashVersion,
824 };
825
826 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
827 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11828 } else if (process_type == switches::kGpuProcess) {
829 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
830 // because GPU is expected to be unreliable.
831 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
832 !command_line->HasSwitch(switches::kDisableBreakpad))
833 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30834 }
[email protected]6f08af82011-09-15 01:19:03835
836 // The command line switch kEnableBenchmarking needs to be specified along
837 // with the kEnableStatsTable switch to ensure that the stats table global
838 // is initialized correctly.
839 if (command_line->HasSwitch(switches::kEnableBenchmarking))
840 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30841}
842
843std::string ChromeContentBrowserClient::GetApplicationLocale() {
844 return g_browser_process->GetApplicationLocale();
845}
846
[email protected]597a867b2011-11-18 18:31:20847std::string ChromeContentBrowserClient::GetAcceptLangs(
848 content::BrowserContext* context) {
849 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37850 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08851}
852
[email protected]ac55e292011-06-24 05:16:08853SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22854 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08855 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
856}
857
[email protected]a2176792011-05-08 19:30:49858bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09859 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19860 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20861 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20863 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05864 return io_data->GetCookieSettings()->
865 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49866}
867
[email protected]ed24fad2011-05-10 22:44:01868bool ChromeContentBrowserClient::AllowGetCookie(
869 const GURL& url,
870 const GURL& first_party,
871 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20872 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01873 int render_process_id,
874 int render_view_id) {
875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20876 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05877 bool allow = io_data->GetCookieSettings()->
878 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01879
[email protected]8093a542011-05-13 07:29:32880 BrowserThread::PostTask(
881 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03882 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43883 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01884 return allow;
885}
886
887bool ChromeContentBrowserClient::AllowSetCookie(
888 const GURL& url,
889 const GURL& first_party,
890 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20891 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01892 int render_process_id,
893 int render_view_id,
894 net::CookieOptions* options) {
895 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20896 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05897 CookieSettings* cookie_settings = io_data->GetCookieSettings();
898 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
899
900 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09901 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01902
[email protected]8093a542011-05-13 07:29:32903 BrowserThread::PostTask(
904 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03905 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43906 render_view_id, url, first_party, cookie_line, *options,
907 !allow));
[email protected]ed24fad2011-05-10 22:44:01908 return allow;
909}
910
[email protected]d5a19162011-06-30 18:51:54911bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20912 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20914 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26915
[email protected]f24bd172012-03-31 01:54:59916 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54917}
918
[email protected]5c5a88e2011-11-12 00:45:35919bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35920 const GURL& url,
921 const string16& name,
922 const string16& display_name,
923 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20924 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48925 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20927 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35928 CookieSettings* cookie_settings = io_data->GetCookieSettings();
929 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
930
[email protected]62151052012-02-01 18:40:48931 // Record access to database for potential display in UI.
932 std::vector<std::pair<int, int> >::const_iterator i;
933 for (i = render_views.begin(); i != render_views.end(); ++i) {
934 BrowserThread::PostTask(
935 BrowserThread::UI, FROM_HERE,
936 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
937 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35938 }
939
940 return allow;
941}
942
943bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35944 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20945 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48946 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20948 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35949 CookieSettings* cookie_settings = io_data->GetCookieSettings();
950 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
951
[email protected]62151052012-02-01 18:40:48952 // Record access to file system for potential display in UI.
953 std::vector<std::pair<int, int> >::const_iterator i;
954 for (i = render_views.begin(); i != render_views.end(); ++i) {
955 BrowserThread::PostTask(
956 BrowserThread::UI, FROM_HERE,
957 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
958 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35959 }
960
961 return allow;
962}
963
[email protected]7c5ff9a2012-03-02 07:42:49964bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
965 const GURL& url,
966 const string16& name,
967 content::ResourceContext* context,
968 const std::vector<std::pair<int, int> >& render_views) {
969 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
970 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
971 CookieSettings* cookie_settings = io_data->GetCookieSettings();
972 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
973
974 // Record access to IndexedDB for potential display in UI.
975 std::vector<std::pair<int, int> >::const_iterator i;
976 for (i = render_views.begin(); i != render_views.end(); ++i) {
977 BrowserThread::PostTask(
978 BrowserThread::UI, FROM_HERE,
979 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
980 i->first, i->second, url, name, !allow));
981 }
982
983 return allow;
984}
985
[email protected]6133f922011-07-01 21:34:34986net::URLRequestContext*
987ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20988 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34989 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
990 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20991 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34992 return io_data->extensions_request_context();
993 }
994
995 return NULL;
996}
997
[email protected]317f96c92011-05-31 06:53:41998QuotaPermissionContext*
999ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1000 return new ChromeQuotaPermissionContext();
1001}
1002
[email protected]a0ce3282011-08-19 20:49:521003void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421004 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421005}
1006
[email protected]a0ce3282011-08-19 20:49:521007void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521008 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521009}
1010
[email protected]848dd042011-06-04 18:24:031011void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171012 int render_process_id,
1013 int render_view_id,
1014 int cert_error,
1015 const net::SSLInfo& ssl_info,
1016 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031017 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171018 const base::Callback<void(bool)>& callback,
1019 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411020 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131021 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171022 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411023 if (!tab) {
1024 NOTREACHED();
1025 return;
1026 }
1027 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501028 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301029 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091030 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411031 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171032 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411033 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171034 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411035 return;
1036 }
1037 }
1038
1039 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171040 new SSLBlockingPage(
1041 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031042}
1043
[email protected]c99c442e2011-08-24 11:37:301044void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451045 int render_process_id,
1046 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401047 const net::HttpNetworkSession* network_session,
1048 net::SSLCertRequestInfo* cert_request_info,
1049 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131050 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451051 render_process_id, render_view_id);
1052 if (!tab) {
1053 NOTREACHED();
1054 return;
1055 }
1056
[email protected]6786bf402011-12-03 15:19:451057 GURL requesting_url("https://" + cert_request_info->host_and_port);
1058 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1059 << cert_request_info->host_and_port;
1060
[email protected]627e0512011-12-21 22:55:301061 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451062 scoped_ptr<Value> filter(
1063 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1064 requesting_url,
1065 requesting_url,
1066 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1067 std::string(), NULL));
1068
1069 if (filter.get()) {
1070 // Try to automatically select a client certificate.
1071 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1072 DictionaryValue* filter_dict =
1073 static_cast<DictionaryValue*>(filter.get());
1074
1075 const std::vector<scoped_refptr<net::X509Certificate> >&
1076 all_client_certs = cert_request_info->client_certs;
1077 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1078 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1079 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401080 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451081 return;
1082 }
1083 }
1084 } else {
1085 NOTREACHED();
1086 }
1087 }
1088
[email protected]8ec26472011-06-06 16:52:451089 TabContentsWrapper* wrapper =
1090 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451091 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131092 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451093 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141094 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401095 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451096 return;
1097 }
[email protected]7a593db2012-02-13 21:19:401098 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1099 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451100}
1101
1102void ChromeContentBrowserClient::AddNewCertificate(
1103 net::URLRequest* request,
1104 net::X509Certificate* cert,
1105 int render_process_id,
1106 int render_view_id) {
1107 // The handler will run the UI and delete itself when it's finished.
1108 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1109}
1110
[email protected]a93670ab2012-02-24 03:46:391111void ChromeContentBrowserClient::RequestMediaAccessPermission(
1112 const content::MediaStreamRequest* request,
1113 const content::MediaResponseCallback& callback) {
1114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1115
[email protected]117b6b42012-02-29 09:11:081116 WebContents* contents = tab_util::GetWebContentsByID(
1117 request->render_process_id, request->render_view_id);
1118 if (!contents) {
1119 // Abort, if the tab was closed after the request was made but before we
1120 // got to this point.
1121 callback.Run(content::MediaStreamDevices());
1122 return;
1123 }
1124
1125 TabContentsWrapper* tab =
1126 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1127 DCHECK(tab);
1128
1129 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1130 InfoBarDelegate* old_infobar = NULL;
1131 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1132 old_infobar =
[email protected]51d1fc62012-04-28 03:47:531133 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfoBarDelegate();
[email protected]117b6b42012-02-29 09:11:081134 }
1135
[email protected]117b6b42012-02-29 09:11:081136 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1137 request,
1138 callback);
1139 if (old_infobar)
1140 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1141 else
1142 infobar_helper->AddInfoBar(infobar);
[email protected]a93670ab2012-02-24 03:46:391143}
1144
[email protected]dc73a7b2012-03-25 15:27:181145content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1146 return MediaInternals::GetInstance();
1147}
1148
[email protected]941623e2011-06-07 23:06:041149void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1150 const GURL& source_origin,
1151 int callback_context,
1152 int render_process_id,
1153 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111154#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041155 RenderViewHost* rvh = RenderViewHost::FromID(
1156 render_process_id, render_view_id);
1157 if (!rvh) {
1158 NOTREACHED();
1159 return;
1160 }
1161
[email protected]9f76c1e2012-03-05 15:15:581162 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301163 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041164 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371165 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041166 service->RequestPermission(
1167 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131168 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111169#else
1170 NOTIMPLEMENTED();
1171#endif
[email protected]941623e2011-06-07 23:06:041172}
1173
1174WebKit::WebNotificationPresenter::Permission
1175 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021176 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201177 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021178 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111179#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201181 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021182 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1183 source_origin, render_process_id,
1184 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041185 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041186
1187 // Fall back to the regular notification preferences, which works on an
1188 // origin basis.
1189 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371190 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041191 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111192#else
1193 return WebKit::WebNotificationPresenter::PermissionAllowed;
1194#endif
[email protected]941623e2011-06-07 23:06:041195}
1196
1197void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171198 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041199 int render_process_id,
1200 int render_view_id,
1201 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111202#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041203 RenderViewHost* rvh = RenderViewHost::FromID(
1204 render_process_id, render_view_id);
1205 if (!rvh) {
1206 NOTREACHED();
1207 return;
1208 }
1209
[email protected]9f76c1e2012-03-05 15:15:581210 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301211 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041212 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371213 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041214 service->ShowDesktopNotification(
1215 params, render_process_id, render_view_id,
1216 worker ? DesktopNotificationService::WorkerNotification :
1217 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111218#else
1219 NOTIMPLEMENTED();
1220#endif
[email protected]941623e2011-06-07 23:06:041221}
1222
1223void ChromeContentBrowserClient::CancelDesktopNotification(
1224 int render_process_id,
1225 int render_view_id,
1226 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111227#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041228 RenderViewHost* rvh = RenderViewHost::FromID(
1229 render_process_id, render_view_id);
1230 if (!rvh) {
1231 NOTREACHED();
1232 return;
1233 }
1234
[email protected]9f76c1e2012-03-05 15:15:581235 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301236 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041237 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371238 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041239 service->CancelDesktopNotification(
1240 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111241#else
1242 NOTIMPLEMENTED();
1243#endif
[email protected]941623e2011-06-07 23:06:041244}
1245
[email protected]9f3fba52011-06-08 20:37:191246bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351247 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021248 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191249 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201250 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011251 int render_process_id,
1252 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011254
1255 *no_javascript_access = false;
1256
[email protected]9f3fba52011-06-08 20:37:191257 // If the opener is trying to create a background window but doesn't have
1258 // the appropriate permission, fail the attempt.
1259 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201260 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531261 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1262
[email protected]03b6d552012-03-29 04:03:011263 if (!map->SecurityOriginHasAPIPermission(
1264 source_origin,
1265 render_process_id,
1266 ExtensionAPIPermission::kBackground)) {
1267 return false;
1268 }
1269
[email protected]7b54ca02012-03-02 18:06:531270 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1271 // return a recently installed Extension even if this CanCreateWindow call
1272 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011273 // because the permission check above would have caused an early return
1274 // already. We must use the full URL to find hosted apps, though, and not
1275 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531276 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351277 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531278 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011279 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191280 }
1281 return true;
1282}
1283
1284std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201285 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1287 // Check if it's an extension-created worker, in which case we want to use
1288 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201289 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191290 const Extension* extension =
1291 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1292 return extension ? extension->name() : std::string();
1293}
1294
[email protected]99907362012-01-11 05:41:401295void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1296 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171297}
1298
[email protected]c52b2892012-03-07 11:01:021299content::SpeechRecognitionManagerDelegate*
1300 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321301#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021302 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321303#else
1304 return NULL;
1305#endif
[email protected]66cfec62012-02-24 17:57:511306}
1307
[email protected]3cb054e62011-06-13 05:21:171308ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1309 return g_browser_process->clipboard();
1310}
1311
[email protected]ae6e9912011-07-27 01:18:281312net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1313 return g_browser_process->net_log();
1314}
1315
[email protected]32538d92011-08-25 00:09:231316AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1317 return new ChromeAccessTokenStore();
1318}
1319
[email protected]dbae6b02011-06-29 23:51:411320bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1321 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1322 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1323}
1324
[email protected]64d69de42012-02-06 00:19:541325void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321326 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061327 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581328 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061329 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061330
[email protected]64d69de42012-02-06 00:19:541331 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061332 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541333 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061334 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541335 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061336 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541337 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061338 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541339 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061340 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541341 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061342 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1343
1344 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541345 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061346 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541347 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061348 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541349 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061350 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541351 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061352 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541353 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061354 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541355 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061356
[email protected]64d69de42012-02-06 00:19:541357 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061358 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541359 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061360 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541361 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061362 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541363 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061364 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1365
[email protected]64d69de42012-02-06 00:19:541366 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061367
[email protected]64d69de42012-02-06 00:19:541368 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061369 prefs->GetBoolean(
1370 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541371 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061372 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541373 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061374 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1375 const DictionaryValue* inspector_settings =
1376 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1377 if (inspector_settings) {
1378 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1379 iter != inspector_settings->end_keys(); ++iter) {
1380 std::string value;
1381 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541382 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061383 std::make_pair(*iter, value));
1384 }
1385 }
[email protected]64d69de42012-02-06 00:19:541386 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061387
[email protected]64d69de42012-02-06 00:19:541388 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1389 web_prefs->javascript_enabled = false;
1390 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1391 web_prefs->web_security_enabled = false;
1392 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1393 web_prefs->plugins_enabled = false;
1394 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1395 web_prefs->java_enabled = false;
1396 web_prefs->loads_images_automatically =
1397 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061398
[email protected]64d69de42012-02-06 00:19:541399 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1400 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061401
[email protected]64d69de42012-02-06 00:19:541402 web_prefs->memory_info_enabled =
1403 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1404 web_prefs->allow_displaying_insecure_content =
1405 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1406 web_prefs->allow_running_insecure_content =
1407 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081408 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061409
[email protected]64d69de42012-02-06 00:19:541410 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151411 UserStyleSheetWatcher* user_style_sheet_watcher =
1412 UserStyleSheetWatcherFactory::GetForProfile(profile);
1413 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541414 web_prefs->user_style_sheet_enabled = true;
1415 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151416 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541417 } else {
1418 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061419 }
1420
[email protected]b7e44ff2012-02-16 03:37:341421 web_prefs->asynchronous_spell_checking_enabled =
[email protected]8e466dd2012-05-04 19:16:051422 CommandLine::ForCurrentProcess()->
1423 HasSwitch(switches::kEnableAsynchronousSpellChecking);
[email protected]b7e44ff2012-02-16 03:37:341424 web_prefs->unified_textchecker_enabled =
1425 web_prefs->asynchronous_spell_checking_enabled ||
1426 CommandLine::ForCurrentProcess()->
1427 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571428
[email protected]64d69de42012-02-06 00:19:541429 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061430 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541431 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061432 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541433 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061434 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1435
1436 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541437 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061438 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541439 web_prefs->default_encoding);
1440 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061441 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541442 web_prefs->default_encoding =
1443 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061444 }
[email protected]64d69de42012-02-06 00:19:541445 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061446
1447 ExtensionService* service = profile->GetExtensionService();
1448 if (service) {
1449 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581450 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061451 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581452 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061453 }
1454
[email protected]9f76c1e2012-03-05 15:15:581455 if (rvh->GetDelegate()->GetRenderViewType() ==
1456 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541457 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581458 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061459 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1460 // Disable all kinds of acceleration for background pages.
1461 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541462 web_prefs->force_compositing_mode = false;
1463 web_prefs->accelerated_compositing_enabled = false;
1464 web_prefs->accelerated_2d_canvas_enabled = false;
1465 web_prefs->accelerated_video_enabled = false;
1466 web_prefs->accelerated_painting_enabled = false;
1467 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061468 }
[email protected]2e21fe292012-03-02 22:52:321469
1470#if defined(FILE_MANAGER_EXTENSION)
1471 // Override the default of suppressing HW compositing for WebUI pages for the
1472 // file manager, which is implemented using WebUI but wants HW acceleration
1473 // for video decode & render.
1474 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1475 web_prefs->accelerated_compositing_enabled = true;
1476 web_prefs->accelerated_2d_canvas_enabled = true;
1477 }
1478#endif
[email protected]181a95ee2011-07-12 19:26:361479}
1480
1481void ChromeContentBrowserClient::UpdateInspectorSetting(
1482 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061483 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581484 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061485 DictionaryPrefUpdate update(
1486 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1487 prefs::kWebKitInspectorSettings);
1488 DictionaryValue* inspector_settings = update.Get();
1489 inspector_settings->SetWithoutPathExpansion(key,
1490 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361491}
1492
1493void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061494 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581495 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061496 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1497 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361498}
1499
[email protected]b8148ac2011-07-13 22:03:251500void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1501 BrowserURLHandler* handler) {
1502 // Add the default URL handlers.
1503 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1504 BrowserURLHandler::null_handler());
1505 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1506 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1507
[email protected]b3adbd02011-11-30 22:23:271508 // about: handler. Must come before chrome: handler, since it will
1509 // rewrite about: urls to chrome: URLs and then expect chrome: to
1510 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251511 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1512 BrowserURLHandler::null_handler());
1513 // chrome: & friends.
1514 handler->AddHandlerPair(&HandleWebUI,
1515 BrowserURLHandler::null_handler());
1516}
1517
1518void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371519 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581520 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251521 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1522 BrowsingDataRemover::EVERYTHING,
1523 base::Time());
1524 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1525 // BrowsingDataRemover takes care of deleting itself when done.
1526}
1527
1528void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371529 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581530 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251531 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1532 BrowsingDataRemover::EVERYTHING,
1533 base::Time());
[email protected]dceaa912011-09-06 17:17:231534 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251535 remover->Remove(remove_mask);
1536 // BrowsingDataRemover takes care of deleting itself when done.
1537}
1538
[email protected]e1d16eb92011-08-18 23:19:321539FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1540 return download_util::GetDefaultDownloadDirectory();
1541}
1542
[email protected]c9b6eb62011-10-18 20:49:391543std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1544 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1545}
1546
[email protected]a658d452012-03-02 12:45:291547bool ChromeContentBrowserClient::AllowSocketAPI(
1548 content::BrowserContext* browser_context, const GURL& url) {
1549 if (!url.is_valid())
1550 return false;
1551
1552 std::string host = url.host();
1553 if (allowed_socket_origins_.count(host))
1554 return true;
1555
[email protected]9a5940d2012-04-27 19:16:231556 Profile* profile = Profile::FromBrowserContext(browser_context);
1557 const Extension* extension = NULL;
1558 if (profile && profile->GetExtensionService()) {
1559 extension = profile->GetExtensionService()->extensions()->
1560 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1561 }
1562
[email protected]f237c0f2012-03-10 07:49:101563 // Need to check this now and not on construction because otherwise it won't
1564 // work with browser_tests.
1565 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1566 std::string allowed_list =
1567 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231568 if (allowed_list == "*") {
1569 // The wildcard allows socket API only for packaged and platform apps.
1570 return extension &&
1571 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1572 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1573 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101574 StringTokenizer t(allowed_list, ",");
1575 while (t.GetNext()) {
1576 if (t.token() == host)
1577 return true;
1578 }
1579 }
1580
[email protected]a658d452012-03-02 12:45:291581 if (!extension)
1582 return false;
1583
1584 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1585 return true;
1586
1587 return false;
[email protected]e461da2f2012-02-16 19:06:401588}
1589
[email protected]e60c0232011-11-11 19:56:351590#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301591int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521592 const CommandLine& command_line) {
1593 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071594 ExtensionCrashHandlerHostLinux* crash_handler =
1595 ExtensionCrashHandlerHostLinux::GetInstance();
1596 return crash_handler->GetDeathSignalSocket();
1597 }
1598
[email protected]718eab62011-10-05 21:16:521599 std::string process_type =
1600 command_line.GetSwitchValueASCII(switches::kProcessType);
1601
1602 if (process_type == switches::kRendererProcess)
1603 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1604
[email protected]b80f68432011-05-02 17:22:301605 if (process_type == switches::kPluginProcess)
1606 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1607
1608 if (process_type == switches::kPpapiPluginProcess)
1609 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1610
1611 if (process_type == switches::kGpuProcess)
1612 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1613
1614 return -1;
1615}
[email protected]e60c0232011-11-11 19:56:351616#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301617
[email protected]4a65826d2011-08-25 16:04:011618#if defined(OS_WIN)
1619const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1620 return chrome::kBrowserResourcesDll;
1621}
1622#endif
1623
[email protected]37a72af2011-06-13 05:42:011624#if defined(USE_NSS)
1625crypto::CryptoModuleBlockingPasswordDelegate*
1626 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1627 const GURL& url) {
1628 return browser::NewCryptoModuleBlockingDialogDelegate(
1629 browser::kCryptoModulePasswordKeygen, url.host());
1630}
1631#endif
1632
[email protected]d977f9c2011-03-14 16:10:261633} // namespace chrome