OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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/user_script_master.h" | 5 #include "chrome/browser/extensions/user_script_master.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 else | 129 else |
130 master_->NewScriptsAvailable(memory); | 130 master_->NewScriptsAvailable(memory); |
131 | 131 |
132 // Drop our self-reference. | 132 // Drop our self-reference. |
133 // Balances StartScan(). | 133 // Balances StartScan(). |
134 Release(); | 134 Release(); |
135 } | 135 } |
136 | 136 |
137 static bool LoadScriptContent(UserScript::File* script_file) { | 137 static bool LoadScriptContent(UserScript::File* script_file) { |
138 std::string content; | 138 std::string content; |
139 FilePath path = script_file->resource().GetFilePath(); | 139 const FilePath& path = ExtensionResource::GetFilePath( |
| 140 script_file->extension_root(), script_file->relative_path()); |
140 if (path.empty() || !file_util::ReadFileToString(path, &content)) { | 141 if (path.empty() || !file_util::ReadFileToString(path, &content)) { |
141 LOG(WARNING) << "Failed to load user script file: " << path.value(); | 142 LOG(WARNING) << "Failed to load user script file: " << path.value(); |
142 return false; | 143 return false; |
143 } | 144 } |
144 | 145 |
145 script_file->set_content(content); | 146 script_file->set_content(content); |
146 LOG(INFO) << "Loaded user script file: " << path.value(); | 147 LOG(INFO) << "Loaded user script file: " << path.value(); |
147 return true; | 148 return true; |
148 } | 149 } |
149 | 150 |
(...skipping 11 matching lines...) Expand all Loading... |
161 file_util::FileEnumerator enumerator(script_dir, false, | 162 file_util::FileEnumerator enumerator(script_dir, false, |
162 file_util::FileEnumerator::FILES, | 163 file_util::FileEnumerator::FILES, |
163 FILE_PATH_LITERAL("*.user.js")); | 164 FILE_PATH_LITERAL("*.user.js")); |
164 for (FilePath file = enumerator.Next(); !file.value().empty(); | 165 for (FilePath file = enumerator.Next(); !file.value().empty(); |
165 file = enumerator.Next()) { | 166 file = enumerator.Next()) { |
166 result->push_back(UserScript()); | 167 result->push_back(UserScript()); |
167 UserScript& user_script = result->back(); | 168 UserScript& user_script = result->back(); |
168 // Push single js file in this UserScript. | 169 // Push single js file in this UserScript. |
169 GURL url(std::string(chrome::kUserScriptScheme) + ":/" + | 170 GURL url(std::string(chrome::kUserScriptScheme) + ":/" + |
170 net::FilePathToFileURL(file).ExtractFileName()); | 171 net::FilePathToFileURL(file).ExtractFileName()); |
171 ExtensionResource resource(script_dir, file.BaseName()); | 172 user_script.js_scripts().push_back(UserScript::File( |
172 user_script.js_scripts().push_back(UserScript::File(resource, url)); | 173 script_dir, file.BaseName(), url)); |
173 UserScript::File& script_file = user_script.js_scripts().back(); | 174 UserScript::File& script_file = user_script.js_scripts().back(); |
174 if (!LoadScriptContent(&script_file)) | 175 if (!LoadScriptContent(&script_file)) |
175 result->pop_back(); | 176 result->pop_back(); |
176 else | 177 else |
177 ParseMetadataHeader(script_file.GetContent(), &user_script); | 178 ParseMetadataHeader(script_file.GetContent(), &user_script); |
178 } | 179 } |
179 } | 180 } |
180 } | 181 } |
181 | 182 |
182 static void LoadLoneScripts(UserScriptList* lone_scripts) { | 183 static void LoadLoneScripts(UserScriptList* lone_scripts) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 DCHECK(false); | 378 DCHECK(false); |
378 } | 379 } |
379 } | 380 } |
380 | 381 |
381 void UserScriptMaster::StartScan() { | 382 void UserScriptMaster::StartScan() { |
382 if (!script_reloader_) | 383 if (!script_reloader_) |
383 script_reloader_ = new ScriptReloader(this); | 384 script_reloader_ = new ScriptReloader(this); |
384 | 385 |
385 script_reloader_->StartScan(worker_loop_, user_script_dir_, lone_scripts_); | 386 script_reloader_->StartScan(worker_loop_, user_script_dir_, lone_scripts_); |
386 } | 387 } |
OLD | NEW |