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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/services/gcm/push_messaging_permission_context.h" 5 #include "chrome/browser/services/gcm/push_messaging_permission_context.h"
6 6
7 #include "chrome/browser/profiles/profile.h"
8 #include "components/content_settings/core/browser/host_content_settings_map.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_delegate.h"
11
12 const ContentSettingsType kPushSettingType =
13 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING;
14 const ContentSettingsType kNotificationSettingType =
15 CONTENT_SETTINGS_TYPE_NOTIFICATIONS;
16
7 namespace gcm { 17 namespace gcm {
8 18
9 PushMessagingPermissionContext::PushMessagingPermissionContext(Profile* profile) 19 PushMessagingPermissionContext::PushMessagingPermissionContext(Profile* profile)
10 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) { 20 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING),
21 push_profile_(profile) {
11 } 22 }
12 23
13 PushMessagingPermissionContext::~PushMessagingPermissionContext() { 24 PushMessagingPermissionContext::~PushMessagingPermissionContext() {
14 } 25 }
15 26
27 ContentSetting PushMessagingPermissionContext::GetPermissionStatus(
28 const GURL& requesting_origin,
29 const GURL& embedding_origin) const {
30 ContentSetting push_content_setting =
31 push_profile_->GetHostContentSettingsMap()->GetContentSetting(
32 requesting_origin, embedding_origin, kPushSettingType,
33 std::string());
34
35 ContentSetting notifications_content_setting =
36 push_profile_->GetHostContentSettingsMap()->GetContentSetting(
37 requesting_origin, embedding_origin,
38 kNotificationSettingType, std::string());
39
40 if (notifications_content_setting == CONTENT_SETTING_BLOCK ||
41 push_content_setting == CONTENT_SETTING_BLOCK) {
42 return CONTENT_SETTING_BLOCK;
43 }
44 if (notifications_content_setting == CONTENT_SETTING_ASK ||
45 push_content_setting == CONTENT_SETTING_ASK) {
46 return CONTENT_SETTING_ASK;
47 }
48 DCHECK_EQ(CONTENT_SETTING_ALLOW, notifications_content_setting);
49 DCHECK_EQ(CONTENT_SETTING_ALLOW, push_content_setting);
50 return CONTENT_SETTING_ALLOW;
51 }
52
53
54 // Unlike other permissions, push is decided by the following algorithm
55 // - You need to have notification permission granted.
56 // - You need to not have push permission explicitly blocked
57 // - If those two things are true it is granted without prompting.
58 // This is done to avoid double prompting for notifications and push.
59 void PushMessagingPermissionContext::DecidePermission(
60 content::WebContents* web_contents,
61 const PermissionRequestID& id,
62 const GURL& requesting_origin,
63 const GURL& embedding_origin,
64 bool user_gesture,
65 const BrowserPermissionCallback& callback) {
66 ContentSetting notifications_content_setting =
67 push_profile_->GetHostContentSettingsMap()
68 ->GetContentSettingAndMaybeUpdateLastUsage(
69 requesting_origin, embedding_origin,
70 kNotificationSettingType, std::string());
71
72 if (notifications_content_setting != CONTENT_SETTING_ALLOW) {
73 DLOG(INFO) << "Notification permission has not been granted.";
74 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
75 false /* persist */, false /* granted */);
76 return;
77 }
78
79 ContentSetting push_content_setting =
80 push_profile_->GetHostContentSettingsMap()
81 ->GetContentSettingAndMaybeUpdateLastUsage(
82 requesting_origin, embedding_origin, kPushSettingType,
83 std::string());
84
85 if (push_content_setting == CONTENT_SETTING_BLOCK) {
86 DLOG(INFO) << "Push permission was explicitly blocked.";
87 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
88 false /* persist */, false /* granted */);
89 return;
90 }
91
92 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
93 true /* persist */, true /* granted */);
94 }
95
16 } // namespace gcm 96 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698