| Index: extensions/renderer/user_script_injector.cc
|
| diff --git a/extensions/renderer/user_script_injector.cc b/extensions/renderer/user_script_injector.cc
|
| index 21a59eac30fa4bd3e03c928090db5f13e6189ed9..9783859734f7b929757031f0c2be5772b93a83c8 100644
|
| --- a/extensions/renderer/user_script_injector.cc
|
| +++ b/extensions/renderer/user_script_injector.cc
|
| @@ -101,7 +101,7 @@ UserScriptInjector::~UserScriptInjector() {
|
|
|
| void UserScriptInjector::OnUserScriptsUpdated(
|
| const std::set<HostID>& changed_hosts,
|
| - const std::vector<std::unique_ptr<UserScript>>& scripts) {
|
| + const UserScriptList& scripts) {
|
| // If the host causing this injection changed, then this injection
|
| // will be removed, and there's no guarantee the backing script still exists.
|
| if (changed_hosts.count(host_id_) > 0) {
|
| @@ -202,13 +202,11 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
|
|
|
| DCHECK_EQ(script_->run_location(), run_location);
|
|
|
| - const UserScript::FileList& js_scripts = script_->js_scripts();
|
| -
|
| - for (UserScript::FileList::const_iterator iter = js_scripts.begin();
|
| - iter != js_scripts.end();
|
| - ++iter) {
|
| - std::string content = iter->GetContent().as_string();
|
| -
|
| + for (const std::unique_ptr<UserScript::File>& file : script_->js_scripts()) {
|
| + // TODO(lazyboy): Script contents are copied twice here! We could explore
|
| + // leveraging WebString-s refcounting, which might be hard. At the very
|
| + // least, we should make single copy for non-greasemonkey case.
|
| + std::string content = file->GetContent().as_string();
|
| // We add this dumb function wrapper for user scripts to emulate what
|
| // Greasemonkey does.
|
| if (script_->emulate_greasemonkey()) {
|
| @@ -216,7 +214,7 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
|
| content += kUserScriptTail;
|
| }
|
| sources.push_back(blink::WebScriptSource(
|
| - blink::WebString::fromUTF8(content), iter->url()));
|
| + blink::WebString::fromUTF8(content), file->url()));
|
| }
|
|
|
| // Emulate Greasemonkey API for scripts that were converted to extension
|
| @@ -235,11 +233,12 @@ std::vector<std::string> UserScriptInjector::GetCssSources(
|
| if (!script_)
|
| return sources;
|
|
|
| - const UserScript::FileList& css_scripts = script_->css_scripts();
|
| - for (UserScript::FileList::const_iterator iter = css_scripts.begin();
|
| - iter != css_scripts.end();
|
| - ++iter) {
|
| - sources.push_back(iter->GetContent().as_string());
|
| + for (const std::unique_ptr<UserScript::File>& file : script_->css_scripts()) {
|
| + // TODO(lazyboy): This is a StringPiece -> std::string copy, and then it
|
| + // gets copied into a WebString where GetCssSources() is used :( Getting
|
| + // rid of first copy should be trivial and we should also try to get rid of
|
| + // the second copy.
|
| + sources.push_back(file->GetContent().as_string());
|
| }
|
| return sources;
|
| }
|
| @@ -253,9 +252,7 @@ void UserScriptInjector::GetRunInfo(
|
| if (ShouldInjectJs(run_location)) {
|
| const UserScript::FileList& js_scripts = script_->js_scripts();
|
| scripts_run_info->num_js += js_scripts.size();
|
| - for (UserScript::FileList::const_iterator iter = js_scripts.begin();
|
| - iter != js_scripts.end();
|
| - ++iter) {
|
| + for (const std::unique_ptr<UserScript::File>& iter : js_scripts) {
|
| scripts_run_info->executing_scripts[host_id_.id()].insert(
|
| iter->url().path());
|
| }
|
|
|