Skip to content

Commit

Permalink
Bug 14202: Support relative paths when installing external extensions…
Browse files Browse the repository at this point in the history
… through prefs.

First we try the path as absolute path. If the file is not found, we try a relative path: [installation path]\extensions

This will make installing extensions easier from pre-installed prefs, since we can drop them into an extensions directory under the program directory.

BUG=14202
TEST=Specify relative path when installing extensions through prefs. Best to test this with an installer that supports deploying extensions (blocked on 14201)

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18554 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
finnur@chromium.org committed Jun 16, 2009
1 parent cff7926 commit 560541e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/app_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ bool PathProvider(int key, FilePath* result) {
#endif
create_dir = true;
break;
case app::DIR_EXTERNAL_EXTENSIONS:
if (!PathService::Get(base::DIR_MODULE, &cur))
return false;
cur = cur.Append(FILE_PATH_LITERAL("extensions"));
create_dir = true;
break;
// The following are only valid in the development environment, and
// will fail if executed from an installed executable (because the
// generated path won't exist).
Expand Down
13 changes: 7 additions & 6 deletions app/app_paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.

#ifndef APP_APP_PATHS_
#define APP_APP_PATHS_
#ifndef APP_APP_PATHS_H_
#define APP_APP_PATHS_H_

// This file declares path keys for the app module. These can be used with
// the PathService to access various special directories and files.
Expand All @@ -13,11 +13,12 @@ namespace app {
enum {
PATH_START = 2000,

DIR_THEMES, // directory where theme dll files are stored
DIR_LOCALES, // directory where locale resources are stored
DIR_THEMES, // Directory where theme dll files are stored.
DIR_LOCALES, // Directory where locale resources are stored.
DIR_EXTERNAL_EXTENSIONS, // Directory where installer places .crx files.

// Valid only in development environment; TODO(darin): move these
DIR_TEST_DATA, // directory where unit test data resides
DIR_TEST_DATA, // Directory where unit test data resides.

PATH_END
};
Expand All @@ -27,4 +28,4 @@ void RegisterPathProvider();

} // namespace app

#endif // #ifndef APP_APP_PATHS_
#endif // APP_APP_PATHS_H_
26 changes: 25 additions & 1 deletion chrome/browser/extensions/external_pref_extension_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "chrome/browser/extensions/external_pref_extension_provider.h"

#include "app/app_paths.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/version.h"

Expand Down Expand Up @@ -56,10 +59,31 @@ void ExternalPrefExtensionProvider::VisitRegisteredExtension(
continue;
}

if (external_crx.find(FilePath::kParentDirectory) != StringPiece::npos) {
LOG(WARNING) << "Path traversal not allowed in path: "
<< external_crx.c_str();
continue;
}

// See if it's an absolute path...
FilePath path(external_crx);
if (!path.IsAbsolute()) {
// Try path as relative path from external extension dir.
FilePath base_path;
PathService::Get(app::DIR_EXTERNAL_EXTENSIONS, &base_path);
path = base_path.Append(external_crx);
}

if (!file_util::PathExists(path)) {
LOG(WARNING) << "Cannot find extension: " << external_crx.c_str();
continue; // Path is neither absolute nor relative. Might be
// meta-physical, but we don't support those (yet).
}

scoped_ptr<Version> version;
version.reset(Version::GetVersionFromString(external_version));
visitor->OnExternalExtensionFound(
WideToASCII(extension_id), version.get(), FilePath(external_crx));
WideToASCII(extension_id), version.get(), path);
}
}

Expand Down

0 comments on commit 560541e

Please sign in to comment.