Chromium Code Reviews| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 const GURL& origin, | 332 const GURL& origin, |
| 333 const content::PlatformNotificationData& notification_data, | 333 const content::PlatformNotificationData& notification_data, |
| 334 const content::NotificationResources& notification_resources, | 334 const content::NotificationResources& notification_resources, |
| 335 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 335 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 336 base::Closure* cancel_callback) { | 336 base::Closure* cancel_callback) { |
| 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 338 | 338 |
| 339 Profile* profile = Profile::FromBrowserContext(browser_context); | 339 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 340 DCHECK(profile); | 340 DCHECK(profile); |
| 341 DCHECK_EQ(0u, notification_data.actions.size()); | 341 DCHECK_EQ(0u, notification_data.actions.size()); |
| 342 DCHECK_EQ(0u, notification_resources.action_icons.size()); | |
| 342 | 343 |
| 343 NotificationObjectProxy* proxy = | 344 NotificationObjectProxy* proxy = |
| 344 new NotificationObjectProxy(browser_context, std::move(delegate)); | 345 new NotificationObjectProxy(browser_context, std::move(delegate)); |
| 345 Notification notification = CreateNotificationFromData( | 346 Notification notification = CreateNotificationFromData( |
| 346 profile, origin, notification_data, notification_resources, proxy); | 347 profile, origin, notification_data, notification_resources, proxy); |
| 347 | 348 |
| 348 GetNotificationUIManager()->Add(notification, profile); | 349 GetNotificationUIManager()->Add(notification, profile); |
| 349 if (cancel_callback) | 350 if (cancel_callback) |
| 350 *cancel_callback = | 351 *cancel_callback = |
| 351 base::Bind(&CancelNotification, | 352 base::Bind(&CancelNotification, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 return false; | 450 return false; |
| 450 #endif // !defined(OS_ANDROID) | 451 #endif // !defined(OS_ANDROID) |
| 451 } | 452 } |
| 452 | 453 |
| 453 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( | 454 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
| 454 Profile* profile, | 455 Profile* profile, |
| 455 const GURL& origin, | 456 const GURL& origin, |
| 456 const content::PlatformNotificationData& notification_data, | 457 const content::PlatformNotificationData& notification_data, |
| 457 const content::NotificationResources& notification_resources, | 458 const content::NotificationResources& notification_resources, |
| 458 NotificationDelegate* delegate) const { | 459 NotificationDelegate* delegate) const { |
| 460 DCHECK_EQ(notification_data.actions.size(), | |
| 461 notification_resources.action_icons.size()); | |
| 462 | |
| 459 // TODO(peter): Icons for Web Notifications are currently always requested for | 463 // TODO(peter): Icons for Web Notifications are currently always requested for |
| 460 // 1x scale, whereas the displays on which they can be displayed can have a | 464 // 1x scale, whereas the displays on which they can be displayed can have a |
| 461 // different pixel density. Be smarter about this when the API gets updated | 465 // different pixel density. Be smarter about this when the API gets updated |
| 462 // with a way for developers to specify images of different resolutions. | 466 // with a way for developers to specify images of different resolutions. |
| 463 Notification notification( | 467 Notification notification( |
| 464 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, | 468 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, |
| 465 notification_data.body, | 469 notification_data.body, |
| 466 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), | 470 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), |
| 467 message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()), | 471 message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()), |
| 468 origin, notification_data.tag, message_center::RichNotificationData(), | 472 origin, notification_data.tag, message_center::RichNotificationData(), |
| 469 delegate); | 473 delegate); |
| 470 | 474 |
| 471 notification.set_context_message( | 475 notification.set_context_message( |
| 472 DisplayNameForContextMessage(profile, origin)); | 476 DisplayNameForContextMessage(profile, origin)); |
| 473 notification.set_vibration_pattern(notification_data.vibration_pattern); | 477 notification.set_vibration_pattern(notification_data.vibration_pattern); |
| 474 notification.set_timestamp(notification_data.timestamp); | 478 notification.set_timestamp(notification_data.timestamp); |
| 475 notification.set_silent(notification_data.silent); | 479 notification.set_silent(notification_data.silent); |
| 476 | 480 |
| 481 // Developer supplied action buttons. | |
| 477 std::vector<message_center::ButtonInfo> buttons; | 482 std::vector<message_center::ButtonInfo> buttons; |
| 478 | 483 for (size_t i = 0; i < notification_data.actions.size(); i++) { |
| 479 // Developer supplied buttons. | 484 message_center::ButtonInfo button(notification_data.actions[i].title); |
| 480 for (const auto& action : notification_data.actions) | 485 button.icon = |
|
Peter Beverloo
2016/02/10 12:29:37
Please add a reference to the TODO on line 463.
Michael van Ouwerkerk
2016/02/10 17:18:12
I've shortened that bit and added a bug reference.
| |
| 481 buttons.push_back(message_center::ButtonInfo(action.title)); | 486 gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]); |
| 482 | 487 buttons.push_back(button); |
| 488 } | |
| 483 notification.set_buttons(buttons); | 489 notification.set_buttons(buttons); |
| 484 | 490 |
| 485 // On desktop, notifications with require_interaction==true stay on-screen | 491 // On desktop, notifications with require_interaction==true stay on-screen |
| 486 // rather than minimizing to the notification center after a timeout. | 492 // rather than minimizing to the notification center after a timeout. |
| 487 // On mobile, this is ignored (notifications are minimized at all times). | 493 // On mobile, this is ignored (notifications are minimized at all times). |
| 488 if (notification_data.require_interaction) | 494 if (notification_data.require_interaction) |
| 489 notification.set_never_timeout(true); | 495 notification.set_never_timeout(true); |
| 490 | 496 |
| 491 return notification; | 497 return notification; |
| 492 } | 498 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 546 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 541 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 547 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 542 DCHECK(extension); | 548 DCHECK(extension); |
| 543 | 549 |
| 544 return base::UTF8ToUTF16(extension->name()); | 550 return base::UTF8ToUTF16(extension->name()); |
| 545 } | 551 } |
| 546 #endif | 552 #endif |
| 547 | 553 |
| 548 return base::string16(); | 554 return base::string16(); |
| 549 } | 555 } |
| OLD | NEW |