Chromium Code Reviews| 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..e7640a574758c63e1144d82082696d4ff4f0c3a9 100644 |
| --- a/chrome/browser/services/gcm/push_messaging_permission_context.cc |
| +++ b/chrome/browser/services/gcm/push_messaging_permission_context.cc |
| @@ -4,13 +4,90 @@ |
| #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()->GetContentSetting( |
| + requesting_origin, embedding_origin, |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()); |
| + |
| + if (notifications_content_setting == CONTENT_SETTING_BLOCK || |
|
Bernhard Bauer
2014/11/14 12:31:33
Nit: add braces for multiline conditions.
Miguel Garcia
2014/11/17 11:43:22
Done.
|
| + 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(notifications_content_setting, CONTENT_SETTING_ALLOW); |
|
Bernhard Bauer
2014/11/14 12:31:33
Put the expected value first for nicer error messa
Miguel Garcia
2014/11/17 11:43:22
Done.
|
| + DCHECK_EQ(push_content_setting, CONTENT_SETTING_ALLOW); |
| + return CONTENT_SETTING_ALLOW; |
| +} |
| + |
| +/** |
|
Bernhard Bauer
2014/11/14 12:31:33
Use //-style comments, not Javadoc :)
Miguel Garcia
2014/11/17 11:43:22
Done.
|
| + * 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 = |
| + push_profile_->GetHostContentSettingsMap() |
| + ->GetContentSettingAndMaybeUpdateLastUsage( |
| + requesting_origin, embedding_origin, |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()); |
| + |
| + if (notifications_content_setting != CONTENT_SETTING_ALLOW) { |
| + DLOG(WARNING) << "Notification permission has not been granted."; |
| + NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| + false /* persist */, false /* granted */); |
| + return; |
| + } |
| + |
| + ContentSetting push_content_setting = |
| + push_profile_->GetHostContentSettingsMap() |
| + ->GetContentSettingAndMaybeUpdateLastUsage( |
| + requesting_origin, embedding_origin, push_setting_type_, |
| + std::string()); |
| + |
| + if (push_content_setting == CONTENT_SETTING_BLOCK) { |
| + DLOG(WARNING) << "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 |