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

Side by Side Diff: chrome/browser/notifications/notification_permission_context.cc

Issue 1726323002: Have Permission{Manager,Service} use Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clarify and test Origin.empty_. Created 4 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/notifications/notification_permission_context.h" 5 #include "chrome/browser/notifications/notification_permission_context.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 NotificationPermissionContext::NotificationPermissionContext(Profile* profile) 162 NotificationPermissionContext::NotificationPermissionContext(Profile* profile)
163 : PermissionContextBase(profile, 163 : PermissionContextBase(profile,
164 content::PermissionType::NOTIFICATIONS, 164 content::PermissionType::NOTIFICATIONS,
165 CONTENT_SETTINGS_TYPE_NOTIFICATIONS), 165 CONTENT_SETTINGS_TYPE_NOTIFICATIONS),
166 weak_factory_ui_thread_(this) {} 166 weak_factory_ui_thread_(this) {}
167 167
168 NotificationPermissionContext::~NotificationPermissionContext() {} 168 NotificationPermissionContext::~NotificationPermissionContext() {}
169 169
170 void NotificationPermissionContext::ResetPermission( 170 void NotificationPermissionContext::ResetPermission(
171 const GURL& requesting_origin, 171 const url::Origin& requesting_origin,
172 const GURL& embedder_origin) { 172 const url::Origin& embedder_origin) {
173 DesktopNotificationProfileUtil::ClearSetting( 173 DesktopNotificationProfileUtil::ClearSetting(
174 profile(), ContentSettingsPattern::FromURLNoWildcard(requesting_origin)); 174 profile(), ContentSettingsPattern::FromURLNoWildcard(
175 GURL(requesting_origin.Serialize())));
175 } 176 }
176 177
177 void NotificationPermissionContext::CancelPermissionRequest( 178 void NotificationPermissionContext::CancelPermissionRequest(
178 content::WebContents* web_contents, 179 content::WebContents* web_contents,
179 const PermissionRequestID& id) { 180 const PermissionRequestID& id) {
180 if (profile()->IsOffTheRecord()) { 181 if (profile()->IsOffTheRecord()) {
181 VisibilityTimerTabHelper::FromWebContents(web_contents)->CancelTask(id); 182 VisibilityTimerTabHelper::FromWebContents(web_contents)->CancelTask(id);
182 } else { 183 } else {
183 PermissionContextBase::CancelPermissionRequest(web_contents, id); 184 PermissionContextBase::CancelPermissionRequest(web_contents, id);
184 } 185 }
185 } 186 }
186 187
187 void NotificationPermissionContext::DecidePermission( 188 void NotificationPermissionContext::DecidePermission(
188 content::WebContents* web_contents, 189 content::WebContents* web_contents,
189 const PermissionRequestID& id, 190 const PermissionRequestID& id,
190 const GURL& requesting_origin, 191 const url::Origin& requesting_origin,
191 const GURL& embedding_origin, 192 const url::Origin& embedding_origin,
192 const BrowserPermissionCallback& callback) { 193 const BrowserPermissionCallback& callback) {
193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 194 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
194 195
195 // Notifications permission is always denied in incognito. To prevent sites 196 // Notifications permission is always denied in incognito. To prevent sites
196 // from using that to detect whether incognito mode is active, we deny after a 197 // from using that to detect whether incognito mode is active, we deny after a
197 // random time delay, to simulate a user clicking a bubble/infobar. See also 198 // random time delay, to simulate a user clicking a bubble/infobar. See also
198 // ContentSettingsRegistry::Init, which marks notifications as 199 // ContentSettingsRegistry::Init, which marks notifications as
199 // INHERIT_IN_INCOGNITO_EXCEPT_ALLOW, and 200 // INHERIT_IN_INCOGNITO_EXCEPT_ALLOW, and
200 // PermissionMenuModel::PermissionMenuModel which prevents users from manually 201 // PermissionMenuModel::PermissionMenuModel which prevents users from manually
201 // allowing the permission. 202 // allowing the permission.
(...skipping 15 matching lines...) Expand all
217 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, 218 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin,
218 embedding_origin, callback); 219 embedding_origin, callback);
219 } 220 }
220 221
221 // Unlike other permission types, granting a notification for a given origin 222 // Unlike other permission types, granting a notification for a given origin
222 // will not take into account the |embedder_origin|, it will only be based 223 // will not take into account the |embedder_origin|, it will only be based
223 // on the requesting iframe origin. 224 // on the requesting iframe origin.
224 // TODO(mukai) Consider why notifications behave differently than 225 // TODO(mukai) Consider why notifications behave differently than
225 // other permissions. https://crbug.com/416894 226 // other permissions. https://crbug.com/416894
226 void NotificationPermissionContext::UpdateContentSetting( 227 void NotificationPermissionContext::UpdateContentSetting(
227 const GURL& requesting_origin, 228 const url::Origin& requesting_origin,
228 const GURL& embedder_origin, 229 const url::Origin& embedder_origin,
229 ContentSetting content_setting) { 230 ContentSetting content_setting) {
230 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 231 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
231 content_setting == CONTENT_SETTING_BLOCK); 232 content_setting == CONTENT_SETTING_BLOCK);
232 233
234 const GURL requesting_url(requesting_origin.Serialize());
233 if (content_setting == CONTENT_SETTING_ALLOW) { 235 if (content_setting == CONTENT_SETTING_ALLOW) {
234 DesktopNotificationProfileUtil::GrantPermission(profile(), 236 DesktopNotificationProfileUtil::GrantPermission(profile(), requesting_url);
235 requesting_origin);
236 } else { 237 } else {
237 DesktopNotificationProfileUtil::DenyPermission(profile(), 238 DesktopNotificationProfileUtil::DenyPermission(profile(), requesting_url);
238 requesting_origin);
239 } 239 }
240 } 240 }
241 241
242 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { 242 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const {
243 return false; 243 return false;
244 } 244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698