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/ui/views/ash/balloon_view_ash.h" | 5 #include "chrome/browser/ui/views/ash/balloon_view_ash.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/web_notification/web_notification_tray.h" | 8 #include "ash/system/web_notification/web_notification_tray.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/favicon/favicon_util.h" | 12 #include "chrome/browser/favicon/favicon_util.h" |
13 #include "chrome/browser/notifications/balloon_collection.h" | 13 #include "chrome/browser/notifications/balloon_collection.h" |
14 #include "chrome/browser/notifications/notification.h" | 14 #include "chrome/browser/notifications/notification.h" |
15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
16 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/site_instance.h" | 17 #include "content/public/browser/site_instance.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
20 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
21 #include "ipc/ipc_message.h" | 21 #include "ipc/ipc_message.h" |
22 #include "ipc/ipc_message_macros.h" | 22 #include "ipc/ipc_message_macros.h" |
23 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
24 #include "ui/message_center/message_center.h" | 24 #include "ui/message_center/message_center.h" |
| 25 #include "ui/message_center/message_center_constants.h" |
25 #include "webkit/glue/image_resource_fetcher.h" | 26 #include "webkit/glue/image_resource_fetcher.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 typedef base::Callback<void(const gfx::ImageSkia&)> SetImageCallback; | 30 typedef base::Callback<void(const gfx::ImageSkia&)> SetImageCallback; |
30 | 31 |
31 const int kPrimaryIconImageSize = 64; | 32 const int kPrimaryIconImageSize = 64; |
32 const int kSecondaryIconImageSize = 15; | 33 const int kSecondaryIconImageSize = 15; |
33 | 34 |
34 // static | 35 // static |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 154 } |
154 | 155 |
155 gfx::Size BalloonViewAsh::GetSize() const { | 156 gfx::Size BalloonViewAsh::GetSize() const { |
156 return gfx::Size(); | 157 return gfx::Size(); |
157 } | 158 } |
158 | 159 |
159 BalloonHost* BalloonViewAsh::GetHost() const { | 160 BalloonHost* BalloonViewAsh::GetHost() const { |
160 return NULL; | 161 return NULL; |
161 } | 162 } |
162 | 163 |
163 void BalloonViewAsh::SetNotificationPrimaryIcon(const std::string& id, | 164 void BalloonViewAsh::SetNotificationIcon(const std::string& id, |
164 const gfx::ImageSkia& image) { | 165 const gfx::ImageSkia& image) { |
165 GetMessageCenter()->SetNotificationPrimaryIcon(id, image); | 166 GetMessageCenter()->SetNotificationPrimaryIcon(id, image); |
166 } | 167 } |
167 | 168 |
168 void BalloonViewAsh::SetNotificationSecondaryIcon(const std::string& id, | |
169 const gfx::ImageSkia& image) { | |
170 GetMessageCenter()->SetNotificationSecondaryIcon(id, image); | |
171 } | |
172 | |
173 void BalloonViewAsh::DownloadImages(const Notification& notification) { | 169 void BalloonViewAsh::DownloadImages(const Notification& notification) { |
174 // Cancel any previous downloads. | 170 // Cancel any previous downloads. |
175 downloads_.clear(); | 171 downloads_.clear(); |
176 | 172 |
177 // Set the notification's primary icon, or start a download for it. | 173 // Set the notification's primary icon, or start a download for it. |
178 if (!notification.icon().isNull()) { | 174 if (!notification.icon().isNull()) { |
179 SetNotificationPrimaryIcon(notification_id_, notification.icon()); | 175 SetNotificationIcon(notification_id_, notification.icon()); |
180 } else if (!notification.icon_url().is_empty()) { | 176 } else if (!notification.icon_url().is_empty()) { |
181 downloads_.push_back(linked_ptr<ImageDownload>(new ImageDownload( | 177 downloads_.push_back(linked_ptr<ImageDownload>(new ImageDownload( |
182 notification, notification.icon_url(), kPrimaryIconImageSize, | 178 notification, notification.icon_url(), |
183 base::Bind(&BalloonViewAsh::SetNotificationPrimaryIcon, | 179 message_center::kNotificationIconWidth, |
| 180 base::Bind(&BalloonViewAsh::SetNotificationIcon, |
184 base::Unretained(this), notification.notification_id())))); | 181 base::Unretained(this), notification.notification_id())))); |
185 } | 182 } |
186 | |
187 // Start a download for the notification's secondary icon if appropriate. | |
188 const base::DictionaryValue* optional_fields = notification.optional_fields(); | |
189 if (optional_fields && | |
190 optional_fields->HasKey(ui::notifications::kSecondIconUrlKey)) { | |
191 string16 url; | |
192 optional_fields->GetString(ui::notifications::kSecondIconUrlKey, &url); | |
193 if (!url.empty()) { | |
194 downloads_.push_back(linked_ptr<ImageDownload>(new ImageDownload( | |
195 notification, GURL(url), kSecondaryIconImageSize, | |
196 base::Bind(&BalloonViewAsh::SetNotificationSecondaryIcon, | |
197 base::Unretained(this), notification.notification_id())))); | |
198 } | |
199 } | |
200 } | 183 } |
OLD | NEW |