Commit b967a1b2 authored by skerner@google.com's avatar skerner@google.com

Check that registry external extension records point to a readable CRX file.

Some refactoring to make all error paths consistent.

BUG=81687
TEST=Create registry values for every error case, watch that I can hit them in the debugger, and a key without any errors leads to an install.

Review URL: http://codereview.chromium.org/7650014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97134 0039d316-1c4b-4281-b951-d872f2087c98
parent 7b5ce7d6
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/extensions/external_registry_extension_loader_win.h" #include "chrome/browser/extensions/external_registry_extension_loader_win.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/scoped_handle.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
...@@ -27,6 +29,11 @@ const wchar_t kRegistryExtensionPath[] = L"path"; ...@@ -27,6 +29,11 @@ const wchar_t kRegistryExtensionPath[] = L"path";
// Registry value of that key that defines the current version of the .crx file. // Registry value of that key that defines the current version of the .crx file.
const wchar_t kRegistryExtensionVersion[] = L"version"; const wchar_t kRegistryExtensionVersion[] = L"version";
bool CanOpenFileForReading(const FilePath& path) {
ScopedStdioHandle file_handle(file_util::OpenFile(path, "rb"));
return file_handle.get() != NULL;
}
} // namespace } // namespace
void ExternalRegistryExtensionLoader::StartLoading() { void ExternalRegistryExtensionLoader::StartLoading() {
...@@ -44,64 +51,80 @@ void ExternalRegistryExtensionLoader::LoadOnFileThread() { ...@@ -44,64 +51,80 @@ void ExternalRegistryExtensionLoader::LoadOnFileThread() {
base::win::RegistryKeyIterator iterator( base::win::RegistryKeyIterator iterator(
kRegRoot, ASCIIToWide(kRegistryExtensions).c_str()); kRegRoot, ASCIIToWide(kRegistryExtensions).c_str());
while (iterator.Valid()) { for (; iterator.Valid(); ++iterator) {
base::win::RegKey key; base::win::RegKey key;
std::wstring key_path = ASCIIToWide(kRegistryExtensions); std::wstring key_path = ASCIIToWide(kRegistryExtensions);
key_path.append(L"\\"); key_path.append(L"\\");
key_path.append(iterator.Name()); key_path.append(iterator.Name());
if (key.Open(kRegRoot, key_path.c_str(), KEY_READ) == ERROR_SUCCESS) { if (key.Open(kRegRoot, key_path.c_str(), KEY_READ) != ERROR_SUCCESS) {
std::wstring extension_path_str; LOG(ERROR) << "Unable to read registry key at path: " << key_path << ".";
if (key.ReadValue(kRegistryExtensionPath, &extension_path_str) continue;
== ERROR_SUCCESS) {
FilePath extension_path(extension_path_str);
if (!extension_path.IsAbsolute()) {
LOG(ERROR) << "Path " << extension_path_str
<< " needs to be absolute in key "
<< key_path;
++iterator;
continue;
}
std::wstring extension_version;
if (key.ReadValue(kRegistryExtensionVersion, &extension_version)
== ERROR_SUCCESS) {
std::string id = WideToASCII(iterator.Name());
StringToLowerASCII(&id);
if (!Extension::IdIsValid(id)) {
LOG(ERROR) << "Invalid id value " << id
<< " for key " << key_path << " .";
++iterator;
continue;
}
scoped_ptr<Version> version;
version.reset(Version::GetVersionFromString(
WideToASCII(extension_version)));
if (!version.get()) {
LOG(ERROR) << "Invalid version value " << extension_version
<< " for key " << key_path << " .";
++iterator;
continue;
}
prefs->SetString(
id + "." + ExternalExtensionProviderImpl::kExternalVersion,
WideToASCII(extension_version));
prefs->SetString(
id + "." + ExternalExtensionProviderImpl::kExternalCrx,
extension_path_str);
} else {
// TODO(erikkay): find a way to get this into about:extensions
LOG(ERROR) << "Missing value " << kRegistryExtensionVersion
<< " for key " << key_path << " .";
}
} else {
// TODO(erikkay): find a way to get this into about:extensions
LOG(ERROR) << "Missing value " << kRegistryExtensionPath
<< " for key " << key_path << " .";
}
} }
++iterator;
std::wstring extension_path_str;
if (key.ReadValue(kRegistryExtensionPath, &extension_path_str)
!= ERROR_SUCCESS) {
// TODO(erikkay): find a way to get this into about:extensions
LOG(ERROR) << "Missing value " << kRegistryExtensionPath
<< " for key " << key_path << ".";
continue;
}
FilePath extension_path(extension_path_str);
if (!extension_path.IsAbsolute()) {
LOG(ERROR) << "File path " << extension_path_str
<< " needs to be absolute in key "
<< key_path;
continue;
}
if (!file_util::PathExists(extension_path)) {
LOG(ERROR) << "File " << extension_path_str
<< " for key " << key_path
<< " does not exist or is not readable.";
continue;
}
if (!CanOpenFileForReading(extension_path)) {
LOG(ERROR) << "File " << extension_path_str
<< " for key " << key_path << " can not be read. "
<< "Check that users who should have the extension "
<< "installed have permission to read it.";
continue;
}
std::wstring extension_version;
if (key.ReadValue(kRegistryExtensionVersion, &extension_version)
!= ERROR_SUCCESS) {
// TODO(erikkay): find a way to get this into about:extensions
LOG(ERROR) << "Missing value " << kRegistryExtensionVersion
<< " for key " << key_path << ".";
continue;
}
std::string id = WideToASCII(iterator.Name());
StringToLowerASCII(&id);
if (!Extension::IdIsValid(id)) {
LOG(ERROR) << "Invalid id value " << id
<< " for key " << key_path << ".";
continue;
}
scoped_ptr<Version> version;
version.reset(Version::GetVersionFromString(
WideToASCII(extension_version)));
if (!version.get()) {
LOG(ERROR) << "Invalid version value " << extension_version
<< " for key " << key_path << ".";
continue;
}
prefs->SetString(
id + "." + ExternalExtensionProviderImpl::kExternalVersion,
WideToASCII(extension_version));
prefs->SetString(
id + "." + ExternalExtensionProviderImpl::kExternalCrx,
extension_path_str);
} }
prefs_.reset(prefs.release()); prefs_.reset(prefs.release());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment