blob: 111dd03ab4f012e8d1bae8561d6b0a0212b39503 [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// 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>
8#include <vector>
9
[email protected]317c58f02011-11-09 02:15:0310#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3011#include "base/command_line.h"
12#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2513#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3014#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2315#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1216#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0317#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]97e6c4c2011-05-18 16:08:5118#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4119#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]30fde822011-10-28 09:49:0520#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]8093a542011-05-13 07:29:3221#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3222#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0423#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1024#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2625#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2526#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]39a5b532011-10-22 01:47:0727#include "chrome/browser/extensions/extension_webrequest_api.h"
[email protected]32538d92011-08-25 00:09:2328#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1229#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2830#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0431#include "chrome/browser/notifications/desktop_notification_service.h"
32#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4233#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1234#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4135#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5036#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4137#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1438#include "chrome/browser/printing/printing_message_filter.h"
39#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3240#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1441#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3342#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4243#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1444#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0445#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4646#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4547#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0348#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3649#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4550#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
51#include "chrome/browser/tab_contents/tab_util.h"
52#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5653#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3054#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0155#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3056#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0457#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3458#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1259#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3860#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0961#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2562#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0963#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5164#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1465#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2666#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4967#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0968#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4169#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4570#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1271#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3272#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3673#include "content/browser/worker_host/worker_process_host.h"
[email protected]b48c9182011-10-26 18:03:3074#include "content/public/browser/browser_main_parts.h"
[email protected]c9b6eb62011-10-18 20:49:3975#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3476#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0177#include "net/base/cookie_monster.h"
78#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3979#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0880#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2681
[email protected]b48c9182011-10-26 18:03:3082#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3883#include "chrome/browser/chrome_browser_main_win.h"
84#elif defined(OS_MACOSX)
85#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:3086#elif defined(OS_CHROMEOS)
87#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3588#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3089#include "chrome/browser/chrome_browser_main_linux.h"
90#elif defined(OS_POSIX)
91#include "chrome/browser/chrome_browser_main_posix.h"
92#endif
93
[email protected]b48c9182011-10-26 18:03:3094#if defined(TOOLKIT_USES_GTK)
95#include "chrome/browser/chrome_browser_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:3896#endif
97
[email protected]c7480942011-11-08 19:18:2798#if defined(TOOLKIT_VIEWS)
99#include "chrome/browser/chrome_browser_parts_views.h"
100#endif
101
102#if defined(USE_AURA)
103#include "chrome/browser/chrome_browser_parts_aura.h"
[email protected]2ddfe432011-11-07 19:26:30104#endif
105
[email protected]e60c0232011-11-11 19:56:35106#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30107#include "base/linux_util.h"
108#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43109#endif
[email protected]b80f68432011-05-02 17:22:30110
[email protected]c7480942011-11-08 19:18:27111#if defined(TOUCH_UI)
112#include "chrome/browser/chrome_browser_parts_touch.h"
113#endif
114
[email protected]080f34f2011-09-20 05:39:26115#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32116#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21117#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45118#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]74313b42011-08-24 16:51:32119#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
120#elif defined(OS_MACOSX)
121#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32122#endif
123
[email protected]37a72af2011-06-13 05:42:01124#if defined(USE_NSS)
125#include "chrome/browser/ui/crypto_module_password_dialog.h"
126#endif
127
[email protected]91ad1472011-10-27 15:09:48128#if defined(USE_AURA)
129#include "content/browser/renderer_host/render_widget_host_view_aura.h"
130#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17131#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
132#elif defined(OS_WIN)
133#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
134#include "content/browser/renderer_host/render_widget_host_view_win.h"
[email protected]c92f4ed2011-10-21 19:50:21135#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17136#include "content/browser/renderer_host/render_widget_host_view_gtk.h"
137#elif defined(OS_MACOSX)
138#include "content/browser/renderer_host/render_widget_host_view_mac.h"
139#endif
140
[email protected]631bb742011-11-02 11:29:39141using content::BrowserThread;
142
[email protected]c5dbef02011-05-13 05:06:09143namespace {
144
[email protected]b8148ac2011-07-13 22:03:25145// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42146bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37147 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25148 return false;
149
150 // Special case the new tab page. In older versions of Chrome, the new tab
151 // page was hosted at chrome-internal:<blah>. This might be in people's saved
152 // sessions or bookmarks, so we say any URL with that scheme triggers the new
153 // tab page.
154 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
155 // Rewrite it with the proper new tab URL.
156 *url = GURL(chrome::kChromeUINewTabURL);
157 }
158
159 return true;
160}
161
[email protected]8d3132f62011-10-12 07:13:42162// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
163// below. Extension, and isolated apps require different privileges to be
164// granted to their RenderProcessHosts. This classification allows us to make
165// sure URLs are served by hosts with the right set of privileges.
166enum RenderProcessHostPrivilege {
167 PRIV_NORMAL,
168 PRIV_EXTENSION,
169 PRIV_ISOLATED,
170};
171
172RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
173 const GURL& url,
174 ExtensionService* service) {
175 // Default to a normal renderer cause it is lower privileged. This should only
176 // occur if the URL on a site instance is either malformed, or uninitialized.
177 // If it is malformed, then there is no need for better privileges anyways.
178 // If it is uninitialized, but eventually settles on being an a scheme other
179 // than normal webrenderer, the navigation logic will correct us out of band
180 // anyways.
181 if (!url.is_valid())
182 return PRIV_NORMAL;
183
184 if (url.SchemeIs(chrome::kExtensionScheme)) {
185 const Extension* extension = service->GetExtensionByURL(url);
186 if (extension && extension->is_storage_isolated()) {
187 return PRIV_ISOLATED;
188 }
189
190 return PRIV_EXTENSION;
191 }
192
193 return PRIV_NORMAL;
194}
195
196RenderProcessHostPrivilege GetProcessPrivilege(
197 RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46198 extensions::ProcessMap* process_map,
199 ExtensionService* service) {
200 // TODO(aa): It seems like hosted apps should be grouped separately from
201 // extensions: crbug.com/102533.
202 std::set<std::string> extension_ids =
203 process_map->GetExtensionsInProcess(process_host->id());
204 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21205 return PRIV_NORMAL;
206
[email protected]6f371442011-11-09 06:45:46207 for (std::set<std::string>::iterator iter = extension_ids.begin();
208 iter != extension_ids.end(); ++iter) {
209 const Extension* extension = service->GetExtensionById(*iter, false);
210 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42211 return PRIV_ISOLATED;
[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]9dbfff12011-07-01 19:37:07217} // namespace
[email protected]c5dbef02011-05-13 05:06:09218
[email protected]d977f9c2011-03-14 16:10:26219namespace chrome {
220
[email protected]b48c9182011-10-26 18:03:30221void ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]4573fbd2011-10-31 20:25:18222 const content::MainFunctionParams& parameters,
[email protected]b48c9182011-10-26 18:03:30223 std::vector<content::BrowserMainParts*>* parts_list) {
224 // Construct the Main browser parts based on the OS type.
225#if defined(OS_WIN)
226 parts_list->push_back(new ChromeBrowserMainPartsWin(parameters));
[email protected]f967b722011-09-07 00:58:04227#elif defined(OS_MACOSX)
[email protected]b48c9182011-10-26 18:03:30228 parts_list->push_back(new ChromeBrowserMainPartsMac(parameters));
229#elif defined(OS_CHROMEOS)
230 parts_list->push_back(new ChromeBrowserMainPartsChromeos(parameters));
[email protected]e60c0232011-11-11 19:56:35231#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:30232 parts_list->push_back(new ChromeBrowserMainPartsLinux(parameters));
233#elif defined(OS_POSIX)
234 parts_list->push_back(new ChromeBrowserMainPartsPosix(parameters));
[email protected]f967b722011-09-07 00:58:04235#else
[email protected]b48c9182011-10-26 18:03:30236 NOTREACHED();
237 parts_list->push_back(new ChromeBrowserMainParts(parameters));
238#endif
239
[email protected]c7480942011-11-08 19:18:27240 // Construct additional browser parts. Stages are called in the order in
241 // which they are added.
[email protected]b48c9182011-10-26 18:03:30242#if defined(TOOLKIT_USES_GTK)
243 parts_list->push_back(new ChromeBrowserPartsGtk());
[email protected]f967b722011-09-07 00:58:04244#endif
[email protected]c7480942011-11-08 19:18:27245
246#if defined(TOOLKIT_VIEWS)
247 parts_list->push_back(new ChromeBrowserPartsViews());
248#endif
249
250#if defined(USE_AURA)
251 parts_list->push_back(new ChromeBrowserPartsAura());
252#endif
253
[email protected]2ddfe432011-11-07 19:26:30254#if defined(TOUCH_UI)
255 parts_list->push_back(new ChromeBrowserPartsTouch());
256#endif
[email protected]c7480942011-11-08 19:18:27257
[email protected]f967b722011-09-07 00:58:04258}
259
[email protected]b45937e2011-10-07 19:49:17260RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
261 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48262#if defined(USE_AURA)
263 return new RenderWidgetHostViewAura(widget);
264#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17265 return new RenderWidgetHostViewViews(widget);
266#elif defined(OS_WIN)
267 if (views::Widget::IsPureViews())
268 return new RenderWidgetHostViewViews(widget);
269 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21270#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17271 return new RenderWidgetHostViewGtk(widget);
272#elif defined(OS_MACOSX)
273 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
274#else
275#error Need to create your platform ViewForWidget here.
276#endif
277}
278
[email protected]74313b42011-08-24 16:51:32279TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
280 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26281#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32282 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21283#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45284 return new TabContentsViewGtk(tab_contents,
285 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32286#elif defined(OS_MACOSX)
287 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32288#else
289#error Need to create your platform TabContentsView here.
290#endif
291}
292
[email protected]f364d1392011-04-08 21:03:10293void ChromeContentBrowserClient::RenderViewHostCreated(
294 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46295
296 SiteInstance* site_instance = render_view_host->site_instance();
297 Profile* profile = Profile::FromBrowserContext(
298 site_instance->browsing_instance()->browser_context());
299
300 new ChromeRenderViewHostObserver(render_view_host,
301 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10302 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26303}
304
[email protected]05fcf982011-04-19 00:44:14305void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
306 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02307 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37308 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14309 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02310 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]8aa7a412011-11-07 12:33:42311 host->channel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]05fcf982011-04-19 00:44:14312 host->channel()->AddFilter(new PrintingMessageFilter());
313 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02314 new SearchProviderInstallStateMessageFilter(id, profile));
315 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03316 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
317 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38318
[email protected]2ccf45c2011-08-19 23:35:50319 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
320 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07321
322 SendExtensionWebRequestStatusToHost(host);
[email protected]5ccd49512011-11-10 01:56:15323 ContentSettingsForOneType settings;
324 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
325 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &settings);
326 host->Send(new ChromeViewMsg_SetImageSettingRules(settings));
[email protected]05fcf982011-04-19 00:44:14327}
328
[email protected]97e6c4c2011-05-18 16:08:51329void ChromeContentBrowserClient::PluginProcessHostCreated(
330 PluginProcessHost* host) {
331 host->AddFilter(new ChromePluginMessageFilter(host));
332}
333
[email protected]1fd1a502011-03-30 16:55:56334content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
335 return ChromeWebUIFactory::GetInstance();
336}
337
[email protected]3d7474ff2011-07-27 17:47:37338GURL ChromeContentBrowserClient::GetEffectiveURL(
339 content::BrowserContext* browser_context, const GURL& url) {
340 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08341 // Get the effective URL for the given actual URL. If the URL is part of an
342 // installed app, the effective URL is an extension URL with the ID of that
343 // extension as the host. This has the effect of grouping apps together in
344 // a common SiteInstance.
345 if (!profile || !profile->GetExtensionService())
346 return url;
347
348 const Extension* extension =
349 profile->GetExtensionService()->GetExtensionByWebExtent(url);
350 if (!extension)
351 return url;
352
353 // If the URL is part of an extension's web extent, convert it to an
354 // extension URL.
355 return extension->GetResourceURL(url.path());
356}
357
[email protected]056ad2a2011-07-12 02:13:55358bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37359 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55360 // Non-extension URLs should generally use process-per-site-instance.
361 // Because we expect to use the effective URL, hosted apps URLs should have
362 // an extension scheme by now.
363 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
364 return false;
365
[email protected]3d7474ff2011-07-27 17:47:37366 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55367 if (!profile || !profile->GetExtensionService())
368 return false;
369
370 const Extension* extension =
371 profile->GetExtensionService()->GetExtensionByURL(effective_url);
372 if (!extension)
373 return false;
374
375 // If the URL is part of a hosted app that does not have the background
376 // permission, we want to give each instance its own process to improve
377 // responsiveness.
378 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
379 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
380 return false;
381
382 // Hosted apps that have the background permission must use process per site,
383 // since all instances can make synchronous calls to the background window.
384 // Other extensions should use process per site as well.
385 return true;
386}
387
[email protected]0f012df82011-05-19 14:15:29388bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03389 return url == GURL(chrome::kChromeUICrashURL) ||
390 url == GURL(chrome::kChromeUIKillURL) ||
391 url == GURL(chrome::kChromeUIHangURL) ||
392 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29393}
394
[email protected]2a5221b2011-09-27 23:07:31395bool ChromeContentBrowserClient::IsSuitableHost(
396 RenderProcessHost* process_host,
397 const GURL& site_url) {
398 Profile* profile =
399 Profile::FromBrowserContext(process_host->browser_context());
[email protected]8d3132f62011-10-12 07:13:42400 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46401 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31402
[email protected]8d3132f62011-10-12 07:13:42403 // These may be NULL during tests. In that case, just assume any site can
404 // share any host.
[email protected]6f371442011-11-09 06:45:46405 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31406 return true;
407
[email protected]a8c269a2011-10-25 20:17:22408 // Experimental:
409 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
410 // to share a renderer process. (We could allow pages from the same site or
411 // extensions of the same type to share, if we knew what the given process
412 // was dedicated to. Allowing no sharing is simpler for now.) This may
413 // cause resource exhaustion issues if too many sites are open at once.
414 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
415 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
416 return false;
417
[email protected]6f371442011-11-09 06:45:46418 return GetProcessPrivilege(process_host, process_map, service) ==
[email protected]8d3132f62011-10-12 07:13:42419 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]2a5221b2011-09-27 23:07:31420}
421
[email protected]6f371442011-11-09 06:45:46422void ChromeContentBrowserClient::SiteInstanceGotProcess(
423 SiteInstance* site_instance) {
424 CHECK(site_instance->HasProcess());
425
426 Profile* profile = Profile::FromBrowserContext(
427 site_instance->browsing_instance()->browser_context());
428 ExtensionService* service = profile->GetExtensionService();
429 if (!service)
430 return;
431
432 const Extension* extension =
433 service->GetExtensionByURL(site_instance->site());
434 if (!extension)
435 extension = service->GetExtensionByWebExtent(site_instance->site());
436 if (!extension)
437 return;
438
439 service->process_map()->Insert(
440 extension->id(), site_instance->GetProcess()->id());
441 BrowserThread::PostTask(
442 BrowserThread::IO, FROM_HERE,
443 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
444 profile->GetExtensionInfoMap(),
445 extension->id(),
446 site_instance->GetProcess()->id()));
447}
448
449void ChromeContentBrowserClient::SiteInstanceDeleting(
450 SiteInstance* site_instance) {
451 if (!site_instance->HasProcess())
452 return;
453
454 Profile* profile = Profile::FromBrowserContext(
455 site_instance->browsing_instance()->browser_context());
456 ExtensionService* service = profile->GetExtensionService();
457 if (!service)
458 return;
459
460 const Extension* extension =
461 service->GetExtensionByURL(site_instance->site());
462 if (!extension)
463 extension = service->GetExtensionByWebExtent(site_instance->site());
464 if (!extension)
465 return;
466
467 service->process_map()->Remove(
468 extension->id(), site_instance->GetProcess()->id());
469 BrowserThread::PostTask(
470 BrowserThread::IO, FROM_HERE,
471 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
472 profile->GetExtensionInfoMap(),
473 extension->id(),
474 site_instance->GetProcess()->id()));
475}
476
[email protected]e3daf3c2011-10-05 21:17:08477bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
478 const GURL& current_url,
479 const GURL& new_url) {
480 if (current_url.is_empty()) {
481 // Always choose a new process when navigating to extension URLs. The
482 // process grouping logic will combine all of a given extension's pages
483 // into the same process.
484 if (new_url.SchemeIs(chrome::kExtensionScheme))
485 return true;
486
487 return false;
488 }
489
490 // Also, we must switch if one is an extension and the other is not the exact
491 // same extension.
492 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
493 new_url.SchemeIs(chrome::kExtensionScheme)) {
494 if (current_url.GetOrigin() != new_url.GetOrigin())
495 return true;
496 }
497
498 return false;
499}
500
[email protected]763ec4ca2011-04-29 15:48:12501std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
502 const std::string& alias_name) {
503 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
504}
505
[email protected]b80f68432011-05-02 17:22:30506void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
507 CommandLine* command_line, int child_process_id) {
508#if defined(USE_LINUX_BREAKPAD)
509 if (IsCrashReporterEnabled()) {
510 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
511 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
512 }
513#elif defined(OS_MACOSX)
514 if (IsCrashReporterEnabled()) {
515 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
516 child_process_logging::GetClientId());
517 }
518#endif // OS_MACOSX
519
[email protected]f1933792011-06-14 00:49:34520 if (logging::DialogsAreSuppressed())
521 command_line->AppendSwitch(switches::kNoErrorDialogs);
522
[email protected]b80f68432011-05-02 17:22:30523 std::string process_type =
524 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17525 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52526 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30527 FilePath user_data_dir =
528 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
529 if (!user_data_dir.empty())
530 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
531#if defined(OS_CHROMEOS)
532 const std::string& login_profile =
533 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
534 if (!login_profile.empty())
535 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
536#endif
537
538 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
539
[email protected]3d7474ff2011-07-27 17:47:37540 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]6f371442011-11-09 06:45:46541 extensions::ProcessMap* process_map =
542 profile->GetExtensionService()->process_map();
543 if (process_map && process_map->Contains(process->id()))
[email protected]718eab62011-10-05 21:16:52544 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]718eab62011-10-05 21:16:52545
[email protected]3d7474ff2011-07-27 17:47:37546 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30547 // Currently this pref is only registered if applied via a policy.
548 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
549 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
550 // Turn this policy into a command line switch.
551 command_line->AppendSwitch(switches::kDisable3DAPIs);
552 }
553
554 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46555 // in the Profile preferences or the browser process.
556 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
557 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30558 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46559 }
[email protected]4287a3d2011-06-13 23:56:51560
561 static const char* const kSwitchNames[] = {
562 switches::kAllowHTTPBackgroundPage,
563 switches::kAllowScriptingGallery,
564 switches::kAppsCheckoutURL,
565 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31566 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51567 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51568 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51569 switches::kDomAutomationController,
570 switches::kDumpHistogramsOnExit,
571 switches::kEnableClickToPlay,
572 switches::kEnableCrxlessWebApps,
573 switches::kEnableExperimentalExtensionApis,
574 switches::kEnableInBrowserThumbnailing,
575 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12576 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51577 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53578 switches::kEnablePlatformApps,
[email protected]5714ee32011-08-18 01:51:24579 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51580 switches::kEnableSearchProviderApiV2,
581 switches::kEnableWatchdog,
582 switches::kExperimentalSpellcheckerFeatures,
583 switches::kMemoryProfiling,
584 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04585 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51586 switches::kPpapiFlashArgs,
587 switches::kPpapiFlashInProcess,
588 switches::kPpapiFlashPath,
589 switches::kPpapiFlashVersion,
590 switches::kProfilingAtStart,
591 switches::kProfilingFile,
592 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51593 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03594 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51595 };
596
597 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
598 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17599 } else if (process_type == switches::kUtilityProcess) {
600 if (browser_command_line.HasSwitch(
601 switches::kEnableExperimentalExtensionApis)) {
602 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
603 }
[email protected]4287a3d2011-06-13 23:56:51604 } else if (process_type == switches::kPluginProcess) {
605 static const char* const kSwitchNames[] = {
606 #if defined(OS_CHROMEOS)
607 switches::kLoginProfile,
608 #endif
609 switches::kMemoryProfiling,
610 switches::kSilentDumpOnDCHECK,
611 switches::kUserDataDir,
612 };
613
614 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
615 arraysize(kSwitchNames));
616 } else if (process_type == switches::kZygoteProcess) {
617 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51618 switches::kUserDataDir, // Make logs go to the right file.
619 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
620 switches::kPpapiFlashInProcess,
621 switches::kPpapiFlashPath,
622 switches::kPpapiFlashVersion,
623 };
624
625 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
626 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30627 }
[email protected]6f08af82011-09-15 01:19:03628
629 // The command line switch kEnableBenchmarking needs to be specified along
630 // with the kEnableStatsTable switch to ensure that the stats table global
631 // is initialized correctly.
632 if (command_line->HasSwitch(switches::kEnableBenchmarking))
633 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30634}
635
636std::string ChromeContentBrowserClient::GetApplicationLocale() {
637 return g_browser_process->GetApplicationLocale();
638}
639
[email protected]b5cca982011-05-26 04:42:08640std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37641 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
642 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08643}
644
[email protected]ac55e292011-06-24 05:16:08645SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22646 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]2cc6a9292011-10-13 21:41:01647#if defined(TOUCH_UI)
648 // In touch builds, we want large default favicons for the tabstrip, but in
649 // other places (such as bookmark, manage search engines, homepage) we assume
650 // default favicons are 16x16.
651 return rb.GetBitmapNamed(IDR_DEFAULT_LARGE_FAVICON);
652#else
[email protected]ac55e292011-06-24 05:16:08653 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
[email protected]2cc6a9292011-10-13 21:41:01654#endif
[email protected]ac55e292011-06-24 05:16:08655}
656
[email protected]a2176792011-05-08 19:30:49657bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09658 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19659 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09660 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
662 ProfileIOData* io_data =
663 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05664 return io_data->GetCookieSettings()->
665 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49666}
667
[email protected]ed24fad2011-05-10 22:44:01668bool ChromeContentBrowserClient::AllowGetCookie(
669 const GURL& url,
670 const GURL& first_party,
671 const net::CookieList& cookie_list,
672 const content::ResourceContext& context,
673 int render_process_id,
674 int render_view_id) {
675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32676 ProfileIOData* io_data =
677 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05678 bool allow = io_data->GetCookieSettings()->
679 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01680
[email protected]8093a542011-05-13 07:29:32681 BrowserThread::PostTask(
682 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03683 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
684 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01685 return allow;
686}
687
688bool ChromeContentBrowserClient::AllowSetCookie(
689 const GURL& url,
690 const GURL& first_party,
691 const std::string& cookie_line,
692 const content::ResourceContext& context,
693 int render_process_id,
694 int render_view_id,
695 net::CookieOptions* options) {
696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32697 ProfileIOData* io_data =
698 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01699
[email protected]30fde822011-10-28 09:49:05700 CookieSettings* cookie_settings = io_data->GetCookieSettings();
701 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
702
703 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09704 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01705
[email protected]8093a542011-05-13 07:29:32706 BrowserThread::PostTask(
707 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03708 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
709 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01710 return allow;
711}
712
[email protected]d5a19162011-06-30 18:51:54713bool ChromeContentBrowserClient::AllowSaveLocalState(
714 const content::ResourceContext& context) {
715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
716 ProfileIOData* io_data =
717 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
718 return !io_data->clear_local_state_on_exit()->GetValue();
719}
720
[email protected]5c5a88e2011-11-12 00:45:35721bool ChromeContentBrowserClient::AllowWorkerDatabase(
722 int worker_route_id,
723 const GURL& url,
724 const string16& name,
725 const string16& display_name,
726 unsigned long estimated_size,
727 WorkerProcessHost* worker_process_host) {
728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
729 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
730 worker_process_host->resource_context()->GetUserData(NULL));
731 CookieSettings* cookie_settings = io_data->GetCookieSettings();
732 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
733
734 // Record access to database for potential display in UI: Find the worker
735 // instance and forward the message to all attached documents.
736 WorkerProcessHost::Instances::const_iterator i;
737 for (i = worker_process_host->instances().begin();
738 i != worker_process_host->instances().end(); ++i) {
739 if (i->worker_route_id() != worker_route_id)
740 continue;
741 const WorkerDocumentSet::DocumentInfoSet& documents =
742 i->worker_document_set()->documents();
743 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
744 documents.begin(); doc != documents.end(); ++doc) {
745 BrowserThread::PostTask(
746 BrowserThread::UI, FROM_HERE,
747 base::Bind(
748 &TabSpecificContentSettings::WebDatabaseAccessed,
749 doc->render_process_id(), doc->render_view_id(),
750 url, name, display_name, !allow));
751 }
752 break;
753 }
754
755 return allow;
756}
757
758bool ChromeContentBrowserClient::AllowWorkerFileSystem(
759 int worker_route_id,
760 const GURL& url,
761 WorkerProcessHost* worker_process_host) {
762 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
763 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
764 worker_process_host->resource_context()->GetUserData(NULL));
765 CookieSettings* cookie_settings = io_data->GetCookieSettings();
766 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
767
768 // Record access to file system for potential display in UI: Find the worker
769 // instance and forward the message to all attached documents.
770 WorkerProcessHost::Instances::const_iterator i;
771 for (i = worker_process_host->instances().begin();
772 i != worker_process_host->instances().end(); ++i) {
773 if (i->worker_route_id() != worker_route_id)
774 continue;
775 const WorkerDocumentSet::DocumentInfoSet& documents =
776 i->worker_document_set()->documents();
777 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
778 documents.begin(); doc != documents.end(); ++doc) {
779 BrowserThread::PostTask(
780 BrowserThread::UI, FROM_HERE,
781 base::Bind(
782 &TabSpecificContentSettings::FileSystemAccessed,
783 doc->render_process_id(), doc->render_view_id(), url, !allow));
784 }
785 break;
786 }
787
788 return allow;
789}
790
[email protected]6133f922011-07-01 21:34:34791net::URLRequestContext*
792ChromeContentBrowserClient::OverrideRequestContextForURL(
793 const GURL& url, const content::ResourceContext& context) {
794 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
795 if (url.SchemeIs(chrome::kExtensionScheme)) {
796 ProfileIOData* io_data =
797 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
798 return io_data->extensions_request_context();
799 }
800
801 return NULL;
802}
803
[email protected]317f96c92011-05-31 06:53:41804QuotaPermissionContext*
805ChromeContentBrowserClient::CreateQuotaPermissionContext() {
806 return new ChromeQuotaPermissionContext();
807}
808
[email protected]a0ce3282011-08-19 20:49:52809void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42810 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42811}
812
[email protected]a0ce3282011-08-19 20:49:52813void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52814 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52815}
816
[email protected]848dd042011-06-04 18:24:03817void ChromeContentBrowserClient::AllowCertificateError(
818 SSLCertErrorHandler* handler,
819 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58820 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41821 // If the tab is being prerendered, cancel the prerender and the request.
822 TabContents* tab = tab_util::GetTabContentsByID(
823 handler->render_process_host_id(),
824 handler->tab_contents_id());
825 if (!tab) {
826 NOTREACHED();
827 return;
828 }
829 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50830 prerender::PrerenderManagerFactory::GetForProfile(
831 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41832 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
833 if (prerender_manager->prerender_tracker()->TryCancel(
834 handler->render_process_host_id(),
835 handler->tab_contents_id(),
836 prerender::FINAL_STATUS_SSL_ERROR)) {
837 handler->CancelRequest();
838 return;
839 }
840 }
841
842 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03843 SSLBlockingPage* blocking_page = new SSLBlockingPage(
844 handler, overridable, callback);
845 blocking_page->Show();
846}
847
[email protected]c99c442e2011-08-24 11:37:30848void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45849 int render_process_id,
850 int render_view_id,
851 SSLClientAuthHandler* handler) {
852 TabContents* tab = tab_util::GetTabContentsByID(
853 render_process_id, render_view_id);
854 if (!tab) {
855 NOTREACHED();
856 return;
857 }
858
859 TabContentsWrapper* wrapper =
860 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30861 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45862}
863
864void ChromeContentBrowserClient::AddNewCertificate(
865 net::URLRequest* request,
866 net::X509Certificate* cert,
867 int render_process_id,
868 int render_view_id) {
869 // The handler will run the UI and delete itself when it's finished.
870 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
871}
872
[email protected]941623e2011-06-07 23:06:04873void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
874 const GURL& source_origin,
875 int callback_context,
876 int render_process_id,
877 int render_view_id) {
878 RenderViewHost* rvh = RenderViewHost::FromID(
879 render_process_id, render_view_id);
880 if (!rvh) {
881 NOTREACHED();
882 return;
883 }
884
885 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37886 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04887 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37888 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04889 service->RequestPermission(
890 source_origin, render_process_id, render_view_id, callback_context,
891 tab_util::GetTabContentsByID(render_process_id, render_view_id));
892}
893
894WebKit::WebNotificationPresenter::Permission
895 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02896 const GURL& source_origin,
897 const content::ResourceContext& context,
898 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04899 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
900 ProfileIOData* io_data =
901 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
902
[email protected]34eec7ffe32011-11-02 23:49:02903 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
904 source_origin, render_process_id,
905 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04906 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04907
908 // Fall back to the regular notification preferences, which works on an
909 // origin basis.
910 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:37911 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:04912 WebKit::WebNotificationPresenter::PermissionNotAllowed;
913}
914
915void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:17916 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:04917 int render_process_id,
918 int render_view_id,
919 bool worker) {
920 RenderViewHost* rvh = RenderViewHost::FromID(
921 render_process_id, render_view_id);
922 if (!rvh) {
923 NOTREACHED();
924 return;
925 }
926
927 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37928 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04929 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37930 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04931 service->ShowDesktopNotification(
932 params, render_process_id, render_view_id,
933 worker ? DesktopNotificationService::WorkerNotification :
934 DesktopNotificationService::PageNotification);
935}
936
937void ChromeContentBrowserClient::CancelDesktopNotification(
938 int render_process_id,
939 int render_view_id,
940 int notification_id) {
941 RenderViewHost* rvh = RenderViewHost::FromID(
942 render_process_id, render_view_id);
943 if (!rvh) {
944 NOTREACHED();
945 return;
946 }
947
948 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37949 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04950 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37951 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04952 service->CancelDesktopNotification(
953 render_process_id, render_view_id, notification_id);
954}
955
[email protected]9f3fba52011-06-08 20:37:19956bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:02957 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:19958 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:02959 const content::ResourceContext& context,
960 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:19961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
962 // If the opener is trying to create a background window but doesn't have
963 // the appropriate permission, fail the attempt.
964 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
965 ProfileIOData* io_data =
966 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:02967 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
968 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:19969 }
970 return true;
971}
972
973std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
974 const GURL& url, const content::ResourceContext& context) {
975 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
976 // Check if it's an extension-created worker, in which case we want to use
977 // the name of the extension.
978 ProfileIOData* io_data =
979 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
980 const Extension* extension =
981 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
982 return extension ? extension->name() : std::string();
983}
984
[email protected]3cb054e62011-06-13 05:21:17985ResourceDispatcherHost*
986 ChromeContentBrowserClient::GetResourceDispatcherHost() {
987 return g_browser_process->resource_dispatcher_host();
988}
989
990ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
991 return g_browser_process->clipboard();
992}
993
[email protected]8f6a3b852011-07-19 16:48:56994MHTMLGenerationManager*
995 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
996 return g_browser_process->mhtml_generation_manager();
997}
998
[email protected]dce502762011-07-20 08:53:49999DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
1000 return g_browser_process->devtools_manager();
1001}
1002
[email protected]ae6e9912011-07-27 01:18:281003net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1004 return g_browser_process->net_log();
1005}
1006
[email protected]3bc0b562011-08-24 23:51:041007speech_input::SpeechInputManager*
1008 ChromeContentBrowserClient::GetSpeechInputManager() {
1009 return speech_input::ChromeSpeechInputManager::GetInstance();
1010}
1011
[email protected]32538d92011-08-25 00:09:231012AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1013 return new ChromeAccessTokenStore();
1014}
1015
[email protected]dbae6b02011-06-29 23:51:411016bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1017 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1018 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1019}
1020
[email protected]5092c282011-10-29 21:48:371021WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
1022 return RenderViewHostDelegateHelper::GetWebkitPrefs(rvh);
[email protected]181a95ee2011-07-12 19:26:361023}
1024
1025void ChromeContentBrowserClient::UpdateInspectorSetting(
1026 RenderViewHost* rvh, const std::string& key, const std::string& value) {
1027 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:371028 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:361029}
1030
1031void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
1032 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:371033 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:361034}
1035
[email protected]b8148ac2011-07-13 22:03:251036void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1037 BrowserURLHandler* handler) {
1038 // Add the default URL handlers.
1039 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1040 BrowserURLHandler::null_handler());
1041 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1042 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1043
1044 // about:
1045 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1046 BrowserURLHandler::null_handler());
1047 // chrome: & friends.
1048 handler->AddHandlerPair(&HandleWebUI,
1049 BrowserURLHandler::null_handler());
1050}
1051
1052void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371053 Profile* profile = Profile::FromBrowserContext(
1054 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:251055 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1056 BrowsingDataRemover::EVERYTHING,
1057 base::Time());
1058 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1059 // BrowsingDataRemover takes care of deleting itself when done.
1060}
1061
1062void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371063 Profile* profile = Profile::FromBrowserContext(
1064 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:251065 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1066 BrowsingDataRemover::EVERYTHING,
1067 base::Time());
[email protected]dceaa912011-09-06 17:17:231068 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251069 remover->Remove(remove_mask);
1070 // BrowsingDataRemover takes care of deleting itself when done.
1071}
1072
[email protected]e1d16eb92011-08-18 23:19:321073FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1074 return download_util::GetDefaultDownloadDirectory();
1075}
1076
[email protected]c9b6eb62011-10-18 20:49:391077std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1078 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1079}
1080
[email protected]e60c0232011-11-11 19:56:351081#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301082int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521083 const CommandLine& command_line) {
1084 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071085 ExtensionCrashHandlerHostLinux* crash_handler =
1086 ExtensionCrashHandlerHostLinux::GetInstance();
1087 return crash_handler->GetDeathSignalSocket();
1088 }
1089
[email protected]718eab62011-10-05 21:16:521090 std::string process_type =
1091 command_line.GetSwitchValueASCII(switches::kProcessType);
1092
1093 if (process_type == switches::kRendererProcess)
1094 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1095
[email protected]b80f68432011-05-02 17:22:301096 if (process_type == switches::kPluginProcess)
1097 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1098
1099 if (process_type == switches::kPpapiPluginProcess)
1100 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1101
1102 if (process_type == switches::kGpuProcess)
1103 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1104
1105 return -1;
1106}
[email protected]e60c0232011-11-11 19:56:351107#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301108
[email protected]4a65826d2011-08-25 16:04:011109#if defined(OS_WIN)
1110const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1111 return chrome::kBrowserResourcesDll;
1112}
1113#endif
1114
[email protected]37a72af2011-06-13 05:42:011115#if defined(USE_NSS)
1116crypto::CryptoModuleBlockingPasswordDelegate*
1117 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1118 const GURL& url) {
1119 return browser::NewCryptoModuleBlockingDialogDelegate(
1120 browser::kCryptoModulePasswordKeygen, url.host());
1121}
1122#endif
1123
[email protected]d977f9c2011-03-14 16:10:261124} // namespace chrome