blob: db379fd2b92bfe477b71e4c474e3f4732c8cf49a [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]a2176792011-05-08 19:30:4970#include "content/browser/resource_context.h"
[email protected]f9034cf2011-07-21 12:43:4171#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4572#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]b48c9182011-10-26 18:03:3073#include "content/public/browser/browser_main_parts.h"
[email protected]b9535422012-02-09 01:47:5974#include "content/public/browser/child_process_security_policy.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]b9535422012-02-09 01:47:59133using content::ChildProcessSecurityPolicy;
[email protected]b6583592012-01-25 19:52:33134using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13135using content::WebContents;
[email protected]631bb742011-11-02 11:29:39136
[email protected]c5dbef02011-05-13 05:06:09137namespace {
138
[email protected]b8148ac2011-07-13 22:03:25139// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42140bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50141 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
142 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25143 return false;
144
145 // Special case the new tab page. In older versions of Chrome, the new tab
146 // page was hosted at chrome-internal:<blah>. This might be in people's saved
147 // sessions or bookmarks, so we say any URL with that scheme triggers the new
148 // tab page.
149 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
150 // Rewrite it with the proper new tab URL.
151 *url = GURL(chrome::kChromeUINewTabURL);
152 }
153
154 return true;
155}
156
[email protected]8d3132f62011-10-12 07:13:42157// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
158// below. Extension, and isolated apps require different privileges to be
159// granted to their RenderProcessHosts. This classification allows us to make
160// sure URLs are served by hosts with the right set of privileges.
161enum RenderProcessHostPrivilege {
162 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45163 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42164 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45165 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42166};
167
168RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
169 const GURL& url,
170 ExtensionService* service) {
171 // Default to a normal renderer cause it is lower privileged. This should only
172 // occur if the URL on a site instance is either malformed, or uninitialized.
173 // If it is malformed, then there is no need for better privileges anyways.
174 // If it is uninitialized, but eventually settles on being an a scheme other
175 // than normal webrenderer, the navigation logic will correct us out of band
176 // anyways.
177 if (!url.is_valid())
178 return PRIV_NORMAL;
179
180 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44181 const Extension* extension =
182 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45183 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42184 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45185 if (extension && extension->is_hosted_app())
186 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42187
188 return PRIV_EXTENSION;
189 }
190
191 return PRIV_NORMAL;
192}
193
194RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30195 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46196 extensions::ProcessMap* process_map,
197 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46198 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30199 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46200 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21201 return PRIV_NORMAL;
202
[email protected]6f371442011-11-09 06:45:46203 for (std::set<std::string>::iterator iter = extension_ids.begin();
204 iter != extension_ids.end(); ++iter) {
205 const Extension* extension = service->GetExtensionById(*iter, false);
206 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42207 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45208 if (extension && extension->is_hosted_app())
209 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42210 }
211
[email protected]676f6ab2011-10-19 20:23:21212 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42213}
214
[email protected]eec0b33c2011-12-05 22:09:45215bool IsIsolatedAppInProcess(const GURL& site_url,
216 content::RenderProcessHost* process_host,
217 extensions::ProcessMap* process_map,
218 ExtensionService* service) {
219 std::set<std::string> extension_ids =
220 process_map->GetExtensionsInProcess(process_host->GetID());
221 if (extension_ids.empty())
222 return false;
223
224 for (std::set<std::string>::iterator iter = extension_ids.begin();
225 iter != extension_ids.end(); ++iter) {
226 const Extension* extension = service->GetExtensionById(*iter, false);
227 if (extension &&
228 extension->is_storage_isolated() &&
229 extension->url() == site_url)
230 return true;
231 }
232
233 return false;
234}
235
[email protected]6786bf402011-12-03 15:19:45236bool CertMatchesFilter(const net::X509Certificate& cert,
237 const base::DictionaryValue& filter) {
238 // TODO(markusheintz): This is the minimal required filter implementation.
239 // Implement a better matcher.
240
241 // An empty filter matches any client certificate since no requirements are
242 // specified at all.
243 if (filter.empty())
244 return true;
245
246 std::string common_name;
247 if (filter.GetString("ISSUER.CN", &common_name) &&
248 (cert.issuer().common_name == common_name)) {
249 return true;
250 }
251 return false;
252}
253
[email protected]f3986f82012-01-03 20:00:06254// Fills |map| with the per-script font prefs under path |map_name|.
255void FillFontFamilyMap(const PrefService* prefs,
256 const char* map_name,
257 WebPreferences::ScriptFontFamilyMap* map) {
258 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
259 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
260 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
261 std::string font_family = prefs->GetString(pref_name.c_str());
262 if (!font_family.empty())
263 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
264 }
265}
266
[email protected]9dbfff12011-07-01 19:37:07267} // namespace
[email protected]c5dbef02011-05-13 05:06:09268
[email protected]d977f9c2011-03-14 16:10:26269namespace chrome {
270
[email protected]50462bf02011-11-21 19:13:31271content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
272 const content::MainFunctionParams& parameters) {
273 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30274 // Construct the Main browser parts based on the OS type.
275#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31276 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04277#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31278 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30279#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31280 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35281#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31282 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30283#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31284 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04285#else
[email protected]b48c9182011-10-26 18:03:30286 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31287 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30288#endif
289
[email protected]c7480942011-11-08 19:18:27290 // Construct additional browser parts. Stages are called in the order in
291 // which they are added.
[email protected]b48c9182011-10-26 18:03:30292#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31293 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04294#endif
[email protected]c7480942011-11-08 19:18:27295
296#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31297 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27298#endif
299
300#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31301 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27302#endif
303
[email protected]50462bf02011-11-21 19:13:31304 return main_parts;
[email protected]f967b722011-09-07 00:58:04305}
306
[email protected]8643e6d2012-01-18 20:26:10307content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35308 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26309#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35310 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21311#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35312 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22313 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32314#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29315 return web_contents_view_mac::CreateWebContentsView(
[email protected]cce3ab72012-02-04 18:05:16316 web_contents,
317 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
318 web_contents));
[email protected]74313b42011-08-24 16:51:32319#else
[email protected]8643e6d2012-01-18 20:26:10320#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32321#endif
322}
323
[email protected]f364d1392011-04-08 21:03:10324void ChromeContentBrowserClient::RenderViewHostCreated(
325 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46326
327 SiteInstance* site_instance = render_view_host->site_instance();
328 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02329 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46330
331 new ChromeRenderViewHostObserver(render_view_host,
332 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10333 new ExtensionMessageHandler(render_view_host);
[email protected]85f0a572012-02-07 22:20:13334
335 if (render_view_host->delegate()->GetRenderViewType() ==
336 content::VIEW_TYPE_INTERSTITIAL_PAGE) {
337 render_view_host->Send(new ChromeViewMsg_SetAsInterstitial(
338 render_view_host->routing_id()));
339 }
[email protected]d977f9c2011-03-14 16:10:26340}
341
[email protected]f3b1a082011-11-18 00:34:30342void ChromeContentBrowserClient::RenderProcessHostCreated(
343 content::RenderProcessHost* host) {
344 int id = host->GetID();
345 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
346 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02347 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30348 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
349 host->GetChannel()->AddFilter(new PrintingMessageFilter());
350 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02351 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30352 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56353#if defined(OS_MACOSX)
354 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
355#endif
[email protected]f3b1a082011-11-18 00:34:30356 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03357 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38358
[email protected]2ccf45c2011-08-19 23:35:50359 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
360 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07361
362 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56363
364 RendererContentSettingRules rules;
365 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
366 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14367}
368
[email protected]863f70a2012-01-27 02:05:50369content::WebUIControllerFactory*
370 ChromeContentBrowserClient::GetWebUIControllerFactory() {
371 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56372}
373
[email protected]3d7474ff2011-07-27 17:47:37374GURL ChromeContentBrowserClient::GetEffectiveURL(
375 content::BrowserContext* browser_context, const GURL& url) {
376 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08377 // Get the effective URL for the given actual URL. If the URL is part of an
378 // installed app, the effective URL is an extension URL with the ID of that
379 // extension as the host. This has the effect of grouping apps together in
380 // a common SiteInstance.
381 if (!profile || !profile->GetExtensionService())
382 return url;
383
[email protected]615d88f2011-12-13 01:47:44384 const Extension* extension = profile->GetExtensionService()->extensions()->
385 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08386 if (!extension)
387 return url;
388
[email protected]15877ca2011-11-18 22:40:52389 // Bookmark apps do not use the hosted app process model, and should be
390 // treated as normal URLs.
391 if (extension->from_bookmark())
392 return url;
393
[email protected]36fb2c7c2011-04-04 15:49:08394 // If the URL is part of an extension's web extent, convert it to an
395 // extension URL.
396 return extension->GetResourceURL(url.path());
397}
398
[email protected]056ad2a2011-07-12 02:13:55399bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37400 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55401 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52402 // Because we expect to use the effective URL, URLs for hosted apps (apart
403 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55404 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
405 return false;
406
[email protected]3d7474ff2011-07-27 17:47:37407 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55408 if (!profile || !profile->GetExtensionService())
409 return false;
410
[email protected]615d88f2011-12-13 01:47:44411 const Extension* extension = profile->GetExtensionService()->extensions()->
412 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55413 if (!extension)
414 return false;
415
416 // If the URL is part of a hosted app that does not have the background
417 // permission, we want to give each instance its own process to improve
418 // responsiveness.
419 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
420 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
421 return false;
422
423 // Hosted apps that have the background permission must use process per site,
424 // since all instances can make synchronous calls to the background window.
425 // Other extensions should use process per site as well.
426 return true;
427}
428
[email protected]46fb9442011-12-09 17:57:47429bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
430 return ProfileIOData::IsHandledURL(url);
431}
432
[email protected]2a5221b2011-09-27 23:07:31433bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30434 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31435 const GURL& site_url) {
436 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30437 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42438 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46439 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31440
[email protected]ffa97602011-11-17 17:55:52441 // Don't allow the Task Manager to share a process with anything else.
442 // Otherwise it can affect the renderers it is observing.
443 // Note: we could create another RenderProcessHostPrivilege bucket for
444 // this to allow multiple chrome://tasks instances to share, but that's
445 // a very unlikely case without serious consequences.
446 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
447 return false;
448
[email protected]8d3132f62011-10-12 07:13:42449 // These may be NULL during tests. In that case, just assume any site can
450 // share any host.
[email protected]6f371442011-11-09 06:45:46451 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31452 return true;
453
[email protected]a8c269a2011-10-25 20:17:22454 // Experimental:
455 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
456 // to share a renderer process. (We could allow pages from the same site or
457 // extensions of the same type to share, if we knew what the given process
458 // was dedicated to. Allowing no sharing is simpler for now.) This may
459 // cause resource exhaustion issues if too many sites are open at once.
460 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
461 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
462 return false;
463
[email protected]eec0b33c2011-12-05 22:09:45464 // An isolated app is only allowed to share with the exact same app in order
465 // to provide complete renderer process isolation. This also works around
466 // issue http://crbug.com/85588, where different isolated apps in the same
467 // process would end up using the first app's storage contexts.
468 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42469 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45470 if (privilege_required == PRIV_ISOLATED)
471 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
472
473 // Otherwise, just make sure the process privilege matches the privilege
474 // required by the site.
475 return GetProcessPrivilege(process_host, process_map, service) ==
476 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31477}
478
[email protected]6f371442011-11-09 06:45:46479void ChromeContentBrowserClient::SiteInstanceGotProcess(
480 SiteInstance* site_instance) {
481 CHECK(site_instance->HasProcess());
482
483 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02484 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46485 ExtensionService* service = profile->GetExtensionService();
486 if (!service)
487 return;
488
489 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44490 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33491 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46492 if (!extension)
493 return;
494
[email protected]6bc04fd82011-12-04 02:29:35495 service->process_map()->Insert(extension->id(),
496 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33497 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46498 BrowserThread::PostTask(
499 BrowserThread::IO, FROM_HERE,
500 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
501 profile->GetExtensionInfoMap(),
502 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35503 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33504 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46505}
506
507void ChromeContentBrowserClient::SiteInstanceDeleting(
508 SiteInstance* site_instance) {
509 if (!site_instance->HasProcess())
510 return;
511
512 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02513 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46514 ExtensionService* service = profile->GetExtensionService();
515 if (!service)
516 return;
517
518 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44519 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33520 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46521 if (!extension)
522 return;
523
[email protected]6bc04fd82011-12-04 02:29:35524 service->process_map()->Remove(extension->id(),
525 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33526 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46527 BrowserThread::PostTask(
528 BrowserThread::IO, FROM_HERE,
529 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
530 profile->GetExtensionInfoMap(),
531 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35532 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33533 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46534}
535
[email protected]e3daf3c2011-10-05 21:17:08536bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
537 const GURL& current_url,
538 const GURL& new_url) {
539 if (current_url.is_empty()) {
540 // Always choose a new process when navigating to extension URLs. The
541 // process grouping logic will combine all of a given extension's pages
542 // into the same process.
543 if (new_url.SchemeIs(chrome::kExtensionScheme))
544 return true;
545
546 return false;
547 }
548
549 // Also, we must switch if one is an extension and the other is not the exact
550 // same extension.
551 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
552 new_url.SchemeIs(chrome::kExtensionScheme)) {
553 if (current_url.GetOrigin() != new_url.GetOrigin())
554 return true;
555 }
556
557 return false;
558}
559
[email protected]763ec4ca2011-04-29 15:48:12560std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
561 const std::string& alias_name) {
562 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
563}
564
[email protected]b80f68432011-05-02 17:22:30565void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
566 CommandLine* command_line, int child_process_id) {
567#if defined(USE_LINUX_BREAKPAD)
568 if (IsCrashReporterEnabled()) {
569 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
570 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
571 }
572#elif defined(OS_MACOSX)
573 if (IsCrashReporterEnabled()) {
574 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
575 child_process_logging::GetClientId());
576 }
577#endif // OS_MACOSX
578
[email protected]f1933792011-06-14 00:49:34579 if (logging::DialogsAreSuppressed())
580 command_line->AppendSwitch(switches::kNoErrorDialogs);
581
[email protected]b80f68432011-05-02 17:22:30582 std::string process_type =
583 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17584 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52585 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30586 FilePath user_data_dir =
587 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
588 if (!user_data_dir.empty())
589 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
590#if defined(OS_CHROMEOS)
591 const std::string& login_profile =
592 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
593 if (!login_profile.empty())
594 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
595#endif
596
[email protected]f3b1a082011-11-18 00:34:30597 content::RenderProcessHost* process =
598 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37599 if (process) {
600 Profile* profile = Profile::FromBrowserContext(
601 process->GetBrowserContext());
602 extensions::ProcessMap* process_map =
603 profile->GetExtensionService()->process_map();
604 if (process_map && process_map->Contains(process->GetID()))
605 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30606
[email protected]a8d851f82011-12-21 00:32:37607 PrefService* prefs = profile->GetPrefs();
608 // Currently this pref is only registered if applied via a policy.
609 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
610 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
611 // Turn this policy into a command line switch.
612 command_line->AppendSwitch(switches::kDisable3DAPIs);
613 }
[email protected]718eab62011-10-05 21:16:52614
[email protected]a8d851f82011-12-21 00:32:37615 // Disable client-side phishing detection in the renderer if it is
616 // disabled in the Profile preferences or the browser process.
617 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
618 !g_browser_process->safe_browsing_detection_service()) {
619 command_line->AppendSwitch(
620 switches::kDisableClientSidePhishingDetection);
621 }
[email protected]8c40da62011-07-13 22:58:46622 }
[email protected]47c7ec82012-01-18 03:29:21623 {
624 PrefService* local_state = g_browser_process->local_state();
625 if (local_state &&
626 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
627 command_line->AppendSwitch(switches::kRendererPrintPreview);
628 }
629 }
[email protected]4287a3d2011-06-13 23:56:51630
[email protected]47c7ec82012-01-18 03:29:21631 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51632 static const char* const kSwitchNames[] = {
633 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48634 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18635 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51636 switches::kAllowScriptingGallery,
637 switches::kAppsCheckoutURL,
638 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31639 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51640 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51641 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21642 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51643 switches::kEnableCrxlessWebApps,
644 switches::kEnableExperimentalExtensionApis,
645 switches::kEnableInBrowserThumbnailing,
646 switches::kEnableIPCFuzzing,
647 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53648 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51649 switches::kEnableWatchdog,
650 switches::kExperimentalSpellcheckerFeatures,
651 switches::kMemoryProfiling,
652 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04653 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51654 switches::kPpapiFlashArgs,
655 switches::kPpapiFlashInProcess,
656 switches::kPpapiFlashPath,
657 switches::kPpapiFlashVersion,
658 switches::kProfilingAtStart,
659 switches::kProfilingFile,
660 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51661 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38662 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51663 };
664
665 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
666 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17667 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38668 static const char* const kSwitchNames[] = {
669 switches::kEnableExperimentalExtensionApis,
670 switches::kWhitelistedExtensionID,
671 };
672
673 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
674 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51675 } else if (process_type == switches::kPluginProcess) {
676 static const char* const kSwitchNames[] = {
677 #if defined(OS_CHROMEOS)
678 switches::kLoginProfile,
679 #endif
680 switches::kMemoryProfiling,
681 switches::kSilentDumpOnDCHECK,
682 switches::kUserDataDir,
683 };
684
685 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
686 arraysize(kSwitchNames));
687 } else if (process_type == switches::kZygoteProcess) {
688 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51689 switches::kUserDataDir, // Make logs go to the right file.
690 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
691 switches::kPpapiFlashInProcess,
692 switches::kPpapiFlashPath,
693 switches::kPpapiFlashVersion,
694 };
695
696 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
697 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30698 }
[email protected]6f08af82011-09-15 01:19:03699
700 // The command line switch kEnableBenchmarking needs to be specified along
701 // with the kEnableStatsTable switch to ensure that the stats table global
702 // is initialized correctly.
703 if (command_line->HasSwitch(switches::kEnableBenchmarking))
704 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30705}
706
707std::string ChromeContentBrowserClient::GetApplicationLocale() {
708 return g_browser_process->GetApplicationLocale();
709}
710
[email protected]597a867b2011-11-18 18:31:20711std::string ChromeContentBrowserClient::GetAcceptLangs(
712 content::BrowserContext* context) {
713 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37714 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08715}
716
[email protected]ac55e292011-06-24 05:16:08717SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22718 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08719 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
720}
721
[email protected]a2176792011-05-08 19:30:49722bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09723 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19724 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20725 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20727 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[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,
[email protected]df02aca2012-02-09 21:03:20736 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01737 int render_process_id,
738 int render_view_id) {
739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20740 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05741 bool allow = io_data->GetCookieSettings()->
742 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01743
[email protected]8093a542011-05-13 07:29:32744 BrowserThread::PostTask(
745 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03746 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
747 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01748 return allow;
749}
750
751bool ChromeContentBrowserClient::AllowSetCookie(
752 const GURL& url,
753 const GURL& first_party,
754 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20755 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01756 int render_process_id,
757 int render_view_id,
758 net::CookieOptions* options) {
759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20760 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05761 CookieSettings* cookie_settings = io_data->GetCookieSettings();
762 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
763
764 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09765 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01766
[email protected]8093a542011-05-13 07:29:32767 BrowserThread::PostTask(
768 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03769 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
770 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01771 return allow;
772}
773
[email protected]d5a19162011-06-30 18:51:54774bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20775 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20777 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]d5a19162011-06-30 18:51:54778 return !io_data->clear_local_state_on_exit()->GetValue();
779}
780
[email protected]5c5a88e2011-11-12 00:45:35781bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35782 const GURL& url,
783 const string16& name,
784 const string16& display_name,
785 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20786 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48787 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35788 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20789 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35790 CookieSettings* cookie_settings = io_data->GetCookieSettings();
791 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
792
[email protected]62151052012-02-01 18:40:48793 // Record access to database for potential display in UI.
794 std::vector<std::pair<int, int> >::const_iterator i;
795 for (i = render_views.begin(); i != render_views.end(); ++i) {
796 BrowserThread::PostTask(
797 BrowserThread::UI, FROM_HERE,
798 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
799 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35800 }
801
802 return allow;
803}
804
805bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35806 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20807 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48808 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35809 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20810 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35811 CookieSettings* cookie_settings = io_data->GetCookieSettings();
812 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
813
[email protected]62151052012-02-01 18:40:48814 // Record access to file system for potential display in UI.
815 std::vector<std::pair<int, int> >::const_iterator i;
816 for (i = render_views.begin(); i != render_views.end(); ++i) {
817 BrowserThread::PostTask(
818 BrowserThread::UI, FROM_HERE,
819 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
820 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35821 }
822
823 return allow;
824}
825
[email protected]6133f922011-07-01 21:34:34826net::URLRequestContext*
827ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20828 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34829 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
830 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20831 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34832 return io_data->extensions_request_context();
833 }
834
835 return NULL;
836}
837
[email protected]317f96c92011-05-31 06:53:41838QuotaPermissionContext*
839ChromeContentBrowserClient::CreateQuotaPermissionContext() {
840 return new ChromeQuotaPermissionContext();
841}
842
[email protected]a0ce3282011-08-19 20:49:52843void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42844 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42845}
846
[email protected]a0ce3282011-08-19 20:49:52847void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52848 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52849}
850
[email protected]848dd042011-06-04 18:24:03851void ChromeContentBrowserClient::AllowCertificateError(
852 SSLCertErrorHandler* handler,
853 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58854 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41855 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13856 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]f9034cf2011-07-21 12:43:41857 handler->render_process_host_id(),
858 handler->tab_contents_id());
859 if (!tab) {
860 NOTREACHED();
861 return;
862 }
863 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50864 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30865 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09866 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41867 if (prerender_manager->prerender_tracker()->TryCancel(
868 handler->render_process_host_id(),
869 handler->tab_contents_id(),
870 prerender::FINAL_STATUS_SSL_ERROR)) {
871 handler->CancelRequest();
872 return;
873 }
874 }
875
876 // Otherwise, display an SSL blocking page.
[email protected]85f0a572012-02-07 22:20:13877 new SSLBlockingPage(handler, overridable, callback);
[email protected]848dd042011-06-04 18:24:03878}
879
[email protected]c99c442e2011-08-24 11:37:30880void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45881 int render_process_id,
882 int render_view_id,
883 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13884 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45885 render_process_id, render_view_id);
886 if (!tab) {
887 NOTREACHED();
888 return;
889 }
890
[email protected]6786bf402011-12-03 15:19:45891 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
892 GURL requesting_url("https://" + cert_request_info->host_and_port);
893 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
894 << cert_request_info->host_and_port;
895
[email protected]627e0512011-12-21 22:55:30896 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45897 DCHECK(profile);
898 scoped_ptr<Value> filter(
899 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
900 requesting_url,
901 requesting_url,
902 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
903 std::string(), NULL));
904
905 if (filter.get()) {
906 // Try to automatically select a client certificate.
907 if (filter->IsType(Value::TYPE_DICTIONARY)) {
908 DictionaryValue* filter_dict =
909 static_cast<DictionaryValue*>(filter.get());
910
911 const std::vector<scoped_refptr<net::X509Certificate> >&
912 all_client_certs = cert_request_info->client_certs;
913 for (size_t i = 0; i < all_client_certs.size(); ++i) {
914 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
915 // Use the first certificate that is matched by the filter.
916 handler->CertificateSelected(all_client_certs[i]);
917 return;
918 }
919 }
920 } else {
921 NOTREACHED();
922 }
923 }
924
[email protected]8ec26472011-06-06 16:52:45925 TabContentsWrapper* wrapper =
926 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45927 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13928 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45929 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14930 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45931 handler->CertificateSelected(NULL);
932 return;
933 }
934 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45935}
936
937void ChromeContentBrowserClient::AddNewCertificate(
938 net::URLRequest* request,
939 net::X509Certificate* cert,
940 int render_process_id,
941 int render_view_id) {
942 // The handler will run the UI and delete itself when it's finished.
943 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
944}
945
[email protected]941623e2011-06-07 23:06:04946void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
947 const GURL& source_origin,
948 int callback_context,
949 int render_process_id,
950 int render_view_id) {
951 RenderViewHost* rvh = RenderViewHost::FromID(
952 render_process_id, render_view_id);
953 if (!rvh) {
954 NOTREACHED();
955 return;
956 }
957
[email protected]f3b1a082011-11-18 00:34:30958 content::RenderProcessHost* process = rvh->process();
959 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04960 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37961 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04962 service->RequestPermission(
963 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:13964 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:04965}
966
967WebKit::WebNotificationPresenter::Permission
968 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02969 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:20970 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:02971 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04972 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20973 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:02974 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
975 source_origin, render_process_id,
976 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04977 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04978
979 // Fall back to the regular notification preferences, which works on an
980 // origin basis.
981 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:37982 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:04983 WebKit::WebNotificationPresenter::PermissionNotAllowed;
984}
985
986void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:17987 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:04988 int render_process_id,
989 int render_view_id,
990 bool worker) {
991 RenderViewHost* rvh = RenderViewHost::FromID(
992 render_process_id, render_view_id);
993 if (!rvh) {
994 NOTREACHED();
995 return;
996 }
997
[email protected]f3b1a082011-11-18 00:34:30998 content::RenderProcessHost* process = rvh->process();
999 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041000 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371001 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041002 service->ShowDesktopNotification(
1003 params, render_process_id, render_view_id,
1004 worker ? DesktopNotificationService::WorkerNotification :
1005 DesktopNotificationService::PageNotification);
1006}
1007
1008void ChromeContentBrowserClient::CancelDesktopNotification(
1009 int render_process_id,
1010 int render_view_id,
1011 int notification_id) {
1012 RenderViewHost* rvh = RenderViewHost::FromID(
1013 render_process_id, render_view_id);
1014 if (!rvh) {
1015 NOTREACHED();
1016 return;
1017 }
1018
[email protected]f3b1a082011-11-18 00:34:301019 content::RenderProcessHost* process = rvh->process();
1020 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041021 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371022 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041023 service->CancelDesktopNotification(
1024 render_process_id, render_view_id, notification_id);
1025}
1026
[email protected]9f3fba52011-06-08 20:37:191027bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021028 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191029 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201030 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021031 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191032 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1033 // If the opener is trying to create a background window but doesn't have
1034 // the appropriate permission, fail the attempt.
1035 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201036 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021037 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1038 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191039 }
1040 return true;
1041}
1042
1043std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201044 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1046 // Check if it's an extension-created worker, in which case we want to use
1047 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201048 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191049 const Extension* extension =
1050 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1051 return extension ? extension->name() : std::string();
1052}
1053
[email protected]99907362012-01-11 05:41:401054void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1055 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171056}
1057
1058ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1059 return g_browser_process->clipboard();
1060}
1061
[email protected]8f6a3b852011-07-19 16:48:561062MHTMLGenerationManager*
1063 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1064 return g_browser_process->mhtml_generation_manager();
1065}
1066
[email protected]ae6e9912011-07-27 01:18:281067net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1068 return g_browser_process->net_log();
1069}
1070
[email protected]3bc0b562011-08-24 23:51:041071speech_input::SpeechInputManager*
1072 ChromeContentBrowserClient::GetSpeechInputManager() {
1073 return speech_input::ChromeSpeechInputManager::GetInstance();
1074}
1075
[email protected]32538d92011-08-25 00:09:231076AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1077 return new ChromeAccessTokenStore();
1078}
1079
[email protected]dbae6b02011-06-29 23:51:411080bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1081 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1082 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1083}
1084
[email protected]64d69de42012-02-06 00:19:541085void ChromeContentBrowserClient::OverrideWebkitPrefs(
1086 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061087 Profile* profile = Profile::FromBrowserContext(
1088 rvh->process()->GetBrowserContext());
1089 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061090
[email protected]64d69de42012-02-06 00:19:541091 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061092 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541093 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061094 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541095 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061096 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541097 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061098 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541099 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061100 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541101 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061102 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1103
1104 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541105 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061106 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541107 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061108 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541109 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061110 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541111 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061112 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541113 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061114 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541115 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061116
[email protected]64d69de42012-02-06 00:19:541117 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061118 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541119 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061120 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541121 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061122 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541123 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061124 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1125
[email protected]64d69de42012-02-06 00:19:541126 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061127
[email protected]64d69de42012-02-06 00:19:541128 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061129 prefs->GetBoolean(
1130 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541131 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061132 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541133 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061134 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1135 const DictionaryValue* inspector_settings =
1136 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1137 if (inspector_settings) {
1138 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1139 iter != inspector_settings->end_keys(); ++iter) {
1140 std::string value;
1141 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541142 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061143 std::make_pair(*iter, value));
1144 }
1145 }
[email protected]64d69de42012-02-06 00:19:541146 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061147
[email protected]64d69de42012-02-06 00:19:541148 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1149 web_prefs->javascript_enabled = false;
1150 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1151 web_prefs->web_security_enabled = false;
1152 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1153 web_prefs->plugins_enabled = false;
1154 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1155 web_prefs->java_enabled = false;
1156 web_prefs->loads_images_automatically =
1157 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061158
[email protected]64d69de42012-02-06 00:19:541159 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1160 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061161
[email protected]64d69de42012-02-06 00:19:541162 web_prefs->memory_info_enabled =
1163 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1164 web_prefs->allow_displaying_insecure_content =
1165 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1166 web_prefs->allow_running_insecure_content =
1167 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]f3986f82012-01-03 20:00:061168
[email protected]64d69de42012-02-06 00:19:541169 // The user stylesheet watcher may not exist in a testing profile.
1170 if (profile->GetUserStyleSheetWatcher()) {
1171 web_prefs->user_style_sheet_enabled = true;
1172 web_prefs->user_style_sheet_location =
1173 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1174 } else {
1175 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061176 }
1177
[email protected]64d69de42012-02-06 00:19:541178 web_prefs->unified_textchecker_enabled = CommandLine::ForCurrentProcess()->
1179 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571180
[email protected]64d69de42012-02-06 00:19:541181 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061182 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541183 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061184 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541185 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061186 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1187
1188 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541189 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061190 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541191 web_prefs->default_encoding);
1192 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061193 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541194 web_prefs->default_encoding =
1195 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061196 }
[email protected]64d69de42012-02-06 00:19:541197 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061198
1199 ExtensionService* service = profile->GetExtensionService();
1200 if (service) {
1201 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331202 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061203 extension_webkit_preferences::SetPreferences(
[email protected]64d69de42012-02-06 00:19:541204 extension, rvh->delegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061205 }
1206
1207 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541208 web_prefs->allow_scripts_to_close_windows = true;
[email protected]f3986f82012-01-03 20:00:061209 } else if (rvh->delegate()->GetRenderViewType() ==
1210 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1211 // Disable all kinds of acceleration for background pages.
1212 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541213 web_prefs->force_compositing_mode = false;
1214 web_prefs->accelerated_compositing_enabled = false;
1215 web_prefs->accelerated_2d_canvas_enabled = false;
1216 web_prefs->accelerated_video_enabled = false;
1217 web_prefs->accelerated_painting_enabled = false;
1218 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061219 }
[email protected]181a95ee2011-07-12 19:26:361220}
1221
1222void ChromeContentBrowserClient::UpdateInspectorSetting(
1223 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061224 content::BrowserContext* browser_context =
1225 rvh->process()->GetBrowserContext();
1226 DictionaryPrefUpdate update(
1227 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1228 prefs::kWebKitInspectorSettings);
1229 DictionaryValue* inspector_settings = update.Get();
1230 inspector_settings->SetWithoutPathExpansion(key,
1231 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361232}
1233
1234void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061235 content::BrowserContext* browser_context =
1236 rvh->process()->GetBrowserContext();
1237 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1238 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361239}
1240
[email protected]b8148ac2011-07-13 22:03:251241void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1242 BrowserURLHandler* handler) {
1243 // Add the default URL handlers.
1244 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1245 BrowserURLHandler::null_handler());
1246 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1247 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1248
[email protected]b3adbd02011-11-30 22:23:271249 // about: handler. Must come before chrome: handler, since it will
1250 // rewrite about: urls to chrome: URLs and then expect chrome: to
1251 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251252 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1253 BrowserURLHandler::null_handler());
1254 // chrome: & friends.
1255 handler->AddHandlerPair(&HandleWebUI,
1256 BrowserURLHandler::null_handler());
1257}
1258
1259void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371260 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301261 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251262 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1263 BrowsingDataRemover::EVERYTHING,
1264 base::Time());
1265 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1266 // BrowsingDataRemover takes care of deleting itself when done.
1267}
1268
1269void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371270 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301271 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251272 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1273 BrowsingDataRemover::EVERYTHING,
1274 base::Time());
[email protected]dceaa912011-09-06 17:17:231275 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251276 remover->Remove(remove_mask);
1277 // BrowsingDataRemover takes care of deleting itself when done.
1278}
1279
[email protected]e1d16eb92011-08-18 23:19:321280FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1281 return download_util::GetDefaultDownloadDirectory();
1282}
1283
[email protected]c9b6eb62011-10-18 20:49:391284std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1285 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1286}
1287
[email protected]e60c0232011-11-11 19:56:351288#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301289int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521290 const CommandLine& command_line) {
1291 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071292 ExtensionCrashHandlerHostLinux* crash_handler =
1293 ExtensionCrashHandlerHostLinux::GetInstance();
1294 return crash_handler->GetDeathSignalSocket();
1295 }
1296
[email protected]718eab62011-10-05 21:16:521297 std::string process_type =
1298 command_line.GetSwitchValueASCII(switches::kProcessType);
1299
1300 if (process_type == switches::kRendererProcess)
1301 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1302
[email protected]b80f68432011-05-02 17:22:301303 if (process_type == switches::kPluginProcess)
1304 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1305
1306 if (process_type == switches::kPpapiPluginProcess)
1307 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1308
1309 if (process_type == switches::kGpuProcess)
1310 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1311
1312 return -1;
1313}
[email protected]e60c0232011-11-11 19:56:351314#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301315
[email protected]4a65826d2011-08-25 16:04:011316#if defined(OS_WIN)
1317const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1318 return chrome::kBrowserResourcesDll;
1319}
1320#endif
1321
[email protected]37a72af2011-06-13 05:42:011322#if defined(USE_NSS)
1323crypto::CryptoModuleBlockingPasswordDelegate*
1324 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1325 const GURL& url) {
1326 return browser::NewCryptoModuleBlockingDialogDelegate(
1327 browser::kCryptoModulePasswordKeygen, url.host());
1328}
1329#endif
1330
[email protected]d977f9c2011-03-14 16:10:261331} // namespace chrome