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/string16.h" | 11 #include "base/string16.h" |
12 #include "base/time.h" | 12 #include "base/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_types.h" | 17 #include "ui/message_center/notification_types.h" |
17 | 18 |
18 namespace message_center { | 19 namespace message_center { |
19 | 20 |
20 struct MESSAGE_CENTER_EXPORT NotificationItem { | 21 struct MESSAGE_CENTER_EXPORT NotificationItem { |
21 string16 title; | 22 string16 title; |
22 string16 message; | 23 string16 message; |
23 | 24 |
24 NotificationItem(const string16& title, const string16& message); | 25 NotificationItem(const string16& title, const string16& message); |
25 }; | 26 }; |
26 | 27 |
27 struct MESSAGE_CENTER_EXPORT ButtonInfo { | 28 struct MESSAGE_CENTER_EXPORT ButtonInfo { |
28 string16 title; | 29 string16 title; |
29 gfx::Image icon; | 30 gfx::Image icon; |
30 | 31 |
31 ButtonInfo(const string16& title); | 32 ButtonInfo(const string16& title); |
32 }; | 33 }; |
33 | 34 |
34 class MESSAGE_CENTER_EXPORT Notification { | 35 class MESSAGE_CENTER_EXPORT Notification { |
35 public: | 36 public: |
36 Notification(NotificationType type, | 37 Notification(NotificationType type, |
37 const std::string& id, | 38 const std::string& id, |
38 const string16& title, | 39 const string16& title, |
39 const string16& message, | 40 const string16& message, |
40 const string16& display_source, | 41 const string16& display_source, |
41 const std::string& extension_id, | 42 const std::string& extension_id, |
42 const DictionaryValue* optional_fields); // May be NULL. | 43 const DictionaryValue* optional_fields, // May be NULL. |
| 44 NotificationDelegate* delegate); // May be NULL. |
43 virtual ~Notification(); | 45 virtual ~Notification(); |
44 | 46 |
45 // Copies the internal on-memory state from |base|, i.e. shown_as_popup, | 47 // Copies the internal on-memory state from |base|, i.e. shown_as_popup, |
46 // is_read, is_expanded, and never_timeout. | 48 // is_read, is_expanded, and never_timeout. |
47 void CopyState(Notification* base); | 49 void CopyState(Notification* base); |
48 | 50 |
49 NotificationType type() const { return type_; } | 51 NotificationType type() const { return type_; } |
50 const std::string& id() const { return id_; } | 52 const std::string& id() const { return id_; } |
51 const string16& title() const { return title_; } | 53 const string16& title() const { return title_; } |
52 const string16& message() const { return message_; } | 54 const string16& message() const { return message_; } |
(...skipping 29 matching lines...) Expand all Loading... |
82 | 84 |
83 // Expanded status in the message center (not the popups). | 85 // Expanded status in the message center (not the popups). |
84 bool is_expanded() const { return is_expanded_; } | 86 bool is_expanded() const { return is_expanded_; } |
85 void set_is_expanded(bool expanded) { is_expanded_ = expanded; } | 87 void set_is_expanded(bool expanded) { is_expanded_ = expanded; } |
86 | 88 |
87 // Used to keep the order of notifications with the same timestamp. | 89 // Used to keep the order of notifications with the same timestamp. |
88 // The notification with lesser serial_number is considered 'older'. | 90 // The notification with lesser serial_number is considered 'older'. |
89 unsigned serial_number() { return serial_number_; } | 91 unsigned serial_number() { return serial_number_; } |
90 | 92 |
91 bool never_timeout() const { return never_timeout_; } | 93 bool never_timeout() const { return never_timeout_; } |
| 94 NotificationDelegate* delegate() { return delegate_.get(); } |
92 | 95 |
93 private: | 96 private: |
94 // Unpacks the provided |optional_fields| and applies the values to override | 97 // Unpacks the provided |optional_fields| and applies the values to override |
95 // the notification's data members. | 98 // the notification's data members. |
96 void ApplyOptionalFields(const DictionaryValue* optional_fields); | 99 void ApplyOptionalFields(const DictionaryValue* optional_fields); |
97 | 100 |
98 NotificationType type_; | 101 NotificationType type_; |
99 std::string id_; | 102 std::string id_; |
100 string16 title_; | 103 string16 title_; |
101 string16 message_; | 104 string16 message_; |
102 string16 display_source_; | 105 string16 display_source_; |
103 std::string extension_id_; | 106 std::string extension_id_; |
104 int priority_; | 107 int priority_; |
105 base::Time timestamp_; | 108 base::Time timestamp_; |
106 unsigned serial_number_; | 109 unsigned serial_number_; |
107 string16 expanded_message_; | 110 string16 expanded_message_; |
108 std::vector<NotificationItem> items_; | 111 std::vector<NotificationItem> items_; |
109 gfx::Image icon_; | 112 gfx::Image icon_; |
110 gfx::Image image_; | 113 gfx::Image image_; |
111 std::vector<ButtonInfo> buttons_; | 114 std::vector<ButtonInfo> buttons_; |
112 bool shown_as_popup_; // True if this has been shown as a popup. | 115 bool shown_as_popup_; // True if this has been shown as a popup. |
113 bool is_read_; // True if this has been seen in the message center. | 116 bool is_read_; // True if this has been seen in the message center. |
114 bool is_expanded_; // True if this has been expanded in the message center. | 117 bool is_expanded_; // True if this has been expanded in the message center. |
115 bool never_timeout_; // True if it doesn't timeout when it appears as a toast. | 118 bool never_timeout_; // True if it doesn't timeout when it appears as a toast. |
116 | 119 |
| 120 // A proxy object that allows access back to the JavaScript object that |
| 121 // represents the notification, for firing events. |
| 122 scoped_refptr<NotificationDelegate> delegate_; |
| 123 |
117 DISALLOW_COPY_AND_ASSIGN(Notification); | 124 DISALLOW_COPY_AND_ASSIGN(Notification); |
118 }; | 125 }; |
119 | 126 |
120 } // namespace message_center | 127 } // namespace message_center |
121 | 128 |
122 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ | 129 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ |
OLD | NEW |