Index: chrome/browser/ui/pdf/adobe_reader_info_win.cc |
diff --git a/chrome/browser/ui/pdf/adobe_reader_info_win.cc b/chrome/browser/ui/pdf/adobe_reader_info_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5ac929de46204bd4382906bef206408bbdda1706 |
--- /dev/null |
+++ b/chrome/browser/ui/pdf/adobe_reader_info_win.cc |
@@ -0,0 +1,158 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/pdf/adobe_reader_info_win.h" |
+ |
+#include <algorithm> |
+#include <vector> |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/file_version_info.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "base/win/registry.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/plugins/plugin_finder.h" |
+#include "chrome/browser/plugins/plugin_metadata.h" |
+#include "chrome/browser/plugins/plugin_prefs.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
+#include "chrome/installer/util/shell_util.h" |
+#include "content/public/browser/plugin_service.h" |
+#include "content/public/common/registry_utils_win.h" |
+ |
+namespace { |
+ |
+// Hardcoded value for the secure version of Acrobat Reader. |
+const char kSecureVersion[] = "11.0.7.79"; |
+ |
+const char kAdobeReaderIdentifier[] = "adobe-reader"; |
+const char kPdfMimeType[] = "application/pdf"; |
+ |
+bool IsPdfMimeType(const content::WebPluginMimeType& plugin_mime_type) { |
+ return plugin_mime_type.mime_type == kPdfMimeType; |
+} |
+ |
+AdobeReaderPluginInfo GetReaderPlugin( |
+ Profile* profile, |
+ const std::vector<content::WebPluginInfo>& plugins) { |
+ AdobeReaderPluginInfo reader_info; |
+ reader_info.is_installed = false; |
+ reader_info.is_enabled = false; |
+ reader_info.is_secure = false; |
+ |
+ PluginFinder* plugin_finder = PluginFinder::GetInstance(); |
+ for (size_t i = 0; i < plugins.size(); ++i) { |
+ const content::WebPluginInfo& plugin = plugins[i]; |
+ if (plugin.is_pepper_plugin()) |
+ continue; |
+ if (std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(), |
+ IsPdfMimeType) == plugin.mime_types.end()) |
+ continue; |
+ scoped_ptr<PluginMetadata> plugin_metadata( |
+ plugin_finder->GetPluginMetadata(plugins[i])); |
+ if (plugin_metadata->identifier() != kAdobeReaderIdentifier) |
+ continue; |
+ |
+ reader_info.is_installed = true; |
+ |
+ if (profile) { |
+ PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); |
+ PluginPrefs::PolicyStatus plugin_status = |
+ plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()); |
+ reader_info.is_enabled = plugin_status != PluginPrefs::POLICY_DISABLED; |
+ } |
+ |
+ PluginMetadata::SecurityStatus security_status = |
+ plugin_metadata->GetSecurityStatus(plugins[i]); |
+ reader_info.is_secure = |
+ security_status == PluginMetadata::SECURITY_STATUS_UP_TO_DATE; |
+ |
+ reader_info.plugin_info = plugins[i]; |
+ break; |
+ } |
+ return reader_info; |
+} |
+ |
+void OnGotPluginInfo(Profile* profile, |
+ const GetAdobeReaderPluginInfoCallback& callback, |
+ const std::vector<content::WebPluginInfo>& plugins) { |
+ if (!g_browser_process->profile_manager()->IsValidProfile(profile)) |
+ profile = NULL; |
+ callback.Run(GetReaderPlugin(profile, plugins)); |
+} |
+ |
+bool IsAdobeReaderDefaultPDFViewerInternal(base::FilePath* path) { |
+ // Look up the default file type for .pdf. |
+ base::win::RegKey pdf_extension_key(HKEY_CLASSES_ROOT, L".pdf", KEY_READ); |
+ base::string16 file_type; |
+ if (!pdf_extension_key.Valid() || |
+ pdf_extension_key.ReadValue(L"", &file_type) != ERROR_SUCCESS || |
+ file_type.empty() || |
+ file_type.find('\\') != base::string16::npos) |
+ return false; |
+ |
+ // Look up the association for the file type. |
+ base::string16 key_path = file_type + ShellUtil::kRegShellOpen; |
+ base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); |
+ base::string16 app_cmd; |
+ if (!key.Valid() || (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS)) |
+ return false; |
asanka
2014/06/12 16:50:55
Have you looked at using AssocQueryString() to get
Lei Zhang
2014/06/18 13:48:29
Done.
|
+ |
+ // Looks for the install paths for Acrobat / Reader. |
+ base::FilePath install_path; |
+ bool has_reader = content::GetInstalledPath( |
+ content::kRegistryAcrobatReader, &install_path); |
+ if (!has_reader) { |
+ has_reader = content::GetInstalledPath( |
+ content::kRegistryAcrobat, &install_path); |
+ } |
+ if (!has_reader) |
+ return false; |
+ |
+ bool found = app_cmd.find(install_path.value()) != base::string16::npos; |
+ if (found && path) |
+ *path = install_path; |
+ return found; |
+} |
+ |
+} // namespace |
+ |
+void GetAdobeReaderPluginInfoAsync( |
+ Profile* profile, |
+ const GetAdobeReaderPluginInfoCallback& callback) { |
+ DCHECK(!callback.is_null()); |
+ content::PluginService::GetInstance()->GetPlugins( |
+ base::Bind(&OnGotPluginInfo, profile, callback)); |
+} |
+ |
+bool GetAdobeReaderPluginInfo(Profile* profile, |
+ AdobeReaderPluginInfo* reader_info) { |
+ DCHECK(reader_info); |
+ std::vector<content::WebPluginInfo> plugins; |
+ bool up_to_date = content::PluginService::GetInstance()->GetPluginInfoArray( |
+ GURL(), kPdfMimeType, false, &plugins, NULL); |
+ *reader_info = GetReaderPlugin(profile, plugins); |
+ return up_to_date; |
+} |
+ |
+bool IsAdobeReaderDefaultPDFViewer() { |
+ return IsAdobeReaderDefaultPDFViewerInternal(NULL); |
+} |
+ |
+bool IsAdobeReaderUpToDate() { |
+ base::FilePath install_path; |
+ bool is_default = IsAdobeReaderDefaultPDFViewerInternal(&install_path); |
+ if (!is_default) |
+ return false; |
+ |
+ scoped_ptr<FileVersionInfo> file_version_info( |
+ FileVersionInfo::CreateFileVersionInfo(install_path)); |
+ if (!file_version_info) |
+ return false; |
+ |
+ base::Version file_version( |
+ base::UTF16ToUTF8(file_version_info->product_version())); |
+ return file_version.IsOlderThan(kSecureVersion); |
+} |