OLD | NEW |
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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 } else { | 181 } else { |
182 PermissionContextBase::CancelPermissionRequest(web_contents, id); | 182 PermissionContextBase::CancelPermissionRequest(web_contents, id); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 void NotificationPermissionContext::DecidePermission( | 186 void NotificationPermissionContext::DecidePermission( |
187 content::WebContents* web_contents, | 187 content::WebContents* web_contents, |
188 const PermissionRequestID& id, | 188 const PermissionRequestID& id, |
189 const GURL& requesting_origin, | 189 const GURL& requesting_origin, |
190 const GURL& embedding_origin, | 190 const GURL& embedding_origin, |
| 191 bool user_gesture, |
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. |
201 if (profile()->IsOffTheRecord()) { | 202 if (profile()->IsOffTheRecord()) { |
202 // Random number of seconds in the range [1.0, 2.0). | 203 // Random number of seconds in the range [1.0, 2.0). |
203 double delay_seconds = 1.0 + 1.0 * base::RandDouble(); | 204 double delay_seconds = 1.0 + 1.0 * base::RandDouble(); |
204 VisibilityTimerTabHelper::CreateForWebContents(web_contents); | 205 VisibilityTimerTabHelper::CreateForWebContents(web_contents); |
205 VisibilityTimerTabHelper::FromWebContents(web_contents) | 206 VisibilityTimerTabHelper::FromWebContents(web_contents) |
206 ->PostTaskAfterVisibleDelay( | 207 ->PostTaskAfterVisibleDelay( |
207 FROM_HERE, | 208 FROM_HERE, |
208 base::Bind(&NotificationPermissionContext::NotifyPermissionSet, | 209 base::Bind(&NotificationPermissionContext::NotifyPermissionSet, |
209 weak_factory_ui_thread_.GetWeakPtr(), id, | 210 weak_factory_ui_thread_.GetWeakPtr(), id, |
210 requesting_origin, embedding_origin, callback, | 211 requesting_origin, embedding_origin, callback, |
211 true /* persist */, CONTENT_SETTING_BLOCK), | 212 true /* persist */, CONTENT_SETTING_BLOCK), |
212 base::TimeDelta::FromSecondsD(delay_seconds), id); | 213 base::TimeDelta::FromSecondsD(delay_seconds), id); |
213 return; | 214 return; |
214 } | 215 } |
215 | 216 |
216 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, | 217 PermissionContextBase::DecidePermission(web_contents, id, requesting_origin, |
217 embedding_origin, callback); | 218 embedding_origin, user_gesture, |
| 219 callback); |
218 } | 220 } |
219 | 221 |
220 // Unlike other permission types, granting a notification for a given origin | 222 // 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 | 223 // will not take into account the |embedder_origin|, it will only be based |
222 // on the requesting iframe origin. | 224 // on the requesting iframe origin. |
223 // TODO(mukai) Consider why notifications behave differently than | 225 // TODO(mukai) Consider why notifications behave differently than |
224 // other permissions. https://crbug.com/416894 | 226 // other permissions. https://crbug.com/416894 |
225 void NotificationPermissionContext::UpdateContentSetting( | 227 void NotificationPermissionContext::UpdateContentSetting( |
226 const GURL& requesting_origin, | 228 const GURL& requesting_origin, |
227 const GURL& embedder_origin, | 229 const GURL& embedder_origin, |
228 ContentSetting content_setting) { | 230 ContentSetting content_setting) { |
229 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 231 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
230 content_setting == CONTENT_SETTING_BLOCK); | 232 content_setting == CONTENT_SETTING_BLOCK); |
231 | 233 |
232 if (content_setting == CONTENT_SETTING_ALLOW) { | 234 if (content_setting == CONTENT_SETTING_ALLOW) { |
233 DesktopNotificationProfileUtil::GrantPermission(profile(), | 235 DesktopNotificationProfileUtil::GrantPermission(profile(), |
234 requesting_origin); | 236 requesting_origin); |
235 } else { | 237 } else { |
236 DesktopNotificationProfileUtil::DenyPermission(profile(), | 238 DesktopNotificationProfileUtil::DenyPermission(profile(), |
237 requesting_origin); | 239 requesting_origin); |
238 } | 240 } |
239 } | 241 } |
240 | 242 |
241 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { | 243 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { |
242 return false; | 244 return false; |
243 } | 245 } |
OLD | NEW |