Chromium Code Reviews| Index: chrome/browser/notifications/notification_permission_context.cc |
| diff --git a/chrome/browser/notifications/notification_permission_context.cc b/chrome/browser/notifications/notification_permission_context.cc |
| index 06037ae2409ba04171ebe604daf1d13d2bc13922..fd788d4b0ae6178d9313e80b752be8b342ffb35d 100644 |
| --- a/chrome/browser/notifications/notification_permission_context.cc |
| +++ b/chrome/browser/notifications/notification_permission_context.cc |
| @@ -4,10 +4,27 @@ |
| #include "chrome/browser/notifications/notification_permission_context.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| +#include "chrome/browser/infobars/infobar_service.h" |
| #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| +#include "chrome/browser/notifications/incognito_denied_infobar_delegate.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "components/content_settings/core/browser/host_content_settings_map.h" |
| #include "components/content_settings/core/common/content_settings_pattern.h" |
| +#include "content/public/browser/browser_thread.h" |
| #include "url/gurl.h" |
| +namespace { |
| + |
| +void RunClosureIgnoringBools(const base::Closure& closure, |
| + bool ignored_a, bool ignored_b) { |
| + closure.Run(); |
| +} |
| + |
| +} // namespace |
| + |
| NotificationPermissionContext::NotificationPermissionContext(Profile* profile) |
| : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS) {} |
| @@ -20,6 +37,39 @@ void NotificationPermissionContext::ResetPermission( |
| profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin)); |
| } |
| +void NotificationPermissionContext::DecidePermission( |
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id, |
| + const GURL& requesting_origin, |
| + const GURL& embedding_origin, |
| + bool user_gesture, |
| + const BrowserPermissionCallback& callback) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + if (!profile()->IsOffTheRecord()) { |
|
mlamouri (slow - plz ping)
2015/11/28 17:00:54
nit: I think it's nice to have the special case fi
johnme
2015/11/30 15:37:20
Usually I prefer to keep the short early-out first
|
| + PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, |
| + embedding_origin, user_gesture, |
| + callback); |
| + return; |
| + } |
| + // Notifications are disabled in incognito, so show a custom infobar which |
| + // explains this to the user, and denies permission once the infobar is |
| + // dismissed (the permission has to start off as ASK to prevent websites |
| + // from detecting incognito mode). |
| + base::Closure deny_closure = |
| + base::Bind(&HostContentSettingsMap::SetContentSetting, |
| + HostContentSettingsMapFactory::GetForProfile(profile()), |
| + ContentSettingsPattern::FromURLNoWildcard( |
| + requesting_origin.GetOrigin()), |
| + ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string(), |
| + CONTENT_SETTING_BLOCK); |
| + IncognitoDeniedInfobarDelegate::Create( |
|
mlamouri (slow - plz ping)
2015/11/28 17:00:54
I thought we were moving infobar out on Desktop. U
johnme
2015/11/30 15:37:20
I'll double-check with them before landing.
|
| + InfoBarService::FromWebContents(web_contents), requesting_origin, |
| + profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| + base::Bind(&RunClosureIgnoringBools, deny_closure)); |
|
mlamouri (slow - plz ping)
2015/11/28 17:00:54
Instead of having this closure to re-route while i
johnme
2015/11/30 15:37:20
Done (heh, yeah, realised this myself when mulling
|
| +} |
| + |
| // Unlike other permission types, granting a notification for a given origin |
| // will not take into account the |embedder_origin|, it will only be based |
| // on the requesting iframe origin. |