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/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/download/download_crx_util.h" | 9 #include "chrome/browser/download/download_crx_util.h" |
10 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 UpdateNotificationData(ADD_NEW); | 106 UpdateNotificationData(ADD_NEW); |
107 } | 107 } |
108 | 108 |
109 DownloadNotificationItem::~DownloadNotificationItem() { | 109 DownloadNotificationItem::~DownloadNotificationItem() { |
110 if (item_) | 110 if (item_) |
111 item_->RemoveObserver(this); | 111 item_->RemoveObserver(this); |
112 } | 112 } |
113 | 113 |
114 void DownloadNotificationItem::OnNotificationClick() { | 114 void DownloadNotificationItem::OnNotificationClick() { |
115 if (openable_) { | 115 if (item_->IsDangerous()) { |
116 if (item_->IsDone()) { | 116 #if defined(FULL_SAFE_BROWSING) |
| 117 DownloadCommands(item_).ExecuteCommand( |
| 118 DownloadCommands::LEARN_MORE_SCANNING); |
| 119 #else |
| 120 CloseNotificationByUser(); |
| 121 #endif |
| 122 return; |
| 123 } |
| 124 |
| 125 switch (item_->GetState()) { |
| 126 case content::DownloadItem::IN_PROGRESS: |
| 127 item_->SetOpenWhenComplete(!item_->GetOpenWhenComplete()); // Toggle |
| 128 break; |
| 129 case content::DownloadItem::CANCELLED: |
| 130 case content::DownloadItem::INTERRUPTED: |
| 131 GetBrowser()->OpenURL(content::OpenURLParams( |
| 132 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), |
| 133 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
| 134 false /* is_renderer_initiated */)); |
| 135 CloseNotificationByUser(); |
| 136 break; |
| 137 case content::DownloadItem::COMPLETE: |
117 item_->OpenDownload(); | 138 item_->OpenDownload(); |
118 CloseNotificationByUser(); | 139 CloseNotificationByUser(); |
119 } else { | 140 break; |
120 item_->SetOpenWhenComplete(!item_->GetOpenWhenComplete()); // Toggle | 141 case content::DownloadItem::MAX_DOWNLOAD_STATE: |
121 } | 142 NOTREACHED(); |
122 } else if (item_->GetState() == content::DownloadItem::INTERRUPTED || | |
123 item_->GetState() == content::DownloadItem::CANCELLED) { | |
124 GetBrowser()->OpenURL(content::OpenURLParams( | |
125 GURL(chrome::kChromeUIDownloadsURL), content::Referrer(), | |
126 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | |
127 false /* is_renderer_initiated */)); | |
128 CloseNotificationByUser(); | |
129 } else if (item_->IsDone()) { | |
130 CloseNotificationByUser(); | |
131 } | 143 } |
132 } | 144 } |
133 | 145 |
134 void DownloadNotificationItem::OnNotificationButtonClick(int button_index) { | 146 void DownloadNotificationItem::OnNotificationButtonClick(int button_index) { |
135 if (button_index < 0 || | 147 if (button_index < 0 || |
136 static_cast<size_t>(button_index) >= button_actions_->size()) { | 148 static_cast<size_t>(button_index) >= button_actions_->size()) { |
137 // Out of boundary. | 149 // Out of boundary. |
138 NOTREACHED(); | 150 NOTREACHED(); |
139 return; | 151 return; |
140 } | 152 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 notification_->set_progress(0); | 271 notification_->set_progress(0); |
260 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_WARNING); | 272 SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_WARNING); |
261 break; | 273 break; |
262 case content::DownloadItem::MAX_DOWNLOAD_STATE: // sentinel | 274 case content::DownloadItem::MAX_DOWNLOAD_STATE: // sentinel |
263 NOTREACHED(); | 275 NOTREACHED(); |
264 } | 276 } |
265 } | 277 } |
266 | 278 |
267 std::vector<message_center::ButtonInfo> notification_actions; | 279 std::vector<message_center::ButtonInfo> notification_actions; |
268 scoped_ptr<std::vector<DownloadCommands::Command>> actions( | 280 scoped_ptr<std::vector<DownloadCommands::Command>> actions( |
269 GetPossibleActions().Pass()); | 281 GetExtraActions().Pass()); |
270 | 282 |
271 openable_ = false; | |
272 button_actions_.reset(new std::vector<DownloadCommands::Command>); | 283 button_actions_.reset(new std::vector<DownloadCommands::Command>); |
273 for (auto it = actions->begin(); it != actions->end(); it++) { | 284 for (auto it = actions->begin(); it != actions->end(); it++) { |
274 if (*it == DownloadCommands::OPEN_WHEN_COMPLETE) { | 285 button_actions_->push_back(*it); |
275 openable_ = true; | 286 message_center::ButtonInfo button_info = |
276 } else { | 287 message_center::ButtonInfo(GetCommandLabel(*it)); |
277 button_actions_->push_back(*it); | 288 button_info.icon = command.GetCommandIcon(*it); |
278 message_center::ButtonInfo button_info = | 289 notification_actions.push_back(button_info); |
279 message_center::ButtonInfo(GetCommandLabel(*it)); | |
280 button_info.icon = command.GetCommandIcon(*it); | |
281 notification_actions.push_back(button_info); | |
282 } | |
283 } | 290 } |
284 notification_->set_buttons(notification_actions); | 291 notification_->set_buttons(notification_actions); |
285 | 292 |
286 if (item_->IsDone()) { | 293 if (item_->IsDone()) { |
287 // TODO(yoshiki): If the downloaded file is an image, show the thumbnail. | 294 // TODO(yoshiki): If the downloaded file is an image, show the thumbnail. |
288 } | 295 } |
289 | 296 |
290 if (type == ADD_NEW) { | 297 if (type == ADD_NEW) { |
291 notification_ui_manager()->Add(*notification_, profile_); | 298 notification_ui_manager()->Add(*notification_, profile_); |
292 } else if (type == UPDATE_EXISTING) { | 299 } else if (type == UPDATE_EXISTING) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 348 |
342 NotificationUIManager* DownloadNotificationItem::notification_ui_manager() | 349 NotificationUIManager* DownloadNotificationItem::notification_ui_manager() |
343 const { | 350 const { |
344 if (stub_notification_ui_manager_for_testing_) { | 351 if (stub_notification_ui_manager_for_testing_) { |
345 return stub_notification_ui_manager_for_testing_; | 352 return stub_notification_ui_manager_for_testing_; |
346 } | 353 } |
347 return g_browser_process->notification_ui_manager(); | 354 return g_browser_process->notification_ui_manager(); |
348 } | 355 } |
349 | 356 |
350 scoped_ptr<std::vector<DownloadCommands::Command>> | 357 scoped_ptr<std::vector<DownloadCommands::Command>> |
351 DownloadNotificationItem::GetPossibleActions() const { | 358 DownloadNotificationItem::GetExtraActions() const { |
352 scoped_ptr<std::vector<DownloadCommands::Command>> actions( | 359 scoped_ptr<std::vector<DownloadCommands::Command>> actions( |
353 new std::vector<DownloadCommands::Command>()); | 360 new std::vector<DownloadCommands::Command>()); |
354 | 361 |
355 if (item_->IsDangerous()) { | 362 if (item_->IsDangerous()) { |
356 actions->push_back(DownloadCommands::DISCARD); | 363 actions->push_back(DownloadCommands::DISCARD); |
357 actions->push_back(DownloadCommands::KEEP); | 364 actions->push_back(DownloadCommands::KEEP); |
358 return actions.Pass(); | 365 return actions.Pass(); |
359 } | 366 } |
360 | 367 |
361 switch (item_->GetState()) { | 368 switch (item_->GetState()) { |
362 case content::DownloadItem::IN_PROGRESS: | 369 case content::DownloadItem::IN_PROGRESS: |
363 actions->push_back(DownloadCommands::OPEN_WHEN_COMPLETE); | |
364 if (!item_->IsPaused()) | 370 if (!item_->IsPaused()) |
365 actions->push_back(DownloadCommands::PAUSE); | 371 actions->push_back(DownloadCommands::PAUSE); |
366 else | 372 else |
367 actions->push_back(DownloadCommands::RESUME); | 373 actions->push_back(DownloadCommands::RESUME); |
368 actions->push_back(DownloadCommands::CANCEL); | 374 actions->push_back(DownloadCommands::CANCEL); |
369 break; | 375 break; |
370 case content::DownloadItem::CANCELLED: | 376 case content::DownloadItem::CANCELLED: |
371 case content::DownloadItem::INTERRUPTED: | 377 case content::DownloadItem::INTERRUPTED: |
372 if (item_->CanResume()) | 378 if (item_->CanResume()) |
373 actions->push_back(DownloadCommands::RESUME); | 379 actions->push_back(DownloadCommands::RESUME); |
374 break; | 380 break; |
375 case content::DownloadItem::COMPLETE: | 381 case content::DownloadItem::COMPLETE: |
376 actions->push_back(DownloadCommands::OPEN_WHEN_COMPLETE); | |
377 actions->push_back(DownloadCommands::SHOW_IN_FOLDER); | 382 actions->push_back(DownloadCommands::SHOW_IN_FOLDER); |
378 break; | 383 break; |
379 case content::DownloadItem::MAX_DOWNLOAD_STATE: | 384 case content::DownloadItem::MAX_DOWNLOAD_STATE: |
380 NOTREACHED(); | 385 NOTREACHED(); |
381 } | 386 } |
382 return actions.Pass(); | 387 return actions.Pass(); |
383 } | 388 } |
384 | 389 |
385 base::string16 DownloadNotificationItem::GetTitle() const { | 390 base::string16 DownloadNotificationItem::GetTitle() const { |
386 base::string16 title_text; | 391 base::string16 title_text; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 NOTREACHED(); | 497 NOTREACHED(); |
493 return base::string16(); | 498 return base::string16(); |
494 } | 499 } |
495 | 500 |
496 Browser* DownloadNotificationItem::GetBrowser() { | 501 Browser* DownloadNotificationItem::GetBrowser() { |
497 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | 502 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
498 profile_, chrome::GetActiveDesktop()); | 503 profile_, chrome::GetActiveDesktop()); |
499 DCHECK(browser_displayer.browser()); | 504 DCHECK(browser_displayer.browser()); |
500 return browser_displayer.browser(); | 505 return browser_displayer.browser(); |
501 } | 506 } |
OLD | NEW |