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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 web_ui()->RegisterMessageCallback("clearAll", | 316 web_ui()->RegisterMessageCallback("clearAll", |
316 base::Bind(&DownloadsDOMHandler::HandleClearAll, | 317 base::Bind(&DownloadsDOMHandler::HandleClearAll, |
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 new_downloads_.insert(download_item->GetId()); |
asanka
2015/03/10 04:15:51
If OnDownloadCreated() is called for a download re
Dan Beam
2015/03/10 05:41:02
added back the original code
| |
327 } | 328 } |
328 | 329 |
329 void DownloadsDOMHandler::OnDownloadUpdated( | 330 void DownloadsDOMHandler::OnDownloadUpdated( |
330 content::DownloadManager* manager, | 331 content::DownloadManager* manager, |
331 content::DownloadItem* download_item) { | 332 content::DownloadItem* download_item) { |
332 if (IsDownloadDisplayable(*download_item)) { | 333 const uint32 download_id = download_item->GetId(); |
333 if (search_terms_ && !search_terms_->empty()) { | 334 if (new_downloads_.count(download_id)) { |
334 // Don't CallDownloadUpdated() if download_item doesn't match | 335 // New downloads must be sent before they can be updated. |
335 // search_terms_. | 336 if (!IsDownloadDisplayable(*download_item)) { |
336 // TODO(benjhayden): Consider splitting MatchesQuery() out to a function. | 337 // Item isn't ready to be displayed yet. Wait until it is. |
337 content::DownloadManager::DownloadVector all_items, filtered_items; | 338 return; |
338 all_items.push_back(download_item); | |
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 } | 339 } |
345 base::ListValue results_value; | 340 // Send rather than schedule as this must happen before |CallUpdateItem|. |
346 results_value.Append(CreateDownloadItemValue( | 341 SendCurrentDownloads(); |
asanka
2015/03/10 04:15:51
If we go this route, then a subsequent CallUpdateI
Dan Beam
2015/03/10 05:41:03
Done.
| |
347 download_item, | 342 new_downloads_.erase(download_id); |
348 (original_notifier_.get() && | 343 } |
349 (manager == main_notifier_.GetManager())))); | 344 |
350 CallDownloadUpdated(results_value); | 345 if (DownloadItemModel(download_item).IsBeingRevived() || |
351 } else { | 346 !IsDownloadDisplayable(*download_item)) { |
asanka
2015/03/10 04:15:51
IsDownloadDisplayable() could be returning false f
Dan Beam
2015/03/10 05:41:03
this matches what the current code does
asanka
2015/03/11 19:57:49
True, but it's still going to be quite expensive t
| |
347 // A download will be shown or hidden by this update. Resend the list. | |
352 ScheduleSendCurrentDownloads(); | 348 ScheduleSendCurrentDownloads(); |
349 return; | |
353 } | 350 } |
351 | |
352 if (search_terms_ && !search_terms_->empty()) { | |
353 // Don't CallUpdateItem() if download_item doesn't match | |
354 // search_terms_. | |
355 // TODO(benjhayden): Consider splitting MatchesQuery() out to a function. | |
356 content::DownloadManager::DownloadVector all_items, filtered_items; | |
357 all_items.push_back(download_item); | |
358 DownloadQuery query; | |
359 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_); | |
360 query.Search(all_items.begin(), all_items.end(), &filtered_items); | |
361 if (filtered_items.empty()) | |
362 return; | |
363 } | |
364 | |
365 scoped_ptr<base::DictionaryValue> item(CreateDownloadItemValue( | |
366 download_item, | |
367 original_notifier_ && manager == main_notifier_.GetManager())); | |
368 CallUpdateItem(*item); | |
354 } | 369 } |
355 | 370 |
356 void DownloadsDOMHandler::OnDownloadRemoved( | 371 void DownloadsDOMHandler::OnDownloadRemoved( |
357 content::DownloadManager* manager, | 372 content::DownloadManager* manager, |
358 content::DownloadItem* download_item) { | 373 content::DownloadItem* download_item) { |
359 if (!DownloadItemModel(download_item).ShouldShowInShelf()) | 374 if (!DownloadItemModel(download_item).ShouldShowInShelf()) |
360 return; | 375 return; |
361 | 376 |
362 // This relies on |download_item| being removed from DownloadManager in this | 377 // This relies on |download_item| being removed from DownloadManager in this |
363 // MessageLoop iteration. |download_item| may not have been removed from | 378 // MessageLoop iteration. |download_item| may not have been removed from |
364 // DownloadManager when OnDownloadRemoved() is fired, so bounce off the | 379 // DownloadManager when OnDownloadRemoved() is fired, so bounce off the |
365 // MessageLoop to give it a chance to be removed. SendCurrentDownloads() looks | 380 // 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 | 381 // 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 | 382 // removed. If DownloadManager is ever changed to not immediately remove |
368 // |download_item| from its map when OnDownloadRemoved is sent, then | 383 // |download_item| from its map when OnDownloadRemoved is sent, then |
369 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell | 384 // DownloadsDOMHandler::OnDownloadRemoved() will need to explicitly tell |
370 // SendCurrentDownloads() that |download_item| was removed. A | 385 // SendCurrentDownloads() that |download_item| was removed. A |
371 // SupportsUserData::Data would be the correct way to do this. | 386 // SupportsUserData::Data would be the correct way to do this. |
372 ScheduleSendCurrentDownloads(); | 387 ScheduleSendCurrentDownloads(); |
373 } | 388 } |
374 | 389 |
375 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { | 390 void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { |
376 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); | 391 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); |
377 search_terms_.reset((args && !args->empty()) ? args->DeepCopy() : NULL); | 392 search_terms_.reset(args && !args->empty() ? args->DeepCopy() : NULL); |
378 SendCurrentDownloads(); | 393 SendCurrentDownloads(); |
379 } | 394 } |
380 | 395 |
381 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { | 396 void DownloadsDOMHandler::HandleOpenFile(const base::ListValue* args) { |
382 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); | 397 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FILE); |
383 content::DownloadItem* file = GetDownloadByValue(args); | 398 content::DownloadItem* file = GetDownloadByValue(args); |
384 if (file) | 399 if (file) |
385 file->OpenDownload(); | 400 file->OpenDownload(); |
386 } | 401 } |
387 | 402 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 if (removals_.empty()) | 479 if (removals_.empty()) |
465 return; | 480 return; |
466 | 481 |
467 const std::set<uint32> last_removed_ids = removals_.back(); | 482 const std::set<uint32> last_removed_ids = removals_.back(); |
468 removals_.pop_back(); | 483 removals_.pop_back(); |
469 | 484 |
470 for (auto id : last_removed_ids) { | 485 for (auto id : last_removed_ids) { |
471 content::DownloadItem* download = GetDownloadById(id); | 486 content::DownloadItem* download = GetDownloadById(id); |
472 if (!download) | 487 if (!download) |
473 continue; | 488 continue; |
474 DownloadItemModel(download).SetShouldShowInShelf(true); | 489 |
490 DownloadItemModel model(download); | |
491 model.SetShouldShowInShelf(true); | |
asanka
2015/03/10 04:15:51
Why was this necessary?
Dan Beam
2015/03/10 05:41:02
DownloadsDOMHandler::Handle{Remove,ClearAll}() run
| |
492 model.SetIsBeingRevived(true); | |
asanka
2015/03/10 04:15:51
It seems the only purpose of SetIsBeingRevived() i
Dan Beam
2015/03/10 05:41:02
that would work with only 1 handler.
ALL handlers
| |
493 | |
475 download->UpdateObservers(); | 494 download->UpdateObservers(); |
495 | |
496 model.SetIsBeingRevived(false); | |
476 } | 497 } |
477 } | 498 } |
478 | 499 |
479 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) { | 500 void DownloadsDOMHandler::HandleCancel(const base::ListValue* args) { |
480 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); | 501 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CANCEL); |
481 content::DownloadItem* file = GetDownloadByValue(args); | 502 content::DownloadItem* file = GetDownloadByValue(args); |
482 if (file) | 503 if (file) |
483 file->Cancel(true); | 504 file->Cancel(true); |
484 } | 505 } |
485 | 506 |
486 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { | 507 void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) { |
487 if (!IsDeletingHistoryAllowed()) | 508 if (!IsDeletingHistoryAllowed()) { |
509 // This should only be reached during tests. | |
488 return; | 510 return; |
511 } | |
489 | 512 |
490 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); | 513 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_CLEAR_ALL); |
491 | 514 |
492 std::vector<content::DownloadItem*> downloads; | 515 std::vector<content::DownloadItem*> downloads; |
493 if (GetMainNotifierManager()) | 516 if (GetMainNotifierManager()) |
494 GetMainNotifierManager()->GetAllDownloads(&downloads); | 517 GetMainNotifierManager()->GetAllDownloads(&downloads); |
495 if (original_notifier_ && original_notifier_->GetManager()) | 518 if (original_notifier_ && original_notifier_->GetManager()) |
496 original_notifier_->GetManager()->GetAllDownloads(&downloads); | 519 original_notifier_->GetManager()->GetAllDownloads(&downloads); |
497 RemoveDownloads(downloads); | 520 RemoveDownloads(downloads); |
498 } | 521 } |
499 | 522 |
500 void DownloadsDOMHandler::RemoveDownloads( | 523 void DownloadsDOMHandler::RemoveDownloads( |
501 const std::vector<content::DownloadItem*>& to_remove) { | 524 const std::vector<content::DownloadItem*>& to_remove) { |
502 std::set<uint32> ids; | 525 std::set<uint32> ids; |
526 | |
503 for (auto* download : to_remove) { | 527 for (auto* download : to_remove) { |
504 DownloadItemModel item_model(download); | 528 DownloadItemModel item_model(download); |
505 if (!item_model.ShouldShowInShelf() || | 529 if (!item_model.ShouldShowInShelf() || |
506 download->GetState() == content::DownloadItem::IN_PROGRESS) { | 530 download->GetState() == content::DownloadItem::IN_PROGRESS) { |
507 continue; | 531 continue; |
508 } | 532 } |
509 | 533 |
510 item_model.SetShouldShowInShelf(false); | 534 item_model.SetShouldShowInShelf(false); |
511 ids.insert(download->GetId()); | 535 ids.insert(download->GetId()); |
512 download->UpdateObservers(); | 536 download->UpdateObservers(); |
513 } | 537 } |
538 | |
514 if (!ids.empty()) | 539 if (!ids.empty()) |
515 removals_.push_back(ids); | 540 removals_.push_back(ids); |
516 } | 541 } |
517 | 542 |
518 void DownloadsDOMHandler::HandleOpenDownloadsFolder( | 543 void DownloadsDOMHandler::HandleOpenDownloadsFolder( |
519 const base::ListValue* args) { | 544 const base::ListValue* args) { |
520 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); | 545 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); |
521 content::DownloadManager* manager = main_notifier_.GetManager(); | 546 content::DownloadManager* manager = main_notifier_.GetManager(); |
522 if (manager) { | 547 if (manager) { |
523 platform_util::OpenItem( | 548 platform_util::OpenItem( |
524 Profile::FromBrowserContext(manager->GetBrowserContext()), | 549 Profile::FromBrowserContext(manager->GetBrowserContext()), |
525 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); | 550 DownloadPrefs::FromDownloadManager(manager)->DownloadPath()); |
526 } | 551 } |
527 } | 552 } |
528 | 553 |
529 // DownloadsDOMHandler, private: ---------------------------------------------- | 554 // DownloadsDOMHandler, private: ---------------------------------------------- |
530 | 555 |
531 void DownloadsDOMHandler::ScheduleSendCurrentDownloads() { | 556 void DownloadsDOMHandler::ScheduleSendCurrentDownloads() { |
532 // Don't call SendCurrentDownloads() every time anything changes. Batch them | 557 // Don't call SendCurrentDownloads() every time anything changes. Batch them |
533 // together instead. This may handle hundreds of OnDownloadDestroyed() calls | 558 // together instead. This may handle hundreds of OnDownloadDestroyed() calls |
534 // in a single UI message loop iteration when the user Clears All downloads. | 559 // in a single UI message loop iteration when the user Clears All downloads. |
535 if (update_scheduled_) | 560 if (update_scheduled_) |
536 return; | 561 return; |
562 | |
537 update_scheduled_ = true; | 563 update_scheduled_ = true; |
564 | |
538 BrowserThread::PostTask( | 565 BrowserThread::PostTask( |
539 BrowserThread::UI, FROM_HERE, | 566 BrowserThread::UI, FROM_HERE, |
540 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, | 567 base::Bind(&DownloadsDOMHandler::SendCurrentDownloads, |
541 weak_ptr_factory_.GetWeakPtr())); | 568 weak_ptr_factory_.GetWeakPtr())); |
542 } | 569 } |
543 | 570 |
544 content::DownloadManager* DownloadsDOMHandler::GetMainNotifierManager() { | 571 content::DownloadManager* DownloadsDOMHandler::GetMainNotifierManager() { |
545 return main_notifier_.GetManager(); | 572 return main_notifier_.GetManager(); |
546 } | 573 } |
547 | 574 |
548 void DownloadsDOMHandler::FinalizeRemovals() { | 575 void DownloadsDOMHandler::FinalizeRemovals() { |
549 while (!removals_.empty()) { | 576 while (!removals_.empty()) { |
550 const std::set<uint32> remove = removals_.back(); | 577 const std::set<uint32> remove = removals_.back(); |
551 removals_.pop_back(); | 578 removals_.pop_back(); |
552 | 579 |
553 for (const auto id : remove) { | 580 for (const auto id : remove) { |
554 content::DownloadItem* download = GetDownloadById(id); | 581 content::DownloadItem* download = GetDownloadById(id); |
555 if (download) | 582 if (download) |
556 download->Remove(); | 583 download->Remove(); |
557 } | 584 } |
558 } | 585 } |
559 } | 586 } |
560 | 587 |
561 void DownloadsDOMHandler::SendCurrentDownloads() { | 588 void DownloadsDOMHandler::SendCurrentDownloads() { |
562 update_scheduled_ = false; | 589 update_scheduled_ = false; |
590 | |
563 content::DownloadManager::DownloadVector all_items, filtered_items; | 591 content::DownloadManager::DownloadVector all_items, filtered_items; |
564 if (main_notifier_.GetManager()) { | 592 if (main_notifier_.GetManager()) { |
565 main_notifier_.GetManager()->GetAllDownloads(&all_items); | 593 main_notifier_.GetManager()->GetAllDownloads(&all_items); |
566 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); | 594 main_notifier_.GetManager()->CheckForHistoryFilesRemoval(); |
567 } | 595 } |
568 if (original_notifier_.get() && original_notifier_->GetManager()) { | 596 if (original_notifier_ && original_notifier_->GetManager()) { |
569 original_notifier_->GetManager()->GetAllDownloads(&all_items); | 597 original_notifier_->GetManager()->GetAllDownloads(&all_items); |
570 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); | 598 original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); |
571 } | 599 } |
600 | |
572 DownloadQuery query; | 601 DownloadQuery query; |
573 if (search_terms_ && !search_terms_->empty()) { | 602 if (search_terms_ && !search_terms_->empty()) |
574 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_.get()); | 603 query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_); |
575 } | |
576 query.AddFilter(base::Bind(&IsDownloadDisplayable)); | 604 query.AddFilter(base::Bind(&IsDownloadDisplayable)); |
577 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); | 605 query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); |
578 query.Limit(kMaxDownloads); | 606 query.Limit(kMaxDownloads); |
579 query.Search(all_items.begin(), all_items.end(), &filtered_items); | 607 query.Search(all_items.begin(), all_items.end(), &filtered_items); |
608 | |
580 base::ListValue results_value; | 609 base::ListValue results_value; |
581 for (content::DownloadManager::DownloadVector::iterator | 610 for (auto it = filtered_items.begin(); it != filtered_items.end(); ++it) { |
asanka
2015/03/10 04:15:51
Use a range based for instead.
Dan Beam
2015/03/10 05:41:02
Done.
| |
582 iter = filtered_items.begin(); iter != filtered_items.end(); ++iter) { | |
583 results_value.Append(CreateDownloadItemValue( | 611 results_value.Append(CreateDownloadItemValue( |
584 *iter, | 612 *it, |
585 (original_notifier_.get() && | 613 original_notifier_ && main_notifier_.GetManager() && |
586 main_notifier_.GetManager() && | 614 main_notifier_.GetManager()->GetDownload((*it)->GetId()) == *it)); |
587 (main_notifier_.GetManager()->GetDownload((*iter)->GetId()) == | |
588 *iter)))); | |
589 } | 615 } |
590 CallDownloadsList(results_value); | 616 CallUpdateAll(results_value); |
591 } | 617 } |
592 | 618 |
593 void DownloadsDOMHandler::ShowDangerPrompt( | 619 void DownloadsDOMHandler::ShowDangerPrompt( |
594 content::DownloadItem* dangerous_item) { | 620 content::DownloadItem* dangerous_item) { |
595 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create( | 621 DownloadDangerPrompt* danger_prompt = DownloadDangerPrompt::Create( |
596 dangerous_item, | 622 dangerous_item, |
597 GetWebUIWebContents(), | 623 GetWebUIWebContents(), |
598 false, | 624 false, |
599 base::Bind(&DownloadsDOMHandler::DangerPromptDone, | 625 base::Bind(&DownloadsDOMHandler::DangerPromptDone, |
600 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId())); | 626 weak_ptr_factory_.GetWeakPtr(), dangerous_item->GetId())); |
(...skipping 11 matching lines...) Expand all Loading... | |
612 if (!item && original_notifier_.get() && original_notifier_->GetManager()) | 638 if (!item && original_notifier_.get() && original_notifier_->GetManager()) |
613 item = original_notifier_->GetManager()->GetDownload(download_id); | 639 item = original_notifier_->GetManager()->GetDownload(download_id); |
614 if (!item || item->IsDone()) | 640 if (!item || item->IsDone()) |
615 return; | 641 return; |
616 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS); | 642 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_SAVE_DANGEROUS); |
617 item->ValidateDangerousDownload(); | 643 item->ValidateDangerousDownload(); |
618 } | 644 } |
619 | 645 |
620 bool DownloadsDOMHandler::IsDeletingHistoryAllowed() { | 646 bool DownloadsDOMHandler::IsDeletingHistoryAllowed() { |
621 content::DownloadManager* manager = main_notifier_.GetManager(); | 647 content::DownloadManager* manager = main_notifier_.GetManager(); |
622 return (manager && | 648 return manager && |
623 Profile::FromBrowserContext(manager->GetBrowserContext())-> | 649 Profile::FromBrowserContext(manager->GetBrowserContext())-> |
624 GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory)); | 650 GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory); |
625 } | 651 } |
626 | 652 |
627 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( | 653 content::DownloadItem* DownloadsDOMHandler::GetDownloadByValue( |
628 const base::ListValue* args) { | 654 const base::ListValue* args) { |
629 std::string download_id; | 655 std::string download_id; |
630 if (!args->GetString(0, &download_id)) { | 656 if (!args->GetString(0, &download_id)) { |
631 NOTREACHED(); | 657 NOTREACHED(); |
632 return nullptr; | 658 return nullptr; |
633 } | 659 } |
634 | 660 |
635 uint64 id; | 661 uint64 id; |
636 if (!base::StringToUint64(download_id, &id)) { | 662 if (!base::StringToUint64(download_id, &id)) { |
637 NOTREACHED(); | 663 NOTREACHED(); |
638 return nullptr; | 664 return nullptr; |
639 } | 665 } |
640 | 666 |
641 return GetDownloadById(static_cast<uint32>(id)); | 667 return GetDownloadById(static_cast<uint32>(id)); |
642 } | 668 } |
643 | 669 |
644 content::DownloadItem* DownloadsDOMHandler::GetDownloadById(uint32 id) { | 670 content::DownloadItem* DownloadsDOMHandler::GetDownloadById(uint32 id) { |
645 content::DownloadItem* item = NULL; | 671 content::DownloadItem* item = NULL; |
646 if (GetMainNotifierManager()) | 672 if (GetMainNotifierManager()) |
647 item = GetMainNotifierManager()->GetDownload(id); | 673 item = GetMainNotifierManager()->GetDownload(id); |
648 if (!item && original_notifier_.get() && original_notifier_->GetManager()) | 674 if (!item && original_notifier_ && original_notifier_->GetManager()) |
649 item = original_notifier_->GetManager()->GetDownload(id); | 675 item = original_notifier_->GetManager()->GetDownload(id); |
650 return item; | 676 return item; |
651 } | 677 } |
652 | 678 |
653 content::WebContents* DownloadsDOMHandler::GetWebUIWebContents() { | 679 content::WebContents* DownloadsDOMHandler::GetWebUIWebContents() { |
654 return web_ui()->GetWebContents(); | 680 return web_ui()->GetWebContents(); |
655 } | 681 } |
656 | 682 |
657 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { | 683 void DownloadsDOMHandler::CallUpdateAll(const base::ListValue& list) { |
658 web_ui()->CallJavascriptFunction("downloadsList", downloads); | 684 web_ui()->CallJavascriptFunction("downloads.Manager.updateAll", list); |
659 } | 685 } |
660 | 686 |
661 void DownloadsDOMHandler::CallDownloadUpdated( | 687 void DownloadsDOMHandler::CallUpdateItem(const base::DictionaryValue& item) { |
662 const base::ListValue& download_item) { | 688 web_ui()->CallJavascriptFunction("downloads.Manager.updateItem", item); |
663 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); | |
664 } | 689 } |
OLD | NEW |