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 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase Created 3 years, 10 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"
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/notifications/desktop_notification_profile_util.h" 16 #include "chrome/browser/notifications/desktop_notification_profile_util.h"
17 #include "chrome/browser/permissions/permission_request_id.h" 17 #include "chrome/browser/permissions/permission_request_id.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "components/content_settings/core/common/content_settings_pattern.h" 19 #include "components/content_settings/core/common/content_settings_pattern.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/permission_type.h"
22 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/web_contents_observer.h" 22 #include "content/public/browser/web_contents_observer.h"
24 #include "content/public/browser/web_contents_user_data.h" 23 #include "content/public/browser/web_contents_user_data.h"
25 #include "url/gurl.h" 24 #include "url/gurl.h"
26 25
27 namespace { 26 namespace {
28 27
29 // At most one of these is attached to each WebContents. It allows posting 28 // 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 29 // delayed tasks whose timer only counts down whilst the WebContents is visible
31 // (and whose timer is reset whenever the WebContents stops being visible). 30 // (and whose timer is reset whenever the WebContents stops being visible).
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (!task_queue_.empty()) 153 if (!task_queue_.empty())
155 task_queue_.front().timer->Reset(); 154 task_queue_.front().timer->Reset();
156 } 155 }
157 156
158 } // namespace 157 } // namespace
159 158
160 DEFINE_WEB_CONTENTS_USER_DATA_KEY(VisibilityTimerTabHelper); 159 DEFINE_WEB_CONTENTS_USER_DATA_KEY(VisibilityTimerTabHelper);
161 160
162 NotificationPermissionContext::NotificationPermissionContext( 161 NotificationPermissionContext::NotificationPermissionContext(
163 Profile* profile, 162 Profile* profile,
164 content::PermissionType permission_type) 163 ContentSettingsType content_settings_type)
165 : PermissionContextBase(profile, 164 : PermissionContextBase(profile, content_settings_type),
166 permission_type,
167 CONTENT_SETTINGS_TYPE_NOTIFICATIONS),
168 weak_factory_ui_thread_(this) { 165 weak_factory_ui_thread_(this) {
169 DCHECK(permission_type == content::PermissionType::NOTIFICATIONS || 166 DCHECK(content_settings_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS ||
170 permission_type == content::PermissionType::PUSH_MESSAGING); 167 content_settings_type == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
171 } 168 }
172 169
173 NotificationPermissionContext::~NotificationPermissionContext() {} 170 NotificationPermissionContext::~NotificationPermissionContext() {}
174 171
175 ContentSetting NotificationPermissionContext::GetPermissionStatusInternal( 172 ContentSetting NotificationPermissionContext::GetPermissionStatusInternal(
176 const GURL& requesting_origin, 173 const GURL& requesting_origin,
177 const GURL& embedding_origin) const { 174 const GURL& embedding_origin) const {
178 // Push messaging is only allowed to be granted on top-level origins. 175 // Push messaging is only allowed to be granted on top-level origins.
179 if (permission_type() == content::PermissionType::PUSH_MESSAGING && 176 if (content_settings_type() == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING
180 requesting_origin != embedding_origin) { 177 && requesting_origin != embedding_origin) {
181 return CONTENT_SETTING_BLOCK; 178 return CONTENT_SETTING_BLOCK;
182 } 179 }
183 180
184 return PermissionContextBase::GetPermissionStatusInternal(requesting_origin, 181 return PermissionContextBase::GetPermissionStatusInternal(requesting_origin,
185 embedding_origin); 182 embedding_origin);
186 } 183 }
187 184
188 void NotificationPermissionContext::ResetPermission( 185 void NotificationPermissionContext::ResetPermission(
189 const GURL& requesting_origin, 186 const GURL& requesting_origin,
190 const GURL& embedder_origin) { 187 const GURL& embedder_origin) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if (content_setting == CONTENT_SETTING_ALLOW) { 249 if (content_setting == CONTENT_SETTING_ALLOW) {
253 DesktopNotificationProfileUtil::GrantPermission(profile(), 250 DesktopNotificationProfileUtil::GrantPermission(profile(),
254 requesting_origin); 251 requesting_origin);
255 } else { 252 } else {
256 DesktopNotificationProfileUtil::DenyPermission(profile(), 253 DesktopNotificationProfileUtil::DenyPermission(profile(),
257 requesting_origin); 254 requesting_origin);
258 } 255 }
259 } 256 }
260 257
261 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const { 258 bool NotificationPermissionContext::IsRestrictedToSecureOrigins() const {
262 return permission_type() == content::PermissionType::PUSH_MESSAGING; 259 return content_settings_type() == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING;
263 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698