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

Unified Diff: extensions/renderer/script_injection.cc

Issue 2134613002: Stop injection when injections are invalidated Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Expand scope of ScriptInjectionWatchers Created 4 years, 5 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 da93590c3908c00fb33421a2b3ff9f1077e04b06..b58638fcccfab08a3d34bd5bd9859163fa86ceaf 100644
--- a/extensions/renderer/script_injection.cc
+++ b/extensions/renderer/script_injection.cc
@@ -153,7 +153,7 @@ ScriptInjection::InjectionResult ScriptInjection::TryToInject(
if (!injection_host_) {
NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED);
- return INJECTION_FINISHED; // We're done.
+ return INJECTION_CANCELED; // We're done.
}
blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame();
@@ -172,6 +172,8 @@ ScriptInjection::InjectionResult ScriptInjection::TryToInject(
// notify it upon completion.
if (result == INJECTION_BLOCKED)
async_completion_callback_ = async_completion_callback;
+ else if (result == INJECTION_CANCELED)
+ NotifyWillNotInject(ScriptInjector::EXTENSION_REMOVED);
return result;
}
@@ -211,6 +213,7 @@ void ScriptInjection::NotifyWillNotInject(
ScriptInjection::InjectionResult ScriptInjection::Inject(
ScriptsRunInfo* scripts_run_info) {
DCHECK(injection_host_);
+ DCHECK(render_frame_);
DCHECK(scripts_run_info);
DCHECK(!complete_);
@@ -218,8 +221,15 @@ ScriptInjection::InjectionResult ScriptInjection::Inject(
bool should_inject_css = injector_->ShouldInjectCss(run_location_);
DCHECK(should_inject_js || should_inject_css);
- if (should_inject_js)
+ if (should_inject_js) {
InjectJs();
+ // InjectJs() may run arbitrary blocking JavaScript code for an unspecified
+ // amount of time and destroy the frame and/or injection host.
+ if (!injection_host_)
+ return INJECTION_CANCELED;
+ if (!render_frame_)
+ return INJECTION_FINISHED;
+ }
if (should_inject_css)
InjectCss();
@@ -274,7 +284,7 @@ void ScriptInjection::InjectJs() {
callback.release());
}
- if (injection_host_->id().type() == HostID::EXTENSIONS)
+ if (injection_host_ && injection_host_->id().type() == HostID::EXTENSIONS)
UMA_HISTOGRAM_TIMES("Extensions.InjectScriptTime", exec_timer.Elapsed());
}

Powered by Google App Engine
This is Rietveld 408576698