| 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/webui/md_downloads/md_downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/md_downloads/md_downloads_dom_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 void MdDownloadsDOMHandler::HandleSaveDangerous(const base::ListValue* args) { | 194 void MdDownloadsDOMHandler::HandleSaveDangerous(const base::ListValue* args) { |
| 195 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS); | 195 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS); |
| 196 content::DownloadItem* file = GetDownloadByValue(args); | 196 content::DownloadItem* file = GetDownloadByValue(args); |
| 197 if (file) | 197 if (file) |
| 198 ShowDangerPrompt(file); | 198 ShowDangerPrompt(file); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void MdDownloadsDOMHandler::HandleDiscardDangerous( | 201 void MdDownloadsDOMHandler::HandleDiscardDangerous( |
| 202 const base::ListValue* args) { | 202 const base::ListValue* args) { |
| 203 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS); | 203 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_DISCARD_DANGEROUS); |
| 204 content::DownloadItem* file = GetDownloadByValue(args); | 204 RemoveDownloadInArgs(args); |
| 205 if (file) | |
| 206 file->Remove(); | |
| 207 } | 205 } |
| 208 | 206 |
| 209 void MdDownloadsDOMHandler::HandleShow(const base::ListValue* args) { | 207 void MdDownloadsDOMHandler::HandleShow(const base::ListValue* args) { |
| 210 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SHOW); | 208 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SHOW); |
| 211 content::DownloadItem* file = GetDownloadByValue(args); | 209 content::DownloadItem* file = GetDownloadByValue(args); |
| 212 if (file) | 210 if (file) |
| 213 file->ShowDownloadInShell(); | 211 file->ShowDownloadInShell(); |
| 214 } | 212 } |
| 215 | 213 |
| 216 void MdDownloadsDOMHandler::HandlePause(const base::ListValue* args) { | 214 void MdDownloadsDOMHandler::HandlePause(const base::ListValue* args) { |
| 217 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); | 215 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_PAUSE); |
| 218 content::DownloadItem* file = GetDownloadByValue(args); | 216 content::DownloadItem* file = GetDownloadByValue(args); |
| 219 if (file) | 217 if (file) |
| 220 file->Pause(); | 218 file->Pause(); |
| 221 } | 219 } |
| 222 | 220 |
| 223 void MdDownloadsDOMHandler::HandleResume(const base::ListValue* args) { | 221 void MdDownloadsDOMHandler::HandleResume(const base::ListValue* args) { |
| 224 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_RESUME); | 222 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_RESUME); |
| 225 content::DownloadItem* file = GetDownloadByValue(args); | 223 content::DownloadItem* file = GetDownloadByValue(args); |
| 226 if (file) | 224 if (file) |
| 227 file->Resume(); | 225 file->Resume(); |
| 228 } | 226 } |
| 229 | 227 |
| 230 void MdDownloadsDOMHandler::HandleRemove(const base::ListValue* args) { | 228 void MdDownloadsDOMHandler::HandleRemove(const base::ListValue* args) { |
| 231 if (!IsDeletingHistoryAllowed()) | 229 if (!IsDeletingHistoryAllowed()) |
| 232 return; | 230 return; |
| 233 | 231 |
| 234 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); | 232 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_REMOVE); |
| 235 content::DownloadItem* file = GetDownloadByValue(args); | 233 RemoveDownloadInArgs(args); |
| 236 if (!file) | |
| 237 return; | |
| 238 | |
| 239 DownloadVector downloads; | |
| 240 downloads.push_back(file); | |
| 241 RemoveDownloads(downloads); | |
| 242 } | 234 } |
| 243 | 235 |
| 244 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) { | 236 void MdDownloadsDOMHandler::HandleUndo(const base::ListValue* args) { |
| 245 // TODO(dbeam): handle more than removed downloads someday? | 237 // TODO(dbeam): handle more than removed downloads someday? |
| 246 if (removals_.empty()) | 238 if (removals_.empty()) |
| 247 return; | 239 return; |
| 248 | 240 |
| 249 const IdSet last_removed_ids = removals_.back(); | 241 const IdSet last_removed_ids = removals_.back(); |
| 250 removals_.pop_back(); | 242 removals_.pop_back(); |
| 251 | 243 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 GetOriginalNotifierManager()->GetAllDownloads(&downloads); | 290 GetOriginalNotifierManager()->GetAllDownloads(&downloads); |
| 299 RemoveDownloads(downloads); | 291 RemoveDownloads(downloads); |
| 300 | 292 |
| 301 list_tracker_.StartAndSendChunk(); | 293 list_tracker_.StartAndSendChunk(); |
| 302 } | 294 } |
| 303 | 295 |
| 304 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) { | 296 void MdDownloadsDOMHandler::RemoveDownloads(const DownloadVector& to_remove) { |
| 305 IdSet ids; | 297 IdSet ids; |
| 306 | 298 |
| 307 for (auto* download : to_remove) { | 299 for (auto* download : to_remove) { |
| 300 if (download->IsDangerous()) { |
| 301 // Don't allow users to revive dangerous downloads; just nuke 'em. |
| 302 download->Remove(); |
| 303 continue; |
| 304 } |
| 305 |
| 308 DownloadItemModel item_model(download); | 306 DownloadItemModel item_model(download); |
| 309 if (!item_model.ShouldShowInShelf() || | 307 if (!item_model.ShouldShowInShelf() || |
| 310 download->GetState() == content::DownloadItem::IN_PROGRESS) { | 308 download->GetState() == content::DownloadItem::IN_PROGRESS) { |
| 311 continue; | 309 continue; |
| 312 } | 310 } |
| 313 | 311 |
| 314 item_model.SetShouldShowInShelf(false); | 312 item_model.SetShouldShowInShelf(false); |
| 315 ids.insert(download->GetId()); | 313 ids.insert(download->GetId()); |
| 316 download->UpdateObservers(); | 314 download->UpdateObservers(); |
| 317 } | 315 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() { | 418 content::WebContents* MdDownloadsDOMHandler::GetWebUIWebContents() { |
| 421 return web_ui()->GetWebContents(); | 419 return web_ui()->GetWebContents(); |
| 422 } | 420 } |
| 423 | 421 |
| 424 void MdDownloadsDOMHandler::CheckForRemovedFiles() { | 422 void MdDownloadsDOMHandler::CheckForRemovedFiles() { |
| 425 if (GetMainNotifierManager()) | 423 if (GetMainNotifierManager()) |
| 426 GetMainNotifierManager()->CheckForHistoryFilesRemoval(); | 424 GetMainNotifierManager()->CheckForHistoryFilesRemoval(); |
| 427 if (GetOriginalNotifierManager()) | 425 if (GetOriginalNotifierManager()) |
| 428 GetOriginalNotifierManager()->CheckForHistoryFilesRemoval(); | 426 GetOriginalNotifierManager()->CheckForHistoryFilesRemoval(); |
| 429 } | 427 } |
| 428 |
| 429 void MdDownloadsDOMHandler::RemoveDownloadInArgs(const base::ListValue* args) { |
| 430 content::DownloadItem* file = GetDownloadByValue(args); |
| 431 if (!file) |
| 432 return; |
| 433 |
| 434 DownloadVector downloads; |
| 435 downloads.push_back(file); |
| 436 RemoveDownloads(downloads); |
| 437 } |
| OLD | NEW |