| 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 "content/common/plugin_list.h" | 5 #include "content/common/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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/file_version_info.h" | 11 #include "base/file_version_info.h" |
| 12 #include "base/file_version_info_win.h" | 12 #include "base/file_version_info_win.h" |
| 13 #include "base/files/memory_mapped_file.h" | 13 #include "base/files/memory_mapped_file.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/win/pe_image.h" | 20 #include "base/win/pe_image.h" |
| 21 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
| 22 #include "base/win/scoped_handle.h" | 22 #include "base/win/scoped_handle.h" |
| 23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 24 #include "content/common/plugin_constants_win.h" | 24 #include "content/common/plugin_constants_win.h" |
| 25 #include "content/public/common/registry_utils_win.h" |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 const base::char16 kRegistryApps[] = | |
| 30 L"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths"; | |
| 31 const base::char16 kRegistryFirefox[] = L"firefox.exe"; | 30 const base::char16 kRegistryFirefox[] = L"firefox.exe"; |
| 32 const base::char16 kRegistryAcrobat[] = L"Acrobat.exe"; | |
| 33 const base::char16 kRegistryAcrobatReader[] = L"AcroRd32.exe"; | |
| 34 const base::char16 kRegistryWindowsMedia[] = L"wmplayer.exe"; | 31 const base::char16 kRegistryWindowsMedia[] = L"wmplayer.exe"; |
| 35 const base::char16 kRegistryQuickTime[] = L"QuickTimePlayer.exe"; | 32 const base::char16 kRegistryQuickTime[] = L"QuickTimePlayer.exe"; |
| 36 const base::char16 kRegistryPath[] = L"Path"; | |
| 37 const base::char16 kRegistryFirefoxInstalled[] = | 33 const base::char16 kRegistryFirefoxInstalled[] = |
| 38 L"SOFTWARE\\Mozilla\\Mozilla Firefox"; | 34 L"SOFTWARE\\Mozilla\\Mozilla Firefox"; |
| 39 const base::char16 kRegistryJava[] = | 35 const base::char16 kRegistryJava[] = |
| 40 L"Software\\JavaSoft\\Java Runtime Environment"; | 36 L"Software\\JavaSoft\\Java Runtime Environment"; |
| 41 const base::char16 kRegistryBrowserJavaVersion[] = L"BrowserJavaVersion"; | 37 const base::char16 kRegistryBrowserJavaVersion[] = L"BrowserJavaVersion"; |
| 42 const base::char16 kRegistryCurrentJavaVersion[] = L"CurrentVersion"; | 38 const base::char16 kRegistryCurrentJavaVersion[] = L"CurrentVersion"; |
| 43 const base::char16 kRegistryJavaHome[] = L"JavaHome"; | 39 const base::char16 kRegistryJavaHome[] = L"JavaHome"; |
| 44 const base::char16 kJavaDeploy1[] = L"npdeploytk.dll"; | |
| 45 const base::char16 kJavaDeploy2[] = L"npdeployjava1.dll"; | |
| 46 | 40 |
| 47 base::FilePath AppendPluginsDir(const base::FilePath& path) { | 41 base::FilePath AppendPluginsDir(const base::FilePath& path) { |
| 48 return path.AppendASCII("plugins"); | 42 return path.AppendASCII("plugins"); |
| 49 } | 43 } |
| 50 | 44 |
| 51 // Gets the directory where the application data and libraries exist. This | 45 // Gets the directory where the application data and libraries exist. This |
| 52 // may be a versioned subdirectory, or it may be the same directory as the | 46 // may be a versioned subdirectory, or it may be the same directory as the |
| 53 // GetExeDirectory(), depending on the embedder's implementation. | 47 // GetExeDirectory(), depending on the embedder's implementation. |
| 54 // Path is an output parameter to receive the path. | 48 // Path is an output parameter to receive the path. |
| 55 void GetAppDirectory(std::set<base::FilePath>* plugin_dirs) { | 49 void GetAppDirectory(std::set<base::FilePath>* plugin_dirs) { |
| 56 base::FilePath app_path; | 50 base::FilePath app_path; |
| 57 if (!PathService::Get(base::DIR_MODULE, &app_path)) | 51 if (!PathService::Get(base::DIR_MODULE, &app_path)) |
| 58 return; | 52 return; |
| 59 plugin_dirs->insert(AppendPluginsDir(app_path)); | 53 plugin_dirs->insert(AppendPluginsDir(app_path)); |
| 60 } | 54 } |
| 61 | 55 |
| 62 // Gets the directory where the launching executable resides on disk. | 56 // Gets the directory where the launching executable resides on disk. |
| 63 // Path is an output parameter to receive the path. | 57 // Path is an output parameter to receive the path. |
| 64 void GetExeDirectory(std::set<base::FilePath>* plugin_dirs) { | 58 void GetExeDirectory(std::set<base::FilePath>* plugin_dirs) { |
| 65 base::FilePath exe_path; | 59 base::FilePath exe_path; |
| 66 if (!PathService::Get(base::DIR_EXE, &exe_path)) | 60 if (!PathService::Get(base::DIR_EXE, &exe_path)) |
| 67 return; | 61 return; |
| 68 plugin_dirs->insert(AppendPluginsDir(exe_path)); | 62 plugin_dirs->insert(AppendPluginsDir(exe_path)); |
| 69 } | 63 } |
| 70 | 64 |
| 71 // Gets the installed path for a registered app. | |
| 72 bool GetInstalledPath(const base::char16* app, base::FilePath* out) { | |
| 73 base::string16 reg_path(kRegistryApps); | |
| 74 reg_path.append(L"\\"); | |
| 75 reg_path.append(app); | |
| 76 | |
| 77 base::win::RegKey hkcu_key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); | |
| 78 base::string16 path; | |
| 79 // As of Win7 AppPaths can also be registered in HKCU: http://goo.gl/UgFOf. | |
| 80 if (base::win::GetVersion() >= base::win::VERSION_WIN7 && | |
| 81 hkcu_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { | |
| 82 *out = base::FilePath(path); | |
| 83 return true; | |
| 84 } else { | |
| 85 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | |
| 86 if (hklm_key.ReadValue(kRegistryPath, &path) == ERROR_SUCCESS) { | |
| 87 *out = base::FilePath(path); | |
| 88 return true; | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 return false; | |
| 93 } | |
| 94 | |
| 95 // Search the registry at the given path and detect plugin directories. | 65 // Search the registry at the given path and detect plugin directories. |
| 96 void GetPluginsInRegistryDirectory( | 66 void GetPluginsInRegistryDirectory( |
| 97 HKEY root_key, | 67 HKEY root_key, |
| 98 const base::string16& registry_folder, | 68 const base::string16& registry_folder, |
| 99 std::set<base::FilePath>* plugin_dirs) { | 69 std::set<base::FilePath>* plugin_dirs) { |
| 100 for (base::win::RegistryKeyIterator iter(root_key, registry_folder.c_str()); | 70 for (base::win::RegistryKeyIterator iter(root_key, registry_folder.c_str()); |
| 101 iter.Valid(); ++iter) { | 71 iter.Valid(); ++iter) { |
| 102 // Use the registry to gather plugin across the file system. | 72 // Use the registry to gather plugin across the file system. |
| 103 base::string16 reg_path = registry_folder; | 73 base::string16 reg_path = registry_folder; |
| 104 reg_path.append(L"\\"); | 74 reg_path.append(L"\\"); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // Load firefox plugins too. This is mainly to try to locate | 287 // Load firefox plugins too. This is mainly to try to locate |
| 318 // a pre-installed Flash player. | 288 // a pre-installed Flash player. |
| 319 GetFirefoxDirectory(&dirs); | 289 GetFirefoxDirectory(&dirs); |
| 320 | 290 |
| 321 // Firefox hard-codes the paths of some popular plugins to ensure that | 291 // Firefox hard-codes the paths of some popular plugins to ensure that |
| 322 // the plugins are found. We are going to copy this as well. | 292 // the plugins are found. We are going to copy this as well. |
| 323 GetAcrobatDirectory(&dirs); | 293 GetAcrobatDirectory(&dirs); |
| 324 GetQuicktimeDirectory(&dirs); | 294 GetQuicktimeDirectory(&dirs); |
| 325 GetWindowsMediaDirectory(&dirs); | 295 GetWindowsMediaDirectory(&dirs); |
| 326 | 296 |
| 327 for (std::set<base::FilePath>::iterator i = dirs.begin(); i != dirs.end(); ++i
) | 297 for (std::set<base::FilePath>::iterator i = dirs.begin(); |
| 298 i != dirs.end(); ++i) |
| 328 plugin_dirs->push_back(*i); | 299 plugin_dirs->push_back(*i); |
| 329 } | 300 } |
| 330 | 301 |
| 331 void PluginList::GetPluginsInDir( | 302 void PluginList::GetPluginsInDir( |
| 332 const base::FilePath& path, std::vector<base::FilePath>* plugins) { | 303 const base::FilePath& path, std::vector<base::FilePath>* plugins) { |
| 333 WIN32_FIND_DATA find_file_data; | 304 WIN32_FIND_DATA find_file_data; |
| 334 HANDLE find_handle; | 305 HANDLE find_handle; |
| 335 | 306 |
| 336 base::string16 dir = path.value(); | 307 base::string16 dir = path.value(); |
| 337 // FindFirstFile requires that you specify a wildcard for directories. | 308 // FindFirstFile requires that you specify a wildcard for directories. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 info.path) == extra_plugin_paths_.end(); | 352 info.path) == extra_plugin_paths_.end(); |
| 382 } | 353 } |
| 383 // Version check for plugins that are not coming from |extra_plugin_paths_|. | 354 // Version check for plugins that are not coming from |extra_plugin_paths_|. |
| 384 if (should_check_version) { | 355 if (should_check_version) { |
| 385 for (size_t j = 0; j < plugins->size(); ++j) { | 356 for (size_t j = 0; j < plugins->size(); ++j) { |
| 386 base::FilePath::StringType plugin1 = | 357 base::FilePath::StringType plugin1 = |
| 387 StringToLowerASCII((*plugins)[j].path.BaseName().value()); | 358 StringToLowerASCII((*plugins)[j].path.BaseName().value()); |
| 388 base::FilePath::StringType plugin2 = | 359 base::FilePath::StringType plugin2 = |
| 389 StringToLowerASCII(info.path.BaseName().value()); | 360 StringToLowerASCII(info.path.BaseName().value()); |
| 390 if ((plugin1 == plugin2 && HaveSharedMimeType((*plugins)[j], info)) || | 361 if ((plugin1 == plugin2 && HaveSharedMimeType((*plugins)[j], info)) || |
| 391 (plugin1 == kJavaDeploy1 && plugin2 == kJavaDeploy2) || | 362 (plugin1 == kJavaPlugin2 && plugin2 == kJavaPlugin3) || |
| 392 (plugin1 == kJavaDeploy2 && plugin2 == kJavaDeploy1)) { | 363 (plugin1 == kJavaPlugin3 && plugin2 == kJavaPlugin2)) { |
| 393 if (IsNewerVersion(info.version, (*plugins)[j].version)) | 364 if (IsNewerVersion(info.version, (*plugins)[j].version)) |
| 394 return false; // We have loaded a plugin whose version is newer. | 365 return false; // We have loaded a plugin whose version is newer. |
| 395 plugins->erase(plugins->begin() + j); | 366 plugins->erase(plugins->begin() + j); |
| 396 break; | 367 break; |
| 397 } | 368 } |
| 398 } | 369 } |
| 399 } | 370 } |
| 400 | 371 |
| 401 // The checks below only apply to NPAPI plugins. | 372 // The checks below only apply to NPAPI plugins. |
| 402 if (info.type != WebPluginInfo::PLUGIN_TYPE_NPAPI) | 373 if (info.type != WebPluginInfo::PLUGIN_TYPE_NPAPI) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 #if !defined(ARCH_CPU_X86_64) | 437 #if !defined(ARCH_CPU_X86_64) |
| 467 // The plugin in question could be a 64 bit plugin which we cannot load. | 438 // The plugin in question could be a 64 bit plugin which we cannot load. |
| 468 base::FilePath plugin_path(info.path); | 439 base::FilePath plugin_path(info.path); |
| 469 if (!IsValid32BitImage(base::MakeAbsoluteFilePath(plugin_path))) | 440 if (!IsValid32BitImage(base::MakeAbsoluteFilePath(plugin_path))) |
| 470 return false; | 441 return false; |
| 471 #endif | 442 #endif |
| 472 return true; | 443 return true; |
| 473 } | 444 } |
| 474 | 445 |
| 475 } // namespace content | 446 } // namespace content |
| OLD | NEW |