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

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: Rebase. 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 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(profile(), requesting_origin); 173 DesktopNotificationProfileUtil::ClearSetting(
174 profile(), GURL(requesting_origin.Serialize()));
174 } 175 }
175 176
176 void NotificationPermissionContext::CancelPermissionRequest( 177 void NotificationPermissionContext::CancelPermissionRequest(
177 content::WebContents* web_contents, 178 content::WebContents* web_contents,
178 const PermissionRequestID& id) { 179 const PermissionRequestID& id) {
179 if (profile()->IsOffTheRecord()) { 180 if (profile()->IsOffTheRecord()) {
180 VisibilityTimerTabHelper::FromWebContents(web_contents)->CancelTask(id); 181 VisibilityTimerTabHelper::FromWebContents(web_contents)->CancelTask(id);
181 } else { 182 } else {
182 PermissionContextBase::CancelPermissionRequest(web_contents, id); 183 PermissionContextBase::CancelPermissionRequest(web_contents, id);
183 } 184 }
184 } 185 }
185 186
186 void NotificationPermissionContext::DecidePermission( 187 void NotificationPermissionContext::DecidePermission(
187 content::WebContents* web_contents, 188 content::WebContents* web_contents,
188 const PermissionRequestID& id, 189 const PermissionRequestID& id,
189 const GURL& requesting_origin, 190 const url::Origin& requesting_origin,
190 const GURL& embedding_origin, 191 const url::Origin& embedding_origin,
191 const BrowserPermissionCallback& callback) { 192 const BrowserPermissionCallback& callback) {
192 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 193 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
193 194
194 // Notifications permission is always denied in incognito. To prevent sites 195 // Notifications permission is always denied in incognito. To prevent sites
195 // from using that to detect whether incognito mode is active, we deny after a 196 // from using that to detect whether incognito mode is active, we deny after a
196 // random time delay, to simulate a user clicking a bubble/infobar. See also 197 // random time delay, to simulate a user clicking a bubble/infobar. See also
197 // ContentSettingsRegistry::Init, which marks notifications as 198 // ContentSettingsRegistry::Init, which marks notifications as
198 // INHERIT_IN_INCOGNITO_EXCEPT_ALLOW, and 199 // INHERIT_IN_INCOGNITO_EXCEPT_ALLOW, and
199 // PermissionMenuModel::PermissionMenuModel which prevents users from manually 200 // PermissionMenuModel::PermissionMenuModel which prevents users from manually
200 // allowing the permission. 201 // allowing the permission.
(...skipping 15 matching lines...) Expand all
216 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, 217 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin,
217 embedding_origin, callback); 218 embedding_origin, callback);
218 } 219 }
219 220
220 // Unlike other permission types, granting a notification for a given origin 221 // Unlike other permission types, granting a notification for a given origin
221 // will not take into account the |embedder_origin|, it will only be based 222 // will not take into account the |embedder_origin|, it will only be based
222 // on the requesting iframe origin. 223 // on the requesting iframe origin.
223 // TODO(mukai) Consider why notifications behave differently than 224 // TODO(mukai) Consider why notifications behave differently than
224 // other permissions. https://crbug.com/416894 225 // other permissions. https://crbug.com/416894
225 void NotificationPermissionContext::UpdateContentSetting( 226 void NotificationPermissionContext::UpdateContentSetting(
226 const GURL& requesting_origin, 227 const url::Origin& requesting_origin,
227 const GURL& embedder_origin, 228 const url::Origin& embedder_origin,
228 ContentSetting content_setting) { 229 ContentSetting content_setting) {
229 DCHECK(content_setting == CONTENT_SETTING_ALLOW || 230 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
230 content_setting == CONTENT_SETTING_BLOCK); 231 content_setting == CONTENT_SETTING_BLOCK);
231 232
233 const GURL requesting_url(requesting_origin.Serialize());
232 if (content_setting == CONTENT_SETTING_ALLOW) { 234 if (content_setting == CONTENT_SETTING_ALLOW) {
233 DesktopNotificationProfileUtil::GrantPermission(profile(), 235 DesktopNotificationProfileUtil::GrantPermission(profile(), requesting_url);
234 requesting_origin);
235 } else { 236 } else {
236 DesktopNotificationProfileUtil::DenyPermission(profile(), 237 DesktopNotificationProfileUtil::DenyPermission(profile(), requesting_url);
237 requesting_origin);
238 } 238 }
239 } 239 }
240 240
241 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { 241 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const {
242 return false; 242 return false;
243 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698