summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 02:39:16 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-18 02:39:16 +0000
commit99efb7b19b5ecb8e7f8f3b646f191fda8a756841 (patch)
tree3d569055ca0cfa7a1af56e3226c89927117006b8 /chrome
parent4bd50cba12dc8311d3913569c3d43aa64f7312d0 (diff)
downloadchromium_src-99efb7b19b5ecb8e7f8f3b646f191fda8a756841.zip
chromium_src-99efb7b19b5ecb8e7f8f3b646f191fda8a756841.tar.gz
chromium_src-99efb7b19b5ecb8e7f8f3b646f191fda8a756841.tar.bz2
Extensions: file handling clean up.
- remove various invalid uses of ASCII functions - properly escape resource requests - clean up file path handling Some work remains to be done on the last bullet point but this is enough to fix the bug. BUG=30509 TEST=see bug Review URL: http://codereview.chromium.org/501046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/convert_user_script.cc2
-rw-r--r--chrome/browser/extensions/convert_user_script_unittest.cc4
-rw-r--r--chrome/browser/extensions/extension_file_util.cc49
-rw-r--r--chrome/browser/extensions/extension_file_util.h3
-rw-r--r--chrome/browser/extensions/extension_file_util_unittest.cc4
-rw-r--r--chrome/browser/extensions/extension_protocols.cc10
-rw-r--r--chrome/browser/extensions/extension_ui_unittest.cc2
-rw-r--r--chrome/browser/extensions/extensions_service.cc4
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc2
-rw-r--r--chrome/browser/extensions/extensions_ui.cc7
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker.cc4
-rw-r--r--chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc7
-rw-r--r--chrome/common/extensions/extension.cc51
-rw-r--r--chrome/common/extensions/extension.h21
-rw-r--r--chrome/common/extensions/extension_l10n_util.cc4
-rw-r--r--chrome/common/extensions/extension_l10n_util_unittest.cc20
-rw-r--r--chrome/common/extensions/extension_resource.cc1
-rw-r--r--chrome/common/extensions/extension_resource_unittest.cc2
-rw-r--r--chrome/common/extensions/extension_unittest.cc2
-rw-r--r--chrome/common/extensions/extension_unpacker.cc6
20 files changed, 109 insertions, 96 deletions
diff --git a/chrome/browser/extensions/convert_user_script.cc b/chrome/browser/extensions/convert_user_script.cc
index 814d17f..404f2af 100644
--- a/chrome/browser/extensions/convert_user_script.cc
+++ b/chrome/browser/extensions/convert_user_script.cc
@@ -112,7 +112,7 @@ Extension* ConvertUserScriptToExtension(const FilePath& user_script_path,
root->Set(keys::kContentScripts, content_scripts);
- FilePath manifest_path = temp_dir.path().AppendASCII(
+ FilePath manifest_path = temp_dir.path().Append(
Extension::kManifestFilename);
JSONFileValueSerializer serializer(manifest_path);
if (!serializer.Serialize(*root)) {
diff --git a/chrome/browser/extensions/convert_user_script_unittest.cc b/chrome/browser/extensions/convert_user_script_unittest.cc
index b7aea54..2c9ddab 100644
--- a/chrome/browser/extensions/convert_user_script_unittest.cc
+++ b/chrome/browser/extensions/convert_user_script_unittest.cc
@@ -48,7 +48,7 @@ TEST(ExtensionFromUserScript, Basic) {
EXPECT_TRUE(file_util::PathExists(
extension->path().Append(script.js_scripts()[0].relative_path())));
EXPECT_TRUE(file_util::PathExists(
- extension->path().AppendASCII(Extension::kManifestFilename)));
+ extension->path().Append(Extension::kManifestFilename)));
}
TEST(ExtensionFromUserScript, NoMetdata) {
@@ -84,5 +84,5 @@ TEST(ExtensionFromUserScript, NoMetdata) {
EXPECT_TRUE(file_util::PathExists(
extension->path().Append(script.js_scripts()[0].relative_path())));
EXPECT_TRUE(file_util::PathExists(
- extension->path().AppendASCII(Extension::kManifestFilename)));
+ extension->path().Append(Extension::kManifestFilename)));
}
diff --git a/chrome/browser/extensions/extension_file_util.cc b/chrome/browser/extensions/extension_file_util.cc
index 6e84e81..a9db4b3 100644
--- a/chrome/browser/extensions/extension_file_util.cc
+++ b/chrome/browser/extensions/extension_file_util.cc
@@ -17,6 +17,7 @@
#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/json_value_serializer.h"
+#include "net/base/escape.h"
#include "net/base/file_stream.h"
namespace errors = extension_manifest_errors;
@@ -84,7 +85,7 @@ bool SanityCheckExtension(const FilePath& dir) {
// Verify that the directory actually exists.
// TODO(erikkay): A further step would be to verify that the extension
// has actually loaded successfully.
- FilePath manifest_file(dir.AppendASCII(Extension::kManifestFilename));
+ FilePath manifest_file(dir.Append(Extension::kManifestFilename));
return file_util::PathExists(dir) && file_util::PathExists(manifest_file);
}
@@ -108,7 +109,7 @@ Extension* LoadExtension(const FilePath& extension_path,
bool require_key,
std::string* error) {
FilePath manifest_path =
- extension_path.AppendASCII(Extension::kManifestFilename);
+ extension_path.Append(Extension::kManifestFilename);
if (!file_util::PathExists(manifest_path)) {
*error = extension_manifest_errors::kManifestUnreadable;
return NULL;
@@ -278,7 +279,8 @@ bool ValidateExtension(Extension* extension, std::string* error) {
// Validate background page location.
if (!extension->background_url().is_empty()) {
- const std::string page_path = extension->background_url().path();
+ FilePath page_path = ExtensionURLToRelativeFilePath(
+ extension->background_url());
const FilePath path = extension->GetResource(page_path).GetFilePath();
if (!file_util::PathExists(path)) {
*error = StringPrintf("Could not load background page '%s'.",
@@ -399,7 +401,7 @@ ExtensionMessageBundle* LoadExtensionMessageBundle(
std::string* error) {
error->clear();
// Load locale information if available.
- FilePath locale_path = extension_path.AppendASCII(Extension::kLocaleFolder);
+ FilePath locale_path = extension_path.Append(Extension::kLocaleFolder);
if (!file_util::PathExists(locale_path))
return NULL;
@@ -426,7 +428,7 @@ ExtensionMessageBundle* LoadExtensionMessageBundle(
static bool ValidateLocaleInfo(const Extension& extension, std::string* error) {
// default_locale and _locales have to be both present or both missing.
- const FilePath path = extension.path().AppendASCII(Extension::kLocaleFolder);
+ const FilePath path = extension.path().Append(Extension::kLocaleFolder);
bool path_exists = file_util::PathExists(path);
std::string default_locale = extension.default_locale();
@@ -464,7 +466,7 @@ static bool ValidateLocaleInfo(const Extension& extension, std::string* error) {
continue;
FilePath messages_path =
- locale_path.AppendASCII(Extension::kMessagesFilename);
+ locale_path.Append(Extension::kMessagesFilename);
if (!file_util::PathExists(messages_path)) {
*error = StringPrintf(
@@ -490,12 +492,12 @@ static bool ValidateLocaleInfo(const Extension& extension, std::string* error) {
bool CheckForIllegalFilenames(const FilePath& extension_path,
std::string* error) {
// Reserved underscore names.
- static const char* reserved_names[] = {
+ static const FilePath::CharType* reserved_names[] = {
Extension::kLocaleFolder,
- "__MACOSX"
+ FILE_PATH_LITERAL("__MACOSX"),
};
- static std::set<std::string> reserved_underscore_names(
- reserved_names, reserved_names + arraysize(reserved_names));
+ static std::set<FilePath::StringType> reserved_underscore_names(
+ reserved_names, reserved_names + arraysize(reserved_names));
// Enumerate all files and directories in the extension root.
// There is a problem when using pattern "_*" with FileEnumerator, so we have
@@ -507,14 +509,13 @@ bool CheckForIllegalFilenames(const FilePath& extension_path,
file_util::FileEnumerator::DIRECTORIES |
file_util::FileEnumerator::FILES));
- FilePath files;
- while (!(files = all_files.Next()).empty()) {
- std::string filename =
- WideToASCII(files.BaseName().ToWStringHack());
+ FilePath file;
+ while (!(file = all_files.Next()).empty()) {
+ FilePath::StringType filename = file.BaseName().value();
// Skip all that don't start with "_".
- if (filename.find_first_of("_") != 0) continue;
+ if (filename.find_first_of(FILE_PATH_LITERAL("_")) != 0) continue;
if (reserved_underscore_names.find(filename) ==
- reserved_underscore_names.end()) {
+ reserved_underscore_names.end()) {
*error = StringPrintf(
"Cannot load extension with file or directory name %s. "
"Filenames starting with \"_\" are reserved for use by the system.",
@@ -526,4 +527,20 @@ bool CheckForIllegalFilenames(const FilePath& extension_path,
return true;
}
+FilePath ExtensionURLToRelativeFilePath(const GURL& url) {
+ std::string url_path = url.path();
+ if (url_path.empty() || url_path[0] != '/')
+ return FilePath();
+
+ // Drop the leading slash and convert %-encoded UTF8 to regular UTF8.
+ std::string file_path = UnescapeURLComponent(url_path.substr(1),
+ UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
+
+#if defined(OS_POSIX)
+ return FilePath(file_path);
+#elif defined(OS_WIN)
+ return FilePath(UTF8ToWide(file_path));
+#endif
+}
+
} // namespace extension_file_util
diff --git a/chrome/browser/extensions/extension_file_util.h b/chrome/browser/extensions/extension_file_util.h
index e6c88ff..d8bb448 100644
--- a/chrome/browser/extensions/extension_file_util.h
+++ b/chrome/browser/extensions/extension_file_util.h
@@ -100,6 +100,9 @@ ExtensionMessageBundle* LoadExtensionMessageBundle(
bool CheckForIllegalFilenames(const FilePath& extension_path,
std::string* error);
+// Get a relative file path from a chrome-extension:// URL.
+FilePath ExtensionURLToRelativeFilePath(const GURL& url);
+
} // extension_file_util
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FILE_UTIL_H_
diff --git a/chrome/browser/extensions/extension_file_util_unittest.cc b/chrome/browser/extensions/extension_file_util_unittest.cc
index 5b6cd71..675914d 100644
--- a/chrome/browser/extensions/extension_file_util_unittest.cc
+++ b/chrome/browser/extensions/extension_file_util_unittest.cc
@@ -162,7 +162,7 @@ TEST(ExtensionFileUtil, CheckIllegalFilenamesOnlyReserved) {
ScopedTempDir temp;
ASSERT_TRUE(temp.CreateUniqueTempDir());
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(src_path));
std::string error;
@@ -174,7 +174,7 @@ TEST(ExtensionFileUtil, CheckIllegalFilenamesReservedAndIllegal) {
ScopedTempDir temp;
ASSERT_TRUE(temp.CreateUniqueTempDir());
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(src_path));
src_path = temp.path().AppendASCII("_some_dir");
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
index 3be8337..2141622 100644
--- a/chrome/browser/extensions/extension_protocols.cc
+++ b/chrome/browser/extensions/extension_protocols.cc
@@ -5,12 +5,12 @@
#include "chrome/browser/extensions/extension_protocols.h"
#include "base/string_util.h"
+#include "chrome/browser/extensions/extension_file_util.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_resource.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/url_util.h"
-#include "net/base/net_util.h"
#include "net/url_request/url_request_file_job.h"
// Factory registered with URLRequest to create URLRequestJobs for extension://
@@ -27,8 +27,8 @@ static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request,
return NULL;
}
- ExtensionResource resource =
- Extension::GetResource(directory_path, request->url().path());
+ ExtensionResource resource(directory_path,
+ extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
return new URLRequestFileJob(request, resource.GetFilePath());
}
@@ -43,8 +43,8 @@ static URLRequestJob* CreateUserScriptURLRequestJob(URLRequest* request,
// chrome-user-script:/user-script-name.user.js
FilePath directory_path = context->user_script_dir_path();
- ExtensionResource resource =
- Extension::GetResource(directory_path, request->url().path());
+ ExtensionResource resource(directory_path,
+ extension_file_util::ExtensionURLToRelativeFilePath(request->url()));
return new URLRequestFileJob(request, resource.GetFilePath());
}
diff --git a/chrome/browser/extensions/extension_ui_unittest.cc b/chrome/browser/extensions/extension_ui_unittest.cc
index 773ebe2..4bffb44 100644
--- a/chrome/browser/extensions/extension_ui_unittest.cc
+++ b/chrome/browser/extensions/extension_ui_unittest.cc
@@ -36,7 +36,7 @@ namespace {
Extension extension(path);
std::string error;
- FilePath manifest_path = extension_path.AppendASCII(
+ FilePath manifest_path = extension_path.Append(
Extension::kManifestFilename);
scoped_ptr<DictionaryValue> extension_data(DeserializeJSONTestData(
manifest_path, &error));
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 2e26261..86d86c5 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -811,7 +811,7 @@ void ExtensionsService::ReportExtensionLoadError(
Details<const std::string>(&error));
// TODO(port): note that this isn't guaranteed to work properly on Linux.
- std::string path_str = WideToASCII(extension_path.ToWStringHack());
+ std::string path_str = WideToUTF8(extension_path.ToWStringHack());
std::string message = StringPrintf("Could not load extension from '%s'. %s",
path_str.c_str(), error.c_str());
ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy);
@@ -929,7 +929,7 @@ void ExtensionsServiceBackend::LoadSingleExtension(
file_util::AbsolutePath(&extension_path);
LOG(INFO) << "Loading single extension from " <<
- WideToASCII(extension_path.BaseName().ToWStringHack());
+ extension_path.BaseName().value();
std::string error;
Extension* extension = extension_file_util::LoadExtension(
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 92ea8f6..95748b7 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -844,7 +844,7 @@ TEST_F(ExtensionsServiceTest, PackExtension) {
// Try packing with an invalid manifest.
std::string invalid_manifest_content = "I am not a manifest.";
ASSERT_TRUE(file_util::WriteFile(
- temp_dir2.path().AppendASCII(Extension::kManifestFilename),
+ temp_dir2.path().Append(Extension::kManifestFilename),
invalid_manifest_content.c_str(), invalid_manifest_content.size()));
creator.reset(new ExtensionCreator());
ASSERT_FALSE(creator->Run(temp_dir2.path(), crx_path, privkey_path,
diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc
index a18cb7a..7ddf152 100644
--- a/chrome/browser/extensions/extensions_ui.cc
+++ b/chrome/browser/extensions/extensions_ui.cc
@@ -440,13 +440,12 @@ void ExtensionsDOMHandler::HandleOptionsMessage(const Value* value) {
}
void ExtensionsDOMHandler::HandleLoadMessage(const Value* value) {
- std::string string_path;
+ FilePath::StringType string_path;
CHECK(value->IsType(Value::TYPE_LIST));
const ListValue* list = static_cast<const ListValue*>(value);
CHECK(list->GetSize() == 1) << list->GetSize();
CHECK(list->GetString(0, &string_path));
- FilePath file_path = FilePath::FromWStringHack(ASCIIToWide(string_path));
- extensions_service_->LoadExtension(file_path);
+ extensions_service_->LoadExtension(FilePath(string_path));
}
void ExtensionsDOMHandler::ShowAlert(const std::string& message) {
@@ -653,7 +652,7 @@ DictionaryValue* ExtensionsDOMHandler::CreateExtensionDetailValue(
// Determine the sort order: Extensions loaded through --load-extensions show
// up at the top. Disabled extensions show up at the bottom.
- if (extension->location() == Extension::LOAD)
+ if (extension->location() == Extension::LOAD)
extension_data->SetInteger(L"order", 1);
else
extension_data->SetInteger(L"order", 2);
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker.cc b/chrome/browser/extensions/sandboxed_extension_unpacker.cc
index cf83cef..9d004e3 100644
--- a/chrome/browser/extensions/sandboxed_extension_unpacker.cc
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker.cc
@@ -264,7 +264,7 @@ DictionaryValue* SandboxedExtensionUnpacker::RewriteManifestFile(
}
FilePath manifest_path =
- extension_root_.AppendASCII(Extension::kManifestFilename);
+ extension_root_.Append(Extension::kManifestFilename);
if (!file_util::WriteFile(manifest_path,
manifest_json.data(), manifest_json.size())) {
ReportFailure("Error saving manifest.json.");
@@ -346,7 +346,7 @@ bool SandboxedExtensionUnpacker::RewriteCatalogFiles(
}
FilePath relative_path = FilePath::FromWStringHack(*key_it);
- relative_path = relative_path.AppendASCII(Extension::kMessagesFilename);
+ relative_path = relative_path.Append(Extension::kMessagesFilename);
if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) {
ReportFailure("Invalid path for catalog.");
return false;
diff --git a/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc b/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
index f48da5d..3212080 100644
--- a/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
+++ b/chrome/browser/extensions/sandboxed_extension_unpacker_unittest.cc
@@ -128,7 +128,7 @@ TEST_F(SandboxedExtensionUnpackerTest, NoCatalogsSuccess) {
// Check that there is no _locales folder.
FilePath install_path =
- GetInstallPath().AppendASCII(Extension::kLocaleFolder);
+ GetInstallPath().Append(Extension::kLocaleFolder);
EXPECT_FALSE(file_util::PathExists(install_path));
OnUnpackSucceeded();
@@ -146,10 +146,9 @@ TEST_F(SandboxedExtensionUnpackerTest, WithCatalogsSuccess) {
// Check timestamp on _locales/en_US/messages.json.
FilePath messages_file;
- messages_file = GetInstallPath()
- .AppendASCII(Extension::kLocaleFolder)
+ messages_file = GetInstallPath().Append(Extension::kLocaleFolder)
.AppendASCII("en_US")
- .AppendASCII(Extension::kMessagesFilename);
+ .Append(Extension::kMessagesFilename);
file_util::FileInfo old_info;
EXPECT_TRUE(file_util::GetFileInfo(messages_file, &old_info));
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 4ed91b58..9097086 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -72,9 +72,12 @@ static bool IsAPIPermission(const std::string& str) {
} // namespace
-const char Extension::kManifestFilename[] = "manifest.json";
-const char Extension::kLocaleFolder[] = "_locales";
-const char Extension::kMessagesFilename[] = "messages.json";
+const FilePath::CharType Extension::kManifestFilename[] =
+ FILE_PATH_LITERAL("manifest.json");
+const FilePath::CharType Extension::kLocaleFolder[] =
+ FILE_PATH_LITERAL("_locales");
+const FilePath::CharType Extension::kMessagesFilename[] =
+ FILE_PATH_LITERAL("messages.json");
// A list of all the keys allowed by themes.
static const wchar_t* kValidThemeKeys[] = {
@@ -301,15 +304,14 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script,
for (size_t script_index = 0; script_index < js->GetSize();
++script_index) {
Value* value;
- std::wstring relative;
+ std::string relative;
if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) {
*error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidJs,
IntToString(definition_index), IntToString(script_index));
return false;
}
- // TODO(georged): Make GetResourceURL accept wstring too
- GURL url = GetResourceURL(WideToUTF8(relative));
- ExtensionResource resource = GetResource(WideToUTF8(relative));
+ GURL url = GetResourceURL(relative);
+ ExtensionResource resource = GetResource(relative);
result->js_scripts().push_back(UserScript::File(
resource.extension_root(), resource.relative_path(), url));
}
@@ -319,15 +321,14 @@ bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script,
for (size_t script_index = 0; script_index < css->GetSize();
++script_index) {
Value* value;
- std::wstring relative;
+ std::string relative;
if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) {
*error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidCss,
IntToString(definition_index), IntToString(script_index));
return false;
}
- // TODO(georged): Make GetResourceURL accept wstring too
- GURL url = GetResourceURL(WideToUTF8(relative));
- ExtensionResource resource = GetResource(WideToUTF8(relative));
+ GURL url = GetResourceURL(relative);
+ ExtensionResource resource = GetResource(relative);
result->css_scripts().push_back(UserScript::File(
resource.extension_root(), resource.relative_path(), url));
}
@@ -489,21 +490,6 @@ bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) {
return false;
}
-// static
-ExtensionResource Extension::GetResource(const FilePath& extension_path,
- const std::string& relative_path) {
- // IsAbsolutePath gets confused on Unix if relative path starts with /.
- // Lets remove leading / if there is one.
- size_t start_pos = relative_path.find_first_not_of("/");
- if (start_pos == std::string::npos)
- return ExtensionResource();
- std::string trimmed_path = relative_path.substr(start_pos);
-
- FilePath relative_resource_path;
- return ExtensionResource(extension_path,
- relative_resource_path.AppendASCII(trimmed_path));
-}
-
Extension::Extension(const FilePath& path)
: converted_from_user_script_(false), is_theme_(false),
background_page_ready_(false) {
@@ -525,6 +511,19 @@ Extension::Extension(const FilePath& path)
#endif
}
+ExtensionResource Extension::GetResource(const std::string& relative_path) {
+#if defined(OS_POSIX)
+ FilePath relative_file_path(relative_path);
+#elif defined(OS_WIN)
+ FilePath relative_file_path(UTF8ToWide(relative_path));
+#endif
+ return ExtensionResource(path(), relative_file_path);
+}
+
+ExtensionResource Extension::GetResource(const FilePath& relative_file_path) {
+ return ExtensionResource(path(), relative_file_path);
+}
+
// TODO(rafaelw): Move ParsePEMKeyBytes, ProducePEM & FormatPEMForOutput to a
// util class in base:
// http://code.google.com/p/chromium/issues/detail?id=13572
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 52e3363..9906aea 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -100,13 +100,13 @@ class Extension {
};
// The name of the manifest inside an extension.
- static const char kManifestFilename[];
+ static const FilePath::CharType kManifestFilename[];
// The name of locale folder inside an extension.
- static const char kLocaleFolder[];
+ static const FilePath::CharType kLocaleFolder[];
// The name of the messages file inside an extension.
- static const char kMessagesFilename[];
+ static const FilePath::CharType kMessagesFilename[];
#if defined(OS_WIN)
static const char* kExtensionRegistryPath;
@@ -144,15 +144,12 @@ class Extension {
return GetResourceURL(url(), relative_path);
}
- // Returns an extension resource object. The |extension_path| argument should
- // be the path() from an Extension object.
- // The |relative_path| can be untrusted user input.
- // NOTE: Static so that it can be used from multiple threads.
- static ExtensionResource GetResource(const FilePath& extension_path,
- const std::string& relative_path);
- ExtensionResource GetResource(const std::string& relative_path) {
- return GetResource(path(), relative_path);
- }
+ // Returns an extension resource object. |relative_path| should be UTF8
+ // encoded.
+ ExtensionResource GetResource(const std::string& relative_path);
+
+ // As above, but with |relative_path| following the file system's encoding.
+ ExtensionResource GetResource(const FilePath& relative_path);
// |input| is expected to be the text of an rsa public or private key. It
// tolerates the presence or absence of bracking header/footer like this:
diff --git a/chrome/common/extensions/extension_l10n_util.cc b/chrome/common/extensions/extension_l10n_util.cc
index f315d92..f3431d7 100644
--- a/chrome/common/extensions/extension_l10n_util.cc
+++ b/chrome/common/extensions/extension_l10n_util.cc
@@ -153,7 +153,7 @@ bool AddLocale(const std::set<std::string>& chrome_locales,
}
// Check if messages file is actually present (but don't check content).
if (file_util::PathExists(
- locale_folder.AppendASCII(Extension::kMessagesFilename))) {
+ locale_folder.Append(Extension::kMessagesFilename))) {
valid_locales->insert(locale_name);
} else {
*error = StringPrintf("Catalog file is missing for locale %s.",
@@ -249,7 +249,7 @@ static DictionaryValue* LoadMessageFile(const FilePath& locale_path,
std::string* error) {
std::string extension_locale = locale;
FilePath file = locale_path.AppendASCII(extension_locale)
- .AppendASCII(Extension::kMessagesFilename);
+ .Append(Extension::kMessagesFilename);
JSONFileValueSerializer messages_serializer(file);
Value *dictionary = messages_serializer.Deserialize(error);
if (!dictionary && error->empty()) {
diff --git a/chrome/common/extensions/extension_l10n_util_unittest.cc b/chrome/common/extensions/extension_l10n_util_unittest.cc
index 4da8b38..93b16d3 100644
--- a/chrome/common/extensions/extension_l10n_util_unittest.cc
+++ b/chrome/common/extensions/extension_l10n_util_unittest.cc
@@ -26,7 +26,7 @@ TEST(ExtensionL10nUtil, GetValidLocalesEmptyLocaleFolder) {
ScopedTempDir temp;
ASSERT_TRUE(temp.CreateUniqueTempDir());
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(src_path));
std::string error;
@@ -42,7 +42,7 @@ TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocaleNoMessagesFile) {
ScopedTempDir temp;
ASSERT_TRUE(temp.CreateUniqueTempDir());
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(src_path));
ASSERT_TRUE(file_util::CreateDirectory(src_path.AppendASCII("sr")));
@@ -63,7 +63,7 @@ TEST(ExtensionL10nUtil, GetValidLocalesWithValidLocalesAndMessagesFile) {
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")
- .AppendASCII(Extension::kLocaleFolder);
+ .Append(Extension::kLocaleFolder);
std::string error;
std::set<std::string> locales;
@@ -84,7 +84,7 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsValidFallback) {
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")
- .AppendASCII(Extension::kLocaleFolder);
+ .Append(Extension::kLocaleFolder);
std::string error;
std::set<std::string> locales;
@@ -105,7 +105,7 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsMissingFiles) {
ScopedTempDir temp;
ASSERT_TRUE(temp.CreateUniqueTempDir());
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(src_path));
std::set<std::string> valid_locales;
@@ -124,7 +124,7 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsBadJSONFormat) {
ScopedTempDir temp;
ASSERT_TRUE(temp.CreateUniqueTempDir());
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(src_path));
FilePath locale = src_path.AppendASCII("sr");
@@ -132,7 +132,7 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsBadJSONFormat) {
std::string data = "{ \"name\":";
ASSERT_TRUE(
- file_util::WriteFile(locale.AppendASCII(Extension::kMessagesFilename),
+ file_util::WriteFile(locale.Append(Extension::kMessagesFilename),
data.c_str(), data.length()));
std::set<std::string> valid_locales;
@@ -151,7 +151,7 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) {
ScopedTempDir temp;
ASSERT_TRUE(temp.CreateUniqueTempDir());
- FilePath src_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath src_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(src_path));
FilePath locale_1 = src_path.AppendASCII("en");
@@ -161,14 +161,14 @@ TEST(ExtensionL10nUtil, LoadMessageCatalogsDuplicateKeys) {
"{ \"name\": { \"message\": \"something\" }, "
"\"name\": { \"message\": \"something else\" } }";
ASSERT_TRUE(
- file_util::WriteFile(locale_1.AppendASCII(Extension::kMessagesFilename),
+ file_util::WriteFile(locale_1.Append(Extension::kMessagesFilename),
data.c_str(), data.length()));
FilePath locale_2 = src_path.AppendASCII("sr");
ASSERT_TRUE(file_util::CreateDirectory(locale_2));
ASSERT_TRUE(
- file_util::WriteFile(locale_2.AppendASCII(Extension::kMessagesFilename),
+ file_util::WriteFile(locale_2.Append(Extension::kMessagesFilename),
data.c_str(), data.length()));
std::set<std::string> valid_locales;
diff --git a/chrome/common/extensions/extension_resource.cc b/chrome/common/extensions/extension_resource.cc
index aeb6231..575b3a3 100644
--- a/chrome/common/extensions/extension_resource.cc
+++ b/chrome/common/extensions/extension_resource.cc
@@ -9,7 +9,6 @@
#include "base/string_util.h"
#include "chrome/common/extensions/extension_l10n_util.h"
#include "googleurl/src/gurl.h"
-#include "net/base/net_util.h"
ExtensionResource::ExtensionResource() {
}
diff --git a/chrome/common/extensions/extension_resource_unittest.cc b/chrome/common/extensions/extension_resource_unittest.cc
index 7493107..258227f 100644
--- a/chrome/common/extensions/extension_resource_unittest.cc
+++ b/chrome/common/extensions/extension_resource_unittest.cc
@@ -52,7 +52,7 @@ TEST(ExtensionResourceTest, CreateWithAllResourcesOnDisk) {
ASSERT_TRUE(file_util::WriteFile(root_resource, data.c_str(), data.length()));
// Create l10n resources (for current locale and its parents).
- FilePath l10n_path = temp.path().AppendASCII(Extension::kLocaleFolder);
+ FilePath l10n_path = temp.path().Append(Extension::kLocaleFolder);
ASSERT_TRUE(file_util::CreateDirectory(l10n_path));
std::vector<std::string> locales;
diff --git a/chrome/common/extensions/extension_unittest.cc b/chrome/common/extensions/extension_unittest.cc
index 894d5be..db992eb 100644
--- a/chrome/common/extensions/extension_unittest.cc
+++ b/chrome/common/extensions/extension_unittest.cc
@@ -42,7 +42,7 @@ TEST(ExtensionTest, DISABLED_InitFromValueInvalid) {
.AppendASCII("Extensions")
.AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
.AppendASCII("1.0.0.0")
- .AppendASCII(Extension::kManifestFilename);
+ .Append(Extension::kManifestFilename);
JSONFileValueSerializer serializer(extensions_path);
scoped_ptr<DictionaryValue> valid_value(
diff --git a/chrome/common/extensions/extension_unpacker.cc b/chrome/common/extensions/extension_unpacker.cc
index e5c7758..425105f 100644
--- a/chrome/common/extensions/extension_unpacker.cc
+++ b/chrome/common/extensions/extension_unpacker.cc
@@ -88,7 +88,7 @@ static bool PathContainsParentDirectory(const FilePath& path) {
DictionaryValue* ExtensionUnpacker::ReadManifest() {
FilePath manifest_path =
- temp_install_dir_.AppendASCII(Extension::kManifestFilename);
+ temp_install_dir_.Append(Extension::kManifestFilename);
if (!file_util::PathExists(manifest_path)) {
SetError(errors::kInvalidManifest);
return NULL;
@@ -113,7 +113,7 @@ DictionaryValue* ExtensionUnpacker::ReadManifest() {
bool ExtensionUnpacker::ReadAllMessageCatalogs(
const std::string& default_locale) {
FilePath locales_path =
- temp_install_dir_.AppendASCII(Extension::kLocaleFolder);
+ temp_install_dir_.Append(Extension::kLocaleFolder);
// Treat all folders under _locales as valid locales.
file_util::FileEnumerator locales(locales_path,
@@ -134,7 +134,7 @@ bool ExtensionUnpacker::ReadAllMessageCatalogs(
continue;
FilePath messages_path =
- locale_path.AppendASCII(Extension::kMessagesFilename);
+ locale_path.Append(Extension::kMessagesFilename);
if (!ReadMessageCatalog(messages_path))
return false;