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..8af490a315d20a7482633433f322c629b85a3c60 100644 |
--- a/chrome/browser/notifications/notification_permission_context.cc |
+++ b/chrome/browser/notifications/notification_permission_context.cc |
@@ -4,8 +4,16 @@ |
#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" |
NotificationPermissionContext::NotificationPermissionContext(Profile* profile) |
@@ -20,6 +28,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()) { |
+ // 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). |
+ IncognitoDeniedInfobarDelegate::Create( |
+ InfoBarService::FromWebContents(web_contents), requesting_origin, |
+ profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), |
+ base::Bind(&HostContentSettingsMap::SetContentSetting, |
+ HostContentSettingsMapFactory::GetForProfile(profile()), |
+ ContentSettingsPattern::FromURLNoWildcard( |
+ requesting_origin.GetOrigin()), |
+ ContentSettingsPattern::Wildcard(), |
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
+ std::string(), |
+ CONTENT_SETTING_BLOCK)); |
+ return; |
+ } |
+ |
+ PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, |
+ embedding_origin, user_gesture, |
+ callback); |
+} |
+ |
// 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. |