Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: ui/message_center/notification.h

Issue 14631005: Enable users of NotificationUIManager to specify binary images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase for relanding. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/message_center/message_center_tray_unittest.cc ('k') | ui/message_center/notification.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 14 matching lines...) Expand all
25 NotificationItem(const string16& title, const string16& message); 25 NotificationItem(const string16& title, const string16& message);
26 }; 26 };
27 27
28 struct MESSAGE_CENTER_EXPORT ButtonInfo { 28 struct MESSAGE_CENTER_EXPORT ButtonInfo {
29 string16 title; 29 string16 title;
30 gfx::Image icon; 30 gfx::Image icon;
31 31
32 ButtonInfo(const string16& title); 32 ButtonInfo(const string16& title);
33 }; 33 };
34 34
35 class MESSAGE_CENTER_EXPORT RichNotificationData {
36 public:
37 RichNotificationData();
38 RichNotificationData(const RichNotificationData& other);
39 ~RichNotificationData();
40
41 int priority;
42 bool never_timeout;
43 base::Time timestamp;
44 string16 expanded_message;
45 gfx::Image image;
46 std::vector<NotificationItem> items;
47 std::vector<ButtonInfo> buttons;
48 };
49
35 class MESSAGE_CENTER_EXPORT Notification { 50 class MESSAGE_CENTER_EXPORT Notification {
36 public: 51 public:
37 Notification(NotificationType type, 52 Notification(NotificationType type,
38 const std::string& id, 53 const std::string& id,
39 const string16& title, 54 const string16& title,
40 const string16& message, 55 const string16& message,
56 const gfx::Image& icon,
41 const string16& display_source, 57 const string16& display_source,
42 const std::string& extension_id, 58 const std::string& extension_id,
43 const DictionaryValue* optional_fields, // May be NULL. 59 const DictionaryValue* optional_fields, // May be NULL.
44 NotificationDelegate* delegate); // May be NULL. 60 NotificationDelegate* delegate); // May be NULL.
61
62 Notification(NotificationType type,
63 const std::string& id,
64 const string16& title,
65 const string16& message,
66 const gfx::Image& icon,
67 const string16& display_source,
68 const std::string& extension_id,
69 const RichNotificationData& optional_fields,
70 NotificationDelegate* delegate);
71
72 Notification(const Notification& other);
73 Notification& operator=(const Notification& other);
45 virtual ~Notification(); 74 virtual ~Notification();
46 75
47 // Copies the internal on-memory state from |base|, i.e. shown_as_popup, 76 // Copies the internal on-memory state from |base|, i.e. shown_as_popup,
48 // is_read, is_expanded, and never_timeout. 77 // is_read, is_expanded, and never_timeout.
49 void CopyState(Notification* base); 78 void CopyState(Notification* base);
50 79
51 NotificationType type() const { return type_; } 80 NotificationType type() const { return type_; }
52 const std::string& id() const { return id_; } 81 const std::string& id() const { return id_; }
53 const string16& title() const { return title_; } 82 const string16& title() const { return title_; }
54 const string16& message() const { return message_; } 83 const string16& message() const { return message_; }
84
85 // A display string for the source of the notification.
55 const string16& display_source() const { return display_source_; } 86 const string16& display_source() const { return display_source_; }
56 const std::string& extension_id() const { return extension_id_; } 87 const std::string& extension_id() const { return extension_id_; }
88 void set_extension_id(const std::string& extension_id) {
89 extension_id_ = extension_id;
90 }
57 91
58 // Begin unpacked values from optional_fields. 92 // Begin unpacked values from optional_fields.
59 int priority() const { return priority_; } 93 int priority() const { return optional_fields_.priority; }
60 base::Time timestamp() const { return timestamp_; } 94 base::Time timestamp() const { return optional_fields_.timestamp; }
61 const string16& expanded_message() const { return expanded_message_; } 95 const string16& expanded_message() const {
62 const std::vector<NotificationItem>& items() const { return items_; } 96 return optional_fields_.expanded_message;
97 }
98 const std::vector<NotificationItem>& items() const {
99 return optional_fields_.items;
100 }
63 // End unpacked values. 101 // End unpacked values.
64 102
65 // Images fetched asynchronously. 103 // Images fetched asynchronously.
66 const gfx::Image& icon() const { return icon_; } 104 const gfx::Image& icon() const { return icon_; }
67 void set_icon(const gfx::Image& icon) { icon_ = icon; } 105 void set_icon(const gfx::Image& icon) { icon_ = icon; }
68 106
69 const gfx::Image& image() const { return image_; } 107 const gfx::Image& image() const { return optional_fields_.image; }
70 void set_image(const gfx::Image& image) { image_ = image; } 108 void set_image(const gfx::Image& image) { optional_fields_.image = image; }
71 109
72 // Buttons, with icons fetched asynchronously. 110 // Buttons, with icons fetched asynchronously.
73 const std::vector<ButtonInfo>& buttons() const { return buttons_; } 111 const std::vector<ButtonInfo>& buttons() const {
74 bool SetButtonIcon(size_t index, const gfx::Image& icon); 112 return optional_fields_.buttons;
113 }
114 void SetButtonIcon(size_t index, const gfx::Image& icon);
75 115
76 bool shown_as_popup() const { return shown_as_popup_; } 116 bool shown_as_popup() const { return shown_as_popup_; }
77 void set_shown_as_popup(bool shown_as_popup) { 117 void set_shown_as_popup(bool shown_as_popup) {
78 shown_as_popup_ = shown_as_popup; 118 shown_as_popup_ = shown_as_popup;
79 } 119 }
80 120
81 // Read status in the message center. 121 // Read status in the message center.
82 bool is_read() const { return is_read_; } 122 bool is_read() const { return is_read_; }
83 void set_is_read(bool read) { is_read_ = read; } 123 void set_is_read(bool read) { is_read_ = read; }
84 124
85 // Expanded status in the message center (not the popups). 125 // Expanded status in the message center (not the popups).
86 bool is_expanded() const { return is_expanded_; } 126 bool is_expanded() const { return is_expanded_; }
87 void set_is_expanded(bool expanded) { is_expanded_ = expanded; } 127 void set_is_expanded(bool expanded) { is_expanded_ = expanded; }
88 128
89 // Used to keep the order of notifications with the same timestamp. 129 // Used to keep the order of notifications with the same timestamp.
90 // The notification with lesser serial_number is considered 'older'. 130 // The notification with lesser serial_number is considered 'older'.
91 unsigned serial_number() { return serial_number_; } 131 unsigned serial_number() { return serial_number_; }
92 132
93 bool never_timeout() const { return never_timeout_; } 133 // Marks this explicitly to prevent the timeout dismiss of notification.
94 NotificationDelegate* delegate() { return delegate_.get(); } 134 // This is used by webkit notifications to keep the existing behavior.
135 void set_never_timeout(bool never_timeout) {
136 optional_fields_.never_timeout = never_timeout;
137 }
138
139 bool never_timeout() const { return optional_fields_.never_timeout; }
140 NotificationDelegate* delegate() const { return delegate_.get(); }
141 const RichNotificationData& rich_notification_data() const {
142 return optional_fields_;
143 }
144
145 // Delegate actions.
146 void Display() const { delegate()->Display(); }
147 void Error() const { delegate()->Error(); }
148 bool HasClickedListener() const { return delegate()->HasClickedListener(); }
149 void Click() const { delegate()->Click(); }
150 void ButtonClick(int index) const { delegate()->ButtonClick(index); }
151 void Close(bool by_user) const { delegate()->Close(by_user); }
152
153 protected:
154 // The type of notification we'd like displayed.
155 NotificationType type_;
156
157 std::string id_;
158 string16 title_;
159 string16 message_;
160
161 // Image data for the associated icon, used by Ash when available.
162 gfx::Image icon_;
163
164 // The display string for the source of the notification. Could be
165 // the same as origin_url_, or the name of an extension.
166 string16 display_source_;
95 167
96 private: 168 private:
97 // Unpacks the provided |optional_fields| and applies the values to override 169 // Unpacks the provided |optional_fields| and applies the values to override
98 // the notification's data members. 170 // the notification's data members.
99 void ApplyOptionalFields(const DictionaryValue* optional_fields); 171 void ApplyOptionalFields(const DictionaryValue* optional_fields);
100 172
101 NotificationType type_;
102 std::string id_;
103 string16 title_;
104 string16 message_;
105 string16 display_source_;
106 std::string extension_id_; 173 std::string extension_id_;
107 int priority_;
108 base::Time timestamp_;
109 unsigned serial_number_; 174 unsigned serial_number_;
110 string16 expanded_message_; 175 RichNotificationData optional_fields_;
111 std::vector<NotificationItem> items_;
112 gfx::Image icon_;
113 gfx::Image image_;
114 std::vector<ButtonInfo> buttons_;
115 bool shown_as_popup_; // True if this has been shown as a popup. 176 bool shown_as_popup_; // True if this has been shown as a popup.
116 bool is_read_; // True if this has been seen in the message center. 177 bool is_read_; // True if this has been seen in the message center.
117 bool is_expanded_; // True if this has been expanded in the message center. 178 bool is_expanded_; // True if this has been expanded in the message center.
118 bool never_timeout_; // True if it doesn't timeout when it appears as a toast.
119 179
120 // A proxy object that allows access back to the JavaScript object that 180 // A proxy object that allows access back to the JavaScript object that
121 // represents the notification, for firing events. 181 // represents the notification, for firing events.
122 scoped_refptr<NotificationDelegate> delegate_; 182 scoped_refptr<NotificationDelegate> delegate_;
123
124 DISALLOW_COPY_AND_ASSIGN(Notification);
125 }; 183 };
126 184
127 } // namespace message_center 185 } // namespace message_center
128 186
129 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ 187 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_
OLDNEW
« no previous file with comments | « ui/message_center/message_center_tray_unittest.cc ('k') | ui/message_center/notification.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698