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/strings/string16.h" | 12 #include "base/strings/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 "third_party/WebKit/public/web/WebTextDirection.h" | 15 #include "third_party/WebKit/public/web/WebTextDirection.h" |
16 #include "ui/message_center/notification.h" | 16 #include "ui/message_center/notification.h" |
17 #include "ui/message_center/notification_types.h" | 17 #include "ui/message_center/notification_types.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 namespace gfx { | 20 namespace gfx { |
21 class Image; | 21 class Image; |
22 } | 22 } |
23 | 23 |
24 // Representation of a notification to be shown to the user. | 24 // Representation of a notification to be shown to the user. |
25 // On non-Ash platforms these are rendered as HTML, sometimes described by a | |
26 // data url converted from text + icon data. On Ash they are rendered as | |
27 // formated text and icon data. | |
28 class Notification : public message_center::Notification { | 25 class Notification : public message_center::Notification { |
29 public: | 26 public: |
30 // Initializes a notification with text content. On non-ash platforms, this | |
31 // creates an HTML representation using a data: URL for display. | |
32 Notification(const GURL& origin_url, | 27 Notification(const GURL& origin_url, |
33 const GURL& icon_url, | |
34 const base::string16& title, | 28 const base::string16& title, |
35 const base::string16& body, | 29 const base::string16& body, |
36 blink::WebTextDirection dir, | 30 const gfx::Image& icon, |
37 const base::string16& display_source, | 31 const base::string16& display_source, |
38 const base::string16& replace_id, | 32 const base::string16& replace_id, |
39 NotificationDelegate* delegate); | 33 NotificationDelegate* delegate); |
40 | 34 |
41 Notification( | 35 Notification( |
42 message_center::NotificationType type, | 36 message_center::NotificationType type, |
43 const GURL& origin_url, | 37 const GURL& origin_url, |
44 const base::string16& title, | 38 const base::string16& title, |
45 const base::string16& body, | 39 const base::string16& body, |
46 const gfx::Image& icon, | 40 const gfx::Image& icon, |
47 blink::WebTextDirection dir, | 41 blink::WebTextDirection dir, |
48 const message_center::NotifierId& notifier_id, | 42 const message_center::NotifierId& notifier_id, |
49 const base::string16& display_source, | 43 const base::string16& display_source, |
50 const base::string16& replace_id, | 44 const base::string16& replace_id, |
51 const message_center::RichNotificationData& rich_notification_data, | 45 const message_center::RichNotificationData& rich_notification_data, |
52 NotificationDelegate* delegate); | 46 NotificationDelegate* delegate); |
53 | 47 |
54 Notification(const Notification& notification); | 48 Notification(const Notification& notification); |
55 virtual ~Notification(); | 49 virtual ~Notification(); |
56 Notification& operator=(const Notification& notification); | 50 Notification& operator=(const Notification& notification); |
57 | 51 |
58 // The origin URL of the script which requested the notification. | 52 // The origin URL of the script which requested the notification. |
59 const GURL& origin_url() const { return origin_url_; } | 53 const GURL& origin_url() const { return origin_url_; } |
60 | 54 |
61 // A url for the icon to be shown (optional). | |
62 const GURL& icon_url() const { return icon_url_; } | |
63 | |
64 // A unique identifier used to update (replace) or remove a notification. | 55 // A unique identifier used to update (replace) or remove a notification. |
65 const base::string16& replace_id() const { return replace_id_; } | 56 const base::string16& replace_id() const { return replace_id_; } |
66 | 57 |
67 // A url for the button icons to be shown (optional). | 58 // A url for the button icons to be shown (optional). |
68 const GURL& button_one_icon_url() const { return button_one_icon_url_; } | 59 const GURL& button_one_icon_url() const { return button_one_icon_url_; } |
69 const GURL& button_two_icon_url() const { return button_two_icon_url_; } | 60 const GURL& button_two_icon_url() const { return button_two_icon_url_; } |
70 | 61 |
71 // A url for the image to be shown (optional). | 62 // A url for the image to be shown (optional). |
72 const GURL& image_url() const { return image_url_; } | 63 const GURL& image_url() const { return image_url_; } |
73 | 64 |
74 // Id of the delegate embedded inside this instance. | 65 // Id of the delegate embedded inside this instance. |
75 std::string delegate_id() const { return delegate()->id(); } | 66 std::string delegate_id() const { return delegate()->id(); } |
76 | 67 |
77 NotificationDelegate* delegate() const { return delegate_.get(); } | 68 NotificationDelegate* delegate() const { return delegate_.get(); } |
78 | 69 |
79 private: | 70 private: |
80 // The Origin of the page/worker which created this notification. | 71 // The Origin of the page/worker which created this notification. |
81 GURL origin_url_; | 72 GURL origin_url_; |
82 | 73 |
83 // URL for the icon associated with the notification. Requires delegate_ | |
84 // to have a non NULL RenderViewHost. | |
85 GURL icon_url_; | |
86 | |
87 // The URLs of the button images for a rich notification. | 74 // The URLs of the button images for a rich notification. |
88 GURL button_one_icon_url_; | 75 GURL button_one_icon_url_; |
89 GURL button_two_icon_url_; | 76 GURL button_two_icon_url_; |
90 | 77 |
91 // The URL of a large image to be displayed for a a rich notification. | 78 // The URL of a large image to be displayed for a a rich notification. |
92 GURL image_url_; | 79 GURL image_url_; |
93 | 80 |
94 // The user-supplied replace ID for the notification. | 81 // The user-supplied replace ID for the notification. |
95 base::string16 replace_id_; | 82 base::string16 replace_id_; |
96 | 83 |
97 // A proxy object that allows access back to the JavaScript object that | 84 // A proxy object that allows access back to the JavaScript object that |
98 // represents the notification, for firing events. | 85 // represents the notification, for firing events. |
99 scoped_refptr<NotificationDelegate> delegate_; | 86 scoped_refptr<NotificationDelegate> delegate_; |
100 }; | 87 }; |
101 | 88 |
102 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ | 89 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ |
OLD | NEW |