blob: 2c4ce1271c85721beaf0300d890500b63e8a0104 [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]f3986f82012-01-03 20:00:0669#include "content/browser/child_process_security_policy.h"
[email protected]d977f9c2011-03-14 16:10:2670#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4971#include "content/browser/resource_context.h"
[email protected]f9034cf2011-07-21 12:43:4172#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4573#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]b48c9182011-10-26 18:03:3074#include "content/public/browser/browser_main_parts.h"
[email protected]f3b1a082011-11-18 00:34:3075#include "content/public/browser/render_process_host.h"
[email protected]b6583592012-01-25 19:52:3376#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1977#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1078#include "content/public/browser/web_contents_view.h"
[email protected]c9b6eb62011-10-18 20:49:3979#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3480#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0181#include "net/base/cookie_monster.h"
82#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3983#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0884#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3685#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2686
[email protected]b48c9182011-10-26 18:03:3087#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3888#include "chrome/browser/chrome_browser_main_win.h"
89#elif defined(OS_MACOSX)
90#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5691#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3092#elif defined(OS_CHROMEOS)
93#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3594#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3095#include "chrome/browser/chrome_browser_main_linux.h"
96#elif defined(OS_POSIX)
97#include "chrome/browser/chrome_browser_main_posix.h"
98#endif
99
[email protected]b48c9182011-10-26 18:03:30100#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31101#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38102#endif
103
[email protected]c7480942011-11-08 19:18:27104#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31105#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27106#endif
107
108#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31109#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
110#endif
111
[email protected]e60c0232011-11-11 19:56:35112#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30113#include "base/linux_util.h"
114#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43115#endif
[email protected]b80f68432011-05-02 17:22:30116
[email protected]080f34f2011-09-20 05:39:26117#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32118#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21119#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45120#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]90580422012-01-12 00:26:22121#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32122#elif defined(OS_MACOSX)
[email protected]cce3ab72012-02-04 18:05:16123#include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h"
[email protected]eb668c92012-02-06 15:35:29124#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32125#endif
126
[email protected]37a72af2011-06-13 05:42:01127#if defined(USE_NSS)
128#include "chrome/browser/ui/crypto_module_password_dialog.h"
129#endif
130
[email protected]c8c77182011-12-21 15:04:47131using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39132using content::BrowserThread;
[email protected]b6583592012-01-25 19:52:33133using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13134using content::WebContents;
[email protected]631bb742011-11-02 11:29:39135
[email protected]c5dbef02011-05-13 05:06:09136namespace {
137
[email protected]b8148ac2011-07-13 22:03:25138// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42139bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50140 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
141 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25142 return false;
143
144 // Special case the new tab page. In older versions of Chrome, the new tab
145 // page was hosted at chrome-internal:<blah>. This might be in people's saved
146 // sessions or bookmarks, so we say any URL with that scheme triggers the new
147 // tab page.
148 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
149 // Rewrite it with the proper new tab URL.
150 *url = GURL(chrome::kChromeUINewTabURL);
151 }
152
153 return true;
154}
155
[email protected]8d3132f62011-10-12 07:13:42156// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
157// below. Extension, and isolated apps require different privileges to be
158// granted to their RenderProcessHosts. This classification allows us to make
159// sure URLs are served by hosts with the right set of privileges.
160enum RenderProcessHostPrivilege {
161 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45162 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42163 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45164 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42165};
166
167RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
168 const GURL& url,
169 ExtensionService* service) {
170 // Default to a normal renderer cause it is lower privileged. This should only
171 // occur if the URL on a site instance is either malformed, or uninitialized.
172 // If it is malformed, then there is no need for better privileges anyways.
173 // If it is uninitialized, but eventually settles on being an a scheme other
174 // than normal webrenderer, the navigation logic will correct us out of band
175 // anyways.
176 if (!url.is_valid())
177 return PRIV_NORMAL;
178
179 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44180 const Extension* extension =
181 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45182 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42183 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45184 if (extension && extension->is_hosted_app())
185 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42186
187 return PRIV_EXTENSION;
188 }
189
190 return PRIV_NORMAL;
191}
192
193RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30194 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46195 extensions::ProcessMap* process_map,
196 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46197 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30198 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46199 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21200 return PRIV_NORMAL;
201
[email protected]6f371442011-11-09 06:45:46202 for (std::set<std::string>::iterator iter = extension_ids.begin();
203 iter != extension_ids.end(); ++iter) {
204 const Extension* extension = service->GetExtensionById(*iter, false);
205 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42206 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45207 if (extension && extension->is_hosted_app())
208 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42209 }
210
[email protected]676f6ab2011-10-19 20:23:21211 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42212}
213
[email protected]eec0b33c2011-12-05 22:09:45214bool IsIsolatedAppInProcess(const GURL& site_url,
215 content::RenderProcessHost* process_host,
216 extensions::ProcessMap* process_map,
217 ExtensionService* service) {
218 std::set<std::string> extension_ids =
219 process_map->GetExtensionsInProcess(process_host->GetID());
220 if (extension_ids.empty())
221 return false;
222
223 for (std::set<std::string>::iterator iter = extension_ids.begin();
224 iter != extension_ids.end(); ++iter) {
225 const Extension* extension = service->GetExtensionById(*iter, false);
226 if (extension &&
227 extension->is_storage_isolated() &&
228 extension->url() == site_url)
229 return true;
230 }
231
232 return false;
233}
234
[email protected]6786bf402011-12-03 15:19:45235bool CertMatchesFilter(const net::X509Certificate& cert,
236 const base::DictionaryValue& filter) {
237 // TODO(markusheintz): This is the minimal required filter implementation.
238 // Implement a better matcher.
239
240 // An empty filter matches any client certificate since no requirements are
241 // specified at all.
242 if (filter.empty())
243 return true;
244
245 std::string common_name;
246 if (filter.GetString("ISSUER.CN", &common_name) &&
247 (cert.issuer().common_name == common_name)) {
248 return true;
249 }
250 return false;
251}
252
[email protected]f3986f82012-01-03 20:00:06253// Fills |map| with the per-script font prefs under path |map_name|.
254void FillFontFamilyMap(const PrefService* prefs,
255 const char* map_name,
256 WebPreferences::ScriptFontFamilyMap* map) {
257 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
258 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
259 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
260 std::string font_family = prefs->GetString(pref_name.c_str());
261 if (!font_family.empty())
262 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
263 }
264}
265
[email protected]9dbfff12011-07-01 19:37:07266} // namespace
[email protected]c5dbef02011-05-13 05:06:09267
[email protected]d977f9c2011-03-14 16:10:26268namespace chrome {
269
[email protected]50462bf02011-11-21 19:13:31270content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
271 const content::MainFunctionParams& parameters) {
272 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30273 // Construct the Main browser parts based on the OS type.
274#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31275 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04276#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31277 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30278#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31279 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35280#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31281 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30282#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31283 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04284#else
[email protected]b48c9182011-10-26 18:03:30285 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31286 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30287#endif
288
[email protected]c7480942011-11-08 19:18:27289 // Construct additional browser parts. Stages are called in the order in
290 // which they are added.
[email protected]b48c9182011-10-26 18:03:30291#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31292 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04293#endif
[email protected]c7480942011-11-08 19:18:27294
295#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31296 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27297#endif
298
299#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31300 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27301#endif
302
[email protected]50462bf02011-11-21 19:13:31303 return main_parts;
[email protected]f967b722011-09-07 00:58:04304}
305
[email protected]8643e6d2012-01-18 20:26:10306content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35307 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26308#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35309 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21310#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35311 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22312 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32313#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29314 return web_contents_view_mac::CreateWebContentsView(
[email protected]cce3ab72012-02-04 18:05:16315 web_contents,
316 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
317 web_contents));
[email protected]74313b42011-08-24 16:51:32318#else
[email protected]8643e6d2012-01-18 20:26:10319#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32320#endif
321}
322
[email protected]f364d1392011-04-08 21:03:10323void ChromeContentBrowserClient::RenderViewHostCreated(
324 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46325
326 SiteInstance* site_instance = render_view_host->site_instance();
327 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02328 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46329
330 new ChromeRenderViewHostObserver(render_view_host,
331 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10332 new ExtensionMessageHandler(render_view_host);
[email protected]85f0a572012-02-07 22:20:13333
334 if (render_view_host->delegate()->GetRenderViewType() ==
335 content::VIEW_TYPE_INTERSTITIAL_PAGE) {
336 render_view_host->Send(new ChromeViewMsg_SetAsInterstitial(
337 render_view_host->routing_id()));
338 }
[email protected]d977f9c2011-03-14 16:10:26339}
340
[email protected]f3b1a082011-11-18 00:34:30341void ChromeContentBrowserClient::RenderProcessHostCreated(
342 content::RenderProcessHost* host) {
343 int id = host->GetID();
344 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
345 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02346 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30347 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
348 host->GetChannel()->AddFilter(new PrintingMessageFilter());
349 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02350 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30351 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56352#if defined(OS_MACOSX)
353 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
354#endif
[email protected]f3b1a082011-11-18 00:34:30355 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03356 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38357
[email protected]2ccf45c2011-08-19 23:35:50358 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
359 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07360
361 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56362
363 RendererContentSettingRules rules;
364 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
365 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14366}
367
[email protected]863f70a2012-01-27 02:05:50368content::WebUIControllerFactory*
369 ChromeContentBrowserClient::GetWebUIControllerFactory() {
370 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56371}
372
[email protected]3d7474ff2011-07-27 17:47:37373GURL ChromeContentBrowserClient::GetEffectiveURL(
374 content::BrowserContext* browser_context, const GURL& url) {
375 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08376 // Get the effective URL for the given actual URL. If the URL is part of an
377 // installed app, the effective URL is an extension URL with the ID of that
378 // extension as the host. This has the effect of grouping apps together in
379 // a common SiteInstance.
380 if (!profile || !profile->GetExtensionService())
381 return url;
382
[email protected]615d88f2011-12-13 01:47:44383 const Extension* extension = profile->GetExtensionService()->extensions()->
384 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08385 if (!extension)
386 return url;
387
[email protected]15877ca2011-11-18 22:40:52388 // Bookmark apps do not use the hosted app process model, and should be
389 // treated as normal URLs.
390 if (extension->from_bookmark())
391 return url;
392
[email protected]36fb2c7c2011-04-04 15:49:08393 // If the URL is part of an extension's web extent, convert it to an
394 // extension URL.
395 return extension->GetResourceURL(url.path());
396}
397
[email protected]056ad2a2011-07-12 02:13:55398bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37399 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55400 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52401 // Because we expect to use the effective URL, URLs for hosted apps (apart
402 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55403 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
404 return false;
405
[email protected]3d7474ff2011-07-27 17:47:37406 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55407 if (!profile || !profile->GetExtensionService())
408 return false;
409
[email protected]615d88f2011-12-13 01:47:44410 const Extension* extension = profile->GetExtensionService()->extensions()->
411 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55412 if (!extension)
413 return false;
414
415 // If the URL is part of a hosted app that does not have the background
416 // permission, we want to give each instance its own process to improve
417 // responsiveness.
418 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
419 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
420 return false;
421
422 // Hosted apps that have the background permission must use process per site,
423 // since all instances can make synchronous calls to the background window.
424 // Other extensions should use process per site as well.
425 return true;
426}
427
[email protected]46fb9442011-12-09 17:57:47428bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
429 return ProfileIOData::IsHandledURL(url);
430}
431
[email protected]2a5221b2011-09-27 23:07:31432bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30433 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31434 const GURL& site_url) {
435 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30436 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42437 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46438 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31439
[email protected]ffa97602011-11-17 17:55:52440 // Don't allow the Task Manager to share a process with anything else.
441 // Otherwise it can affect the renderers it is observing.
442 // Note: we could create another RenderProcessHostPrivilege bucket for
443 // this to allow multiple chrome://tasks instances to share, but that's
444 // a very unlikely case without serious consequences.
445 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
446 return false;
447
[email protected]8d3132f62011-10-12 07:13:42448 // These may be NULL during tests. In that case, just assume any site can
449 // share any host.
[email protected]6f371442011-11-09 06:45:46450 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31451 return true;
452
[email protected]a8c269a2011-10-25 20:17:22453 // Experimental:
454 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
455 // to share a renderer process. (We could allow pages from the same site or
456 // extensions of the same type to share, if we knew what the given process
457 // was dedicated to. Allowing no sharing is simpler for now.) This may
458 // cause resource exhaustion issues if too many sites are open at once.
459 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
460 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
461 return false;
462
[email protected]eec0b33c2011-12-05 22:09:45463 // An isolated app is only allowed to share with the exact same app in order
464 // to provide complete renderer process isolation. This also works around
465 // issue http://crbug.com/85588, where different isolated apps in the same
466 // process would end up using the first app's storage contexts.
467 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42468 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45469 if (privilege_required == PRIV_ISOLATED)
470 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
471
472 // Otherwise, just make sure the process privilege matches the privilege
473 // required by the site.
474 return GetProcessPrivilege(process_host, process_map, service) ==
475 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31476}
477
[email protected]6f371442011-11-09 06:45:46478void ChromeContentBrowserClient::SiteInstanceGotProcess(
479 SiteInstance* site_instance) {
480 CHECK(site_instance->HasProcess());
481
482 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02483 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46484 ExtensionService* service = profile->GetExtensionService();
485 if (!service)
486 return;
487
488 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44489 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33490 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46491 if (!extension)
492 return;
493
[email protected]6bc04fd82011-12-04 02:29:35494 service->process_map()->Insert(extension->id(),
495 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33496 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46497 BrowserThread::PostTask(
498 BrowserThread::IO, FROM_HERE,
499 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
500 profile->GetExtensionInfoMap(),
501 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35502 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33503 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46504}
505
506void ChromeContentBrowserClient::SiteInstanceDeleting(
507 SiteInstance* site_instance) {
508 if (!site_instance->HasProcess())
509 return;
510
511 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02512 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46513 ExtensionService* service = profile->GetExtensionService();
514 if (!service)
515 return;
516
517 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44518 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33519 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46520 if (!extension)
521 return;
522
[email protected]6bc04fd82011-12-04 02:29:35523 service->process_map()->Remove(extension->id(),
524 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33525 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46526 BrowserThread::PostTask(
527 BrowserThread::IO, FROM_HERE,
528 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
529 profile->GetExtensionInfoMap(),
530 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35531 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33532 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46533}
534
[email protected]e3daf3c2011-10-05 21:17:08535bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
536 const GURL& current_url,
537 const GURL& new_url) {
538 if (current_url.is_empty()) {
539 // Always choose a new process when navigating to extension URLs. The
540 // process grouping logic will combine all of a given extension's pages
541 // into the same process.
542 if (new_url.SchemeIs(chrome::kExtensionScheme))
543 return true;
544
545 return false;
546 }
547
548 // Also, we must switch if one is an extension and the other is not the exact
549 // same extension.
550 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
551 new_url.SchemeIs(chrome::kExtensionScheme)) {
552 if (current_url.GetOrigin() != new_url.GetOrigin())
553 return true;
554 }
555
556 return false;
557}
558
[email protected]763ec4ca2011-04-29 15:48:12559std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
560 const std::string& alias_name) {
561 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
562}
563
[email protected]b80f68432011-05-02 17:22:30564void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
565 CommandLine* command_line, int child_process_id) {
566#if defined(USE_LINUX_BREAKPAD)
567 if (IsCrashReporterEnabled()) {
568 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
569 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
570 }
571#elif defined(OS_MACOSX)
572 if (IsCrashReporterEnabled()) {
573 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
574 child_process_logging::GetClientId());
575 }
576#endif // OS_MACOSX
577
[email protected]f1933792011-06-14 00:49:34578 if (logging::DialogsAreSuppressed())
579 command_line->AppendSwitch(switches::kNoErrorDialogs);
580
[email protected]b80f68432011-05-02 17:22:30581 std::string process_type =
582 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17583 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52584 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30585 FilePath user_data_dir =
586 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
587 if (!user_data_dir.empty())
588 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
589#if defined(OS_CHROMEOS)
590 const std::string& login_profile =
591 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
592 if (!login_profile.empty())
593 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
594#endif
595
[email protected]f3b1a082011-11-18 00:34:30596 content::RenderProcessHost* process =
597 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37598 if (process) {
599 Profile* profile = Profile::FromBrowserContext(
600 process->GetBrowserContext());
601 extensions::ProcessMap* process_map =
602 profile->GetExtensionService()->process_map();
603 if (process_map && process_map->Contains(process->GetID()))
604 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30605
[email protected]a8d851f82011-12-21 00:32:37606 PrefService* prefs = profile->GetPrefs();
607 // Currently this pref is only registered if applied via a policy.
608 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
609 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
610 // Turn this policy into a command line switch.
611 command_line->AppendSwitch(switches::kDisable3DAPIs);
612 }
[email protected]718eab62011-10-05 21:16:52613
[email protected]a8d851f82011-12-21 00:32:37614 // Disable client-side phishing detection in the renderer if it is
615 // disabled in the Profile preferences or the browser process.
616 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
617 !g_browser_process->safe_browsing_detection_service()) {
618 command_line->AppendSwitch(
619 switches::kDisableClientSidePhishingDetection);
620 }
[email protected]8c40da62011-07-13 22:58:46621 }
[email protected]47c7ec82012-01-18 03:29:21622 {
623 PrefService* local_state = g_browser_process->local_state();
624 if (local_state &&
625 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
626 command_line->AppendSwitch(switches::kRendererPrintPreview);
627 }
628 }
[email protected]4287a3d2011-06-13 23:56:51629
[email protected]47c7ec82012-01-18 03:29:21630 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51631 static const char* const kSwitchNames[] = {
632 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48633 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18634 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51635 switches::kAllowScriptingGallery,
636 switches::kAppsCheckoutURL,
637 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31638 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51639 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51640 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21641 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51642 switches::kEnableCrxlessWebApps,
643 switches::kEnableExperimentalExtensionApis,
644 switches::kEnableInBrowserThumbnailing,
645 switches::kEnableIPCFuzzing,
646 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53647 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51648 switches::kEnableWatchdog,
649 switches::kExperimentalSpellcheckerFeatures,
650 switches::kMemoryProfiling,
651 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04652 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51653 switches::kPpapiFlashArgs,
654 switches::kPpapiFlashInProcess,
655 switches::kPpapiFlashPath,
656 switches::kPpapiFlashVersion,
657 switches::kProfilingAtStart,
658 switches::kProfilingFile,
659 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51660 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38661 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51662 };
663
664 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
665 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17666 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38667 static const char* const kSwitchNames[] = {
668 switches::kEnableExperimentalExtensionApis,
669 switches::kWhitelistedExtensionID,
670 };
671
672 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
673 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51674 } else if (process_type == switches::kPluginProcess) {
675 static const char* const kSwitchNames[] = {
676 #if defined(OS_CHROMEOS)
677 switches::kLoginProfile,
678 #endif
679 switches::kMemoryProfiling,
680 switches::kSilentDumpOnDCHECK,
681 switches::kUserDataDir,
682 };
683
684 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
685 arraysize(kSwitchNames));
686 } else if (process_type == switches::kZygoteProcess) {
687 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51688 switches::kUserDataDir, // Make logs go to the right file.
689 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
690 switches::kPpapiFlashInProcess,
691 switches::kPpapiFlashPath,
692 switches::kPpapiFlashVersion,
693 };
694
695 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
696 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30697 }
[email protected]6f08af82011-09-15 01:19:03698
699 // The command line switch kEnableBenchmarking needs to be specified along
700 // with the kEnableStatsTable switch to ensure that the stats table global
701 // is initialized correctly.
702 if (command_line->HasSwitch(switches::kEnableBenchmarking))
703 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30704}
705
706std::string ChromeContentBrowserClient::GetApplicationLocale() {
707 return g_browser_process->GetApplicationLocale();
708}
709
[email protected]597a867b2011-11-18 18:31:20710std::string ChromeContentBrowserClient::GetAcceptLangs(
711 content::BrowserContext* context) {
712 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37713 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08714}
715
[email protected]ac55e292011-06-24 05:16:08716SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22717 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08718 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
719}
720
[email protected]a2176792011-05-08 19:30:49721bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09722 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19723 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09724 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
726 ProfileIOData* io_data =
727 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05728 return io_data->GetCookieSettings()->
729 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49730}
731
[email protected]ed24fad2011-05-10 22:44:01732bool ChromeContentBrowserClient::AllowGetCookie(
733 const GURL& url,
734 const GURL& first_party,
735 const net::CookieList& cookie_list,
736 const content::ResourceContext& context,
737 int render_process_id,
738 int render_view_id) {
739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32740 ProfileIOData* io_data =
741 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05742 bool allow = io_data->GetCookieSettings()->
743 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01744
[email protected]8093a542011-05-13 07:29:32745 BrowserThread::PostTask(
746 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03747 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
748 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01749 return allow;
750}
751
752bool ChromeContentBrowserClient::AllowSetCookie(
753 const GURL& url,
754 const GURL& first_party,
755 const std::string& cookie_line,
756 const content::ResourceContext& context,
757 int render_process_id,
758 int render_view_id,
759 net::CookieOptions* options) {
760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32761 ProfileIOData* io_data =
762 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01763
[email protected]30fde822011-10-28 09:49:05764 CookieSettings* cookie_settings = io_data->GetCookieSettings();
765 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
766
767 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09768 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01769
[email protected]8093a542011-05-13 07:29:32770 BrowserThread::PostTask(
771 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03772 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
773 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01774 return allow;
775}
776
[email protected]d5a19162011-06-30 18:51:54777bool ChromeContentBrowserClient::AllowSaveLocalState(
778 const content::ResourceContext& context) {
779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
780 ProfileIOData* io_data =
781 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
782 return !io_data->clear_local_state_on_exit()->GetValue();
783}
784
[email protected]5c5a88e2011-11-12 00:45:35785bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35786 const GURL& url,
787 const string16& name,
788 const string16& display_name,
789 unsigned long estimated_size,
[email protected]62151052012-02-01 18:40:48790 const content::ResourceContext& context,
791 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35792 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
793 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
[email protected]62151052012-02-01 18:40:48794 context.GetUserData(NULL));
[email protected]5c5a88e2011-11-12 00:45:35795 CookieSettings* cookie_settings = io_data->GetCookieSettings();
796 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
797
[email protected]62151052012-02-01 18:40:48798 // Record access to database for potential display in UI.
799 std::vector<std::pair<int, int> >::const_iterator i;
800 for (i = render_views.begin(); i != render_views.end(); ++i) {
801 BrowserThread::PostTask(
802 BrowserThread::UI, FROM_HERE,
803 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
804 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35805 }
806
807 return allow;
808}
809
810bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35811 const GURL& url,
[email protected]62151052012-02-01 18:40:48812 const content::ResourceContext& context,
813 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
815 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
[email protected]62151052012-02-01 18:40:48816 context.GetUserData(NULL));
[email protected]5c5a88e2011-11-12 00:45:35817 CookieSettings* cookie_settings = io_data->GetCookieSettings();
818 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
819
[email protected]62151052012-02-01 18:40:48820 // Record access to file system for potential display in UI.
821 std::vector<std::pair<int, int> >::const_iterator i;
822 for (i = render_views.begin(); i != render_views.end(); ++i) {
823 BrowserThread::PostTask(
824 BrowserThread::UI, FROM_HERE,
825 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
826 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35827 }
828
829 return allow;
830}
831
[email protected]6133f922011-07-01 21:34:34832net::URLRequestContext*
833ChromeContentBrowserClient::OverrideRequestContextForURL(
834 const GURL& url, const content::ResourceContext& context) {
835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
836 if (url.SchemeIs(chrome::kExtensionScheme)) {
837 ProfileIOData* io_data =
838 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
839 return io_data->extensions_request_context();
840 }
841
842 return NULL;
843}
844
[email protected]317f96c92011-05-31 06:53:41845QuotaPermissionContext*
846ChromeContentBrowserClient::CreateQuotaPermissionContext() {
847 return new ChromeQuotaPermissionContext();
848}
849
[email protected]a0ce3282011-08-19 20:49:52850void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42851 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42852}
853
[email protected]a0ce3282011-08-19 20:49:52854void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52855 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52856}
857
[email protected]848dd042011-06-04 18:24:03858void ChromeContentBrowserClient::AllowCertificateError(
859 SSLCertErrorHandler* handler,
860 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58861 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41862 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13863 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]f9034cf2011-07-21 12:43:41864 handler->render_process_host_id(),
865 handler->tab_contents_id());
866 if (!tab) {
867 NOTREACHED();
868 return;
869 }
870 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50871 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30872 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09873 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41874 if (prerender_manager->prerender_tracker()->TryCancel(
875 handler->render_process_host_id(),
876 handler->tab_contents_id(),
877 prerender::FINAL_STATUS_SSL_ERROR)) {
878 handler->CancelRequest();
879 return;
880 }
881 }
882
883 // Otherwise, display an SSL blocking page.
[email protected]85f0a572012-02-07 22:20:13884 new SSLBlockingPage(handler, overridable, callback);
[email protected]848dd042011-06-04 18:24:03885}
886
[email protected]c99c442e2011-08-24 11:37:30887void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45888 int render_process_id,
889 int render_view_id,
890 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13891 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45892 render_process_id, render_view_id);
893 if (!tab) {
894 NOTREACHED();
895 return;
896 }
897
[email protected]6786bf402011-12-03 15:19:45898 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
899 GURL requesting_url("https://" + cert_request_info->host_and_port);
900 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
901 << cert_request_info->host_and_port;
902
[email protected]627e0512011-12-21 22:55:30903 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45904 DCHECK(profile);
905 scoped_ptr<Value> filter(
906 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
907 requesting_url,
908 requesting_url,
909 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
910 std::string(), NULL));
911
912 if (filter.get()) {
913 // Try to automatically select a client certificate.
914 if (filter->IsType(Value::TYPE_DICTIONARY)) {
915 DictionaryValue* filter_dict =
916 static_cast<DictionaryValue*>(filter.get());
917
918 const std::vector<scoped_refptr<net::X509Certificate> >&
919 all_client_certs = cert_request_info->client_certs;
920 for (size_t i = 0; i < all_client_certs.size(); ++i) {
921 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
922 // Use the first certificate that is matched by the filter.
923 handler->CertificateSelected(all_client_certs[i]);
924 return;
925 }
926 }
927 } else {
928 NOTREACHED();
929 }
930 }
931
[email protected]8ec26472011-06-06 16:52:45932 TabContentsWrapper* wrapper =
933 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45934 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13935 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45936 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14937 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45938 handler->CertificateSelected(NULL);
939 return;
940 }
941 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45942}
943
944void ChromeContentBrowserClient::AddNewCertificate(
945 net::URLRequest* request,
946 net::X509Certificate* cert,
947 int render_process_id,
948 int render_view_id) {
949 // The handler will run the UI and delete itself when it's finished.
950 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
951}
952
[email protected]941623e2011-06-07 23:06:04953void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
954 const GURL& source_origin,
955 int callback_context,
956 int render_process_id,
957 int render_view_id) {
958 RenderViewHost* rvh = RenderViewHost::FromID(
959 render_process_id, render_view_id);
960 if (!rvh) {
961 NOTREACHED();
962 return;
963 }
964
[email protected]f3b1a082011-11-18 00:34:30965 content::RenderProcessHost* process = rvh->process();
966 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04967 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37968 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04969 service->RequestPermission(
970 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:13971 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:04972}
973
974WebKit::WebNotificationPresenter::Permission
975 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02976 const GURL& source_origin,
977 const content::ResourceContext& context,
978 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04979 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
980 ProfileIOData* io_data =
981 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
982
[email protected]34eec7ffe32011-11-02 23:49:02983 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
984 source_origin, render_process_id,
985 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04986 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04987
988 // Fall back to the regular notification preferences, which works on an
989 // origin basis.
990 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:37991 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:04992 WebKit::WebNotificationPresenter::PermissionNotAllowed;
993}
994
995void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:17996 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:04997 int render_process_id,
998 int render_view_id,
999 bool worker) {
1000 RenderViewHost* rvh = RenderViewHost::FromID(
1001 render_process_id, render_view_id);
1002 if (!rvh) {
1003 NOTREACHED();
1004 return;
1005 }
1006
[email protected]f3b1a082011-11-18 00:34:301007 content::RenderProcessHost* process = rvh->process();
1008 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041009 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371010 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041011 service->ShowDesktopNotification(
1012 params, render_process_id, render_view_id,
1013 worker ? DesktopNotificationService::WorkerNotification :
1014 DesktopNotificationService::PageNotification);
1015}
1016
1017void ChromeContentBrowserClient::CancelDesktopNotification(
1018 int render_process_id,
1019 int render_view_id,
1020 int notification_id) {
1021 RenderViewHost* rvh = RenderViewHost::FromID(
1022 render_process_id, render_view_id);
1023 if (!rvh) {
1024 NOTREACHED();
1025 return;
1026 }
1027
[email protected]f3b1a082011-11-18 00:34:301028 content::RenderProcessHost* process = rvh->process();
1029 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041030 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371031 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041032 service->CancelDesktopNotification(
1033 render_process_id, render_view_id, notification_id);
1034}
1035
[email protected]9f3fba52011-06-08 20:37:191036bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021037 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191038 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021039 const content::ResourceContext& context,
1040 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191041 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1042 // If the opener is trying to create a background window but doesn't have
1043 // the appropriate permission, fail the attempt.
1044 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1045 ProfileIOData* io_data =
1046 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021047 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1048 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191049 }
1050 return true;
1051}
1052
1053std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1054 const GURL& url, const content::ResourceContext& context) {
1055 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1056 // Check if it's an extension-created worker, in which case we want to use
1057 // the name of the extension.
1058 ProfileIOData* io_data =
1059 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1060 const Extension* extension =
1061 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1062 return extension ? extension->name() : std::string();
1063}
1064
[email protected]99907362012-01-11 05:41:401065void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1066 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171067}
1068
1069ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1070 return g_browser_process->clipboard();
1071}
1072
[email protected]8f6a3b852011-07-19 16:48:561073MHTMLGenerationManager*
1074 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1075 return g_browser_process->mhtml_generation_manager();
1076}
1077
[email protected]ae6e9912011-07-27 01:18:281078net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1079 return g_browser_process->net_log();
1080}
1081
[email protected]3bc0b562011-08-24 23:51:041082speech_input::SpeechInputManager*
1083 ChromeContentBrowserClient::GetSpeechInputManager() {
1084 return speech_input::ChromeSpeechInputManager::GetInstance();
1085}
1086
[email protected]32538d92011-08-25 00:09:231087AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1088 return new ChromeAccessTokenStore();
1089}
1090
[email protected]dbae6b02011-06-29 23:51:411091bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1092 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1093 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1094}
1095
[email protected]64d69de42012-02-06 00:19:541096void ChromeContentBrowserClient::OverrideWebkitPrefs(
1097 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061098 Profile* profile = Profile::FromBrowserContext(
1099 rvh->process()->GetBrowserContext());
1100 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061101
[email protected]64d69de42012-02-06 00:19:541102 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061103 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541104 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061105 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541106 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061107 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541108 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061109 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541110 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061111 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541112 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061113 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1114
1115 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541116 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061117 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541118 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061119 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541120 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061121 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541122 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061123 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541124 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061125 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541126 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061127
[email protected]64d69de42012-02-06 00:19:541128 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061129 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541130 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061131 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541132 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061133 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541134 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061135 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1136
[email protected]64d69de42012-02-06 00:19:541137 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061138
[email protected]64d69de42012-02-06 00:19:541139 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061140 prefs->GetBoolean(
1141 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541142 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061143 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541144 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061145 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1146 const DictionaryValue* inspector_settings =
1147 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1148 if (inspector_settings) {
1149 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1150 iter != inspector_settings->end_keys(); ++iter) {
1151 std::string value;
1152 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541153 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061154 std::make_pair(*iter, value));
1155 }
1156 }
[email protected]64d69de42012-02-06 00:19:541157 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061158
[email protected]64d69de42012-02-06 00:19:541159 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1160 web_prefs->javascript_enabled = false;
1161 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1162 web_prefs->web_security_enabled = false;
1163 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1164 web_prefs->plugins_enabled = false;
1165 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1166 web_prefs->java_enabled = false;
1167 web_prefs->loads_images_automatically =
1168 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061169
[email protected]64d69de42012-02-06 00:19:541170 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1171 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061172
[email protected]64d69de42012-02-06 00:19:541173 web_prefs->memory_info_enabled =
1174 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1175 web_prefs->allow_displaying_insecure_content =
1176 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1177 web_prefs->allow_running_insecure_content =
1178 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]f3986f82012-01-03 20:00:061179
[email protected]64d69de42012-02-06 00:19:541180 // The user stylesheet watcher may not exist in a testing profile.
1181 if (profile->GetUserStyleSheetWatcher()) {
1182 web_prefs->user_style_sheet_enabled = true;
1183 web_prefs->user_style_sheet_location =
1184 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1185 } else {
1186 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061187 }
1188
[email protected]64d69de42012-02-06 00:19:541189 web_prefs->unified_textchecker_enabled = CommandLine::ForCurrentProcess()->
1190 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571191
[email protected]64d69de42012-02-06 00:19:541192 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061193 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541194 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061195 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541196 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061197 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1198
1199 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541200 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061201 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541202 web_prefs->default_encoding);
1203 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061204 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541205 web_prefs->default_encoding =
1206 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061207 }
[email protected]64d69de42012-02-06 00:19:541208 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061209
1210 ExtensionService* service = profile->GetExtensionService();
1211 if (service) {
1212 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331213 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061214 extension_webkit_preferences::SetPreferences(
[email protected]64d69de42012-02-06 00:19:541215 extension, rvh->delegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061216 }
1217
1218 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541219 web_prefs->allow_scripts_to_close_windows = true;
[email protected]f3986f82012-01-03 20:00:061220 } else if (rvh->delegate()->GetRenderViewType() ==
1221 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1222 // Disable all kinds of acceleration for background pages.
1223 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541224 web_prefs->force_compositing_mode = false;
1225 web_prefs->accelerated_compositing_enabled = false;
1226 web_prefs->accelerated_2d_canvas_enabled = false;
1227 web_prefs->accelerated_video_enabled = false;
1228 web_prefs->accelerated_painting_enabled = false;
1229 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061230 }
[email protected]181a95ee2011-07-12 19:26:361231}
1232
1233void ChromeContentBrowserClient::UpdateInspectorSetting(
1234 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061235 content::BrowserContext* browser_context =
1236 rvh->process()->GetBrowserContext();
1237 DictionaryPrefUpdate update(
1238 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1239 prefs::kWebKitInspectorSettings);
1240 DictionaryValue* inspector_settings = update.Get();
1241 inspector_settings->SetWithoutPathExpansion(key,
1242 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361243}
1244
1245void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061246 content::BrowserContext* browser_context =
1247 rvh->process()->GetBrowserContext();
1248 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1249 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361250}
1251
[email protected]b8148ac2011-07-13 22:03:251252void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1253 BrowserURLHandler* handler) {
1254 // Add the default URL handlers.
1255 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1256 BrowserURLHandler::null_handler());
1257 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1258 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1259
[email protected]b3adbd02011-11-30 22:23:271260 // about: handler. Must come before chrome: handler, since it will
1261 // rewrite about: urls to chrome: URLs and then expect chrome: to
1262 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251263 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1264 BrowserURLHandler::null_handler());
1265 // chrome: & friends.
1266 handler->AddHandlerPair(&HandleWebUI,
1267 BrowserURLHandler::null_handler());
1268}
1269
1270void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371271 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301272 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251273 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1274 BrowsingDataRemover::EVERYTHING,
1275 base::Time());
1276 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1277 // BrowsingDataRemover takes care of deleting itself when done.
1278}
1279
1280void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371281 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301282 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251283 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1284 BrowsingDataRemover::EVERYTHING,
1285 base::Time());
[email protected]dceaa912011-09-06 17:17:231286 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251287 remover->Remove(remove_mask);
1288 // BrowsingDataRemover takes care of deleting itself when done.
1289}
1290
[email protected]e1d16eb92011-08-18 23:19:321291FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1292 return download_util::GetDefaultDownloadDirectory();
1293}
1294
[email protected]c9b6eb62011-10-18 20:49:391295std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1296 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1297}
1298
[email protected]e60c0232011-11-11 19:56:351299#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301300int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521301 const CommandLine& command_line) {
1302 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071303 ExtensionCrashHandlerHostLinux* crash_handler =
1304 ExtensionCrashHandlerHostLinux::GetInstance();
1305 return crash_handler->GetDeathSignalSocket();
1306 }
1307
[email protected]718eab62011-10-05 21:16:521308 std::string process_type =
1309 command_line.GetSwitchValueASCII(switches::kProcessType);
1310
1311 if (process_type == switches::kRendererProcess)
1312 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1313
[email protected]b80f68432011-05-02 17:22:301314 if (process_type == switches::kPluginProcess)
1315 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1316
1317 if (process_type == switches::kPpapiPluginProcess)
1318 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1319
1320 if (process_type == switches::kGpuProcess)
1321 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1322
1323 return -1;
1324}
[email protected]e60c0232011-11-11 19:56:351325#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301326
[email protected]4a65826d2011-08-25 16:04:011327#if defined(OS_WIN)
1328const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1329 return chrome::kBrowserResourcesDll;
1330}
1331#endif
1332
[email protected]37a72af2011-06-13 05:42:011333#if defined(USE_NSS)
1334crypto::CryptoModuleBlockingPasswordDelegate*
1335 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1336 const GURL& url) {
1337 return browser::NewCryptoModuleBlockingDialogDelegate(
1338 browser::kCryptoModulePasswordKeygen, url.host());
1339}
1340#endif
1341
[email protected]d977f9c2011-03-14 16:10:261342} // namespace chrome