blob: 9a360deaec70ee7a37de45ab487e258047305382 [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]f3986f82012-01-03 20:00:0613#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3014#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2515#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3016#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2317#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1218#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0319#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4120#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5621#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0522#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4523#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3224#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3225#include "chrome/browser/download/download_util.h"
[email protected]6e672df2012-01-25 10:39:4726#include "chrome/browser/extensions/api/webrequest/webrequest_api.h"
[email protected]941623e2011-06-07 23:06:0427#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1028#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2629#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2530#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0631#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2332#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1233#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2834#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0435#include "chrome/browser/notifications/desktop_notification_service.h"
36#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4237#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1238#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0639#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4140#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5041#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4142#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1443#include "chrome/browser/printing/printing_message_filter.h"
44#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3245#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1446#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3347#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4248#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1449#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0450#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4651#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4552#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0353#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4554#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
55#include "chrome/browser/tab_contents/tab_util.h"
56#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5057#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0658#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3059#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0160#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3061#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0462#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4463#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3464#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1265#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3866#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0967#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2568#include "content/browser/browser_url_handler.h"
[email protected]d977f9c2011-03-14 16:10:2669#include "content/browser/renderer_host/render_view_host.h"
[email protected]8ec26472011-06-06 16:52:4570#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]b48c9182011-10-26 18:03:3071#include "content/public/browser/browser_main_parts.h"
[email protected]b9535422012-02-09 01:47:5972#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3073#include "content/public/browser/render_process_host.h"
[email protected]ce967862012-02-09 22:47:0574#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3375#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1976#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1077#include "content/public/browser/web_contents_view.h"
[email protected]c9b6eb62011-10-18 20:49:3978#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3479#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0180#include "net/base/cookie_monster.h"
81#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3982#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0883#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3684#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2685
[email protected]b48c9182011-10-26 18:03:3086#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3887#include "chrome/browser/chrome_browser_main_win.h"
88#elif defined(OS_MACOSX)
89#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5690#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3091#elif defined(OS_CHROMEOS)
92#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3593#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3094#include "chrome/browser/chrome_browser_main_linux.h"
95#elif defined(OS_POSIX)
96#include "chrome/browser/chrome_browser_main_posix.h"
97#endif
98
[email protected]b48c9182011-10-26 18:03:3099#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31100#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38101#endif
102
[email protected]c7480942011-11-08 19:18:27103#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31104#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27105#endif
106
107#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31108#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
109#endif
110
[email protected]e60c0232011-11-11 19:56:35111#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30112#include "base/linux_util.h"
113#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43114#endif
[email protected]b80f68432011-05-02 17:22:30115
[email protected]080f34f2011-09-20 05:39:26116#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32117#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21118#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45119#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]90580422012-01-12 00:26:22120#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32121#elif defined(OS_MACOSX)
[email protected]cce3ab72012-02-04 18:05:16122#include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h"
[email protected]eb668c92012-02-06 15:35:29123#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]6e677a342012-02-11 01:21:14124#elif defined(OS_ANDROID)
125#include "content/browser/tab_contents/tab_contents_view_android.h"
[email protected]74313b42011-08-24 16:51:32126#endif
127
[email protected]37a72af2011-06-13 05:42:01128#if defined(USE_NSS)
129#include "chrome/browser/ui/crypto_module_password_dialog.h"
130#endif
131
[email protected]c8c77182011-12-21 15:04:47132using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39133using content::BrowserThread;
[email protected]b9535422012-02-09 01:47:59134using content::ChildProcessSecurityPolicy;
[email protected]b6583592012-01-25 19:52:33135using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13136using content::WebContents;
[email protected]631bb742011-11-02 11:29:39137
[email protected]c5dbef02011-05-13 05:06:09138namespace {
139
[email protected]b8148ac2011-07-13 22:03:25140// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42141bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50142 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
143 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25144 return false;
145
146 // Special case the new tab page. In older versions of Chrome, the new tab
147 // page was hosted at chrome-internal:<blah>. This might be in people's saved
148 // sessions or bookmarks, so we say any URL with that scheme triggers the new
149 // tab page.
150 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
151 // Rewrite it with the proper new tab URL.
152 *url = GURL(chrome::kChromeUINewTabURL);
153 }
154
155 return true;
156}
157
[email protected]8d3132f62011-10-12 07:13:42158// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
159// below. Extension, and isolated apps require different privileges to be
160// granted to their RenderProcessHosts. This classification allows us to make
161// sure URLs are served by hosts with the right set of privileges.
162enum RenderProcessHostPrivilege {
163 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45164 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42165 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45166 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42167};
168
169RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
170 const GURL& url,
171 ExtensionService* service) {
172 // Default to a normal renderer cause it is lower privileged. This should only
173 // occur if the URL on a site instance is either malformed, or uninitialized.
174 // If it is malformed, then there is no need for better privileges anyways.
175 // If it is uninitialized, but eventually settles on being an a scheme other
176 // than normal webrenderer, the navigation logic will correct us out of band
177 // anyways.
178 if (!url.is_valid())
179 return PRIV_NORMAL;
180
181 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44182 const Extension* extension =
183 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45184 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42185 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45186 if (extension && extension->is_hosted_app())
187 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42188
189 return PRIV_EXTENSION;
190 }
191
192 return PRIV_NORMAL;
193}
194
195RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30196 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46197 extensions::ProcessMap* process_map,
198 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46199 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30200 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46201 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21202 return PRIV_NORMAL;
203
[email protected]6f371442011-11-09 06:45:46204 for (std::set<std::string>::iterator iter = extension_ids.begin();
205 iter != extension_ids.end(); ++iter) {
206 const Extension* extension = service->GetExtensionById(*iter, false);
207 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42208 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45209 if (extension && extension->is_hosted_app())
210 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42211 }
212
[email protected]676f6ab2011-10-19 20:23:21213 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42214}
215
[email protected]eec0b33c2011-12-05 22:09:45216bool IsIsolatedAppInProcess(const GURL& site_url,
217 content::RenderProcessHost* process_host,
218 extensions::ProcessMap* process_map,
219 ExtensionService* service) {
220 std::set<std::string> extension_ids =
221 process_map->GetExtensionsInProcess(process_host->GetID());
222 if (extension_ids.empty())
223 return false;
224
225 for (std::set<std::string>::iterator iter = extension_ids.begin();
226 iter != extension_ids.end(); ++iter) {
227 const Extension* extension = service->GetExtensionById(*iter, false);
228 if (extension &&
229 extension->is_storage_isolated() &&
230 extension->url() == site_url)
231 return true;
232 }
233
234 return false;
235}
236
[email protected]6786bf402011-12-03 15:19:45237bool CertMatchesFilter(const net::X509Certificate& cert,
238 const base::DictionaryValue& filter) {
239 // TODO(markusheintz): This is the minimal required filter implementation.
240 // Implement a better matcher.
241
242 // An empty filter matches any client certificate since no requirements are
243 // specified at all.
244 if (filter.empty())
245 return true;
246
247 std::string common_name;
248 if (filter.GetString("ISSUER.CN", &common_name) &&
249 (cert.issuer().common_name == common_name)) {
250 return true;
251 }
252 return false;
253}
254
[email protected]f3986f82012-01-03 20:00:06255// Fills |map| with the per-script font prefs under path |map_name|.
256void FillFontFamilyMap(const PrefService* prefs,
257 const char* map_name,
258 WebPreferences::ScriptFontFamilyMap* map) {
259 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
260 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
261 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
262 std::string font_family = prefs->GetString(pref_name.c_str());
263 if (!font_family.empty())
264 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
265 }
266}
267
[email protected]9dbfff12011-07-01 19:37:07268} // namespace
[email protected]c5dbef02011-05-13 05:06:09269
[email protected]d977f9c2011-03-14 16:10:26270namespace chrome {
271
[email protected]50462bf02011-11-21 19:13:31272content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
273 const content::MainFunctionParams& parameters) {
274 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30275 // Construct the Main browser parts based on the OS type.
276#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31277 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04278#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31279 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30280#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31281 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35282#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31283 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14284#elif defined(OS_ANDROID)
285 // Do nothing for Android.
286 // TODO(klobag): Android initialization should use the
287 // *BrowserMainParts class-hierarchy for setting up custom initialization.
288 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30289#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31290 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04291#else
[email protected]b48c9182011-10-26 18:03:30292 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31293 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30294#endif
295
[email protected]c7480942011-11-08 19:18:27296 // Construct additional browser parts. Stages are called in the order in
297 // which they are added.
[email protected]b48c9182011-10-26 18:03:30298#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31299 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04300#endif
[email protected]c7480942011-11-08 19:18:27301
302#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31303 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27304#endif
305
306#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31307 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27308#endif
309
[email protected]50462bf02011-11-21 19:13:31310 return main_parts;
[email protected]f967b722011-09-07 00:58:04311}
312
[email protected]8643e6d2012-01-18 20:26:10313content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35314 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26315#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35316 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21317#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35318 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22319 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32320#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29321 return web_contents_view_mac::CreateWebContentsView(
[email protected]cce3ab72012-02-04 18:05:16322 web_contents,
323 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
324 web_contents));
[email protected]6e677a342012-02-11 01:21:14325#elif defined(OS_ANDROID)
326 return new TabContentsViewAndroid(web_contents);
[email protected]74313b42011-08-24 16:51:32327#else
[email protected]8643e6d2012-01-18 20:26:10328#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32329#endif
330}
331
[email protected]f364d1392011-04-08 21:03:10332void ChromeContentBrowserClient::RenderViewHostCreated(
333 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46334
335 SiteInstance* site_instance = render_view_host->site_instance();
336 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02337 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46338
339 new ChromeRenderViewHostObserver(render_view_host,
340 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10341 new ExtensionMessageHandler(render_view_host);
[email protected]85f0a572012-02-07 22:20:13342
343 if (render_view_host->delegate()->GetRenderViewType() ==
344 content::VIEW_TYPE_INTERSTITIAL_PAGE) {
345 render_view_host->Send(new ChromeViewMsg_SetAsInterstitial(
346 render_view_host->routing_id()));
347 }
[email protected]d977f9c2011-03-14 16:10:26348}
349
[email protected]f3b1a082011-11-18 00:34:30350void ChromeContentBrowserClient::RenderProcessHostCreated(
351 content::RenderProcessHost* host) {
352 int id = host->GetID();
353 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
354 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02355 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30356 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
357 host->GetChannel()->AddFilter(new PrintingMessageFilter());
358 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02359 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30360 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56361#if defined(OS_MACOSX)
362 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
363#endif
[email protected]f3b1a082011-11-18 00:34:30364 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03365 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38366
[email protected]2ccf45c2011-08-19 23:35:50367 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
368 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07369
370 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56371
372 RendererContentSettingRules rules;
373 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
374 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14375}
376
[email protected]863f70a2012-01-27 02:05:50377content::WebUIControllerFactory*
378 ChromeContentBrowserClient::GetWebUIControllerFactory() {
379 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56380}
381
[email protected]3d7474ff2011-07-27 17:47:37382GURL ChromeContentBrowserClient::GetEffectiveURL(
383 content::BrowserContext* browser_context, const GURL& url) {
384 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08385 // Get the effective URL for the given actual URL. If the URL is part of an
386 // installed app, the effective URL is an extension URL with the ID of that
387 // extension as the host. This has the effect of grouping apps together in
388 // a common SiteInstance.
389 if (!profile || !profile->GetExtensionService())
390 return url;
391
[email protected]615d88f2011-12-13 01:47:44392 const Extension* extension = profile->GetExtensionService()->extensions()->
393 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08394 if (!extension)
395 return url;
396
[email protected]15877ca2011-11-18 22:40:52397 // Bookmark apps do not use the hosted app process model, and should be
398 // treated as normal URLs.
399 if (extension->from_bookmark())
400 return url;
401
[email protected]36fb2c7c2011-04-04 15:49:08402 // If the URL is part of an extension's web extent, convert it to an
403 // extension URL.
404 return extension->GetResourceURL(url.path());
405}
406
[email protected]056ad2a2011-07-12 02:13:55407bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37408 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55409 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52410 // Because we expect to use the effective URL, URLs for hosted apps (apart
411 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55412 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
413 return false;
414
[email protected]3d7474ff2011-07-27 17:47:37415 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55416 if (!profile || !profile->GetExtensionService())
417 return false;
418
[email protected]615d88f2011-12-13 01:47:44419 const Extension* extension = profile->GetExtensionService()->extensions()->
420 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55421 if (!extension)
422 return false;
423
424 // If the URL is part of a hosted app that does not have the background
425 // permission, we want to give each instance its own process to improve
426 // responsiveness.
427 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
428 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
429 return false;
430
431 // Hosted apps that have the background permission must use process per site,
432 // since all instances can make synchronous calls to the background window.
433 // Other extensions should use process per site as well.
434 return true;
435}
436
[email protected]46fb9442011-12-09 17:57:47437bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
438 return ProfileIOData::IsHandledURL(url);
439}
440
[email protected]2a5221b2011-09-27 23:07:31441bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30442 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31443 const GURL& site_url) {
444 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30445 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42446 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46447 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31448
[email protected]ffa97602011-11-17 17:55:52449 // Don't allow the Task Manager to share a process with anything else.
450 // Otherwise it can affect the renderers it is observing.
451 // Note: we could create another RenderProcessHostPrivilege bucket for
452 // this to allow multiple chrome://tasks instances to share, but that's
453 // a very unlikely case without serious consequences.
454 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
455 return false;
456
[email protected]8d3132f62011-10-12 07:13:42457 // These may be NULL during tests. In that case, just assume any site can
458 // share any host.
[email protected]6f371442011-11-09 06:45:46459 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31460 return true;
461
[email protected]a8c269a2011-10-25 20:17:22462 // Experimental:
463 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
464 // to share a renderer process. (We could allow pages from the same site or
465 // extensions of the same type to share, if we knew what the given process
466 // was dedicated to. Allowing no sharing is simpler for now.) This may
467 // cause resource exhaustion issues if too many sites are open at once.
468 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
469 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
470 return false;
471
[email protected]eec0b33c2011-12-05 22:09:45472 // An isolated app is only allowed to share with the exact same app in order
473 // to provide complete renderer process isolation. This also works around
474 // issue http://crbug.com/85588, where different isolated apps in the same
475 // process would end up using the first app's storage contexts.
476 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42477 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45478 if (privilege_required == PRIV_ISOLATED)
479 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
480
481 // Otherwise, just make sure the process privilege matches the privilege
482 // required by the site.
483 return GetProcessPrivilege(process_host, process_map, service) ==
484 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31485}
486
[email protected]6f371442011-11-09 06:45:46487void ChromeContentBrowserClient::SiteInstanceGotProcess(
488 SiteInstance* site_instance) {
489 CHECK(site_instance->HasProcess());
490
491 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02492 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46493 ExtensionService* service = profile->GetExtensionService();
494 if (!service)
495 return;
496
497 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44498 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33499 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46500 if (!extension)
501 return;
502
[email protected]6bc04fd82011-12-04 02:29:35503 service->process_map()->Insert(extension->id(),
504 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33505 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46506 BrowserThread::PostTask(
507 BrowserThread::IO, FROM_HERE,
508 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
509 profile->GetExtensionInfoMap(),
510 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35511 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33512 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46513}
514
515void ChromeContentBrowserClient::SiteInstanceDeleting(
516 SiteInstance* site_instance) {
517 if (!site_instance->HasProcess())
518 return;
519
520 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02521 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46522 ExtensionService* service = profile->GetExtensionService();
523 if (!service)
524 return;
525
526 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44527 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33528 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46529 if (!extension)
530 return;
531
[email protected]6bc04fd82011-12-04 02:29:35532 service->process_map()->Remove(extension->id(),
533 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33534 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46535 BrowserThread::PostTask(
536 BrowserThread::IO, FROM_HERE,
537 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
538 profile->GetExtensionInfoMap(),
539 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35540 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33541 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46542}
543
[email protected]e3daf3c2011-10-05 21:17:08544bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
545 const GURL& current_url,
546 const GURL& new_url) {
547 if (current_url.is_empty()) {
548 // Always choose a new process when navigating to extension URLs. The
549 // process grouping logic will combine all of a given extension's pages
550 // into the same process.
551 if (new_url.SchemeIs(chrome::kExtensionScheme))
552 return true;
553
554 return false;
555 }
556
557 // Also, we must switch if one is an extension and the other is not the exact
558 // same extension.
559 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
560 new_url.SchemeIs(chrome::kExtensionScheme)) {
561 if (current_url.GetOrigin() != new_url.GetOrigin())
562 return true;
563 }
564
565 return false;
566}
567
[email protected]763ec4ca2011-04-29 15:48:12568std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
569 const std::string& alias_name) {
570 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
571}
572
[email protected]b80f68432011-05-02 17:22:30573void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
574 CommandLine* command_line, int child_process_id) {
575#if defined(USE_LINUX_BREAKPAD)
576 if (IsCrashReporterEnabled()) {
577 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
578 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
579 }
580#elif defined(OS_MACOSX)
581 if (IsCrashReporterEnabled()) {
582 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
583 child_process_logging::GetClientId());
584 }
585#endif // OS_MACOSX
586
[email protected]f1933792011-06-14 00:49:34587 if (logging::DialogsAreSuppressed())
588 command_line->AppendSwitch(switches::kNoErrorDialogs);
589
[email protected]b80f68432011-05-02 17:22:30590 std::string process_type =
591 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17592 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52593 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30594 FilePath user_data_dir =
595 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
596 if (!user_data_dir.empty())
597 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
598#if defined(OS_CHROMEOS)
599 const std::string& login_profile =
600 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
601 if (!login_profile.empty())
602 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
603#endif
604
[email protected]f3b1a082011-11-18 00:34:30605 content::RenderProcessHost* process =
606 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37607 if (process) {
608 Profile* profile = Profile::FromBrowserContext(
609 process->GetBrowserContext());
610 extensions::ProcessMap* process_map =
611 profile->GetExtensionService()->process_map();
612 if (process_map && process_map->Contains(process->GetID()))
613 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30614
[email protected]a8d851f82011-12-21 00:32:37615 PrefService* prefs = profile->GetPrefs();
616 // Currently this pref is only registered if applied via a policy.
617 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
618 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
619 // Turn this policy into a command line switch.
620 command_line->AppendSwitch(switches::kDisable3DAPIs);
621 }
[email protected]718eab62011-10-05 21:16:52622
[email protected]a8d851f82011-12-21 00:32:37623 // Disable client-side phishing detection in the renderer if it is
624 // disabled in the Profile preferences or the browser process.
625 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
626 !g_browser_process->safe_browsing_detection_service()) {
627 command_line->AppendSwitch(
628 switches::kDisableClientSidePhishingDetection);
629 }
[email protected]8c40da62011-07-13 22:58:46630 }
[email protected]47c7ec82012-01-18 03:29:21631 {
632 PrefService* local_state = g_browser_process->local_state();
633 if (local_state &&
634 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
635 command_line->AppendSwitch(switches::kRendererPrintPreview);
636 }
637 }
[email protected]4287a3d2011-06-13 23:56:51638
[email protected]47c7ec82012-01-18 03:29:21639 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51640 static const char* const kSwitchNames[] = {
641 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48642 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18643 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51644 switches::kAllowScriptingGallery,
645 switches::kAppsCheckoutURL,
646 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31647 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51648 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51649 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21650 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51651 switches::kEnableCrxlessWebApps,
652 switches::kEnableExperimentalExtensionApis,
653 switches::kEnableInBrowserThumbnailing,
654 switches::kEnableIPCFuzzing,
655 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53656 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51657 switches::kEnableWatchdog,
658 switches::kExperimentalSpellcheckerFeatures,
659 switches::kMemoryProfiling,
660 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04661 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51662 switches::kPpapiFlashArgs,
663 switches::kPpapiFlashInProcess,
664 switches::kPpapiFlashPath,
665 switches::kPpapiFlashVersion,
666 switches::kProfilingAtStart,
667 switches::kProfilingFile,
668 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51669 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38670 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51671 };
672
673 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
674 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17675 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38676 static const char* const kSwitchNames[] = {
677 switches::kEnableExperimentalExtensionApis,
678 switches::kWhitelistedExtensionID,
679 };
680
681 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
682 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51683 } else if (process_type == switches::kPluginProcess) {
684 static const char* const kSwitchNames[] = {
685 #if defined(OS_CHROMEOS)
686 switches::kLoginProfile,
687 #endif
688 switches::kMemoryProfiling,
689 switches::kSilentDumpOnDCHECK,
690 switches::kUserDataDir,
691 };
692
693 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
694 arraysize(kSwitchNames));
695 } else if (process_type == switches::kZygoteProcess) {
696 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51697 switches::kUserDataDir, // Make logs go to the right file.
698 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
699 switches::kPpapiFlashInProcess,
700 switches::kPpapiFlashPath,
701 switches::kPpapiFlashVersion,
702 };
703
704 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
705 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30706 }
[email protected]6f08af82011-09-15 01:19:03707
708 // The command line switch kEnableBenchmarking needs to be specified along
709 // with the kEnableStatsTable switch to ensure that the stats table global
710 // is initialized correctly.
711 if (command_line->HasSwitch(switches::kEnableBenchmarking))
712 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30713}
714
715std::string ChromeContentBrowserClient::GetApplicationLocale() {
716 return g_browser_process->GetApplicationLocale();
717}
718
[email protected]597a867b2011-11-18 18:31:20719std::string ChromeContentBrowserClient::GetAcceptLangs(
720 content::BrowserContext* context) {
721 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37722 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08723}
724
[email protected]ac55e292011-06-24 05:16:08725SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22726 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08727 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
728}
729
[email protected]a2176792011-05-08 19:30:49730bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09731 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19732 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20733 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20735 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05736 return io_data->GetCookieSettings()->
737 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49738}
739
[email protected]ed24fad2011-05-10 22:44:01740bool ChromeContentBrowserClient::AllowGetCookie(
741 const GURL& url,
742 const GURL& first_party,
743 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20744 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01745 int render_process_id,
746 int render_view_id) {
747 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20748 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05749 bool allow = io_data->GetCookieSettings()->
750 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01751
[email protected]8093a542011-05-13 07:29:32752 BrowserThread::PostTask(
753 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03754 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
755 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01756 return allow;
757}
758
759bool ChromeContentBrowserClient::AllowSetCookie(
760 const GURL& url,
761 const GURL& first_party,
762 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20763 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01764 int render_process_id,
765 int render_view_id,
766 net::CookieOptions* options) {
767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20768 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05769 CookieSettings* cookie_settings = io_data->GetCookieSettings();
770 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
771
772 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09773 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01774
[email protected]8093a542011-05-13 07:29:32775 BrowserThread::PostTask(
776 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03777 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
778 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01779 return allow;
780}
781
[email protected]d5a19162011-06-30 18:51:54782bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20783 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20785 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]d5a19162011-06-30 18:51:54786 return !io_data->clear_local_state_on_exit()->GetValue();
787}
788
[email protected]5c5a88e2011-11-12 00:45:35789bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35790 const GURL& url,
791 const string16& name,
792 const string16& display_name,
793 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20794 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48795 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35796 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20797 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35798 CookieSettings* cookie_settings = io_data->GetCookieSettings();
799 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
800
[email protected]62151052012-02-01 18:40:48801 // Record access to database for potential display in UI.
802 std::vector<std::pair<int, int> >::const_iterator i;
803 for (i = render_views.begin(); i != render_views.end(); ++i) {
804 BrowserThread::PostTask(
805 BrowserThread::UI, FROM_HERE,
806 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
807 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35808 }
809
810 return allow;
811}
812
813bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35814 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20815 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48816 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35817 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20818 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35819 CookieSettings* cookie_settings = io_data->GetCookieSettings();
820 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
821
[email protected]62151052012-02-01 18:40:48822 // Record access to file system for potential display in UI.
823 std::vector<std::pair<int, int> >::const_iterator i;
824 for (i = render_views.begin(); i != render_views.end(); ++i) {
825 BrowserThread::PostTask(
826 BrowserThread::UI, FROM_HERE,
827 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
828 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35829 }
830
831 return allow;
832}
833
[email protected]6133f922011-07-01 21:34:34834net::URLRequestContext*
835ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20836 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
838 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20839 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34840 return io_data->extensions_request_context();
841 }
842
843 return NULL;
844}
845
[email protected]317f96c92011-05-31 06:53:41846QuotaPermissionContext*
847ChromeContentBrowserClient::CreateQuotaPermissionContext() {
848 return new ChromeQuotaPermissionContext();
849}
850
[email protected]a0ce3282011-08-19 20:49:52851void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42852 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42853}
854
[email protected]a0ce3282011-08-19 20:49:52855void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52856 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52857}
858
[email protected]848dd042011-06-04 18:24:03859void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:17860 int render_process_id,
861 int render_view_id,
862 int cert_error,
863 const net::SSLInfo& ssl_info,
864 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:03865 bool overridable,
[email protected]4cf611e32012-02-13 16:06:17866 const base::Callback<void(bool)>& callback,
867 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:41868 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13869 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:17870 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:41871 if (!tab) {
872 NOTREACHED();
873 return;
874 }
875 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50876 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30877 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09878 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41879 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:17880 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:41881 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:17882 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:41883 return;
884 }
885 }
886
887 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:17888 new SSLBlockingPage(
889 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:03890}
891
[email protected]c99c442e2011-08-24 11:37:30892void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45893 int render_process_id,
894 int render_view_id,
895 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13896 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45897 render_process_id, render_view_id);
898 if (!tab) {
899 NOTREACHED();
900 return;
901 }
902
[email protected]6786bf402011-12-03 15:19:45903 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
904 GURL requesting_url("https://" + cert_request_info->host_and_port);
905 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
906 << cert_request_info->host_and_port;
907
[email protected]627e0512011-12-21 22:55:30908 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45909 DCHECK(profile);
910 scoped_ptr<Value> filter(
911 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
912 requesting_url,
913 requesting_url,
914 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
915 std::string(), NULL));
916
917 if (filter.get()) {
918 // Try to automatically select a client certificate.
919 if (filter->IsType(Value::TYPE_DICTIONARY)) {
920 DictionaryValue* filter_dict =
921 static_cast<DictionaryValue*>(filter.get());
922
923 const std::vector<scoped_refptr<net::X509Certificate> >&
924 all_client_certs = cert_request_info->client_certs;
925 for (size_t i = 0; i < all_client_certs.size(); ++i) {
926 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
927 // Use the first certificate that is matched by the filter.
928 handler->CertificateSelected(all_client_certs[i]);
929 return;
930 }
931 }
932 } else {
933 NOTREACHED();
934 }
935 }
936
[email protected]8ec26472011-06-06 16:52:45937 TabContentsWrapper* wrapper =
938 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45939 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13940 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45941 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14942 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45943 handler->CertificateSelected(NULL);
944 return;
945 }
946 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45947}
948
949void ChromeContentBrowserClient::AddNewCertificate(
950 net::URLRequest* request,
951 net::X509Certificate* cert,
952 int render_process_id,
953 int render_view_id) {
954 // The handler will run the UI and delete itself when it's finished.
955 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
956}
957
[email protected]941623e2011-06-07 23:06:04958void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
959 const GURL& source_origin,
960 int callback_context,
961 int render_process_id,
962 int render_view_id) {
963 RenderViewHost* rvh = RenderViewHost::FromID(
964 render_process_id, render_view_id);
965 if (!rvh) {
966 NOTREACHED();
967 return;
968 }
969
[email protected]f3b1a082011-11-18 00:34:30970 content::RenderProcessHost* process = rvh->process();
971 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04972 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37973 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04974 service->RequestPermission(
975 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:13976 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:04977}
978
979WebKit::WebNotificationPresenter::Permission
980 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02981 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:20982 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:02983 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04984 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20985 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:02986 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
987 source_origin, render_process_id,
988 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04989 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04990
991 // Fall back to the regular notification preferences, which works on an
992 // origin basis.
993 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:37994 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:04995 WebKit::WebNotificationPresenter::PermissionNotAllowed;
996}
997
998void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:17999 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041000 int render_process_id,
1001 int render_view_id,
1002 bool worker) {
1003 RenderViewHost* rvh = RenderViewHost::FromID(
1004 render_process_id, render_view_id);
1005 if (!rvh) {
1006 NOTREACHED();
1007 return;
1008 }
1009
[email protected]f3b1a082011-11-18 00:34:301010 content::RenderProcessHost* process = rvh->process();
1011 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041012 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371013 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041014 service->ShowDesktopNotification(
1015 params, render_process_id, render_view_id,
1016 worker ? DesktopNotificationService::WorkerNotification :
1017 DesktopNotificationService::PageNotification);
1018}
1019
1020void ChromeContentBrowserClient::CancelDesktopNotification(
1021 int render_process_id,
1022 int render_view_id,
1023 int notification_id) {
1024 RenderViewHost* rvh = RenderViewHost::FromID(
1025 render_process_id, render_view_id);
1026 if (!rvh) {
1027 NOTREACHED();
1028 return;
1029 }
1030
[email protected]f3b1a082011-11-18 00:34:301031 content::RenderProcessHost* process = rvh->process();
1032 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041033 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371034 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041035 service->CancelDesktopNotification(
1036 render_process_id, render_view_id, notification_id);
1037}
1038
[email protected]9f3fba52011-06-08 20:37:191039bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021040 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191041 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201042 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021043 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191044 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1045 // If the opener is trying to create a background window but doesn't have
1046 // the appropriate permission, fail the attempt.
1047 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201048 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021049 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1050 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191051 }
1052 return true;
1053}
1054
1055std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201056 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1058 // Check if it's an extension-created worker, in which case we want to use
1059 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201060 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191061 const Extension* extension =
1062 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1063 return extension ? extension->name() : std::string();
1064}
1065
[email protected]99907362012-01-11 05:41:401066void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1067 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171068}
1069
1070ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1071 return g_browser_process->clipboard();
1072}
1073
[email protected]8f6a3b852011-07-19 16:48:561074MHTMLGenerationManager*
1075 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1076 return g_browser_process->mhtml_generation_manager();
1077}
1078
[email protected]ae6e9912011-07-27 01:18:281079net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1080 return g_browser_process->net_log();
1081}
1082
[email protected]3bc0b562011-08-24 23:51:041083speech_input::SpeechInputManager*
1084 ChromeContentBrowserClient::GetSpeechInputManager() {
1085 return speech_input::ChromeSpeechInputManager::GetInstance();
1086}
1087
[email protected]32538d92011-08-25 00:09:231088AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1089 return new ChromeAccessTokenStore();
1090}
1091
[email protected]dbae6b02011-06-29 23:51:411092bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1093 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1094 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1095}
1096
[email protected]64d69de42012-02-06 00:19:541097void ChromeContentBrowserClient::OverrideWebkitPrefs(
1098 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061099 Profile* profile = Profile::FromBrowserContext(
1100 rvh->process()->GetBrowserContext());
1101 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061102
[email protected]64d69de42012-02-06 00:19:541103 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061104 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541105 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061106 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541107 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061108 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541109 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061110 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541111 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061112 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541113 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061114 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1115
1116 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541117 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061118 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541119 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061120 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541121 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061122 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541123 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061124 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541125 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061126 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541127 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061128
[email protected]64d69de42012-02-06 00:19:541129 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061130 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541131 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061132 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541133 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061134 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541135 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061136 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1137
[email protected]64d69de42012-02-06 00:19:541138 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061139
[email protected]64d69de42012-02-06 00:19:541140 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061141 prefs->GetBoolean(
1142 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541143 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061144 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541145 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061146 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1147 const DictionaryValue* inspector_settings =
1148 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1149 if (inspector_settings) {
1150 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1151 iter != inspector_settings->end_keys(); ++iter) {
1152 std::string value;
1153 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541154 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061155 std::make_pair(*iter, value));
1156 }
1157 }
[email protected]64d69de42012-02-06 00:19:541158 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061159
[email protected]64d69de42012-02-06 00:19:541160 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1161 web_prefs->javascript_enabled = false;
1162 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1163 web_prefs->web_security_enabled = false;
1164 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1165 web_prefs->plugins_enabled = false;
1166 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1167 web_prefs->java_enabled = false;
1168 web_prefs->loads_images_automatically =
1169 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061170
[email protected]64d69de42012-02-06 00:19:541171 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1172 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061173
[email protected]64d69de42012-02-06 00:19:541174 web_prefs->memory_info_enabled =
1175 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1176 web_prefs->allow_displaying_insecure_content =
1177 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1178 web_prefs->allow_running_insecure_content =
1179 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]f3986f82012-01-03 20:00:061180
[email protected]64d69de42012-02-06 00:19:541181 // The user stylesheet watcher may not exist in a testing profile.
1182 if (profile->GetUserStyleSheetWatcher()) {
1183 web_prefs->user_style_sheet_enabled = true;
1184 web_prefs->user_style_sheet_location =
1185 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1186 } else {
1187 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061188 }
1189
[email protected]64d69de42012-02-06 00:19:541190 web_prefs->unified_textchecker_enabled = CommandLine::ForCurrentProcess()->
1191 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571192
[email protected]64d69de42012-02-06 00:19:541193 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061194 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541195 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061196 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541197 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061198 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1199
1200 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541201 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061202 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541203 web_prefs->default_encoding);
1204 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061205 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541206 web_prefs->default_encoding =
1207 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061208 }
[email protected]64d69de42012-02-06 00:19:541209 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061210
1211 ExtensionService* service = profile->GetExtensionService();
1212 if (service) {
1213 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331214 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061215 extension_webkit_preferences::SetPreferences(
[email protected]64d69de42012-02-06 00:19:541216 extension, rvh->delegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061217 }
1218
1219 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541220 web_prefs->allow_scripts_to_close_windows = true;
[email protected]f3986f82012-01-03 20:00:061221 } else if (rvh->delegate()->GetRenderViewType() ==
1222 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1223 // Disable all kinds of acceleration for background pages.
1224 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541225 web_prefs->force_compositing_mode = false;
1226 web_prefs->accelerated_compositing_enabled = false;
1227 web_prefs->accelerated_2d_canvas_enabled = false;
1228 web_prefs->accelerated_video_enabled = false;
1229 web_prefs->accelerated_painting_enabled = false;
1230 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061231 }
[email protected]181a95ee2011-07-12 19:26:361232}
1233
1234void ChromeContentBrowserClient::UpdateInspectorSetting(
1235 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061236 content::BrowserContext* browser_context =
1237 rvh->process()->GetBrowserContext();
1238 DictionaryPrefUpdate update(
1239 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1240 prefs::kWebKitInspectorSettings);
1241 DictionaryValue* inspector_settings = update.Get();
1242 inspector_settings->SetWithoutPathExpansion(key,
1243 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361244}
1245
1246void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061247 content::BrowserContext* browser_context =
1248 rvh->process()->GetBrowserContext();
1249 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1250 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361251}
1252
[email protected]b8148ac2011-07-13 22:03:251253void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1254 BrowserURLHandler* handler) {
1255 // Add the default URL handlers.
1256 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1257 BrowserURLHandler::null_handler());
1258 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1259 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1260
[email protected]b3adbd02011-11-30 22:23:271261 // about: handler. Must come before chrome: handler, since it will
1262 // rewrite about: urls to chrome: URLs and then expect chrome: to
1263 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251264 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1265 BrowserURLHandler::null_handler());
1266 // chrome: & friends.
1267 handler->AddHandlerPair(&HandleWebUI,
1268 BrowserURLHandler::null_handler());
1269}
1270
1271void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371272 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301273 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251274 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1275 BrowsingDataRemover::EVERYTHING,
1276 base::Time());
1277 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1278 // BrowsingDataRemover takes care of deleting itself when done.
1279}
1280
1281void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371282 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301283 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251284 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1285 BrowsingDataRemover::EVERYTHING,
1286 base::Time());
[email protected]dceaa912011-09-06 17:17:231287 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251288 remover->Remove(remove_mask);
1289 // BrowsingDataRemover takes care of deleting itself when done.
1290}
1291
[email protected]e1d16eb92011-08-18 23:19:321292FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1293 return download_util::GetDefaultDownloadDirectory();
1294}
1295
[email protected]c9b6eb62011-10-18 20:49:391296std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1297 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1298}
1299
[email protected]e60c0232011-11-11 19:56:351300#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301301int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521302 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141303#if defined(OS_ANDROID)
1304 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1305 // fork. http://crbug.com/113560
1306 NOTIMPLEMENTED();
1307#else
[email protected]718eab62011-10-05 21:16:521308 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071309 ExtensionCrashHandlerHostLinux* crash_handler =
1310 ExtensionCrashHandlerHostLinux::GetInstance();
1311 return crash_handler->GetDeathSignalSocket();
1312 }
1313
[email protected]718eab62011-10-05 21:16:521314 std::string process_type =
1315 command_line.GetSwitchValueASCII(switches::kProcessType);
1316
1317 if (process_type == switches::kRendererProcess)
1318 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1319
[email protected]b80f68432011-05-02 17:22:301320 if (process_type == switches::kPluginProcess)
1321 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1322
1323 if (process_type == switches::kPpapiPluginProcess)
1324 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1325
1326 if (process_type == switches::kGpuProcess)
1327 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141328#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301329
1330 return -1;
1331}
[email protected]e60c0232011-11-11 19:56:351332#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301333
[email protected]4a65826d2011-08-25 16:04:011334#if defined(OS_WIN)
1335const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1336 return chrome::kBrowserResourcesDll;
1337}
1338#endif
1339
[email protected]37a72af2011-06-13 05:42:011340#if defined(USE_NSS)
1341crypto::CryptoModuleBlockingPasswordDelegate*
1342 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1343 const GURL& url) {
1344 return browser::NewCryptoModuleBlockingDialogDelegate(
1345 browser::kCryptoModulePasswordKeygen, url.host());
1346}
1347#endif
1348
[email protected]d977f9c2011-03-14 16:10:261349} // namespace chrome