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 <shlwapi.h> | |
| 8 | |
| 9 #include <algorithm> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/bind.h" | |
| 13 #include "base/callback.h" | |
| 14 #include "base/file_version_info.h" | |
| 15 #include "base/strings/string_util.h" | |
| 16 #include "base/strings/stringprintf.h" | |
| 17 #include "base/strings/utf_string_conversions.h" | |
| 18 #include "chrome/browser/browser_process.h" | |
| 19 #include "chrome/browser/plugins/plugin_finder.h" | |
| 20 #include "chrome/browser/plugins/plugin_metadata.h" | |
| 21 #include "chrome/browser/plugins/plugin_prefs.h" | |
| 22 #include "chrome/browser/profiles/profile.h" | |
| 23 #include "chrome/browser/profiles/profile_manager.h" | |
| 24 #include "content/public/browser/plugin_service.h" | |
| 25 #include "content/public/common/registry_utils_win.h" | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 // Hardcoded value for the secure version of Acrobat Reader. | |
| 30 const char kSecureVersion[] = "11.0.7.79"; | |
| 31 | |
| 32 const char kAdobeReaderIdentifier[] = "adobe-reader"; | |
| 33 const char kPdfMimeType[] = "application/pdf"; | |
| 34 | |
| 35 bool IsPdfMimeType(const content::WebPluginMimeType& plugin_mime_type) { | |
| 36 return plugin_mime_type.mime_type == kPdfMimeType; | |
| 37 } | |
| 38 | |
| 39 AdobeReaderPluginInfo GetReaderPlugin( | |
| 40 Profile* profile, | |
| 41 const std::vector<content::WebPluginInfo>& plugins) { | |
| 42 AdobeReaderPluginInfo reader_info; | |
| 43 reader_info.is_installed = false; | |
| 44 reader_info.is_enabled = false; | |
| 45 reader_info.is_secure = false; | |
| 46 | |
| 47 PluginFinder* plugin_finder = PluginFinder::GetInstance(); | |
| 48 for (size_t i = 0; i < plugins.size(); ++i) { | |
| 49 const content::WebPluginInfo& plugin = plugins[i]; | |
| 50 if (plugin.is_pepper_plugin()) | |
| 51 continue; | |
| 52 if (std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(), | |
| 53 IsPdfMimeType) == plugin.mime_types.end()) | |
| 54 continue; | |
| 55 scoped_ptr<PluginMetadata> plugin_metadata( | |
| 56 plugin_finder->GetPluginMetadata(plugins[i])); | |
| 57 if (plugin_metadata->identifier() != kAdobeReaderIdentifier) | |
| 58 continue; | |
| 59 | |
| 60 reader_info.is_installed = true; | |
| 61 | |
| 62 if (profile) { | |
| 63 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(profile); | |
| 64 PluginPrefs::PolicyStatus plugin_status = | |
| 65 plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name()); | |
| 66 reader_info.is_enabled = plugin_status != PluginPrefs::POLICY_DISABLED; | |
| 67 } | |
| 68 | |
| 69 PluginMetadata::SecurityStatus security_status = | |
| 70 plugin_metadata->GetSecurityStatus(plugins[i]); | |
| 71 reader_info.is_secure = | |
| 72 security_status == PluginMetadata::SECURITY_STATUS_UP_TO_DATE; | |
| 73 | |
| 74 reader_info.plugin_info = plugins[i]; | |
| 75 break; | |
| 76 } | |
| 77 return reader_info; | |
| 78 } | |
| 79 | |
| 80 void OnGotPluginInfo(Profile* profile, | |
| 81 const GetAdobeReaderPluginInfoCallback& callback, | |
| 82 const std::vector<content::WebPluginInfo>& plugins) { | |
| 83 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | |
| 84 profile = NULL; | |
| 85 callback.Run(GetReaderPlugin(profile, plugins)); | |
| 86 } | |
| 87 | |
| 88 bool IsAdobeReaderDefaultPDFViewerInternal(base::FilePath* path) { | |
| 89 base::char16 app_cmd_buf[MAX_PATH]; | |
| 90 DWORD app_cmd_buf_len = MAX_PATH; | |
| 91 HRESULT hr = AssocQueryString(ASSOCF_NONE, ASSOCSTR_COMMAND, L".pdf", L"open", | |
| 92 app_cmd_buf, &app_cmd_buf_len); | |
| 93 if (FAILED(hr)) | |
| 94 return false; | |
| 95 | |
| 96 // Looks for the install paths for Acrobat / Reader. | |
| 97 base::FilePath install_path; | |
| 98 bool has_reader = content::GetInstalledPath( | |
| 99 content::kRegistryAcrobatReader, &install_path); | |
| 100 if (has_reader) { | |
| 101 install_path = install_path.Append(content::kRegistryAcrobatReader); | |
| 102 } else { | |
| 103 has_reader = content::GetInstalledPath( | |
| 104 content::kRegistryAcrobat, &install_path); | |
| 105 if (has_reader) | |
| 106 install_path = install_path.Append(content::kRegistryAcrobat); | |
| 107 else | |
| 108 return false; | |
| 109 } | |
| 110 | |
| 111 base::string16 app_cmd(app_cmd_buf); | |
| 112 bool found = app_cmd.find(install_path.value()) != base::string16::npos; | |
| 113 if (found && path) | |
| 114 *path = install_path; | |
| 115 return found; | |
| 116 } | |
| 117 | |
| 118 } // namespace | |
| 119 | |
| 120 void GetAdobeReaderPluginInfoAsync( | |
| 121 Profile* profile, | |
| 122 const GetAdobeReaderPluginInfoCallback& callback) { | |
| 123 DCHECK(!callback.is_null()); | |
| 124 content::PluginService::GetInstance()->GetPlugins( | |
| 125 base::Bind(&OnGotPluginInfo, profile, callback)); | |
| 126 } | |
| 127 | |
| 128 bool GetAdobeReaderPluginInfo(Profile* profile, | |
| 129 AdobeReaderPluginInfo* reader_info) { | |
| 130 DCHECK(reader_info); | |
| 131 std::vector<content::WebPluginInfo> plugins; | |
| 132 bool up_to_date = content::PluginService::GetInstance()->GetPluginInfoArray( | |
| 133 GURL(), kPdfMimeType, false, &plugins, NULL); | |
| 134 *reader_info = GetReaderPlugin(profile, plugins); | |
| 135 return up_to_date; | |
| 136 } | |
| 137 | |
| 138 bool IsAdobeReaderDefaultPDFViewer() { | |
| 139 return IsAdobeReaderDefaultPDFViewerInternal(NULL); | |
| 140 } | |
| 141 | |
| 142 bool IsAdobeReaderUpToDate() { | |
| 143 base::FilePath install_path; | |
| 144 bool is_default = IsAdobeReaderDefaultPDFViewerInternal(&install_path); | |
| 145 if (!is_default) | |
| 146 return false; | |
| 147 | |
| 148 scoped_ptr<FileVersionInfo> file_version_info( | |
| 149 FileVersionInfo::CreateFileVersionInfo(install_path)); | |
| 150 if (!file_version_info) | |
| 151 return false; | |
| 152 | |
| 153 std::string reader_version = | |
| 154 base::UTF16ToUTF8(file_version_info->product_version()); | |
| 155 // Convert 1.2.03.45 to 1.2.3.45 so base::Version considers it as valid. | |
| 156 for (int i = 1; i <= 9; ++i) { | |
| 157 std::string from = base::StringPrintf(".0%d", i); | |
| 158 std::string to = base::StringPrintf(".%d", i); | |
| 159 ReplaceSubstringsAfterOffset(&reader_version, 0, from, to); | |
| 160 } | |
| 161 base::Version file_version(reader_version); | |
| 162 return file_version.IsValid() && !file_version.IsOlderThan(kSecureVersion); | |
|
jam
2014/06/19 16:37:06
what if IsAdobeReaderDefaultPDFViewerInternal retu
Lei Zhang
2014/06/19 18:12:30
http://www.adobe.com/support/downloads/product.jsp
| |
| 163 } | |
| OLD | NEW |