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 | 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 | 26 // data url converted from text + icon data. On Ash they are rendered as |
27 // formated text and icon data. | 27 // formated text and icon data. |
28 class Notification : public message_center::Notification { | 28 class Notification : public message_center::Notification { |
29 public: | 29 public: |
30 // Initializes a notification with text content. On non-ash platforms, this | 30 // Initializes a notification with text content and an icon image. |
31 // creates an HTML representation using a data: URL for display. | |
32 Notification(const GURL& origin_url, | |
33 const GURL& icon_url, | |
34 const base::string16& title, | |
35 const base::string16& body, | |
36 blink::WebTextDirection dir, | |
37 const base::string16& display_source, | |
38 const base::string16& replace_id, | |
39 NotificationDelegate* delegate); | |
40 | |
41 // Initializes a notification with text content and an icon image. Currently | |
42 // only used on Ash. Does not generate content_url_. | |
43 Notification(const GURL& origin_url, | 31 Notification(const GURL& origin_url, |
44 const gfx::Image& icon, | 32 const gfx::Image& icon, |
45 const base::string16& title, | 33 const base::string16& title, |
46 const base::string16& body, | 34 const base::string16& body, |
47 blink::WebTextDirection dir, | 35 blink::WebTextDirection dir, |
48 const base::string16& display_source, | 36 const base::string16& display_source, |
49 const base::string16& replace_id, | 37 const base::string16& replace_id, |
50 NotificationDelegate* delegate); | 38 NotificationDelegate* delegate); |
51 | 39 |
52 Notification( | 40 Notification( |
53 message_center::NotificationType type, | 41 message_center::NotificationType type, |
54 const GURL& origin_url, | 42 const GURL& origin_url, |
55 const base::string16& title, | 43 const base::string16& title, |
56 const base::string16& body, | 44 const base::string16& body, |
57 const gfx::Image& icon, | 45 const gfx::Image& icon, |
58 blink::WebTextDirection dir, | 46 blink::WebTextDirection dir, |
59 const message_center::NotifierId& notifier_id, | 47 const message_center::NotifierId& notifier_id, |
60 const base::string16& display_source, | 48 const base::string16& display_source, |
61 const base::string16& replace_id, | 49 const base::string16& replace_id, |
62 const message_center::RichNotificationData& rich_notification_data, | 50 const message_center::RichNotificationData& rich_notification_data, |
63 NotificationDelegate* delegate); | 51 NotificationDelegate* delegate); |
64 | 52 |
65 Notification(const Notification& notification); | 53 Notification(const Notification& notification); |
66 virtual ~Notification(); | 54 virtual ~Notification(); |
67 Notification& operator=(const Notification& notification); | 55 Notification& operator=(const Notification& notification); |
68 | 56 |
69 // The origin URL of the script which requested the notification. | 57 // The origin URL of the script which requested the notification. |
70 const GURL& origin_url() const { return origin_url_; } | 58 const GURL& origin_url() const { return origin_url_; } |
71 | 59 |
72 // A url for the icon to be shown (optional). | |
73 const GURL& icon_url() const { return icon_url_; } | |
74 | |
75 // A unique identifier used to update (replace) or remove a notification. | 60 // A unique identifier used to update (replace) or remove a notification. |
76 const base::string16& replace_id() const { return replace_id_; } | 61 const base::string16& replace_id() const { return replace_id_; } |
77 | 62 |
78 // A url for the button icons to be shown (optional). | 63 // A url for the button icons to be shown (optional). |
79 const GURL& button_one_icon_url() const { return button_one_icon_url_; } | 64 const GURL& button_one_icon_url() const { return button_one_icon_url_; } |
80 const GURL& button_two_icon_url() const { return button_two_icon_url_; } | 65 const GURL& button_two_icon_url() const { return button_two_icon_url_; } |
81 | 66 |
82 // A url for the image to be shown (optional). | 67 // A url for the image to be shown (optional). |
83 const GURL& image_url() const { return image_url_; } | 68 const GURL& image_url() const { return image_url_; } |
84 | 69 |
85 // Id of the delegate embedded inside this instance. | 70 // Id of the delegate embedded inside this instance. |
86 std::string delegate_id() const { return delegate()->id(); } | 71 std::string delegate_id() const { return delegate()->id(); } |
87 int process_id() const { return delegate()->process_id(); } | 72 int process_id() const { return delegate()->process_id(); } |
88 | 73 |
89 content::WebContents* GetWebContents() const { | 74 content::WebContents* GetWebContents() const { |
90 return delegate()->GetWebContents(); | 75 return delegate()->GetWebContents(); |
91 } | 76 } |
92 void DoneRendering() { delegate()->ReleaseRenderViewHost(); } | 77 void DoneRendering() { delegate()->ReleaseRenderViewHost(); } |
93 | 78 |
94 NotificationDelegate* delegate() const { return delegate_.get(); } | 79 NotificationDelegate* delegate() const { return delegate_.get(); } |
95 | 80 |
96 private: | 81 private: |
97 // The Origin of the page/worker which created this notification. | 82 // The Origin of the page/worker which created this notification. |
98 GURL origin_url_; | 83 GURL origin_url_; |
99 | 84 |
100 // URL for the icon associated with the notification. Requires delegate_ | |
101 // to have a non NULL RenderViewHost. | |
102 GURL icon_url_; | |
103 | |
104 // The URLs of the button images for a rich notification. | 85 // The URLs of the button images for a rich notification. |
105 GURL button_one_icon_url_; | 86 GURL button_one_icon_url_; |
106 GURL button_two_icon_url_; | 87 GURL button_two_icon_url_; |
107 | 88 |
108 // The URL of a large image to be displayed for a a rich notification. | 89 // The URL of a large image to be displayed for a a rich notification. |
109 GURL image_url_; | 90 GURL image_url_; |
110 | 91 |
111 // The URL of a small image to be displayed for a a rich notification. | 92 // The URL of a small image to be displayed for a a rich notification. |
112 GURL small_image_url_; | 93 GURL small_image_url_; |
113 | 94 |
114 // The user-supplied replace ID for the notification. | 95 // The user-supplied replace ID for the notification. |
115 base::string16 replace_id_; | 96 base::string16 replace_id_; |
116 | 97 |
117 // A proxy object that allows access back to the JavaScript object that | 98 // A proxy object that allows access back to the JavaScript object that |
118 // represents the notification, for firing events. | 99 // represents the notification, for firing events. |
119 scoped_refptr<NotificationDelegate> delegate_; | 100 scoped_refptr<NotificationDelegate> delegate_; |
120 }; | 101 }; |
121 | 102 |
122 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ | 103 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ |
OLD | NEW |