OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/notifications/notification_delegate.h" | 14 #include "chrome/browser/notifications/notification_delegate.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" |
17 #include "ui/gfx/image/image.h" | 17 #include "ui/gfx/image/image.h" |
18 #include "ui/message_center/notification.h" | |
18 #include "ui/message_center/notification_types.h" | 19 #include "ui/message_center/notification_types.h" |
19 | 20 |
20 // Representation of a notification to be shown to the user. | 21 // Representation of a notification to be shown to the user. |
21 // On non-Ash platforms these are rendered as HTML, sometimes described by a | 22 // On non-Ash platforms these are rendered as HTML, sometimes described by a |
22 // data url converted from text + icon data. On Ash they are rendered as | 23 // data url converted from text + icon data. On Ash they are rendered as |
23 // formated text and icon data. | 24 // formated text and icon data. |
24 class Notification { | 25 class Notification : public message_center::Notification { |
25 public: | 26 public: |
26 // Initializes a notification with HTML content. | 27 // Initializes a notification with HTML content. |
27 Notification(const GURL& origin_url, | 28 Notification(const GURL& origin_url, |
28 const GURL& content_url, | 29 const GURL& content_url, |
29 const string16& display_source, | 30 const string16& display_source, |
30 const string16& replace_id, | 31 const string16& replace_id, |
31 NotificationDelegate* delegate); | 32 NotificationDelegate* delegate); |
32 | 33 |
33 // Initializes a notification with text content. On non-ash platforms, this | 34 // Initializes a notification with text content. On non-ash platforms, this |
34 // creates an HTML representation using a data: URL for display. | 35 // creates an HTML representation using a data: URL for display. |
(...skipping 23 matching lines...) Expand all Loading... | |
58 // only used on Ash. Does not generate content_url_. | 59 // only used on Ash. Does not generate content_url_. |
59 Notification(const GURL& origin_url, | 60 Notification(const GURL& origin_url, |
60 const gfx::Image& icon, | 61 const gfx::Image& icon, |
61 const string16& title, | 62 const string16& title, |
62 const string16& body, | 63 const string16& body, |
63 WebKit::WebTextDirection dir, | 64 WebKit::WebTextDirection dir, |
64 const string16& display_source, | 65 const string16& display_source, |
65 const string16& replace_id, | 66 const string16& replace_id, |
66 NotificationDelegate* delegate); | 67 NotificationDelegate* delegate); |
67 | 68 |
69 Notification( | |
70 message_center::NotificationType type, | |
71 const GURL& origin_url, | |
72 const string16& title, | |
73 const string16& body, | |
74 const gfx::Image& icon, | |
75 WebKit::WebTextDirection dir, | |
76 const string16& display_source, | |
77 const string16& replace_id, | |
78 const message_center::RichNotificationData& rich_notification_data, | |
79 NotificationDelegate* delegate); | |
80 | |
68 Notification(const Notification& notification); | 81 Notification(const Notification& notification); |
69 ~Notification(); | 82 virtual ~Notification(); |
70 Notification& operator=(const Notification& notification); | 83 Notification& operator=(const Notification& notification); |
71 | 84 |
72 // If this is a HTML notification. | 85 // If this is a HTML notification. |
73 bool is_html() const { return is_html_; } | 86 bool is_html() const { return is_html_; } |
74 | 87 |
75 message_center::NotificationType type() const { | |
76 return type_; | |
77 } | |
78 | |
79 // The URL (may be data:) containing the contents for the notification. | 88 // The URL (may be data:) containing the contents for the notification. |
80 const GURL& content_url() const { return content_url_; } | 89 const GURL& content_url() const { return content_url_; } |
81 | 90 |
82 // Title and message text of the notification. | |
83 const string16& title() const { return title_; } | |
84 const string16& body() const { return body_; } | |
85 | |
86 // The origin URL of the script which requested the notification. | 91 // The origin URL of the script which requested the notification. |
87 const GURL& origin_url() const { return origin_url_; } | 92 const GURL& origin_url() const { return origin_url_; } |
88 | 93 |
89 // A url for the icon to be shown (optional). | 94 // A url for the icon to be shown (optional). |
90 const GURL& icon_url() const { return icon_url_; } | 95 const GURL& icon_url() const { return icon_url_; } |
91 | 96 |
92 // An image for the icon to be shown (optional). | |
93 const gfx::Image& icon() const { return icon_; } | |
94 | |
95 // A display string for the source of the notification. | |
96 const string16& display_source() const { return display_source_; } | |
97 | |
98 // A unique identifier used to update (replace) or remove a notification. | 97 // A unique identifier used to update (replace) or remove a notification. |
99 const string16& replace_id() const { return replace_id_; } | 98 const string16& replace_id() const { return replace_id_; } |
100 | 99 |
101 const DictionaryValue* optional_fields() const { | 100 const DictionaryValue* optional_fields() const { |
102 return optional_fields_.get(); | 101 return optional_fields_.get(); |
103 } | 102 } |
104 | 103 |
105 // Marks this explicitly to prevent the timeout dismiss of notification. | |
106 // This is used by webkit notifications to keep the existing behavior. | |
107 void DisableTimeout(); | |
108 | |
109 void Display() const { delegate()->Display(); } | |
110 void Error() const { delegate()->Error(); } | |
111 bool HasClickedListener() const { return delegate()->HasClickedListener(); } | |
112 void Click() const { delegate()->Click(); } | |
113 void ButtonClick(int index) const { delegate()->ButtonClick(index); } | |
114 void Close(bool by_user) const { delegate()->Close(by_user); } | |
115 void DoneRendering() { delegate()->ReleaseRenderViewHost(); } | |
116 | |
117 std::string notification_id() const { return delegate()->id(); } | 104 std::string notification_id() const { return delegate()->id(); } |
118 | |
119 int process_id() const { return delegate()->process_id(); } | 105 int process_id() const { return delegate()->process_id(); } |
120 | 106 |
121 content::RenderViewHost* GetRenderViewHost() const { | 107 content::RenderViewHost* GetRenderViewHost() const { |
122 return delegate()->GetRenderViewHost(); | 108 return delegate()->GetRenderViewHost(); |
123 } | 109 } |
110 void DoneRendering() { delegate()->ReleaseRenderViewHost(); } | |
124 | 111 |
125 NotificationDelegate* delegate() const { return delegate_.get(); } | 112 NotificationDelegate* delegate() const { return delegate_.get(); } |
126 | 113 |
127 private: | 114 private: |
128 // The type of notification we'd like displayed. | |
129 message_center::NotificationType type_; | |
130 | |
131 // The Origin of the page/worker which created this notification. | 115 // The Origin of the page/worker which created this notification. |
132 GURL origin_url_; | 116 GURL origin_url_; |
133 | 117 |
134 // Image data for the associated icon, used by Ash when available. | |
135 gfx::Image icon_; | |
136 | |
137 // URL for the icon associated with the notification. Requires delegate_ | 118 // URL for the icon associated with the notification. Requires delegate_ |
138 // to have a non NULL RenderViewHost. | 119 // to have a non NULL RenderViewHost. |
139 GURL icon_url_; | 120 GURL icon_url_; |
140 | 121 |
141 // If this is a HTML notification, the content is in |content_url_|. If | 122 // If this is a HTML notification, the content is in |content_url_|. If |
142 // false, the data is in |title_| and |body_|. | 123 // false, the data is in |title_| and |message_|. |
143 bool is_html_; | 124 bool is_html_; |
144 | 125 |
145 // The URL of the HTML content of the toast (may be a data: URL for simple | 126 // The URL of the HTML content of the toast (may be a data: URL for simple |
146 // string-based notifications). | 127 // string-based notifications). |
147 GURL content_url_; | 128 GURL content_url_; |
148 | 129 |
149 // The content for a text notification. | 130 // The user-supplied replace ID for the notification. |
150 string16 title_; | |
151 string16 body_; | |
152 | |
153 // The display string for the source of the notification. Could be | |
154 // the same as origin_url_, or the name of an extension. | |
155 string16 display_source_; | |
156 | |
157 // The replace ID for the notification. | |
158 string16 replace_id_; | 131 string16 replace_id_; |
159 | 132 |
133 // Contains URLs for optional images. | |
Jun Mukai
2013/06/02 21:21:23
This comment doesn't sound correct, it still conta
dewittj
2013/06/03 17:32:26
Did one better and just saved all the items separa
| |
160 scoped_ptr<DictionaryValue> optional_fields_; | 134 scoped_ptr<DictionaryValue> optional_fields_; |
161 | 135 |
162 // A proxy object that allows access back to the JavaScript object that | 136 // A proxy object that allows access back to the JavaScript object that |
163 // represents the notification, for firing events. | 137 // represents the notification, for firing events. |
164 scoped_refptr<NotificationDelegate> delegate_; | 138 scoped_refptr<NotificationDelegate> delegate_; |
165 }; | 139 }; |
166 | 140 |
167 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ | 141 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ |
OLD | NEW |