| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extensions/external_registry_extension_provider_win.h" | 5 #include "chrome/browser/extensions/external_registry_extension_loader_win.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" |
| 10 #include "base/version.h" | 11 #include "base/version.h" |
| 11 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
| 13 #include "chrome/browser/browser_thread.h" |
| 14 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
| 12 | 15 |
| 13 namespace { | 16 namespace { |
| 14 | 17 |
| 15 // The Registry hive where to look for external extensions. | 18 // The Registry hive where to look for external extensions. |
| 16 const HKEY kRegRoot = HKEY_LOCAL_MACHINE; | 19 const HKEY kRegRoot = HKEY_LOCAL_MACHINE; |
| 17 | 20 |
| 18 // The Registry subkey that contains information about external extensions. | 21 // The Registry subkey that contains information about external extensions. |
| 19 const char kRegistryExtensions[] = "Software\\Google\\Chrome\\Extensions"; | 22 const char kRegistryExtensions[] = "Software\\Google\\Chrome\\Extensions"; |
| 20 | 23 |
| 21 // Registry value of of that key that defines the path to the .crx file. | 24 // Registry value of of that key that defines the path to the .crx file. |
| 22 const wchar_t kRegistryExtensionPath[] = L"path"; | 25 const wchar_t kRegistryExtensionPath[] = L"path"; |
| 23 | 26 |
| 24 // Registry value of that key that defines the current version of the .crx file. | 27 // Registry value of that key that defines the current version of the .crx file. |
| 25 const wchar_t kRegistryExtensionVersion[] = L"version"; | 28 const wchar_t kRegistryExtensionVersion[] = L"version"; |
| 26 | 29 |
| 27 bool OpenKeyById(const std::string& id, base::win::RegKey *key) { | 30 } // namespace |
| 28 std::wstring key_path = ASCIIToWide(kRegistryExtensions); | |
| 29 key_path.append(L"\\"); | |
| 30 key_path.append(ASCIIToWide(id)); | |
| 31 | 31 |
| 32 return key->Open(kRegRoot, key_path.c_str(), KEY_READ); | 32 void ExternalRegistryExtensionLoader::StartLoading() { |
| 33 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 34 BrowserThread::PostTask( |
| 35 BrowserThread::FILE, FROM_HERE, |
| 36 NewRunnableMethod( |
| 37 this, |
| 38 &ExternalRegistryExtensionLoader::LoadOnFileThread)); |
| 33 } | 39 } |
| 34 | 40 |
| 35 } // namespace | 41 void ExternalRegistryExtensionLoader::LoadOnFileThread() { |
| 42 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 43 scoped_ptr<DictionaryValue> prefs(new DictionaryValue); |
| 36 | 44 |
| 37 ExternalRegistryExtensionProvider::ExternalRegistryExtensionProvider() { | |
| 38 } | |
| 39 | |
| 40 ExternalRegistryExtensionProvider::~ExternalRegistryExtensionProvider() { | |
| 41 } | |
| 42 | |
| 43 void ExternalRegistryExtensionProvider::VisitRegisteredExtension( | |
| 44 Visitor* visitor) const { | |
| 45 base::win::RegistryKeyIterator iterator( | 45 base::win::RegistryKeyIterator iterator( |
| 46 kRegRoot, ASCIIToWide(kRegistryExtensions).c_str()); | 46 kRegRoot, ASCIIToWide(kRegistryExtensions).c_str()); |
| 47 while (iterator.Valid()) { | 47 while (iterator.Valid()) { |
| 48 base::win::RegKey key; | 48 base::win::RegKey key; |
| 49 std::wstring key_path = ASCIIToWide(kRegistryExtensions); | 49 std::wstring key_path = ASCIIToWide(kRegistryExtensions); |
| 50 key_path.append(L"\\"); | 50 key_path.append(L"\\"); |
| 51 key_path.append(iterator.Name()); | 51 key_path.append(iterator.Name()); |
| 52 if (key.Open(kRegRoot, key_path.c_str(), KEY_READ)) { | 52 if (key.Open(kRegRoot, key_path.c_str(), KEY_READ)) { |
| 53 std::wstring extension_path; | 53 std::wstring extension_path; |
| 54 if (key.ReadValue(kRegistryExtensionPath, &extension_path)) { | 54 if (key.ReadValue(kRegistryExtensionPath, &extension_path)) { |
| 55 std::wstring extension_version; | 55 std::wstring extension_version; |
| 56 if (key.ReadValue(kRegistryExtensionVersion, &extension_version)) { | 56 if (key.ReadValue(kRegistryExtensionVersion, &extension_version)) { |
| 57 std::string id = WideToASCII(iterator.Name()); | 57 std::string id = WideToASCII(iterator.Name()); |
| 58 StringToLowerASCII(&id); | 58 StringToLowerASCII(&id); |
| 59 | 59 |
| 60 scoped_ptr<Version> version; | 60 prefs->SetString( |
| 61 version.reset(Version::GetVersionFromString( | 61 id + "." + ExternalExtensionProviderImpl::kExternalVersion, |
| 62 WideToASCII(extension_version))); | 62 WideToASCII(extension_version)); |
| 63 if (!version.get()) { | 63 prefs->SetString( |
| 64 LOG(ERROR) << "Invalid version value " << extension_version | 64 id + "." + ExternalExtensionProviderImpl::kExternalCrx, |
| 65 << " for key " << key_path; | 65 extension_path); |
| 66 ++iterator; | |
| 67 continue; | |
| 68 } | |
| 69 | |
| 70 FilePath path = FilePath::FromWStringHack(extension_path); | |
| 71 visitor->OnExternalExtensionFileFound(id, version.get(), path, | |
| 72 Extension::EXTERNAL_REGISTRY); | |
| 73 } else { | 66 } else { |
| 74 // TODO(erikkay): find a way to get this into about:extensions | 67 // TODO(erikkay): find a way to get this into about:extensions |
| 75 LOG(ERROR) << "Missing value " << kRegistryExtensionVersion | 68 LOG(ERROR) << "Missing value " << kRegistryExtensionVersion |
| 76 << " for key " << key_path; | 69 << " for key " << key_path; |
| 77 } | 70 } |
| 78 } else { | 71 } else { |
| 79 // TODO(erikkay): find a way to get this into about:extensions | 72 // TODO(erikkay): find a way to get this into about:extensions |
| 80 LOG(ERROR) << "Missing value " << kRegistryExtensionPath | 73 LOG(ERROR) << "Missing value " << kRegistryExtensionPath |
| 81 << " for key " << key_path; | 74 << " for key " << key_path; |
| 82 } | 75 } |
| 83 } | 76 } |
| 84 ++iterator; | 77 ++iterator; |
| 85 } | 78 } |
| 79 |
| 80 prefs_.reset(prefs.release()); |
| 81 BrowserThread::PostTask( |
| 82 BrowserThread::UI, FROM_HERE, |
| 83 NewRunnableMethod( |
| 84 this, |
| 85 &ExternalRegistryExtensionLoader::LoadFinished)); |
| 86 } | 86 } |
| 87 | |
| 88 | |
| 89 bool ExternalRegistryExtensionProvider::HasExtension( | |
| 90 const std::string& id) const { | |
| 91 base::win::RegKey key; | |
| 92 return OpenKeyById(id, &key); | |
| 93 } | |
| 94 | |
| 95 bool ExternalRegistryExtensionProvider::GetExtensionDetails( | |
| 96 const std::string& id, | |
| 97 Extension::Location* location, | |
| 98 scoped_ptr<Version>* version) const { | |
| 99 base::win::RegKey key; | |
| 100 if (!OpenKeyById(id, &key)) | |
| 101 return false; | |
| 102 | |
| 103 std::wstring extension_version; | |
| 104 if (!key.ReadValue(kRegistryExtensionVersion, &extension_version)) | |
| 105 return false; | |
| 106 | |
| 107 if (version) { | |
| 108 version->reset(Version::GetVersionFromString( | |
| 109 WideToASCII(extension_version))); | |
| 110 } | |
| 111 | |
| 112 if (location) | |
| 113 *location = Extension::EXTERNAL_REGISTRY; | |
| 114 return true; | |
| 115 } | |
| OLD | NEW |