Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/ui/webui/downloads_dom_handler.cc

Issue 966983002: downloads: clicking "remove" on chrome://downloads should also hide shelf item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/download/download_shelf_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 14 matching lines...) Expand all
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/download/download_crx_util.h" 27 #include "chrome/browser/download/download_crx_util.h"
28 #include "chrome/browser/download/download_danger_prompt.h" 28 #include "chrome/browser/download/download_danger_prompt.h"
29 #include "chrome/browser/download/download_history.h" 29 #include "chrome/browser/download/download_history.h"
30 #include "chrome/browser/download/download_item_model.h" 30 #include "chrome/browser/download/download_item_model.h"
31 #include "chrome/browser/download/download_prefs.h" 31 #include "chrome/browser/download/download_prefs.h"
32 #include "chrome/browser/download/download_query.h" 32 #include "chrome/browser/download/download_query.h"
33 #include "chrome/browser/download/download_service.h" 33 #include "chrome/browser/download/download_service.h"
34 #include "chrome/browser/download/download_service_factory.h" 34 #include "chrome/browser/download/download_service_factory.h"
35 #include "chrome/browser/download/download_shelf.h"
35 #include "chrome/browser/download/drag_download_item.h" 36 #include "chrome/browser/download/drag_download_item.h"
36 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 37 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
37 #include "chrome/browser/extensions/extension_service.h" 38 #include "chrome/browser/extensions/extension_service.h"
38 #include "chrome/browser/platform_util.h" 39 #include "chrome/browser/platform_util.h"
39 #include "chrome/browser/profiles/profile.h" 40 #include "chrome/browser/profiles/profile.h"
41 #include "chrome/browser/ui/browser_finder.h"
42 #include "chrome/browser/ui/browser_window.h"
40 #include "chrome/browser/ui/webui/fileicon_source.h" 43 #include "chrome/browser/ui/webui/fileicon_source.h"
41 #include "chrome/common/pref_names.h" 44 #include "chrome/common/pref_names.h"
42 #include "chrome/common/url_constants.h" 45 #include "chrome/common/url_constants.h"
43 #include "content/public/browser/browser_thread.h" 46 #include "content/public/browser/browser_thread.h"
44 #include "content/public/browser/download_item.h" 47 #include "content/public/browser/download_item.h"
45 #include "content/public/browser/url_data_source.h" 48 #include "content/public/browser/url_data_source.h"
46 #include "content/public/browser/user_metrics.h" 49 #include "content/public/browser/user_metrics.h"
47 #include "content/public/browser/web_contents.h" 50 #include "content/public/browser/web_contents.h"
48 #include "content/public/browser/web_ui.h" 51 #include "content/public/browser/web_ui.h"
49 #include "extensions/browser/extension_system.h" 52 #include "extensions/browser/extension_system.h"
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (GetMainNotifierManager()) 538 if (GetMainNotifierManager())
536 GetMainNotifierManager()->GetAllDownloads(&downloads); 539 GetMainNotifierManager()->GetAllDownloads(&downloads);
537 if (original_notifier_ && original_notifier_->GetManager()) 540 if (original_notifier_ && original_notifier_->GetManager())
538 original_notifier_->GetManager()->GetAllDownloads(&downloads); 541 original_notifier_->GetManager()->GetAllDownloads(&downloads);
539 RemoveDownloads(downloads); 542 RemoveDownloads(downloads);
540 } 543 }
541 544
542 void DownloadsDOMHandler::RemoveDownloads( 545 void DownloadsDOMHandler::RemoveDownloads(
543 const std::vector<content::DownloadItem*>& to_remove) { 546 const std::vector<content::DownloadItem*>& to_remove) {
544 std::set<uint32> ids; 547 std::set<uint32> ids;
548
549 DownloadShelf* shelf = nullptr;
550
551 // |web_contents| is NULL in tests.
552 content::WebContents* web_contents = GetWebUIWebContents();
553 if (web_contents) {
554 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
555 shelf = browser->window()->GetDownloadShelf();
asanka 2015/02/28 00:58:52 This might not work since the shelf could be on a
556 }
557
545 for (auto* download : to_remove) { 558 for (auto* download : to_remove) {
546 if (IsRemoved(*download) || 559 if (IsRemoved(*download) ||
547 download->GetState() == content::DownloadItem::IN_PROGRESS) { 560 download->GetState() == content::DownloadItem::IN_PROGRESS) {
548 continue; 561 continue;
549 } 562 }
550 563
551 DownloadsDOMHandlerData::Create(download)->set_is_removed(true); 564 DownloadsDOMHandlerData::Create(download)->set_is_removed(true);
552 ids.insert(download->GetId()); 565 ids.insert(download->GetId());
553 download->UpdateObservers(); 566 download->UpdateObservers();
567
568 if (shelf)
569 shelf->RemoveDownload(download);
554 } 570 }
571
555 removes_.push_back(ids); 572 removes_.push_back(ids);
556 } 573 }
557 574
558 void DownloadsDOMHandler::HandleOpenDownloadsFolder( 575 void DownloadsDOMHandler::HandleOpenDownloadsFolder(
559 const base::ListValue* args) { 576 const base::ListValue* args) {
560 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER); 577 CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_OPEN_FOLDER);
561 content::DownloadManager* manager = main_notifier_.GetManager(); 578 content::DownloadManager* manager = main_notifier_.GetManager();
562 if (manager) { 579 if (manager) {
563 platform_util::OpenItem( 580 platform_util::OpenItem(
564 Profile::FromBrowserContext(manager->GetBrowserContext()), 581 Profile::FromBrowserContext(manager->GetBrowserContext()),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 699 }
683 700
684 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) { 701 void DownloadsDOMHandler::CallDownloadsList(const base::ListValue& downloads) {
685 web_ui()->CallJavascriptFunction("downloadsList", downloads); 702 web_ui()->CallJavascriptFunction("downloadsList", downloads);
686 } 703 }
687 704
688 void DownloadsDOMHandler::CallDownloadUpdated( 705 void DownloadsDOMHandler::CallDownloadUpdated(
689 const base::ListValue& download_item) { 706 const base::ListValue& download_item) {
690 web_ui()->CallJavascriptFunction("downloadUpdated", download_item); 707 web_ui()->CallJavascriptFunction("downloadUpdated", download_item);
691 } 708 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/download/download_shelf_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698