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

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

Issue 955383003: ContentBrowserClient::RequestPermission replies with PermissionStatus instead of bool. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix android geolocation breakage Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/desktop_notification_service.h" 5 #include "chrome/browser/notifications/desktop_notification_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 DesktopNotificationService::~DesktopNotificationService() { 91 DesktopNotificationService::~DesktopNotificationService() {
92 } 92 }
93 93
94 void DesktopNotificationService::RequestNotificationPermission( 94 void DesktopNotificationService::RequestNotificationPermission(
95 content::WebContents* web_contents, 95 content::WebContents* web_contents,
96 const PermissionRequestID& request_id, 96 const PermissionRequestID& request_id,
97 const GURL& requesting_origin, 97 const GURL& requesting_origin,
98 bool user_gesture, 98 bool user_gesture,
99 const base::Callback<void(bool)>& result_callback) { 99 const BrowserPermissionCallback& result_callback) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
101 101
102 #if defined(ENABLE_EXTENSIONS) 102 #if defined(ENABLE_EXTENSIONS)
103 extensions::InfoMap* extension_info_map = 103 extensions::InfoMap* extension_info_map =
104 extensions::ExtensionSystem::Get(profile_)->info_map(); 104 extensions::ExtensionSystem::Get(profile_)->info_map();
105 const extensions::Extension* extension = NULL; 105 const extensions::Extension* extension = NULL;
106 if (extension_info_map) { 106 if (extension_info_map) {
107 extensions::ExtensionSet extensions; 107 extensions::ExtensionSet extensions;
108 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin( 108 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
109 requesting_origin, 109 requesting_origin,
110 request_id.render_process_id(), 110 request_id.render_process_id(),
111 extensions::APIPermission::kNotifications, 111 extensions::APIPermission::kNotifications,
112 &extensions); 112 &extensions);
113 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); 113 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
114 iter != extensions.end(); ++iter) { 114 iter != extensions.end(); ++iter) {
115 if (IsNotifierEnabled(NotifierId( 115 if (IsNotifierEnabled(NotifierId(
116 NotifierId::APPLICATION, (*iter)->id()))) { 116 NotifierId::APPLICATION, (*iter)->id()))) {
117 extension = iter->get(); 117 extension = iter->get();
118 break; 118 break;
119 } 119 }
120 } 120 }
121 } 121 }
122 if (IsExtensionWithPermissionOrSuggestInConsole( 122 if (IsExtensionWithPermissionOrSuggestInConsole(
123 extensions::APIPermission::kNotifications, 123 extensions::APIPermission::kNotifications,
124 extension, 124 extension,
125 web_contents->GetRenderViewHost())) { 125 web_contents->GetRenderViewHost())) {
126 result_callback.Run(true); 126 result_callback.Run(CONTENT_SETTING_ALLOW);
127 return; 127 return;
128 } 128 }
129 #endif 129 #endif
130 130
131 // Track whether the requesting and embedding origins are different when 131 // Track whether the requesting and embedding origins are different when
132 // permission to display Web Notifications is being requested. 132 // permission to display Web Notifications is being requested.
133 UMA_HISTOGRAM_BOOLEAN("Notifications.DifferentRequestingEmbeddingOrigins", 133 UMA_HISTOGRAM_BOOLEAN("Notifications.DifferentRequestingEmbeddingOrigins",
134 requesting_origin.GetOrigin() != 134 requesting_origin.GetOrigin() !=
135 web_contents->GetLastCommittedURL().GetOrigin()); 135 web_contents->GetLastCommittedURL().GetOrigin());
136 136
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 #endif 238 #endif
239 239
240 // Unlike other permission types, granting a notification for a given origin 240 // Unlike other permission types, granting a notification for a given origin
241 // will not take into account the |embedder_origin|, it will only be based 241 // will not take into account the |embedder_origin|, it will only be based
242 // on the requesting iframe origin. 242 // on the requesting iframe origin.
243 // TODO(mukai) Consider why notifications behave differently than 243 // TODO(mukai) Consider why notifications behave differently than
244 // other permissions. crbug.com/416894 244 // other permissions. crbug.com/416894
245 void DesktopNotificationService::UpdateContentSetting( 245 void DesktopNotificationService::UpdateContentSetting(
246 const GURL& requesting_origin, 246 const GURL& requesting_origin,
247 const GURL& embedder_origin, 247 const GURL& embedder_origin,
248 bool allowed) { 248 ContentSetting content_setting) {
249 if (allowed) { 249 DCHECK(content_setting == CONTENT_SETTING_ALLOW ||
250 content_setting == CONTENT_SETTING_BLOCK);
251
252 if (content_setting == CONTENT_SETTING_ALLOW) {
250 DesktopNotificationProfileUtil::GrantPermission( 253 DesktopNotificationProfileUtil::GrantPermission(
251 profile_, requesting_origin); 254 profile_, requesting_origin);
252 } else { 255 } else {
253 DesktopNotificationProfileUtil::DenyPermission(profile_, requesting_origin); 256 DesktopNotificationProfileUtil::DenyPermission(profile_, requesting_origin);
254 } 257 }
255 } 258 }
256 259
257 void DesktopNotificationService::FirePermissionLevelChangedEvent( 260 void DesktopNotificationService::FirePermissionLevelChangedEvent(
258 const NotifierId& notifier_id, bool enabled) { 261 const NotifierId& notifier_id, bool enabled) {
259 #if defined(ENABLE_EXTENSIONS) 262 #if defined(ENABLE_EXTENSIONS)
(...skipping 13 matching lines...) Expand all
273 // Tell the IO thread that this extension's permission for notifications 276 // Tell the IO thread that this extension's permission for notifications
274 // has changed. 277 // has changed.
275 extensions::InfoMap* extension_info_map = 278 extensions::InfoMap* extension_info_map =
276 extensions::ExtensionSystem::Get(profile_)->info_map(); 279 extensions::ExtensionSystem::Get(profile_)->info_map();
277 BrowserThread::PostTask( 280 BrowserThread::PostTask(
278 BrowserThread::IO, FROM_HERE, 281 BrowserThread::IO, FROM_HERE,
279 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, 282 base::Bind(&extensions::InfoMap::SetNotificationsDisabled,
280 extension_info_map, notifier_id.id, !enabled)); 283 extension_info_map, notifier_id.id, !enabled));
281 #endif 284 #endif
282 } 285 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698