blob: 4ad318d3dab29da3052a9b049fdd26f8569da550 [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]b80f68432011-05-02 17:22:307#include "base/command_line.h"
8#include "chrome/app/breakpad_mac.h"
9#include "chrome/browser/browser_process.h"
[email protected]763ec4ca2011-04-29 15:48:1210#include "chrome/browser/character_encoding.h"
[email protected]97e6c4c2011-05-18 16:08:5111#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4112#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3613#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4914#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3215#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]f364d1392011-04-08 21:03:1016#include "chrome/browser/debugger/devtools_handler.h"
[email protected]941623e2011-06-07 23:06:0417#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1018#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2619#include "chrome/browser/extensions/extension_service.h"
[email protected]763ec4ca2011-04-29 15:48:1220#include "chrome/browser/google/google_util.h"
[email protected]941623e2011-06-07 23:06:0421#include "chrome/browser/notifications/desktop_notification_service.h"
22#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4223#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/prefs/pref_service.h"
[email protected]05fcf982011-04-19 00:44:1425#include "chrome/browser/printing/printing_message_filter.h"
26#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3227#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1428#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3329#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0130#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1431#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
32#include "chrome/browser/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4533#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0334#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4535#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
36#include "chrome/browser/tab_contents/tab_util.h"
37#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5638#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3039#include "chrome/common/child_process_logging.h"
40#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0441#include "chrome/common/extensions/extension.h"
[email protected]c5dbef02011-05-13 05:06:0942#include "chrome/common/extensions/extension_messages.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3844#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0945#include "chrome/common/url_constants.h"
46#include "content/browser/browsing_instance.h"
47#include "content/browser/child_process_security_policy.h"
[email protected]97e6c4c2011-05-18 16:08:5148#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1449#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2650#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4951#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0952#include "content/browser/site_instance.h"
[email protected]8ec26472011-06-06 16:52:4553#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1254#include "content/browser/tab_contents/tab_contents.h"
[email protected]5327dfb2011-05-03 17:50:3655#include "content/browser/worker_host/worker_process_host.h"
[email protected]c5dbef02011-05-13 05:06:0956#include "content/common/bindings_policy.h"
[email protected]941623e2011-06-07 23:06:0457#include "content/common/desktop_notification_messages.h"
[email protected]ed24fad2011-05-10 22:44:0158#include "net/base/cookie_monster.h"
59#include "net/base/cookie_options.h"
[email protected]d977f9c2011-03-14 16:10:2660
[email protected]b80f68432011-05-02 17:22:3061#if defined(OS_LINUX)
62#include "base/linux_util.h"
63#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4364#endif
[email protected]b80f68432011-05-02 17:22:3065
[email protected]37a72af2011-06-13 05:42:0166#if defined(USE_NSS)
67#include "chrome/browser/ui/crypto_module_password_dialog.h"
68#endif
69
[email protected]c5dbef02011-05-13 05:06:0970namespace {
71
72void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) {
73 // Note that due to GetEffectiveURL(), even hosted apps will have a
74 // chrome-extension:// URL for their site, so we can ignore that wrinkle here.
75 SiteInstance* site_instance = render_view_host->site_instance();
76 const GURL& site = site_instance->site();
77 RenderProcessHost* process = render_view_host->process();
78
79 if (!site.SchemeIs(chrome::kExtensionScheme))
80 return;
81
82 Profile* profile = site_instance->browsing_instance()->profile();
83 ExtensionService* service = profile->GetExtensionService();
84 if (!service)
85 return;
86
87 ExtensionProcessManager* process_manager =
88 profile->GetExtensionProcessManager();
89 CHECK(process_manager);
90
91 // This can happen if somebody typos a chrome-extension:// URL.
92 const Extension* extension = service->GetExtensionByURL(site);
93 if (!extension)
94 return;
95
96 site_instance->GetProcess()->mark_is_extension_process();
97
98 // Register the association between extension and process with
99 // ExtensionProcessManager.
100 process_manager->RegisterExtensionProcess(extension->id(), process->id());
101
102 // Record which, if any, installed app is associated with this process.
103 // TODO(aa): Totally lame to store this state in a global map in extension
104 // service. Can we get it from EPM instead?
105 if (extension->is_app())
106 service->SetInstalledAppForRenderer(process->id(), extension);
107
108 // Some extensions use chrome:// URLs.
109 Extension::Type type = extension->GetType();
110 if (type == Extension::TYPE_EXTENSION ||
111 type == Extension::TYPE_PACKAGED_APP) {
112 ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
113 process->id(), chrome::kChromeUIScheme);
114 }
115
116 // Enable extension bindings for the renderer. Currently only extensions,
117 // packaged apps, and hosted component apps use extension bindings.
118 if (type == Extension::TYPE_EXTENSION ||
[email protected]2333bf22011-05-19 02:16:51119 type == Extension::TYPE_USER_SCRIPT ||
[email protected]c5dbef02011-05-13 05:06:09120 type == Extension::TYPE_PACKAGED_APP ||
121 (type == Extension::TYPE_HOSTED_APP &&
122 extension->location() == Extension::COMPONENT)) {
123 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id()));
124 render_view_host->AllowBindings(BindingsPolicy::EXTENSION);
125 }
126}
127
128}
129
[email protected]d977f9c2011-03-14 16:10:26130namespace chrome {
131
[email protected]f364d1392011-04-08 21:03:10132void ChromeContentBrowserClient::RenderViewHostCreated(
133 RenderViewHost* render_view_host) {
[email protected]53a0afa2011-04-28 02:09:33134 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10135 new DevToolsHandler(render_view_host);
136 new ExtensionMessageHandler(render_view_host);
[email protected]f364d1392011-04-08 21:03:10137
[email protected]c5dbef02011-05-13 05:06:09138 InitRenderViewHostForExtensions(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26139}
140
[email protected]05fcf982011-04-19 00:44:14141void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
142 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02143 int id = host->id();
144 Profile* profile = host->profile();
[email protected]05fcf982011-04-19 00:44:14145 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02146 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14147 host->channel()->AddFilter(new PrintingMessageFilter());
148 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02149 new SearchProviderInstallStateMessageFilter(id, profile));
150 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01151#if defined(OS_MACOSX)
152 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
153#endif
[email protected]3e69bc82011-05-26 23:22:38154
155 host->Send(new ViewMsg_SetIsIncognitoProcess(profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14156}
157
[email protected]97e6c4c2011-05-18 16:08:51158void ChromeContentBrowserClient::PluginProcessHostCreated(
159 PluginProcessHost* host) {
160 host->AddFilter(new ChromePluginMessageFilter(host));
161}
162
[email protected]5327dfb2011-05-03 17:50:36163void ChromeContentBrowserClient::WorkerProcessHostCreated(
164 WorkerProcessHost* host) {
165 host->AddFilter(new ChromeWorkerMessageFilter(host));
166}
167
[email protected]1fd1a502011-03-30 16:55:56168content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
169 return ChromeWebUIFactory::GetInstance();
170}
171
[email protected]36fb2c7c2011-04-04 15:49:08172GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile,
173 const GURL& url) {
174 // Get the effective URL for the given actual URL. If the URL is part of an
175 // installed app, the effective URL is an extension URL with the ID of that
176 // extension as the host. This has the effect of grouping apps together in
177 // a common SiteInstance.
178 if (!profile || !profile->GetExtensionService())
179 return url;
180
181 const Extension* extension =
182 profile->GetExtensionService()->GetExtensionByWebExtent(url);
183 if (!extension)
184 return url;
185
186 // If the URL is part of an extension's web extent, convert it to an
187 // extension URL.
188 return extension->GetResourceURL(url.path());
189}
190
[email protected]0f012df82011-05-19 14:15:29191bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03192 return url == GURL(chrome::kChromeUICrashURL) ||
193 url == GURL(chrome::kChromeUIKillURL) ||
194 url == GURL(chrome::kChromeUIHangURL) ||
195 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29196}
197
[email protected]763ec4ca2011-04-29 15:48:12198std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
199 const std::string& alias_name) {
200 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
201}
202
[email protected]b80f68432011-05-02 17:22:30203void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
204 CommandLine* command_line, int child_process_id) {
205#if defined(USE_LINUX_BREAKPAD)
206 if (IsCrashReporterEnabled()) {
207 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
208 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
209 }
210#elif defined(OS_MACOSX)
211 if (IsCrashReporterEnabled()) {
212 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
213 child_process_logging::GetClientId());
214 }
215#endif // OS_MACOSX
216
217 std::string process_type =
218 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17219 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30220 if (process_type == switches::kExtensionProcess ||
221 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30222 FilePath user_data_dir =
223 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
224 if (!user_data_dir.empty())
225 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
226#if defined(OS_CHROMEOS)
227 const std::string& login_profile =
228 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
229 if (!login_profile.empty())
230 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
231#endif
232
233 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
234
235 PrefService* prefs = process->profile()->GetPrefs();
236 // Currently this pref is only registered if applied via a policy.
237 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
238 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
239 // Turn this policy into a command line switch.
240 command_line->AppendSwitch(switches::kDisable3DAPIs);
241 }
242
243 // Disable client-side phishing detection in the renderer if it is disabled
244 // in the browser process.
245 if (!g_browser_process->safe_browsing_detection_service())
246 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]3cb054e62011-06-13 05:21:17247 } else if (process_type == switches::kUtilityProcess) {
248 if (browser_command_line.HasSwitch(
249 switches::kEnableExperimentalExtensionApis)) {
250 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
251 }
[email protected]b80f68432011-05-02 17:22:30252 }
253}
254
255std::string ChromeContentBrowserClient::GetApplicationLocale() {
256 return g_browser_process->GetApplicationLocale();
257}
258
[email protected]b5cca982011-05-26 04:42:08259std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
260 return tab->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
261}
262
[email protected]a2176792011-05-08 19:30:49263bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09264 const GURL& manifest_url,
265 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
267 ProfileIOData* io_data =
268 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09269 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38270 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09271 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49272 DCHECK(setting != CONTENT_SETTING_DEFAULT);
273 return setting != CONTENT_SETTING_BLOCK;
274}
275
[email protected]ed24fad2011-05-10 22:44:01276bool ChromeContentBrowserClient::AllowGetCookie(
277 const GURL& url,
278 const GURL& first_party,
279 const net::CookieList& cookie_list,
280 const content::ResourceContext& context,
281 int render_process_id,
282 int render_view_id) {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32284 ProfileIOData* io_data =
285 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09286 ContentSetting setting = io_data->GetHostContentSettingsMap()->
287 GetCookieContentSetting(url, first_party, false);
288 bool allow = setting == CONTENT_SETTING_ALLOW ||
289 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01290
[email protected]8093a542011-05-13 07:29:32291 BrowserThread::PostTask(
292 BrowserThread::UI, FROM_HERE,
293 NewRunnableFunction(
294 &TabSpecificContentSettings::CookiesRead,
295 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01296 return allow;
297}
298
299bool ChromeContentBrowserClient::AllowSetCookie(
300 const GURL& url,
301 const GURL& first_party,
302 const std::string& cookie_line,
303 const content::ResourceContext& context,
304 int render_process_id,
305 int render_view_id,
306 net::CookieOptions* options) {
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32308 ProfileIOData* io_data =
309 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09310 ContentSetting setting = io_data->GetHostContentSettingsMap()->
311 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01312
[email protected]5b52ad42011-05-26 14:26:09313 if (setting == CONTENT_SETTING_SESSION_ONLY)
314 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01315
[email protected]5b52ad42011-05-26 14:26:09316 bool allow = setting == CONTENT_SETTING_ALLOW ||
317 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01318
[email protected]8093a542011-05-13 07:29:32319 BrowserThread::PostTask(
320 BrowserThread::UI, FROM_HERE,
321 NewRunnableFunction(
322 &TabSpecificContentSettings::CookieChanged,
323 render_process_id, render_view_id, url, cookie_line, *options,
324 !allow));
[email protected]ed24fad2011-05-10 22:44:01325 return allow;
326}
327
[email protected]317f96c92011-05-31 06:53:41328QuotaPermissionContext*
329ChromeContentBrowserClient::CreateQuotaPermissionContext() {
330 return new ChromeQuotaPermissionContext();
331}
332
[email protected]0609b17f2011-05-31 20:13:42333void ChromeContentBrowserClient::RevealFolderInOS(const FilePath& path) {
334 // On Mac, this call needs to be done on the UI thread. On other platforms,
335 // do it on the FILE thread so we don't slow down UI.
336#if defined(OS_MACOSX)
337 platform_util::OpenItem(path);
338#else
339 BrowserThread::PostTask(
340 BrowserThread::FILE, FROM_HERE,
341 NewRunnableFunction(&platform_util::OpenItem, path));
342#endif
343}
344
[email protected]848dd042011-06-04 18:24:03345void ChromeContentBrowserClient::AllowCertificateError(
346 SSLCertErrorHandler* handler,
347 bool overridable,
348 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
349 SSLBlockingPage* blocking_page = new SSLBlockingPage(
350 handler, overridable, callback);
351 blocking_page->Show();
352}
353
[email protected]8ec26472011-06-06 16:52:45354void ChromeContentBrowserClient::ShowClientCertificateRequestDialog(
355 int render_process_id,
356 int render_view_id,
357 SSLClientAuthHandler* handler) {
358 TabContents* tab = tab_util::GetTabContentsByID(
359 render_process_id, render_view_id);
360 if (!tab) {
361 NOTREACHED();
362 return;
363 }
364
365 TabContentsWrapper* wrapper =
366 TabContentsWrapper::GetCurrentWrapperForContents(tab);
367 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
368}
369
370void ChromeContentBrowserClient::AddNewCertificate(
371 net::URLRequest* request,
372 net::X509Certificate* cert,
373 int render_process_id,
374 int render_view_id) {
375 // The handler will run the UI and delete itself when it's finished.
376 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
377}
378
[email protected]941623e2011-06-07 23:06:04379void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
380 const GURL& source_origin,
381 int callback_context,
382 int render_process_id,
383 int render_view_id) {
384 RenderViewHost* rvh = RenderViewHost::FromID(
385 render_process_id, render_view_id);
386 if (!rvh) {
387 NOTREACHED();
388 return;
389 }
390
391 RenderProcessHost* process = rvh->process();
392 DesktopNotificationService* service =
393 DesktopNotificationServiceFactory::GetForProfile(process->profile());
394 service->RequestPermission(
395 source_origin, render_process_id, render_view_id, callback_context,
396 tab_util::GetTabContentsByID(render_process_id, render_view_id));
397}
398
399WebKit::WebNotificationPresenter::Permission
400 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
401 const GURL& source_url,
402 const content::ResourceContext& context) {
403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
404 ProfileIOData* io_data =
405 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
406
407 const Extension* extension =
408 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
409 if (extension &&
410 extension->HasApiPermission(Extension::kNotificationPermission)) {
411 return WebKit::WebNotificationPresenter::PermissionAllowed;
412 }
413
414 // Fall back to the regular notification preferences, which works on an
415 // origin basis.
416 return io_data->GetNotificationService() ?
417 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
418 WebKit::WebNotificationPresenter::PermissionNotAllowed;
419}
420
421void ChromeContentBrowserClient::ShowDesktopNotification(
422 const DesktopNotificationHostMsg_Show_Params& params,
423 int render_process_id,
424 int render_view_id,
425 bool worker) {
426 RenderViewHost* rvh = RenderViewHost::FromID(
427 render_process_id, render_view_id);
428 if (!rvh) {
429 NOTREACHED();
430 return;
431 }
432
433 RenderProcessHost* process = rvh->process();
434 DesktopNotificationService* service =
435 DesktopNotificationServiceFactory::GetForProfile(process->profile());
436 service->ShowDesktopNotification(
437 params, render_process_id, render_view_id,
438 worker ? DesktopNotificationService::WorkerNotification :
439 DesktopNotificationService::PageNotification);
440}
441
442void ChromeContentBrowserClient::CancelDesktopNotification(
443 int render_process_id,
444 int render_view_id,
445 int notification_id) {
446 RenderViewHost* rvh = RenderViewHost::FromID(
447 render_process_id, render_view_id);
448 if (!rvh) {
449 NOTREACHED();
450 return;
451 }
452
453 RenderProcessHost* process = rvh->process();
454 DesktopNotificationService* service =
455 DesktopNotificationServiceFactory::GetForProfile(process->profile());
456 service->CancelDesktopNotification(
457 render_process_id, render_view_id, notification_id);
458}
459
[email protected]9f3fba52011-06-08 20:37:19460bool ChromeContentBrowserClient::CanCreateWindow(
461 const GURL& source_url,
462 WindowContainerType container_type,
463 const content::ResourceContext& context) {
464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
465 // If the opener is trying to create a background window but doesn't have
466 // the appropriate permission, fail the attempt.
467 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
468 ProfileIOData* io_data =
469 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
470 const Extension* extension =
471 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
472 return (extension &&
473 extension->HasApiPermission(Extension::kBackgroundPermission));
474 }
475 return true;
476}
477
478std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
479 const GURL& url, const content::ResourceContext& context) {
480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
481 // Check if it's an extension-created worker, in which case we want to use
482 // the name of the extension.
483 ProfileIOData* io_data =
484 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
485 const Extension* extension =
486 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
487 return extension ? extension->name() : std::string();
488}
489
[email protected]3cb054e62011-06-13 05:21:17490ResourceDispatcherHost*
491 ChromeContentBrowserClient::GetResourceDispatcherHost() {
492 return g_browser_process->resource_dispatcher_host();
493}
494
495ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
496 return g_browser_process->clipboard();
497}
498
[email protected]b80f68432011-05-02 17:22:30499#if defined(OS_LINUX)
500int ChromeContentBrowserClient::GetCrashSignalFD(
501 const std::string& process_type) {
502 if (process_type == switches::kRendererProcess)
503 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
504
505 if (process_type == switches::kPluginProcess)
506 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
507
508 if (process_type == switches::kPpapiPluginProcess)
509 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
510
511 if (process_type == switches::kGpuProcess)
512 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
513
514 return -1;
515}
516#endif
517
[email protected]37a72af2011-06-13 05:42:01518#if defined(USE_NSS)
519crypto::CryptoModuleBlockingPasswordDelegate*
520 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
521 const GURL& url) {
522 return browser::NewCryptoModuleBlockingDialogDelegate(
523 browser::kCryptoModulePasswordKeygen, url.host());
524}
525#endif
526
[email protected]d977f9c2011-03-14 16:10:26527} // namespace chrome