Commit ab33e9ff authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Download Shelf : Changed DownloadShelfContextMenu to work with DownloadUIModel

Bug: 885322
Change-Id: Id509eb2009958b2532a428abd8db5156a7c026ae
Reviewed-on: https://chromium-review.googlesource.com/1232477
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592667}
parent b81d51e4
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/download/download_shelf_context_menu.h" #include "chrome/browser/download/download_shelf_context_menu.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -15,43 +14,41 @@ ...@@ -15,43 +14,41 @@
#include "chrome/browser/ui/pdf/adobe_reader_info_win.h" #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
#endif #endif
using download::DownloadItem;
bool DownloadShelfContextMenu::WantsContextMenu( bool DownloadShelfContextMenu::WantsContextMenu(
const DownloadItemModel& download_model) { DownloadUIModel* download_model) {
return !download_model.IsDangerous() || download_model.MightBeMalicious(); return !download_model->IsDangerous() || !download_model->MightBeMalicious();
} }
DownloadShelfContextMenu::~DownloadShelfContextMenu() { DownloadShelfContextMenu::~DownloadShelfContextMenu() {
DetachFromDownloadItem(); DetachFromDownloadItem();
} }
DownloadShelfContextMenu::DownloadShelfContextMenu(DownloadItem* download_item) DownloadShelfContextMenu::DownloadShelfContextMenu(DownloadUIModel* download)
: download_item_(download_item), : download_(download),
download_commands_(new DownloadCommands(download_item)) { // TODO(shaktisahu) : Fix DownloadCommands construction.
DCHECK(download_item_); download_commands_(
download_item_->AddObserver(this); new DownloadCommands(download_->GetDownloadCommands())) {
DCHECK(download_);
download_->AddObserver(this);
} }
ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() {
ui::SimpleMenuModel* model = NULL; ui::SimpleMenuModel* model = NULL;
if (!download_item_) if (!download_)
return NULL; return NULL;
DownloadItemModel download_model(download_item_); DCHECK(WantsContextMenu(download_));
DCHECK(WantsContextMenu(download_model));
if (download_model.IsMalicious()) if (download_->IsMalicious())
model = GetMaliciousMenuModel(); model = GetMaliciousMenuModel();
else if (download_model.MightBeMalicious()) else if (download_->MightBeMalicious())
model = GetMaybeMaliciousMenuModel(); model = GetMaybeMaliciousMenuModel();
else if (download_item_->GetState() == DownloadItem::COMPLETE) else if (download_->GetState() == download::DownloadItem::COMPLETE)
model = GetFinishedMenuModel(); model = GetFinishedMenuModel();
else if (download_item_->GetState() == DownloadItem::INTERRUPTED) else if (download_->GetState() == download::DownloadItem::INTERRUPTED)
model = GetInterruptedMenuModel(); model = GetInterruptedMenuModel();
else if (download_item_->IsPaused()) else if (download_->IsPaused())
model = GetInProgressPausedMenuModel(); model = GetInProgressPausedMenuModel();
else else
model = GetInProgressMenuModel(); model = GetInProgressMenuModel();
...@@ -100,7 +97,7 @@ base::string16 DownloadShelfContextMenu::GetLabelForCommandId( ...@@ -100,7 +97,7 @@ base::string16 DownloadShelfContextMenu::GetLabelForCommandId(
switch (static_cast<DownloadCommands::Command>(command_id)) { switch (static_cast<DownloadCommands::Command>(command_id)) {
case DownloadCommands::OPEN_WHEN_COMPLETE: case DownloadCommands::OPEN_WHEN_COMPLETE:
if (download_item_ && !download_item_->IsDone()) if (download_ && !download_->IsDone())
id = IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE; id = IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE;
else else
id = IDS_DOWNLOAD_MENU_OPEN; id = IDS_DOWNLOAD_MENU_OPEN;
...@@ -164,16 +161,15 @@ base::string16 DownloadShelfContextMenu::GetLabelForCommandId( ...@@ -164,16 +161,15 @@ base::string16 DownloadShelfContextMenu::GetLabelForCommandId(
} }
void DownloadShelfContextMenu::DetachFromDownloadItem() { void DownloadShelfContextMenu::DetachFromDownloadItem() {
if (!download_item_) if (!download_)
return; return;
download_commands_.reset(); download_commands_.reset();
download_item_->RemoveObserver(this); download_->RemoveObserver(this);
download_item_ = NULL; download_ = NULL;
} }
void DownloadShelfContextMenu::OnDownloadDestroyed(DownloadItem* download) { void DownloadShelfContextMenu::OnDownloadDestroyed() {
DCHECK(download_item_ == download);
DetachFromDownloadItem(); DetachFromDownloadItem();
} }
......
...@@ -12,28 +12,25 @@ ...@@ -12,28 +12,25 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/download/download_commands.h" #include "chrome/browser/download/download_commands.h"
#include "chrome/browser/download/download_ui_model.h"
#include "components/download/public/common/download_item.h" #include "components/download/public/common/download_item.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
class DownloadItemModel;
// This class is responsible for the download shelf context menu. Platform // This class is responsible for the download shelf context menu. Platform
// specific subclasses are responsible for creating and running the menu. // specific subclasses are responsible for creating and running the menu.
// //
// The DownloadItem corresponding to the context menu is observed for removal or // The DownloadItem corresponding to the context menu is observed for removal or
// destruction. // destruction.
class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate,
public download::DownloadItem::Observer { public DownloadUIModel::Observer {
public: public:
// Only show a context menu for a dangerous download if it is malicious. // Only show a context menu for a dangerous download if it is malicious.
static bool WantsContextMenu(const DownloadItemModel&); static bool WantsContextMenu(DownloadUIModel* download_model);
~DownloadShelfContextMenu() override; ~DownloadShelfContextMenu() override;
download::DownloadItem* download_item() const { return download_item_; }
protected: protected:
explicit DownloadShelfContextMenu(download::DownloadItem* download_item); explicit DownloadShelfContextMenu(DownloadUIModel* download);
// Returns the correct menu model depending on the state of the download item. // Returns the correct menu model depending on the state of the download item.
// Returns NULL if the download was destroyed. // Returns NULL if the download was destroyed.
...@@ -52,8 +49,8 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, ...@@ -52,8 +49,8 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate,
// destroyed or when this object is being destroyed. // destroyed or when this object is being destroyed.
void DetachFromDownloadItem(); void DetachFromDownloadItem();
// download::DownloadItem::Observer // DownloadUIModel::Observer overrides.
void OnDownloadDestroyed(download::DownloadItem* download) override; void OnDownloadDestroyed() override;
ui::SimpleMenuModel* GetInProgressMenuModel(); ui::SimpleMenuModel* GetInProgressMenuModel();
ui::SimpleMenuModel* GetInProgressPausedMenuModel(); ui::SimpleMenuModel* GetInProgressPausedMenuModel();
...@@ -72,7 +69,7 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, ...@@ -72,7 +69,7 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate,
std::unique_ptr<ui::SimpleMenuModel> malicious_download_menu_model_; std::unique_ptr<ui::SimpleMenuModel> malicious_download_menu_model_;
// Information source. // Information source.
download::DownloadItem* download_item_; DownloadUIModel* download_;
std::unique_ptr<DownloadCommands> download_commands_; std::unique_ptr<DownloadCommands> download_commands_;
DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu); DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu);
......
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
DownloadShelfContextMenuView::DownloadShelfContextMenuView( DownloadShelfContextMenuView::DownloadShelfContextMenuView(
DownloadItemView* download_item_view) DownloadItemView* download_item_view)
// TODO(shaktisahu): Fix this. This will not work for offline item. : DownloadShelfContextMenu(download_item_view->model()),
: DownloadShelfContextMenu(download_item_view->model()->download()),
download_item_view_(download_item_view) {} download_item_view_(download_item_view) {}
DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {} DownloadShelfContextMenuView::~DownloadShelfContextMenuView() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment