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

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

Issue 6293006: Allow relative paths to external extension files for some providers, error out for others. (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: Rebase for commit. Created 9 years, 11 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
OLDNEW
1 // Copyright (c) 2011 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_extension_provider_impl.h" 5 #include "chrome/browser/extensions/external_extension_provider_impl.h"
6 6
7 #include "app/app_paths.h" 7 #include "app/app_paths.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/linked_ptr.h" 10 #include "base/linked_ptr.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "base/version.h" 13 #include "base/version.h"
14 #include "chrome/browser/browser_thread.h" 14 #include "chrome/browser/browser_thread.h"
15 #include "chrome/browser/extensions/external_extension_provider_interface.h" 15 #include "chrome/browser/extensions/external_extension_provider_interface.h"
16 #include "chrome/browser/extensions/external_policy_extension_loader.h" 16 #include "chrome/browser/extensions/external_policy_extension_loader.h"
17 #include "chrome/browser/extensions/external_pref_extension_loader.h" 17 #include "chrome/browser/extensions/external_pref_extension_loader.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/chrome_paths.h"
19 20
20 #if defined(OS_WIN) 21 #if defined(OS_WIN)
21 #include "chrome/browser/extensions/external_registry_extension_loader_win.h" 22 #include "chrome/browser/extensions/external_registry_extension_loader_win.h"
22 #endif 23 #endif
23 24
24 // Constants for keeping track of extension preferences in a dictionary. 25 // Constants for keeping track of extension preferences in a dictionary.
25 const char ExternalExtensionProviderImpl::kLocation[] = "location"; 26 const char ExternalExtensionProviderImpl::kLocation[] = "location";
26 const char ExternalExtensionProviderImpl::kState[] = "state"; 27 const char ExternalExtensionProviderImpl::kState[] = "state";
27 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx"; 28 const char ExternalExtensionProviderImpl::kExternalCrx[] = "external_crx";
28 const char ExternalExtensionProviderImpl::kExternalVersion[] = 29 const char ExternalExtensionProviderImpl::kExternalVersion[] =
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 << "extensions from crx files."; 114 << "extensions from crx files.";
114 continue; 115 continue;
115 } 116 }
116 if (external_crx.find(FilePath::kParentDirectory) != 117 if (external_crx.find(FilePath::kParentDirectory) !=
117 base::StringPiece::npos) { 118 base::StringPiece::npos) {
118 LOG(WARNING) << "Path traversal not allowed in path: " 119 LOG(WARNING) << "Path traversal not allowed in path: "
119 << external_crx.c_str(); 120 << external_crx.c_str();
120 continue; 121 continue;
121 } 122 }
122 123
123 // If the path is relative, make it absolute. 124 // If the path is relative, and the provider has a base path,
125 // build the absolute path to the crx file.
124 FilePath path(external_crx); 126 FilePath path(external_crx);
125 if (!path.IsAbsolute()) { 127 if (!path.IsAbsolute()) {
126 // Try path as relative path from external extension dir. 128 FilePath base_path = loader_->GetBaseCrxFilePath();
127 FilePath base_path; 129 if (base_path.empty()) {
128 PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &base_path); 130 LOG(WARNING) << "File path " << external_crx.c_str()
131 << " is relative. An absolute path is required.";
132 continue;
133 }
129 path = base_path.Append(external_crx); 134 path = base_path.Append(external_crx);
130 } 135 }
131 136
132 scoped_ptr<Version> version; 137 scoped_ptr<Version> version;
133 version.reset(Version::GetVersionFromString(external_version)); 138 version.reset(Version::GetVersionFromString(external_version));
134 if (!version.get()) { 139 if (!version.get()) {
135 LOG(WARNING) << "Malformed extension dictionary for extension: " 140 LOG(WARNING) << "Malformed extension dictionary for extension: "
136 << extension_id.c_str() << ". Invalid version string \"" 141 << extension_id.c_str() << ". Invalid version string \""
137 << external_version << "\"."; 142 << external_version << "\".";
138 continue; 143 continue;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 220
216 // static 221 // static
217 void ExternalExtensionProviderImpl::CreateExternalProviders( 222 void ExternalExtensionProviderImpl::CreateExternalProviders(
218 VisitorInterface* service, 223 VisitorInterface* service,
219 Profile* profile, 224 Profile* profile,
220 ProviderCollection* provider_list) { 225 ProviderCollection* provider_list) {
221 provider_list->push_back( 226 provider_list->push_back(
222 linked_ptr<ExternalExtensionProviderInterface>( 227 linked_ptr<ExternalExtensionProviderInterface>(
223 new ExternalExtensionProviderImpl( 228 new ExternalExtensionProviderImpl(
224 service, 229 service,
225 new ExternalPrefExtensionLoader, 230 new ExternalPrefExtensionLoader(app::DIR_EXTERNAL_EXTENSIONS),
226 Extension::EXTERNAL_PREF, 231 Extension::EXTERNAL_PREF,
227 Extension::EXTERNAL_PREF_DOWNLOAD))); 232 Extension::EXTERNAL_PREF_DOWNLOAD)));
228 #if defined(OS_WIN) 233 #if defined(OS_WIN)
229 provider_list->push_back( 234 provider_list->push_back(
230 linked_ptr<ExternalExtensionProviderInterface>( 235 linked_ptr<ExternalExtensionProviderInterface>(
231 new ExternalExtensionProviderImpl( 236 new ExternalExtensionProviderImpl(
232 service, 237 service,
233 new ExternalRegistryExtensionLoader, 238 new ExternalRegistryExtensionLoader,
234 Extension::EXTERNAL_REGISTRY, 239 Extension::EXTERNAL_REGISTRY,
235 Extension::INVALID))); 240 Extension::INVALID)));
236 #endif 241 #endif
237 provider_list->push_back( 242 provider_list->push_back(
238 linked_ptr<ExternalExtensionProviderInterface>( 243 linked_ptr<ExternalExtensionProviderInterface>(
239 new ExternalExtensionProviderImpl( 244 new ExternalExtensionProviderImpl(
240 service, 245 service,
241 new ExternalPolicyExtensionLoader(profile), 246 new ExternalPolicyExtensionLoader(profile),
242 Extension::INVALID, 247 Extension::INVALID,
243 Extension::EXTERNAL_POLICY_DOWNLOAD))); 248 Extension::EXTERNAL_POLICY_DOWNLOAD)));
244 } 249 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/external_extension_loader.cc ('k') | chrome/browser/extensions/external_pref_extension_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698