Fix build break
[chromium-blink-merge.git] / chrome / browser / notifications / notification.h
blobfd1c2a80a36e58a3d0a198bce9c0c97ecedaddd2
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/string16.h"
13 #include "base/values.h"
14 #include "chrome/browser/notifications/notification_delegate.h"
15 #include "googleurl/src/gurl.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
17 #include "ui/gfx/image/image.h"
18 #include "ui/message_center/notification_types.h"
20 // 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 // data url converted from text + icon data. On Ash they are rendered as
23 // formated text and icon data.
24 class Notification {
25 public:
26 // Initializes a notification with HTML content.
27 Notification(const GURL& origin_url,
28 const GURL& content_url,
29 const string16& display_source,
30 const string16& replace_id,
31 NotificationDelegate* delegate);
33 // Initializes a notification with text content. On non-ash platforms, this
34 // creates an HTML representation using a data: URL for display.
35 Notification(const GURL& origin_url,
36 const GURL& icon_url,
37 const string16& title,
38 const string16& body,
39 WebKit::WebTextDirection dir,
40 const string16& display_source,
41 const string16& replace_id,
42 NotificationDelegate* delegate);
44 // Initializes a notification with a given type. Makes a deep copy of
45 // optional_fields.
46 Notification(message_center::NotificationType type,
47 const GURL& origin_url,
48 const GURL& icon_url,
49 const string16& title,
50 const string16& body,
51 WebKit::WebTextDirection dir,
52 const string16& display_source,
53 const string16& replace_id,
54 const DictionaryValue* optional_fields,
55 NotificationDelegate* delegate);
57 // Initializes a notification with text content and an icon image. Currently
58 // only used on Ash. Does not generate content_url_.
59 Notification(const GURL& origin_url,
60 const gfx::Image& icon,
61 const string16& title,
62 const string16& body,
63 WebKit::WebTextDirection dir,
64 const string16& display_source,
65 const string16& replace_id,
66 NotificationDelegate* delegate);
68 Notification(const Notification& notification);
69 ~Notification();
70 Notification& operator=(const Notification& notification);
72 // If this is a HTML notification.
73 bool is_html() const { return is_html_; }
75 message_center::NotificationType type() const {
76 return type_;
79 // The URL (may be data:) containing the contents for the notification.
80 const GURL& content_url() const { return content_url_; }
82 // Title and message text of the notification.
83 const string16& title() const { return title_; }
84 const string16& body() const { return body_; }
86 // The origin URL of the script which requested the notification.
87 const GURL& origin_url() const { return origin_url_; }
89 // A url for the icon to be shown (optional).
90 const GURL& icon_url() const { return icon_url_; }
92 // An image for the icon to be shown (optional).
93 const gfx::Image& icon() const { return icon_; }
95 // A display string for the source of the notification.
96 const string16& display_source() const { return display_source_; }
98 // A unique identifier used to update (replace) or remove a notification.
99 const string16& replace_id() const { return replace_id_; }
101 const DictionaryValue* optional_fields() const {
102 return optional_fields_.get();
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();
109 void Display() const { delegate()->Display(); }
110 void Error() const { delegate()->Error(); }
111 void Click() const { delegate()->Click(); }
112 void ButtonClick(int index) const { delegate()->ButtonClick(index); }
113 void Close(bool by_user) const { delegate()->Close(by_user); }
115 std::string notification_id() const { return delegate()->id(); }
117 content::RenderViewHost* GetRenderViewHost() const {
118 return delegate()->GetRenderViewHost();
121 private:
122 NotificationDelegate* delegate() const { return delegate_.get(); }
124 // The type of notification we'd like displayed.
125 message_center::NotificationType type_;
127 // The Origin of the page/worker which created this notification.
128 GURL origin_url_;
130 // Image data for the associated icon, used by Ash when available.
131 gfx::Image icon_;
133 // URL for the icon associated with the notification. Requires delegate_
134 // to have a non NULL RenderViewHost.
135 GURL icon_url_;
137 // If this is a HTML notification, the content is in |content_url_|. If
138 // false, the data is in |title_| and |body_|.
139 bool is_html_;
141 // The URL of the HTML content of the toast (may be a data: URL for simple
142 // string-based notifications).
143 GURL content_url_;
145 // The content for a text notification.
146 string16 title_;
147 string16 body_;
149 // The display string for the source of the notification. Could be
150 // the same as origin_url_, or the name of an extension.
151 string16 display_source_;
153 // The replace ID for the notification.
154 string16 replace_id_;
156 scoped_ptr<DictionaryValue> optional_fields_;
158 // A proxy object that allows access back to the JavaScript object that
159 // represents the notification, for firing events.
160 scoped_refptr<NotificationDelegate> delegate_;
163 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_