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

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

Issue 1943963004: Revert of (reland) Move permission.mojom from WebKit/public/platform/ to components/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/platform_notification_service_impl.h" 5 #include "chrome/browser/notifications/platform_notification_service_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 base::Bind(&ProfileLoadedCallback, operation, origin, 171 base::Bind(&ProfileLoadedCallback, operation, origin,
172 persistent_notification_id, action_index)); 172 persistent_notification_id, action_index));
173 } 173 }
174 174
175 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( 175 void PlatformNotificationServiceImpl::OnPersistentNotificationClick(
176 BrowserContext* browser_context, 176 BrowserContext* browser_context,
177 int64_t persistent_notification_id, 177 int64_t persistent_notification_id,
178 const GURL& origin, 178 const GURL& origin,
179 int action_index) { 179 int action_index) {
180 DCHECK_CURRENTLY_ON(BrowserThread::UI); 180 DCHECK_CURRENTLY_ON(BrowserThread::UI);
181 permissions::mojom::PermissionStatus permission_status = 181 blink::mojom::PermissionStatus permission_status =
182 CheckPermissionOnUIThread(browser_context, origin, 182 CheckPermissionOnUIThread(browser_context, origin,
183 kInvalidRenderProcessId); 183 kInvalidRenderProcessId);
184 184
185 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved. 185 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved.
186 // Also change this method to be const again. 186 // Also change this method to be const again.
187 if (permission_status != permissions::mojom::PermissionStatus::GRANTED) { 187 if (permission_status != blink::mojom::PermissionStatus::GRANTED) {
188 content::RecordAction(base::UserMetricsAction( 188 content::RecordAction(base::UserMetricsAction(
189 "Notifications.Persistent.ClickedWithoutPermission")); 189 "Notifications.Persistent.ClickedWithoutPermission"));
190 return; 190 return;
191 } 191 }
192 192
193 if (action_index == -1) { 193 if (action_index == -1) {
194 content::RecordAction(base::UserMetricsAction( 194 content::RecordAction(base::UserMetricsAction(
195 "Notifications.Persistent.Clicked")); 195 "Notifications.Persistent.Clicked"));
196 } else { 196 } else {
197 content::RecordAction(base::UserMetricsAction( 197 content::RecordAction(base::UserMetricsAction(
(...skipping 23 matching lines...) Expand all
221 } else { 221 } else {
222 content::RecordAction(base::UserMetricsAction( 222 content::RecordAction(base::UserMetricsAction(
223 "Notifications.Persistent.ClosedProgrammatically")); 223 "Notifications.Persistent.ClosedProgrammatically"));
224 } 224 }
225 content::NotificationEventDispatcher::GetInstance() 225 content::NotificationEventDispatcher::GetInstance()
226 ->DispatchNotificationCloseEvent( 226 ->DispatchNotificationCloseEvent(
227 browser_context, persistent_notification_id, origin, by_user, 227 browser_context, persistent_notification_id, origin, by_user,
228 base::Bind(&OnCloseEventDispatchComplete)); 228 base::Bind(&OnCloseEventDispatchComplete));
229 } 229 }
230 230
231 permissions::mojom::PermissionStatus 231 blink::mojom::PermissionStatus
232 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( 232 PlatformNotificationServiceImpl::CheckPermissionOnUIThread(
233 BrowserContext* browser_context, 233 BrowserContext* browser_context,
234 const GURL& origin, 234 const GURL& origin,
235 int render_process_id) { 235 int render_process_id) {
236 DCHECK_CURRENTLY_ON(BrowserThread::UI); 236 DCHECK_CURRENTLY_ON(BrowserThread::UI);
237 237
238 Profile* profile = Profile::FromBrowserContext(browser_context); 238 Profile* profile = Profile::FromBrowserContext(browser_context);
239 DCHECK(profile); 239 DCHECK(profile);
240 240
241 #if defined(ENABLE_EXTENSIONS) 241 #if defined(ENABLE_EXTENSIONS)
(...skipping 13 matching lines...) Expand all
255 if (extension && 255 if (extension &&
256 extension->permissions_data()->HasAPIPermission( 256 extension->permissions_data()->HasAPIPermission(
257 extensions::APIPermission::kNotifications) && 257 extensions::APIPermission::kNotifications) &&
258 process_map->Contains(extension->id(), render_process_id)) { 258 process_map->Contains(extension->id(), render_process_id)) {
259 NotifierStateTracker* notifier_state_tracker = 259 NotifierStateTracker* notifier_state_tracker =
260 NotifierStateTrackerFactory::GetForProfile(profile); 260 NotifierStateTrackerFactory::GetForProfile(profile);
261 DCHECK(notifier_state_tracker); 261 DCHECK(notifier_state_tracker);
262 262
263 NotifierId notifier_id(NotifierId::APPLICATION, extension->id()); 263 NotifierId notifier_id(NotifierId::APPLICATION, extension->id());
264 if (notifier_state_tracker->IsNotifierEnabled(notifier_id)) 264 if (notifier_state_tracker->IsNotifierEnabled(notifier_id))
265 return permissions::mojom::PermissionStatus::GRANTED; 265 return blink::mojom::PermissionStatus::GRANTED;
266 } 266 }
267 } 267 }
268 #endif 268 #endif
269 269
270 ContentSetting setting = 270 ContentSetting setting =
271 DesktopNotificationProfileUtil::GetContentSetting(profile, origin); 271 DesktopNotificationProfileUtil::GetContentSetting(profile, origin);
272 272
273 if (setting == CONTENT_SETTING_ALLOW) 273 if (setting == CONTENT_SETTING_ALLOW)
274 return permissions::mojom::PermissionStatus::GRANTED; 274 return blink::mojom::PermissionStatus::GRANTED;
275 if (setting == CONTENT_SETTING_BLOCK) 275 if (setting == CONTENT_SETTING_BLOCK)
276 return permissions::mojom::PermissionStatus::DENIED; 276 return blink::mojom::PermissionStatus::DENIED;
277 277
278 return permissions::mojom::PermissionStatus::ASK; 278 return blink::mojom::PermissionStatus::ASK;
279 } 279 }
280 280
281 permissions::mojom::PermissionStatus 281 blink::mojom::PermissionStatus
282 PlatformNotificationServiceImpl::CheckPermissionOnIOThread( 282 PlatformNotificationServiceImpl::CheckPermissionOnIOThread(
283 content::ResourceContext* resource_context, 283 content::ResourceContext* resource_context,
284 const GURL& origin, 284 const GURL& origin,
285 int render_process_id) { 285 int render_process_id) {
286 DCHECK_CURRENTLY_ON(BrowserThread::IO); 286 DCHECK_CURRENTLY_ON(BrowserThread::IO);
287 287
288 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); 288 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
289 #if defined(ENABLE_EXTENSIONS) 289 #if defined(ENABLE_EXTENSIONS)
290 // Extensions support an API permission named "notification". This will grant 290 // Extensions support an API permission named "notification". This will grant
291 // not only grant permission for using the Chrome App extension API, but also 291 // not only grant permission for using the Chrome App extension API, but also
292 // for the Web Notification API. 292 // for the Web Notification API.
293 if (origin.SchemeIs(extensions::kExtensionScheme)) { 293 if (origin.SchemeIs(extensions::kExtensionScheme)) {
294 extensions::InfoMap* extension_info_map = io_data->GetExtensionInfoMap(); 294 extensions::InfoMap* extension_info_map = io_data->GetExtensionInfoMap();
295 const extensions::ProcessMap& process_map = 295 const extensions::ProcessMap& process_map =
296 extension_info_map->process_map(); 296 extension_info_map->process_map();
297 297
298 const extensions::Extension* extension = 298 const extensions::Extension* extension =
299 extension_info_map->extensions().GetByID(origin.host()); 299 extension_info_map->extensions().GetByID(origin.host());
300 300
301 if (extension && 301 if (extension &&
302 extension->permissions_data()->HasAPIPermission( 302 extension->permissions_data()->HasAPIPermission(
303 extensions::APIPermission::kNotifications) && 303 extensions::APIPermission::kNotifications) &&
304 process_map.Contains(extension->id(), render_process_id)) { 304 process_map.Contains(extension->id(), render_process_id)) {
305 if (!extension_info_map->AreNotificationsDisabled(extension->id())) 305 if (!extension_info_map->AreNotificationsDisabled(extension->id()))
306 return permissions::mojom::PermissionStatus::GRANTED; 306 return blink::mojom::PermissionStatus::GRANTED;
307 } 307 }
308 } 308 }
309 #endif 309 #endif
310 310
311 // No enabled extensions exist, so check the normal host content settings. 311 // No enabled extensions exist, so check the normal host content settings.
312 HostContentSettingsMap* host_content_settings_map = 312 HostContentSettingsMap* host_content_settings_map =
313 io_data->GetHostContentSettingsMap(); 313 io_data->GetHostContentSettingsMap();
314 ContentSetting setting = host_content_settings_map->GetContentSetting( 314 ContentSetting setting = host_content_settings_map->GetContentSetting(
315 origin, 315 origin,
316 origin, 316 origin,
317 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 317 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
318 content_settings::ResourceIdentifier()); 318 content_settings::ResourceIdentifier());
319 319
320 if (setting == CONTENT_SETTING_ALLOW) 320 if (setting == CONTENT_SETTING_ALLOW)
321 return permissions::mojom::PermissionStatus::GRANTED; 321 return blink::mojom::PermissionStatus::GRANTED;
322 if (setting == CONTENT_SETTING_BLOCK) 322 if (setting == CONTENT_SETTING_BLOCK)
323 return permissions::mojom::PermissionStatus::DENIED; 323 return blink::mojom::PermissionStatus::DENIED;
324 324
325 return permissions::mojom::PermissionStatus::ASK; 325 return blink::mojom::PermissionStatus::ASK;
326 } 326 }
327 327
328 void PlatformNotificationServiceImpl::DisplayNotification( 328 void PlatformNotificationServiceImpl::DisplayNotification(
329 BrowserContext* browser_context, 329 BrowserContext* browser_context,
330 const GURL& origin, 330 const GURL& origin,
331 const content::PlatformNotificationData& notification_data, 331 const content::PlatformNotificationData& notification_data,
332 const content::NotificationResources& notification_resources, 332 const content::NotificationResources& notification_resources,
333 std::unique_ptr<content::DesktopNotificationDelegate> delegate, 333 std::unique_ptr<content::DesktopNotificationDelegate> delegate,
334 base::Closure* cancel_callback) { 334 base::Closure* cancel_callback) {
335 DCHECK_CURRENTLY_ON(BrowserThread::UI); 335 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 539 }
540 #endif 540 #endif
541 541
542 return base::string16(); 542 return base::string16();
543 } 543 }
544 544
545 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( 545 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting(
546 NotificationDisplayService* display_service) { 546 NotificationDisplayService* display_service) {
547 test_display_service_ = display_service; 547 test_display_service_ = display_service;
548 } 548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698