summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/user_script_master.cc
diff options
context:
space:
mode:
authorcira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 22:49:10 +0000
committercira@chromium.org <cira@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 22:49:10 +0000
commitecabe6eed156a36238888bfd2fdb96ec4906f0a4 (patch)
tree9419d9a349fc940d45fa450b3a75169fdf48b39f /chrome/browser/extensions/user_script_master.cc
parent7050861ff094fd74d155264b6da3ca3795543870 (diff)
downloadchromium_src-ecabe6eed156a36238888bfd2fdb96ec4906f0a4.zip
chromium_src-ecabe6eed156a36238888bfd2fdb96ec4906f0a4.tar.gz
chromium_src-ecabe6eed156a36238888bfd2fdb96ec4906f0a4.tar.bz2
Loads local resources from current locale subtree if available, if not it falls back to extension subtree.
We look for ext_root/foo/bar.js under ext_root/_locales/fr/foo/bar.js if current locale is fr. If there is no fr specific resource we load ext_root/foo/bar.js instead. Lots of small refactoring to replace FilePath with ExtensionResource. BUG=12131 TEST=See unittest for sample tree. Review URL: http://codereview.chromium.org/256022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28333 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/user_script_master.cc')
-rw-r--r--chrome/browser/extensions/user_script_master.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index b4130c8..f58a9e6 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -136,20 +136,20 @@ void UserScriptMaster::ScriptReloader::NotifyMaster(
static bool LoadScriptContent(UserScript::File* script_file) {
std::string content;
- if (!file_util::ReadFileToString(script_file->path(), &content)) {
- LOG(WARNING) << "Failed to load user script file: "
- << script_file->path().value();
+ FilePath path = script_file->resource().GetFilePath();
+ if (path.empty() || !file_util::ReadFileToString(path, &content)) {
+ LOG(WARNING) << "Failed to load user script file: " << path.value();
return false;
}
script_file->set_content(content);
- LOG(INFO) << "Loaded user script file: " << script_file->path().value();
+ LOG(INFO) << "Loaded user script file: " << path.value();
return true;
}
void UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory(
const FilePath& script_dir, UserScriptList* result) {
- // Clear the list. We will populate it with the scrips found in script_dir.
+ // Clear the list. We will populate it with the scripts found in script_dir.
result->clear();
// Find all the scripts in |script_dir|.
@@ -168,7 +168,8 @@ void UserScriptMaster::ScriptReloader::LoadScriptsFromDirectory(
// Push single js file in this UserScript.
GURL url(std::string(chrome::kUserScriptScheme) + ":/" +
net::FilePathToFileURL(file).ExtractFileName());
- user_script.js_scripts().push_back(UserScript::File(file, url));
+ ExtensionResource resource(script_dir, file.BaseName());
+ user_script.js_scripts().push_back(UserScript::File(resource, url));
UserScript::File& script_file = user_script.js_scripts().back();
if (!LoadScriptContent(&script_file))
result->pop_back();