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 #include "chrome/browser/notifications/notification.h" | 5 #include "chrome/browser/notifications/notification.h" |
6 | 6 |
| 7 #include "base/string_util.h" |
7 #include "chrome/browser/notifications/desktop_notification_service.h" | 8 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 9 #include "ui/message_center/message_center_util.h" |
| 10 #include "ui/webui/web_ui_util.h" |
8 | 11 |
9 Notification::Notification(const GURL& origin_url, | 12 Notification::Notification(const GURL& origin_url, |
10 const GURL& content_url, | 13 const GURL& content_url, |
11 const string16& display_source, | 14 const string16& display_source, |
12 const string16& replace_id, | 15 const string16& replace_id, |
13 NotificationDelegate* delegate) | 16 NotificationDelegate* delegate) |
14 : type_(message_center::NOTIFICATION_TYPE_SIMPLE), | 17 : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 18 delegate->id(), |
| 19 EmptyString16(), |
| 20 EmptyString16(), |
| 21 gfx::Image(), |
| 22 display_source, |
| 23 origin_url.spec(), |
| 24 NULL, |
| 25 delegate), |
15 origin_url_(origin_url), | 26 origin_url_(origin_url), |
16 is_html_(true), | 27 is_html_(true), |
17 content_url_(content_url), | 28 content_url_(content_url), |
18 display_source_(display_source), | |
19 replace_id_(replace_id), | 29 replace_id_(replace_id), |
20 delegate_(delegate) {} | 30 delegate_(delegate) {} |
21 | 31 |
22 Notification::Notification(const GURL& origin_url, | 32 Notification::Notification(const GURL& origin_url, |
23 const GURL& icon_url, | 33 const GURL& icon_url, |
24 const string16& title, | 34 const string16& title, |
25 const string16& body, | 35 const string16& body, |
26 WebKit::WebTextDirection dir, | 36 WebKit::WebTextDirection dir, |
27 const string16& display_source, | 37 const string16& display_source, |
28 const string16& replace_id, | 38 const string16& replace_id, |
29 NotificationDelegate* delegate) | 39 NotificationDelegate* delegate) |
30 : type_(message_center::NOTIFICATION_TYPE_SIMPLE), | 40 : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 41 delegate->id(), |
| 42 title, |
| 43 body, |
| 44 gfx::Image(), |
| 45 display_source, |
| 46 origin_url.spec(), |
| 47 NULL, |
| 48 delegate), |
31 origin_url_(origin_url), | 49 origin_url_(origin_url), |
32 icon_url_(icon_url), | 50 icon_url_(icon_url), |
33 is_html_(false), | 51 is_html_(false), |
34 title_(title), | |
35 body_(body), | |
36 display_source_(display_source), | |
37 replace_id_(replace_id), | 52 replace_id_(replace_id), |
38 delegate_(delegate) { | 53 delegate_(delegate) { |
39 // "Upconvert" the string parameters to a data: URL. | 54 // "Upconvert" the string parameters to a data: URL. |
40 content_url_ = GURL(DesktopNotificationService::CreateDataUrl( | 55 content_url_ = GURL(DesktopNotificationService::CreateDataUrl( |
41 icon_url, title, body, dir)); | 56 icon_url, title, body, dir)); |
42 } | 57 } |
43 | 58 |
44 Notification::Notification(message_center::NotificationType type, | 59 Notification::Notification(message_center::NotificationType type, |
45 const GURL& origin_url, | 60 const GURL& origin_url, |
46 const GURL& icon_url, | 61 const GURL& icon_url, |
47 const string16& title, | 62 const string16& title, |
48 const string16& body, | 63 const string16& body, |
49 WebKit::WebTextDirection dir, | 64 WebKit::WebTextDirection dir, |
50 const string16& display_source, | 65 const string16& display_source, |
51 const string16& replace_id, | 66 const string16& replace_id, |
52 const DictionaryValue* optional_fields, | 67 const DictionaryValue* optional_fields, |
53 NotificationDelegate* delegate) | 68 NotificationDelegate* delegate) |
54 : type_(type), | 69 : message_center::Notification(type, |
| 70 delegate->id(), |
| 71 title, |
| 72 body, |
| 73 gfx::Image(), |
| 74 display_source, |
| 75 origin_url.spec(), |
| 76 optional_fields, |
| 77 delegate), |
55 origin_url_(origin_url), | 78 origin_url_(origin_url), |
56 icon_url_(icon_url), | 79 icon_url_(icon_url), |
57 is_html_(false), | 80 is_html_(false), |
58 title_(title), | |
59 body_(body), | |
60 display_source_(display_source), | |
61 replace_id_(replace_id), | 81 replace_id_(replace_id), |
62 optional_fields_(NULL), | 82 optional_fields_(NULL), |
63 delegate_(delegate) { | 83 delegate_(delegate) { |
64 if (optional_fields) | 84 if (optional_fields) |
65 optional_fields_.reset(optional_fields->DeepCopy()); | 85 optional_fields_.reset(optional_fields->DeepCopy()); |
66 // "Upconvert" the string parameters to a data: URL. Some balloon views | 86 // "Upconvert" the string parameters to a data: URL. Some balloon views |
67 // require content URL to render anything, so this serves as a backup. | 87 // require content URL to render anything, so this serves as a backup. |
68 content_url_ = GURL(DesktopNotificationService::CreateDataUrl( | 88 content_url_ = GURL(DesktopNotificationService::CreateDataUrl( |
69 icon_url, title, body, dir)); | 89 icon_url, title, body, dir)); |
70 } | 90 } |
71 | 91 |
| 92 Notification::Notification( |
| 93 message_center::NotificationType type, |
| 94 const GURL& origin_url, |
| 95 const string16& title, |
| 96 const string16& body, |
| 97 const gfx::Image& icon, |
| 98 WebKit::WebTextDirection dir, |
| 99 const string16& display_source, |
| 100 const string16& replace_id, |
| 101 const message_center::RichNotificationData& rich_notification_data, |
| 102 NotificationDelegate* delegate) |
| 103 : message_center::Notification(type, |
| 104 delegate->id(), |
| 105 title, |
| 106 body, |
| 107 icon, |
| 108 display_source, |
| 109 origin_url.spec(), |
| 110 rich_notification_data, |
| 111 delegate), |
| 112 origin_url_(origin_url), |
| 113 is_html_(false), |
| 114 replace_id_(replace_id), |
| 115 delegate_(delegate) { |
| 116 if (!message_center::IsRichNotificationEnabled()) { |
| 117 // "Upconvert" the string parameters to a data: URL. Some balloon views |
| 118 // require content URL to render anything, so this serves as a backup. |
| 119 GURL icon_url; |
| 120 if (!icon.IsEmpty()) |
| 121 icon_url_ = GURL(webui::GetBitmapDataUrl(*icon.ToSkBitmap())); |
| 122 content_url_ = GURL( |
| 123 DesktopNotificationService::CreateDataUrl(icon_url, title, body, dir)); |
| 124 } |
| 125 } |
| 126 |
72 Notification::Notification(const GURL& origin_url, | 127 Notification::Notification(const GURL& origin_url, |
73 const gfx::Image& icon, | 128 const gfx::Image& icon, |
74 const string16& title, | 129 const string16& title, |
75 const string16& body, | 130 const string16& body, |
76 WebKit::WebTextDirection dir, | 131 WebKit::WebTextDirection dir, |
77 const string16& display_source, | 132 const string16& display_source, |
78 const string16& replace_id, | 133 const string16& replace_id, |
79 NotificationDelegate* delegate) | 134 NotificationDelegate* delegate) |
80 : type_(message_center::NOTIFICATION_TYPE_SIMPLE), | 135 : message_center::Notification(message_center::NOTIFICATION_TYPE_SIMPLE, |
| 136 delegate->id(), |
| 137 title, |
| 138 body, |
| 139 icon, |
| 140 display_source, |
| 141 origin_url.spec(), |
| 142 NULL, |
| 143 delegate), |
81 origin_url_(origin_url), | 144 origin_url_(origin_url), |
82 icon_(icon), | |
83 is_html_(false), | 145 is_html_(false), |
84 title_(title), | |
85 body_(body), | |
86 display_source_(display_source), | |
87 replace_id_(replace_id), | 146 replace_id_(replace_id), |
88 delegate_(delegate) {} | 147 delegate_(delegate) {} |
89 | 148 |
90 Notification::Notification(const Notification& notification) | 149 Notification::Notification(const Notification& notification) |
91 : type_(notification.type()), | 150 : message_center::Notification(notification), |
92 origin_url_(notification.origin_url()), | 151 origin_url_(notification.origin_url()), |
93 icon_(notification.icon()), | |
94 icon_url_(notification.icon_url()), | 152 icon_url_(notification.icon_url()), |
95 is_html_(notification.is_html()), | 153 is_html_(notification.is_html()), |
96 content_url_(notification.content_url()), | 154 content_url_(notification.content_url()), |
97 title_(notification.title()), | |
98 body_(notification.body()), | |
99 display_source_(notification.display_source()), | |
100 replace_id_(notification.replace_id()), | 155 replace_id_(notification.replace_id()), |
101 delegate_(notification.delegate()) { | 156 delegate_(notification.delegate()) { |
102 if (notification.optional_fields()) | 157 if (notification.optional_fields()) |
103 optional_fields_.reset(notification.optional_fields()->DeepCopy()); | 158 optional_fields_.reset(notification.optional_fields()->DeepCopy()); |
104 } | 159 } |
105 | 160 |
106 Notification::~Notification() {} | 161 Notification::~Notification() {} |
107 | 162 |
108 Notification& Notification::operator=(const Notification& notification) { | 163 Notification& Notification::operator=(const Notification& notification) { |
109 type_ = notification.type(); | 164 message_center::Notification::operator=(notification); |
110 origin_url_ = notification.origin_url(); | 165 origin_url_ = notification.origin_url(); |
111 icon_ = notification.icon_; | |
112 icon_url_ = notification.icon_url(); | 166 icon_url_ = notification.icon_url(); |
113 is_html_ = notification.is_html(); | 167 is_html_ = notification.is_html(); |
114 content_url_ = notification.content_url(); | 168 content_url_ = notification.content_url(); |
115 title_ = notification.title(); | |
116 body_ = notification.body(); | |
117 display_source_ = notification.display_source(); | |
118 replace_id_ = notification.replace_id(); | 169 replace_id_ = notification.replace_id(); |
119 if (notification.optional_fields()) | 170 if (notification.optional_fields()) |
120 optional_fields_.reset(notification.optional_fields()->DeepCopy()); | 171 optional_fields_.reset(notification.optional_fields()->DeepCopy()); |
121 else | 172 else |
122 optional_fields_.reset(); | 173 optional_fields_.reset(); |
123 delegate_ = notification.delegate(); | 174 delegate_ = notification.delegate(); |
124 return *this; | 175 return *this; |
125 } | 176 } |
126 | |
127 void Notification::DisableTimeout() { | |
128 if (!optional_fields_.get()) | |
129 optional_fields_.reset(new base::DictionaryValue()); | |
130 optional_fields_->SetBoolean(message_center::kPrivateNeverTimeoutKey, true); | |
131 } | |
OLD | NEW |