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/sync_notifier/synced_notification.h" | 5 #include "chrome/browser/notifications/sync_notifier/synced_notification.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/notifications/notification.h" | 12 #include "chrome/browser/notifications/notification.h" |
12 #include "chrome/browser/notifications/notification_ui_manager.h" | 13 #include "chrome/browser/notifications/notification_ui_manager.h" |
13 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" | 14 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" |
14 #include "sync/protocol/sync.pb.h" | 15 #include "sync/protocol/sync.pb.h" |
15 #include "sync/protocol/synced_notification_specifics.pb.h" | 16 #include "sync/protocol/synced_notification_specifics.pb.h" |
| 17 #include "ui/gfx/image/image.h" |
16 #include "ui/message_center/message_center_util.h" | 18 #include "ui/message_center/message_center_util.h" |
17 #include "ui/message_center/notification_types.h" | 19 #include "ui/message_center/notification_types.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 const char kExtensionScheme[] = "chrome-extension://"; | 22 const char kExtensionScheme[] = "chrome-extension://"; |
21 | 23 |
22 bool UseRichNotifications() { | 24 bool UseRichNotifications() { |
23 return message_center::IsRichNotificationEnabled(); | 25 return message_center::IsRichNotificationEnabled(); |
24 } | 26 } |
25 | 27 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // I change the interface to let NotificationUIManager know the right way. | 79 // I change the interface to let NotificationUIManager know the right way. |
78 if (SyncedNotification::kRead == GetReadState() || | 80 if (SyncedNotification::kRead == GetReadState() || |
79 SyncedNotification::kDismissed == GetReadState() ) { | 81 SyncedNotification::kDismissed == GetReadState() ) { |
80 DVLOG(2) << "Dismissed notification arrived" | 82 DVLOG(2) << "Dismissed notification arrived" |
81 << GetHeading() << " " << GetText(); | 83 << GetHeading() << " " << GetText(); |
82 return; | 84 return; |
83 } | 85 } |
84 | 86 |
85 // Some inputs and fields are only used if there is a notification center. | 87 // Some inputs and fields are only used if there is a notification center. |
86 if (UseRichNotifications()) { | 88 if (UseRichNotifications()) { |
87 double creation_time = static_cast<double>(GetCreationTime()); | 89 base::Time creation_time = |
| 90 base::Time::FromDoubleT(static_cast<double>(GetCreationTime())); |
88 int priority = GetPriority(); | 91 int priority = GetPriority(); |
89 int notification_count = GetNotificationCount(); | 92 int notification_count = GetNotificationCount(); |
90 int button_count = GetButtonCount(); | 93 int button_count = GetButtonCount(); |
91 // TODO(petewil): Refactor this for an arbitrary number of buttons. | 94 // TODO(petewil): Refactor this for an arbitrary number of buttons. |
92 std::string button_one_title = GetButtonOneTitle(); | 95 std::string button_one_title = GetButtonOneTitle(); |
93 std::string button_one_icon_url = GetButtonOneIconUrl(); | |
94 std::string button_two_title = GetButtonTwoTitle(); | 96 std::string button_two_title = GetButtonTwoTitle(); |
95 std::string button_two_icon_url = GetButtonTwoIconUrl(); | |
96 | 97 |
97 // Deduce which notification template to use from the data. | 98 // Deduce which notification template to use from the data. |
98 message_center::NotificationType notification_type = | 99 message_center::NotificationType notification_type = |
99 message_center::NOTIFICATION_TYPE_BASE_FORMAT; | 100 message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
100 if (!image_url.is_empty()) { | 101 if (!image_url.is_empty()) { |
101 notification_type = message_center::NOTIFICATION_TYPE_IMAGE; | 102 notification_type = message_center::NOTIFICATION_TYPE_IMAGE; |
102 } else if (notification_count > 1) { | 103 } else if (notification_count > 1) { |
103 notification_type = message_center::NOTIFICATION_TYPE_MULTIPLE; | 104 notification_type = message_center::NOTIFICATION_TYPE_MULTIPLE; |
104 } else if (button_count > 0) { | 105 } else if (button_count > 0) { |
105 notification_type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; | 106 notification_type = message_center::NOTIFICATION_TYPE_BASE_FORMAT; |
106 } | 107 } |
107 | 108 |
108 // Fill the optional fields with the information we need to make a | 109 // Fill the optional fields with the information we need to make a |
109 // notification. | 110 // notification. |
110 DictionaryValue optional_fields; | 111 message_center::RichNotificationData rich_notification_data; |
111 optional_fields.SetDouble(message_center::kTimestampKey, creation_time); | 112 rich_notification_data.timestamp = creation_time; |
112 if (priority != SyncedNotification::kUndefinedPriority) | 113 if (priority != SyncedNotification::kUndefinedPriority) |
113 optional_fields.SetInteger(message_center::kPriorityKey, priority); | 114 rich_notification_data.priority = priority; |
114 if (!button_one_title.empty()) | 115 if (!button_one_title.empty()) { |
115 optional_fields.SetString(message_center::kButtonOneTitleKey, | 116 message_center::ButtonInfo button_info(UTF8ToUTF16(button_one_title)); |
116 button_one_title); | 117 rich_notification_data.buttons.push_back(button_info); |
117 if (!button_one_icon_url.empty()) | 118 // TODO(petewil): Add a button icon here. |
118 optional_fields.SetString(message_center::kButtonOneIconUrlKey, | 119 } |
119 button_one_icon_url); | 120 if (!button_two_title.empty()) { |
120 if (!button_two_title.empty()) | 121 message_center::ButtonInfo button_info(UTF8ToUTF16(button_two_title)); |
121 optional_fields.SetString(message_center::kButtonTwoTitleKey, | 122 rich_notification_data.buttons.push_back(button_info); |
122 button_two_title); | 123 // TODO(petewil): Add a button icon here. |
123 if (!button_two_icon_url.empty()) | 124 } |
124 optional_fields.SetString(message_center::kButtonTwoIconUrlKey, | |
125 button_two_icon_url); | |
126 | 125 |
127 // Fill the individual notification fields for a multiple notification. | 126 // Fill the individual notification fields for a multiple notification. |
128 if (notification_count > 1) { | 127 if (notification_count > 1) { |
129 base::ListValue* items = new base::ListValue(); | |
130 | |
131 for (int ii = 0; ii < notification_count; ++ii) { | 128 for (int ii = 0; ii < notification_count; ++ii) { |
132 DictionaryValue* item = new DictionaryValue(); | 129 message_center::NotificationItem item( |
133 item->SetString(message_center::kItemTitleKey, | 130 UTF8ToUTF16(GetContainedNotificationTitle(ii)), |
134 UTF8ToUTF16(GetContainedNotificationTitle( | 131 UTF8ToUTF16(GetContainedNotificationMessage(ii))); |
135 ii))); | 132 rich_notification_data.items.push_back(item); |
136 item->SetString(message_center::kItemMessageKey, | |
137 UTF8ToUTF16(GetContainedNotificationMessage( | |
138 ii))); | |
139 items->Append(item); | |
140 } | 133 } |
141 | |
142 optional_fields.Set(message_center::kItemsKey, items); | |
143 } | 134 } |
144 | 135 |
| 136 // TODO(petewil): Add code here that sets the various notification images |
| 137 // that have been decoded. Also, don't use the notification tray icon once |
| 138 // this is enabled, that could cause user confusion. |
145 Notification ui_notification(notification_type, | 139 Notification ui_notification(notification_type, |
146 GetOriginUrl(), | 140 GetOriginUrl(), |
147 GetAppIconUrl(), | |
148 heading, | 141 heading, |
149 text, | 142 text, |
| 143 gfx::Image(), |
150 WebKit::WebTextDirectionDefault, | 144 WebKit::WebTextDirectionDefault, |
151 display_source, | 145 display_source, |
152 replace_key, | 146 replace_key, |
153 &optional_fields, | 147 rich_notification_data, |
154 delegate.get()); | 148 delegate.get()); |
155 | |
156 notification_manager->Add(ui_notification, profile); | 149 notification_manager->Add(ui_notification, profile); |
157 } else { | 150 } else { |
158 | 151 |
159 Notification ui_notification(GetOriginUrl(), | 152 Notification ui_notification(GetOriginUrl(), |
160 GetAppIconUrl(), | 153 GetAppIconUrl(), |
161 heading, | 154 heading, |
162 text, | 155 text, |
163 WebKit::WebTextDirectionDefault, | 156 WebKit::WebTextDirectionDefault, |
164 display_source, | 157 display_source, |
165 replace_key, | 158 replace_key, |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 int index) const { | 465 int index) const { |
473 if (specifics_.coalesced_notification().render_info().expanded_info(). | 466 if (specifics_.coalesced_notification().render_info().expanded_info(). |
474 collapsed_info_size() < index + 1) | 467 collapsed_info_size() < index + 1) |
475 return std::string(); | 468 return std::string(); |
476 | 469 |
477 return specifics_.coalesced_notification().render_info().expanded_info(). | 470 return specifics_.coalesced_notification().render_info().expanded_info(). |
478 collapsed_info(index).simple_collapsed_layout().description(); | 471 collapsed_info(index).simple_collapsed_layout().description(); |
479 } | 472 } |
480 | 473 |
481 } // namespace notifier | 474 } // namespace notifier |
OLD | NEW |