Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/ui/views/ash/balloon_view_ash.cc

Issue 11639041: Added support for image notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 BalloonHost* BalloonViewAsh::GetHost() const { 182 BalloonHost* BalloonViewAsh::GetHost() const {
183 return NULL; 183 return NULL;
184 } 184 }
185 185
186 void BalloonViewAsh::SetNotificationIcon(const std::string& id, 186 void BalloonViewAsh::SetNotificationIcon(const std::string& id,
187 const gfx::ImageSkia& image) { 187 const gfx::ImageSkia& image) {
188 GetMessageCenter()->SetNotificationPrimaryIcon(id, image); 188 GetMessageCenter()->SetNotificationPrimaryIcon(id, image);
189 } 189 }
190 190
191 void BalloonViewAsh::SetNotificationImage(const std::string& id,
192 const gfx::ImageSkia& image) {
193 GetMessageCenter()->SetNotificationImage(id, image);
194 }
195
191 void BalloonViewAsh::DownloadImages(const Notification& notification) { 196 void BalloonViewAsh::DownloadImages(const Notification& notification) {
192 // Cancel any previous downloads. 197 // Cancel any previous downloads.
193 downloads_.clear(); 198 downloads_.clear();
194 199
195 // Set the notification's primary icon, or set up a download for it. 200 // Set the notification's primary icon, or set up a download for it.
196 if (!notification.icon().isNull()) { 201 if (!notification.icon().isNull()) {
197 SetNotificationIcon(notification_id_, notification.icon()); 202 SetNotificationIcon(notification_id_, notification.icon());
198 } else if (!notification.icon_url().is_empty()) { 203 } else if (!notification.icon_url().is_empty()) {
199 GetImageDownload(notification.icon_url()).AddCallback( 204 GetImageDownload(notification.icon_url()).AddCallback(
200 message_center::kNotificationIconWidth, base::Bind( 205 message_center::kNotificationIconWidth, base::Bind(
201 &BalloonViewAsh::SetNotificationIcon, 206 &BalloonViewAsh::SetNotificationIcon,
202 base::Unretained(this))); 207 base::Unretained(this)));
203 } 208 }
204 209
210 // Set up a download for the notification's image if appropriate.
211 const base::DictionaryValue* optional_fields = notification.optional_fields();
212 if (optional_fields->HasKey(ui::notifications::kImageUrlKey)) {
213 string16 url;
214 optional_fields->GetString(ui::notifications::kImageUrlKey, &url);
215 if (!url.empty()) {
216 GetImageDownload(GURL(url)).AddCallback(
217 message_center::kNotificationPreferredImageSize, base::Bind(
218 &BalloonViewAsh::SetNotificationImage,
219 base::Unretained(this)));
220 }
221 }
222
205 // Start the downloads. 223 // Start the downloads.
206 for (ImageDownloads::const_iterator i = downloads_.begin(); 224 for (ImageDownloads::const_iterator i = downloads_.begin();
207 i != downloads_.end(); 225 i != downloads_.end();
208 ++i) { 226 ++i) {
209 i->second->Start(notification); 227 i->second->Start(notification);
210 } 228 }
211 } 229 }
212 230
213 BalloonViewAsh::ImageDownload& BalloonViewAsh::GetImageDownload( 231 BalloonViewAsh::ImageDownload& BalloonViewAsh::GetImageDownload(
214 const GURL& url) { 232 const GURL& url) {
215 if (!downloads_.count(url)) 233 if (!downloads_.count(url))
216 downloads_[url].reset(new ImageDownload(url)); 234 downloads_[url].reset(new ImageDownload(url));
217 return *downloads_[url]; 235 return *downloads_[url];
218 } 236 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698