Add ICU message format support
[chromium-blink-merge.git] / ui / message_center / notification.h
blob122cd6760629823e67d51cc789869a27269cad54
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_H_
6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_
8 #include <string>
9 #include <vector>
11 #include "base/strings/string16.h"
12 #include "base/time/time.h"
13 #include "base/values.h"
14 #include "ui/gfx/image/image.h"
15 #include "ui/message_center/message_center_export.h"
16 #include "ui/message_center/notification_delegate.h"
17 #include "ui/message_center/notification_types.h"
18 #include "ui/message_center/notifier_settings.h"
20 namespace message_center {
22 struct MESSAGE_CENTER_EXPORT NotificationItem {
23 base::string16 title;
24 base::string16 message;
26 NotificationItem(const base::string16& title, const base::string16& message);
29 struct MESSAGE_CENTER_EXPORT ButtonInfo {
30 base::string16 title;
31 gfx::Image icon;
33 ButtonInfo(const base::string16& title);
36 class MESSAGE_CENTER_EXPORT RichNotificationData {
37 public:
38 RichNotificationData();
39 RichNotificationData(const RichNotificationData& other);
40 ~RichNotificationData();
42 int priority;
43 bool never_timeout;
44 base::Time timestamp;
45 base::string16 context_message;
46 gfx::Image image;
47 gfx::Image small_image;
48 std::vector<NotificationItem> items;
49 int progress;
50 std::vector<ButtonInfo> buttons;
51 bool should_make_spoken_feedback_for_popup_updates;
52 bool clickable;
53 std::vector<int> vibration_pattern;
54 bool silent;
57 class MESSAGE_CENTER_EXPORT Notification {
58 public:
59 Notification(NotificationType type,
60 const std::string& id,
61 const base::string16& title,
62 const base::string16& message,
63 const gfx::Image& icon,
64 const base::string16& display_source,
65 const NotifierId& notifier_id,
66 const RichNotificationData& optional_fields,
67 NotificationDelegate* delegate);
69 Notification(const std::string& id, const Notification& other);
71 Notification(const Notification& other);
73 virtual ~Notification();
75 // Copies the internal on-memory state from |base|, i.e. shown_as_popup,
76 // is_read, and never_timeout.
77 void CopyState(Notification* base);
79 NotificationType type() const { return type_; }
80 void set_type(NotificationType type) { type_ = type; }
82 // Uniquely identifies a notification in the message center. For
83 // notification front ends that support multiple profiles, this id should
84 // identify a unique profile + frontend_notification_id combination. You can
85 // Use this id against the MessageCenter interface but not the
86 // NotificationUIManager interface.
87 const std::string& id() const { return id_; }
89 const base::string16& title() const { return title_; }
90 void set_title(const base::string16& title) { title_ = title; }
92 const base::string16& message() const { return message_; }
93 void set_message(const base::string16& message) { message_ = message; }
95 // A display string for the source of the notification.
96 const base::string16& display_source() const { return display_source_; }
98 const NotifierId& notifier_id() const { return notifier_id_; }
100 void set_profile_id(const std::string& profile_id) {
101 notifier_id_.profile_id = profile_id;
104 // Begin unpacked values from optional_fields.
105 int priority() const { return optional_fields_.priority; }
106 void set_priority(int priority) { optional_fields_.priority = priority; }
108 // This vibration_pattern property currently has no effect on
109 // non-Android platforms.
110 const std::vector<int>& vibration_pattern() const {
111 return optional_fields_.vibration_pattern;
113 void set_vibration_pattern(const std::vector<int>& vibration_pattern) {
114 optional_fields_.vibration_pattern = vibration_pattern;
117 // This property currently has no effect on non-Android platforms.
118 bool silent() const { return optional_fields_.silent; }
119 void set_silent(bool silent) { optional_fields_.silent = silent; }
121 base::Time timestamp() const { return optional_fields_.timestamp; }
122 void set_timestamp(const base::Time& timestamp) {
123 optional_fields_.timestamp = timestamp;
126 const base::string16& context_message() const {
127 return optional_fields_.context_message;
129 void set_context_message(const base::string16& context_message) {
130 optional_fields_.context_message = context_message;
133 const std::vector<NotificationItem>& items() const {
134 return optional_fields_.items;
136 void set_items(const std::vector<NotificationItem>& items) {
137 optional_fields_.items = items;
140 int progress() const { return optional_fields_.progress; }
141 void set_progress(int progress) { optional_fields_.progress = progress; }
142 // End unpacked values.
144 // Images fetched asynchronously.
145 const gfx::Image& icon() const { return icon_; }
146 void set_icon(const gfx::Image& icon) { icon_ = icon; }
148 const gfx::Image& image() const { return optional_fields_.image; }
149 void set_image(const gfx::Image& image) { optional_fields_.image = image; }
151 const gfx::Image& small_image() const { return optional_fields_.small_image; }
152 void set_small_image(const gfx::Image& image) {
153 optional_fields_.small_image = image;
156 // Buttons, with icons fetched asynchronously.
157 const std::vector<ButtonInfo>& buttons() const {
158 return optional_fields_.buttons;
160 void set_buttons(const std::vector<ButtonInfo>& buttons) {
161 optional_fields_.buttons = buttons;
163 void SetButtonIcon(size_t index, const gfx::Image& icon);
165 bool shown_as_popup() const { return shown_as_popup_; }
166 void set_shown_as_popup(bool shown_as_popup) {
167 shown_as_popup_ = shown_as_popup;
170 // Read status in the message center.
171 bool IsRead() const;
172 void set_is_read(bool read) { is_read_ = read; }
174 // Used to keep the order of notifications with the same timestamp.
175 // The notification with lesser serial_number is considered 'older'.
176 unsigned serial_number() { return serial_number_; }
178 // Marks this explicitly to prevent the timeout dismiss of notification.
179 // This is used by webkit notifications to keep the existing behavior.
180 void set_never_timeout(bool never_timeout) {
181 optional_fields_.never_timeout = never_timeout;
184 bool never_timeout() const { return optional_fields_.never_timeout; }
186 bool clickable() const { return optional_fields_.clickable; }
187 void set_clickable(bool clickable) {
188 optional_fields_.clickable = clickable;
191 NotificationDelegate* delegate() const { return delegate_.get(); }
193 const RichNotificationData& rich_notification_data() const {
194 return optional_fields_;
197 // Set the priority to SYSTEM. The system priority user needs to call this
198 // method explicitly, to avoid setting it accidentally.
199 void SetSystemPriority();
201 // Delegate actions.
202 void Display() const { delegate()->Display(); }
203 bool HasClickedListener() const { return delegate()->HasClickedListener(); }
204 void Click() const { delegate()->Click(); }
205 void ButtonClick(int index) const { delegate()->ButtonClick(index); }
206 void Close(bool by_user) const { delegate()->Close(by_user); }
208 // Helper method to create a simple system notification. |click_callback|
209 // will be invoked when the notification is clicked.
210 static scoped_ptr<Notification> CreateSystemNotification(
211 const std::string& notification_id,
212 const base::string16& title,
213 const base::string16& message,
214 const gfx::Image& icon,
215 const std::string& system_component_id,
216 const base::Closure& click_callback);
218 protected:
219 Notification& operator=(const Notification& other);
221 // The type of notification we'd like displayed.
222 NotificationType type_;
224 std::string id_;
225 base::string16 title_;
226 base::string16 message_;
228 // Image data for the associated icon, used by Ash when available.
229 gfx::Image icon_;
231 // The display string for the source of the notification. Could be
232 // the same as origin_url_, or the name of an extension.
233 base::string16 display_source_;
235 private:
236 NotifierId notifier_id_;
237 unsigned serial_number_;
238 RichNotificationData optional_fields_;
239 bool shown_as_popup_; // True if this has been shown as a popup.
240 bool is_read_; // True if this has been seen in the message center.
242 // A proxy object that allows access back to the JavaScript object that
243 // represents the notification, for firing events.
244 scoped_refptr<NotificationDelegate> delegate_;
247 } // namespace message_center
249 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_