OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_H_ | 5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_H_ |
6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_ | 6 #define UI_MESSAGE_CENTER_NOTIFICATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
15 #include "ui/message_center/message_center_export.h" | 15 #include "ui/message_center/message_center_export.h" |
16 #include "ui/message_center/notification_delegate.h" | 16 #include "ui/message_center/notification_delegate.h" |
17 #include "ui/message_center/notification_types.h" | 17 #include "ui/message_center/notification_types.h" |
18 #include "ui/message_center/notifier_settings.h" | 18 #include "ui/message_center/notifier_settings.h" |
19 #include "url/gurl.h" | |
19 | 20 |
20 namespace message_center { | 21 namespace message_center { |
21 | 22 |
22 struct MESSAGE_CENTER_EXPORT NotificationItem { | 23 struct MESSAGE_CENTER_EXPORT NotificationItem { |
23 base::string16 title; | 24 base::string16 title; |
24 base::string16 message; | 25 base::string16 message; |
25 | 26 |
26 NotificationItem(const base::string16& title, const base::string16& message); | 27 NotificationItem(const base::string16& title, const base::string16& message); |
27 }; | 28 }; |
28 | 29 |
29 struct MESSAGE_CENTER_EXPORT ButtonInfo { | 30 struct MESSAGE_CENTER_EXPORT ButtonInfo { |
30 base::string16 title; | 31 base::string16 title; |
31 gfx::Image icon; | 32 gfx::Image icon; |
32 | 33 |
33 ButtonInfo(const base::string16& title); | 34 ButtonInfo(const base::string16& title); |
34 }; | 35 }; |
35 | 36 |
37 struct MESSAGE_CENTER_EXPORT ContextMessage { | |
38 ContextMessage(base::string16 msg, bool use_origin) | |
39 : message(msg), use_origin_as_context(use_origin) {} | |
40 base::string16 message; | |
41 bool use_origin_as_context; | |
Jun Mukai
2015/08/18 18:28:48
I really want to eliminate this flag (and the stru
Miguel Garcia
2015/08/19 15:02:59
Following our chat yesterday I implemented the cha
| |
42 }; | |
43 | |
36 class MESSAGE_CENTER_EXPORT RichNotificationData { | 44 class MESSAGE_CENTER_EXPORT RichNotificationData { |
37 public: | 45 public: |
38 RichNotificationData(); | 46 RichNotificationData(); |
39 RichNotificationData(const RichNotificationData& other); | 47 RichNotificationData(const RichNotificationData& other); |
40 ~RichNotificationData(); | 48 ~RichNotificationData(); |
41 | 49 |
42 int priority; | 50 int priority; |
43 bool never_timeout; | 51 bool never_timeout; |
44 base::Time timestamp; | 52 base::Time timestamp; |
45 base::string16 context_message; | 53 ContextMessage context_message; |
46 gfx::Image image; | 54 gfx::Image image; |
47 gfx::Image small_image; | 55 gfx::Image small_image; |
48 std::vector<NotificationItem> items; | 56 std::vector<NotificationItem> items; |
49 int progress; | 57 int progress; |
50 std::vector<ButtonInfo> buttons; | 58 std::vector<ButtonInfo> buttons; |
51 bool should_make_spoken_feedback_for_popup_updates; | 59 bool should_make_spoken_feedback_for_popup_updates; |
52 bool clickable; | 60 bool clickable; |
53 std::vector<int> vibration_pattern; | 61 std::vector<int> vibration_pattern; |
54 bool silent; | 62 bool silent; |
55 }; | 63 }; |
56 | 64 |
57 class MESSAGE_CENTER_EXPORT Notification { | 65 class MESSAGE_CENTER_EXPORT Notification { |
58 public: | 66 public: |
59 Notification(NotificationType type, | 67 Notification(NotificationType type, |
60 const std::string& id, | 68 const std::string& id, |
61 const base::string16& title, | 69 const base::string16& title, |
62 const base::string16& message, | 70 const base::string16& message, |
63 const gfx::Image& icon, | 71 const gfx::Image& icon, |
64 const base::string16& display_source, | 72 const base::string16& display_source, |
73 const GURL& origin_url, | |
65 const NotifierId& notifier_id, | 74 const NotifierId& notifier_id, |
66 const RichNotificationData& optional_fields, | 75 const RichNotificationData& optional_fields, |
67 NotificationDelegate* delegate); | 76 NotificationDelegate* delegate); |
68 | 77 |
69 Notification(const std::string& id, const Notification& other); | 78 Notification(const std::string& id, const Notification& other); |
70 | 79 |
71 Notification(const Notification& other); | 80 Notification(const Notification& other); |
72 | 81 |
73 virtual ~Notification(); | 82 virtual ~Notification(); |
74 | 83 |
(...skipping 10 matching lines...) Expand all Loading... | |
85 // Use this id against the MessageCenter interface but not the | 94 // Use this id against the MessageCenter interface but not the |
86 // NotificationUIManager interface. | 95 // NotificationUIManager interface. |
87 const std::string& id() const { return id_; } | 96 const std::string& id() const { return id_; } |
88 | 97 |
89 const base::string16& title() const { return title_; } | 98 const base::string16& title() const { return title_; } |
90 void set_title(const base::string16& title) { title_ = title; } | 99 void set_title(const base::string16& title) { title_ = title; } |
91 | 100 |
92 const base::string16& message() const { return message_; } | 101 const base::string16& message() const { return message_; } |
93 void set_message(const base::string16& message) { message_ = message; } | 102 void set_message(const base::string16& message) { message_ = message; } |
94 | 103 |
104 // The origin URL of the script which requested the notification. | |
105 // Can be empty if the notification is requested by an extension or | |
106 // Chrome app. | |
107 const GURL& origin_url() const { return origin_url_; } | |
108 | |
95 // A display string for the source of the notification. | 109 // A display string for the source of the notification. |
96 const base::string16& display_source() const { return display_source_; } | 110 const base::string16& display_source() const { return display_source_; } |
97 | 111 |
98 const NotifierId& notifier_id() const { return notifier_id_; } | 112 const NotifierId& notifier_id() const { return notifier_id_; } |
99 | 113 |
100 void set_profile_id(const std::string& profile_id) { | 114 void set_profile_id(const std::string& profile_id) { |
101 notifier_id_.profile_id = profile_id; | 115 notifier_id_.profile_id = profile_id; |
102 } | 116 } |
103 | 117 |
104 // Begin unpacked values from optional_fields. | 118 // Begin unpacked values from optional_fields. |
(...skipping 11 matching lines...) Expand all Loading... | |
116 | 130 |
117 // This property currently has no effect on non-Android platforms. | 131 // This property currently has no effect on non-Android platforms. |
118 bool silent() const { return optional_fields_.silent; } | 132 bool silent() const { return optional_fields_.silent; } |
119 void set_silent(bool silent) { optional_fields_.silent = silent; } | 133 void set_silent(bool silent) { optional_fields_.silent = silent; } |
120 | 134 |
121 base::Time timestamp() const { return optional_fields_.timestamp; } | 135 base::Time timestamp() const { return optional_fields_.timestamp; } |
122 void set_timestamp(const base::Time& timestamp) { | 136 void set_timestamp(const base::Time& timestamp) { |
123 optional_fields_.timestamp = timestamp; | 137 optional_fields_.timestamp = timestamp; |
124 } | 138 } |
125 | 139 |
126 const base::string16& context_message() const { | 140 const ContextMessage context_message() const { |
127 return optional_fields_.context_message; | 141 return optional_fields_.context_message; |
128 } | 142 } |
129 void set_context_message(const base::string16& context_message) { | 143 |
130 optional_fields_.context_message = context_message; | 144 void set_context_message(const base::string16& context_message, |
145 bool use_origin_as_context) { | |
146 optional_fields_.context_message.message = context_message; | |
147 optional_fields_.context_message.use_origin_as_context = | |
148 use_origin_as_context; | |
131 } | 149 } |
132 | 150 |
133 const std::vector<NotificationItem>& items() const { | 151 const std::vector<NotificationItem>& items() const { |
134 return optional_fields_.items; | 152 return optional_fields_.items; |
135 } | 153 } |
136 void set_items(const std::vector<NotificationItem>& items) { | 154 void set_items(const std::vector<NotificationItem>& items) { |
137 optional_fields_.items = items; | 155 optional_fields_.items = items; |
138 } | 156 } |
139 | 157 |
140 int progress() const { return optional_fields_.progress; } | 158 int progress() const { return optional_fields_.progress; } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 base::string16 message_; | 244 base::string16 message_; |
227 | 245 |
228 // Image data for the associated icon, used by Ash when available. | 246 // Image data for the associated icon, used by Ash when available. |
229 gfx::Image icon_; | 247 gfx::Image icon_; |
230 | 248 |
231 // The display string for the source of the notification. Could be | 249 // The display string for the source of the notification. Could be |
232 // the same as origin_url_, or the name of an extension. | 250 // the same as origin_url_, or the name of an extension. |
233 base::string16 display_source_; | 251 base::string16 display_source_; |
234 | 252 |
235 private: | 253 private: |
254 // The origin URL of the script which requested the notification. | |
255 // Can be empty if requested through a chrome app or extension or if | |
256 // it's a system notification. | |
257 GURL origin_url_; | |
236 NotifierId notifier_id_; | 258 NotifierId notifier_id_; |
237 unsigned serial_number_; | 259 unsigned serial_number_; |
238 RichNotificationData optional_fields_; | 260 RichNotificationData optional_fields_; |
239 bool shown_as_popup_; // True if this has been shown as a popup. | 261 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. | 262 bool is_read_; // True if this has been seen in the message center. |
241 | 263 |
242 // A proxy object that allows access back to the JavaScript object that | 264 // A proxy object that allows access back to the JavaScript object that |
243 // represents the notification, for firing events. | 265 // represents the notification, for firing events. |
244 scoped_refptr<NotificationDelegate> delegate_; | 266 scoped_refptr<NotificationDelegate> delegate_; |
245 }; | 267 }; |
246 | 268 |
247 } // namespace message_center | 269 } // namespace message_center |
248 | 270 |
249 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ | 271 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ |
OLD | NEW |