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

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
7 namespace gcm { 12 namespace gcm {
8 13
9 PushMessagingPermissionContext::PushMessagingPermissionContext(Profile* profile) 14 PushMessagingPermissionContext::PushMessagingPermissionContext(Profile* profile)
10 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) { 15 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_PUSH_MESSAGING),
16 push_profile_(profile),
17 push_setting_type_(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) {
11 } 18 }
12 19
13 PushMessagingPermissionContext::~PushMessagingPermissionContext() { 20 PushMessagingPermissionContext::~PushMessagingPermissionContext() {
14 } 21 }
15 22
23 ContentSetting PushMessagingPermissionContext::GetPermissionStatus(
24 const GURL& requesting_origin,
25 const GURL& embedding_origin) const {
26 ContentSetting push_content_setting =
27 push_profile_->GetHostContentSettingsMap()->GetContentSetting(
28 requesting_origin, embedding_origin, push_setting_type_,
29 std::string());
30
31 ContentSetting notifications_content_setting =
32 push_profile_->GetHostContentSettingsMap()
33 ->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
34 requesting_origin, embedding_origin,
35 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
36
37 if (notifications_content_setting == CONTENT_SETTING_BLOCK ||
38 push_content_setting == CONTENT_SETTING_BLOCK)
39 return CONTENT_SETTING_BLOCK;
40
41 if (notifications_content_setting == CONTENT_SETTING_ASK ||
42 push_content_setting == CONTENT_SETTING_ASK)
43 return CONTENT_SETTING_ASK;
44 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.
45 DCHECK(push_content_setting == CONTENT_SETTING_ALLOW);
46 return CONTENT_SETTING_ALLOW;
47 }
48
49 /**
50 * Unlike other permissions, push is decided by the following algorithm
51 * - You need to have notification permission granted.
52 * - You need to not have push permission explicitly blocked
53 * - If those two things are true it is granted without prompting.
54 *
55 * This is done to avoid double prompting for notifications and push.
56 */
57 void PushMessagingPermissionContext::DecidePermission(
58 content::WebContents* web_contents,
59 const PermissionRequestID& id,
60 const GURL& requesting_origin,
61 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.
62 bool user_gesture,
63 const BrowserPermissionCallback& callback) {
64 ContentSetting notifications_content_setting =
65 push_profile_->GetHostContentSettingsMap()
66 ->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
67 requesting_origin, embedder_origin,
68 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
69
70 if (notifications_content_setting != CONTENT_SETTING_ALLOW) {
71 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
72 NotifyPermissionSet(id, requesting_origin, embedder_origin, callback,
73 false /* persist */, false /* granted */);
74 return;
75 }
76
77 ContentSetting push_content_setting =
78 push_profile_->GetHostContentSettingsMap()
79 ->GetContentSettingAndMaybeUpdateLastUsage(
80 requesting_origin, embedder_origin, push_setting_type_,
81 std::string());
82
83 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
84 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.
85 NotifyPermissionSet(id, requesting_origin, embedder_origin, callback,
86 false /* persist */, false /* granted */);
87 return;
88 }
89
90 NotifyPermissionSet(id, requesting_origin, embedder_origin, callback,
91 true /* persist */, true /* granted */);
92 }
93
16 } // namespace gcm 94 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698