blob: 9766cad893716f1be38644152c95f0a36b81e9fa [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]f9034cf2011-07-21 12:43:4170#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4571#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]b48c9182011-10-26 18:03:3072#include "content/public/browser/browser_main_parts.h"
[email protected]b9535422012-02-09 01:47:5973#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3074#include "content/public/browser/render_process_host.h"
[email protected]ce967862012-02-09 22:47:0575#include "content/public/browser/resource_context.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]6e677a342012-02-11 01:21:14125#elif defined(OS_ANDROID)
126#include "content/browser/tab_contents/tab_contents_view_android.h"
[email protected]74313b42011-08-24 16:51:32127#endif
128
[email protected]37a72af2011-06-13 05:42:01129#if defined(USE_NSS)
130#include "chrome/browser/ui/crypto_module_password_dialog.h"
131#endif
132
[email protected]c8c77182011-12-21 15:04:47133using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39134using content::BrowserThread;
[email protected]b9535422012-02-09 01:47:59135using content::ChildProcessSecurityPolicy;
[email protected]b6583592012-01-25 19:52:33136using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13137using content::WebContents;
[email protected]631bb742011-11-02 11:29:39138
[email protected]c5dbef02011-05-13 05:06:09139namespace {
140
[email protected]b8148ac2011-07-13 22:03:25141// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42142bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50143 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
144 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25145 return false;
146
147 // Special case the new tab page. In older versions of Chrome, the new tab
148 // page was hosted at chrome-internal:<blah>. This might be in people's saved
149 // sessions or bookmarks, so we say any URL with that scheme triggers the new
150 // tab page.
151 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
152 // Rewrite it with the proper new tab URL.
153 *url = GURL(chrome::kChromeUINewTabURL);
154 }
155
156 return true;
157}
158
[email protected]8d3132f62011-10-12 07:13:42159// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
160// below. Extension, and isolated apps require different privileges to be
161// granted to their RenderProcessHosts. This classification allows us to make
162// sure URLs are served by hosts with the right set of privileges.
163enum RenderProcessHostPrivilege {
164 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45165 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42166 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45167 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42168};
169
170RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
171 const GURL& url,
172 ExtensionService* service) {
173 // Default to a normal renderer cause it is lower privileged. This should only
174 // occur if the URL on a site instance is either malformed, or uninitialized.
175 // If it is malformed, then there is no need for better privileges anyways.
176 // If it is uninitialized, but eventually settles on being an a scheme other
177 // than normal webrenderer, the navigation logic will correct us out of band
178 // anyways.
179 if (!url.is_valid())
180 return PRIV_NORMAL;
181
182 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44183 const Extension* extension =
184 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45185 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42186 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45187 if (extension && extension->is_hosted_app())
188 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42189
190 return PRIV_EXTENSION;
191 }
192
193 return PRIV_NORMAL;
194}
195
196RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30197 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46198 extensions::ProcessMap* process_map,
199 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46200 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30201 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46202 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21203 return PRIV_NORMAL;
204
[email protected]6f371442011-11-09 06:45:46205 for (std::set<std::string>::iterator iter = extension_ids.begin();
206 iter != extension_ids.end(); ++iter) {
207 const Extension* extension = service->GetExtensionById(*iter, false);
208 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42209 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45210 if (extension && extension->is_hosted_app())
211 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42212 }
213
[email protected]676f6ab2011-10-19 20:23:21214 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42215}
216
[email protected]eec0b33c2011-12-05 22:09:45217bool IsIsolatedAppInProcess(const GURL& site_url,
218 content::RenderProcessHost* process_host,
219 extensions::ProcessMap* process_map,
220 ExtensionService* service) {
221 std::set<std::string> extension_ids =
222 process_map->GetExtensionsInProcess(process_host->GetID());
223 if (extension_ids.empty())
224 return false;
225
226 for (std::set<std::string>::iterator iter = extension_ids.begin();
227 iter != extension_ids.end(); ++iter) {
228 const Extension* extension = service->GetExtensionById(*iter, false);
229 if (extension &&
230 extension->is_storage_isolated() &&
231 extension->url() == site_url)
232 return true;
233 }
234
235 return false;
236}
237
[email protected]6786bf402011-12-03 15:19:45238bool CertMatchesFilter(const net::X509Certificate& cert,
239 const base::DictionaryValue& filter) {
240 // TODO(markusheintz): This is the minimal required filter implementation.
241 // Implement a better matcher.
242
243 // An empty filter matches any client certificate since no requirements are
244 // specified at all.
245 if (filter.empty())
246 return true;
247
248 std::string common_name;
249 if (filter.GetString("ISSUER.CN", &common_name) &&
250 (cert.issuer().common_name == common_name)) {
251 return true;
252 }
253 return false;
254}
255
[email protected]f3986f82012-01-03 20:00:06256// Fills |map| with the per-script font prefs under path |map_name|.
257void FillFontFamilyMap(const PrefService* prefs,
258 const char* map_name,
259 WebPreferences::ScriptFontFamilyMap* map) {
260 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
261 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
262 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
263 std::string font_family = prefs->GetString(pref_name.c_str());
264 if (!font_family.empty())
265 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
266 }
267}
268
[email protected]9dbfff12011-07-01 19:37:07269} // namespace
[email protected]c5dbef02011-05-13 05:06:09270
[email protected]d977f9c2011-03-14 16:10:26271namespace chrome {
272
[email protected]50462bf02011-11-21 19:13:31273content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
274 const content::MainFunctionParams& parameters) {
275 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30276 // Construct the Main browser parts based on the OS type.
277#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31278 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04279#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31280 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30281#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31282 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35283#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31284 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14285#elif defined(OS_ANDROID)
286 // Do nothing for Android.
287 // TODO(klobag): Android initialization should use the
288 // *BrowserMainParts class-hierarchy for setting up custom initialization.
289 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30290#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31291 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04292#else
[email protected]b48c9182011-10-26 18:03:30293 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31294 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30295#endif
296
[email protected]c7480942011-11-08 19:18:27297 // Construct additional browser parts. Stages are called in the order in
298 // which they are added.
[email protected]b48c9182011-10-26 18:03:30299#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31300 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04301#endif
[email protected]c7480942011-11-08 19:18:27302
303#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31304 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27305#endif
306
307#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31308 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27309#endif
310
[email protected]50462bf02011-11-21 19:13:31311 return main_parts;
[email protected]f967b722011-09-07 00:58:04312}
313
[email protected]8643e6d2012-01-18 20:26:10314content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35315 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26316#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35317 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21318#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35319 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22320 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32321#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29322 return web_contents_view_mac::CreateWebContentsView(
[email protected]cce3ab72012-02-04 18:05:16323 web_contents,
324 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
325 web_contents));
[email protected]6e677a342012-02-11 01:21:14326#elif defined(OS_ANDROID)
327 return new TabContentsViewAndroid(web_contents);
[email protected]74313b42011-08-24 16:51:32328#else
[email protected]8643e6d2012-01-18 20:26:10329#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32330#endif
331}
332
[email protected]f364d1392011-04-08 21:03:10333void ChromeContentBrowserClient::RenderViewHostCreated(
334 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46335
336 SiteInstance* site_instance = render_view_host->site_instance();
337 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02338 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46339
340 new ChromeRenderViewHostObserver(render_view_host,
341 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10342 new ExtensionMessageHandler(render_view_host);
[email protected]85f0a572012-02-07 22:20:13343
344 if (render_view_host->delegate()->GetRenderViewType() ==
345 content::VIEW_TYPE_INTERSTITIAL_PAGE) {
346 render_view_host->Send(new ChromeViewMsg_SetAsInterstitial(
347 render_view_host->routing_id()));
348 }
[email protected]d977f9c2011-03-14 16:10:26349}
350
[email protected]f3b1a082011-11-18 00:34:30351void ChromeContentBrowserClient::RenderProcessHostCreated(
352 content::RenderProcessHost* host) {
353 int id = host->GetID();
354 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
355 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02356 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30357 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
358 host->GetChannel()->AddFilter(new PrintingMessageFilter());
359 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02360 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30361 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56362#if defined(OS_MACOSX)
363 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
364#endif
[email protected]f3b1a082011-11-18 00:34:30365 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03366 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38367
[email protected]2ccf45c2011-08-19 23:35:50368 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
369 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07370
371 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56372
373 RendererContentSettingRules rules;
374 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
375 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14376}
377
[email protected]863f70a2012-01-27 02:05:50378content::WebUIControllerFactory*
379 ChromeContentBrowserClient::GetWebUIControllerFactory() {
380 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56381}
382
[email protected]3d7474ff2011-07-27 17:47:37383GURL ChromeContentBrowserClient::GetEffectiveURL(
384 content::BrowserContext* browser_context, const GURL& url) {
385 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08386 // Get the effective URL for the given actual URL. If the URL is part of an
387 // installed app, the effective URL is an extension URL with the ID of that
388 // extension as the host. This has the effect of grouping apps together in
389 // a common SiteInstance.
390 if (!profile || !profile->GetExtensionService())
391 return url;
392
[email protected]615d88f2011-12-13 01:47:44393 const Extension* extension = profile->GetExtensionService()->extensions()->
394 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08395 if (!extension)
396 return url;
397
[email protected]15877ca2011-11-18 22:40:52398 // Bookmark apps do not use the hosted app process model, and should be
399 // treated as normal URLs.
400 if (extension->from_bookmark())
401 return url;
402
[email protected]36fb2c7c2011-04-04 15:49:08403 // If the URL is part of an extension's web extent, convert it to an
404 // extension URL.
405 return extension->GetResourceURL(url.path());
406}
407
[email protected]056ad2a2011-07-12 02:13:55408bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37409 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55410 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52411 // Because we expect to use the effective URL, URLs for hosted apps (apart
412 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55413 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
414 return false;
415
[email protected]3d7474ff2011-07-27 17:47:37416 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55417 if (!profile || !profile->GetExtensionService())
418 return false;
419
[email protected]615d88f2011-12-13 01:47:44420 const Extension* extension = profile->GetExtensionService()->extensions()->
421 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55422 if (!extension)
423 return false;
424
425 // If the URL is part of a hosted app that does not have the background
426 // permission, we want to give each instance its own process to improve
427 // responsiveness.
428 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
429 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
430 return false;
431
432 // Hosted apps that have the background permission must use process per site,
433 // since all instances can make synchronous calls to the background window.
434 // Other extensions should use process per site as well.
435 return true;
436}
437
[email protected]46fb9442011-12-09 17:57:47438bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
439 return ProfileIOData::IsHandledURL(url);
440}
441
[email protected]2a5221b2011-09-27 23:07:31442bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30443 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31444 const GURL& site_url) {
445 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30446 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42447 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46448 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31449
[email protected]ffa97602011-11-17 17:55:52450 // Don't allow the Task Manager to share a process with anything else.
451 // Otherwise it can affect the renderers it is observing.
452 // Note: we could create another RenderProcessHostPrivilege bucket for
453 // this to allow multiple chrome://tasks instances to share, but that's
454 // a very unlikely case without serious consequences.
455 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
456 return false;
457
[email protected]8d3132f62011-10-12 07:13:42458 // These may be NULL during tests. In that case, just assume any site can
459 // share any host.
[email protected]6f371442011-11-09 06:45:46460 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31461 return true;
462
[email protected]a8c269a2011-10-25 20:17:22463 // Experimental:
464 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
465 // to share a renderer process. (We could allow pages from the same site or
466 // extensions of the same type to share, if we knew what the given process
467 // was dedicated to. Allowing no sharing is simpler for now.) This may
468 // cause resource exhaustion issues if too many sites are open at once.
469 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
470 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
471 return false;
472
[email protected]eec0b33c2011-12-05 22:09:45473 // An isolated app is only allowed to share with the exact same app in order
474 // to provide complete renderer process isolation. This also works around
475 // issue http://crbug.com/85588, where different isolated apps in the same
476 // process would end up using the first app's storage contexts.
477 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42478 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45479 if (privilege_required == PRIV_ISOLATED)
480 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
481
482 // Otherwise, just make sure the process privilege matches the privilege
483 // required by the site.
484 return GetProcessPrivilege(process_host, process_map, service) ==
485 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31486}
487
[email protected]6f371442011-11-09 06:45:46488void ChromeContentBrowserClient::SiteInstanceGotProcess(
489 SiteInstance* site_instance) {
490 CHECK(site_instance->HasProcess());
491
492 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02493 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46494 ExtensionService* service = profile->GetExtensionService();
495 if (!service)
496 return;
497
498 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44499 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33500 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46501 if (!extension)
502 return;
503
[email protected]6bc04fd82011-12-04 02:29:35504 service->process_map()->Insert(extension->id(),
505 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33506 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46507 BrowserThread::PostTask(
508 BrowserThread::IO, FROM_HERE,
509 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
510 profile->GetExtensionInfoMap(),
511 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35512 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33513 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46514}
515
516void ChromeContentBrowserClient::SiteInstanceDeleting(
517 SiteInstance* site_instance) {
518 if (!site_instance->HasProcess())
519 return;
520
521 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02522 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46523 ExtensionService* service = profile->GetExtensionService();
524 if (!service)
525 return;
526
527 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44528 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33529 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46530 if (!extension)
531 return;
532
[email protected]6bc04fd82011-12-04 02:29:35533 service->process_map()->Remove(extension->id(),
534 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33535 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46536 BrowserThread::PostTask(
537 BrowserThread::IO, FROM_HERE,
538 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
539 profile->GetExtensionInfoMap(),
540 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35541 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33542 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46543}
544
[email protected]e3daf3c2011-10-05 21:17:08545bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
546 const GURL& current_url,
547 const GURL& new_url) {
548 if (current_url.is_empty()) {
549 // Always choose a new process when navigating to extension URLs. The
550 // process grouping logic will combine all of a given extension's pages
551 // into the same process.
552 if (new_url.SchemeIs(chrome::kExtensionScheme))
553 return true;
554
555 return false;
556 }
557
558 // Also, we must switch if one is an extension and the other is not the exact
559 // same extension.
560 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
561 new_url.SchemeIs(chrome::kExtensionScheme)) {
562 if (current_url.GetOrigin() != new_url.GetOrigin())
563 return true;
564 }
565
566 return false;
567}
568
[email protected]763ec4ca2011-04-29 15:48:12569std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
570 const std::string& alias_name) {
571 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
572}
573
[email protected]b80f68432011-05-02 17:22:30574void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
575 CommandLine* command_line, int child_process_id) {
576#if defined(USE_LINUX_BREAKPAD)
577 if (IsCrashReporterEnabled()) {
578 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
579 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
580 }
581#elif defined(OS_MACOSX)
582 if (IsCrashReporterEnabled()) {
583 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
584 child_process_logging::GetClientId());
585 }
586#endif // OS_MACOSX
587
[email protected]f1933792011-06-14 00:49:34588 if (logging::DialogsAreSuppressed())
589 command_line->AppendSwitch(switches::kNoErrorDialogs);
590
[email protected]b80f68432011-05-02 17:22:30591 std::string process_type =
592 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17593 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52594 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30595 FilePath user_data_dir =
596 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
597 if (!user_data_dir.empty())
598 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
599#if defined(OS_CHROMEOS)
600 const std::string& login_profile =
601 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
602 if (!login_profile.empty())
603 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
604#endif
605
[email protected]f3b1a082011-11-18 00:34:30606 content::RenderProcessHost* process =
607 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37608 if (process) {
609 Profile* profile = Profile::FromBrowserContext(
610 process->GetBrowserContext());
611 extensions::ProcessMap* process_map =
612 profile->GetExtensionService()->process_map();
613 if (process_map && process_map->Contains(process->GetID()))
614 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30615
[email protected]a8d851f82011-12-21 00:32:37616 PrefService* prefs = profile->GetPrefs();
617 // Currently this pref is only registered if applied via a policy.
618 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
619 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
620 // Turn this policy into a command line switch.
621 command_line->AppendSwitch(switches::kDisable3DAPIs);
622 }
[email protected]718eab62011-10-05 21:16:52623
[email protected]a8d851f82011-12-21 00:32:37624 // Disable client-side phishing detection in the renderer if it is
625 // disabled in the Profile preferences or the browser process.
626 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
627 !g_browser_process->safe_browsing_detection_service()) {
628 command_line->AppendSwitch(
629 switches::kDisableClientSidePhishingDetection);
630 }
[email protected]8c40da62011-07-13 22:58:46631 }
[email protected]47c7ec82012-01-18 03:29:21632 {
633 PrefService* local_state = g_browser_process->local_state();
634 if (local_state &&
635 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
636 command_line->AppendSwitch(switches::kRendererPrintPreview);
637 }
638 }
[email protected]4287a3d2011-06-13 23:56:51639
[email protected]47c7ec82012-01-18 03:29:21640 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51641 static const char* const kSwitchNames[] = {
642 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48643 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18644 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51645 switches::kAllowScriptingGallery,
646 switches::kAppsCheckoutURL,
647 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31648 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51649 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51650 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21651 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51652 switches::kEnableCrxlessWebApps,
653 switches::kEnableExperimentalExtensionApis,
654 switches::kEnableInBrowserThumbnailing,
655 switches::kEnableIPCFuzzing,
656 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53657 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51658 switches::kEnableWatchdog,
659 switches::kExperimentalSpellcheckerFeatures,
660 switches::kMemoryProfiling,
661 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04662 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51663 switches::kPpapiFlashArgs,
664 switches::kPpapiFlashInProcess,
665 switches::kPpapiFlashPath,
666 switches::kPpapiFlashVersion,
667 switches::kProfilingAtStart,
668 switches::kProfilingFile,
669 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51670 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38671 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51672 };
673
674 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
675 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17676 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38677 static const char* const kSwitchNames[] = {
678 switches::kEnableExperimentalExtensionApis,
679 switches::kWhitelistedExtensionID,
680 };
681
682 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
683 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51684 } else if (process_type == switches::kPluginProcess) {
685 static const char* const kSwitchNames[] = {
686 #if defined(OS_CHROMEOS)
687 switches::kLoginProfile,
688 #endif
689 switches::kMemoryProfiling,
690 switches::kSilentDumpOnDCHECK,
691 switches::kUserDataDir,
692 };
693
694 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
695 arraysize(kSwitchNames));
696 } else if (process_type == switches::kZygoteProcess) {
697 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51698 switches::kUserDataDir, // Make logs go to the right file.
699 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
700 switches::kPpapiFlashInProcess,
701 switches::kPpapiFlashPath,
702 switches::kPpapiFlashVersion,
703 };
704
705 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
706 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30707 }
[email protected]6f08af82011-09-15 01:19:03708
709 // The command line switch kEnableBenchmarking needs to be specified along
710 // with the kEnableStatsTable switch to ensure that the stats table global
711 // is initialized correctly.
712 if (command_line->HasSwitch(switches::kEnableBenchmarking))
713 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30714}
715
716std::string ChromeContentBrowserClient::GetApplicationLocale() {
717 return g_browser_process->GetApplicationLocale();
718}
719
[email protected]597a867b2011-11-18 18:31:20720std::string ChromeContentBrowserClient::GetAcceptLangs(
721 content::BrowserContext* context) {
722 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37723 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08724}
725
[email protected]ac55e292011-06-24 05:16:08726SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22727 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08728 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
729}
730
[email protected]a2176792011-05-08 19:30:49731bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09732 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19733 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20734 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20736 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05737 return io_data->GetCookieSettings()->
738 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49739}
740
[email protected]ed24fad2011-05-10 22:44:01741bool ChromeContentBrowserClient::AllowGetCookie(
742 const GURL& url,
743 const GURL& first_party,
744 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20745 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01746 int render_process_id,
747 int render_view_id) {
748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20749 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05750 bool allow = io_data->GetCookieSettings()->
751 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01752
[email protected]8093a542011-05-13 07:29:32753 BrowserThread::PostTask(
754 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03755 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
756 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01757 return allow;
758}
759
760bool ChromeContentBrowserClient::AllowSetCookie(
761 const GURL& url,
762 const GURL& first_party,
763 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20764 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01765 int render_process_id,
766 int render_view_id,
767 net::CookieOptions* options) {
768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20769 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05770 CookieSettings* cookie_settings = io_data->GetCookieSettings();
771 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
772
773 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09774 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01775
[email protected]8093a542011-05-13 07:29:32776 BrowserThread::PostTask(
777 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03778 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
779 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01780 return allow;
781}
782
[email protected]d5a19162011-06-30 18:51:54783bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20784 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54785 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20786 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]d5a19162011-06-30 18:51:54787 return !io_data->clear_local_state_on_exit()->GetValue();
788}
789
[email protected]5c5a88e2011-11-12 00:45:35790bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35791 const GURL& url,
792 const string16& name,
793 const string16& display_name,
794 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20795 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48796 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20798 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35799 CookieSettings* cookie_settings = io_data->GetCookieSettings();
800 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
801
[email protected]62151052012-02-01 18:40:48802 // Record access to database for potential display in UI.
803 std::vector<std::pair<int, int> >::const_iterator i;
804 for (i = render_views.begin(); i != render_views.end(); ++i) {
805 BrowserThread::PostTask(
806 BrowserThread::UI, FROM_HERE,
807 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
808 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35809 }
810
811 return allow;
812}
813
814bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35815 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20816 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48817 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35818 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20819 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35820 CookieSettings* cookie_settings = io_data->GetCookieSettings();
821 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
822
[email protected]62151052012-02-01 18:40:48823 // Record access to file system for potential display in UI.
824 std::vector<std::pair<int, int> >::const_iterator i;
825 for (i = render_views.begin(); i != render_views.end(); ++i) {
826 BrowserThread::PostTask(
827 BrowserThread::UI, FROM_HERE,
828 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
829 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35830 }
831
832 return allow;
833}
834
[email protected]6133f922011-07-01 21:34:34835net::URLRequestContext*
836ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20837 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
839 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20840 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34841 return io_data->extensions_request_context();
842 }
843
844 return NULL;
845}
846
[email protected]317f96c92011-05-31 06:53:41847QuotaPermissionContext*
848ChromeContentBrowserClient::CreateQuotaPermissionContext() {
849 return new ChromeQuotaPermissionContext();
850}
851
[email protected]a0ce3282011-08-19 20:49:52852void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42853 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42854}
855
[email protected]a0ce3282011-08-19 20:49:52856void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52857 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52858}
859
[email protected]848dd042011-06-04 18:24:03860void ChromeContentBrowserClient::AllowCertificateError(
861 SSLCertErrorHandler* handler,
862 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58863 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41864 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13865 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]f9034cf2011-07-21 12:43:41866 handler->render_process_host_id(),
867 handler->tab_contents_id());
868 if (!tab) {
869 NOTREACHED();
870 return;
871 }
872 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50873 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30874 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09875 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41876 if (prerender_manager->prerender_tracker()->TryCancel(
877 handler->render_process_host_id(),
878 handler->tab_contents_id(),
879 prerender::FINAL_STATUS_SSL_ERROR)) {
880 handler->CancelRequest();
881 return;
882 }
883 }
884
885 // Otherwise, display an SSL blocking page.
[email protected]85f0a572012-02-07 22:20:13886 new SSLBlockingPage(handler, overridable, callback);
[email protected]848dd042011-06-04 18:24:03887}
888
[email protected]c99c442e2011-08-24 11:37:30889void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45890 int render_process_id,
891 int render_view_id,
892 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13893 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45894 render_process_id, render_view_id);
895 if (!tab) {
896 NOTREACHED();
897 return;
898 }
899
[email protected]6786bf402011-12-03 15:19:45900 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
901 GURL requesting_url("https://" + cert_request_info->host_and_port);
902 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
903 << cert_request_info->host_and_port;
904
[email protected]627e0512011-12-21 22:55:30905 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45906 DCHECK(profile);
907 scoped_ptr<Value> filter(
908 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
909 requesting_url,
910 requesting_url,
911 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
912 std::string(), NULL));
913
914 if (filter.get()) {
915 // Try to automatically select a client certificate.
916 if (filter->IsType(Value::TYPE_DICTIONARY)) {
917 DictionaryValue* filter_dict =
918 static_cast<DictionaryValue*>(filter.get());
919
920 const std::vector<scoped_refptr<net::X509Certificate> >&
921 all_client_certs = cert_request_info->client_certs;
922 for (size_t i = 0; i < all_client_certs.size(); ++i) {
923 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
924 // Use the first certificate that is matched by the filter.
925 handler->CertificateSelected(all_client_certs[i]);
926 return;
927 }
928 }
929 } else {
930 NOTREACHED();
931 }
932 }
933
[email protected]8ec26472011-06-06 16:52:45934 TabContentsWrapper* wrapper =
935 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45936 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13937 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45938 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14939 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45940 handler->CertificateSelected(NULL);
941 return;
942 }
943 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45944}
945
946void ChromeContentBrowserClient::AddNewCertificate(
947 net::URLRequest* request,
948 net::X509Certificate* cert,
949 int render_process_id,
950 int render_view_id) {
951 // The handler will run the UI and delete itself when it's finished.
952 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
953}
954
[email protected]941623e2011-06-07 23:06:04955void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
956 const GURL& source_origin,
957 int callback_context,
958 int render_process_id,
959 int render_view_id) {
960 RenderViewHost* rvh = RenderViewHost::FromID(
961 render_process_id, render_view_id);
962 if (!rvh) {
963 NOTREACHED();
964 return;
965 }
966
[email protected]f3b1a082011-11-18 00:34:30967 content::RenderProcessHost* process = rvh->process();
968 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04969 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37970 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04971 service->RequestPermission(
972 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:13973 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:04974}
975
976WebKit::WebNotificationPresenter::Permission
977 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02978 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:20979 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:02980 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04981 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20982 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[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]df02aca2012-02-09 21:03:201039 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021040 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) {
[email protected]df02aca2012-02-09 21:03:201045 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021046 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1047 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191048 }
1049 return true;
1050}
1051
1052std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201053 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191054 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1055 // Check if it's an extension-created worker, in which case we want to use
1056 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201057 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191058 const Extension* extension =
1059 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1060 return extension ? extension->name() : std::string();
1061}
1062
[email protected]99907362012-01-11 05:41:401063void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1064 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171065}
1066
1067ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1068 return g_browser_process->clipboard();
1069}
1070
[email protected]8f6a3b852011-07-19 16:48:561071MHTMLGenerationManager*
1072 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1073 return g_browser_process->mhtml_generation_manager();
1074}
1075
[email protected]ae6e9912011-07-27 01:18:281076net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1077 return g_browser_process->net_log();
1078}
1079
[email protected]3bc0b562011-08-24 23:51:041080speech_input::SpeechInputManager*
1081 ChromeContentBrowserClient::GetSpeechInputManager() {
1082 return speech_input::ChromeSpeechInputManager::GetInstance();
1083}
1084
[email protected]32538d92011-08-25 00:09:231085AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1086 return new ChromeAccessTokenStore();
1087}
1088
[email protected]dbae6b02011-06-29 23:51:411089bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1090 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1091 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1092}
1093
[email protected]64d69de42012-02-06 00:19:541094void ChromeContentBrowserClient::OverrideWebkitPrefs(
1095 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061096 Profile* profile = Profile::FromBrowserContext(
1097 rvh->process()->GetBrowserContext());
1098 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061099
[email protected]64d69de42012-02-06 00:19:541100 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061101 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541102 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061103 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541104 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061105 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541106 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061107 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541108 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061109 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541110 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061111 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1112
1113 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541114 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061115 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541116 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061117 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541118 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061119 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541120 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061121 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541122 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061123 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541124 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061125
[email protected]64d69de42012-02-06 00:19:541126 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061127 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541128 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061129 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541130 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061131 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541132 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061133 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1134
[email protected]64d69de42012-02-06 00:19:541135 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061136
[email protected]64d69de42012-02-06 00:19:541137 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061138 prefs->GetBoolean(
1139 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541140 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061141 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541142 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061143 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1144 const DictionaryValue* inspector_settings =
1145 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1146 if (inspector_settings) {
1147 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1148 iter != inspector_settings->end_keys(); ++iter) {
1149 std::string value;
1150 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541151 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061152 std::make_pair(*iter, value));
1153 }
1154 }
[email protected]64d69de42012-02-06 00:19:541155 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061156
[email protected]64d69de42012-02-06 00:19:541157 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1158 web_prefs->javascript_enabled = false;
1159 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1160 web_prefs->web_security_enabled = false;
1161 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1162 web_prefs->plugins_enabled = false;
1163 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1164 web_prefs->java_enabled = false;
1165 web_prefs->loads_images_automatically =
1166 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061167
[email protected]64d69de42012-02-06 00:19:541168 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1169 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061170
[email protected]64d69de42012-02-06 00:19:541171 web_prefs->memory_info_enabled =
1172 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1173 web_prefs->allow_displaying_insecure_content =
1174 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1175 web_prefs->allow_running_insecure_content =
1176 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]f3986f82012-01-03 20:00:061177
[email protected]64d69de42012-02-06 00:19:541178 // The user stylesheet watcher may not exist in a testing profile.
1179 if (profile->GetUserStyleSheetWatcher()) {
1180 web_prefs->user_style_sheet_enabled = true;
1181 web_prefs->user_style_sheet_location =
1182 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1183 } else {
1184 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061185 }
1186
[email protected]64d69de42012-02-06 00:19:541187 web_prefs->unified_textchecker_enabled = CommandLine::ForCurrentProcess()->
1188 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571189
[email protected]64d69de42012-02-06 00:19:541190 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061191 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541192 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061193 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541194 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061195 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1196
1197 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541198 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061199 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541200 web_prefs->default_encoding);
1201 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061202 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541203 web_prefs->default_encoding =
1204 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061205 }
[email protected]64d69de42012-02-06 00:19:541206 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061207
1208 ExtensionService* service = profile->GetExtensionService();
1209 if (service) {
1210 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331211 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061212 extension_webkit_preferences::SetPreferences(
[email protected]64d69de42012-02-06 00:19:541213 extension, rvh->delegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061214 }
1215
1216 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541217 web_prefs->allow_scripts_to_close_windows = true;
[email protected]f3986f82012-01-03 20:00:061218 } else if (rvh->delegate()->GetRenderViewType() ==
1219 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1220 // Disable all kinds of acceleration for background pages.
1221 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541222 web_prefs->force_compositing_mode = false;
1223 web_prefs->accelerated_compositing_enabled = false;
1224 web_prefs->accelerated_2d_canvas_enabled = false;
1225 web_prefs->accelerated_video_enabled = false;
1226 web_prefs->accelerated_painting_enabled = false;
1227 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061228 }
[email protected]181a95ee2011-07-12 19:26:361229}
1230
1231void ChromeContentBrowserClient::UpdateInspectorSetting(
1232 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061233 content::BrowserContext* browser_context =
1234 rvh->process()->GetBrowserContext();
1235 DictionaryPrefUpdate update(
1236 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1237 prefs::kWebKitInspectorSettings);
1238 DictionaryValue* inspector_settings = update.Get();
1239 inspector_settings->SetWithoutPathExpansion(key,
1240 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361241}
1242
1243void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061244 content::BrowserContext* browser_context =
1245 rvh->process()->GetBrowserContext();
1246 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1247 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361248}
1249
[email protected]b8148ac2011-07-13 22:03:251250void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1251 BrowserURLHandler* handler) {
1252 // Add the default URL handlers.
1253 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1254 BrowserURLHandler::null_handler());
1255 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1256 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1257
[email protected]b3adbd02011-11-30 22:23:271258 // about: handler. Must come before chrome: handler, since it will
1259 // rewrite about: urls to chrome: URLs and then expect chrome: to
1260 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251261 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1262 BrowserURLHandler::null_handler());
1263 // chrome: & friends.
1264 handler->AddHandlerPair(&HandleWebUI,
1265 BrowserURLHandler::null_handler());
1266}
1267
1268void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371269 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301270 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251271 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1272 BrowsingDataRemover::EVERYTHING,
1273 base::Time());
1274 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1275 // BrowsingDataRemover takes care of deleting itself when done.
1276}
1277
1278void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371279 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301280 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251281 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1282 BrowsingDataRemover::EVERYTHING,
1283 base::Time());
[email protected]dceaa912011-09-06 17:17:231284 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251285 remover->Remove(remove_mask);
1286 // BrowsingDataRemover takes care of deleting itself when done.
1287}
1288
[email protected]e1d16eb92011-08-18 23:19:321289FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1290 return download_util::GetDefaultDownloadDirectory();
1291}
1292
[email protected]c9b6eb62011-10-18 20:49:391293std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1294 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1295}
1296
[email protected]e60c0232011-11-11 19:56:351297#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301298int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521299 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141300#if defined(OS_ANDROID)
1301 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1302 // fork. http://crbug.com/113560
1303 NOTIMPLEMENTED();
1304#else
[email protected]718eab62011-10-05 21:16:521305 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071306 ExtensionCrashHandlerHostLinux* crash_handler =
1307 ExtensionCrashHandlerHostLinux::GetInstance();
1308 return crash_handler->GetDeathSignalSocket();
1309 }
1310
[email protected]718eab62011-10-05 21:16:521311 std::string process_type =
1312 command_line.GetSwitchValueASCII(switches::kProcessType);
1313
1314 if (process_type == switches::kRendererProcess)
1315 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1316
[email protected]b80f68432011-05-02 17:22:301317 if (process_type == switches::kPluginProcess)
1318 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1319
1320 if (process_type == switches::kPpapiPluginProcess)
1321 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1322
1323 if (process_type == switches::kGpuProcess)
1324 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141325#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301326
1327 return -1;
1328}
[email protected]e60c0232011-11-11 19:56:351329#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301330
[email protected]4a65826d2011-08-25 16:04:011331#if defined(OS_WIN)
1332const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1333 return chrome::kBrowserResourcesDll;
1334}
1335#endif
1336
[email protected]37a72af2011-06-13 05:42:011337#if defined(USE_NSS)
1338crypto::CryptoModuleBlockingPasswordDelegate*
1339 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1340 const GURL& url) {
1341 return browser::NewCryptoModuleBlockingDialogDelegate(
1342 browser::kCryptoModulePasswordKeygen, url.host());
1343}
1344#endif
1345
[email protected]d977f9c2011-03-14 16:10:261346} // namespace chrome