| 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 { |
| 459 // TODO(peter): Icons for Web Notifications are currently always requested for | 460 DCHECK_EQ(notification_data.actions.size(), |
| 460 // 1x scale, whereas the displays on which they can be displayed can have a | 461 notification_resources.action_icons.size()); |
| 461 // different pixel density. Be smarter about this when the API gets updated | 462 |
| 462 // with a way for developers to specify images of different resolutions. | 463 // TODO(peter): Handle different screen densities instead of always using the |
| 464 // 1x bitmap - crbug.com/585815. |
| 463 Notification notification( | 465 Notification notification( |
| 464 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, | 466 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, |
| 465 notification_data.body, | 467 notification_data.body, |
| 466 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), | 468 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), |
| 467 message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()), | 469 message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()), |
| 468 origin, notification_data.tag, message_center::RichNotificationData(), | 470 origin, notification_data.tag, message_center::RichNotificationData(), |
| 469 delegate); | 471 delegate); |
| 470 | 472 |
| 471 notification.set_context_message( | 473 notification.set_context_message( |
| 472 DisplayNameForContextMessage(profile, origin)); | 474 DisplayNameForContextMessage(profile, origin)); |
| 473 notification.set_vibration_pattern(notification_data.vibration_pattern); | 475 notification.set_vibration_pattern(notification_data.vibration_pattern); |
| 474 notification.set_timestamp(notification_data.timestamp); | 476 notification.set_timestamp(notification_data.timestamp); |
| 475 notification.set_silent(notification_data.silent); | 477 notification.set_silent(notification_data.silent); |
| 476 | 478 |
| 479 // Developer supplied action buttons. |
| 477 std::vector<message_center::ButtonInfo> buttons; | 480 std::vector<message_center::ButtonInfo> buttons; |
| 478 | 481 for (size_t i = 0; i < notification_data.actions.size(); i++) { |
| 479 // Developer supplied buttons. | 482 message_center::ButtonInfo button(notification_data.actions[i].title); |
| 480 for (const auto& action : notification_data.actions) | 483 // TODO(peter): Handle different screen densities instead of always using |
| 481 buttons.push_back(message_center::ButtonInfo(action.title)); | 484 // the 1x bitmap - crbug.com/585815. |
| 482 | 485 button.icon = |
| 486 gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]); |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 545 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
| 540 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 546 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
| 541 DCHECK(extension); | 547 DCHECK(extension); |
| 542 | 548 |
| 543 return base::UTF8ToUTF16(extension->name()); | 549 return base::UTF8ToUTF16(extension->name()); |
| 544 } | 550 } |
| 545 #endif | 551 #endif |
| 546 | 552 |
| 547 return base::string16(); | 553 return base::string16(); |
| 548 } | 554 } |
| OLD | NEW |