Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Unified Diff: extensions/renderer/script_injection.cc

Issue 2213603002: Prevent duplicate content script injection defined in manifest.json (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed patch 6 code review comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/renderer/script_injection.cc
diff --git a/extensions/renderer/script_injection.cc b/extensions/renderer/script_injection.cc
index 69cfc526c797f2cd7b9407495b34290765210d9e..8ff4422c6028d1f5b79b5e4c0f790c707788c779 100644
--- a/extensions/renderer/script_injection.cc
+++ b/extensions/renderer/script_injection.cc
@@ -213,19 +213,27 @@ ScriptInjection::InjectionResult ScriptInjection::Inject(
DCHECK(injection_host_);
DCHECK(scripts_run_info);
DCHECK(!complete_);
-
- bool should_inject_js = injector_->ShouldInjectJs(run_location_);
- bool should_inject_css = injector_->ShouldInjectCss(run_location_);
- DCHECK(should_inject_js || should_inject_css);
+ bool should_inject_js = injector_->ShouldInjectJs(
+ run_location_, scripts_run_info->injected_scripts);
+ bool should_inject_css = injector_->ShouldInjectCss(
+ run_location_, scripts_run_info->injected_scripts);
+
+ // This can happen if the extension specified a script to
+ // be run in multiple rules, and the script has already run.
+ // See crbug.com/631247.
+ if (!should_inject_js && !should_inject_css) {
+ return INJECTION_FINISHED;
+ }
if (should_inject_js)
- InjectJs();
+ InjectJs(scripts_run_info);
if (should_inject_css)
- InjectCss();
+ InjectCss(scripts_run_info);
complete_ = did_inject_js_ || !should_inject_js;
- injector_->GetRunInfo(scripts_run_info, run_location_);
+ injector_->GetRunInfo(scripts_run_info, run_location_, complete_,
Devlin 2016/08/29 20:48:14 why do we pass |complete_| instead of |should_inje
catmullings 2016/09/01 17:43:51 No longer applicable with GetRunInfo rolled into G
catmullings 2016/09/01 17:43:51 Done.
+ should_inject_css);
if (complete_) {
injector_->OnInjectionComplete(std::move(execution_result_), run_location_,
@@ -237,11 +245,12 @@ ScriptInjection::InjectionResult ScriptInjection::Inject(
return complete_ ? INJECTION_FINISHED : INJECTION_BLOCKED;
}
-void ScriptInjection::InjectJs() {
+void ScriptInjection::InjectJs(ScriptsRunInfo* scripts_run_info) {
DCHECK(!did_inject_js_);
blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame();
- std::vector<blink::WebScriptSource> sources =
- injector_->GetJsSources(run_location_);
+ std::vector<blink::WebScriptSource> sources = injector_->GetJsSources(
+ run_location_, scripts_run_info->injected_scripts);
+ DCHECK(!sources.empty());
bool in_main_world = injector_->ShouldExecuteInMainWorld();
int world_id = in_main_world
? DOMActivityLogger::kMainWorldId
@@ -311,9 +320,9 @@ void ScriptInjection::OnJsInjectionCompleted(
}
}
-void ScriptInjection::InjectCss() {
- std::vector<blink::WebString> css_sources =
- injector_->GetCssSources(run_location_);
+void ScriptInjection::InjectCss(ScriptsRunInfo* scripts_run_info) {
+ std::vector<blink::WebString> css_sources = injector_->GetCssSources(
+ run_location_, scripts_run_info->injected_scripts);
blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame();
for (const blink::WebString& css : css_sources)
web_frame->document().insertStyleSheet(css);

Powered by Google App Engine
This is Rietveld 408576698