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

Side by Side Diff: chrome/browser/download/notification/download_notification_item.cc

Issue 1159363002: [Download Notification] Show preview if downloaded file is image (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adressed comment #10 Created 5 years, 6 months 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/download/notification/download_notification_item.h" 5 #include "chrome/browser/download/notification/download_notification_item.h"
6 6
7 #include "base/files/file_util.h"
7 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
8 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/download/download_crx_util.h" 10 #include "chrome/browser/download/download_crx_util.h"
10 #include "chrome/browser/download/download_item_model.h" 11 #include "chrome/browser/download/download_item_model.h"
11 #include "chrome/browser/notifications/notification.h" 12 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/notifications/notification_ui_manager.h" 13 #include "chrome/browser/notifications/notification_ui_manager.h"
13 #include "chrome/browser/notifications/profile_notification.h" 14 #include "chrome/browser/notifications/profile_notification.h"
14 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "chrome/grit/chromium_strings.h" 17 #include "chrome/grit/chromium_strings.h"
17 #include "chrome/grit/generated_resources.h" 18 #include "chrome/grit/generated_resources.h"
19 #include "components/mime_util/mime_util.h"
18 #include "content/public/browser/browser_context.h" 20 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/download_interrupt_reasons.h" 22 #include "content/public/browser/download_interrupt_reasons.h"
21 #include "content/public/browser/download_item.h" 23 #include "content/public/browser/download_item.h"
22 #include "content/public/browser/page_navigator.h" 24 #include "content/public/browser/page_navigator.h"
23 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
24 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
27 #include "net/base/mime_util.h"
28 #include "third_party/skia/include/core/SkBitmap.h"
asanka 2015/06/11 03:30:51 Nit: Already included in download_notification_ite
yoshiki 2015/06/11 08:22:09 Done.
25 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/codec/jpeg_codec.h"
32 #include "ui/gfx/image/image.h"
27 #include "ui/message_center/message_center.h" 33 #include "ui/message_center/message_center.h"
28 34
29 namespace { 35 namespace {
30 36
31 const char kDownloadNotificationNotifierId[] = 37 const char kDownloadNotificationNotifierId[] =
32 "chrome://downloads/notification/id-notifier"; 38 "chrome://downloads/notification/id-notifier";
33 39
40 // Maximum size of preview image. If the image exceeds this size, don't show the
41 // preview image.
42 const int64 kMaxImagePreviewSize = 10 * 1024 * 1024; // 10 MB
43
34 } // anonymous namespace 44 } // anonymous namespace
35 45
36 // static 46 // static
37 const char DownloadNotificationItem::kDownloadNotificationOrigin[] = 47 const char DownloadNotificationItem::kDownloadNotificationOrigin[] =
38 "chrome://downloads"; 48 "chrome://downloads";
39 49
40 // static 50 // static
41 StubNotificationUIManager* 51 StubNotificationUIManager*
42 DownloadNotificationItem::stub_notification_ui_manager_for_testing_ = 52 DownloadNotificationItem::stub_notification_ui_manager_for_testing_ =
43 nullptr; 53 nullptr;
44 54
45 DownloadNotificationItem::NotificationWatcher::NotificationWatcher( 55 DownloadNotificationItem::NotificationWatcher::NotificationWatcher(
46 DownloadNotificationItem* item) 56 DownloadNotificationItem* item)
47 : item_(item) { 57 : item_(item) {
48 } 58 }
49 59
50 DownloadNotificationItem::NotificationWatcher::~NotificationWatcher() { 60 DownloadNotificationItem::NotificationWatcher::~NotificationWatcher() {
51 } 61 }
52 62
53 void DownloadNotificationItem::NotificationWatcher::Close(bool by_user) { 63 void DownloadNotificationItem::NotificationWatcher::Close(bool by_user) {
54 // Do nothing. 64 item_->OnNotificationClose(by_user);
55 } 65 }
56 66
57 void DownloadNotificationItem::NotificationWatcher::Click() { 67 void DownloadNotificationItem::NotificationWatcher::Click() {
58 item_->OnNotificationClick(); 68 item_->OnNotificationClick();
59 } 69 }
60 70
61 bool DownloadNotificationItem::NotificationWatcher::HasClickedListener() { 71 bool DownloadNotificationItem::NotificationWatcher::HasClickedListener() {
62 return true; 72 return true;
63 } 73 }
64 74
65 void DownloadNotificationItem::NotificationWatcher::ButtonClick( 75 void DownloadNotificationItem::NotificationWatcher::ButtonClick(
66 int button_index) { 76 int button_index) {
67 item_->OnNotificationButtonClick(button_index); 77 item_->OnNotificationButtonClick(button_index);
68 } 78 }
69 79
70 std::string DownloadNotificationItem::NotificationWatcher::id() const { 80 std::string DownloadNotificationItem::NotificationWatcher::id() const {
71 return base::UintToString(item_->item_->GetId()); 81 return base::UintToString(item_->item_->GetId());
72 } 82 }
73 83
74 DownloadNotificationItem::DownloadNotificationItem(content::DownloadItem* item, 84 DownloadNotificationItem::DownloadNotificationItem(content::DownloadItem* item,
75 Profile* profile, 85 Profile* profile,
76 Delegate* delegate) 86 Delegate* delegate)
77 : profile_(profile), 87 : profile_(profile),
78 watcher_(new NotificationWatcher(this)), 88 watcher_(new NotificationWatcher(this)),
79 item_(item), 89 item_(item),
80 delegate_(delegate) { 90 delegate_(delegate),
91 weak_factory_(this) {
81 item->AddObserver(this); 92 item->AddObserver(this);
82 93
83 // Notify that the instance is just created. 94 // Notify that the instance is just created.
84 delegate_->OnCreated(this); 95 delegate_->OnCreated(this);
85 96
86 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 97 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
87 98
88 message_center::RichNotificationData data; 99 message_center::RichNotificationData data;
89 // Creates the notification instance. |title| and |body| will be overridden 100 // Creates the notification instance. |title| and |body| will be overridden
90 // by UpdateNotificationData() below. 101 // by UpdateNotificationData() below.
91 notification_.reset(new Notification( 102 notification_.reset(new Notification(
92 message_center::NOTIFICATION_TYPE_PROGRESS, 103 message_center::NOTIFICATION_TYPE_PROGRESS,
93 GURL(kDownloadNotificationOrigin), // origin_url 104 GURL(kDownloadNotificationOrigin), // origin_url
94 base::string16(), // title 105 base::string16(), // title
95 base::string16(), // body 106 base::string16(), // body
96 bundle.GetImageNamed(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING), 107 bundle.GetImageNamed(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING),
97 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 108 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
98 kDownloadNotificationNotifierId), 109 kDownloadNotificationNotifierId),
99 base::string16(), // display_source 110 base::string16(), // display_source
100 base::UintToString(item_->GetId()), // tag 111 base::UintToString(item_->GetId()), // tag
101 data, watcher_.get())); 112 data, watcher_.get()));
102 113
103 notification_->set_progress(0); 114 notification_->set_progress(0);
104 notification_->set_never_timeout(false); 115 notification_->set_never_timeout(false);
105 116
106 UpdateNotificationData(ADD_NEW); 117 UpdateNotificationData(ADD_NEW);
107 } 118 }
108 119
109 DownloadNotificationItem::~DownloadNotificationItem() { 120 DownloadNotificationItem::~DownloadNotificationItem() {
asanka 2015/06/11 03:30:51 It seems OnNotificationClose() must always be rece
yoshiki 2015/06/11 08:22:09 Done.
110 if (item_) 121 if (item_)
111 item_->RemoveObserver(this); 122 item_->RemoveObserver(this);
112 } 123 }
113 124
114 void DownloadNotificationItem::OnNotificationClick() { 125 void DownloadNotificationItem::OnNotificationClick() {
115 if (item_->IsDangerous()) { 126 if (item_->IsDangerous()) {
116 #if defined(FULL_SAFE_BROWSING) 127 #if defined(FULL_SAFE_BROWSING)
117 DownloadCommands(item_).ExecuteCommand( 128 DownloadCommands(item_).ExecuteCommand(
118 DownloadCommands::LEARN_MORE_SCANNING); 129 DownloadCommands::LEARN_MORE_SCANNING);
119 #else 130 #else
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 CloseNotificationByUser(); 168 CloseNotificationByUser();
158 } 169 }
159 170
160 DownloadCommands(item_).ExecuteCommand(command); 171 DownloadCommands(item_).ExecuteCommand(command);
161 172
162 // Shows the notification again after clicking "Keep" on dangerous download. 173 // Shows the notification again after clicking "Keep" on dangerous download.
163 if (command == DownloadCommands::KEEP) 174 if (command == DownloadCommands::KEEP)
164 UpdateNotificationData(ADD_NEW); 175 UpdateNotificationData(ADD_NEW);
165 } 176 }
166 177
178 void DownloadNotificationItem::OnNotificationClose(bool by_user) {
179 if (image_decode_status_ == IN_PROGRESS) {
180 image_decode_status_ = NOT_STARTED;
181 ImageDecoder::Cancel(this);
182 }
183 }
184
167 // DownloadItem::Observer methods 185 // DownloadItem::Observer methods
168 void DownloadNotificationItem::OnDownloadUpdated(content::DownloadItem* item) { 186 void DownloadNotificationItem::OnDownloadUpdated(content::DownloadItem* item) {
169 DCHECK_EQ(item, item_); 187 DCHECK_EQ(item, item_);
170 188
171 UpdateNotificationData(UPDATE_EXISTING); 189 UpdateNotificationData(UPDATE_EXISTING);
172 } 190 }
173 191
174 void DownloadNotificationItem::CloseNotificationByNonUser() { 192 void DownloadNotificationItem::CloseNotificationByNonUser() {
175 const std::string& notification_id = watcher_->id(); 193 const std::string& notification_id = watcher_->id();
176 const ProfileID profile_id = NotificationUIManager::GetProfileID(profile_); 194 const ProfileID profile_id = NotificationUIManager::GetProfileID(profile_);
(...skipping 16 matching lines...) Expand all
193 // because it's by user action. So, we request closing of it directlly to 211 // because it's by user action. So, we request closing of it directlly to
194 // MessageCenter instance. 212 // MessageCenter instance.
195 // Note that: this calling has no side-effect even when the message center 213 // Note that: this calling has no side-effect even when the message center
196 // is not opened. 214 // is not opened.
197 g_browser_process->message_center()->RemoveNotification( 215 g_browser_process->message_center()->RemoveNotification(
198 notification_id_in_message_center, true /* by_user */); 216 notification_id_in_message_center, true /* by_user */);
199 } 217 }
200 218
201 void DownloadNotificationItem::UpdateNotificationData( 219 void DownloadNotificationItem::UpdateNotificationData(
202 NotificationUpdateType type) { 220 NotificationUpdateType type) {
221 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
asanka 2015/06/11 03:30:51 DCHECK_CURRENTLY_ON
yoshiki 2015/06/11 08:22:09 Done.
222
203 DownloadItemModel model(item_); 223 DownloadItemModel model(item_);
204 DownloadCommands command(item_); 224 DownloadCommands command(item_);
205 225
206 if (previous_download_state_ != content::DownloadItem::IN_PROGRESS) { 226 if (previous_download_state_ != content::DownloadItem::IN_PROGRESS) {
207 if (item_->GetState() == content::DownloadItem::IN_PROGRESS) 227 if (item_->GetState() == content::DownloadItem::IN_PROGRESS)
208 delegate_->OnDownloadStarted(this); 228 delegate_->OnDownloadStarted(this);
209 } else { 229 } else {
210 if (item_->GetState() != content::DownloadItem::IN_PROGRESS) 230 if (item_->GetState() != content::DownloadItem::IN_PROGRESS)
211 delegate_->OnDownloadStopped(this); 231 delegate_->OnDownloadStopped(this);
212 } 232 }
213 233
214 if (item_->IsDangerous()) { 234 if (item_->IsDangerous()) {
215 notification_->set_type(message_center::NOTIFICATION_TYPE_BASE_FORMAT); 235 notification_->set_type(message_center::NOTIFICATION_TYPE_BASE_FORMAT);
216 notification_->set_title(GetTitle()); 236 notification_->set_title(GetTitle());
217 notification_->set_message(GetWarningText()); 237 notification_->set_message(GetWarningText());
218 238
219 // Show icon. 239 // Show icon.
220 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_MALICIOUS); 240 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_MALICIOUS);
221 } else { 241 } else {
222 notification_->set_title(GetTitle()); 242 notification_->set_title(GetTitle());
223 notification_->set_message(model.GetStatusText()); 243 notification_->set_message(model.GetStatusText());
224 244
225 bool is_off_the_record = item_->GetBrowserContext() && 245 bool is_off_the_record = item_->GetBrowserContext() &&
226 item_->GetBrowserContext()->IsOffTheRecord(); 246 item_->GetBrowserContext()->IsOffTheRecord();
227 247
228 switch (item_->GetState()) { 248 switch (item_->GetState()) {
229 case content::DownloadItem::IN_PROGRESS: 249 case content::DownloadItem::IN_PROGRESS:
230 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS); 250 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
231 notification_->set_progress(item_->PercentComplete()); 251 notification_->set_progress(item_->PercentComplete());
232 if (is_off_the_record) { 252 if (is_off_the_record) {
233 // TODO(yoshiki): Replace the tentative image. 253 // TODO(yoshiki): Replace the tentative image.
234 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO); 254 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO);
235 } else { 255 } else {
236 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING); 256 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING);
237 } 257 }
238 break; 258 break;
239 case content::DownloadItem::COMPLETE: 259 case content::DownloadItem::COMPLETE:
240 DCHECK(item_->IsDone()); 260 DCHECK(item_->IsDone());
241 261
242 // Shows a notifiation as progress type once so the visible content will 262 // Shows a notifiation as progress type once so the visible content will
243 // be updated. 263 // be updated.
244 // Note: only progress-type notification's content will be updated 264 // Note: only progress-type notification's content will be updated
245 // immediately when the message center is visible. 265 // immediately when the message center is visible.
246 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS); 266 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
247 notification_->set_progress(100); 267 notification_->set_progress(100);
248 268
249 if (is_off_the_record) { 269 if (is_off_the_record) {
250 // TODO(yoshiki): Replace the tentative image. 270 // TODO(yoshiki): Replace the tentative image.
251 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO); 271 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO);
252 } else { 272 } else {
253 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING); 273 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING);
254 } 274 }
255 break; 275 break;
256 case content::DownloadItem::CANCELLED: 276 case content::DownloadItem::CANCELLED:
257 // Confgirms that a download is cancelled by user action. 277 // Confgirms that a download is cancelled by user action.
258 DCHECK(item_->GetLastReason() == 278 DCHECK(item_->GetLastReason() ==
259 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED || 279 content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED ||
260 item_->GetLastReason() == 280 item_->GetLastReason() ==
261 content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN); 281 content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
262 282
263 CloseNotificationByUser(); 283 CloseNotificationByUser();
264 284
265 previous_download_state_ = item_->GetState(); 285 previous_download_state_ = item_->GetState();
266 return; // Skips the remaining since the notification has closed. 286 return; // Skips the remaining since the notification has closed.
267 case content::DownloadItem::INTERRUPTED: 287 case content::DownloadItem::INTERRUPTED:
268 // Shows a notifiation as progress type once so the visible content will 288 // Shows a notifiation as progress type once so the visible content will
269 // be updated. (same as the case of type = COMPLETE) 289 // be updated. (same as the case of type = COMPLETE)
270 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS); 290 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
271 notification_->set_progress(0); 291 notification_->set_progress(0);
272 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_WARNING); 292 SetNotificationIcon(IDR_DOWNLOAD_NOTIFICATION_WARNING);
273 break; 293 break;
274 case content::DownloadItem::MAX_DOWNLOAD_STATE: // sentinel 294 case content::DownloadItem::MAX_DOWNLOAD_STATE: // sentinel
275 NOTREACHED(); 295 NOTREACHED();
276 } 296 }
277 } 297 }
278 298
279 std::vector<message_center::ButtonInfo> notification_actions; 299 std::vector<message_center::ButtonInfo> notification_actions;
280 scoped_ptr<std::vector<DownloadCommands::Command>> actions( 300 scoped_ptr<std::vector<DownloadCommands::Command>> actions(
281 GetExtraActions().Pass()); 301 GetExtraActions().Pass());
282 302
283 button_actions_.reset(new std::vector<DownloadCommands::Command>); 303 button_actions_.reset(new std::vector<DownloadCommands::Command>);
284 for (auto it = actions->begin(); it != actions->end(); it++) { 304 for (auto it = actions->begin(); it != actions->end(); it++) {
285 button_actions_->push_back(*it); 305 button_actions_->push_back(*it);
286 message_center::ButtonInfo button_info = 306 message_center::ButtonInfo button_info =
287 message_center::ButtonInfo(GetCommandLabel(*it)); 307 message_center::ButtonInfo(GetCommandLabel(*it));
288 button_info.icon = command.GetCommandIcon(*it); 308 button_info.icon = command.GetCommandIcon(*it);
289 notification_actions.push_back(button_info); 309 notification_actions.push_back(button_info);
290 } 310 }
291 notification_->set_buttons(notification_actions); 311 notification_->set_buttons(notification_actions);
292 312
293 if (item_->IsDone()) {
294 // TODO(yoshiki): If the downloaded file is an image, show the thumbnail.
295 }
296
297 if (type == ADD_NEW) { 313 if (type == ADD_NEW) {
298 notification_ui_manager()->Add(*notification_, profile_); 314 notification_ui_manager()->Add(*notification_, profile_);
299 } else if (type == UPDATE_EXISTING) { 315 } else if (type == UPDATE_EXISTING) {
300 notification_ui_manager()->Update(*notification_, profile_); 316 notification_ui_manager()->Update(*notification_, profile_);
301 317
302 // When the download is just completed (or interrupted), close the 318 // When the download is just completed (or interrupted), close the
303 // notification once and re-show it immediately so it'll pop up. 319 // notification once and re-show it immediately so it'll pop up.
304 if ((item_->GetState() == content::DownloadItem::COMPLETE && 320 if ((item_->GetState() == content::DownloadItem::COMPLETE &&
305 previous_download_state_ != content::DownloadItem::COMPLETE) || 321 previous_download_state_ != content::DownloadItem::COMPLETE) ||
306 (item_->GetState() == content::DownloadItem::INTERRUPTED && 322 (item_->GetState() == content::DownloadItem::INTERRUPTED &&
307 previous_download_state_ != content::DownloadItem::INTERRUPTED)) { 323 previous_download_state_ != content::DownloadItem::INTERRUPTED)) {
308 CloseNotificationByNonUser(); 324 CloseNotificationByNonUser();
309 // Changes the type from PROGRESS to BASE_FORMAT. 325 // Changes the type from PROGRESS to BASE_FORMAT.
310 notification_->set_type(message_center::NOTIFICATION_TYPE_BASE_FORMAT); 326 notification_->set_type(message_center::NOTIFICATION_TYPE_BASE_FORMAT);
311 notification_ui_manager()->Add(*notification_, profile_); 327 notification_ui_manager()->Add(*notification_, profile_);
312 } 328 }
313 } else { 329 } else {
314 NOTREACHED(); 330 NOTREACHED();
315 } 331 }
316 332
317 previous_download_state_ = item_->GetState(); 333 previous_download_state_ = item_->GetState();
334
335 if (item_->IsDone() && image_decode_status_ == NOT_STARTED &&
336 item_->GetReceivedBytes() <= kMaxImagePreviewSize) {
337 DCHECK(notification_->image().IsEmpty());
338
339 image_decode_status_ = IN_PROGRESS;
340
341 bool maybe_image = false;
342 if (mime_util::IsSupportedImageMimeType(item_->GetMimeType())) {
343 maybe_image = true;
344 } else {
345 std::string mime;
346 if (net::GetWellKnownMimeTypeFromExtension(
347 item_->GetTargetFilePath().FinalExtension(),
348 &mime) &&
349 mime_util::IsSupportedImageMimeType(mime)) {
350 maybe_image = true;
351 }
352 }
353
354 if (maybe_image) {
355 base::FilePath file_path = item_->GetFullPath();
356 // TODO(yoshiki): Shrink the image size to supress memory usage.
357 ImageDecoder::Start(this, file_path);
358 } else {
359 image_decode_status_ = NOT_IMAGE;
360 }
361 }
318 } 362 }
319 363
320 void DownloadNotificationItem::OnDownloadOpened(content::DownloadItem* item) { 364 void DownloadNotificationItem::OnDownloadOpened(content::DownloadItem* item) {
321 DCHECK_EQ(item, item_); 365 DCHECK_EQ(item, item_);
322 // Do nothing. 366 // Do nothing.
323 } 367 }
324 368
325 void DownloadNotificationItem::OnDownloadRemoved(content::DownloadItem* item) { 369 void DownloadNotificationItem::OnDownloadRemoved(content::DownloadItem* item) {
326 DCHECK_EQ(item, item_); 370 DCHECK_EQ(item, item_);
327 371
328 // Removing the notification causes calling |NotificationDelegate::Close()|. 372 // Removing the notification causes calling |NotificationDelegate::Close()|.
329 notification_ui_manager()->CancelById( 373 notification_ui_manager()->CancelById(
330 watcher_->id(), NotificationUIManager::GetProfileID(profile_)); 374 watcher_->id(), NotificationUIManager::GetProfileID(profile_));
331 delegate_->OnDownloadRemoved(this); 375 delegate_->OnDownloadRemoved(this);
332 } 376 }
333 377
334 void DownloadNotificationItem::OnDownloadDestroyed( 378 void DownloadNotificationItem::OnDownloadDestroyed(
335 content::DownloadItem* item) { 379 content::DownloadItem* item) {
336 DCHECK_EQ(item, item_); 380 DCHECK_EQ(item, item_);
337 381
338 item_ = nullptr; 382 item_ = nullptr;
339 } 383 }
340 384
341 void DownloadNotificationItem::SetNotificationImage(int resource_id) { 385 void DownloadNotificationItem::SetNotificationIcon(int resource_id) {
342 if (image_resource_id_ == resource_id) 386 if (image_resource_id_ == resource_id)
343 return; 387 return;
344 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 388 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
345 image_resource_id_ = resource_id; 389 image_resource_id_ = resource_id;
346 notification_->set_icon(bundle.GetImageNamed(image_resource_id_)); 390 notification_->set_icon(bundle.GetImageNamed(image_resource_id_));
347 } 391 }
348 392
393 void DownloadNotificationItem::OnImageDecoded(const SkBitmap& decoded_image) {
394 gfx::Image image = gfx::Image::CreateFrom1xBitmap(decoded_image);
395 notification_->set_image(image);
396 image_decode_status_ = DONE;
397 UpdateNotificationData(UPDATE_EXISTING);
398 }
399
400 void DownloadNotificationItem::OnDecodeImageFailed() {
401 notification_->set_image(gfx::Image());
402 image_decode_status_ = FAILED;
403 UpdateNotificationData(UPDATE_EXISTING);
404 }
405
349 NotificationUIManager* DownloadNotificationItem::notification_ui_manager() 406 NotificationUIManager* DownloadNotificationItem::notification_ui_manager()
350 const { 407 const {
351 if (stub_notification_ui_manager_for_testing_) { 408 if (stub_notification_ui_manager_for_testing_) {
352 return stub_notification_ui_manager_for_testing_; 409 return stub_notification_ui_manager_for_testing_;
353 } 410 }
354 return g_browser_process->notification_ui_manager(); 411 return g_browser_process->notification_ui_manager();
355 } 412 }
356 413
357 scoped_ptr<std::vector<DownloadCommands::Command>> 414 scoped_ptr<std::vector<DownloadCommands::Command>>
358 DownloadNotificationItem::GetExtraActions() const { 415 DownloadNotificationItem::GetExtraActions() const {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 NOTREACHED(); 554 NOTREACHED();
498 return base::string16(); 555 return base::string16();
499 } 556 }
500 557
501 Browser* DownloadNotificationItem::GetBrowser() { 558 Browser* DownloadNotificationItem::GetBrowser() {
502 chrome::ScopedTabbedBrowserDisplayer browser_displayer( 559 chrome::ScopedTabbedBrowserDisplayer browser_displayer(
503 profile_, chrome::GetActiveDesktop()); 560 profile_, chrome::GetActiveDesktop());
504 DCHECK(browser_displayer.browser()); 561 DCHECK(browser_displayer.browser());
505 return browser_displayer.browser(); 562 return browser_displayer.browser();
506 } 563 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698