| 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/downloads_dom_handler.h" | 5 #include "chrome/browser/ui/webui/downloads_dom_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 14 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
| 15 #include "base/logging.h" |
| 15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 16 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 18 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/supports_user_data.h" | 23 #include "base/supports_user_data.h" |
| 23 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
| 24 #include "base/value_conversions.h" | 25 #include "base/value_conversions.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 file_value->SetString("danger_type", danger_type_value); | 193 file_value->SetString("danger_type", danger_type_value); |
| 193 } else if (download_item->IsPaused()) { | 194 } else if (download_item->IsPaused()) { |
| 194 file_value->SetString("state", "PAUSED"); | 195 file_value->SetString("state", "PAUSED"); |
| 195 } else { | 196 } else { |
| 196 file_value->SetString("state", "IN_PROGRESS"); | 197 file_value->SetString("state", "IN_PROGRESS"); |
| 197 } | 198 } |
| 198 file_value->SetString("progress_status_text", | 199 file_value->SetString("progress_status_text", |
| 199 download_model.GetTabProgressStatusText()); | 200 download_model.GetTabProgressStatusText()); |
| 200 | 201 |
| 201 file_value->SetInteger("percent", | 202 file_value->SetInteger("percent", |
| 202 static_cast<int>(download_item->PercentComplete())); | 203 std::max(0, static_cast<int>(download_item->PercentComplete()))); |
| 203 file_value->SetInteger("received", | 204 file_value->SetInteger("received", |
| 204 static_cast<int>(download_item->GetReceivedBytes())); | 205 static_cast<int>(download_item->GetReceivedBytes())); |
| 205 break; | 206 break; |
| 206 | 207 |
| 207 case content::DownloadItem::INTERRUPTED: | 208 case content::DownloadItem::INTERRUPTED: |
| 208 file_value->SetString("state", "INTERRUPTED"); | 209 file_value->SetString("state", "INTERRUPTED"); |
| 209 | 210 |
| 210 file_value->SetString("progress_status_text", | 211 file_value->SetString("progress_status_text", |
| 211 download_model.GetTabProgressStatusText()); | 212 download_model.GetTabProgressStatusText()); |
| 212 | 213 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 weak_ptr_factory_.GetWeakPtr())); | 318 weak_ptr_factory_.GetWeakPtr())); |
| 318 web_ui()->RegisterMessageCallback("openDownloadsFolder", | 319 web_ui()->RegisterMessageCallback("openDownloadsFolder", |
| 319 base::Bind(&DownloadsDOMHandler::HandleOpenDownloadsFolder, | 320 base::Bind(&DownloadsDOMHandler::HandleOpenDownloadsFolder, |
| 320 weak_ptr_factory_.GetWeakPtr())); | 321 weak_ptr_factory_.GetWeakPtr())); |
| 321 } | 322 } |
| 322 | 323 |
| 323 void DownloadsDOMHandler::OnDownloadCreated( | 324 void DownloadsDOMHandler::OnDownloadCreated( |
| 324 content::DownloadManager* manager, content::DownloadItem* download_item) { | 325 content::DownloadManager* manager, content::DownloadItem* download_item) { |
| 325 if (IsDownloadDisplayable(*download_item)) | 326 if (IsDownloadDisplayable(*download_item)) |
| 326 ScheduleSendCurrentDownloads(); | 327 ScheduleSendCurrentDownloads(); |
| 328 else |
| 329 new_downloads_.insert(download_item->GetId()); |
| 327 } | 330 } |
| 328 | 331 |
| 329 void DownloadsDOMHandler::OnDownloadUpdated( | 332 void DownloadsDOMHandler::OnDownloadUpdated( |
| 330 content::DownloadManager* manager, | 333 content::DownloadManager* manager, |
| 331 content::DownloadItem* download_item) { | 334 content::DownloadItem* download_item) { |
| 332 if (IsDownloadDisplayable(*download_item)) { | 335 bool showing_new_item = false; |
| 333 if (search_terms_ && !search_terms_->empty()) { | 336 |
| 334 // Don't CallDownloadUpdated() if download_item doesn't match | 337 if (new_downloads_.count(download_item->GetId())) { |
| 335 // search_terms_. | 338 // A new download (that the page doesn't know about yet) has been updated. |
| 336 // TODO(benjhayden): Consider splitting MatchesQuery() out to a function. | 339 if (!IsDownloadDisplayable(*download_item)) { |
| 337 content::DownloadManager::DownloadVector all_items, filtered_items; | 340 // Item isn't ready to be displayed yet. Wait until it is. |
| 338 all_items.push_back(download_item); | 341 return; |
| 339 DownloadQuery query; | |
| 340 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_.get()); | |
| 341 query.Search(all_items.begin(), all_items.end(), &filtered_items); | |
| 342 if (filtered_items.empty()) | |
| 343 return; | |
| 344 } | 342 } |
| 345 base::ListValue results_value; | 343 |
| 346 results_value.Append(CreateDownloadItemValue( | 344 new_downloads_.erase(download_item->GetId()); |
| 347 download_item, | 345 showing_new_item = true; |
| 348 (original_notifier_.get() && | 346 } |
| 349 (manager == main_notifier_.GetManager())))); | 347 |
| 350 CallDownloadUpdated(results_value); | 348 if (showing_new_item || DownloadItemModel(download_item).IsBeingRevived() || |
| 351 } else { | 349 !IsDownloadDisplayable(*download_item)) { |
| 350 // A download will be shown or hidden by this update. Resend the list. |
| 352 ScheduleSendCurrentDownloads(); | 351 ScheduleSendCurrentDownloads(); |
| 352 return; |
| 353 } | 353 } |
| 354 |
| 355 if (search_terms_ && !search_terms_->empty()) { |
| 356 // Don't CallUpdateItem() if download_item doesn't match |
| 357 // search_terms_. |
| 358 // TODO(benjhayden): Consider splitting MatchesQuery() out to a function. |
| 359 content::DownloadManager::DownloadVector all_items, filtered_items; |
| 360 all_items.push_back(download_item); |
| 361 DownloadQuery query; |
| 362 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_); |
| 363 query.Search(all_items.begin(), all_items.end(), &filtered_items); |
| 364 if (filtered_items.empty()) |
| 365 return; |
| 366 } |
| 367 |
| 368 scoped_ptr<base::DictionaryValue> item(CreateDownloadItemValue( |
| 369 download_item, |
| 370 original_notifier_ && manager == main_notifier_.GetManager())); |
| 371 CallUpdateItem(*item); |
| 354 } | 372 } |
| 355 | 373 |
| 356 void DownloadsDOMHandler::OnDownloadRemoved( | 374 void DownloadsDOMHandler::OnDownloadRemoved( |
| 357 content::DownloadManager* manager, | 375 content::DownloadManager* manager, |
| 358 content::DownloadItem* download_item) { | 376 content::DownloadItem* download_item) { |
| 359 if (!DownloadItemModel(download_item).ShouldShowInShelf()) | 377 if (!DownloadItemModel(download_item).ShouldShowInShelf()) |
| 360 return; | 378 return; |
| 361 | 379 |
| 362 // This relies on |download_item| being removed from DownloadManager in this | 380 // This relies on |download_item| being removed from DownloadManager in this |
| 363 // MessageLoop iteration. |download_item| may not have been removed from | 381 // MessageLoop iteration. |download_item| may not have been removed from |
| 364 // DownloadManager when OnDownloadRemoved() is fired, so bounce off the | 382 // DownloadManager when OnDownloadRemoved() is fired, so bounce off the |
| 365 // MessageLoop to give it a chance to be removed. SendCurrentDownloads() looks | 383 // MessageLoop to give it a chance to be removed. SendCurrentDownloads() looks |
| 366 // at all downloads, and we do not tell it that |download_item| is being | 384 // at all downloads, and we do not tell it that |download_item| is being |
| 367 // removed. If DownloadManager is ever changed to not immediately remove | 385 // removed. If DownloadManager is ever changed to not immediately remove |
| 368 // |download_item| from its map when OnDownloadRemoved is sent, then | 386 // |download_item| from its map when OnDownloadRemoved is sent, then |
| 369 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell | 387 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell |
| 370 // SendCurrentDownloads() that |download_item| was removed. A | 388 // SendCurrentDownloads() that |download_item| was removed. A |
| 371 // SupportsUserData::Data would be the correct way to do this. | 389 // SupportsUserData::Data would be the correct way to do this. |
| 372 ScheduleSendCurrentDownloads(); | 390 ScheduleSendCurrentDownloads(); |
| 373 } | 391 } |
| 374 | 392 |
| 375 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { | 393 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { |
| 376 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); | 394 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); |
| 377 search_terms_.reset((args && !args->empty()) ? args->DeepCopy() : NULL); | 395 search_terms_.reset(args && !args->empty() ? args->DeepCopy() : NULL); |
| 378 SendCurrentDownloads(); | 396 SendCurrentDownloads(); |
| 379 } | 397 } |
| 380 | 398 |
| 381 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { | 399 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { |
| 382 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); | 400 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); |
| 383 content::DownloadItem* file = GetDownloadByValue(args); | 401 content::DownloadItem* file = GetDownloadByValue(args); |
| 384 if (file) | 402 if (file) |
| 385 file->OpenDownload(); | 403 file->OpenDownload(); |
| 386 } | 404 } |
| 387 | 405 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 if (removals_.empty()) | 482 if (removals_.empty()) |
| 465 return; | 483 return; |
| 466 | 484 |
| 467 const std::set<uint32> last_removed_ids = removals_.back(); | 485 const std::set<uint32> last_removed_ids = removals_.back(); |
| 468 removals_.pop_back(); | 486 removals_.pop_back(); |
| 469 | 487 |
| 470 for (auto id : last_removed_ids) { | 488 for (auto id : last_removed_ids) { |
| 471 content::DownloadItem* download = GetDownloadById(id); | 489 content::DownloadItem* download = GetDownloadById(id); |
| 472 if (!download) | 490 if (!download) |
| 473 continue; | 491 continue; |
| 474 DownloadItemModel(download).SetShouldShowInShelf(true); | 492 |
| 493 DownloadItemModel model(download); |
| 494 model.SetShouldShowInShelf(true); |
| 495 model.SetIsBeingRevived(true); |
| 496 |
| 475 download->UpdateObservers(); | 497 download->UpdateObservers(); |
| 498 |
| 499 model.SetIsBeingRevived(false); |
| 476 } | 500 } |
| 477 } | 501 } |
| 478 | 502 |
| 479 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) { | 503 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) { |
| 480 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); | 504 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); |
| 481 content::DownloadItem* file = GetDownloadByValue(args); | 505 content::DownloadItem* file = GetDownloadByValue(args); |
| 482 if (file) | 506 if (file) |
| 483 file->Cancel(true); | 507 file->Cancel(true); |
| 484 } | 508 } |
| 485 | 509 |
| 486 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { | 510 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { |
| 487 if (!IsDeletingHistoryAllowed()) | 511 if (!IsDeletingHistoryAllowed()) { |
| 512 // This should only be reached during tests. |
| 488 return; | 513 return; |
| 514 } |
| 489 | 515 |
| 490 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); | 516 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); |
| 491 | 517 |
| 492 std::vector<content::DownloadItem*> downloads; | 518 std::vector<content::DownloadItem*> downloads; |
| 493 if (GetMainNotifierManager()) | 519 if (GetMainNotifierManager()) |
| 494 GetMainNotifierManager()->GetAllDownloads(&downloads); | 520 GetMainNotifierManager()->GetAllDownloads(&downloads); |
| 495 if (original_notifier_ && original_notifier_->GetManager()) | 521 if (original_notifier_ && original_notifier_->GetManager()) |
| 496 original_notifier_->GetManager()->GetAllDownloads(&downloads); | 522 original_notifier_->GetManager()->GetAllDownloads(&downloads); |
| 497 RemoveDownloads(downloads); | 523 RemoveDownloads(downloads); |
| 498 } | 524 } |
| 499 | 525 |
| 500 void DownloadsDOMHandler::RemoveDownloads( | 526 void DownloadsDOMHandler::RemoveDownloads( |
| 501 const std::vector<content::DownloadItem*>& to_remove) { | 527 const std::vector<content::DownloadItem*>& to_remove) { |
| 502 std::set<uint32> ids; | 528 std::set<uint32> ids; |
| 529 |
| 503 for (auto* download : to_remove) { | 530 for (auto* download : to_remove) { |
| 504 DownloadItemModel item_model(download); | 531 DownloadItemModel item_model(download); |
| 505 if (!item_model.ShouldShowInShelf() || | 532 if (!item_model.ShouldShowInShelf() || |
| 506 download->GetState() == content::DownloadItem::IN_PROGRESS) { | 533 download->GetState() == content::DownloadItem::IN_PROGRESS) { |
| 507 continue; | 534 continue; |
| 508 } | 535 } |
| 509 | 536 |
| 510 item_model.SetShouldShowInShelf(false); | 537 item_model.SetShouldShowInShelf(false); |
| 511 ids.insert(download->GetId()); | 538 ids.insert(download->GetId()); |
| 512 download->UpdateObservers(); | 539 download->UpdateObservers(); |
| 513 } | 540 } |
| 541 |
| 514 if (!ids.empty()) | 542 if (!ids.empty()) |
| 515 removals_.push_back(ids); | 543 removals_.push_back(ids); |
| 516 } | 544 } |
| 517 | 545 |
| 518 void DownloadsDOMHandler::HandleOpenDownloadsFolder( | 546 void DownloadsDOMHandler::HandleOpenDownloadsFolder( |
| 519 const base::ListValue* args) { | 547 const base::ListValue* args) { |
| 520 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); | 548 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); |
| 521 content::DownloadManager* manager = main_notifier_.GetManager(); | 549 content::DownloadManager* manager = main_notifier_.GetManager(); |
| 522 if (manager) { | 550 if (manager) { |
| 523 platform_util::OpenItem( | 551 platform_util::OpenItem( |
| 524 Profile::FromBrowserContext(manager->GetBrowserContext()), | 552 Profile::FromBrowserContext(manager->GetBrowserContext()), |
| 525 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); | 553 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); |
| 526 } | 554 } |
| 527 } | 555 } |
| 528 | 556 |
| 529 // DownloadsDOMHandler, private: ---------------------------------------------- | 557 // DownloadsDOMHandler, private: ---------------------------------------------- |
| 530 | 558 |
| 531 void DownloadsDOMHandler::ScheduleSendCurrentDownloads() { | 559 void DownloadsDOMHandler::ScheduleSendCurrentDownloads() { |
| 532 // Don't call SendCurrentDownloads() every time anything changes. Batch them | 560 // Don't call SendCurrentDownloads() every time anything changes. Batch them |
| 533 // together instead. This may handle hundreds of OnDownloadDestroyed() calls | 561 // together instead. This may handle hundreds of OnDownloadDestroyed() calls |
| 534 // in a single UI message loop iteration when the user Clears All downloads. | 562 // in a single UI message loop iteration when the user Clears All downloads. |
| 535 if (update_scheduled_) | 563 if (update_scheduled_) |
| 536 return; | 564 return; |
| 565 |
| 537 update_scheduled_ = true; | 566 update_scheduled_ = true; |
| 567 |
| 538 BrowserThread::PostTask( | 568 BrowserThread::PostTask( |
| 539 BrowserThread::UI, FROM_HERE, | 569 BrowserThread::UI, FROM_HERE, |
| 540 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, | 570 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, |
| 541 weak_ptr_factory_.GetWeakPtr())); | 571 weak_ptr_factory_.GetWeakPtr())); |
| 542 } | 572 } |
| 543 | 573 |
| 544 content::DownloadManager* DownloadsDOMHandler::GetMainNotifierManager() { | 574 content::DownloadManager* DownloadsDOMHandler::GetMainNotifierManager() { |
| 545 return main_notifier_.GetManager(); | 575 return main_notifier_.GetManager(); |
| 546 } | 576 } |
| 547 | 577 |
| 548 void DownloadsDOMHandler::FinalizeRemovals() { | 578 void DownloadsDOMHandler::FinalizeRemovals() { |
| 549 while (!removals_.empty()) { | 579 while (!removals_.empty()) { |
| 550 const std::set<uint32> remove = removals_.back(); | 580 const std::set<uint32> remove = removals_.back(); |
| 551 removals_.pop_back(); | 581 removals_.pop_back(); |
| 552 | 582 |
| 553 for (const auto id : remove) { | 583 for (const auto id : remove) { |
| 554 content::DownloadItem* download = GetDownloadById(id); | 584 content::DownloadItem* download = GetDownloadById(id); |
| 555 if (download) | 585 if (download) |
| 556 download->Remove(); | 586 download->Remove(); |
| 557 } | 587 } |
| 558 } | 588 } |
| 559 } | 589 } |
| 560 | 590 |
| 561 void DownloadsDOMHandler::SendCurrentDownloads() { | 591 void DownloadsDOMHandler::SendCurrentDownloads() { |
| 562 update_scheduled_ = false; | 592 update_scheduled_ = false; |
| 593 |
| 563 content::DownloadManager::DownloadVector all_items, filtered_items; | 594 content::DownloadManager::DownloadVector all_items, filtered_items; |
| 564 if (main_notifier_.GetManager()) { | 595 if (main_notifier_.GetManager()) { |
| 565 main_notifier_.GetManager()->GetAllDownloads(&all_items); | 596 main_notifier_.GetManager()->GetAllDownloads(&all_items); |
| 566 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); | 597 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); |
| 567 } | 598 } |
| 568 if (original_notifier_.get() && original_notifier_->GetManager()) { | 599 if (original_notifier_ && original_notifier_->GetManager()) { |
| 569 original_notifier_->GetManager()->GetAllDownloads(&all_items); | 600 original_notifier_->GetManager()->GetAllDownloads(&all_items); |
| 570 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); | 601 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); |
| 571 } | 602 } |
| 603 |
| 572 DownloadQuery query; | 604 DownloadQuery query; |
| 573 if (search_terms_ && !search_terms_->empty()) { | 605 if (search_terms_ && !search_terms_->empty()) |
| 574 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_.get()); | 606 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_); |
| 575 } | |
| 576 query.AddFilter(base::Bind(&IsDownloadDisplayable)); | 607 query.AddFilter(base::Bind(&IsDownloadDisplayable)); |
| 577 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); | 608 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); |
| 578 query.Limit(kMaxDownloads); | 609 query.Limit(kMaxDownloads); |
| 579 query.Search(all_items.begin(), all_items.end(), &filtered_items); | 610 query.Search(all_items.begin(), all_items.end(), &filtered_items); |
| 611 |
| 580 base::ListValue results_value; | 612 base::ListValue results_value; |
| 581 for (content::DownloadManager::DownloadVector::iterator | 613 for (auto* item : filtered_items) { |
| 582 iter = filtered_items.begin(); iter != filtered_items.end(); ++iter) { | |
| 583 results_value.Append(CreateDownloadItemValue( | 614 results_value.Append(CreateDownloadItemValue( |
| 584 *iter, | 615 item, |
| 585 (original_notifier_.get() && | 616 original_notifier_ && main_notifier_.GetManager() && |
| 586 main_notifier_.GetManager() && | 617 main_notifier_.GetManager()->GetDownload(item->GetId()) == item)); |
| 587 (main_notifier_.GetManager()->GetDownload((*iter)->GetId()) == | |
| 588 *iter)))); | |
| 589 } | 618 } |
| 590 CallDownloadsList(results_value); | 619 CallUpdateAll(results_value); |
| 591 } | 620 } |
| 592 | 621 |
| 593 void DownloadsDOMHandler::ShowDangerPrompt( | 622 void DownloadsDOMHandler::ShowDangerPrompt( |
| 594 content::DownloadItem* dangerous_item) { | 623 content::DownloadItem* dangerous_item) { |
| 595 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create( | 624 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create( |
| 596 dangerous_item, | 625 dangerous_item, |
| 597 GetWebUIWebContents(), | 626 GetWebUIWebContents(), |
| 598 false, | 627 false, |
| 599 base::Bind(&DownloadsDOMHandler::DangerPromptDone, | 628 base::Bind(&DownloadsDOMHandler::DangerPromptDone, |
| 600 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId())); | 629 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 612 if (!item && original_notifier_.get() && original_notifier_->GetManager()) | 641 if (!item && original_notifier_.get() && original_notifier_->GetManager()) |
| 613 item = original_notifier_->GetManager()->GetDownload(download_id); | 642 item = original_notifier_->GetManager()->GetDownload(download_id); |
| 614 if (!item || item->IsDone()) | 643 if (!item || item->IsDone()) |
| 615 return; | 644 return; |
| 616 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS); | 645 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS); |
| 617 item->ValidateDangerousDownload(); | 646 item->ValidateDangerousDownload(); |
| 618 } | 647 } |
| 619 | 648 |
| 620 bool DownloadsDOMHandler::IsDeletingHistoryAllowed() { | 649 bool DownloadsDOMHandler::IsDeletingHistoryAllowed() { |
| 621 content::DownloadManager* manager = main_notifier_.GetManager(); | 650 content::DownloadManager* manager = main_notifier_.GetManager(); |
| 622 return (manager && | 651 return manager && |
| 623 Profile::FromBrowserContext(manager->GetBrowserContext())-> | 652 Profile::FromBrowserContext(manager->GetBrowserContext())-> |
| 624 GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory)); | 653 GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory); |
| 625 } | 654 } |
| 626 | 655 |
| 627 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( | 656 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( |
| 628 const base::ListValue* args) { | 657 const base::ListValue* args) { |
| 629 std::string download_id; | 658 std::string download_id; |
| 630 if (!args->GetString(0, &download_id)) { | 659 if (!args->GetString(0, &download_id)) { |
| 631 NOTREACHED(); | 660 NOTREACHED(); |
| 632 return nullptr; | 661 return nullptr; |
| 633 } | 662 } |
| 634 | 663 |
| 635 uint64 id; | 664 uint64 id; |
| 636 if (!base::StringToUint64(download_id, &id)) { | 665 if (!base::StringToUint64(download_id, &id)) { |
| 637 NOTREACHED(); | 666 NOTREACHED(); |
| 638 return nullptr; | 667 return nullptr; |
| 639 } | 668 } |
| 640 | 669 |
| 641 return GetDownloadById(static_cast<uint32>(id)); | 670 return GetDownloadById(static_cast<uint32>(id)); |
| 642 } | 671 } |
| 643 | 672 |
| 644 content::DownloadItem* DownloadsDOMHandler::GetDownloadById(uint32 id) { | 673 content::DownloadItem* DownloadsDOMHandler::GetDownloadById(uint32 id) { |
| 645 content::DownloadItem* item = NULL; | 674 content::DownloadItem* item = NULL; |
| 646 if (GetMainNotifierManager()) | 675 if (GetMainNotifierManager()) |
| 647 item = GetMainNotifierManager()->GetDownload(id); | 676 item = GetMainNotifierManager()->GetDownload(id); |
| 648 if (!item && original_notifier_.get() && original_notifier_->GetManager()) | 677 if (!item && original_notifier_ && original_notifier_->GetManager()) |
| 649 item = original_notifier_->GetManager()->GetDownload(id); | 678 item = original_notifier_->GetManager()->GetDownload(id); |
| 650 return item; | 679 return item; |
| 651 } | 680 } |
| 652 | 681 |
| 653 content::WebContents* DownloadsDOMHandler::GetWebUIWebContents() { | 682 content::WebContents* DownloadsDOMHandler::GetWebUIWebContents() { |
| 654 return web_ui()->GetWebContents(); | 683 return web_ui()->GetWebContents(); |
| 655 } | 684 } |
| 656 | 685 |
| 657 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { | 686 void DownloadsDOMHandler::CallUpdateAll(const base::ListValue& list) { |
| 658 web_ui()->CallJavascriptFunction("downloadsList", downloads); | 687 web_ui()->CallJavascriptFunction("downloads.Manager.updateAll", list); |
| 659 } | 688 } |
| 660 | 689 |
| 661 void DownloadsDOMHandler::CallDownloadUpdated( | 690 void DownloadsDOMHandler::CallUpdateItem(const base::DictionaryValue& item) { |
| 662 const base::ListValue& download_item) { | 691 web_ui()->CallJavascriptFunction("downloads.Manager.updateItem", item); |
| 663 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); | |
| 664 } | 692 } |
| OLD | NEW |