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

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..d76366864208929de2055ec354498ac92fa0d0d0 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"
+
namespace gcm {
PushMessagingPermissionContext::PushMessagingPermissionContext(Profile* profile)
- : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) {
+ : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING),
+ push_profile_(profile),
+ push_setting_type_(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) {
}
PushMessagingPermissionContext::~PushMessagingPermissionContext() {
}
+ContentSetting PushMessagingPermissionContext::GetPermissionStatus(
+ const GURL& requesting_origin,
+ const GURL& embedding_origin) const {
+ ContentSetting push_content_setting =
+ push_profile_->GetHostContentSettingsMap()->GetContentSetting(
+ requesting_origin, embedding_origin, push_setting_type_,
+ std::string());
+
+ ContentSetting notifications_content_setting =
+ push_profile_->GetHostContentSettingsMap()
+ ->GetContentSettingAndMaybeUpdateLastUsage(
Michael van Ouwerkerk 2014/11/13 18:35:52 I'm not sure I understand this part correctly. Why
Miguel Garcia 2014/11/14 11:34:36 I made it more clear now, I think we want to keep
+ requesting_origin, embedding_origin,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 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(notifications_content_setting == CONTENT_SETTING_ALLOW);
Michael van Ouwerkerk 2014/11/13 18:35:52 Nit: use DCHECK_EQ, here and below.
Miguel Garcia 2014/11/14 11:34:36 Done.
+ DCHECK(push_content_setting == CONTENT_SETTING_ALLOW);
+ 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& embedder_origin,
Michael van Ouwerkerk 2014/11/13 18:35:52 Nit: let's be consistent and call this embedding_o
Miguel Garcia 2014/11/14 11:34:36 Done.
+ bool user_gesture,
+ const BrowserPermissionCallback& callback) {
+ ContentSetting notifications_content_setting =
+ push_profile_->GetHostContentSettingsMap()
+ ->GetContentSettingAndMaybeUpdateLastUsage(
johnme 2014/11/13 18:50:06 I'm not too familiar with AndMaybeUpdateLastUsage
Miguel Garcia 2014/11/14 11:34:36 Yes, the base class does the same. DecidePermissio
+ requesting_origin, embedder_origin,
+ CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
+
+ if (notifications_content_setting != CONTENT_SETTING_ALLOW) {
+ DLOG(WARNING) << "Notification permission has not been granted.";
Michael van Ouwerkerk 2014/11/13 18:35:52 Delete this?
Miguel Garcia 2014/11/14 11:34:36 I actually meant to leave this one, it will be hel
Bernhard Bauer 2014/11/14 12:31:33 Could you at least reduce the severity if it's onl
Miguel Garcia 2014/11/17 11:43:22 Ok, note that there is a presubmit check to avoid
Bernhard Bauer 2014/11/17 11:53:37 Yeah, I think technically you're supposed to use l
+ NotifyPermissionSet(id, requesting_origin, embedder_origin, callback,
+ false /* persist */, false /* granted */);
+ return;
+ }
+
+ ContentSetting push_content_setting =
+ push_profile_->GetHostContentSettingsMap()
+ ->GetContentSettingAndMaybeUpdateLastUsage(
+ requesting_origin, embedder_origin, push_setting_type_,
+ std::string());
+
+ if (push_content_setting == CONTENT_SETTING_BLOCK) {
johnme 2014/11/13 18:50:06 How would we ever get to this state, if only the n
Miguel Garcia 2014/11/14 11:34:36 I just want to be a bit defensive about it just in
+ DLOG(WARNING) << "Push permission was explicitly blocked.";
Michael van Ouwerkerk 2014/11/13 18:35:52 Delete this?
Miguel Garcia 2014/11/14 11:34:36 Same as above.
+ NotifyPermissionSet(id, requesting_origin, embedder_origin, callback,
+ false /* persist */, false /* granted */);
+ return;
+ }
+
+ NotifyPermissionSet(id, requesting_origin, embedder_origin, callback,
+ true /* persist */, true /* granted */);
+}
+
} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698