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_
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
{
24 base::string16 message
;
26 NotificationItem(const base::string16
& title
, const base::string16
& message
);
29 struct MESSAGE_CENTER_EXPORT ButtonInfo
{
33 ButtonInfo(const base::string16
& title
);
36 class MESSAGE_CENTER_EXPORT RichNotificationData
{
38 RichNotificationData();
39 RichNotificationData(const RichNotificationData
& other
);
40 ~RichNotificationData();
45 base::string16 context_message
;
47 gfx::Image small_image
;
48 std::vector
<NotificationItem
> items
;
50 std::vector
<ButtonInfo
> buttons
;
51 bool should_make_spoken_feedback_for_popup_updates
;
56 class MESSAGE_CENTER_EXPORT Notification
{
58 Notification(NotificationType type
,
59 const std::string
& id
,
60 const base::string16
& title
,
61 const base::string16
& message
,
62 const gfx::Image
& icon
,
63 const base::string16
& display_source
,
64 const NotifierId
& notifier_id
,
65 const RichNotificationData
& optional_fields
,
66 NotificationDelegate
* delegate
);
68 Notification(const std::string
& id
, const Notification
& other
);
70 Notification(const Notification
& other
);
72 virtual ~Notification();
74 // Copies the internal on-memory state from |base|, i.e. shown_as_popup,
75 // is_read, and never_timeout.
76 void CopyState(Notification
* base
);
78 NotificationType
type() const { return type_
; }
79 void set_type(NotificationType type
) { type_
= type
; }
81 // Uniquely identifies a notification in the message center. For
82 // notification front ends that support multiple profiles, this id should
83 // identify a unique profile + frontend_notification_id combination. You can
84 // Use this id against the MessageCenter interface but not the
85 // NotificationUIManager interface.
86 const std::string
& id() const { return id_
; }
88 const base::string16
& title() const { return title_
; }
89 void set_title(const base::string16
& title
) { title_
= title
; }
91 const base::string16
& message() const { return message_
; }
92 void set_message(const base::string16
& message
) { message_
= message
; }
94 // A display string for the source of the notification.
95 const base::string16
& display_source() const { return display_source_
; }
97 const NotifierId
& notifier_id() const { return notifier_id_
; }
99 void set_profile_id(const std::string
& profile_id
) {
100 notifier_id_
.profile_id
= profile_id
;
103 // Begin unpacked values from optional_fields.
104 int priority() const { return optional_fields_
.priority
; }
105 void set_priority(int priority
) { optional_fields_
.priority
= priority
; }
107 // This property currently has no effect on non-Android platforms.
108 bool silent() const { return optional_fields_
.silent
; }
109 void set_silent(bool silent
) { optional_fields_
.silent
= silent
; }
111 base::Time
timestamp() const { return optional_fields_
.timestamp
; }
112 void set_timestamp(const base::Time
& timestamp
) {
113 optional_fields_
.timestamp
= timestamp
;
116 const base::string16
& context_message() const {
117 return optional_fields_
.context_message
;
119 void set_context_message(const base::string16
& context_message
) {
120 optional_fields_
.context_message
= context_message
;
123 const std::vector
<NotificationItem
>& items() const {
124 return optional_fields_
.items
;
126 void set_items(const std::vector
<NotificationItem
>& items
) {
127 optional_fields_
.items
= items
;
130 int progress() const { return optional_fields_
.progress
; }
131 void set_progress(int progress
) { optional_fields_
.progress
= progress
; }
132 // End unpacked values.
134 // Images fetched asynchronously.
135 const gfx::Image
& icon() const { return icon_
; }
136 void set_icon(const gfx::Image
& icon
) { icon_
= icon
; }
138 const gfx::Image
& image() const { return optional_fields_
.image
; }
139 void set_image(const gfx::Image
& image
) { optional_fields_
.image
= image
; }
141 const gfx::Image
& small_image() const { return optional_fields_
.small_image
; }
142 void set_small_image(const gfx::Image
& image
) {
143 optional_fields_
.small_image
= image
;
146 // Buttons, with icons fetched asynchronously.
147 const std::vector
<ButtonInfo
>& buttons() const {
148 return optional_fields_
.buttons
;
150 void set_buttons(const std::vector
<ButtonInfo
>& buttons
) {
151 optional_fields_
.buttons
= buttons
;
153 void SetButtonIcon(size_t index
, const gfx::Image
& icon
);
155 bool shown_as_popup() const { return shown_as_popup_
; }
156 void set_shown_as_popup(bool shown_as_popup
) {
157 shown_as_popup_
= shown_as_popup
;
160 // Read status in the message center.
162 void set_is_read(bool read
) { is_read_
= read
; }
164 // Used to keep the order of notifications with the same timestamp.
165 // The notification with lesser serial_number is considered 'older'.
166 unsigned serial_number() { return serial_number_
; }
168 // Marks this explicitly to prevent the timeout dismiss of notification.
169 // This is used by webkit notifications to keep the existing behavior.
170 void set_never_timeout(bool never_timeout
) {
171 optional_fields_
.never_timeout
= never_timeout
;
174 bool never_timeout() const { return optional_fields_
.never_timeout
; }
176 bool clickable() const { return optional_fields_
.clickable
; }
177 void set_clickable(bool clickable
) {
178 optional_fields_
.clickable
= clickable
;
181 NotificationDelegate
* delegate() const { return delegate_
.get(); }
183 const RichNotificationData
& rich_notification_data() const {
184 return optional_fields_
;
187 // Set the priority to SYSTEM. The system priority user needs to call this
188 // method explicitly, to avoid setting it accidentally.
189 void SetSystemPriority();
192 void Display() const { delegate()->Display(); }
193 bool HasClickedListener() const { return delegate()->HasClickedListener(); }
194 void Click() const { delegate()->Click(); }
195 void ButtonClick(int index
) const { delegate()->ButtonClick(index
); }
196 void Close(bool by_user
) const { delegate()->Close(by_user
); }
198 // Helper method to create a simple system notification. |click_callback|
199 // will be invoked when the notification is clicked.
200 static scoped_ptr
<Notification
> CreateSystemNotification(
201 const std::string
& notification_id
,
202 const base::string16
& title
,
203 const base::string16
& message
,
204 const gfx::Image
& icon
,
205 const std::string
& system_component_id
,
206 const base::Closure
& click_callback
);
209 Notification
& operator=(const Notification
& other
);
211 // The type of notification we'd like displayed.
212 NotificationType type_
;
215 base::string16 title_
;
216 base::string16 message_
;
218 // Image data for the associated icon, used by Ash when available.
221 // The display string for the source of the notification. Could be
222 // the same as origin_url_, or the name of an extension.
223 base::string16 display_source_
;
226 NotifierId notifier_id_
;
227 unsigned serial_number_
;
228 RichNotificationData optional_fields_
;
229 bool shown_as_popup_
; // True if this has been shown as a popup.
230 bool is_read_
; // True if this has been seen in the message center.
232 // A proxy object that allows access back to the JavaScript object that
233 // represents the notification, for firing events.
234 scoped_refptr
<NotificationDelegate
> delegate_
;
237 } // namespace message_center
239 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_