blob: 94b16fa09f45b53ed512f85f8a3748b2850b5fc6 [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]317c58f02011-11-09 02:15:037#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:308#include "base/command_line.h"
9#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2510#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3011#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2312#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1213#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0314#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]97e6c4c2011-05-18 16:08:5115#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4116#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3617#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]30fde822011-10-28 09:49:0518#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]8093a542011-05-13 07:29:3219#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3220#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0421#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1022#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2623#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2524#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]39a5b532011-10-22 01:47:0725#include "chrome/browser/extensions/extension_webrequest_api.h"
[email protected]32538d92011-08-25 00:09:2326#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1227#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2828#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0429#include "chrome/browser/notifications/desktop_notification_service.h"
30#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4231#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1232#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4133#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5034#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4135#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1436#include "chrome/browser/printing/printing_message_filter.h"
37#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3238#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1439#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3340#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4241#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1442#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0443#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4644#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4545#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0346#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3647#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4548#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
49#include "chrome/browser/tab_contents/tab_util.h"
50#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5651#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3052#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0153#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3054#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0455#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3456#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1257#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3858#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0959#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2560#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0961#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5162#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1463#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2664#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4965#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0966#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4167#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4568#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1269#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3270#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3671#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0472#include "content/common/desktop_notification_messages.h"
[email protected]b48c9182011-10-26 18:03:3073#include "content/public/browser/browser_main_parts.h"
[email protected]c9b6eb62011-10-18 20:49:3974#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3475#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0176#include "net/base/cookie_monster.h"
77#include "net/base/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3978#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0879#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2680
[email protected]b48c9182011-10-26 18:03:3081#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3882#include "chrome/browser/chrome_browser_main_win.h"
83#elif defined(OS_MACOSX)
84#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]b48c9182011-10-26 18:03:3085#elif defined(OS_CHROMEOS)
86#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3587#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3088#include "chrome/browser/chrome_browser_main_linux.h"
89#elif defined(OS_POSIX)
90#include "chrome/browser/chrome_browser_main_posix.h"
91#endif
92
[email protected]b48c9182011-10-26 18:03:3093#if defined(TOOLKIT_USES_GTK)
94#include "chrome/browser/chrome_browser_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:3895#endif
96
[email protected]c7480942011-11-08 19:18:2797#if defined(TOOLKIT_VIEWS)
98#include "chrome/browser/chrome_browser_parts_views.h"
99#endif
100
101#if defined(USE_AURA)
102#include "chrome/browser/chrome_browser_parts_aura.h"
[email protected]2ddfe432011-11-07 19:26:30103#endif
104
[email protected]e60c0232011-11-11 19:56:35105#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30106#include "base/linux_util.h"
107#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43108#endif
[email protected]b80f68432011-05-02 17:22:30109
[email protected]c7480942011-11-08 19:18:27110#if defined(TOUCH_UI)
111#include "chrome/browser/chrome_browser_parts_touch.h"
112#endif
113
[email protected]080f34f2011-09-20 05:39:26114#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32115#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21116#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32117#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
118#elif defined(OS_MACOSX)
119#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32120#endif
121
[email protected]37a72af2011-06-13 05:42:01122#if defined(USE_NSS)
123#include "chrome/browser/ui/crypto_module_password_dialog.h"
124#endif
125
[email protected]91ad1472011-10-27 15:09:48126#if defined(USE_AURA)
127#include "content/browser/renderer_host/render_widget_host_view_aura.h"
128#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17129#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
130#elif defined(OS_WIN)
131#include "chrome/browser/renderer_host/render_widget_host_view_views.h"
132#include "content/browser/renderer_host/render_widget_host_view_win.h"
[email protected]c92f4ed2011-10-21 19:50:21133#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17134#include "content/browser/renderer_host/render_widget_host_view_gtk.h"
135#elif defined(OS_MACOSX)
136#include "content/browser/renderer_host/render_widget_host_view_mac.h"
137#endif
138
[email protected]631bb742011-11-02 11:29:39139using content::BrowserThread;
140
[email protected]c5dbef02011-05-13 05:06:09141namespace {
142
[email protected]b8148ac2011-07-13 22:03:25143// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42144bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37145 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25146 return false;
147
148 // Special case the new tab page. In older versions of Chrome, the new tab
149 // page was hosted at chrome-internal:<blah>. This might be in people's saved
150 // sessions or bookmarks, so we say any URL with that scheme triggers the new
151 // tab page.
152 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
153 // Rewrite it with the proper new tab URL.
154 *url = GURL(chrome::kChromeUINewTabURL);
155 }
156
157 return true;
158}
159
[email protected]8d3132f62011-10-12 07:13:42160// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
161// below. Extension, and isolated apps require different privileges to be
162// granted to their RenderProcessHosts. This classification allows us to make
163// sure URLs are served by hosts with the right set of privileges.
164enum RenderProcessHostPrivilege {
165 PRIV_NORMAL,
166 PRIV_EXTENSION,
167 PRIV_ISOLATED,
168};
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)) {
183 const Extension* extension = service->GetExtensionByURL(url);
184 if (extension && extension->is_storage_isolated()) {
185 return PRIV_ISOLATED;
186 }
187
188 return PRIV_EXTENSION;
189 }
190
191 return PRIV_NORMAL;
192}
193
194RenderProcessHostPrivilege GetProcessPrivilege(
195 RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46196 extensions::ProcessMap* process_map,
197 ExtensionService* service) {
198 // TODO(aa): It seems like hosted apps should be grouped separately from
199 // extensions: crbug.com/102533.
200 std::set<std::string> extension_ids =
201 process_map->GetExtensionsInProcess(process_host->id());
202 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]8d3132f62011-10-12 07:13:42210 }
211
[email protected]676f6ab2011-10-19 20:23:21212 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42213}
214
[email protected]9dbfff12011-07-01 19:37:07215} // namespace
[email protected]c5dbef02011-05-13 05:06:09216
[email protected]d977f9c2011-03-14 16:10:26217namespace chrome {
218
[email protected]b48c9182011-10-26 18:03:30219void ChromeContentBrowserClient::CreateBrowserMainParts(
[email protected]4573fbd2011-10-31 20:25:18220 const content::MainFunctionParams& parameters,
[email protected]b48c9182011-10-26 18:03:30221 std::vector<content::BrowserMainParts*>* parts_list) {
222 // Construct the Main browser parts based on the OS type.
223#if defined(OS_WIN)
224 parts_list->push_back(new ChromeBrowserMainPartsWin(parameters));
[email protected]f967b722011-09-07 00:58:04225#elif defined(OS_MACOSX)
[email protected]b48c9182011-10-26 18:03:30226 parts_list->push_back(new ChromeBrowserMainPartsMac(parameters));
227#elif defined(OS_CHROMEOS)
228 parts_list->push_back(new ChromeBrowserMainPartsChromeos(parameters));
[email protected]e60c0232011-11-11 19:56:35229#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:30230 parts_list->push_back(new ChromeBrowserMainPartsLinux(parameters));
231#elif defined(OS_POSIX)
232 parts_list->push_back(new ChromeBrowserMainPartsPosix(parameters));
[email protected]f967b722011-09-07 00:58:04233#else
[email protected]b48c9182011-10-26 18:03:30234 NOTREACHED();
235 parts_list->push_back(new ChromeBrowserMainParts(parameters));
236#endif
237
[email protected]c7480942011-11-08 19:18:27238 // Construct additional browser parts. Stages are called in the order in
239 // which they are added.
[email protected]b48c9182011-10-26 18:03:30240#if defined(TOOLKIT_USES_GTK)
241 parts_list->push_back(new ChromeBrowserPartsGtk());
[email protected]f967b722011-09-07 00:58:04242#endif
[email protected]c7480942011-11-08 19:18:27243
244#if defined(TOOLKIT_VIEWS)
245 parts_list->push_back(new ChromeBrowserPartsViews());
246#endif
247
248#if defined(USE_AURA)
249 parts_list->push_back(new ChromeBrowserPartsAura());
250#endif
251
[email protected]2ddfe432011-11-07 19:26:30252#if defined(TOUCH_UI)
253 parts_list->push_back(new ChromeBrowserPartsTouch());
254#endif
[email protected]c7480942011-11-08 19:18:27255
[email protected]f967b722011-09-07 00:58:04256}
257
[email protected]b45937e2011-10-07 19:49:17258RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget(
259 RenderWidgetHost* widget) {
[email protected]91ad1472011-10-27 15:09:48260#if defined(USE_AURA)
261 return new RenderWidgetHostViewAura(widget);
262#elif defined(TOUCH_UI)
[email protected]b45937e2011-10-07 19:49:17263 return new RenderWidgetHostViewViews(widget);
264#elif defined(OS_WIN)
265 if (views::Widget::IsPureViews())
266 return new RenderWidgetHostViewViews(widget);
267 return new RenderWidgetHostViewWin(widget);
[email protected]c92f4ed2011-10-21 19:50:21268#elif defined(TOOLKIT_USES_GTK)
[email protected]b45937e2011-10-07 19:49:17269 return new RenderWidgetHostViewGtk(widget);
270#elif defined(OS_MACOSX)
271 return render_widget_host_view_mac::CreateRenderWidgetHostView(widget);
272#else
273#error Need to create your platform ViewForWidget here.
274#endif
275}
276
[email protected]74313b42011-08-24 16:51:32277TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
278 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26279#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32280 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21281#elif defined(TOOLKIT_USES_GTK)
[email protected]74313b42011-08-24 16:51:32282 return new TabContentsViewGtk(tab_contents);
283#elif defined(OS_MACOSX)
284 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32285#else
286#error Need to create your platform TabContentsView here.
287#endif
288}
289
[email protected]f364d1392011-04-08 21:03:10290void ChromeContentBrowserClient::RenderViewHostCreated(
291 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46292
293 SiteInstance* site_instance = render_view_host->site_instance();
294 Profile* profile = Profile::FromBrowserContext(
295 site_instance->browsing_instance()->browser_context());
296
297 new ChromeRenderViewHostObserver(render_view_host,
298 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10299 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26300}
301
[email protected]05fcf982011-04-19 00:44:14302void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
303 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02304 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37305 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14306 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02307 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]8aa7a412011-11-07 12:33:42308 host->channel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]05fcf982011-04-19 00:44:14309 host->channel()->AddFilter(new PrintingMessageFilter());
310 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02311 new SearchProviderInstallStateMessageFilter(id, profile));
312 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03313 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
314 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38315
[email protected]2ccf45c2011-08-19 23:35:50316 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
317 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07318
319 SendExtensionWebRequestStatusToHost(host);
[email protected]5ccd49512011-11-10 01:56:15320 ContentSettingsForOneType settings;
321 HostContentSettingsMap* map = profile->GetHostContentSettingsMap();
322 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, "", &settings);
323 host->Send(new ChromeViewMsg_SetImageSettingRules(settings));
[email protected]05fcf982011-04-19 00:44:14324}
325
[email protected]97e6c4c2011-05-18 16:08:51326void ChromeContentBrowserClient::PluginProcessHostCreated(
327 PluginProcessHost* host) {
328 host->AddFilter(new ChromePluginMessageFilter(host));
329}
330
[email protected]5327dfb2011-05-03 17:50:36331void ChromeContentBrowserClient::WorkerProcessHostCreated(
332 WorkerProcessHost* host) {
333 host->AddFilter(new ChromeWorkerMessageFilter(host));
334}
335
[email protected]1fd1a502011-03-30 16:55:56336content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
337 return ChromeWebUIFactory::GetInstance();
338}
339
[email protected]3d7474ff2011-07-27 17:47:37340GURL ChromeContentBrowserClient::GetEffectiveURL(
341 content::BrowserContext* browser_context, const GURL& url) {
342 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08343 // Get the effective URL for the given actual URL. If the URL is part of an
344 // installed app, the effective URL is an extension URL with the ID of that
345 // extension as the host. This has the effect of grouping apps together in
346 // a common SiteInstance.
347 if (!profile || !profile->GetExtensionService())
348 return url;
349
350 const Extension* extension =
351 profile->GetExtensionService()->GetExtensionByWebExtent(url);
352 if (!extension)
353 return url;
354
355 // If the URL is part of an extension's web extent, convert it to an
356 // extension URL.
357 return extension->GetResourceURL(url.path());
358}
359
[email protected]056ad2a2011-07-12 02:13:55360bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37361 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55362 // Non-extension URLs should generally use process-per-site-instance.
363 // Because we expect to use the effective URL, hosted apps URLs should have
364 // an extension scheme by now.
365 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
366 return false;
367
[email protected]3d7474ff2011-07-27 17:47:37368 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55369 if (!profile || !profile->GetExtensionService())
370 return false;
371
372 const Extension* extension =
373 profile->GetExtensionService()->GetExtensionByURL(effective_url);
374 if (!extension)
375 return false;
376
377 // If the URL is part of a hosted app that does not have the background
378 // permission, we want to give each instance its own process to improve
379 // responsiveness.
380 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
381 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
382 return false;
383
384 // Hosted apps that have the background permission must use process per site,
385 // since all instances can make synchronous calls to the background window.
386 // Other extensions should use process per site as well.
387 return true;
388}
389
[email protected]0f012df82011-05-19 14:15:29390bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03391 return url == GURL(chrome::kChromeUICrashURL) ||
392 url == GURL(chrome::kChromeUIKillURL) ||
393 url == GURL(chrome::kChromeUIHangURL) ||
394 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29395}
396
[email protected]2a5221b2011-09-27 23:07:31397bool ChromeContentBrowserClient::IsSuitableHost(
398 RenderProcessHost* process_host,
399 const GURL& site_url) {
400 Profile* profile =
401 Profile::FromBrowserContext(process_host->browser_context());
[email protected]8d3132f62011-10-12 07:13:42402 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46403 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31404
[email protected]8d3132f62011-10-12 07:13:42405 // These may be NULL during tests. In that case, just assume any site can
406 // share any host.
[email protected]6f371442011-11-09 06:45:46407 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31408 return true;
409
[email protected]a8c269a2011-10-25 20:17:22410 // Experimental:
411 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
412 // to share a renderer process. (We could allow pages from the same site or
413 // extensions of the same type to share, if we knew what the given process
414 // was dedicated to. Allowing no sharing is simpler for now.) This may
415 // cause resource exhaustion issues if too many sites are open at once.
416 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
417 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
418 return false;
419
[email protected]6f371442011-11-09 06:45:46420 return GetProcessPrivilege(process_host, process_map, service) ==
[email protected]8d3132f62011-10-12 07:13:42421 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]2a5221b2011-09-27 23:07:31422}
423
[email protected]6f371442011-11-09 06:45:46424void ChromeContentBrowserClient::SiteInstanceGotProcess(
425 SiteInstance* site_instance) {
426 CHECK(site_instance->HasProcess());
427
428 Profile* profile = Profile::FromBrowserContext(
429 site_instance->browsing_instance()->browser_context());
430 ExtensionService* service = profile->GetExtensionService();
431 if (!service)
432 return;
433
434 const Extension* extension =
435 service->GetExtensionByURL(site_instance->site());
436 if (!extension)
437 extension = service->GetExtensionByWebExtent(site_instance->site());
438 if (!extension)
439 return;
440
441 service->process_map()->Insert(
442 extension->id(), site_instance->GetProcess()->id());
443 BrowserThread::PostTask(
444 BrowserThread::IO, FROM_HERE,
445 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
446 profile->GetExtensionInfoMap(),
447 extension->id(),
448 site_instance->GetProcess()->id()));
449}
450
451void ChromeContentBrowserClient::SiteInstanceDeleting(
452 SiteInstance* site_instance) {
453 if (!site_instance->HasProcess())
454 return;
455
456 Profile* profile = Profile::FromBrowserContext(
457 site_instance->browsing_instance()->browser_context());
458 ExtensionService* service = profile->GetExtensionService();
459 if (!service)
460 return;
461
462 const Extension* extension =
463 service->GetExtensionByURL(site_instance->site());
464 if (!extension)
465 extension = service->GetExtensionByWebExtent(site_instance->site());
466 if (!extension)
467 return;
468
469 service->process_map()->Remove(
470 extension->id(), site_instance->GetProcess()->id());
471 BrowserThread::PostTask(
472 BrowserThread::IO, FROM_HERE,
473 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
474 profile->GetExtensionInfoMap(),
475 extension->id(),
476 site_instance->GetProcess()->id()));
477}
478
[email protected]e3daf3c2011-10-05 21:17:08479bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
480 const GURL& current_url,
481 const GURL& new_url) {
482 if (current_url.is_empty()) {
483 // Always choose a new process when navigating to extension URLs. The
484 // process grouping logic will combine all of a given extension's pages
485 // into the same process.
486 if (new_url.SchemeIs(chrome::kExtensionScheme))
487 return true;
488
489 return false;
490 }
491
492 // Also, we must switch if one is an extension and the other is not the exact
493 // same extension.
494 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
495 new_url.SchemeIs(chrome::kExtensionScheme)) {
496 if (current_url.GetOrigin() != new_url.GetOrigin())
497 return true;
498 }
499
500 return false;
501}
502
[email protected]763ec4ca2011-04-29 15:48:12503std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
504 const std::string& alias_name) {
505 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
506}
507
[email protected]b80f68432011-05-02 17:22:30508void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
509 CommandLine* command_line, int child_process_id) {
510#if defined(USE_LINUX_BREAKPAD)
511 if (IsCrashReporterEnabled()) {
512 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
513 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
514 }
515#elif defined(OS_MACOSX)
516 if (IsCrashReporterEnabled()) {
517 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
518 child_process_logging::GetClientId());
519 }
520#endif // OS_MACOSX
521
[email protected]f1933792011-06-14 00:49:34522 if (logging::DialogsAreSuppressed())
523 command_line->AppendSwitch(switches::kNoErrorDialogs);
524
[email protected]b80f68432011-05-02 17:22:30525 std::string process_type =
526 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17527 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52528 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30529 FilePath user_data_dir =
530 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
531 if (!user_data_dir.empty())
532 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
533#if defined(OS_CHROMEOS)
534 const std::string& login_profile =
535 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
536 if (!login_profile.empty())
537 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
538#endif
539
540 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
541
[email protected]3d7474ff2011-07-27 17:47:37542 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]6f371442011-11-09 06:45:46543 extensions::ProcessMap* process_map =
544 profile->GetExtensionService()->process_map();
545 if (process_map && process_map->Contains(process->id()))
[email protected]718eab62011-10-05 21:16:52546 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]718eab62011-10-05 21:16:52547
[email protected]3d7474ff2011-07-27 17:47:37548 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30549 // Currently this pref is only registered if applied via a policy.
550 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
551 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
552 // Turn this policy into a command line switch.
553 command_line->AppendSwitch(switches::kDisable3DAPIs);
554 }
555
556 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46557 // in the Profile preferences or the browser process.
558 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
559 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30560 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46561 }
[email protected]4287a3d2011-06-13 23:56:51562
563 static const char* const kSwitchNames[] = {
564 switches::kAllowHTTPBackgroundPage,
565 switches::kAllowScriptingGallery,
566 switches::kAppsCheckoutURL,
567 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31568 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51569 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51570 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51571 switches::kDomAutomationController,
572 switches::kDumpHistogramsOnExit,
573 switches::kEnableClickToPlay,
574 switches::kEnableCrxlessWebApps,
575 switches::kEnableExperimentalExtensionApis,
576 switches::kEnableInBrowserThumbnailing,
577 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12578 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51579 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24580 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51581 switches::kEnableSearchProviderApiV2,
582 switches::kEnableWatchdog,
583 switches::kExperimentalSpellcheckerFeatures,
584 switches::kMemoryProfiling,
585 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04586 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51587 switches::kPpapiFlashArgs,
588 switches::kPpapiFlashInProcess,
589 switches::kPpapiFlashPath,
590 switches::kPpapiFlashVersion,
591 switches::kProfilingAtStart,
592 switches::kProfilingFile,
593 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51594 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03595 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51596 };
597
598 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
599 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17600 } else if (process_type == switches::kUtilityProcess) {
601 if (browser_command_line.HasSwitch(
602 switches::kEnableExperimentalExtensionApis)) {
603 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
604 }
[email protected]4287a3d2011-06-13 23:56:51605 } else if (process_type == switches::kPluginProcess) {
606 static const char* const kSwitchNames[] = {
607 #if defined(OS_CHROMEOS)
608 switches::kLoginProfile,
609 #endif
610 switches::kMemoryProfiling,
611 switches::kSilentDumpOnDCHECK,
612 switches::kUserDataDir,
613 };
614
615 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
616 arraysize(kSwitchNames));
617 } else if (process_type == switches::kZygoteProcess) {
618 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51619 switches::kUserDataDir, // Make logs go to the right file.
620 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
621 switches::kPpapiFlashInProcess,
622 switches::kPpapiFlashPath,
623 switches::kPpapiFlashVersion,
624 };
625
626 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
627 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30628 }
[email protected]6f08af82011-09-15 01:19:03629
630 // The command line switch kEnableBenchmarking needs to be specified along
631 // with the kEnableStatsTable switch to ensure that the stats table global
632 // is initialized correctly.
633 if (command_line->HasSwitch(switches::kEnableBenchmarking))
634 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30635}
636
637std::string ChromeContentBrowserClient::GetApplicationLocale() {
638 return g_browser_process->GetApplicationLocale();
639}
640
[email protected]b5cca982011-05-26 04:42:08641std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37642 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
643 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08644}
645
[email protected]ac55e292011-06-24 05:16:08646SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
647 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
[email protected]2cc6a9292011-10-13 21:41:01648#if defined(TOUCH_UI)
649 // In touch builds, we want large default favicons for the tabstrip, but in
650 // other places (such as bookmark, manage search engines, homepage) we assume
651 // default favicons are 16x16.
652 return rb.GetBitmapNamed(IDR_DEFAULT_LARGE_FAVICON);
653#else
[email protected]ac55e292011-06-24 05:16:08654 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
[email protected]2cc6a9292011-10-13 21:41:01655#endif
[email protected]ac55e292011-06-24 05:16:08656}
657
[email protected]a2176792011-05-08 19:30:49658bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09659 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19660 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09661 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
663 ProfileIOData* io_data =
664 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05665 return io_data->GetCookieSettings()->
666 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49667}
668
[email protected]ed24fad2011-05-10 22:44:01669bool ChromeContentBrowserClient::AllowGetCookie(
670 const GURL& url,
671 const GURL& first_party,
672 const net::CookieList& cookie_list,
673 const content::ResourceContext& context,
674 int render_process_id,
675 int render_view_id) {
676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32677 ProfileIOData* io_data =
678 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05679 bool allow = io_data->GetCookieSettings()->
680 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01681
[email protected]8093a542011-05-13 07:29:32682 BrowserThread::PostTask(
683 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03684 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
685 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01686 return allow;
687}
688
689bool ChromeContentBrowserClient::AllowSetCookie(
690 const GURL& url,
691 const GURL& first_party,
692 const std::string& cookie_line,
693 const content::ResourceContext& context,
694 int render_process_id,
695 int render_view_id,
696 net::CookieOptions* options) {
697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32698 ProfileIOData* io_data =
699 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01700
[email protected]30fde822011-10-28 09:49:05701 CookieSettings* cookie_settings = io_data->GetCookieSettings();
702 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
703
704 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09705 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01706
[email protected]8093a542011-05-13 07:29:32707 BrowserThread::PostTask(
708 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03709 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
710 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01711 return allow;
712}
713
[email protected]d5a19162011-06-30 18:51:54714bool ChromeContentBrowserClient::AllowSaveLocalState(
715 const content::ResourceContext& context) {
716 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
717 ProfileIOData* io_data =
718 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
719 return !io_data->clear_local_state_on_exit()->GetValue();
720}
721
[email protected]6133f922011-07-01 21:34:34722net::URLRequestContext*
723ChromeContentBrowserClient::OverrideRequestContextForURL(
724 const GURL& url, const content::ResourceContext& context) {
725 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
726 if (url.SchemeIs(chrome::kExtensionScheme)) {
727 ProfileIOData* io_data =
728 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
729 return io_data->extensions_request_context();
730 }
731
732 return NULL;
733}
734
[email protected]317f96c92011-05-31 06:53:41735QuotaPermissionContext*
736ChromeContentBrowserClient::CreateQuotaPermissionContext() {
737 return new ChromeQuotaPermissionContext();
738}
739
[email protected]a0ce3282011-08-19 20:49:52740void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42741 // On Mac, this call needs to be done on the UI thread. On other platforms,
742 // do it on the FILE thread so we don't slow down UI.
743#if defined(OS_MACOSX)
744 platform_util::OpenItem(path);
745#else
746 BrowserThread::PostTask(
747 BrowserThread::FILE, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03748 base::Bind(&platform_util::OpenItem, path));
[email protected]0609b17f2011-05-31 20:13:42749#endif
750}
751
[email protected]a0ce3282011-08-19 20:49:52752void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
753#if defined(OS_MACOSX)
754 // Mac needs to run this operation on the UI thread.
755 platform_util::ShowItemInFolder(path);
756#else
757 BrowserThread::PostTask(
758 BrowserThread::FILE, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03759 base::Bind(&platform_util::ShowItemInFolder, path));
[email protected]a0ce3282011-08-19 20:49:52760#endif
761}
762
[email protected]848dd042011-06-04 18:24:03763void ChromeContentBrowserClient::AllowCertificateError(
764 SSLCertErrorHandler* handler,
765 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58766 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41767 // If the tab is being prerendered, cancel the prerender and the request.
768 TabContents* tab = tab_util::GetTabContentsByID(
769 handler->render_process_host_id(),
770 handler->tab_contents_id());
771 if (!tab) {
772 NOTREACHED();
773 return;
774 }
775 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50776 prerender::PrerenderManagerFactory::GetForProfile(
777 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41778 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
779 if (prerender_manager->prerender_tracker()->TryCancel(
780 handler->render_process_host_id(),
781 handler->tab_contents_id(),
782 prerender::FINAL_STATUS_SSL_ERROR)) {
783 handler->CancelRequest();
784 return;
785 }
786 }
787
788 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03789 SSLBlockingPage* blocking_page = new SSLBlockingPage(
790 handler, overridable, callback);
791 blocking_page->Show();
792}
793
[email protected]c99c442e2011-08-24 11:37:30794void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45795 int render_process_id,
796 int render_view_id,
797 SSLClientAuthHandler* handler) {
798 TabContents* tab = tab_util::GetTabContentsByID(
799 render_process_id, render_view_id);
800 if (!tab) {
801 NOTREACHED();
802 return;
803 }
804
805 TabContentsWrapper* wrapper =
806 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30807 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45808}
809
810void ChromeContentBrowserClient::AddNewCertificate(
811 net::URLRequest* request,
812 net::X509Certificate* cert,
813 int render_process_id,
814 int render_view_id) {
815 // The handler will run the UI and delete itself when it's finished.
816 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
817}
818
[email protected]941623e2011-06-07 23:06:04819void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
820 const GURL& source_origin,
821 int callback_context,
822 int render_process_id,
823 int render_view_id) {
824 RenderViewHost* rvh = RenderViewHost::FromID(
825 render_process_id, render_view_id);
826 if (!rvh) {
827 NOTREACHED();
828 return;
829 }
830
831 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37832 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04833 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37834 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04835 service->RequestPermission(
836 source_origin, render_process_id, render_view_id, callback_context,
837 tab_util::GetTabContentsByID(render_process_id, render_view_id));
838}
839
840WebKit::WebNotificationPresenter::Permission
841 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:02842 const GURL& source_origin,
843 const content::ResourceContext& context,
844 int render_process_id) {
[email protected]941623e2011-06-07 23:06:04845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
846 ProfileIOData* io_data =
847 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
848
[email protected]34eec7ffe32011-11-02 23:49:02849 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
850 source_origin, render_process_id,
851 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:04852 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:04853
854 // Fall back to the regular notification preferences, which works on an
855 // origin basis.
856 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:37857 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:04858 WebKit::WebNotificationPresenter::PermissionNotAllowed;
859}
860
861void ChromeContentBrowserClient::ShowDesktopNotification(
862 const DesktopNotificationHostMsg_Show_Params& params,
863 int render_process_id,
864 int render_view_id,
865 bool worker) {
866 RenderViewHost* rvh = RenderViewHost::FromID(
867 render_process_id, render_view_id);
868 if (!rvh) {
869 NOTREACHED();
870 return;
871 }
872
873 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37874 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04875 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37876 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04877 service->ShowDesktopNotification(
878 params, render_process_id, render_view_id,
879 worker ? DesktopNotificationService::WorkerNotification :
880 DesktopNotificationService::PageNotification);
881}
882
883void ChromeContentBrowserClient::CancelDesktopNotification(
884 int render_process_id,
885 int render_view_id,
886 int notification_id) {
887 RenderViewHost* rvh = RenderViewHost::FromID(
888 render_process_id, render_view_id);
889 if (!rvh) {
890 NOTREACHED();
891 return;
892 }
893
894 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37895 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04896 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37897 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04898 service->CancelDesktopNotification(
899 render_process_id, render_view_id, notification_id);
900}
901
[email protected]9f3fba52011-06-08 20:37:19902bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:02903 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:19904 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:02905 const content::ResourceContext& context,
906 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:19907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
908 // If the opener is trying to create a background window but doesn't have
909 // the appropriate permission, fail the attempt.
910 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
911 ProfileIOData* io_data =
912 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:02913 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
914 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:19915 }
916 return true;
917}
918
919std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
920 const GURL& url, const content::ResourceContext& context) {
921 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
922 // Check if it's an extension-created worker, in which case we want to use
923 // the name of the extension.
924 ProfileIOData* io_data =
925 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
926 const Extension* extension =
927 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
928 return extension ? extension->name() : std::string();
929}
930
[email protected]3cb054e62011-06-13 05:21:17931ResourceDispatcherHost*
932 ChromeContentBrowserClient::GetResourceDispatcherHost() {
933 return g_browser_process->resource_dispatcher_host();
934}
935
936ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
937 return g_browser_process->clipboard();
938}
939
[email protected]8f6a3b852011-07-19 16:48:56940MHTMLGenerationManager*
941 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
942 return g_browser_process->mhtml_generation_manager();
943}
944
[email protected]dce502762011-07-20 08:53:49945DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
946 return g_browser_process->devtools_manager();
947}
948
[email protected]ae6e9912011-07-27 01:18:28949net::NetLog* ChromeContentBrowserClient::GetNetLog() {
950 return g_browser_process->net_log();
951}
952
[email protected]3bc0b562011-08-24 23:51:04953speech_input::SpeechInputManager*
954 ChromeContentBrowserClient::GetSpeechInputManager() {
955 return speech_input::ChromeSpeechInputManager::GetInstance();
956}
957
[email protected]32538d92011-08-25 00:09:23958AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
959 return new ChromeAccessTokenStore();
960}
961
[email protected]dbae6b02011-06-29 23:51:41962bool ChromeContentBrowserClient::IsFastShutdownPossible() {
963 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
964 return !browser_command_line.HasSwitch(switches::kChromeFrame);
965}
966
[email protected]5092c282011-10-29 21:48:37967WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
968 return RenderViewHostDelegateHelper::GetWebkitPrefs(rvh);
[email protected]181a95ee2011-07-12 19:26:36969}
970
971void ChromeContentBrowserClient::UpdateInspectorSetting(
972 RenderViewHost* rvh, const std::string& key, const std::string& value) {
973 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37974 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36975}
976
977void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
978 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37979 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36980}
981
[email protected]b8148ac2011-07-13 22:03:25982void ChromeContentBrowserClient::BrowserURLHandlerCreated(
983 BrowserURLHandler* handler) {
984 // Add the default URL handlers.
985 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
986 BrowserURLHandler::null_handler());
987 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
988 &ExtensionWebUI::HandleChromeURLOverrideReverse);
989
990 // about:
991 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
992 BrowserURLHandler::null_handler());
993 // chrome: & friends.
994 handler->AddHandlerPair(&HandleWebUI,
995 BrowserURLHandler::null_handler());
996}
997
998void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37999 Profile* profile = Profile::FromBrowserContext(
1000 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:251001 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1002 BrowsingDataRemover::EVERYTHING,
1003 base::Time());
1004 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1005 // BrowsingDataRemover takes care of deleting itself when done.
1006}
1007
1008void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371009 Profile* profile = Profile::FromBrowserContext(
1010 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:251011 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1012 BrowsingDataRemover::EVERYTHING,
1013 base::Time());
[email protected]dceaa912011-09-06 17:17:231014 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251015 remover->Remove(remove_mask);
1016 // BrowsingDataRemover takes care of deleting itself when done.
1017}
1018
[email protected]e1d16eb92011-08-18 23:19:321019FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1020 return download_util::GetDefaultDownloadDirectory();
1021}
1022
[email protected]c9b6eb62011-10-18 20:49:391023std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1024 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1025}
1026
[email protected]e60c0232011-11-11 19:56:351027#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301028int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521029 const CommandLine& command_line) {
1030 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071031 ExtensionCrashHandlerHostLinux* crash_handler =
1032 ExtensionCrashHandlerHostLinux::GetInstance();
1033 return crash_handler->GetDeathSignalSocket();
1034 }
1035
[email protected]718eab62011-10-05 21:16:521036 std::string process_type =
1037 command_line.GetSwitchValueASCII(switches::kProcessType);
1038
1039 if (process_type == switches::kRendererProcess)
1040 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1041
[email protected]b80f68432011-05-02 17:22:301042 if (process_type == switches::kPluginProcess)
1043 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1044
1045 if (process_type == switches::kPpapiPluginProcess)
1046 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1047
1048 if (process_type == switches::kGpuProcess)
1049 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1050
1051 return -1;
1052}
[email protected]e60c0232011-11-11 19:56:351053#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301054
[email protected]4a65826d2011-08-25 16:04:011055#if defined(OS_WIN)
1056const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1057 return chrome::kBrowserResourcesDll;
1058}
1059#endif
1060
[email protected]37a72af2011-06-13 05:42:011061#if defined(USE_NSS)
1062crypto::CryptoModuleBlockingPasswordDelegate*
1063 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1064 const GURL& url) {
1065 return browser::NewCryptoModuleBlockingDialogDelegate(
1066 browser::kCryptoModulePasswordKeygen, url.host());
1067}
1068#endif
1069
[email protected]d977f9c2011-03-14 16:10:261070} // namespace chrome