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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_permission_context.cc

Issue 1816123002: Add testing for subscription from service workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix asan errors Created 4 years, 8 months 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/push_messaging/push_messaging_permission_context.h" 5 #include "chrome/browser/push_messaging/push_messaging_permission_context.h"
6 6
7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
8 #include "chrome/browser/notifications/notification_permission_context.h" 8 #include "chrome/browser/notifications/notification_permission_context.h"
9 #include "chrome/browser/notifications/notification_permission_context_factory.h " 9 #include "chrome/browser/notifications/notification_permission_context_factory.h "
10 #include "chrome/browser/permissions/permission_request_id.h" 10 #include "chrome/browser/permissions/permission_request_id.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 DCHECK(notification_context); 46 DCHECK(notification_context);
47 47
48 ContentSetting notifications_permission = 48 ContentSetting notifications_permission =
49 notification_context->GetPermissionStatus(requesting_origin, 49 notification_context->GetPermissionStatus(requesting_origin,
50 embedding_origin); 50 embedding_origin);
51 51
52 if (notifications_permission == CONTENT_SETTING_BLOCK || 52 if (notifications_permission == CONTENT_SETTING_BLOCK ||
53 push_content_setting == CONTENT_SETTING_BLOCK) { 53 push_content_setting == CONTENT_SETTING_BLOCK) {
54 return CONTENT_SETTING_BLOCK; 54 return CONTENT_SETTING_BLOCK;
55 } 55 }
56 if (notifications_permission == CONTENT_SETTING_ASK || 56 if (notifications_permission == CONTENT_SETTING_ASK)
57 push_content_setting == CONTENT_SETTING_ASK) {
58 return CONTENT_SETTING_ASK; 57 return CONTENT_SETTING_ASK;
59 } 58
60 DCHECK_EQ(CONTENT_SETTING_ALLOW, notifications_permission); 59 DCHECK(push_content_setting == CONTENT_SETTING_ALLOW ||
61 DCHECK_EQ(CONTENT_SETTING_ALLOW, push_content_setting); 60 push_content_setting == CONTENT_SETTING_ASK);
61
62 // If the notifications permission has already been granted,
63 // and the push permission isn't explicitly blocked, then grant
64 // allow permission.
62 return CONTENT_SETTING_ALLOW; 65 return CONTENT_SETTING_ALLOW;
63 #else 66 #else
64 return CONTENT_SETTING_BLOCK; 67 return CONTENT_SETTING_BLOCK;
65 #endif 68 #endif
66 } 69 }
67 70
68 // Unlike other permissions, push is decided by the following algorithm 71 // Unlike other permissions, push is decided by the following algorithm
69 // - You need to request it from a top level domain 72 // - You need to request it from a top level domain
70 // - You need to have notification permission granted. 73 // - You need to have notification permission granted.
71 // - You need to not have push permission explicitly blocked. 74 // - You need to not have push permission explicitly blocked.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 DVLOG(1) << "Notification permission has not been granted."; 132 DVLOG(1) << "Notification permission has not been granted.";
130 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 133 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
131 false /* persist */, notification_content_setting); 134 false /* persist */, notification_content_setting);
132 return; 135 return;
133 } 136 }
134 137
135 PermissionUmaUtil::PermissionGranted(permission_type(), requesting_origin); 138 PermissionUmaUtil::PermissionGranted(permission_type(), requesting_origin);
136 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, 139 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback,
137 true /* persist */, CONTENT_SETTING_ALLOW); 140 true /* persist */, CONTENT_SETTING_ALLOW);
138 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698