[Cronet] Handle redirects in CronetHttpURLConnection
[chromium-blink-merge.git] / ui / message_center / notification.h
blob4f913d79c6ed6560511f1e0ce6853d620c0ddfc9
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;
55 class MESSAGE_CENTER_EXPORT Notification {
56 public:
57 Notification(NotificationType type,
58 const std::string& id,
59 const base::string16& title,
60 const base::string16& message,
61 const gfx::Image& icon,
62 const base::string16& display_source,
63 const NotifierId& notifier_id,
64 const RichNotificationData& optional_fields,
65 NotificationDelegate* delegate);
67 Notification(const std::string& id, const Notification& other);
69 Notification(const Notification& other);
71 virtual ~Notification();
73 // Copies the internal on-memory state from |base|, i.e. shown_as_popup,
74 // is_read, and never_timeout.
75 void CopyState(Notification* base);
77 NotificationType type() const { return type_; }
78 void set_type(NotificationType type) { type_ = type; }
80 // Uniquely identifies a notification in the message center. For
81 // notification front ends that support multiple profiles, this id should
82 // identify a unique profile + frontend_notification_id combination. You can
83 // Use this id against the MessageCenter interface but not the
84 // NotificationUIManager interface.
85 const std::string& id() const { return id_; }
87 const base::string16& title() const { return title_; }
88 void set_title(const base::string16& title) { title_ = title; }
90 const base::string16& message() const { return message_; }
91 void set_message(const base::string16& message) { message_ = message; }
93 // A display string for the source of the notification.
94 const base::string16& display_source() const { return display_source_; }
96 const NotifierId& notifier_id() const { return notifier_id_; }
98 void set_profile_id(const std::string& profile_id) {
99 notifier_id_.profile_id = profile_id;
102 // Begin unpacked values from optional_fields.
103 int priority() const { return optional_fields_.priority; }
104 void set_priority(int priority) { optional_fields_.priority = priority; }
106 base::Time timestamp() const { return optional_fields_.timestamp; }
107 void set_timestamp(const base::Time& timestamp) {
108 optional_fields_.timestamp = timestamp;
111 const base::string16& context_message() const {
112 return optional_fields_.context_message;
114 void set_context_message(const base::string16& context_message) {
115 optional_fields_.context_message = context_message;
118 const std::vector<NotificationItem>& items() const {
119 return optional_fields_.items;
121 void set_items(const std::vector<NotificationItem>& items) {
122 optional_fields_.items = items;
125 int progress() const { return optional_fields_.progress; }
126 void set_progress(int progress) { optional_fields_.progress = progress; }
127 // End unpacked values.
129 // Images fetched asynchronously.
130 const gfx::Image& icon() const { return icon_; }
131 void set_icon(const gfx::Image& icon) { icon_ = icon; }
133 const gfx::Image& image() const { return optional_fields_.image; }
134 void set_image(const gfx::Image& image) { optional_fields_.image = image; }
136 const gfx::Image& small_image() const { return optional_fields_.small_image; }
137 void set_small_image(const gfx::Image& image) {
138 optional_fields_.small_image = image;
141 // Buttons, with icons fetched asynchronously.
142 const std::vector<ButtonInfo>& buttons() const {
143 return optional_fields_.buttons;
145 void set_buttons(const std::vector<ButtonInfo>& buttons) {
146 optional_fields_.buttons = buttons;
148 void SetButtonIcon(size_t index, const gfx::Image& icon);
150 bool shown_as_popup() const { return shown_as_popup_; }
151 void set_shown_as_popup(bool shown_as_popup) {
152 shown_as_popup_ = shown_as_popup;
155 // Read status in the message center.
156 bool IsRead() const;
157 void set_is_read(bool read) { is_read_ = read; }
159 // Used to keep the order of notifications with the same timestamp.
160 // The notification with lesser serial_number is considered 'older'.
161 unsigned serial_number() { return serial_number_; }
163 // Marks this explicitly to prevent the timeout dismiss of notification.
164 // This is used by webkit notifications to keep the existing behavior.
165 void set_never_timeout(bool never_timeout) {
166 optional_fields_.never_timeout = never_timeout;
169 bool never_timeout() const { return optional_fields_.never_timeout; }
171 bool clickable() const { return optional_fields_.clickable; }
172 void set_clickable(bool clickable) {
173 optional_fields_.clickable = clickable;
176 NotificationDelegate* delegate() const { return delegate_.get(); }
178 const RichNotificationData& rich_notification_data() const {
179 return optional_fields_;
182 // Set the priority to SYSTEM. The system priority user needs to call this
183 // method explicitly, to avoid setting it accidentally.
184 void SetSystemPriority();
186 // Delegate actions.
187 void Display() const { delegate()->Display(); }
188 bool HasClickedListener() const { return delegate()->HasClickedListener(); }
189 void Click() const { delegate()->Click(); }
190 void ButtonClick(int index) const { delegate()->ButtonClick(index); }
191 void Close(bool by_user) const { delegate()->Close(by_user); }
193 // Helper method to create a simple system notification. |click_callback|
194 // will be invoked when the notification is clicked.
195 static scoped_ptr<Notification> CreateSystemNotification(
196 const std::string& notification_id,
197 const base::string16& title,
198 const base::string16& message,
199 const gfx::Image& icon,
200 const std::string& system_component_id,
201 const base::Closure& click_callback);
203 protected:
204 Notification& operator=(const Notification& other);
206 // The type of notification we'd like displayed.
207 NotificationType type_;
209 std::string id_;
210 base::string16 title_;
211 base::string16 message_;
213 // Image data for the associated icon, used by Ash when available.
214 gfx::Image icon_;
216 // The display string for the source of the notification. Could be
217 // the same as origin_url_, or the name of an extension.
218 base::string16 display_source_;
220 private:
221 NotifierId notifier_id_;
222 unsigned serial_number_;
223 RichNotificationData optional_fields_;
224 bool shown_as_popup_; // True if this has been shown as a popup.
225 bool is_read_; // True if this has been seen in the message center.
227 // A proxy object that allows access back to the JavaScript object that
228 // represents the notification, for firing events.
229 scoped_refptr<NotificationDelegate> delegate_;
232 } // namespace message_center
234 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_