Chromium Code Reviews| 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 b7f0858f93e69e75eecebc8dc2a6d85831f75e87..7889e48bbd6938c5ff38ad236758240c5c29000d 100644 |
| --- a/chrome/browser/download/download_shelf_context_menu.cc |
| +++ b/chrome/browser/download/download_shelf_context_menu.cc |
| @@ -20,15 +20,18 @@ |
| #include "grit/generated_resources.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; |
| -using extensions::Extension; |
| namespace { |
| // Returns true if downloads resumption is enabled. |
| bool IsDownloadResumptionEnabled() { |
| - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| - return command_line.HasSwitch(switches::kEnableDownloadResumption); |
| + return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableDownloadResumption); |
| } |
| } // namespace |
| @@ -44,6 +47,12 @@ DownloadShelfContextMenu::DownloadShelfContextMenu( |
| navigator_(navigator) { |
| DCHECK(download_item_); |
| download_item_->AddObserver(this); |
| + |
| +#if defined(OS_WIN) |
| + is_pdf_reader_up_to_date_ = false; |
| + if (IsDownloadPdf() && IsAdobeReaderDefaultPDFViewer()) |
| + is_pdf_reader_up_to_date_ = DownloadPrefs::IsAdobeReaderUpToDate(); |
| +#endif // defined(OS_WIN) |
| } |
| ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { |
| @@ -97,6 +106,7 @@ bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { |
| case LEARN_MORE_INTERRUPTED: |
| return true; |
| } |
| + NOTREACHED(); |
| return false; |
| } |
| @@ -109,6 +119,13 @@ bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { |
| return download_item_->GetOpenWhenComplete() || |
| download_crx_util::IsExtensionDownload(*download_item_); |
| case ALWAYS_OPEN_TYPE: |
| +#if defined(OS_WIN) |
| + if (CanOpenPdfInReader()) { |
| + DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( |
| + download_item_->GetBrowserContext()); |
| + return prefs->ShouldOpenPdfInAdobeReader(); |
| + } |
| +#endif |
| return download_item_->ShouldOpenFileBasedOnExtension(); |
| case TOGGLE_PAUSE: |
| return download_item_->IsPaused(); |
| @@ -128,10 +145,17 @@ void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) { |
| 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) |
| + if (CanOpenPdfInReader()) { |
| + prefs->SetShouldOpenPdfInAdobeReader(is_checked); |
| + return; |
| + } |
| +#endif |
| base::FilePath path = download_item_->GetTargetFilePath(); |
| - if (!IsCommandIdChecked(ALWAYS_OPEN_TYPE)) |
| + if (is_checked) |
| prefs->EnableAutoOpenBasedOnExtension(path); |
| else |
| prefs->DisableAutoOpenBasedOnExtension(path); |
| @@ -203,7 +227,7 @@ base::string16 DownloadShelfContextMenu::GetLabelForCommandId( |
| 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(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); |
| + return l10n_util::GetStringUTF16(GetAlwaysOpenStringId()); |
| case PLATFORM_OPEN: |
| return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PLATFORM_OPEN); |
| case CANCEL: |
| @@ -250,7 +274,7 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel() { |
| in_progress_download_menu_model_->AddCheckItemWithStringId( |
| OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); |
| in_progress_download_menu_model_->AddCheckItemWithStringId( |
| - ALWAYS_OPEN_TYPE, IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); |
| + ALWAYS_OPEN_TYPE, GetAlwaysOpenStringId()); |
| in_progress_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| in_progress_download_menu_model_->AddItemWithStringId( |
| TOGGLE_PAUSE, IDS_DOWNLOAD_MENU_PAUSE_ITEM); |
| @@ -272,10 +296,11 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetFinishedMenuModel() { |
| finished_download_menu_model_->AddItemWithStringId( |
| OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN); |
| finished_download_menu_model_->AddCheckItemWithStringId( |
| - ALWAYS_OPEN_TYPE, IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); |
| - if (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()) |
| + ALWAYS_OPEN_TYPE, GetAlwaysOpenStringId()); |
| + if (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()) { |
| finished_download_menu_model_->AddItemWithStringId( |
| PLATFORM_OPEN, IDS_DOWNLOAD_MENU_PLATFORM_OPEN); |
| + } |
| finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| finished_download_menu_model_->AddItemWithStringId( |
| SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); |
| @@ -333,8 +358,7 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaybeMaliciousMenuModel() { |
| return maybe_malicious_download_menu_model_.get(); |
| } |
| -ui::SimpleMenuModel* |
| -DownloadShelfContextMenu::GetMaliciousMenuModel() { |
| +ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { |
| if (malicious_download_menu_model_) |
| return malicious_download_menu_model_.get(); |
| @@ -346,3 +370,22 @@ DownloadShelfContextMenu::GetMaliciousMenuModel() { |
| return malicious_download_menu_model_.get(); |
| } |
| + |
| +int DownloadShelfContextMenu::GetAlwaysOpenStringId() const { |
| +#if defined(OS_WIN) |
| + if (CanOpenPdfInReader()) |
| + return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER; |
| +#endif |
| + return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE; |
| +} |
| + |
| +#if defined(OS_WIN) |
| +bool DownloadShelfContextMenu::IsDownloadPdf() const { |
| + base::FilePath path = download_item_->GetTargetFilePath(); |
| + return path.Extension() == FILE_PATH_LITERAL(".pdf"); |
|
asanka
2014/06/12 16:50:55
Nit: path.MatchesExtension(...)
Lei Zhang
2014/06/18 13:48:29
Done.
|
| +} |
| + |
| +bool DownloadShelfContextMenu::CanOpenPdfInReader() const { |
| + return (is_pdf_reader_up_to_date_ && IsDownloadPdf()); |
| +} |
| +#endif |