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

Unified Diff: chrome/browser/download/download_prefs.cc

Issue 324593004: Windows: Add an "Open in Adobe Reader" menu item for PDF files in the download shelf. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, check AcroRd32.exe version, set/honor prefs Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_prefs.cc
diff --git a/chrome/browser/download/download_prefs.cc b/chrome/browser/download/download_prefs.cc
index 750e11b5737877a6676eaba00ab0f35cd1a5b396..8f6724f765d2ccd31b8e5dccfeb8eaaef3e1e18c 100644
--- a/chrome/browser/download/download_prefs.cc
+++ b/chrome/browser/download/download_prefs.cc
@@ -37,6 +37,14 @@
#include "chrome/browser/chromeos/file_manager/path_util.h"
#endif
+#if defined(OS_WIN)
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/plugins/plugin_metadata.h"
+#include "chrome/browser/plugins/plugin_prefs.h"
+#include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
+#include "chrome/common/chrome_content_client.h"
+#endif
+
using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
@@ -91,9 +99,24 @@ class DefaultDownloadDirectory {
DISALLOW_COPY_AND_ASSIGN(DefaultDownloadDirectory);
};
-static base::LazyInstance<DefaultDownloadDirectory>
+base::LazyInstance<DefaultDownloadDirectory>
g_default_download_directory = LAZY_INSTANCE_INITIALIZER;
+#if defined(OS_WIN)
+bool g_adobe_reader_up_to_date = false;
+
+// Callback when whether Adobe Reader is up to date is known.
+void OnGotAdobeReaderInfo(Profile* profile, bool up_to_date) {
+ g_adobe_reader_up_to_date = up_to_date;
+ if (!up_to_date) {
+ if (g_browser_process->profile_manager()->IsValidProfile(profile)) {
+ DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext(profile);
+ prefs->SetShouldOpenPdfInAdobeReader(false);
+ }
+ }
+}
+#endif
+
} // namespace
DownloadPrefs::DownloadPrefs(Profile* profile) : profile_(profile) {
@@ -120,12 +143,25 @@ DownloadPrefs::DownloadPrefs(Profile* profile) : profile_(profile) {
}
// Ensure that the default download directory exists.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
+ BrowserThread::PostBlockingPoolTask(
+ FROM_HERE,
base::Bind(base::IgnoreResult(&base::CreateDirectory),
GetDefaultDownloadDirectoryForProfile()));
#endif // defined(OS_CHROMEOS)
+#if defined(OS_WIN)
+ if (IsAdobeReaderDefaultPDFViewer()) {
+ base::PostTaskAndReplyWithResult(
+ BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&IsAdobeReaderUpToDate),
+ base::Bind(&OnGotAdobeReaderInfo, profile));
+ }
+
+ 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,7 +230,20 @@ 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
+}
+
+#if defined(OS_WIN)
+// static
+bool DownloadPrefs::IsAdobeReaderUpToDate() {
+ return g_adobe_reader_up_to_date;
}
+#endif
base::FilePath DownloadPrefs::GetDefaultDownloadDirectoryForProfile() const {
#if defined(OS_CHROMEOS)
@@ -278,6 +327,11 @@ 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") &&
+ g_adobe_reader_up_to_date && ShouldOpenPdfInAdobeReader())
+ return true;
+#endif
return auto_open_.find(extension) != auto_open_.end();
}
@@ -305,6 +359,32 @@ void DownloadPrefs::DisableAutoOpenBasedOnExtension(
SaveAutoOpenState();
}
+#if defined(OS_WIN)
+void DownloadPrefs::SetShouldOpenPdfInAdobeReader(bool should_open) {
+ if (should_open_pdf_in_adobe_reader_ == should_open)
+ return;
+ UpdatePdfPlugins(should_open);
+ profile_->GetPrefs()->SetBoolean(prefs::kOpenPdfDownloadInAdobeReader,
+ should_open);
+}
+
+bool DownloadPrefs::ShouldOpenPdfInAdobeReader() const {
+ return should_open_pdf_in_adobe_reader_;
+}
+
+void DownloadPrefs::UpdatePdfPlugins(bool should_open) {
+ PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile_).get();
+ bool enable_chrome_pdf_plugin = !should_open;
+ bool enable_reader_npapi_plugin = false;
+ plugin_prefs->EnablePluginGroup(
+ enable_reader_npapi_plugin,
+ base::ASCIIToUTF16(PluginMetadata::kAdobeReaderGroupName));
+ plugin_prefs->EnablePluginGroup(
+ enable_chrome_pdf_plugin,
+ base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName));
+}
+#endif
+
void DownloadPrefs::ResetAutoOpen() {
auto_open_.clear();
SaveAutoOpenState();

Powered by Google App Engine
This is Rietveld 408576698