blob: 204d69f28a16ddd593d01c27338a39dcf0b2d06c [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2318#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1219#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0320#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4121#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5622#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0523#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4524#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3225#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0826#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3227#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1628#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0629#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0430#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1031#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0834#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2535#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0636#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2337#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1238#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0839#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1840#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2841#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0442#include "chrome/browser/notifications/desktop_notification_service.h"
43#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4344#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4245#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0647#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4148#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5049#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0750#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4151#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1452#include "chrome/browser/printing/printing_message_filter.h"
53#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3254#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0655#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1456#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3357#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4258#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1459#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0260#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4661#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4562#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0363#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4564#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
65#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0866#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4567#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5068#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]299d7f12012-05-23 05:31:1569#include "chrome/browser/view_type_utils.h"
[email protected]f3986f82012-01-03 20:00:0670#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1571#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3072#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0173#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3074#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0475#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3876#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4477#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3478#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1279#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3880#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0981#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4382#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3083#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3184#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5985#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3086#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3387#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0588#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3389#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1990#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1091#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4392#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3993#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3494#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4095#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0696#include "net/cookies/cookie_monster.h"
97#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3998#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0899#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36100#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04101#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26102
[email protected]b48c9182011-10-26 18:03:30103#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38104#include "chrome/browser/chrome_browser_main_win.h"
105#elif defined(OS_MACOSX)
106#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56107#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57108#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30109#elif defined(OS_CHROMEOS)
110#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49111#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26112#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30113#include "chrome/browser/chrome_browser_main_linux.h"
114#elif defined(OS_POSIX)
115#include "chrome/browser/chrome_browser_main_posix.h"
116#endif
117
[email protected]c0d7f792012-04-18 19:16:00118#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13119#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]61e69822012-03-14 22:08:57120#endif
121
[email protected]a13283cc2012-04-05 00:21:22122#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31123#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38124#endif
125
[email protected]c7480942011-11-08 19:18:27126#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31127#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27128#endif
129
130#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31131#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
132#endif
133
[email protected]dc04be7c2012-03-15 23:57:49134#if defined(USE_ASH)
135#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
136#endif
137
[email protected]6653c192012-04-10 22:52:44138#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30139#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44140#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43141#endif
[email protected]b80f68432011-05-02 17:22:30142
[email protected]38b098f2012-03-14 21:11:57143#if defined(TOOLKIT_GTK)
144#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32145#endif
[email protected]37a72af2011-06-13 05:42:01146#if defined(USE_NSS)
147#include "chrome/browser/ui/crypto_module_password_dialog.h"
148#endif
149
[email protected]c8c77182011-12-21 15:04:47150using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39151using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31152using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59153using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00154using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11155using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33156using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13157using content::WebContents;
[email protected]1c321ee2012-05-21 03:02:34158using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25159using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39160
[email protected]c5dbef02011-05-13 05:06:09161namespace {
162
[email protected]e461da2f2012-02-16 19:06:40163const char* kPredefinedAllowedSocketOrigins[] = {
164 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18165 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45166 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
167 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
168 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
169 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35170 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
171 "cbkkbcmdlboombapidmoeolnmdacpkch" // see crbug.com/129089
[email protected]e461da2f2012-02-16 19:06:40172};
173
[email protected]b8148ac2011-07-13 22:03:25174// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42175bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50176 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
177 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25178 return false;
179
[email protected]fe69558d2012-03-12 11:34:49180#if defined(OS_CHROMEOS)
181 // Special case : in ChromeOS in Guest mode bookmarks and history are
182 // disabled for security reasons. New tab page explains the reasons, so
183 // we redirect user to new tab page.
184 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
185 if (url->SchemeIs(chrome::kChromeUIScheme) &&
186 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
187 url->DomainIs(chrome::kChromeUIHistoryHost))) {
188 // Rewrite with new tab URL
189 *url = GURL(chrome::kChromeUINewTabURL);
190 }
191 }
192#endif
193
[email protected]b8148ac2011-07-13 22:03:25194 // Special case the new tab page. In older versions of Chrome, the new tab
195 // page was hosted at chrome-internal:<blah>. This might be in people's saved
196 // sessions or bookmarks, so we say any URL with that scheme triggers the new
197 // tab page.
198 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
199 // Rewrite it with the proper new tab URL.
200 *url = GURL(chrome::kChromeUINewTabURL);
201 }
202
203 return true;
204}
205
[email protected]8d3132f62011-10-12 07:13:42206// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
207// below. Extension, and isolated apps require different privileges to be
208// granted to their RenderProcessHosts. This classification allows us to make
209// sure URLs are served by hosts with the right set of privileges.
210enum RenderProcessHostPrivilege {
211 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45212 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42213 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45214 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42215};
216
217RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
218 const GURL& url,
219 ExtensionService* service) {
220 // Default to a normal renderer cause it is lower privileged. This should only
221 // occur if the URL on a site instance is either malformed, or uninitialized.
222 // If it is malformed, then there is no need for better privileges anyways.
223 // If it is uninitialized, but eventually settles on being an a scheme other
224 // than normal webrenderer, the navigation logic will correct us out of band
225 // anyways.
226 if (!url.is_valid())
227 return PRIV_NORMAL;
228
229 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44230 const Extension* extension =
231 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45232 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42233 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45234 if (extension && extension->is_hosted_app())
235 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42236
237 return PRIV_EXTENSION;
238 }
239
240 return PRIV_NORMAL;
241}
242
243RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30244 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46245 extensions::ProcessMap* process_map,
246 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46247 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30248 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46249 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21250 return PRIV_NORMAL;
251
[email protected]6f371442011-11-09 06:45:46252 for (std::set<std::string>::iterator iter = extension_ids.begin();
253 iter != extension_ids.end(); ++iter) {
254 const Extension* extension = service->GetExtensionById(*iter, false);
255 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42256 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45257 if (extension && extension->is_hosted_app())
258 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42259 }
260
[email protected]676f6ab2011-10-19 20:23:21261 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42262}
263
[email protected]eec0b33c2011-12-05 22:09:45264bool IsIsolatedAppInProcess(const GURL& site_url,
265 content::RenderProcessHost* process_host,
266 extensions::ProcessMap* process_map,
267 ExtensionService* service) {
268 std::set<std::string> extension_ids =
269 process_map->GetExtensionsInProcess(process_host->GetID());
270 if (extension_ids.empty())
271 return false;
272
273 for (std::set<std::string>::iterator iter = extension_ids.begin();
274 iter != extension_ids.end(); ++iter) {
275 const Extension* extension = service->GetExtensionById(*iter, false);
276 if (extension &&
277 extension->is_storage_isolated() &&
278 extension->url() == site_url)
279 return true;
280 }
281
282 return false;
283}
284
[email protected]6786bf402011-12-03 15:19:45285bool CertMatchesFilter(const net::X509Certificate& cert,
286 const base::DictionaryValue& filter) {
287 // TODO(markusheintz): This is the minimal required filter implementation.
288 // Implement a better matcher.
289
290 // An empty filter matches any client certificate since no requirements are
291 // specified at all.
292 if (filter.empty())
293 return true;
294
295 std::string common_name;
296 if (filter.GetString("ISSUER.CN", &common_name) &&
297 (cert.issuer().common_name == common_name)) {
298 return true;
299 }
300 return false;
301}
302
[email protected]f3986f82012-01-03 20:00:06303// Fills |map| with the per-script font prefs under path |map_name|.
304void FillFontFamilyMap(const PrefService* prefs,
305 const char* map_name,
306 WebPreferences::ScriptFontFamilyMap* map) {
307 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
308 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
309 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
310 std::string font_family = prefs->GetString(pref_name.c_str());
311 if (!font_family.empty())
[email protected]966d1e12012-05-18 07:20:32312 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06313 }
314}
315
[email protected]9dbfff12011-07-01 19:37:07316} // namespace
[email protected]c5dbef02011-05-13 05:06:09317
[email protected]d977f9c2011-03-14 16:10:26318namespace chrome {
319
[email protected]e461da2f2012-02-16 19:06:40320ChromeContentBrowserClient::ChromeContentBrowserClient() {
321 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
322 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40323}
324
325ChromeContentBrowserClient::~ChromeContentBrowserClient() {
326}
327
[email protected]50462bf02011-11-21 19:13:31328content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
329 const content::MainFunctionParams& parameters) {
330 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30331 // Construct the Main browser parts based on the OS type.
332#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31333 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04334#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31335 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30336#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31337 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26338#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31339 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14340#elif defined(OS_ANDROID)
341 // Do nothing for Android.
342 // TODO(klobag): Android initialization should use the
343 // *BrowserMainParts class-hierarchy for setting up custom initialization.
344 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30345#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31346 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04347#else
[email protected]b48c9182011-10-26 18:03:30348 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31349 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30350#endif
351
[email protected]c7480942011-11-08 19:18:27352 // Construct additional browser parts. Stages are called in the order in
353 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22354#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31355 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04356#endif
[email protected]c7480942011-11-08 19:18:27357
358#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31359 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27360#endif
361
[email protected]dc04be7c2012-03-15 23:57:49362#if defined(USE_ASH)
363 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
364#endif
365
[email protected]e050ef142012-03-21 01:04:24366#if defined(USE_AURA)
367 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
368#endif
369
[email protected]50462bf02011-11-21 19:13:31370 return main_parts;
[email protected]f967b722011-09-07 00:58:04371}
372
[email protected]38b098f2012-03-14 21:11:57373content::WebContentsView*
374 ChromeContentBrowserClient::OverrideCreateWebContentsView(
375 WebContents* web_contents) {
[email protected]38b098f2012-03-14 21:11:57376 return NULL;
377}
378
379content::WebContentsViewDelegate*
380 ChromeContentBrowserClient::GetWebContentsViewDelegate(
381 content::WebContents* web_contents) {
[email protected]c0d7f792012-04-18 19:16:00382#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13383 return new ChromeWebContentsViewDelegateViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57384#elif defined(TOOLKIT_GTK)
385 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32386#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57387 return
388 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
389 web_contents);
[email protected]74313b42011-08-24 16:51:32390#else
[email protected]38b098f2012-03-14 21:11:57391 return NULL;
[email protected]74313b42011-08-24 16:51:32392#endif
393}
394
[email protected]f364d1392011-04-08 21:03:10395void ChromeContentBrowserClient::RenderViewHostCreated(
396 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46397
[email protected]9f76c1e2012-03-05 15:15:58398 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46399 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02400 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46401
402 new ChromeRenderViewHostObserver(render_view_host,
403 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10404 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26405}
406
[email protected]f3b1a082011-11-18 00:34:30407void ChromeContentBrowserClient::RenderProcessHostCreated(
408 content::RenderProcessHost* host) {
409 int id = host->GetID();
410 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
411 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02412 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30413 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03414#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30415 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03416#endif
[email protected]f3b1a082011-11-18 00:34:30417 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02418 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30419 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56420#if defined(OS_MACOSX)
421 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
422#endif
[email protected]f3b1a082011-11-18 00:34:30423 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03424 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07425 host->GetChannel()->AddFilter(
426 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38427
[email protected]2ccf45c2011-08-19 23:35:50428 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
429 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07430
431 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56432
433 RendererContentSettingRules rules;
434 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
435 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14436}
437
[email protected]e0ada9c2012-03-20 03:54:43438void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
439 content::BrowserChildProcessHost* host) {
440 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
441}
442
[email protected]863f70a2012-01-27 02:05:50443content::WebUIControllerFactory*
444 ChromeContentBrowserClient::GetWebUIControllerFactory() {
445 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56446}
447
[email protected]3d7474ff2011-07-27 17:47:37448GURL ChromeContentBrowserClient::GetEffectiveURL(
449 content::BrowserContext* browser_context, const GURL& url) {
450 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08451 // Get the effective URL for the given actual URL. If the URL is part of an
452 // installed app, the effective URL is an extension URL with the ID of that
453 // extension as the host. This has the effect of grouping apps together in
454 // a common SiteInstance.
455 if (!profile || !profile->GetExtensionService())
456 return url;
457
[email protected]615d88f2011-12-13 01:47:44458 const Extension* extension = profile->GetExtensionService()->extensions()->
459 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08460 if (!extension)
461 return url;
462
[email protected]15877ca2011-11-18 22:40:52463 // Bookmark apps do not use the hosted app process model, and should be
464 // treated as normal URLs.
465 if (extension->from_bookmark())
466 return url;
467
[email protected]36fb2c7c2011-04-04 15:49:08468 // If the URL is part of an extension's web extent, convert it to an
469 // extension URL.
470 return extension->GetResourceURL(url.path());
471}
472
[email protected]056ad2a2011-07-12 02:13:55473bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37474 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55475 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52476 // Because we expect to use the effective URL, URLs for hosted apps (apart
477 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55478 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
479 return false;
480
[email protected]3d7474ff2011-07-27 17:47:37481 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55482 if (!profile || !profile->GetExtensionService())
483 return false;
484
[email protected]615d88f2011-12-13 01:47:44485 const Extension* extension = profile->GetExtensionService()->extensions()->
486 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55487 if (!extension)
488 return false;
489
490 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53491 // permission, or that does not allow JavaScript access to the background
492 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55493 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53494 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
495 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
496 !extension->allow_background_js_access()) {
497 return false;
498 }
499 }
[email protected]056ad2a2011-07-12 02:13:55500
[email protected]7b54ca02012-03-02 18:06:53501 // Hosted apps that have script access to their background page must use
502 // process per site, since all instances can make synchronous calls to the
503 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55504 return true;
505}
506
[email protected]46fb9442011-12-09 17:57:47507bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
508 return ProfileIOData::IsHandledURL(url);
509}
510
[email protected]2a5221b2011-09-27 23:07:31511bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30512 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31513 const GURL& site_url) {
514 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30515 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42516 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46517 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31518
[email protected]ffa97602011-11-17 17:55:52519 // Don't allow the Task Manager to share a process with anything else.
520 // Otherwise it can affect the renderers it is observing.
521 // Note: we could create another RenderProcessHostPrivilege bucket for
522 // this to allow multiple chrome://tasks instances to share, but that's
523 // a very unlikely case without serious consequences.
524 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
525 return false;
526
[email protected]8d3132f62011-10-12 07:13:42527 // These may be NULL during tests. In that case, just assume any site can
528 // share any host.
[email protected]6f371442011-11-09 06:45:46529 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31530 return true;
531
[email protected]a8c269a2011-10-25 20:17:22532 // Experimental:
533 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
534 // to share a renderer process. (We could allow pages from the same site or
535 // extensions of the same type to share, if we knew what the given process
536 // was dedicated to. Allowing no sharing is simpler for now.) This may
537 // cause resource exhaustion issues if too many sites are open at once.
538 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
539 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
540 return false;
541
[email protected]eec0b33c2011-12-05 22:09:45542 // An isolated app is only allowed to share with the exact same app in order
543 // to provide complete renderer process isolation. This also works around
544 // issue http://crbug.com/85588, where different isolated apps in the same
545 // process would end up using the first app's storage contexts.
546 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42547 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45548 if (privilege_required == PRIV_ISOLATED)
549 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
550
551 // Otherwise, just make sure the process privilege matches the privilege
552 // required by the site.
553 return GetProcessPrivilege(process_host, process_map, service) ==
554 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31555}
556
[email protected]76411f412012-02-22 18:56:06557// This function is trying to limit the amount of processes used by extensions
558// with background pages. It uses a globally set percentage of processes to
559// run such extensions and if the limit is exceeded, it returns true, to
560// indicate to the content module to group extensions together.
561bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
562 content::BrowserContext* browser_context, const GURL& url) {
563 // It has to be a valid URL for us to check for an extension.
564 if (!url.is_valid())
565 return false;
566
567 Profile* profile = Profile::FromBrowserContext(browser_context);
568 ExtensionService* service = profile->GetExtensionService();
569 if (!service)
570 return false;
571
572 // We have to have a valid extension with background page to proceed.
573 const Extension* extension =
574 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
575 if (!extension)
576 return false;
577 if (!extension->has_background_page())
578 return false;
579
580 std::set<int> process_ids;
581 size_t max_process_count =
582 content::RenderProcessHost::GetMaxRendererProcessCount();
583
584 // Go through all profiles to ensure we have total count of extension
585 // processes containing background pages, otherwise one profile can
586 // starve the other.
587 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
588 GetLoadedProfiles();
589 for (size_t i = 0; i < profiles.size(); ++i) {
590 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
[email protected]d1fe1352012-04-26 00:47:32591 for (ExtensionProcessManager::const_iterator iter =
592 epm->background_hosts().begin();
593 iter != epm->background_hosts().end(); ++iter) {
[email protected]76411f412012-02-22 18:56:06594 ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32595 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06596 }
597 }
598
599 if (process_ids.size() >
600 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
601 return true;
602 }
603
604 return false;
605}
606
[email protected]6f371442011-11-09 06:45:46607void ChromeContentBrowserClient::SiteInstanceGotProcess(
608 SiteInstance* site_instance) {
609 CHECK(site_instance->HasProcess());
610
611 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02612 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46613 ExtensionService* service = profile->GetExtensionService();
614 if (!service)
615 return;
616
617 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44618 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33619 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46620 if (!extension)
621 return;
622
[email protected]6bc04fd82011-12-04 02:29:35623 service->process_map()->Insert(extension->id(),
624 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33625 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46626 BrowserThread::PostTask(
627 BrowserThread::IO, FROM_HERE,
628 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24629 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46630 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35631 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33632 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46633}
634
635void ChromeContentBrowserClient::SiteInstanceDeleting(
636 SiteInstance* site_instance) {
637 if (!site_instance->HasProcess())
638 return;
639
640 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02641 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46642 ExtensionService* service = profile->GetExtensionService();
643 if (!service)
644 return;
645
646 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44647 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33648 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46649 if (!extension)
650 return;
651
[email protected]6bc04fd82011-12-04 02:29:35652 service->process_map()->Remove(extension->id(),
653 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33654 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46655 BrowserThread::PostTask(
656 BrowserThread::IO, FROM_HERE,
657 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24658 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46659 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35660 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33661 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46662}
663
[email protected]e3daf3c2011-10-05 21:17:08664bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
665 const GURL& current_url,
666 const GURL& new_url) {
667 if (current_url.is_empty()) {
668 // Always choose a new process when navigating to extension URLs. The
669 // process grouping logic will combine all of a given extension's pages
670 // into the same process.
671 if (new_url.SchemeIs(chrome::kExtensionScheme))
672 return true;
673
674 return false;
675 }
676
677 // Also, we must switch if one is an extension and the other is not the exact
678 // same extension.
679 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
680 new_url.SchemeIs(chrome::kExtensionScheme)) {
681 if (current_url.GetOrigin() != new_url.GetOrigin())
682 return true;
683 }
684
685 return false;
686}
687
[email protected]395045c2012-05-22 15:04:38688bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
689 content::ResourceContext* resource_context, const GURL& current_url,
690 const GURL& new_url) {
691 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
692 return extensions::CrossesExtensionProcessBoundary(
693 io_data->GetExtensionInfoMap()->extensions(),
694 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url));
695}
696
[email protected]763ec4ca2011-04-29 15:48:12697std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
698 const std::string& alias_name) {
699 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
700}
701
[email protected]b80f68432011-05-02 17:22:30702void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
703 CommandLine* command_line, int child_process_id) {
704#if defined(USE_LINUX_BREAKPAD)
705 if (IsCrashReporterEnabled()) {
706 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
707 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
708 }
709#elif defined(OS_MACOSX)
710 if (IsCrashReporterEnabled()) {
711 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
712 child_process_logging::GetClientId());
713 }
714#endif // OS_MACOSX
715
[email protected]f1933792011-06-14 00:49:34716 if (logging::DialogsAreSuppressed())
717 command_line->AppendSwitch(switches::kNoErrorDialogs);
718
[email protected]b80f68432011-05-02 17:22:30719 std::string process_type =
720 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17721 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52722 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30723 FilePath user_data_dir =
724 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
725 if (!user_data_dir.empty())
726 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
727#if defined(OS_CHROMEOS)
728 const std::string& login_profile =
729 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
730 if (!login_profile.empty())
731 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
732#endif
733
[email protected]f3b1a082011-11-18 00:34:30734 content::RenderProcessHost* process =
735 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37736 if (process) {
737 Profile* profile = Profile::FromBrowserContext(
738 process->GetBrowserContext());
739 extensions::ProcessMap* process_map =
740 profile->GetExtensionService()->process_map();
741 if (process_map && process_map->Contains(process->GetID()))
742 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30743
[email protected]a8d851f82011-12-21 00:32:37744 PrefService* prefs = profile->GetPrefs();
745 // Currently this pref is only registered if applied via a policy.
746 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
747 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
748 // Turn this policy into a command line switch.
749 command_line->AppendSwitch(switches::kDisable3DAPIs);
750 }
[email protected]718eab62011-10-05 21:16:52751
[email protected]a8d851f82011-12-21 00:32:37752 // Disable client-side phishing detection in the renderer if it is
753 // disabled in the Profile preferences or the browser process.
754 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
755 !g_browser_process->safe_browsing_detection_service()) {
756 command_line->AppendSwitch(
757 switches::kDisableClientSidePhishingDetection);
758 }
[email protected]8c40da62011-07-13 22:58:46759 }
[email protected]47c7ec82012-01-18 03:29:21760 {
761 PrefService* local_state = g_browser_process->local_state();
762 if (local_state &&
763 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
764 command_line->AppendSwitch(switches::kRendererPrintPreview);
765 }
766 }
[email protected]4287a3d2011-06-13 23:56:51767
[email protected]47c7ec82012-01-18 03:29:21768 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51769 static const char* const kSwitchNames[] = {
770 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48771 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51772 switches::kAllowScriptingGallery,
773 switches::kAppsCheckoutURL,
774 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31775 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51776 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50777 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53778 switches::kDisableExtensionsResourceWhitelist,
[email protected]4287a3d2011-06-13 23:56:51779 switches::kDumpHistogramsOnExit,
[email protected]8e466dd2012-05-04 19:16:05780 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21781 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13782 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51783 switches::kEnableCrxlessWebApps,
784 switches::kEnableExperimentalExtensionApis,
785 switches::kEnableInBrowserThumbnailing,
786 switches::kEnableIPCFuzzing,
787 switches::kEnableNaCl,
[email protected]9c8b116b2012-05-10 23:07:05788 switches::kEnableNaClIPCProxy,
[email protected]bcbe7652012-02-22 00:08:48789 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53790 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51791 switches::kEnableWatchdog,
792 switches::kExperimentalSpellcheckerFeatures,
793 switches::kMemoryProfiling,
794 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37795 switches::kNoJsRandomness,
[email protected]2a6bb0b12011-10-05 19:18:04796 switches::kNoRunningInsecureContent,
[email protected]f45c5f32012-04-18 19:26:37797 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51798 switches::kPpapiFlashArgs,
799 switches::kPpapiFlashInProcess,
800 switches::kPpapiFlashPath,
801 switches::kPpapiFlashVersion,
802 switches::kProfilingAtStart,
803 switches::kProfilingFile,
804 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37805 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51806 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38807 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51808 };
809
810 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
811 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17812 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38813 static const char* const kSwitchNames[] = {
814 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37815 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38816 switches::kWhitelistedExtensionID,
817 };
818
819 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
820 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51821 } else if (process_type == switches::kPluginProcess) {
822 static const char* const kSwitchNames[] = {
823 #if defined(OS_CHROMEOS)
824 switches::kLoginProfile,
825 #endif
826 switches::kMemoryProfiling,
827 switches::kSilentDumpOnDCHECK,
828 switches::kUserDataDir,
829 };
830
831 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
832 arraysize(kSwitchNames));
833 } else if (process_type == switches::kZygoteProcess) {
834 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51835 switches::kUserDataDir, // Make logs go to the right file.
836 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50837 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13838 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51839 switches::kPpapiFlashInProcess,
840 switches::kPpapiFlashPath,
841 switches::kPpapiFlashVersion,
842 };
843
844 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
845 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11846 } else if (process_type == switches::kGpuProcess) {
847 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
848 // because GPU is expected to be unreliable.
849 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
850 !command_line->HasSwitch(switches::kDisableBreakpad))
851 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30852 }
[email protected]6f08af82011-09-15 01:19:03853
854 // The command line switch kEnableBenchmarking needs to be specified along
855 // with the kEnableStatsTable switch to ensure that the stats table global
856 // is initialized correctly.
857 if (command_line->HasSwitch(switches::kEnableBenchmarking))
858 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30859}
860
861std::string ChromeContentBrowserClient::GetApplicationLocale() {
862 return g_browser_process->GetApplicationLocale();
863}
864
[email protected]597a867b2011-11-18 18:31:20865std::string ChromeContentBrowserClient::GetAcceptLangs(
866 content::BrowserContext* context) {
867 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37868 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08869}
870
[email protected]ac55e292011-06-24 05:16:08871SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22872 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08873 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
874}
875
[email protected]a2176792011-05-08 19:30:49876bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09877 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19878 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20879 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32880 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20881 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05882 return io_data->GetCookieSettings()->
883 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49884}
885
[email protected]ed24fad2011-05-10 22:44:01886bool ChromeContentBrowserClient::AllowGetCookie(
887 const GURL& url,
888 const GURL& first_party,
889 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20890 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01891 int render_process_id,
892 int render_view_id) {
893 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20894 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05895 bool allow = io_data->GetCookieSettings()->
896 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01897
[email protected]8093a542011-05-13 07:29:32898 BrowserThread::PostTask(
899 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03900 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43901 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01902 return allow;
903}
904
905bool ChromeContentBrowserClient::AllowSetCookie(
906 const GURL& url,
907 const GURL& first_party,
908 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20909 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01910 int render_process_id,
911 int render_view_id,
912 net::CookieOptions* options) {
913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20914 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05915 CookieSettings* cookie_settings = io_data->GetCookieSettings();
916 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
917
918 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09919 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01920
[email protected]8093a542011-05-13 07:29:32921 BrowserThread::PostTask(
922 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03923 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43924 render_view_id, url, first_party, cookie_line, *options,
925 !allow));
[email protected]ed24fad2011-05-10 22:44:01926 return allow;
927}
928
[email protected]d5a19162011-06-30 18:51:54929bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20930 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20932 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26933
[email protected]f24bd172012-03-31 01:54:59934 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54935}
936
[email protected]5c5a88e2011-11-12 00:45:35937bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35938 const GURL& url,
939 const string16& name,
940 const string16& display_name,
941 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20942 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48943 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35944 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20945 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35946 CookieSettings* cookie_settings = io_data->GetCookieSettings();
947 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
948
[email protected]62151052012-02-01 18:40:48949 // Record access to database for potential display in UI.
950 std::vector<std::pair<int, int> >::const_iterator i;
951 for (i = render_views.begin(); i != render_views.end(); ++i) {
952 BrowserThread::PostTask(
953 BrowserThread::UI, FROM_HERE,
954 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
955 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35956 }
957
958 return allow;
959}
960
961bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35962 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20963 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48964 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35965 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20966 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35967 CookieSettings* cookie_settings = io_data->GetCookieSettings();
968 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
969
[email protected]62151052012-02-01 18:40:48970 // Record access to file system for potential display in UI.
971 std::vector<std::pair<int, int> >::const_iterator i;
972 for (i = render_views.begin(); i != render_views.end(); ++i) {
973 BrowserThread::PostTask(
974 BrowserThread::UI, FROM_HERE,
975 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
976 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35977 }
978
979 return allow;
980}
981
[email protected]7c5ff9a2012-03-02 07:42:49982bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
983 const GURL& url,
984 const string16& name,
985 content::ResourceContext* context,
986 const std::vector<std::pair<int, int> >& render_views) {
987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
988 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
989 CookieSettings* cookie_settings = io_data->GetCookieSettings();
990 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
991
992 // Record access to IndexedDB for potential display in UI.
993 std::vector<std::pair<int, int> >::const_iterator i;
994 for (i = render_views.begin(); i != render_views.end(); ++i) {
995 BrowserThread::PostTask(
996 BrowserThread::UI, FROM_HERE,
997 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
998 i->first, i->second, url, name, !allow));
999 }
1000
1001 return allow;
1002}
1003
[email protected]6133f922011-07-01 21:34:341004net::URLRequestContext*
1005ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201006 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1008 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201009 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341010 return io_data->extensions_request_context();
1011 }
1012
1013 return NULL;
1014}
1015
[email protected]317f96c92011-05-31 06:53:411016QuotaPermissionContext*
1017ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1018 return new ChromeQuotaPermissionContext();
1019}
1020
[email protected]a0ce3282011-08-19 20:49:521021void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421022 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421023}
1024
[email protected]a0ce3282011-08-19 20:49:521025void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521026 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521027}
1028
[email protected]848dd042011-06-04 18:24:031029void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171030 int render_process_id,
1031 int render_view_id,
1032 int cert_error,
1033 const net::SSLInfo& ssl_info,
1034 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031035 bool overridable,
[email protected]d9be47702012-05-16 03:41:221036 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171037 const base::Callback<void(bool)>& callback,
1038 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411039 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131040 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171041 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411042 if (!tab) {
1043 NOTREACHED();
1044 return;
1045 }
1046 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501047 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301048 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091049 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411050 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171051 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411052 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171053 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411054 return;
1055 }
1056 }
1057
1058 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221059 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1060 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031061}
1062
[email protected]c99c442e2011-08-24 11:37:301063void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451064 int render_process_id,
1065 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401066 const net::HttpNetworkSession* network_session,
1067 net::SSLCertRequestInfo* cert_request_info,
1068 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131069 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451070 render_process_id, render_view_id);
1071 if (!tab) {
1072 NOTREACHED();
1073 return;
1074 }
1075
[email protected]6786bf402011-12-03 15:19:451076 GURL requesting_url("https://" + cert_request_info->host_and_port);
1077 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1078 << cert_request_info->host_and_port;
1079
[email protected]627e0512011-12-21 22:55:301080 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451081 scoped_ptr<Value> filter(
1082 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1083 requesting_url,
1084 requesting_url,
1085 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1086 std::string(), NULL));
1087
1088 if (filter.get()) {
1089 // Try to automatically select a client certificate.
1090 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1091 DictionaryValue* filter_dict =
1092 static_cast<DictionaryValue*>(filter.get());
1093
1094 const std::vector<scoped_refptr<net::X509Certificate> >&
1095 all_client_certs = cert_request_info->client_certs;
1096 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1097 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1098 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401099 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451100 return;
1101 }
1102 }
1103 } else {
1104 NOTREACHED();
1105 }
1106 }
1107
[email protected]8ec26472011-06-06 16:52:451108 TabContentsWrapper* wrapper =
1109 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451110 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131111 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451112 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141113 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401114 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451115 return;
1116 }
[email protected]7a593db2012-02-13 21:19:401117 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1118 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451119}
1120
1121void ChromeContentBrowserClient::AddNewCertificate(
1122 net::URLRequest* request,
1123 net::X509Certificate* cert,
1124 int render_process_id,
1125 int render_view_id) {
1126 // The handler will run the UI and delete itself when it's finished.
1127 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1128}
1129
[email protected]a93670ab2012-02-24 03:46:391130void ChromeContentBrowserClient::RequestMediaAccessPermission(
1131 const content::MediaStreamRequest* request,
1132 const content::MediaResponseCallback& callback) {
1133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1134
[email protected]117b6b42012-02-29 09:11:081135 WebContents* contents = tab_util::GetWebContentsByID(
1136 request->render_process_id, request->render_view_id);
1137 if (!contents) {
1138 // Abort, if the tab was closed after the request was made but before we
1139 // got to this point.
1140 callback.Run(content::MediaStreamDevices());
1141 return;
1142 }
1143
1144 TabContentsWrapper* tab =
1145 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1146 DCHECK(tab);
1147
1148 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1149 InfoBarDelegate* old_infobar = NULL;
1150 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1151 old_infobar =
[email protected]51d1fc62012-04-28 03:47:531152 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfoBarDelegate();
[email protected]117b6b42012-02-29 09:11:081153 }
1154
[email protected]117b6b42012-02-29 09:11:081155 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1156 request,
1157 callback);
1158 if (old_infobar)
1159 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1160 else
1161 infobar_helper->AddInfoBar(infobar);
[email protected]a93670ab2012-02-24 03:46:391162}
1163
[email protected]dc73a7b2012-03-25 15:27:181164content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1165 return MediaInternals::GetInstance();
1166}
1167
[email protected]941623e2011-06-07 23:06:041168void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1169 const GURL& source_origin,
1170 int callback_context,
1171 int render_process_id,
1172 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111173#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041174 RenderViewHost* rvh = RenderViewHost::FromID(
1175 render_process_id, render_view_id);
1176 if (!rvh) {
1177 NOTREACHED();
1178 return;
1179 }
1180
[email protected]9f76c1e2012-03-05 15:15:581181 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301182 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041183 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371184 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041185 service->RequestPermission(
1186 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131187 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111188#else
1189 NOTIMPLEMENTED();
1190#endif
[email protected]941623e2011-06-07 23:06:041191}
1192
1193WebKit::WebNotificationPresenter::Permission
1194 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021195 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201196 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021197 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111198#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201200 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021201 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1202 source_origin, render_process_id,
1203 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041204 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041205
1206 // Fall back to the regular notification preferences, which works on an
1207 // origin basis.
1208 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371209 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041210 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111211#else
1212 return WebKit::WebNotificationPresenter::PermissionAllowed;
1213#endif
[email protected]941623e2011-06-07 23:06:041214}
1215
1216void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171217 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041218 int render_process_id,
1219 int render_view_id,
1220 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111221#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041222 RenderViewHost* rvh = RenderViewHost::FromID(
1223 render_process_id, render_view_id);
1224 if (!rvh) {
1225 NOTREACHED();
1226 return;
1227 }
1228
[email protected]9f76c1e2012-03-05 15:15:581229 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301230 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041231 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371232 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041233 service->ShowDesktopNotification(
1234 params, render_process_id, render_view_id,
1235 worker ? DesktopNotificationService::WorkerNotification :
1236 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111237#else
1238 NOTIMPLEMENTED();
1239#endif
[email protected]941623e2011-06-07 23:06:041240}
1241
1242void ChromeContentBrowserClient::CancelDesktopNotification(
1243 int render_process_id,
1244 int render_view_id,
1245 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111246#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041247 RenderViewHost* rvh = RenderViewHost::FromID(
1248 render_process_id, render_view_id);
1249 if (!rvh) {
1250 NOTREACHED();
1251 return;
1252 }
1253
[email protected]9f76c1e2012-03-05 15:15:581254 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301255 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041256 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371257 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041258 service->CancelDesktopNotification(
1259 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111260#else
1261 NOTIMPLEMENTED();
1262#endif
[email protected]941623e2011-06-07 23:06:041263}
1264
[email protected]9f3fba52011-06-08 20:37:191265bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351266 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021267 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191268 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201269 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011270 int render_process_id,
1271 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011273
1274 *no_javascript_access = false;
1275
[email protected]9f3fba52011-06-08 20:37:191276 // If the opener is trying to create a background window but doesn't have
1277 // the appropriate permission, fail the attempt.
1278 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201279 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531280 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1281
[email protected]03b6d552012-03-29 04:03:011282 if (!map->SecurityOriginHasAPIPermission(
1283 source_origin,
1284 render_process_id,
1285 ExtensionAPIPermission::kBackground)) {
1286 return false;
1287 }
1288
[email protected]7b54ca02012-03-02 18:06:531289 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1290 // return a recently installed Extension even if this CanCreateWindow call
1291 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011292 // because the permission check above would have caused an early return
1293 // already. We must use the full URL to find hosted apps, though, and not
1294 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531295 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351296 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531297 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011298 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191299 }
1300 return true;
1301}
1302
1303std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201304 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1306 // Check if it's an extension-created worker, in which case we want to use
1307 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201308 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191309 const Extension* extension =
1310 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1311 return extension ? extension->name() : std::string();
1312}
1313
[email protected]99907362012-01-11 05:41:401314void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1315 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171316}
1317
[email protected]c52b2892012-03-07 11:01:021318content::SpeechRecognitionManagerDelegate*
1319 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321320#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021321 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321322#else
1323 return NULL;
1324#endif
[email protected]66cfec62012-02-24 17:57:511325}
1326
[email protected]3cb054e62011-06-13 05:21:171327ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1328 return g_browser_process->clipboard();
1329}
1330
[email protected]ae6e9912011-07-27 01:18:281331net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1332 return g_browser_process->net_log();
1333}
1334
[email protected]32538d92011-08-25 00:09:231335AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1336 return new ChromeAccessTokenStore();
1337}
1338
[email protected]dbae6b02011-06-29 23:51:411339bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1340 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1341 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1342}
1343
[email protected]64d69de42012-02-06 00:19:541344void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321345 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061346 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581347 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061348 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061349
[email protected]f3986f82012-01-03 20:00:061350 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541351 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061352 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541353 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061354 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541355 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061356 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541357 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061358 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541359 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061360 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541361 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061362
[email protected]64d69de42012-02-06 00:19:541363 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401364 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541365 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401366 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541367 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401368 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541369 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401370 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061371
[email protected]ddf72142012-05-22 04:52:401372 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061373
[email protected]64d69de42012-02-06 00:19:541374 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401375 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541376 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061377 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541378 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061379 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1380 const DictionaryValue* inspector_settings =
1381 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1382 if (inspector_settings) {
1383 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1384 iter != inspector_settings->end_keys(); ++iter) {
1385 std::string value;
1386 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541387 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061388 std::make_pair(*iter, value));
1389 }
1390 }
[email protected]64d69de42012-02-06 00:19:541391 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061392
[email protected]ddf72142012-05-22 04:52:401393 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541394 web_prefs->javascript_enabled = false;
1395 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1396 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401397 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541398 web_prefs->plugins_enabled = false;
1399 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1400 web_prefs->java_enabled = false;
1401 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401402 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061403
[email protected]64d69de42012-02-06 00:19:541404 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1405 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061406
[email protected]64d69de42012-02-06 00:19:541407 web_prefs->memory_info_enabled =
1408 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1409 web_prefs->allow_displaying_insecure_content =
1410 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1411 web_prefs->allow_running_insecure_content =
1412 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081413 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061414
[email protected]64d69de42012-02-06 00:19:541415 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151416 UserStyleSheetWatcher* user_style_sheet_watcher =
1417 UserStyleSheetWatcherFactory::GetForProfile(profile);
1418 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541419 web_prefs->user_style_sheet_enabled = true;
1420 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151421 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541422 } else {
1423 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061424 }
1425
[email protected]b7e44ff2012-02-16 03:37:341426 web_prefs->asynchronous_spell_checking_enabled =
[email protected]8e466dd2012-05-04 19:16:051427 CommandLine::ForCurrentProcess()->
1428 HasSwitch(switches::kEnableAsynchronousSpellChecking);
[email protected]b7e44ff2012-02-16 03:37:341429 web_prefs->unified_textchecker_enabled =
1430 web_prefs->asynchronous_spell_checking_enabled ||
1431 CommandLine::ForCurrentProcess()->
1432 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571433
[email protected]64d69de42012-02-06 00:19:541434 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061435 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541436 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061437 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541438 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061439 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1440
1441 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541442 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061443 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541444 web_prefs->default_encoding);
1445 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401446 prefs->ClearPref(prefs::kDefaultCharset);
1447 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061448 }
[email protected]64d69de42012-02-06 00:19:541449 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061450
[email protected]299d7f12012-05-23 05:31:151451 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1452 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061453 ExtensionService* service = profile->GetExtensionService();
1454 if (service) {
1455 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581456 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061457 extension_webkit_preferences::SetPreferences(
[email protected]299d7f12012-05-23 05:31:151458 extension, view_type, web_prefs);
[email protected]f3986f82012-01-03 20:00:061459 }
1460
[email protected]299d7f12012-05-23 05:31:151461 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541462 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151463 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061464 // Disable all kinds of acceleration for background pages.
1465 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541466 web_prefs->force_compositing_mode = false;
1467 web_prefs->accelerated_compositing_enabled = false;
1468 web_prefs->accelerated_2d_canvas_enabled = false;
1469 web_prefs->accelerated_video_enabled = false;
1470 web_prefs->accelerated_painting_enabled = false;
1471 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061472 }
[email protected]2e21fe292012-03-02 22:52:321473
1474#if defined(FILE_MANAGER_EXTENSION)
1475 // Override the default of suppressing HW compositing for WebUI pages for the
1476 // file manager, which is implemented using WebUI but wants HW acceleration
1477 // for video decode & render.
1478 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1479 web_prefs->accelerated_compositing_enabled = true;
1480 web_prefs->accelerated_2d_canvas_enabled = true;
1481 }
1482#endif
[email protected]181a95ee2011-07-12 19:26:361483}
1484
1485void ChromeContentBrowserClient::UpdateInspectorSetting(
1486 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061487 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581488 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061489 DictionaryPrefUpdate update(
1490 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1491 prefs::kWebKitInspectorSettings);
1492 DictionaryValue* inspector_settings = update.Get();
1493 inspector_settings->SetWithoutPathExpansion(key,
1494 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361495}
1496
1497void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061498 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581499 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061500 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1501 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361502}
1503
[email protected]b8148ac2011-07-13 22:03:251504void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1505 BrowserURLHandler* handler) {
1506 // Add the default URL handlers.
1507 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1508 BrowserURLHandler::null_handler());
1509 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1510 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1511
[email protected]b3adbd02011-11-30 22:23:271512 // about: handler. Must come before chrome: handler, since it will
1513 // rewrite about: urls to chrome: URLs and then expect chrome: to
1514 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251515 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1516 BrowserURLHandler::null_handler());
1517 // chrome: & friends.
1518 handler->AddHandlerPair(&HandleWebUI,
1519 BrowserURLHandler::null_handler());
1520}
1521
1522void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371523 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581524 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251525 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1526 BrowsingDataRemover::EVERYTHING,
1527 base::Time());
1528 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1529 // BrowsingDataRemover takes care of deleting itself when done.
1530}
1531
1532void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371533 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581534 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251535 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1536 BrowsingDataRemover::EVERYTHING,
1537 base::Time());
[email protected]dceaa912011-09-06 17:17:231538 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251539 remover->Remove(remove_mask);
1540 // BrowsingDataRemover takes care of deleting itself when done.
1541}
1542
[email protected]e1d16eb92011-08-18 23:19:321543FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1544 return download_util::GetDefaultDownloadDirectory();
1545}
1546
[email protected]c9b6eb62011-10-18 20:49:391547std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1548 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1549}
1550
[email protected]a658d452012-03-02 12:45:291551bool ChromeContentBrowserClient::AllowSocketAPI(
1552 content::BrowserContext* browser_context, const GURL& url) {
1553 if (!url.is_valid())
1554 return false;
1555
1556 std::string host = url.host();
1557 if (allowed_socket_origins_.count(host))
1558 return true;
1559
[email protected]9a5940d2012-04-27 19:16:231560 Profile* profile = Profile::FromBrowserContext(browser_context);
1561 const Extension* extension = NULL;
1562 if (profile && profile->GetExtensionService()) {
1563 extension = profile->GetExtensionService()->extensions()->
1564 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1565 }
1566
[email protected]f237c0f2012-03-10 07:49:101567 // Need to check this now and not on construction because otherwise it won't
1568 // work with browser_tests.
1569 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1570 std::string allowed_list =
1571 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231572 if (allowed_list == "*") {
1573 // The wildcard allows socket API only for packaged and platform apps.
1574 return extension &&
1575 (extension->GetType() == Extension::TYPE_PACKAGED_APP ||
1576 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1577 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101578 StringTokenizer t(allowed_list, ",");
1579 while (t.GetNext()) {
1580 if (t.token() == host)
1581 return true;
1582 }
1583 }
1584
[email protected]a658d452012-03-02 12:45:291585 if (!extension)
1586 return false;
1587
1588 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1589 return true;
1590
1591 return false;
[email protected]e461da2f2012-02-16 19:06:401592}
1593
[email protected]e60c0232011-11-11 19:56:351594#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301595int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521596 const CommandLine& command_line) {
1597 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071598 ExtensionCrashHandlerHostLinux* crash_handler =
1599 ExtensionCrashHandlerHostLinux::GetInstance();
1600 return crash_handler->GetDeathSignalSocket();
1601 }
1602
[email protected]718eab62011-10-05 21:16:521603 std::string process_type =
1604 command_line.GetSwitchValueASCII(switches::kProcessType);
1605
1606 if (process_type == switches::kRendererProcess)
1607 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1608
[email protected]b80f68432011-05-02 17:22:301609 if (process_type == switches::kPluginProcess)
1610 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1611
1612 if (process_type == switches::kPpapiPluginProcess)
1613 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1614
1615 if (process_type == switches::kGpuProcess)
1616 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1617
1618 return -1;
1619}
[email protected]e60c0232011-11-11 19:56:351620#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301621
[email protected]4a65826d2011-08-25 16:04:011622#if defined(OS_WIN)
1623const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1624 return chrome::kBrowserResourcesDll;
1625}
1626#endif
1627
[email protected]37a72af2011-06-13 05:42:011628#if defined(USE_NSS)
1629crypto::CryptoModuleBlockingPasswordDelegate*
1630 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1631 const GURL& url) {
1632 return browser::NewCryptoModuleBlockingDialogDelegate(
1633 browser::kCryptoModulePasswordKeygen, url.host());
1634}
1635#endif
1636
[email protected]d977f9c2011-03-14 16:10:261637} // namespace chrome