diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 02:39:16 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-18 02:39:16 +0000 |
commit | 99efb7b19b5ecb8e7f8f3b646f191fda8a756841 (patch) | |
tree | 3d569055ca0cfa7a1af56e3226c89927117006b8 /chrome/common/extensions/extension.cc | |
parent | 4bd50cba12dc8311d3913569c3d43aa64f7312d0 (diff) | |
download | chromium_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/common/extensions/extension.cc')
-rw-r--r-- | chrome/common/extensions/extension.cc | 51 |
1 files changed, 25 insertions, 26 deletions
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 |