| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/win/metro.h" | 8 #include "base/win/metro.h" |
| 9 #include "chrome/browser/notifications/notification.h" | 9 #include "chrome/browser/notifications/notification.h" |
| 10 #include "chrome/browser/notifications/notification_object_proxy.h" | 10 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 11 #include "chrome/browser/notifications/notification_ui_manager.h" | 11 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | 12 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 13 #include "win8/util/win8_util.h" |
| 13 | 14 |
| 14 typedef void (*MetroDisplayNotification)( | 15 typedef void (*MetroDisplayNotification)( |
| 15 const char* origin_url, const char* icon_url, const wchar_t* title, | 16 const char* origin_url, const char* icon_url, const wchar_t* title, |
| 16 const wchar_t* body, const wchar_t* display_source, | 17 const wchar_t* body, const wchar_t* display_source, |
| 17 const char* notification_id); | 18 const char* notification_id); |
| 18 | 19 |
| 19 typedef bool (*MetroCancelNotification)(const char* notification_id); | 20 typedef bool (*MetroCancelNotification)(const char* notification_id); |
| 20 | 21 |
| 21 bool DesktopNotificationService::CancelDesktopNotification( | 22 bool DesktopNotificationService::CancelDesktopNotification( |
| 22 int process_id, int route_id, int notification_id) { | 23 int process_id, int route_id, int notification_id) { |
| 23 scoped_refptr<NotificationObjectProxy> proxy( | 24 scoped_refptr<NotificationObjectProxy> proxy( |
| 24 new NotificationObjectProxy(process_id, route_id, notification_id, | 25 new NotificationObjectProxy(process_id, route_id, notification_id, |
| 25 false)); | 26 false)); |
| 26 if (base::win::IsMetroProcess()) { | 27 if (win8::IsSingleWindowMetroMode()) { |
| 27 MetroCancelNotification cancel_metro_notification = | 28 MetroCancelNotification cancel_metro_notification = |
| 28 reinterpret_cast<MetroCancelNotification>(GetProcAddress( | 29 reinterpret_cast<MetroCancelNotification>(GetProcAddress( |
| 29 base::win::GetMetroModule(), "CancelNotification")); | 30 base::win::GetMetroModule(), "CancelNotification")); |
| 30 DCHECK(cancel_metro_notification); | 31 DCHECK(cancel_metro_notification); |
| 31 if (cancel_metro_notification(proxy->id().c_str())) | 32 if (cancel_metro_notification(proxy->id().c_str())) |
| 32 return true; | 33 return true; |
| 33 } | 34 } |
| 34 return GetUIManager()->CancelById(proxy->id()); | 35 return GetUIManager()->CancelById(proxy->id()); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void DesktopNotificationService::ShowNotification( | 38 void DesktopNotificationService::ShowNotification( |
| 38 const Notification& notification) { | 39 const Notification& notification) { |
| 39 if (base::win::IsMetroProcess()) { | 40 if (win8::IsSingleWindowMetroMode()) { |
| 40 MetroDisplayNotification display_metro_notification = | 41 MetroDisplayNotification display_metro_notification = |
| 41 reinterpret_cast<MetroDisplayNotification>(GetProcAddress( | 42 reinterpret_cast<MetroDisplayNotification>(GetProcAddress( |
| 42 base::win::GetMetroModule(), "DisplayNotification")); | 43 base::win::GetMetroModule(), "DisplayNotification")); |
| 43 DCHECK(display_metro_notification); | 44 DCHECK(display_metro_notification); |
| 44 if (!notification.is_html()) { | 45 if (!notification.is_html()) { |
| 45 display_metro_notification(notification.origin_url().spec().c_str(), | 46 display_metro_notification(notification.origin_url().spec().c_str(), |
| 46 notification.content_url().spec().c_str(), | 47 notification.content_url().spec().c_str(), |
| 47 notification.title().c_str(), | 48 notification.title().c_str(), |
| 48 notification.body().c_str(), | 49 notification.body().c_str(), |
| 49 notification.display_source().c_str(), | 50 notification.display_source().c_str(), |
| 50 notification.notification_id().c_str()); | 51 notification.notification_id().c_str()); |
| 51 return; | 52 return; |
| 52 } else { | 53 } else { |
| 53 NOTREACHED() << "We don't support HTML notifications in Windows 8 metro"; | 54 NOTREACHED() << "We don't support HTML notifications in Windows 8 metro"; |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 GetUIManager()->Add(notification, profile_); | 57 GetUIManager()->Add(notification, profile_); |
| 57 } | 58 } |
| OLD | NEW |