Chromium Code Reviews| 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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 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 icon; | |
|
Jun Mukai
2013/05/31 17:08:10
Almost all notifications have icons, especially we
dewittj
2013/05/31 22:13:56
Not sure what you mean. Do you mean take out icon
| |
| 46 gfx::Image image; | |
| 47 std::vector<NotificationItem> items; | |
| 48 std::vector<ButtonInfo> buttons; | |
| 49 }; | |
| 50 | |
| 35 class MESSAGE_CENTER_EXPORT Notification { | 51 class MESSAGE_CENTER_EXPORT Notification { |
| 36 public: | 52 public: |
| 37 Notification(NotificationType type, | 53 Notification(NotificationType type, |
| 38 const std::string& id, | 54 const std::string& id, |
| 39 const string16& title, | 55 const string16& title, |
| 40 const string16& message, | 56 const string16& message, |
| 57 const gfx::Image& icon, | |
| 41 const string16& display_source, | 58 const string16& display_source, |
| 42 const std::string& extension_id, | 59 const std::string& extension_id, |
| 43 const DictionaryValue* optional_fields, // May be NULL. | 60 const DictionaryValue* optional_fields, // May be NULL. |
| 44 NotificationDelegate* delegate); // May be NULL. | 61 NotificationDelegate* delegate); // May be NULL. |
| 62 | |
| 63 Notification(NotificationType type, | |
| 64 const std::string& id, | |
| 65 const string16& title, | |
| 66 const string16& message, | |
| 67 const string16& display_source, | |
| 68 const std::string& extension_id, | |
| 69 const RichNotificationData& optional_fields, | |
| 70 NotificationDelegate* delegate); | |
| 45 virtual ~Notification(); | 71 virtual ~Notification(); |
| 46 | 72 |
| 47 // Copies the internal on-memory state from |base|, i.e. shown_as_popup, | 73 // Copies the internal on-memory state from |base|, i.e. shown_as_popup, |
| 48 // is_read, is_expanded, and never_timeout. | 74 // is_read, is_expanded, and never_timeout. |
| 49 void CopyState(Notification* base); | 75 void CopyState(Notification* base); |
| 50 | 76 |
| 51 NotificationType type() const { return type_; } | 77 NotificationType type() const { return type_; } |
| 52 const std::string& id() const { return id_; } | 78 const std::string& id() const { return id_; } |
| 53 const string16& title() const { return title_; } | 79 const string16& title() const { return title_; } |
| 54 const string16& message() const { return message_; } | 80 const string16& message() const { return message_; } |
| 55 const string16& display_source() const { return display_source_; } | 81 const string16& display_source() const { return display_source_; } |
| 56 const std::string& extension_id() const { return extension_id_; } | 82 const std::string& extension_id() const { return extension_id_; } |
| 57 | 83 |
| 58 // Begin unpacked values from optional_fields. | 84 // Begin unpacked values from optional_fields. |
| 59 int priority() const { return priority_; } | 85 int priority() const { return optional_fields_.priority; } |
| 60 base::Time timestamp() const { return timestamp_; } | 86 base::Time timestamp() const { return optional_fields_.timestamp; } |
| 61 const string16& expanded_message() const { return expanded_message_; } | 87 const string16& expanded_message() const { |
| 62 const std::vector<NotificationItem>& items() const { return items_; } | 88 return optional_fields_.expanded_message; |
| 89 } | |
| 90 const std::vector<NotificationItem>& items() const { | |
| 91 return optional_fields_.items; | |
| 92 } | |
| 63 // End unpacked values. | 93 // End unpacked values. |
| 64 | 94 |
| 65 // Images fetched asynchronously. | 95 // Images fetched asynchronously. |
| 66 const gfx::Image& icon() const { return icon_; } | 96 const gfx::Image& icon() const { return optional_fields_.icon; } |
| 67 void set_icon(const gfx::Image& icon) { icon_ = icon; } | 97 void set_icon(const gfx::Image& icon) { optional_fields_.icon = icon; } |
| 68 | 98 |
| 69 const gfx::Image& image() const { return image_; } | 99 const gfx::Image& image() const { return optional_fields_.image; } |
| 70 void set_image(const gfx::Image& image) { image_ = image; } | 100 void set_image(const gfx::Image& image) { optional_fields_.image = image; } |
| 71 | 101 |
| 72 // Buttons, with icons fetched asynchronously. | 102 // Buttons, with icons fetched asynchronously. |
| 73 const std::vector<ButtonInfo>& buttons() const { return buttons_; } | 103 const std::vector<ButtonInfo>& buttons() const { |
| 74 bool SetButtonIcon(size_t index, const gfx::Image& icon); | 104 return optional_fields_.buttons; |
| 105 } | |
| 106 void SetButtonIcon(size_t index, const gfx::Image& icon); | |
| 75 | 107 |
| 76 bool shown_as_popup() const { return shown_as_popup_; } | 108 bool shown_as_popup() const { return shown_as_popup_; } |
| 77 void set_shown_as_popup(bool shown_as_popup) { | 109 void set_shown_as_popup(bool shown_as_popup) { |
| 78 shown_as_popup_ = shown_as_popup; | 110 shown_as_popup_ = shown_as_popup; |
| 79 } | 111 } |
| 80 | 112 |
| 81 // Read status in the message center. | 113 // Read status in the message center. |
| 82 bool is_read() const { return is_read_; } | 114 bool is_read() const { return is_read_; } |
| 83 void set_is_read(bool read) { is_read_ = read; } | 115 void set_is_read(bool read) { is_read_ = read; } |
| 84 | 116 |
| 85 // Expanded status in the message center (not the popups). | 117 // Expanded status in the message center (not the popups). |
| 86 bool is_expanded() const { return is_expanded_; } | 118 bool is_expanded() const { return is_expanded_; } |
| 87 void set_is_expanded(bool expanded) { is_expanded_ = expanded; } | 119 void set_is_expanded(bool expanded) { is_expanded_ = expanded; } |
| 88 | 120 |
| 89 // Used to keep the order of notifications with the same timestamp. | 121 // Used to keep the order of notifications with the same timestamp. |
| 90 // The notification with lesser serial_number is considered 'older'. | 122 // The notification with lesser serial_number is considered 'older'. |
| 91 unsigned serial_number() { return serial_number_; } | 123 unsigned serial_number() { return serial_number_; } |
| 92 | 124 |
| 93 bool never_timeout() const { return never_timeout_; } | 125 bool never_timeout() const { return optional_fields_.never_timeout; } |
| 94 NotificationDelegate* delegate() { return delegate_.get(); } | 126 NotificationDelegate* delegate() { return delegate_.get(); } |
| 127 const RichNotificationData& optional_fields() { return optional_fields_; } | |
| 95 | 128 |
| 96 private: | 129 private: |
| 97 // Unpacks the provided |optional_fields| and applies the values to override | 130 // Unpacks the provided |optional_fields| and applies the values to override |
| 98 // the notification's data members. | 131 // the notification's data members. |
| 99 void ApplyOptionalFields(const DictionaryValue* optional_fields); | 132 void ApplyOptionalFields(const DictionaryValue* optional_fields); |
| 100 | 133 |
| 101 NotificationType type_; | 134 NotificationType type_; |
| 102 std::string id_; | 135 std::string id_; |
| 103 string16 title_; | 136 string16 title_; |
| 104 string16 message_; | 137 string16 message_; |
| 105 string16 display_source_; | 138 string16 display_source_; |
| 106 std::string extension_id_; | 139 std::string extension_id_; |
| 107 int priority_; | |
| 108 base::Time timestamp_; | |
| 109 unsigned serial_number_; | 140 unsigned serial_number_; |
| 110 string16 expanded_message_; | 141 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. | 142 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. | 143 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. | 144 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 | 145 |
| 120 // A proxy object that allows access back to the JavaScript object that | 146 // A proxy object that allows access back to the JavaScript object that |
| 121 // represents the notification, for firing events. | 147 // represents the notification, for firing events. |
| 122 scoped_refptr<NotificationDelegate> delegate_; | 148 scoped_refptr<NotificationDelegate> delegate_; |
| 123 | 149 |
| 124 DISALLOW_COPY_AND_ASSIGN(Notification); | 150 DISALLOW_COPY_AND_ASSIGN(Notification); |
| 125 }; | 151 }; |
| 126 | 152 |
| 127 } // namespace message_center | 153 } // namespace message_center |
| 128 | 154 |
| 129 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ | 155 #endif // UI_MESSAGE_CENTER_NOTIFICATION_H_ |
| OLD | NEW |