| OLD | NEW |
| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 282 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 283 | 283 |
| 284 Profile* profile = Profile::FromBrowserContext(browser_context); | 284 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 285 DCHECK(profile); | 285 DCHECK(profile); |
| 286 DCHECK_EQ(0u, notification_data.actions.size()); | 286 DCHECK_EQ(0u, notification_data.actions.size()); |
| 287 DCHECK_EQ(0u, notification_resources.action_icons.size()); | 287 DCHECK_EQ(0u, notification_resources.action_icons.size()); |
| 288 | 288 |
| 289 NotificationObjectProxy* proxy = | 289 NotificationObjectProxy* proxy = |
| 290 new NotificationObjectProxy(browser_context, std::move(delegate)); | 290 new NotificationObjectProxy(browser_context, std::move(delegate)); |
| 291 Notification notification = CreateNotificationFromData( | 291 Notification notification = CreateNotificationFromData( |
| 292 profile, origin, notification_data, notification_resources, proxy); | 292 profile, GURL() /* service_worker_scope */, origin, notification_data, |
| 293 notification_resources, proxy); |
| 293 | 294 |
| 294 GetNotificationDisplayService(profile)->Display( | 295 GetNotificationDisplayService(profile)->Display( |
| 295 NotificationCommon::NON_PERSISTENT, notification.delegate_id(), | 296 NotificationCommon::NON_PERSISTENT, notification.delegate_id(), |
| 296 notification); | 297 notification); |
| 297 if (cancel_callback) { | 298 if (cancel_callback) { |
| 298 #if defined(OS_WIN) | 299 #if defined(OS_WIN) |
| 299 std::string profile_id = | 300 std::string profile_id = |
| 300 base::WideToUTF8(profile->GetPath().BaseName().value()); | 301 base::WideToUTF8(profile->GetPath().BaseName().value()); |
| 301 #elif defined(OS_POSIX) | 302 #elif defined(OS_POSIX) |
| 302 std::string profile_id = profile->GetPath().BaseName().value(); | 303 std::string profile_id = profile->GetPath().BaseName().value(); |
| 303 #endif | 304 #endif |
| 304 *cancel_callback = | 305 *cancel_callback = |
| 305 base::Bind(&CancelNotification, notification.delegate_id(), profile_id, | 306 base::Bind(&CancelNotification, notification.delegate_id(), profile_id, |
| 306 profile->IsOffTheRecord()); | 307 profile->IsOffTheRecord()); |
| 307 } | 308 } |
| 308 | 309 |
| 309 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( | 310 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
| 310 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 311 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 311 } | 312 } |
| 312 | 313 |
| 313 void PlatformNotificationServiceImpl::DisplayPersistentNotification( | 314 void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
| 314 BrowserContext* browser_context, | 315 BrowserContext* browser_context, |
| 315 int64_t persistent_notification_id, | 316 int64_t persistent_notification_id, |
| 317 const GURL& service_worker_scope, |
| 316 const GURL& origin, | 318 const GURL& origin, |
| 317 const content::PlatformNotificationData& notification_data, | 319 const content::PlatformNotificationData& notification_data, |
| 318 const content::NotificationResources& notification_resources) { | 320 const content::NotificationResources& notification_resources) { |
| 319 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 321 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 320 | 322 |
| 321 Profile* profile = Profile::FromBrowserContext(browser_context); | 323 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 322 DCHECK(profile); | 324 DCHECK(profile); |
| 323 | 325 |
| 324 // The notification settings button will be appended after the developer- | 326 // The notification settings button will be appended after the developer- |
| 325 // supplied buttons, available in |notification_data.actions|. | 327 // supplied buttons, available in |notification_data.actions|. |
| 326 int settings_button_index = notification_data.actions.size(); | 328 int settings_button_index = notification_data.actions.size(); |
| 327 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( | 329 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( |
| 328 browser_context, persistent_notification_id, origin, | 330 browser_context, persistent_notification_id, origin, |
| 329 settings_button_index); | 331 settings_button_index); |
| 330 | 332 |
| 331 Notification notification = CreateNotificationFromData( | 333 Notification notification = CreateNotificationFromData( |
| 332 profile, origin, notification_data, notification_resources, delegate); | 334 profile, service_worker_scope, origin, notification_data, |
| 335 notification_resources, delegate); |
| 333 | 336 |
| 334 // TODO(peter): Remove this mapping when we have reliable id generation for | 337 // TODO(peter): Remove this mapping when we have reliable id generation for |
| 335 // the message_center::Notification objects. | 338 // the message_center::Notification objects. |
| 336 persistent_notifications_[persistent_notification_id] = notification.id(); | 339 persistent_notifications_[persistent_notification_id] = notification.id(); |
| 337 | 340 |
| 338 GetNotificationDisplayService(profile)->Display( | 341 GetNotificationDisplayService(profile)->Display( |
| 339 NotificationCommon::PERSISTENT, | 342 NotificationCommon::PERSISTENT, |
| 340 base::Int64ToString(delegate->persistent_notification_id()), | 343 base::Int64ToString(delegate->persistent_notification_id()), |
| 341 notification); | 344 notification); |
| 342 content::RecordAction( | 345 content::RecordAction( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 void PlatformNotificationServiceImpl::OnCloseEventDispatchComplete( | 414 void PlatformNotificationServiceImpl::OnCloseEventDispatchComplete( |
| 412 content::PersistentNotificationStatus status) { | 415 content::PersistentNotificationStatus status) { |
| 413 UMA_HISTOGRAM_ENUMERATION( | 416 UMA_HISTOGRAM_ENUMERATION( |
| 414 "Notifications.PersistentWebNotificationCloseResult", status, | 417 "Notifications.PersistentWebNotificationCloseResult", status, |
| 415 content::PersistentNotificationStatus:: | 418 content::PersistentNotificationStatus:: |
| 416 PERSISTENT_NOTIFICATION_STATUS_MAX); | 419 PERSISTENT_NOTIFICATION_STATUS_MAX); |
| 417 } | 420 } |
| 418 | 421 |
| 419 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( | 422 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
| 420 Profile* profile, | 423 Profile* profile, |
| 424 const GURL& service_worker_scope, |
| 421 const GURL& origin, | 425 const GURL& origin, |
| 422 const content::PlatformNotificationData& notification_data, | 426 const content::PlatformNotificationData& notification_data, |
| 423 const content::NotificationResources& notification_resources, | 427 const content::NotificationResources& notification_resources, |
| 424 NotificationDelegate* delegate) const { | 428 NotificationDelegate* delegate) const { |
| 425 DCHECK_EQ(notification_data.actions.size(), | 429 DCHECK_EQ(notification_data.actions.size(), |
| 426 notification_resources.action_icons.size()); | 430 notification_resources.action_icons.size()); |
| 427 | 431 |
| 428 // TODO(peter): Handle different screen densities instead of always using the | 432 // TODO(peter): Handle different screen densities instead of always using the |
| 429 // 1x bitmap - crbug.com/585815. | 433 // 1x bitmap - crbug.com/585815. |
| 430 Notification notification( | 434 Notification notification( |
| 431 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, | 435 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, |
| 432 notification_data.body, | 436 notification_data.body, |
| 433 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), | 437 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), |
| 434 message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()), | 438 message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()), |
| 435 origin, notification_data.tag, message_center::RichNotificationData(), | 439 origin, notification_data.tag, message_center::RichNotificationData(), |
| 436 delegate); | 440 delegate); |
| 437 | 441 |
| 442 notification.set_service_worker_scope(service_worker_scope); |
| 438 notification.set_context_message( | 443 notification.set_context_message( |
| 439 DisplayNameForContextMessage(profile, origin)); | 444 DisplayNameForContextMessage(profile, origin)); |
| 440 notification.set_vibration_pattern(notification_data.vibration_pattern); | 445 notification.set_vibration_pattern(notification_data.vibration_pattern); |
| 441 notification.set_timestamp(notification_data.timestamp); | 446 notification.set_timestamp(notification_data.timestamp); |
| 442 notification.set_renotify(notification_data.renotify); | 447 notification.set_renotify(notification_data.renotify); |
| 443 notification.set_silent(notification_data.silent); | 448 notification.set_silent(notification_data.silent); |
| 444 | 449 |
| 445 // Badges are only supported on Android, primarily because it's the only | 450 // Badges are only supported on Android, primarily because it's the only |
| 446 // platform that makes good use of them in the status bar. | 451 // platform that makes good use of them in the status bar. |
| 447 // TODO(mvanouwerkerk): ensure no badge is loaded when it will not be used. | 452 // TODO(mvanouwerkerk): ensure no badge is loaded when it will not be used. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } | 501 } |
| 497 #endif | 502 #endif |
| 498 | 503 |
| 499 return base::string16(); | 504 return base::string16(); |
| 500 } | 505 } |
| 501 | 506 |
| 502 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( | 507 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( |
| 503 NotificationDisplayService* display_service) { | 508 NotificationDisplayService* display_service) { |
| 504 test_display_service_ = display_service; | 509 test_display_service_ = display_service; |
| 505 } | 510 } |
| OLD | NEW |