Chromium Code Reviews| 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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | |
| 16 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 17 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 17 #include "chrome/browser/permissions/permission_request_id.h" | 18 #include "chrome/browser/permissions/permission_request_id.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "components/content_settings/core/browser/host_content_settings_map.h" | |
| 19 #include "components/content_settings/core/common/content_settings_pattern.h" | 21 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/permission_type.h" | |
| 22 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 23 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.h" |
| 24 #include "content/public/browser/web_contents_user_data.h" | 25 #include "content/public/browser/web_contents_user_data.h" |
| 25 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // At most one of these is attached to each WebContents. It allows posting | 30 // At most one of these is attached to each WebContents. It allows posting |
| 30 // delayed tasks whose timer only counts down whilst the WebContents is visible | 31 // delayed tasks whose timer only counts down whilst the WebContents is visible |
| 31 // (and whose timer is reset whenever the WebContents stops being visible). | 32 // (and whose timer is reset whenever the WebContents stops being visible). |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 if (!task_queue_.empty()) | 155 if (!task_queue_.empty()) |
| 155 task_queue_.front().timer->Reset(); | 156 task_queue_.front().timer->Reset(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 } // namespace | 159 } // namespace |
| 159 | 160 |
| 160 DEFINE_WEB_CONTENTS_USER_DATA_KEY(VisibilityTimerTabHelper); | 161 DEFINE_WEB_CONTENTS_USER_DATA_KEY(VisibilityTimerTabHelper); |
| 161 | 162 |
| 162 NotificationPermissionContext::NotificationPermissionContext( | 163 NotificationPermissionContext::NotificationPermissionContext( |
| 163 Profile* profile, | 164 Profile* profile, |
| 164 content::PermissionType permission_type) | 165 ContentSettingsType content_settings_type) |
| 165 : PermissionContextBase(profile, | 166 : PermissionContextBase(profile, content_settings_type), |
| 166 permission_type, | |
| 167 CONTENT_SETTINGS_TYPE_NOTIFICATIONS), | |
| 168 weak_factory_ui_thread_(this) { | 167 weak_factory_ui_thread_(this) { |
| 169 DCHECK(permission_type == content::PermissionType::NOTIFICATIONS || | 168 DCHECK(content_settings_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || |
| 170 permission_type == content::PermissionType::PUSH_MESSAGING); | 169 content_settings_type == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 171 } | 170 } |
| 172 | 171 |
| 173 NotificationPermissionContext::~NotificationPermissionContext() {} | 172 NotificationPermissionContext::~NotificationPermissionContext() {} |
| 174 | 173 |
| 175 ContentSetting NotificationPermissionContext::GetPermissionStatusInternal( | 174 ContentSetting NotificationPermissionContext::GetPermissionStatusInternal( |
| 176 const GURL& requesting_origin, | 175 const GURL& requesting_origin, |
| 177 const GURL& embedding_origin) const { | 176 const GURL& embedding_origin) const { |
| 178 // Push messaging is only allowed to be granted on top-level origins. | 177 // Push messaging is only allowed to be granted on top-level origins. |
| 179 if (permission_type() == content::PermissionType::PUSH_MESSAGING && | 178 if (content_settings_type() == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING |
| 180 requesting_origin != embedding_origin) { | 179 && requesting_origin != embedding_origin) { |
| 181 return CONTENT_SETTING_BLOCK; | 180 return CONTENT_SETTING_BLOCK; |
| 182 } | 181 } |
| 183 | 182 |
| 184 return PermissionContextBase::GetPermissionStatusInternal(requesting_origin, | 183 return HostContentSettingsMapFactory::GetForProfile(profile()) |
|
dominickn
2017/02/03 21:42:28
What was the motivation for not calling Permission
Timothy Loh
2017/02/03 22:14:14
content_settings_type_ can be set to either NOTIFI
| |
| 185 embedding_origin); | 184 ->GetContentSetting(requesting_origin, embedding_origin, |
| 185 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()); | |
| 186 } | 186 } |
| 187 | 187 |
| 188 void NotificationPermissionContext::ResetPermission( | 188 void NotificationPermissionContext::ResetPermission( |
| 189 const GURL& requesting_origin, | 189 const GURL& requesting_origin, |
| 190 const GURL& embedder_origin) { | 190 const GURL& embedder_origin) { |
| 191 DesktopNotificationProfileUtil::ClearSetting(profile(), requesting_origin); | 191 DesktopNotificationProfileUtil::ClearSetting(profile(), requesting_origin); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void NotificationPermissionContext::CancelPermissionRequest( | 194 void NotificationPermissionContext::CancelPermissionRequest( |
| 195 content::WebContents* web_contents, | 195 content::WebContents* web_contents, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 if (content_setting == CONTENT_SETTING_ALLOW) { | 252 if (content_setting == CONTENT_SETTING_ALLOW) { |
| 253 DesktopNotificationProfileUtil::GrantPermission(profile(), | 253 DesktopNotificationProfileUtil::GrantPermission(profile(), |
| 254 requesting_origin); | 254 requesting_origin); |
| 255 } else { | 255 } else { |
| 256 DesktopNotificationProfileUtil::DenyPermission(profile(), | 256 DesktopNotificationProfileUtil::DenyPermission(profile(), |
| 257 requesting_origin); | 257 requesting_origin); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { | 261 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { |
| 262 return permission_type() == content::PermissionType::PUSH_MESSAGING; | 262 return content_settings_type() == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING; |
| 263 } | 263 } |
| OLD | NEW |