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

Side by Side Diff: chrome/browser/ui/pdf/adobe_reader_info_win.cc

Issue 2518493002: Remove obsolete plugin state handling code. (Closed)
Patch Set: Removed unusued function. Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" 5 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
6 6
7 #include <shlwapi.h> 7 #include <shlwapi.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/file_version_info.h" 15 #include "base/file_version_info.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/version.h"
19 #include "base/win/registry.h" 20 #include "base/win/registry.h"
20 #include "base/win/windows_version.h" 21 #include "base/win/windows_version.h"
21 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
22 #include "chrome/browser/plugins/plugin_finder.h"
23 #include "chrome/browser/plugins/plugin_metadata.h"
24 #include "chrome/browser/plugins/plugin_prefs.h"
25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_manager.h"
27 #include "content/public/browser/plugin_service.h"
28 23
29 namespace { 24 namespace {
30 25
31 // Hardcoded value for the secure version of Acrobat Reader. 26 // Hardcoded value for the secure version of Acrobat Reader.
32 const char kSecureVersion[] = "11.0.8.4"; 27 const char kSecureVersion[] = "11.0.8.4";
33 28
34 const char kAdobeReaderIdentifier[] = "adobe-reader";
35 const char kPdfMimeType[] = "application/pdf";
36 const base::char16 kRegistryAcrobat[] = L"Acrobat.exe"; 29 const base::char16 kRegistryAcrobat[] = L"Acrobat.exe";
37 const base::char16 kRegistryAcrobatReader[] = L"AcroRd32.exe"; 30 const base::char16 kRegistryAcrobatReader[] = L"AcroRd32.exe";
38 const base::char16 kRegistryApps[] = 31 const base::char16 kRegistryApps[] =
39 L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths"; 32 L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths";
40 const base::char16 kRegistryPath[] = L"Path"; 33 const base::char16 kRegistryPath[] = L"Path";
41 34
42 // Gets the installed path for a registered app. 35 // Gets the installed path for a registered app.
43 base::FilePath GetInstalledPath(const base::char16* app) { 36 base::FilePath GetInstalledPath(const base::char16* app) {
44 base::string16 reg_path(kRegistryApps); 37 base::string16 reg_path(kRegistryApps);
45 reg_path.append(L"\\"); 38 reg_path.append(L"\\");
46 reg_path.append(app); 39 reg_path.append(app);
47 40
48 base::FilePath filepath; 41 base::FilePath filepath;
49 base::win::RegKey hkcu_key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); 42 base::win::RegKey hkcu_key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ);
50 base::string16 path; 43 base::string16 path;
51 // As of Win7 AppPaths can also be registered in HKCU: http://goo.gl/UgFOf. 44 // As of Win7 AppPaths can also be registered in HKCU: http://goo.gl/UgFOf.
52 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && 45 if (base::win::GetVersion() >= base::win::VERSION_WIN7 &&
53 hkcu_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { 46 hkcu_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) {
54 filepath = base::FilePath(path); 47 filepath = base::FilePath(path);
55 } else { 48 } else {
56 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); 49 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ);
57 if (hklm_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { 50 if (hklm_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) {
58 filepath = base::FilePath(path); 51 filepath = base::FilePath(path);
59 } 52 }
60 } 53 }
61 return filepath.Append(app); 54 return filepath.Append(app);
62 } 55 }
63 56
64 bool IsPdfMimeType(const content::WebPluginMimeType& plugin_mime_type) {
65 return plugin_mime_type.mime_type == kPdfMimeType;
66 }
67
68 AdobeReaderPluginInfo GetReaderPlugin(
69 Profile* profile,
70 const std::vector<content::WebPluginInfo>& plugins) {
71 AdobeReaderPluginInfo reader_info;
72 reader_info.is_installed = false;
73 reader_info.is_enabled = false;
74 reader_info.is_secure = false;
75
76 PluginFinder* plugin_finder = PluginFinder::GetInstance();
77 for (size_t i = 0; i < plugins.size(); ++i) {
78 const content::WebPluginInfo& plugin = plugins[i];
79 if (plugin.is_pepper_plugin())
80 continue;
81 if (std::find_if(plugin.mime_types.begin(), plugin.mime_types.end(),
82 IsPdfMimeType) == plugin.mime_types.end())
83 continue;
84 std::unique_ptr<PluginMetadata> plugin_metadata(
85 plugin_finder->GetPluginMetadata(plugins[i]));
86 if (plugin_metadata->identifier() != kAdobeReaderIdentifier)
87 continue;
88
89 reader_info.is_installed = true;
90
91 if (profile) {
92 scoped_refptr<PluginPrefs> plugin_prefs =
93 PluginPrefs::GetForProfile(profile);
94 PluginPrefs::PolicyStatus plugin_status =
95 plugin_prefs->PolicyStatusForPlugin(plugin_metadata->name());
96 reader_info.is_enabled = plugin_status != PluginPrefs::POLICY_DISABLED;
97 }
98
99 // Adobe Reader will likely always come up as "requires_authorization".
100 // See http://crbug.com/311655.
101 PluginMetadata::SecurityStatus security_stat =
102 plugin_metadata->GetSecurityStatus(plugins[i]);
103 reader_info.is_secure =
104 security_stat == PluginMetadata::SECURITY_STATUS_UP_TO_DATE ||
105 security_stat == PluginMetadata::SECURITY_STATUS_REQUIRES_AUTHORIZATION;
106
107 reader_info.plugin_info = plugins[i];
108 break;
109 }
110 return reader_info;
111 }
112
113 void OnGotPluginInfo(Profile* profile,
114 const GetAdobeReaderPluginInfoCallback& callback,
115 const std::vector<content::WebPluginInfo>& plugins) {
116 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
117 profile = NULL;
118 callback.Run(GetReaderPlugin(profile, plugins));
119 }
120
121 bool IsAdobeReaderDefaultPDFViewerInternal(base::FilePath* path) { 57 bool IsAdobeReaderDefaultPDFViewerInternal(base::FilePath* path) {
122 base::char16 app_cmd_buf[MAX_PATH]; 58 base::char16 app_cmd_buf[MAX_PATH];
123 DWORD app_cmd_buf_len = MAX_PATH; 59 DWORD app_cmd_buf_len = MAX_PATH;
124 HRESULT hr = AssocQueryString(ASSOCF_NONE, ASSOCSTR_COMMAND, L".pdf", L"open", 60 HRESULT hr = AssocQueryString(ASSOCF_NONE, ASSOCSTR_COMMAND, L".pdf", L"open",
125 app_cmd_buf, &app_cmd_buf_len); 61 app_cmd_buf, &app_cmd_buf_len);
126 if (FAILED(hr)) 62 if (FAILED(hr))
127 return false; 63 return false;
128 64
129 // Looks for the install paths for Acrobat / Reader. 65 // Looks for the install paths for Acrobat / Reader.
130 base::FilePath install_path = GetInstalledPath(kRegistryAcrobatReader); 66 base::FilePath install_path = GetInstalledPath(kRegistryAcrobatReader);
131 if (install_path.empty()) 67 if (install_path.empty())
132 install_path = GetInstalledPath(kRegistryAcrobat); 68 install_path = GetInstalledPath(kRegistryAcrobat);
133 if (install_path.empty()) 69 if (install_path.empty())
134 return false; 70 return false;
135 71
136 base::string16 app_cmd(app_cmd_buf); 72 base::string16 app_cmd(app_cmd_buf);
137 bool found = app_cmd.find(install_path.value()) != base::string16::npos; 73 bool found = app_cmd.find(install_path.value()) != base::string16::npos;
138 if (found && path) 74 if (found && path)
139 *path = install_path; 75 *path = install_path;
140 return found; 76 return found;
141 } 77 }
142 78
143 } // namespace 79 } // namespace
144 80
145 void GetAdobeReaderPluginInfoAsync(
146 Profile* profile,
147 const GetAdobeReaderPluginInfoCallback& callback) {
148 DCHECK(!callback.is_null());
149 content::PluginService::GetInstance()->GetPlugins(
150 base::Bind(&OnGotPluginInfo, profile, callback));
151 }
152
153 bool GetAdobeReaderPluginInfo(Profile* profile,
154 AdobeReaderPluginInfo* reader_info) {
155 DCHECK(reader_info);
156 std::vector<content::WebPluginInfo> plugins;
157 bool up_to_date = content::PluginService::GetInstance()->GetPluginInfoArray(
158 GURL(), kPdfMimeType, false, &plugins, NULL);
159 *reader_info = GetReaderPlugin(profile, plugins);
160 return up_to_date;
161 }
162
163 bool IsAdobeReaderDefaultPDFViewer() { 81 bool IsAdobeReaderDefaultPDFViewer() {
164 return IsAdobeReaderDefaultPDFViewerInternal(NULL); 82 return IsAdobeReaderDefaultPDFViewerInternal(NULL);
165 } 83 }
166 84
167 bool IsAdobeReaderUpToDate() { 85 bool IsAdobeReaderUpToDate() {
168 base::FilePath install_path; 86 base::FilePath install_path;
169 bool is_default = IsAdobeReaderDefaultPDFViewerInternal(&install_path); 87 bool is_default = IsAdobeReaderDefaultPDFViewerInternal(&install_path);
170 if (!is_default) 88 if (!is_default)
171 return false; 89 return false;
172 90
173 std::unique_ptr<FileVersionInfo> file_version_info( 91 std::unique_ptr<FileVersionInfo> file_version_info(
174 FileVersionInfo::CreateFileVersionInfo(install_path)); 92 FileVersionInfo::CreateFileVersionInfo(install_path));
175 if (!file_version_info) 93 if (!file_version_info)
176 return false; 94 return false;
177 95
178 std::string reader_version = 96 std::string reader_version =
179 base::UTF16ToUTF8(file_version_info->product_version()); 97 base::UTF16ToUTF8(file_version_info->product_version());
180 // Convert 1.2.03.45 to 1.2.3.45 so base::Version considers it as valid. 98 // Convert 1.2.03.45 to 1.2.3.45 so base::Version considers it as valid.
181 for (int i = 1; i <= 9; ++i) { 99 for (int i = 1; i <= 9; ++i) {
182 std::string from = base::StringPrintf(".0%d", i); 100 std::string from = base::StringPrintf(".0%d", i);
183 std::string to = base::StringPrintf(".%d", i); 101 std::string to = base::StringPrintf(".%d", i);
184 base::ReplaceSubstringsAfterOffset(&reader_version, 0, from, to); 102 base::ReplaceSubstringsAfterOffset(&reader_version, 0, from, to);
185 } 103 }
186 base::Version file_version(reader_version); 104 base::Version file_version(reader_version);
187 return file_version.IsValid() && 105 return file_version.IsValid() &&
188 file_version >= base::Version(kSecureVersion); 106 file_version >= base::Version(kSecureVersion);
189 } 107 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/pdf/adobe_reader_info_win.h ('k') | chrome/browser/ui/pdf/chrome_pdf_web_contents_helper_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698