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.
5 #include "chrome/browser/notifications/notification.h"
7 #include "base/strings/string_util.h"
8 #include "chrome/browser/notifications/desktop_notification_service.h"
9 #include "ui/base/webui/web_ui_util.h"
10 #include "ui/message_center/message_center_util.h"
12 Notification::Notification(const GURL& origin_url,
13 const GURL& content_url,
14 const string16& display_source,
15 const string16& replace_id,
16 NotificationDelegate* delegate)
17 : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
23 message_center::NotifierId(origin_url),
24 message_center::RichNotificationData(),
26 origin_url_(origin_url),
28 content_url_(content_url),
29 replace_id_(replace_id),
30 delegate_(delegate) {}
32 Notification::Notification(const GURL& origin_url,
34 const string16& title,
36 WebKit::WebTextDirection dir,
37 const string16& display_source,
38 const string16& replace_id,
39 NotificationDelegate* delegate)
40 : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
46 message_center::NotifierId(origin_url),
47 message_center::RichNotificationData(),
49 origin_url_(origin_url),
52 replace_id_(replace_id),
54 // "Upconvert" the string parameters to a data: URL.
55 content_url_ = GURL(DesktopNotificationService::CreateDataUrl(
56 icon_url, title, body, dir));
59 Notification::Notification(
60 message_center::NotificationType type,
61 const GURL& origin_url,
62 const string16& title,
64 const gfx::Image& icon,
65 WebKit::WebTextDirection dir,
66 const message_center::NotifierId& notifier_id,
67 const string16& display_source,
68 const string16& replace_id,
69 const message_center::RichNotificationData& rich_notification_data,
70 NotificationDelegate* delegate)
71 : message_center::Notification(type,
78 rich_notification_data,
80 origin_url_(origin_url),
82 replace_id_(replace_id),
84 // It's important to leave |icon_url_| empty with rich notifications enabled,
85 // to prevent "Downloading" the data url and overwriting the existing |icon|.
86 if (!message_center::IsRichNotificationEnabled()) {
87 // "Upconvert" the string parameters to a data: URL. Some balloon views
88 // require content URL to render anything, so this serves as a backup.
90 icon_url_ = GURL(webui::GetBitmapDataUrl(*icon.ToSkBitmap()));
92 DesktopNotificationService::CreateDataUrl(icon_url_, title, body, dir));
96 Notification::Notification(const GURL& origin_url,
97 const gfx::Image& icon,
98 const string16& title,
100 WebKit::WebTextDirection dir,
101 const string16& display_source,
102 const string16& replace_id,
103 NotificationDelegate* delegate)
104 : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE,
110 message_center::NotifierId(origin_url),
111 message_center::RichNotificationData(),
113 origin_url_(origin_url),
115 replace_id_(replace_id),
116 delegate_(delegate) {}
118 Notification::Notification(const Notification& notification)
119 : message_center::Notification(notification),
120 origin_url_(notification.origin_url()),
121 icon_url_(notification.icon_url()),
122 is_html_(notification.is_html()),
123 content_url_(notification.content_url()),
124 button_one_icon_url_(notification.button_one_icon_url()),
125 button_two_icon_url_(notification.button_two_icon_url()),
126 image_url_(notification.image_url()),
127 replace_id_(notification.replace_id()),
128 delegate_(notification.delegate()) {}
130 Notification::~Notification() {}
132 Notification& Notification::operator=(const Notification& notification) {
133 message_center::Notification::operator=(notification);
134 origin_url_ = notification.origin_url();
135 icon_url_ = notification.icon_url();
136 is_html_ = notification.is_html();
137 content_url_ = notification.content_url();
138 button_one_icon_url_ = notification.button_one_icon_url();
139 button_two_icon_url_ = notification.button_two_icon_url();
140 image_url_ = notification.image_url();
141 replace_id_ = notification.replace_id();
142 delegate_ = notification.delegate();