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..47282d64b89a8836d9d31fde8043c7a3dc97e849 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,38 @@ 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); |
mlamouri (slow - plz ping)
2015/12/02 15:59:29
nit: I would leave an empty line after the DCHECK
johnme
2015/12/08 17:37:22
Done.
johnme
2015/12/08 17:37:22
Done.
|
+ 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). |
mlamouri (slow - plz ping)
2015/12/02 15:59:29
nit: I think this comment would be better the `if`
johnme
2015/12/08 17:37:22
I kept it inside the if to clarify that you don't
|
+ 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. |