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

Side by Side Diff: chrome/browser/notifications/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
OLDNEW
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
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 // A url for the button icons to be shown (optional).
102 return optional_fields_.get(); 101 const GURL& button_one_icon_url() const { return button_one_icon_url_; }
103 } 102 const GURL& button_two_icon_url() const { return button_two_icon_url_; }
104 103
105 // Marks this explicitly to prevent the timeout dismiss of notification. 104 // A url for the image to be shown (optional).
106 // This is used by webkit notifications to keep the existing behavior. 105 const GURL& image_url() const { return image_url_; }
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 106
117 std::string notification_id() const { return delegate()->id(); } 107 std::string notification_id() const { return delegate()->id(); }
118
119 int process_id() const { return delegate()->process_id(); } 108 int process_id() const { return delegate()->process_id(); }
120 109
121 content::RenderViewHost* GetRenderViewHost() const { 110 content::RenderViewHost* GetRenderViewHost() const {
122 return delegate()->GetRenderViewHost(); 111 return delegate()->GetRenderViewHost();
123 } 112 }
113 void DoneRendering() { delegate()->ReleaseRenderViewHost(); }
124 114
125 NotificationDelegate* delegate() const { return delegate_.get(); } 115 NotificationDelegate* delegate() const { return delegate_.get(); }
126 116
127 private: 117 private:
128 // The type of notification we'd like displayed. 118 // Extracts optional URLs from a dictionary value.
129 message_center::NotificationType type_; 119 void ApplyOptionalFields(const DictionaryValue* optional_fields);
130 120
131 // The Origin of the page/worker which created this notification. 121 // The Origin of the page/worker which created this notification.
132 GURL origin_url_; 122 GURL origin_url_;
133 123
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_ 124 // URL for the icon associated with the notification. Requires delegate_
138 // to have a non NULL RenderViewHost. 125 // to have a non NULL RenderViewHost.
139 GURL icon_url_; 126 GURL icon_url_;
140 127
141 // If this is a HTML notification, the content is in |content_url_|. If 128 // If this is a HTML notification, the content is in |content_url_|. If
142 // false, the data is in |title_| and |body_|. 129 // false, the data is in |title_| and |message_|.
143 bool is_html_; 130 bool is_html_;
144 131
145 // The URL of the HTML content of the toast (may be a data: URL for simple 132 // The URL of the HTML content of the toast (may be a data: URL for simple
146 // string-based notifications). 133 // string-based notifications).
147 GURL content_url_; 134 GURL content_url_;
148 135
149 // The content for a text notification. 136 // The URLs of the button images for a rich notification.
150 string16 title_; 137 GURL button_one_icon_url_;
151 string16 body_; 138 GURL button_two_icon_url_;
152 139
153 // The display string for the source of the notification. Could be 140 // The URL of a large image to be displayed for a a rich notification.
154 // the same as origin_url_, or the name of an extension. 141 GURL image_url_;
155 string16 display_source_;
156 142
157 // The replace ID for the notification. 143 // The user-supplied replace ID for the notification.
158 string16 replace_id_; 144 string16 replace_id_;
159 145
160 scoped_ptr<DictionaryValue> optional_fields_;
161
162 // 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
163 // represents the notification, for firing events. 147 // represents the notification, for firing events.
164 scoped_refptr<NotificationDelegate> delegate_; 148 scoped_refptr<NotificationDelegate> delegate_;
165 }; 149 };
166 150
167 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 151 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
OLDNEW
« no previous file with comments | « chrome/browser/notifications/message_center_notifications_browsertest.cc ('k') | chrome/browser/notifications/notification.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698