diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-03 05:49:07 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-03 05:49:07 +0000 |
commit | 6abda2beaab65557677190183486491d01e4de37 (patch) | |
tree | f83d237daf9cdcd88a8feef8de5ac0e8def2e771 /chrome/browser/download | |
parent | e70238a66522e04554fb688078b842d9d9b5937f (diff) | |
download | chromium_src-6abda2beaab65557677190183486491d01e4de37.zip chromium_src-6abda2beaab65557677190183486491d01e4de37.tar.gz chromium_src-6abda2beaab65557677190183486491d01e4de37.tar.bz2 |
Windows: Add an "Open in Adobe Reader" menu item for PDF files in the download shelf.
BUG=370746
Review URL: https://codereview.chromium.org/324593004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281172 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
8 files changed, 258 insertions, 44 deletions
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc index 2a8d6c6..8e81539 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.cc +++ b/chrome/browser/download/chrome_download_manager_delegate.cc @@ -184,29 +184,6 @@ std::string GetMimeType(const base::FilePath& path) { return mime_type; } -bool IsOpenInBrowserPreferreredForFile(const base::FilePath& path) { - // On Android, always prefer opening with an external app. On ChromeOS, there - // are no external apps so just allow all opens to be handled by the "System." -#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS) - // TODO(asanka): Consider other file types and MIME types. - // http://crbug.com/323561 - if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) || - path.MatchesExtension(FILE_PATH_LITERAL(".htm")) || - path.MatchesExtension(FILE_PATH_LITERAL(".html")) || - path.MatchesExtension(FILE_PATH_LITERAL(".shtm")) || - path.MatchesExtension(FILE_PATH_LITERAL(".shtml")) || - path.MatchesExtension(FILE_PATH_LITERAL(".svg")) || - path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || - path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || - path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || - path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || - path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { - return true; - } -#endif - return false; -} - } // namespace ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) @@ -722,3 +699,35 @@ void ChromeDownloadManagerDelegate::OnDownloadTargetDetermined( target_info->danger_type, target_info->intermediate_path); } + +bool ChromeDownloadManagerDelegate::IsOpenInBrowserPreferreredForFile( + const base::FilePath& path) { + // On Windows, PDFs should open in Acrobat Reader if the user chooses. +#if defined(OS_WIN) + if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) && + DownloadTargetDeterminer::IsAdobeReaderUpToDate()) { + return !download_prefs_->ShouldOpenPdfInAdobeReader(); + } +#endif + + // On Android, always prefer opening with an external app. On ChromeOS, there + // are no external apps so just allow all opens to be handled by the "System." +#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) && defined(ENABLE_PLUGINS) + // TODO(asanka): Consider other file types and MIME types. + // http://crbug.com/323561 + if (path.MatchesExtension(FILE_PATH_LITERAL(".pdf")) || + path.MatchesExtension(FILE_PATH_LITERAL(".htm")) || + path.MatchesExtension(FILE_PATH_LITERAL(".html")) || + path.MatchesExtension(FILE_PATH_LITERAL(".shtm")) || + path.MatchesExtension(FILE_PATH_LITERAL(".shtml")) || + path.MatchesExtension(FILE_PATH_LITERAL(".svg")) || + path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || + path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || + path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || + path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || + path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { + return true; + } +#endif + return false; +} diff --git a/chrome/browser/download/chrome_download_manager_delegate.h b/chrome/browser/download/chrome_download_manager_delegate.h index 7cf2c45..ff89300 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.h +++ b/chrome/browser/download/chrome_download_manager_delegate.h @@ -170,6 +170,9 @@ class ChromeDownloadManagerDelegate const content::DownloadTargetCallback& callback, scoped_ptr<DownloadTargetInfo> target_info); + // Returns true if |path| should open in the browser. + bool IsOpenInBrowserPreferreredForFile(const base::FilePath& path); + Profile* profile_; uint32 next_download_id_; IdCallbackVector id_callbacks_; diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc index 750e11b..99abc2c 100644 --- a/chrome/browser/download/download_prefs.cc +++ b/chrome/browser/download/download_prefs.cc @@ -22,6 +22,7 @@ #include "chrome/browser/download/download_extensions.h" #include "chrome/browser/download/download_service.h" #include "chrome/browser/download/download_service_factory.h" +#include "chrome/browser/download/download_target_determiner.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_paths.h" @@ -37,6 +38,10 @@ #include "chrome/browser/chromeos/file_manager/path_util.h" #endif +#if defined(OS_WIN) +#include "chrome/browser/ui/pdf/adobe_reader_info_win.h" +#endif + using content::BrowserContext; using content::BrowserThread; using content::DownloadManager; @@ -91,7 +96,7 @@ class DefaultDownloadDirectory { DISALLOW_COPY_AND_ASSIGN(DefaultDownloadDirectory); }; -static base::LazyInstance<DefaultDownloadDirectory> +base::LazyInstance<DefaultDownloadDirectory> g_default_download_directory = LAZY_INSTANCE_INITIALIZER; } // namespace @@ -126,6 +131,11 @@ DownloadPrefs::DownloadPrefs(Profile* profile) : profile_(profile) { GetDefaultDownloadDirectoryForProfile())); #endif // defined(OS_CHROMEOS) +#if defined(OS_WIN) + should_open_pdf_in_adobe_reader_ = + prefs->GetBoolean(prefs::kOpenPdfDownloadInAdobeReader); +#endif + // If the download path is dangerous we forcefully reset it. But if we do // so we set a flag to make sure we only do it once, to avoid fighting // the user if he really wants it on an unsafe place such as the desktop. @@ -194,6 +204,12 @@ void DownloadPrefs::RegisterProfilePrefs( prefs::kSaveFileDefaultDirectory, default_download_path, user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); +#if defined(OS_WIN) + registry->RegisterBooleanPref( + prefs::kOpenPdfDownloadInAdobeReader, + false, + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); +#endif } base::FilePath DownloadPrefs::GetDefaultDownloadDirectoryForProfile() const { @@ -268,6 +284,10 @@ bool DownloadPrefs::IsDownloadPathManaged() const { } bool DownloadPrefs::IsAutoOpenUsed() const { +#if defined(OS_WIN) + if (ShouldOpenPdfInAdobeReader()) + return true; +#endif return !auto_open_.empty(); } @@ -278,6 +298,12 @@ bool DownloadPrefs::IsAutoOpenEnabledBasedOnExtension( return false; DCHECK(extension[0] == base::FilePath::kExtensionSeparator); extension.erase(0, 1); +#if defined(OS_WIN) + if (extension == FILE_PATH_LITERAL("pdf") && + DownloadTargetDeterminer::IsAdobeReaderUpToDate() && + ShouldOpenPdfInAdobeReader()) + return true; +#endif return auto_open_.find(extension) != auto_open_.end(); } @@ -305,7 +331,24 @@ void DownloadPrefs::DisableAutoOpenBasedOnExtension( SaveAutoOpenState(); } +#if defined(OS_WIN) +void DownloadPrefs::SetShouldOpenPdfInAdobeReader(bool should_open) { + if (should_open_pdf_in_adobe_reader_ == should_open) + return; + should_open_pdf_in_adobe_reader_ = should_open; + profile_->GetPrefs()->SetBoolean(prefs::kOpenPdfDownloadInAdobeReader, + should_open); +} + +bool DownloadPrefs::ShouldOpenPdfInAdobeReader() const { + return should_open_pdf_in_adobe_reader_; +} +#endif + void DownloadPrefs::ResetAutoOpen() { +#if defined(OS_WIN) + SetShouldOpenPdfInAdobeReader(false); +#endif auto_open_.clear(); SaveAutoOpenState(); } diff --git a/chrome/browser/download/download_prefs.h b/chrome/browser/download/download_prefs.h index eca19d3..8d3db57 100644 --- a/chrome/browser/download/download_prefs.h +++ b/chrome/browser/download/download_prefs.h @@ -73,6 +73,15 @@ class DownloadPrefs { // Disables auto-open based on file extension. void DisableAutoOpenBasedOnExtension(const base::FilePath& file_name); +#if defined(OS_WIN) + // Store the user preference to disk. If |should_open| is true, also disable + // the built-in PDF plugin. If |should_open| is false, enable the PDF plugin. + void SetShouldOpenPdfInAdobeReader(bool should_open); + + // Return whether the user prefers to open PDF downloads in Adobe Reader. + bool ShouldOpenPdfInAdobeReader() const; +#endif + void ResetAutoOpen(); private: @@ -94,6 +103,10 @@ class DownloadPrefs { AutoOpenCompareFunctor> AutoOpenSet; AutoOpenSet auto_open_; +#if defined(OS_WIN) + bool should_open_pdf_in_adobe_reader_; +#endif + DISALLOW_COPY_AND_ASSIGN(DownloadPrefs); }; diff --git a/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc index b7f0858..55704c9 100644 --- a/chrome/browser/download/download_shelf_context_menu.cc +++ b/chrome/browser/download/download_shelf_context_menu.cc @@ -9,6 +9,7 @@ #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" @@ -20,15 +21,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 +48,14 @@ 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_ = + DownloadTargetDeterminer::IsAdobeReaderUpToDate(); + } +#endif // defined(OS_WIN) } ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { @@ -97,6 +109,7 @@ bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { case LEARN_MORE_INTERRUPTED: return true; } + NOTREACHED(); return false; } @@ -109,6 +122,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(); @@ -116,6 +136,16 @@ bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { return false; } +bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { + if (!download_item_) + return false; + + if (command_id == PLATFORM_OPEN) + return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()); + + return true; +} + void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) { if (!download_item_) return; @@ -128,13 +158,22 @@ 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); + DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser( + is_checked); + break; + } +#endif base::FilePath path = download_item_->GetTargetFilePath(); - if (!IsCommandIdChecked(ALWAYS_OPEN_TYPE)) - prefs->EnableAutoOpenBasedOnExtension(path); - else + if (is_checked) prefs->DisableAutoOpenBasedOnExtension(path); + else + prefs->EnableAutoOpenBasedOnExtension(path); break; } case PLATFORM_OPEN: @@ -203,7 +242,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 +289,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 +311,9 @@ 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()) - finished_download_menu_model_->AddItemWithStringId( - PLATFORM_OPEN, IDS_DOWNLOAD_MENU_PLATFORM_OPEN); + ALWAYS_OPEN_TYPE, GetAlwaysOpenStringId()); + 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 +371,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 +383,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.MatchesExtension(FILE_PATH_LITERAL(".pdf")); +} + +bool DownloadShelfContextMenu::CanOpenPdfInReader() const { + return (is_pdf_reader_up_to_date_ && IsDownloadPdf()); +} +#endif diff --git a/chrome/browser/download/download_shelf_context_menu.h b/chrome/browser/download/download_shelf_context_menu.h index 15b6504..a5d8a5eb 100644 --- a/chrome/browser/download/download_shelf_context_menu.h +++ b/chrome/browser/download/download_shelf_context_menu.h @@ -52,6 +52,7 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, // ui::SimpleMenuModel::Delegate: virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; + virtual bool IsCommandIdVisible(int command_id) const OVERRIDE; virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; virtual bool GetAcceleratorForCommandId( int command_id, @@ -73,6 +74,13 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, ui::SimpleMenuModel* GetMaybeMaliciousMenuModel(); ui::SimpleMenuModel* GetMaliciousMenuModel(); + int GetAlwaysOpenStringId() const; + +#if defined(OS_WIN) + bool IsDownloadPdf() const; + bool CanOpenPdfInReader() const; +#endif + // We show slightly different menus if the download is in progress vs. if the // download has finished. scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_; @@ -87,6 +95,10 @@ class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate, // Used to open tabs. content::PageNavigator* navigator_; +#if defined(OS_WIN) + bool is_pdf_reader_up_to_date_; +#endif + DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu); }; diff --git a/chrome/browser/download/download_target_determiner.cc b/chrome/browser/download/download_target_determiner.cc index ee54bad..cca194b 100644 --- a/chrome/browser/download/download_target_determiner.cc +++ b/chrome/browser/download/download_target_determiner.cc @@ -36,6 +36,10 @@ #include "content/public/common/webplugininfo.h" #endif +#if defined(OS_WIN) +#include "chrome/browser/ui/pdf/adobe_reader_info_win.h" +#endif + using content::BrowserThread; using content::DownloadItem; @@ -58,7 +62,12 @@ void VisitCountsToVisitedBefore( (first_visit.LocalMidnight() < base::Time::Now().LocalMidnight())); } -} // namespace +#if defined(OS_WIN) +// Keeps track of whether Adobe Reader is up to date. +bool g_is_adobe_reader_up_to_date_ = false; +#endif + +} // namespace DownloadTargetInfo::DownloadTargetInfo() : is_filetype_handled_safely(false) {} @@ -133,6 +142,9 @@ void DownloadTargetDeterminer::DoLoop() { case STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER: result = DoDetermineIfHandledSafely(); break; + case STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE: + result = DoDetermineIfAdobeReaderUpToDate(); + break; case STATE_CHECK_DOWNLOAD_URL: result = DoCheckDownloadUrl(); break; @@ -449,8 +461,8 @@ void IsHandledBySafePlugin(content::ResourceContext* resource_context, BrowserThread::UI, FROM_HERE, base::Bind(callback, is_handled_safely)); } -} // namespace -#endif // ENABLE_PLUGINS +} // namespace +#endif // defined(ENABLE_PLUGINS) DownloadTargetDeterminer::Result DownloadTargetDeterminer::DoDetermineIfHandledSafely() { @@ -459,7 +471,7 @@ DownloadTargetDeterminer::Result DCHECK(!local_path_.empty()); DCHECK(!is_filetype_handled_safely_); - next_state_ = STATE_CHECK_DOWNLOAD_URL; + next_state_ = STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE; if (mime_type_.empty()) return CONTINUE; @@ -487,14 +499,51 @@ DownloadTargetDeterminer::Result #endif } +#if defined(ENABLE_PLUGINS) void DownloadTargetDeterminer::DetermineIfHandledSafelyDone( bool is_handled_safely) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DVLOG(20) << "Is file type handled safely: " << is_filetype_handled_safely_; - DCHECK_EQ(STATE_CHECK_DOWNLOAD_URL, next_state_); + DCHECK_EQ(STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, next_state_); is_filetype_handled_safely_ = is_handled_safely; DoLoop(); } +#endif + +DownloadTargetDeterminer::Result + DownloadTargetDeterminer::DoDetermineIfAdobeReaderUpToDate() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + + next_state_ = STATE_CHECK_DOWNLOAD_URL; + +#if defined(OS_WIN) + if (!local_path_.MatchesExtension(FILE_PATH_LITERAL(".pdf"))) + return CONTINUE; + if (!IsAdobeReaderDefaultPDFViewer()) + return CONTINUE; + + base::PostTaskAndReplyWithResult( + BrowserThread::GetBlockingPool(), + FROM_HERE, + base::Bind(&::IsAdobeReaderUpToDate), + base::Bind(&DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone, + weak_ptr_factory_.GetWeakPtr())); + return QUIT_DOLOOP; +#else + return CONTINUE; +#endif +} + +#if defined(OS_WIN) +void DownloadTargetDeterminer::DetermineIfAdobeReaderUpToDateDone( + bool adobe_reader_up_to_date) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DVLOG(20) << "Is Adobe Reader Up To Date: " << adobe_reader_up_to_date; + DCHECK_EQ(STATE_CHECK_DOWNLOAD_URL, next_state_); + g_is_adobe_reader_up_to_date_ = adobe_reader_up_to_date; + DoLoop(); +} +#endif DownloadTargetDeterminer::Result DownloadTargetDeterminer::DoCheckDownloadUrl() { @@ -828,3 +877,10 @@ base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( const base::FilePath& suggested_path) { return base::FilePath(suggested_path.value() + kCrdownloadSuffix); } + +#if defined(OS_WIN) +// static +bool DownloadTargetDeterminer::IsAdobeReaderUpToDate() { + return g_is_adobe_reader_up_to_date_; +} +#endif diff --git a/chrome/browser/download/download_target_determiner.h b/chrome/browser/download/download_target_determiner.h index f57341d..8cca804 100644 --- a/chrome/browser/download/download_target_determiner.h +++ b/chrome/browser/download/download_target_determiner.h @@ -80,6 +80,13 @@ class DownloadTargetDeterminer // Returns a .crdownload intermediate path for the |suggested_path|. static base::FilePath GetCrDownloadPath(const base::FilePath& suggested_path); +#if defined(OS_WIN) + // Returns true if Adobe Reader is up to date. This information refreshed + // only when Start() gets called for a PDF and Adobe Reader is the default + // System PDF viewer. + static bool IsAdobeReaderUpToDate(); +#endif + private: // The main workflow is controlled via a set of state transitions. Each state // has an associated handler. The handler for STATE_FOO is DoFoo. Each handler @@ -94,6 +101,7 @@ class DownloadTargetDeterminer STATE_DETERMINE_LOCAL_PATH, STATE_DETERMINE_MIME_TYPE, STATE_DETERMINE_IF_HANDLED_SAFELY_BY_BROWSER, + STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE, STATE_CHECK_DOWNLOAD_URL, STATE_CHECK_VISITED_REFERRER_BEFORE, STATE_DETERMINE_INTERMEDIATE_PATH, @@ -206,12 +214,26 @@ class DownloadTargetDeterminer // Determine if the file type can be handled safely by the browser if it were // to be opened via a file:// URL. // Next state: - // - STATE_CHECK_DOWNLOAD_URL. + // - STATE_DETERMINE_IF_ADOBE_READER_UP_TO_DATE. Result DoDetermineIfHandledSafely(); +#if defined(ENABLE_PLUGINS) // Callback invoked when a decision is available about whether the file type // can be handled safely by the browser. void DetermineIfHandledSafelyDone(bool is_handled_safely); +#endif + + // Determine if Adobe Reader is up to date. Only do the check on Windows for + // .pdf file targets. + // Next state: + // - STATE_CHECK_DOWNLOAD_URL. + Result DoDetermineIfAdobeReaderUpToDate(); + +#if defined(OS_WIN) + // Callback invoked when a decision is available about whether Adobe Reader + // is up to date. + void DetermineIfAdobeReaderUpToDateDone(bool adobe_reader_up_to_date); +#endif // Checks whether the downloaded URL is malicious. Invokes the // DownloadProtectionService via the delegate. |