| Index: chrome/browser/download/download_shelf_context_menu.cc
|
| diff --git a/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc
|
| index 0c87b3d88cb56d55f3587fbaddde801f243adeff..9deb380056440f89352f99c39174a43516e358a1 100644
|
| --- a/chrome/browser/download/download_shelf_context_menu.cc
|
| +++ b/chrome/browser/download/download_shelf_context_menu.cc
|
| @@ -5,26 +5,11 @@
|
| #include "chrome/browser/download/download_shelf_context_menu.h"
|
|
|
| #include "base/command_line.h"
|
| -#include "chrome/browser/browser_process.h"
|
| -#include "chrome/browser/download/download_crx_util.h"
|
| #include "chrome/browser/download/download_item_model.h"
|
| -#include "chrome/browser/download/download_prefs.h"
|
| -#include "chrome/browser/download/download_target_determiner.h"
|
| -#include "chrome/browser/safe_browsing/download_protection_service.h"
|
| -#include "chrome/browser/safe_browsing/safe_browsing_service.h"
|
| -#include "chrome/common/url_constants.h"
|
| -#include "chrome/grit/generated_resources.h"
|
| -#include "content/public/browser/download_item.h"
|
| -#include "content/public/browser/download_manager.h"
|
| -#include "content/public/browser/page_navigator.h"
|
| #include "content/public/common/content_switches.h"
|
| #include "extensions/common/extension.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| -#if defined(OS_WIN)
|
| -#include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
|
| -#endif
|
| -
|
| using content::DownloadItem;
|
|
|
| namespace {
|
| @@ -45,17 +30,10 @@ DownloadShelfContextMenu::DownloadShelfContextMenu(
|
| DownloadItem* download_item,
|
| content::PageNavigator* navigator)
|
| : download_item_(download_item),
|
| + download_command_(download_item),
|
| navigator_(navigator) {
|
| DCHECK(download_item_);
|
| download_item_->AddObserver(this);
|
| -
|
| -#if defined(OS_WIN)
|
| - is_adobe_pdf_reader_up_to_date_ = false;
|
| - if (IsDownloadPdf() && IsAdobeReaderDefaultPDFViewer()) {
|
| - is_adobe_pdf_reader_up_to_date_ =
|
| - DownloadTargetDeterminer::IsAdobeReaderUpToDate();
|
| - }
|
| -#endif // defined(OS_WIN)
|
| }
|
|
|
| ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() {
|
| @@ -83,146 +61,23 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() {
|
| }
|
|
|
| bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const {
|
| - if (!download_item_)
|
| - return false;
|
| -
|
| - switch (static_cast<ContextMenuCommands>(command_id)) {
|
| - case SHOW_IN_FOLDER:
|
| - return download_item_->CanShowInFolder();
|
| - case OPEN_WHEN_COMPLETE:
|
| - case PLATFORM_OPEN:
|
| - return download_item_->CanOpenDownload() &&
|
| - !download_crx_util::IsExtensionDownload(*download_item_);
|
| - case ALWAYS_OPEN_TYPE:
|
| - // For temporary downloads, the target filename might be a temporary
|
| - // filename. Don't base an "Always open" decision based on it. Also
|
| - // exclude extensions.
|
| - return download_item_->CanOpenDownload() &&
|
| - !download_crx_util::IsExtensionDownload(*download_item_);
|
| - case CANCEL:
|
| - return !download_item_->IsDone();
|
| - case TOGGLE_PAUSE:
|
| - return !download_item_->IsDone();
|
| - case DISCARD:
|
| - case KEEP:
|
| - case LEARN_MORE_SCANNING:
|
| - case LEARN_MORE_INTERRUPTED:
|
| - return true;
|
| - }
|
| - NOTREACHED();
|
| - return false;
|
| + return download_command_.IsCommandIdEnabled(
|
| + static_cast<DownloadCommand::Commands>(command_id));
|
| }
|
|
|
| bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const {
|
| - if (!download_item_)
|
| - return false;
|
| -
|
| - switch (command_id) {
|
| - case OPEN_WHEN_COMPLETE:
|
| - return download_item_->GetOpenWhenComplete() ||
|
| - download_crx_util::IsExtensionDownload(*download_item_);
|
| - case ALWAYS_OPEN_TYPE:
|
| -#if defined(OS_WIN) || defined(OS_LINUX) || \
|
| - (defined(OS_MACOSX) && !defined(OS_IOS))
|
| - if (CanOpenPdfInSystemViewer()) {
|
| - DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext(
|
| - download_item_->GetBrowserContext());
|
| - return prefs->ShouldOpenPdfInSystemReader();
|
| - }
|
| -#endif
|
| - return download_item_->ShouldOpenFileBasedOnExtension();
|
| - case TOGGLE_PAUSE:
|
| - return download_item_->IsPaused();
|
| - }
|
| - return false;
|
| + return download_command_.IsCommandIdChecked(
|
| + static_cast<DownloadCommand::Commands>(command_id));
|
| }
|
|
|
| bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const {
|
| - if (!download_item_)
|
| - return false;
|
| -
|
| - if (command_id == PLATFORM_OPEN)
|
| - return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser());
|
| -
|
| - return true;
|
| + return download_command_.IsCommandIdVisible(
|
| + static_cast<DownloadCommand::Commands>(command_id));
|
| }
|
|
|
| void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) {
|
| - if (!download_item_)
|
| - return;
|
| -
|
| - switch (static_cast<ContextMenuCommands>(command_id)) {
|
| - case SHOW_IN_FOLDER:
|
| - download_item_->ShowDownloadInShell();
|
| - break;
|
| - case OPEN_WHEN_COMPLETE:
|
| - download_item_->OpenDownload();
|
| - break;
|
| - case ALWAYS_OPEN_TYPE: {
|
| - bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE);
|
| - DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext(
|
| - download_item_->GetBrowserContext());
|
| -#if defined(OS_WIN) || defined(OS_LINUX) || \
|
| - (defined(OS_MACOSX) && !defined(OS_IOS))
|
| - if (CanOpenPdfInSystemViewer()) {
|
| - prefs->SetShouldOpenPdfInSystemReader(!is_checked);
|
| - DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser(
|
| - is_checked);
|
| - break;
|
| - }
|
| -#endif
|
| - base::FilePath path = download_item_->GetTargetFilePath();
|
| - if (is_checked)
|
| - prefs->DisableAutoOpenBasedOnExtension(path);
|
| - else
|
| - prefs->EnableAutoOpenBasedOnExtension(path);
|
| - break;
|
| - }
|
| - case PLATFORM_OPEN:
|
| - DownloadItemModel(download_item_).OpenUsingPlatformHandler();
|
| - break;
|
| - case CANCEL:
|
| - download_item_->Cancel(true /* Cancelled by user */);
|
| - break;
|
| - case TOGGLE_PAUSE:
|
| - if (download_item_->GetState() == DownloadItem::IN_PROGRESS &&
|
| - !download_item_->IsPaused()) {
|
| - download_item_->Pause();
|
| - } else {
|
| - download_item_->Resume();
|
| - }
|
| - break;
|
| - case DISCARD:
|
| - download_item_->Remove();
|
| - break;
|
| - case KEEP:
|
| - download_item_->ValidateDangerousDownload();
|
| - break;
|
| - case LEARN_MORE_SCANNING: {
|
| -#if defined(FULL_SAFE_BROWSING)
|
| - using safe_browsing::DownloadProtectionService;
|
| - SafeBrowsingService* sb_service =
|
| - g_browser_process->safe_browsing_service();
|
| - DownloadProtectionService* protection_service =
|
| - (sb_service ? sb_service->download_protection_service() : NULL);
|
| - if (protection_service) {
|
| - protection_service->ShowDetailsForDownload(*download_item_, navigator_);
|
| - }
|
| -#else
|
| - // Should only be getting invoked if we are using safe browsing.
|
| - NOTREACHED();
|
| -#endif
|
| - break;
|
| - }
|
| - case LEARN_MORE_INTERRUPTED:
|
| - navigator_->OpenURL(
|
| - content::OpenURLParams(GURL(chrome::kDownloadInterruptedLearnMoreURL),
|
| - content::Referrer(),
|
| - NEW_FOREGROUND_TAB,
|
| - ui::PAGE_TRANSITION_LINK,
|
| - false));
|
| - break;
|
| - }
|
| + download_command_.ExecuteCommand(
|
| + static_cast<DownloadCommand::Commands>(command_id), navigator_);
|
| }
|
|
|
| bool DownloadShelfContextMenu::GetAcceleratorForCommandId(
|
| @@ -231,42 +86,18 @@ bool DownloadShelfContextMenu::GetAcceleratorForCommandId(
|
| }
|
|
|
| bool DownloadShelfContextMenu::IsItemForCommandIdDynamic(int command_id) const {
|
| - return command_id == TOGGLE_PAUSE;
|
| + return false;
|
| }
|
|
|
| base::string16 DownloadShelfContextMenu::GetLabelForCommandId(
|
| int command_id) const {
|
| - switch (static_cast<ContextMenuCommands>(command_id)) {
|
| - case SHOW_IN_FOLDER:
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW);
|
| - case OPEN_WHEN_COMPLETE:
|
| - if (download_item_ && !download_item_->IsDone())
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN);
|
| - case ALWAYS_OPEN_TYPE:
|
| - return l10n_util::GetStringUTF16(GetAlwaysOpenStringId());
|
| - case PLATFORM_OPEN:
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PLATFORM_OPEN);
|
| - case CANCEL:
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL);
|
| - case TOGGLE_PAUSE:
|
| - if (download_item_ &&
|
| - download_item_->GetState() == DownloadItem::IN_PROGRESS &&
|
| - !download_item_->IsPaused())
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
|
| - case DISCARD:
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD);
|
| - case KEEP:
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP);
|
| - case LEARN_MORE_SCANNING:
|
| - return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
|
| - case LEARN_MORE_INTERRUPTED:
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED);
|
| - }
|
| - NOTREACHED();
|
| - return base::string16();
|
| + return l10n_util::GetStringUTF16(GetStringIdForCommand(
|
| + static_cast<DownloadCommand::Commands>(command_id)));
|
| +}
|
| +
|
| +int DownloadShelfContextMenu::GetStringIdForCommand(
|
| + DownloadCommand::Commands command) const {
|
| + return download_command_.GetCommandStringIdForMenu(command);
|
| }
|
|
|
| void DownloadShelfContextMenu::DetachFromDownloadItem() {
|
| @@ -289,17 +120,20 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel() {
|
| in_progress_download_menu_model_.reset(new ui::SimpleMenuModel(this));
|
|
|
| in_progress_download_menu_model_->AddCheckItemWithStringId(
|
| - OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
|
| + DownloadCommand::OPEN_WHEN_COMPLETE,
|
| + GetStringIdForCommand(DownloadCommand::OPEN_WHEN_COMPLETE));
|
| in_progress_download_menu_model_->AddCheckItemWithStringId(
|
| - ALWAYS_OPEN_TYPE, GetAlwaysOpenStringId());
|
| + DownloadCommand::ALWAYS_OPEN_TYPE,
|
| + GetStringIdForCommand(DownloadCommand::ALWAYS_OPEN_TYPE));
|
| in_progress_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
|
| in_progress_download_menu_model_->AddItemWithStringId(
|
| - TOGGLE_PAUSE, IDS_DOWNLOAD_MENU_PAUSE_ITEM);
|
| + DownloadCommand::PAUSE, GetStringIdForCommand(DownloadCommand::PAUSE));
|
| in_progress_download_menu_model_->AddItemWithStringId(
|
| - SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW);
|
| + DownloadCommand::SHOW_IN_FOLDER,
|
| + GetStringIdForCommand(DownloadCommand::SHOW_IN_FOLDER));
|
| in_progress_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
|
| in_progress_download_menu_model_->AddItemWithStringId(
|
| - CANCEL, IDS_DOWNLOAD_MENU_CANCEL);
|
| + DownloadCommand::CANCEL, GetStringIdForCommand(DownloadCommand::CANCEL));
|
|
|
| return in_progress_download_menu_model_.get();
|
| }
|
| @@ -311,17 +145,21 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetFinishedMenuModel() {
|
| finished_download_menu_model_.reset(new ui::SimpleMenuModel(this));
|
|
|
| finished_download_menu_model_->AddItemWithStringId(
|
| - OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN);
|
| + DownloadCommand::OPEN_WHEN_COMPLETE,
|
| + GetStringIdForCommand(DownloadCommand::OPEN_WHEN_COMPLETE));
|
| finished_download_menu_model_->AddCheckItemWithStringId(
|
| - ALWAYS_OPEN_TYPE, GetAlwaysOpenStringId());
|
| + DownloadCommand::ALWAYS_OPEN_TYPE,
|
| + GetStringIdForCommand(DownloadCommand::ALWAYS_OPEN_TYPE));
|
| finished_download_menu_model_->AddItemWithStringId(
|
| - PLATFORM_OPEN, IDS_DOWNLOAD_MENU_PLATFORM_OPEN);
|
| + DownloadCommand::PLATFORM_OPEN,
|
| + GetStringIdForCommand(DownloadCommand::PLATFORM_OPEN));
|
| finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
|
| finished_download_menu_model_->AddItemWithStringId(
|
| - SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW);
|
| + DownloadCommand::SHOW_IN_FOLDER,
|
| + GetStringIdForCommand(DownloadCommand::SHOW_IN_FOLDER));
|
| finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
|
| finished_download_menu_model_->AddItemWithStringId(
|
| - CANCEL, IDS_DOWNLOAD_MENU_CANCEL);
|
| + DownloadCommand::CANCEL, GetStringIdForCommand(DownloadCommand::CANCEL));
|
|
|
| return finished_download_menu_model_.get();
|
| }
|
| @@ -341,19 +179,22 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() {
|
|
|
| if (IsDownloadResumptionEnabled()) {
|
| interrupted_download_menu_model_->AddItemWithStringId(
|
| - TOGGLE_PAUSE, IDS_DOWNLOAD_MENU_RESUME_ITEM);
|
| + DownloadCommand::RESUME,
|
| + GetStringIdForCommand(DownloadCommand::RESUME));
|
| }
|
| #if defined(OS_WIN)
|
| // The Help Center article is currently Windows specific.
|
| // TODO(asanka): Enable this for other platforms when the article is expanded
|
| // for other platforms.
|
| interrupted_download_menu_model_->AddItemWithStringId(
|
| - LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED);
|
| + DownloadCommand::LEARN_MORE_INTERRUPTED,
|
| + GetStringIdForCommand(DownloadCommand::LEARN_MORE_INTERRUPTED));
|
| #endif
|
| if (IsDownloadResumptionEnabled()) {
|
| interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
|
| interrupted_download_menu_model_->AddItemWithStringId(
|
| - CANCEL, IDS_DOWNLOAD_MENU_CANCEL);
|
| + DownloadCommand::CANCEL,
|
| + GetStringIdForCommand(DownloadCommand::CANCEL));
|
| }
|
|
|
| return interrupted_download_menu_model_.get();
|
| @@ -366,10 +207,12 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaybeMaliciousMenuModel() {
|
| maybe_malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this));
|
|
|
| maybe_malicious_download_menu_model_->AddItemWithStringId(
|
| - KEEP, IDS_DOWNLOAD_MENU_KEEP);
|
| + DownloadCommand::KEEP,
|
| + GetStringIdForCommand(DownloadCommand::KEEP));
|
| maybe_malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
|
| maybe_malicious_download_menu_model_->AddItemWithStringId(
|
| - LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
|
| + DownloadCommand::LEARN_MORE_SCANNING,
|
| + GetStringIdForCommand(DownloadCommand::LEARN_MORE_SCANNING));
|
| return maybe_malicious_download_menu_model_.get();
|
| }
|
|
|
| @@ -381,37 +224,8 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() {
|
|
|
| DownloadItemModel download_model(download_item_);
|
| malicious_download_menu_model_->AddItemWithStringId(
|
| - LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
|
| + DownloadCommand::LEARN_MORE_SCANNING,
|
| + GetStringIdForCommand(DownloadCommand::LEARN_MORE_SCANNING));
|
|
|
| return malicious_download_menu_model_.get();
|
| }
|
| -
|
| -int DownloadShelfContextMenu::GetAlwaysOpenStringId() const {
|
| -#if defined(OS_WIN)
|
| - if (CanOpenPdfInSystemViewer())
|
| - return IsAdobeReaderDefaultPDFViewer()
|
| - ? IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER
|
| - : IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS;
|
| -#elif defined(OS_MACOSX) || defined(OS_LINUX)
|
| - if (CanOpenPdfInSystemViewer())
|
| - return IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS;
|
| -#endif
|
| - return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE;
|
| -}
|
| -
|
| -#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
|
| -bool DownloadShelfContextMenu::IsDownloadPdf() const {
|
| - base::FilePath path = download_item_->GetTargetFilePath();
|
| - return path.MatchesExtension(FILE_PATH_LITERAL(".pdf"));
|
| -}
|
| -#endif
|
| -
|
| -bool DownloadShelfContextMenu::CanOpenPdfInSystemViewer() const {
|
| -#if defined(OS_WIN)
|
| - return IsDownloadPdf() &&
|
| - (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date_ :
|
| - true);
|
| -#elif defined(OS_MACOSX) || defined(OS_LINUX)
|
| - return IsDownloadPdf();
|
| -#endif
|
| -}
|
|
|