Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: chrome/browser/extensions/external_registry_extension_loader_win.cc

Issue 7650014: Check that registry external extension records point to a readable CRX file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Polish Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_loader_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/file_util.h"
9 #include "base/memory/scoped_handle.h"
8 #include "base/string_util.h" 10 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 12 #include "base/values.h"
11 #include "base/version.h" 13 #include "base/version.h"
12 #include "base/win/registry.h" 14 #include "base/win/registry.h"
13 #include "content/browser/browser_thread.h" 15 #include "content/browser/browser_thread.h"
14 #include "chrome/browser/extensions/external_extension_provider_impl.h" 16 #include "chrome/browser/extensions/external_extension_provider_impl.h"
15 17
16 namespace { 18 namespace {
17 19
18 // The Registry hive where to look for external extensions. 20 // The Registry hive where to look for external extensions.
19 const HKEY kRegRoot = HKEY_LOCAL_MACHINE; 21 const HKEY kRegRoot = HKEY_LOCAL_MACHINE;
20 22
21 // The Registry subkey that contains information about external extensions. 23 // The Registry subkey that contains information about external extensions.
22 const char kRegistryExtensions[] = "Software\\Google\\Chrome\\Extensions"; 24 const char kRegistryExtensions[] = "Software\\Google\\Chrome\\Extensions";
23 25
24 // Registry value of of that key that defines the path to the .crx file. 26 // Registry value of of that key that defines the path to the .crx file.
25 const wchar_t kRegistryExtensionPath[] = L"path"; 27 const wchar_t kRegistryExtensionPath[] = L"path";
26 28
27 // Registry value of that key that defines the current version of the .crx file. 29 // Registry value of that key that defines the current version of the .crx file.
28 const wchar_t kRegistryExtensionVersion[] = L"version"; 30 const wchar_t kRegistryExtensionVersion[] = L"version";
29 31
32 bool CanOpenFileForReading(const FilePath& path) {
33 ScopedStdioHandle file_handle(file_util::OpenFile(path, "rb"));
34 return file_handle.get() != NULL;
35 }
36
30 } // namespace 37 } // namespace
31 38
32 void ExternalRegistryExtensionLoader::StartLoading() { 39 void ExternalRegistryExtensionLoader::StartLoading() {
33 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 40 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
34 BrowserThread::PostTask( 41 BrowserThread::PostTask(
35 BrowserThread::FILE, FROM_HERE, 42 BrowserThread::FILE, FROM_HERE,
36 NewRunnableMethod( 43 NewRunnableMethod(
37 this, 44 this,
38 &ExternalRegistryExtensionLoader::LoadOnFileThread)); 45 &ExternalRegistryExtensionLoader::LoadOnFileThread));
39 } 46 }
40 47
41 void ExternalRegistryExtensionLoader::LoadOnFileThread() { 48 void ExternalRegistryExtensionLoader::LoadOnFileThread() {
42 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 49 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
43 scoped_ptr<DictionaryValue> prefs(new DictionaryValue); 50 scoped_ptr<DictionaryValue> prefs(new DictionaryValue);
44 51
45 base::win::RegistryKeyIterator iterator( 52 base::win::RegistryKeyIterator iterator(
46 kRegRoot, ASCIIToWide(kRegistryExtensions).c_str()); 53 kRegRoot, ASCIIToWide(kRegistryExtensions).c_str());
47 while (iterator.Valid()) { 54 for (; iterator.Valid(); ++iterator) {
48 base::win::RegKey key; 55 base::win::RegKey key;
49 std::wstring key_path = ASCIIToWide(kRegistryExtensions); 56 std::wstring key_path = ASCIIToWide(kRegistryExtensions);
50 key_path.append(L"\\"); 57 key_path.append(L"\\");
51 key_path.append(iterator.Name()); 58 key_path.append(iterator.Name());
52 if (key.Open(kRegRoot, key_path.c_str(), KEY_READ) == ERROR_SUCCESS) { 59 if (key.Open(kRegRoot, key_path.c_str(), KEY_READ) != ERROR_SUCCESS) {
53 std::wstring extension_path_str; 60 LOG(ERROR) << "Unable to read registry key at path: " << key_path << ".";
54 if (key.ReadValue(kRegistryExtensionPath, &extension_path_str) 61 continue;
55 == ERROR_SUCCESS) { 62 }
56 FilePath extension_path(extension_path_str);
57 if (!extension_path.IsAbsolute()) {
58 LOG(ERROR) << "Path " << extension_path_str
59 << " needs to be absolute in key "
60 << key_path;
61 ++iterator;
62 continue;
63 }
64 std::wstring extension_version;
65 if (key.ReadValue(kRegistryExtensionVersion, &extension_version)
66 == ERROR_SUCCESS) {
67 std::string id = WideToASCII(iterator.Name());
68 StringToLowerASCII(&id);
69 63
70 if (!Extension::IdIsValid(id)) { 64 std::wstring extension_path_str;
71 LOG(ERROR) << "Invalid id value " << id 65 if (key.ReadValue(kRegistryExtensionPath, &extension_path_str)
72 << " for key " << key_path << " ."; 66 != ERROR_SUCCESS) {
73 ++iterator; 67 // TODO(erikkay): find a way to get this into about:extensions
74 continue; 68 LOG(ERROR) << "Missing value " << kRegistryExtensionPath
75 } 69 << " for key " << key_path << ".";
70 continue;
71 }
76 72
77 scoped_ptr<Version> version; 73 FilePath extension_path(extension_path_str);
78 version.reset(Version::GetVersionFromString( 74 if (!extension_path.IsAbsolute()) {
79 WideToASCII(extension_version))); 75 LOG(ERROR) << "File " << extension_path_str
Finnur 2011/08/17 10:46:25 I wouldn't change this one, or at least have it sa
Sam Kerner (Chrome) 2011/08/17 14:43:09 Done.
80 if (!version.get()) { 76 << " needs to be absolute in key "
81 LOG(ERROR) << "Invalid version value " << extension_version 77 << key_path;
82 << " for key " << key_path << " ."; 78 continue;
83 ++iterator; 79 }
84 continue;
85 }
86 80
87 prefs->SetString( 81 if (!file_util::PathExists(extension_path)) {
88 id + "." + ExternalExtensionProviderImpl::kExternalVersion, 82 LOG(ERROR) << "File " << extension_path_str
89 WideToASCII(extension_version)); 83 << " for key " << key_path
90 prefs->SetString( 84 << " does not exist or is not readable.";
91 id + "." + ExternalExtensionProviderImpl::kExternalCrx, 85 continue;
92 extension_path_str);
93 } else {
94 // TODO(erikkay): find a way to get this into about:extensions
95 LOG(ERROR) << "Missing value " << kRegistryExtensionVersion
96 << " for key " << key_path << " .";
97 }
98 } else {
99 // TODO(erikkay): find a way to get this into about:extensions
100 LOG(ERROR) << "Missing value " << kRegistryExtensionPath
101 << " for key " << key_path << " .";
102 }
103 } 86 }
104 ++iterator; 87
88 if (!CanOpenFileForReading(extension_path)) {
89 LOG(ERROR) << "File " << extension_path_str
90 << " for key " << key_path << " can not be read. "
91 << "Check that users who should have the extension "
92 << "installed have permission to read it.";
93 continue;
94 }
95
96 std::wstring extension_version;
97 if (key.ReadValue(kRegistryExtensionVersion, &extension_version)
98 != ERROR_SUCCESS) {
99 // TODO(erikkay): find a way to get this into about:extensions
100 LOG(ERROR) << "Missing value " << kRegistryExtensionVersion
101 << " for key " << key_path << ".";
102 continue;
103 }
104
105 std::string id = WideToASCII(iterator.Name());
106 StringToLowerASCII(&id);
107 if (!Extension::IdIsValid(id)) {
108 LOG(ERROR) << "Invalid id value " << id
109 << " for key " << key_path << ".";
110 continue;
111 }
112
113 scoped_ptr<Version> version;
114 version.reset(Version::GetVersionFromString(
115 WideToASCII(extension_version)));
116 if (!version.get()) {
117 LOG(ERROR) << "Invalid version value " << extension_version
118 << " for key " << key_path << ".";
119 continue;
120 }
121
122 prefs->SetString(
123 id + "." + ExternalExtensionProviderImpl::kExternalVersion,
124 WideToASCII(extension_version));
125 prefs->SetString(
126 id + "." + ExternalExtensionProviderImpl::kExternalCrx,
127 extension_path_str);
105 } 128 }
106 129
107 prefs_.reset(prefs.release()); 130 prefs_.reset(prefs.release());
108 BrowserThread::PostTask( 131 BrowserThread::PostTask(
109 BrowserThread::UI, FROM_HERE, 132 BrowserThread::UI, FROM_HERE,
110 NewRunnableMethod( 133 NewRunnableMethod(
111 this, 134 this,
112 &ExternalRegistryExtensionLoader::LoadFinished)); 135 &ExternalRegistryExtensionLoader::LoadFinished));
113 } 136 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698