| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/plugins/npapi/plugin_list.h" | 5 #include "webkit/plugins/npapi/plugin_list.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // Path is an output parameter to receive the path. | 63 // Path is an output parameter to receive the path. |
| 64 void GetExeDirectory(std::set<base::FilePath>* plugin_dirs) { | 64 void GetExeDirectory(std::set<base::FilePath>* plugin_dirs) { |
| 65 base::FilePath exe_path; | 65 base::FilePath exe_path; |
| 66 if (!PathService::Get(base::DIR_EXE, &exe_path)) | 66 if (!PathService::Get(base::DIR_EXE, &exe_path)) |
| 67 return; | 67 return; |
| 68 plugin_dirs->insert(AppendPluginsDir(exe_path)); | 68 plugin_dirs->insert(AppendPluginsDir(exe_path)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Gets the installed path for a registered app. | 71 // Gets the installed path for a registered app. |
| 72 bool GetInstalledPath(const char16* app, base::FilePath* out) { | 72 bool GetInstalledPath(const char16* app, base::FilePath* out) { |
| 73 string16 reg_path(kRegistryApps); | 73 base::string16 reg_path(kRegistryApps); |
| 74 reg_path.append(L"\\"); | 74 reg_path.append(L"\\"); |
| 75 reg_path.append(app); | 75 reg_path.append(app); |
| 76 | 76 |
| 77 base::win::RegKey hkcu_key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); | 77 base::win::RegKey hkcu_key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); |
| 78 string16 path; | 78 base::string16 path; |
| 79 // As of Win7 AppPaths can also be registered in HKCU: http://goo.gl/UgFOf. | 79 // As of Win7 AppPaths can also be registered in HKCU: http://goo.gl/UgFOf. |
| 80 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && | 80 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && |
| 81 hkcu_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { | 81 hkcu_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { |
| 82 *out = base::FilePath(path); | 82 *out = base::FilePath(path); |
| 83 return true; | 83 return true; |
| 84 } else { | 84 } else { |
| 85 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | 85 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); |
| 86 if (hklm_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { | 86 if (hklm_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { |
| 87 *out = base::FilePath(path); | 87 *out = base::FilePath(path); |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 return false; | 92 return false; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Search the registry at the given path and detect plugin directories. | 95 // Search the registry at the given path and detect plugin directories. |
| 96 void GetPluginsInRegistryDirectory( | 96 void GetPluginsInRegistryDirectory( |
| 97 HKEY root_key, | 97 HKEY root_key, |
| 98 const string16& registry_folder, | 98 const base::string16& registry_folder, |
| 99 std::set<base::FilePath>* plugin_dirs) { | 99 std::set<base::FilePath>* plugin_dirs) { |
| 100 for (base::win::RegistryKeyIterator iter(root_key, registry_folder.c_str()); | 100 for (base::win::RegistryKeyIterator iter(root_key, registry_folder.c_str()); |
| 101 iter.Valid(); ++iter) { | 101 iter.Valid(); ++iter) { |
| 102 // Use the registry to gather plugin across the file system. | 102 // Use the registry to gather plugin across the file system. |
| 103 string16 reg_path = registry_folder; | 103 base::string16 reg_path = registry_folder; |
| 104 reg_path.append(L"\\"); | 104 reg_path.append(L"\\"); |
| 105 reg_path.append(iter.Name()); | 105 reg_path.append(iter.Name()); |
| 106 base::win::RegKey key(root_key, reg_path.c_str(), KEY_READ); | 106 base::win::RegKey key(root_key, reg_path.c_str(), KEY_READ); |
| 107 | 107 |
| 108 string16 path; | 108 base::string16 path; |
| 109 if (key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) | 109 if (key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) |
| 110 plugin_dirs->insert(base::FilePath(path)); | 110 plugin_dirs->insert(base::FilePath(path)); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Enumerate through the registry key to find all installed FireFox paths. | 114 // Enumerate through the registry key to find all installed FireFox paths. |
| 115 // FireFox 3 beta and version 2 can coexist. See bug: 1025003 | 115 // FireFox 3 beta and version 2 can coexist. See bug: 1025003 |
| 116 void GetFirefoxInstalledPaths(std::vector<base::FilePath>* out) { | 116 void GetFirefoxInstalledPaths(std::vector<base::FilePath>* out) { |
| 117 base::win::RegistryKeyIterator it(HKEY_LOCAL_MACHINE, | 117 base::win::RegistryKeyIterator it(HKEY_LOCAL_MACHINE, |
| 118 kRegistryFirefoxInstalled); | 118 kRegistryFirefoxInstalled); |
| 119 for (; it.Valid(); ++it) { | 119 for (; it.Valid(); ++it) { |
| 120 string16 full_path = string16(kRegistryFirefoxInstalled) + L"\\" + | 120 base::string16 full_path = base::string16(kRegistryFirefoxInstalled) + |
| 121 it.Name() + L"\\Main"; | 121 L"\\" + it.Name() + L"\\Main"; |
| 122 base::win::RegKey key(HKEY_LOCAL_MACHINE, full_path.c_str(), KEY_READ); | 122 base::win::RegKey key(HKEY_LOCAL_MACHINE, full_path.c_str(), KEY_READ); |
| 123 string16 install_dir; | 123 base::string16 install_dir; |
| 124 if (key.ReadValue(L"Install Directory", &install_dir) != ERROR_SUCCESS) | 124 if (key.ReadValue(L"Install Directory", &install_dir) != ERROR_SUCCESS) |
| 125 continue; | 125 continue; |
| 126 out->push_back(base::FilePath(install_dir)); | 126 out->push_back(base::FilePath(install_dir)); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Get plugin directory locations from the Firefox install path. This is kind | 130 // Get plugin directory locations from the Firefox install path. This is kind |
| 131 // of a kludge, but it helps us locate the flash player for users that | 131 // of a kludge, but it helps us locate the flash player for users that |
| 132 // already have it for firefox. Not having to download yet-another-plugin | 132 // already have it for firefox. Not having to download yet-another-plugin |
| 133 // is a good thing. | 133 // is a good thing. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Hardcoded logic to detect Java plugin location. | 174 // Hardcoded logic to detect Java plugin location. |
| 175 void GetJavaDirectory(std::set<base::FilePath>* plugin_dirs) { | 175 void GetJavaDirectory(std::set<base::FilePath>* plugin_dirs) { |
| 176 // Load the new NPAPI Java plugin | 176 // Load the new NPAPI Java plugin |
| 177 // 1. Open the main JRE key under HKLM | 177 // 1. Open the main JRE key under HKLM |
| 178 base::win::RegKey java_key(HKEY_LOCAL_MACHINE, kRegistryJava, | 178 base::win::RegKey java_key(HKEY_LOCAL_MACHINE, kRegistryJava, |
| 179 KEY_QUERY_VALUE); | 179 KEY_QUERY_VALUE); |
| 180 | 180 |
| 181 // 2. Read the current Java version | 181 // 2. Read the current Java version |
| 182 string16 java_version; | 182 base::string16 java_version; |
| 183 if (java_key.ReadValue(kRegistryBrowserJavaVersion, &java_version) != | 183 if (java_key.ReadValue(kRegistryBrowserJavaVersion, &java_version) != |
| 184 ERROR_SUCCESS) { | 184 ERROR_SUCCESS) { |
| 185 java_key.ReadValue(kRegistryCurrentJavaVersion, &java_version); | 185 java_key.ReadValue(kRegistryCurrentJavaVersion, &java_version); |
| 186 } | 186 } |
| 187 | 187 |
| 188 if (!java_version.empty()) { | 188 if (!java_version.empty()) { |
| 189 java_key.OpenKey(java_version.c_str(), KEY_QUERY_VALUE); | 189 java_key.OpenKey(java_version.c_str(), KEY_QUERY_VALUE); |
| 190 | 190 |
| 191 // 3. Install path of the JRE binaries is specified in "JavaHome" | 191 // 3. Install path of the JRE binaries is specified in "JavaHome" |
| 192 // value under the Java version key. | 192 // value under the Java version key. |
| 193 string16 java_plugin_directory; | 193 base::string16 java_plugin_directory; |
| 194 if (java_key.ReadValue(kRegistryJavaHome, &java_plugin_directory) == | 194 if (java_key.ReadValue(kRegistryJavaHome, &java_plugin_directory) == |
| 195 ERROR_SUCCESS) { | 195 ERROR_SUCCESS) { |
| 196 // 4. The new plugin resides under the 'bin/new_plugin' | 196 // 4. The new plugin resides under the 'bin/new_plugin' |
| 197 // subdirectory. | 197 // subdirectory. |
| 198 DCHECK(!java_plugin_directory.empty()); | 198 DCHECK(!java_plugin_directory.empty()); |
| 199 java_plugin_directory.append(L"\\bin\\new_plugin"); | 199 java_plugin_directory.append(L"\\bin\\new_plugin"); |
| 200 | 200 |
| 201 // 5. We don't know the exact name of the DLL but it's in the form | 201 // 5. We don't know the exact name of the DLL but it's in the form |
| 202 // NP*.dll so just invoke LoadPlugins on this path. | 202 // NP*.dll so just invoke LoadPlugins on this path. |
| 203 plugin_dirs->insert(base::FilePath(java_plugin_directory)); | 203 plugin_dirs->insert(base::FilePath(java_plugin_directory)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 227 if (plugin1.mime_types[i].mime_type == plugin2.mime_types[j].mime_type) | 227 if (plugin1.mime_types[i].mime_type == plugin2.mime_types[j].mime_type) |
| 228 return true; | 228 return true; |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 | 231 |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Compares Windows style version strings (i.e. 1,2,3,4). Returns true if b's | 235 // Compares Windows style version strings (i.e. 1,2,3,4). Returns true if b's |
| 236 // version is newer than a's, or false if it's equal or older. | 236 // version is newer than a's, or false if it's equal or older. |
| 237 bool IsNewerVersion(const string16& a, const string16& b) { | 237 bool IsNewerVersion(const base::string16& a, const base::string16& b) { |
| 238 std::vector<string16> a_ver, b_ver; | 238 std::vector<base::string16> a_ver, b_ver; |
| 239 base::SplitString(a, ',', &a_ver); | 239 base::SplitString(a, ',', &a_ver); |
| 240 base::SplitString(b, ',', &b_ver); | 240 base::SplitString(b, ',', &b_ver); |
| 241 if (a_ver.size() == 1 && b_ver.size() == 1) { | 241 if (a_ver.size() == 1 && b_ver.size() == 1) { |
| 242 base::SplitString(a, '.', &a_ver); | 242 base::SplitString(a, '.', &a_ver); |
| 243 base::SplitString(b, '.', &b_ver); | 243 base::SplitString(b, '.', &b_ver); |
| 244 } | 244 } |
| 245 if (a_ver.size() != b_ver.size()) | 245 if (a_ver.size() != b_ver.size()) |
| 246 return false; | 246 return false; |
| 247 for (size_t i = 0; i < a_ver.size(); i++) { | 247 for (size_t i = 0; i < a_ver.size(); i++) { |
| 248 int cur_a, cur_b; | 248 int cur_a, cur_b; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 292 |
| 293 for (std::set<base::FilePath>::iterator i = dirs.begin(); i != dirs.end(); ++i
) | 293 for (std::set<base::FilePath>::iterator i = dirs.begin(); i != dirs.end(); ++i
) |
| 294 plugin_dirs->push_back(*i); | 294 plugin_dirs->push_back(*i); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void PluginList::GetPluginsInDir( | 297 void PluginList::GetPluginsInDir( |
| 298 const base::FilePath& path, std::vector<base::FilePath>* plugins) { | 298 const base::FilePath& path, std::vector<base::FilePath>* plugins) { |
| 299 WIN32_FIND_DATA find_file_data; | 299 WIN32_FIND_DATA find_file_data; |
| 300 HANDLE find_handle; | 300 HANDLE find_handle; |
| 301 | 301 |
| 302 string16 dir = path.value(); | 302 base::string16 dir = path.value(); |
| 303 // FindFirstFile requires that you specify a wildcard for directories. | 303 // FindFirstFile requires that you specify a wildcard for directories. |
| 304 dir.append(L"\\NP*.DLL"); | 304 dir.append(L"\\NP*.DLL"); |
| 305 | 305 |
| 306 find_handle = FindFirstFile(dir.c_str(), &find_file_data); | 306 find_handle = FindFirstFile(dir.c_str(), &find_file_data); |
| 307 if (find_handle == INVALID_HANDLE_VALUE) | 307 if (find_handle == INVALID_HANDLE_VALUE) |
| 308 return; | 308 return; |
| 309 | 309 |
| 310 do { | 310 do { |
| 311 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { | 311 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { |
| 312 base::FilePath filename = path.Append(find_file_data.cFileName); | 312 base::FilePath filename = path.Append(find_file_data.cFileName); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 base::FilePath plugin_path(info.path); | 421 base::FilePath plugin_path(info.path); |
| 422 file_util::AbsolutePath(&plugin_path); | 422 file_util::AbsolutePath(&plugin_path); |
| 423 if (!IsValid32BitImage(plugin_path)) | 423 if (!IsValid32BitImage(plugin_path)) |
| 424 return false; | 424 return false; |
| 425 #endif | 425 #endif |
| 426 return true; | 426 return true; |
| 427 } | 427 } |
| 428 | 428 |
| 429 } // namespace npapi | 429 } // namespace npapi |
| 430 } // namespace webkit | 430 } // namespace webkit |
| OLD | NEW |