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