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

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

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

Powered by Google App Engine
This is Rietveld 408576698