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. 4 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/strings/string16.h" 13 #include "base/values.h" 14 #include "chrome/browser/notifications/notification_delegate.h" 15 #include "third_party/WebKit/public/web/WebTextDirection.h" 16 #include "ui/message_center/notification.h" 17 #include "ui/message_center/notification_types.h" 18 #include "url/gurl.h" 19 20 namespace gfx { 21 class Image; 22 } 23 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 { 29 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( 42 message_center::NotificationType type, 43 const GURL& origin_url, 44 const base::string16& title, 45 const base::string16& body, 46 const gfx::Image& icon, 47 blink::WebTextDirection dir, 48 const message_center::NotifierId& notifier_id, 49 const base::string16& display_source, 50 const base::string16& replace_id, 51 const message_center::RichNotificationData& rich_notification_data, 52 NotificationDelegate* delegate); 53 54 Notification(const Notification& notification); 55 virtual ~Notification(); 56 Notification& operator=(const Notification& notification); 57 58 // The origin URL of the script which requested the notification. origin_url()59 const GURL& origin_url() const { return origin_url_; } 60 61 // A url for the icon to be shown (optional). icon_url()62 const GURL& icon_url() const { return icon_url_; } 63 64 // A unique identifier used to update (replace) or remove a notification. replace_id()65 const base::string16& replace_id() const { return replace_id_; } 66 67 // A url for the button icons to be shown (optional). button_one_icon_url()68 const GURL& button_one_icon_url() const { return button_one_icon_url_; } button_two_icon_url()69 const GURL& button_two_icon_url() const { return button_two_icon_url_; } 70 71 // A url for the image to be shown (optional). image_url()72 const GURL& image_url() const { return image_url_; } 73 74 // Id of the delegate embedded inside this instance. delegate_id()75 std::string delegate_id() const { return delegate()->id(); } 76 delegate()77 NotificationDelegate* delegate() const { return delegate_.get(); } 78 79 private: 80 // The Origin of the page/worker which created this notification. 81 GURL origin_url_; 82 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. 88 GURL button_one_icon_url_; 89 GURL button_two_icon_url_; 90 91 // The URL of a large image to be displayed for a a rich notification. 92 GURL image_url_; 93 94 // The user-supplied replace ID for the notification. 95 base::string16 replace_id_; 96 97 // A proxy object that allows access back to the JavaScript object that 98 // represents the notification, for firing events. 99 scoped_refptr<NotificationDelegate> delegate_; 100 }; 101 102 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 103