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