Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/bind.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/file_version_info.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "base/win/registry.h" | |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/plugins/plugin_finder.h" | |
| 17 #include "chrome/browser/plugins/plugin_metadata.h" | |
| 18 #include "chrome/browser/plugins/plugin_prefs.h" | |
| 19 #include "chrome/browser/profiles/profile.h" | |
| 20 #include "chrome/browser/profiles/profile_manager.h" | |
| 21 #include "chrome/installer/util/shell_util.h" | |
| 22 #include "content/public/browser/plugin_service.h" | |
| 23 #include "content/public/common/registry_utils_win.h" | |
| 24 | |
| 25 namespace { | |
| 26 | |
| 27 // Hardcoded value for the secure version of Acrobat Reader. | |
| 28 const char kSecureVersion[] = "11.0.7.79"; | |
| 29 | |
| 30 const char kAdobeReaderIdentifier[] = "adobe-reader"; | |
| 31 const char kPdfMimeType[] = "application/pdf"; | |
| 32 | |
| 33 bool IsPdfMimeType(const content::WebPluginMimeType& plugin_mime_type) { | |
| 34 return plugin_mime_type.mime_type == kPdfMimeType; | |
| 35 } | |
| 36 | |
| 37 AdobeReaderPluginInfo GetReaderPlugin( | |
| 38 Profile* profile, | |
| 39 const std::vector<content::WebPluginInfo>& plugins) { | |
| 40 AdobeReaderPluginInfo reader_info; | |
| 41 reader_info.is_installed = false; | |
| 42 reader_info.is_enabled = false; | |
| 43 reader_info.is_secure = false; | |
| 44 | |
| 45 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | |
| 46 for (size_t i = 0; i < plugins.size(); ++i) { | |
| 47 const content::WebPluginInfo& plugin = plugins[i]; | |
| 48 if (plugin.is_pepper_plugin()) | |
| 49 continue; | |
| 50 if (std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(), | |
| 51 IsPdfMimeType) == plugin.mime_types.end()) | |
| 52 continue; | |
| 53 scoped_ptr<PluginMetadata> plugin_metadata( | |
| 54 plugin_finder->GetPluginMetadata(plugins[i])); | |
| 55 if (plugin_metadata->identifier() != kAdobeReaderIdentifier) | |
| 56 continue; | |
| 57 | |
| 58 reader_info.is_installed = true; | |
| 59 | |
| 60 if (profile) { | |
| 61 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | |
| 62 PluginPrefs::PolicyStatus plugin_status = | |
| 63 plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()); | |
| 64 reader_info.is_enabled = plugin_status != PluginPrefs::POLICY_DISABLED; | |
| 65 } | |
| 66 | |
| 67 PluginMetadata::SecurityStatus security_status = | |
| 68 plugin_metadata->GetSecurityStatus(plugins[i]); | |
| 69 reader_info.is_secure = | |
| 70 security_status == PluginMetadata::SECURITY_STATUS_UP_TO_DATE; | |
| 71 | |
| 72 reader_info.plugin_info = plugins[i]; | |
| 73 break; | |
| 74 } | |
| 75 return reader_info; | |
| 76 } | |
| 77 | |
| 78 void OnGotPluginInfo(Profile* profile, | |
| 79 const GetAdobeReaderPluginInfoCallback& callback, | |
| 80 const std::vector<content::WebPluginInfo>& plugins) { | |
| 81 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | |
| 82 profile = NULL; | |
| 83 callback.Run(GetReaderPlugin(profile, plugins)); | |
| 84 } | |
| 85 | |
| 86 bool IsAdobeReaderDefaultPDFViewerInternal(base::FilePath* path) { | |
| 87 // Look up the default file type for .pdf. | |
| 88 base::win::RegKey pdf_extension_key(HKEY_CLASSES_ROOT, L".pdf", KEY_READ); | |
| 89 base::string16 file_type; | |
| 90 if (!pdf_extension_key.Valid() || | |
| 91 pdf_extension_key.ReadValue(L"", &file_type) != ERROR_SUCCESS || | |
| 92 file_type.empty() || | |
| 93 file_type.find('\\') != base::string16::npos) | |
| 94 return false; | |
| 95 | |
| 96 // Look up the association for the file type. | |
| 97 base::string16 key_path = file_type + ShellUtil::kRegShellOpen; | |
| 98 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); | |
| 99 base::string16 app_cmd; | |
| 100 if (!key.Valid() || (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS)) | |
| 101 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.
| |
| 102 | |
| 103 // Looks for the install paths for Acrobat / Reader. | |
| 104 base::FilePath install_path; | |
| 105 bool has_reader = content::GetInstalledPath( | |
| 106 content::kRegistryAcrobatReader, &install_path); | |
| 107 if (!has_reader) { | |
| 108 has_reader = content::GetInstalledPath( | |
| 109 content::kRegistryAcrobat, &install_path); | |
| 110 } | |
| 111 if (!has_reader) | |
| 112 return false; | |
| 113 | |
| 114 bool found = app_cmd.find(install_path.value()) != base::string16::npos; | |
| 115 if (found && path) | |
| 116 *path = install_path; | |
| 117 return found; | |
| 118 } | |
| 119 | |
| 120 } // namespace | |
| 121 | |
| 122 void GetAdobeReaderPluginInfoAsync( | |
| 123 Profile* profile, | |
| 124 const GetAdobeReaderPluginInfoCallback& callback) { | |
| 125 DCHECK(!callback.is_null()); | |
| 126 content::PluginService::GetInstance()->GetPlugins( | |
| 127 base::Bind(&OnGotPluginInfo, profile, callback)); | |
| 128 } | |
| 129 | |
| 130 bool GetAdobeReaderPluginInfo(Profile* profile, | |
| 131 AdobeReaderPluginInfo* reader_info) { | |
| 132 DCHECK(reader_info); | |
| 133 std::vector<content::WebPluginInfo> plugins; | |
| 134 bool up_to_date = content::PluginService::GetInstance()->GetPluginInfoArray( | |
| 135 GURL(), kPdfMimeType, false, &plugins, NULL); | |
| 136 *reader_info = GetReaderPlugin(profile, plugins); | |
| 137 return up_to_date; | |
| 138 } | |
| 139 | |
| 140 bool IsAdobeReaderDefaultPDFViewer() { | |
| 141 return IsAdobeReaderDefaultPDFViewerInternal(NULL); | |
| 142 } | |
| 143 | |
| 144 bool IsAdobeReaderUpToDate() { | |
| 145 base::FilePath install_path; | |
| 146 bool is_default = IsAdobeReaderDefaultPDFViewerInternal(&install_path); | |
| 147 if (!is_default) | |
| 148 return false; | |
| 149 | |
| 150 scoped_ptr<FileVersionInfo> file_version_info( | |
| 151 FileVersionInfo::CreateFileVersionInfo(install_path)); | |
| 152 if (!file_version_info) | |
| 153 return false; | |
| 154 | |
| 155 base::Version file_version( | |
| 156 base::UTF16ToUTF8(file_version_info->product_version())); | |
| 157 return file_version.IsOlderThan(kSecureVersion); | |
| 158 } | |
| OLD | NEW |