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

Unified Diff: extensions/renderer/user_script_injector.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/user_script_injector.cc
diff --git a/extensions/renderer/user_script_injector.cc b/extensions/renderer/user_script_injector.cc
index 1910548ba24b340d720cd7eb4ea16d8af38e6416..88b43ada616d5f1b8cb4eec499689185c92b9bdc 100644
--- a/extensions/renderer/user_script_injector.cc
+++ b/extensions/renderer/user_script_injector.cc
@@ -139,13 +139,15 @@ bool UserScriptInjector::ExpectsResults() const {
bool UserScriptInjector::ShouldInjectJs(
UserScript::RunLocation run_location) const {
- return script_ && script_->run_location() == run_location &&
+ CHECK(script_);
+ return script_->run_location() == run_location &&
!script_->js_scripts().empty();
}
bool UserScriptInjector::ShouldInjectCss(
UserScript::RunLocation run_location) const {
- return script_ && run_location == UserScript::DOCUMENT_START &&
+ CHECK(script_);
+ return run_location == UserScript::DOCUMENT_START &&
!script_->css_scripts().empty();
}
@@ -153,10 +155,7 @@ PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame(
const InjectionHost* injection_host,
blink::WebLocalFrame* web_frame,
int tab_id) const {
- // There is no harm in allowing the injection when the script is gone,
- // because there is nothing to inject.
- if (!script_)
- return PermissionsData::ACCESS_ALLOWED;
+ CHECK(script_);
if (script_->consumer_instance_type() ==
UserScript::ConsumerInstanceType::WEBVIEW) {
@@ -198,14 +197,12 @@ PermissionsData::AccessType UserScriptInjector::CanExecuteOnFrame(
std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
UserScript::RunLocation run_location) const {
- std::vector<blink::WebScriptSource> sources;
- if (!script_)
- return sources;
-
+ CHECK(script_);
DCHECK_EQ(script_->run_location(), run_location);
const UserScript::FileList& js_scripts = script_->js_scripts();
+ std::vector<blink::WebScriptSource> sources;
for (UserScript::FileList::const_iterator iter = js_scripts.begin();
iter != js_scripts.end();
++iter) {
@@ -232,11 +229,9 @@ std::vector<blink::WebScriptSource> UserScriptInjector::GetJsSources(
std::vector<std::string> UserScriptInjector::GetCssSources(
UserScript::RunLocation run_location) const {
DCHECK_EQ(UserScript::DOCUMENT_START, run_location);
+ CHECK(script_);
std::vector<std::string> sources;
- 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();
@@ -249,8 +244,7 @@ std::vector<std::string> UserScriptInjector::GetCssSources(
void UserScriptInjector::GetRunInfo(
ScriptsRunInfo* scripts_run_info,
UserScript::RunLocation run_location) const {
- if (!script_)
- return;
+ CHECK(script_);
if (ShouldInjectJs(run_location)) {
const UserScript::FileList& js_scripts = script_->js_scripts();

Powered by Google App Engine
This is Rietveld 408576698