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

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()->GetContentSetting(
33 requesting_origin, embedding_origin,
34 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
35
36 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.
37 push_content_setting == CONTENT_SETTING_BLOCK)
38 return CONTENT_SETTING_BLOCK;
39
40 if (notifications_content_setting == CONTENT_SETTING_ASK ||
41 push_content_setting == CONTENT_SETTING_ASK)
42 return CONTENT_SETTING_ASK;
43 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.
44 DCHECK_EQ(push_content_setting, CONTENT_SETTING_ALLOW);
45 return CONTENT_SETTING_ALLOW;
46 }
47
48 /**
Bernhard Bauer 2014/11/14 12:31:33 Use //-style comments, not Javadoc :)
Miguel Garcia 2014/11/17 11:43:22 Done.
49 * Unlike other permissions, push is decided by the following algorithm
50 * - You need to have notification permission granted.
51 * - You need to not have push permission explicitly blocked
52 * - If those two things are true it is granted without prompting.
53 *
54 * This is done to avoid double prompting for notifications and push.
55 */
56 void PushMessagingPermissionContext::DecidePermission(
57 content::WebContents* web_contents,
58 const PermissionRequestID& id,
59 const GURL& requesting_origin,
60 const GURL& embedding_origin,
61 bool user_gesture,
62 const BrowserPermissionCallback& callback) {
63 ContentSetting notifications_content_setting =
64 push_profile_->GetHostContentSettingsMap()
65 ->GetContentSettingAndMaybeUpdateLastUsage(
66 requesting_origin, embedding_origin,
67 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
68
69 if (notifications_content_setting != CONTENT_SETTING_ALLOW) {
70 DLOG(WARNING) << "Notification permission has not been granted.";
71 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
72 false /* persist */, false /* granted */);
73 return;
74 }
75
76 ContentSetting push_content_setting =
77 push_profile_->GetHostContentSettingsMap()
78 ->GetContentSettingAndMaybeUpdateLastUsage(
79 requesting_origin, embedding_origin, push_setting_type_,
80 std::string());
81
82 if (push_content_setting == CONTENT_SETTING_BLOCK) {
83 DLOG(WARNING) << "Push permission was explicitly blocked.";
84 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
85 false /* persist */, false /* granted */);
86 return;
87 }
88
89 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
90 true /* persist */, true /* granted */);
91 }
92
16 } // namespace gcm 93 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698