Chromium Code Reviews| Index: extensions/renderer/user_script_injector.cc |
| diff --git a/extensions/renderer/user_script_injector.cc b/extensions/renderer/user_script_injector.cc |
| index 1910548ba24b340d720cd7eb4ea16d8af38e6416..ed30ee5b47e7a4e64e28178911247f7b8571ae8f 100644 |
| --- a/extensions/renderer/user_script_injector.cc |
| +++ b/extensions/renderer/user_script_injector.cc |
| @@ -197,7 +197,8 @@ PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame( |
| } |
| std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
| - UserScript::RunLocation run_location) const { |
| + UserScript::RunLocation run_location, |
| + ScriptsRunInfo* scripts_run_info) const { |
| std::vector<blink::WebScriptSource> sources; |
| if (!script_) |
| return sources; |
| @@ -209,6 +210,11 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
| for (UserScript::FileList::const_iterator iter = js_scripts.begin(); |
| iter != js_scripts.end(); |
| ++iter) { |
| + const GURL& script_url = iter->url(); |
| + // Check if the script is already injected. |
| + if (scripts_run_info->injected_scripts.cout() != 0) |
|
Devlin
2016/07/12 23:32:36
cout? ;) Don't forget to recompile (and maybe re-
catmullings
2016/07/13 17:25:34
Done.
catmullings
2016/07/13 17:25:34
wow, thanks for the catch!
Properly updated this
|
| + continue; |
| + |
| std::string content = iter->GetContent().as_string(); |
| // We add this dumb function wrapper for user scripts to emulate what |
| @@ -218,7 +224,9 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
| content += kUserScriptTail; |
| } |
| sources.push_back(blink::WebScriptSource( |
| - blink::WebString::fromUTF8(content), iter->url())); |
| + blink::WebString::fromUTF8(content), script_url)); |
| + |
| + scripts_run_info->injected_scripts.insert(script_url); |
| } |
| // Emulate Greasemonkey API for scripts that were converted to extension |
| @@ -230,7 +238,8 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources( |
| } |
| std::vector<std::string> UserScriptInjector::GetCssSources( |
| - UserScript::RunLocation run_location) const { |
| + UserScript::RunLocation run_location, |
| + ScriptsRunInfo* scripts_run_info) const { |
| DCHECK_EQ(UserScript::DOCUMENT_START, run_location); |
| std::vector<std::string> sources; |
| @@ -238,10 +247,19 @@ std::vector<std::string> UserScriptInjector::GetCssSources( |
| 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()); |
| + GURL scriptUrl = iter->url(); |
|
Devlin
2016/07/12 23:32:36
variable naming style.
Devlin
2016/07/13 18:58:36
Looks like you missed this one? (Also please make
catmullings
2016/07/15 20:26:59
Done.
|
| + // Check if the script is already injected |
| + if (scripts_run_info->injected_scripts.find(scriptUrl) == |
| + scripts_run_info->injected_scripts.end()) { |
| + std::string content = iter->GetContent().as_string(); |
| + sources.push_back(iter->GetContent().as_string()); |
| + |
| + scripts_run_info->injected_scripts.insert(scriptUrl); |
| + } |
| } |
| return sources; |
| } |