15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/values.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/notifications/notification_delegate.h" 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebTextDirection.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/gfx/image/image.h" 17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ui/message_center/notification.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/message_center/notification_types.h" 19eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Representation of a notification to be shown to the user. 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// On non-Ash platforms these are rendered as HTML, sometimes described by a 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// data url converted from text + icon data. On Ash they are rendered as 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// formated text and icon data. 25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)class Notification : public message_center::Notification { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes a notification with HTML content. 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Notification(const GURL& origin_url, 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& content_url, 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& display_source, 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& replace_id, 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NotificationDelegate* delegate); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes a notification with text content. On non-ash platforms, this 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // creates an HTML representation using a data: URL for display. 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Notification(const GURL& origin_url, 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& icon_url, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& title, 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& body, 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebKit::WebTextDirection dir, 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& display_source, 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& replace_id, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NotificationDelegate* delegate); 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes a notification with text content and an icon image. Currently 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // only used on Ash. Does not generate content_url_. 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Notification(const GURL& origin_url, 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Image& icon, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& title, 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& body, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebKit::WebTextDirection dir, 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& display_source, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& replace_id, 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NotificationDelegate* delegate); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) Notification( 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) message_center::NotificationType type, 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const GURL& origin_url, 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const string16& title, 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const string16& body, 61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const gfx::Image& icon, 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) WebKit::WebTextDirection dir, 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const string16& display_source, 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const string16& replace_id, 65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const message_center::RichNotificationData& rich_notification_data, 66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) NotificationDelegate* delegate); 67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Notification(const Notification& notification); 69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) virtual ~Notification(); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Notification& operator=(const Notification& notification); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this is a HTML notification. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_html() const { return is_html_; } 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The URL (may be data:) containing the contents for the notification. 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& content_url() const { return content_url_; } 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The origin URL of the script which requested the notification. 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& origin_url() const { return origin_url_; } 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A url for the icon to be shown (optional). 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& icon_url() const { return icon_url_; } 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A unique identifier used to update (replace) or remove a notification. 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const string16& replace_id() const { return replace_id_; } 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // A url for the button icons to be shown (optional). 88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const GURL& button_one_icon_url() const { return button_one_icon_url_; } 89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const GURL& button_two_icon_url() const { return button_two_icon_url_; } 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // A url for the image to be shown (optional). 92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const GURL& image_url() const { return image_url_; } 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string notification_id() const { return delegate()->id(); } 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) int process_id() const { return delegate()->process_id(); } 96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::RenderViewHost* GetRenderViewHost() const { 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return delegate()->GetRenderViewHost(); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void DoneRendering() { delegate()->ReleaseRenderViewHost(); } 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NotificationDelegate* delegate() const { return delegate_.get(); } 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The Origin of the page/worker which created this notification. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL origin_url_; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL for the icon associated with the notification. Requires delegate_ 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to have a non NULL RenderViewHost. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL icon_url_; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this is a HTML notification, the content is in |content_url_|. If 113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // false, the data is in |title_| and |message_|. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_html_; 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The URL of the HTML content of the toast (may be a data: URL for simple 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // string-based notifications). 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL content_url_; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The URLs of the button images for a rich notification. 121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GURL button_one_icon_url_; 122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GURL button_two_icon_url_; 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The URL of a large image to be displayed for a a rich notification. 125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) GURL image_url_; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) // The user-supplied replace ID for the notification. 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) string16 replace_id_; 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A proxy object that allows access back to the JavaScript object that 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // represents the notification, for firing events. 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<NotificationDelegate> delegate_; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_H_ 136