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/gfx/image/image.h" 17 #include "ui/message_center/notification.h" 18 #include "ui/message_center/notification_types.h" 19 #include "url/gurl.h" 20 21 // Representation of a notification to be shown to the user. 22 // On non-Ash platforms these are rendered as HTML, sometimes described by a 23 // data url converted from text + icon data. On Ash they are rendered as 24 // formated text and icon data. 25 class Notification : public message_center::Notification { 26 public: 27 // Initializes a notification with HTML content. 28 Notification(const GURL& origin_url, 29 const GURL& content_url, 30 const string16& display_source, 31 const string16& replace_id, 32 NotificationDelegate* delegate); 33 34 // Initializes a notification with text content. On non-ash platforms, this 35 // creates an HTML representation using a data: URL for display. 36 Notification(const GURL& origin_url, 37 const GURL& icon_url, 38 const string16& title, 39 const string16& body, 40 WebKit::WebTextDirection dir, 41 const string16& display_source, 42 const string16& replace_id, 43 NotificationDelegate* delegate); 44 45 // Initializes a notification with text content and an icon image. Currently 46 // only used on Ash. Does not generate content_url_. 47 Notification(const GURL& origin_url, 48 const gfx::Image& icon, 49 const string16& title, 50 const string16& body, 51 WebKit::WebTextDirection dir, 52 const string16& display_source, 53 const string16& replace_id, 54 NotificationDelegate* delegate); 55 56 Notification( 57 message_center::NotificationType type, 58 const GURL& origin_url, 59 const string16& title, 60 const string16& body, 61 const gfx::Image& icon, 62 WebKit::WebTextDirection dir, 63 const string16& display_source, 64 const string16& replace_id, 65 const message_center::RichNotificationData& rich_notification_data, 66 NotificationDelegate* delegate); 67 68 Notification(const Notification& notification); 69 virtual ~Notification(); 70 Notification& operator=(const Notification& notification); 71 72 // If this is a HTML notification. 73 bool is_html() const { return is_html_; } 74 75 // The URL (may be data:) containing the contents for the notification. 76 const GURL& content_url() const { return content_url_; } 77 78 // The origin URL of the script which requested the notification. 79 const GURL& origin_url() const { return origin_url_; } 80 81 // A url for the icon to be shown (optional). 82 const GURL& icon_url() const { return icon_url_; } 83 84 // A unique identifier used to update (replace) or remove a notification. 85 const string16& replace_id() const { return replace_id_; } 86 87 // A url for the button icons to be shown (optional). 88 const GURL& button_one_icon_url() const { return button_one_icon_url_; } 89 const GURL& button_two_icon_url() const { return button_two_icon_url_; } 90 91 // A url for the image to be shown (optional). 92 const GURL& image_url() const { return image_url_; } 93 94 std::string notification_id() const { return delegate()->id(); } 95 int process_id() const { return delegate()->process_id(); } 96 97 content::RenderViewHost* GetRenderViewHost() const { 98 return delegate()->GetRenderViewHost(); 99 } 100 void DoneRendering() { delegate()->ReleaseRenderViewHost(); } 101 102 NotificationDelegate* delegate() const { return delegate_.get(); } 103 104 private: 105 // The Origin of the page/worker which created this notification. 106 GURL origin_url_; 107 108 // URL for the icon associated with the notification. Requires delegate_ 109 // to have a non NULL RenderViewHost. 110 GURL icon_url_; 111 112 // If this is a HTML notification, the content is in |content_url_|. If 113 // false, the data is in |title_| and |message_|. 114 bool is_html_; 115 116 // The URL of the HTML content of the toast (may be a data: URL for simple 117 // string-based notifications). 118 GURL content_url_; 119 120 // The URLs of the button images for a rich notification. 121 GURL button_one_icon_url_; 122 GURL button_two_icon_url_; 123 124 // The URL of a large image to be displayed for a a rich notification. 125 GURL image_url_; 126 127 // The user-supplied replace ID for the notification. 128 string16 replace_id_; 129 130 // A proxy object that allows access back to the JavaScript object that 131 // represents the notification, for firing events. 132 scoped_refptr<NotificationDelegate> delegate_; 133 }; 134 135 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 136