Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Unified Diff: chrome/browser/services/gcm/push_messaging_permission_context.cc

Issue 718203004: [PUSH] Merge notifications and push messaging prompts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/services/gcm/push_messaging_permission_context.cc
diff --git a/chrome/browser/services/gcm/push_messaging_permission_context.cc b/chrome/browser/services/gcm/push_messaging_permission_context.cc
index ad40ff32319f036bc54864967345cab64832a103..1fba719711fa00b5c239b1cd480014a1177265b8 100644
--- a/chrome/browser/services/gcm/push_messaging_permission_context.cc
+++ b/chrome/browser/services/gcm/push_messaging_permission_context.cc
@@ -4,13 +4,91 @@
#include "chrome/browser/services/gcm/push_messaging_permission_context.h"
+#include "chrome/browser/profiles/profile.h"
+#include "components/content_settings/core/browser/host_content_settings_map.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+
+const ContentSettingsType kPushSettingType =
+ CONTENT_SETTINGS_TYPE_PUSH_MESSAGING;
+const ContentSettingsType kNotificationSettingType =
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
+
namespace gcm {
PushMessagingPermissionContext::PushMessagingPermissionContext(Profile* profile)
- : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) {
+ : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING),
+ profile_(profile) {
}
PushMessagingPermissionContext::~PushMessagingPermissionContext() {
}
+ContentSetting PushMessagingPermissionContext::GetPermissionStatus(
+ const GURL& requesting_origin,
+ const GURL& embedding_origin) const {
+ ContentSetting push_content_setting =
+ profile_->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_origin, embedding_origin, kPushSettingType, std::string());
+
+ ContentSetting notifications_content_setting =
+ profile_->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_origin, embedding_origin, kNotificationSettingType,
+ std::string());
+
+ if (notifications_content_setting == CONTENT_SETTING_BLOCK ||
+ push_content_setting == CONTENT_SETTING_BLOCK) {
+ return CONTENT_SETTING_BLOCK;
+ }
+ if (notifications_content_setting == CONTENT_SETTING_ASK ||
+ push_content_setting == CONTENT_SETTING_ASK) {
+ return CONTENT_SETTING_ASK;
+ }
+ DCHECK_EQ(CONTENT_SETTING_ALLOW, notifications_content_setting);
+ DCHECK_EQ(CONTENT_SETTING_ALLOW, push_content_setting);
+ return CONTENT_SETTING_ALLOW;
+}
+
+// Unlike other permissions, push is decided by the following algorithm
+// - You need to have notification permission granted.
+// - You need to not have push permission explicitly blocked.
+// - If those two things are true it is granted without prompting.
+// This is done to avoid double prompting for notifications and push.
+void PushMessagingPermissionContext::DecidePermission(
+ content::WebContents* web_contents,
+ const PermissionRequestID& id,
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ bool user_gesture,
+ const BrowserPermissionCallback& callback) {
+ ContentSetting notifications_content_setting =
+ profile_->GetHostContentSettingsMap()
+ ->GetContentSettingAndMaybeUpdateLastUsage(
+ requesting_origin, embedding_origin, kNotificationSettingType,
+ std::string());
+
+ if (notifications_content_setting != CONTENT_SETTING_ALLOW) {
+ DVLOG(1) << "Notification permission has not been granted.";
+ NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
+ false /* persist */, false /* granted */);
+ return;
+ }
+
+ ContentSetting push_content_setting =
+ profile_->GetHostContentSettingsMap()
+ ->GetContentSettingAndMaybeUpdateLastUsage(
+ requesting_origin, embedding_origin, kPushSettingType,
+ std::string());
+
+ if (push_content_setting == CONTENT_SETTING_BLOCK) {
+ DVLOG(1) << "Push permission was explicitly blocked.";
+ NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
+ false /* persist */, false /* granted */);
+ return;
+ }
+
+ NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
+ true /* persist */, true /* granted */);
+}
+
} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698