| 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, | |
| 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 Notification( | 27 Notification( |
| 42 message_center::NotificationType type, | 28 message_center::NotificationType type, |
| 43 const GURL& origin_url, | 29 const GURL& origin_url, |
| 44 const base::string16& title, | 30 const base::string16& title, |
| 45 const base::string16& body, | 31 const base::string16& body, |
| 46 const gfx::Image& icon, | 32 const gfx::Image& icon, |
| 47 blink::WebTextDirection dir, | 33 blink::WebTextDirection dir, |
| 48 const message_center::NotifierId& notifier_id, | 34 const message_center::NotifierId& notifier_id, |
| 49 const base::string16& display_source, | 35 const base::string16& display_source, |
| 50 const base::string16& replace_id, | 36 const base::string16& replace_id, |
| 51 const message_center::RichNotificationData& rich_notification_data, | 37 const message_center::RichNotificationData& rich_notification_data, |
| 52 NotificationDelegate* delegate); | 38 NotificationDelegate* delegate); |
| 53 | 39 |
| 54 Notification(const Notification& notification); | 40 Notification(const Notification& notification); |
| 55 virtual ~Notification(); | 41 virtual ~Notification(); |
| 56 Notification& operator=(const Notification& notification); | 42 Notification& operator=(const Notification& notification); |
| 57 | 43 |
| 58 // The origin URL of the script which requested the notification. | 44 // The origin URL of the script which requested the notification. |
| 59 const GURL& origin_url() const { return origin_url_; } | 45 const GURL& origin_url() const { return origin_url_; } |
| 60 | 46 |
| 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. | 47 // A unique identifier used to update (replace) or remove a notification. |
| 65 const base::string16& replace_id() const { return replace_id_; } | 48 const base::string16& replace_id() const { return replace_id_; } |
| 66 | 49 |
| 67 // A url for the button icons to be shown (optional). | 50 // A url for the button icons to be shown (optional). |
| 68 const GURL& button_one_icon_url() const { return button_one_icon_url_; } | 51 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_; } | 52 const GURL& button_two_icon_url() const { return button_two_icon_url_; } |
| 70 | 53 |
| 71 // A url for the image to be shown (optional). | 54 // A url for the image to be shown (optional). |
| 72 const GURL& image_url() const { return image_url_; } | 55 const GURL& image_url() const { return image_url_; } |
| 73 | 56 |
| 74 // Id of the delegate embedded inside this instance. | 57 // Id of the delegate embedded inside this instance. |
| 75 std::string delegate_id() const { return delegate()->id(); } | 58 std::string delegate_id() const { return delegate()->id(); } |
| 76 | 59 |
| 77 content::WebContents* GetWebContents() const { | 60 content::WebContents* GetWebContents() const { |
| 78 return delegate()->GetWebContents(); | 61 return delegate()->GetWebContents(); |
| 79 } | 62 } |
| 80 void DoneRendering() { delegate()->ReleaseRenderViewHost(); } | 63 void DoneRendering() { delegate()->ReleaseRenderViewHost(); } |
| 81 | 64 |
| 82 NotificationDelegate* delegate() const { return delegate_.get(); } | 65 NotificationDelegate* delegate() const { return delegate_.get(); } |
| 83 | 66 |
| 84 private: | 67 private: |
| 85 // The Origin of the page/worker which created this notification. | 68 // The Origin of the page/worker which created this notification. |
| 86 GURL origin_url_; | 69 GURL origin_url_; |
| 87 | 70 |
| 88 // URL for the icon associated with the notification. Requires delegate_ | |
| 89 // to have a non NULL RenderViewHost. | |
| 90 GURL icon_url_; | |
| 91 | |
| 92 // The URLs of the button images for a rich notification. | 71 // The URLs of the button images for a rich notification. |
| 93 GURL button_one_icon_url_; | 72 GURL button_one_icon_url_; |
| 94 GURL button_two_icon_url_; | 73 GURL button_two_icon_url_; |
| 95 | 74 |
| 96 // The URL of a large image to be displayed for a a rich notification. | 75 // The URL of a large image to be displayed for a a rich notification. |
| 97 GURL image_url_; | 76 GURL image_url_; |
| 98 | 77 |
| 99 // The URL of a small image to be displayed for a a rich notification. | 78 // The URL of a small image to be displayed for a a rich notification. |
| 100 GURL small_image_url_; | 79 GURL small_image_url_; |
| 101 | 80 |
| 102 // The user-supplied replace ID for the notification. | 81 // The user-supplied replace ID for the notification. |
| 103 base::string16 replace_id_; | 82 base::string16 replace_id_; |
| 104 | 83 |
| 105 // 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 |
| 106 // represents the notification, for firing events. | 85 // represents the notification, for firing events. |
| 107 scoped_refptr<NotificationDelegate> delegate_; | 86 scoped_refptr<NotificationDelegate> delegate_; |
| 108 }; | 87 }; |
| 109 | 88 |
| 110 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ | 89 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ |
| OLD | NEW |