OLD | NEW |
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/version.h" |
20 #include "base/win/registry.h" | 20 #include "base/win/registry.h" |
21 #include "base/win/windows_version.h" | |
22 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 // Hardcoded value for the secure version of Acrobat Reader. | 25 // Hardcoded value for the secure version of Acrobat Reader. |
27 const char kSecureVersion[] = "11.0.8.4"; | 26 const char kSecureVersion[] = "11.0.8.4"; |
28 | 27 |
29 const base::char16 kRegistryAcrobat[] = L"Acrobat.exe"; | 28 const base::char16 kRegistryAcrobat[] = L"Acrobat.exe"; |
30 const base::char16 kRegistryAcrobatReader[] = L"AcroRd32.exe"; | 29 const base::char16 kRegistryAcrobatReader[] = L"AcroRd32.exe"; |
31 const base::char16 kRegistryApps[] = | 30 const base::char16 kRegistryApps[] = |
32 L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths"; | 31 L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths"; |
33 const base::char16 kRegistryPath[] = L"Path"; | 32 const base::char16 kRegistryPath[] = L"Path"; |
34 | 33 |
35 // Gets the installed path for a registered app. | 34 // Gets the installed path for a registered app. |
36 base::FilePath GetInstalledPath(const base::char16* app) { | 35 base::FilePath GetInstalledPath(const base::char16* app) { |
37 base::string16 reg_path(kRegistryApps); | 36 base::string16 reg_path(kRegistryApps); |
38 reg_path.append(L"\\"); | 37 reg_path.append(L"\\"); |
39 reg_path.append(app); | 38 reg_path.append(app); |
40 | 39 |
41 base::FilePath filepath; | 40 base::FilePath filepath; |
42 base::win::RegKey hkcu_key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); | 41 base::win::RegKey hkcu_key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); |
43 base::string16 path; | 42 base::string16 path; |
44 // As of Win7 AppPaths can also be registered in HKCU: http://goo.gl/UgFOf. | 43 // AppPaths can also be registered in HKCU: http://goo.gl/UgFOf. |
45 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && | 44 if (hkcu_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { |
46 hkcu_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { | |
47 filepath = base::FilePath(path); | 45 filepath = base::FilePath(path); |
48 } else { | 46 } else { |
49 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | 47 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); |
50 if (hklm_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { | 48 if (hklm_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { |
51 filepath = base::FilePath(path); | 49 filepath = base::FilePath(path); |
52 } | 50 } |
53 } | 51 } |
54 return filepath.Append(app); | 52 return filepath.Append(app); |
55 } | 53 } |
56 | 54 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // Convert 1.2.03.45 to 1.2.3.45 so base::Version considers it as valid. | 96 // Convert 1.2.03.45 to 1.2.3.45 so base::Version considers it as valid. |
99 for (int i = 1; i <= 9; ++i) { | 97 for (int i = 1; i <= 9; ++i) { |
100 std::string from = base::StringPrintf(".0%d", i); | 98 std::string from = base::StringPrintf(".0%d", i); |
101 std::string to = base::StringPrintf(".%d", i); | 99 std::string to = base::StringPrintf(".%d", i); |
102 base::ReplaceSubstringsAfterOffset(&reader_version, 0, from, to); | 100 base::ReplaceSubstringsAfterOffset(&reader_version, 0, from, to); |
103 } | 101 } |
104 base::Version file_version(reader_version); | 102 base::Version file_version(reader_version); |
105 return file_version.IsValid() && | 103 return file_version.IsValid() && |
106 file_version >= base::Version(kSecureVersion); | 104 file_version >= base::Version(kSecureVersion); |
107 } | 105 } |
OLD | NEW |