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

Unified Diff: extensions/renderer/user_script_injector.cc

Issue 2277373002: [Extensions] Make UserScriptInjector's script update stricter (Closed)
Patch Set: comment 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
« no previous file with comments | « no previous file | extensions/renderer/user_script_set.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/user_script_injector.cc
diff --git a/extensions/renderer/user_script_injector.cc b/extensions/renderer/user_script_injector.cc
index da0c760e54425c7c329438150ed892501b18c6d5..8ae1c164cb64e2e8b8f3d268065b2871dd103e72 100644
--- a/extensions/renderer/user_script_injector.cc
+++ b/extensions/renderer/user_script_injector.cc
@@ -104,21 +104,22 @@ UserScriptInjector::~UserScriptInjector() {
void UserScriptInjector::OnUserScriptsUpdated(
const std::set<HostID>& changed_hosts,
const UserScriptList& scripts) {
+ // When user scripts are updated, all the old script pointers are invalidated.
+ script_ = nullptr;
// 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) {
- script_ = nullptr;
+ if (changed_hosts.count(host_id_) > 0)
return;
- }
for (const std::unique_ptr<UserScript>& script : scripts) {
- // We need to compare to |script_id_| (and not to script_->id()) because the
- // old |script_| may be deleted by now.
if (script->id() == script_id_) {
script_ = script.get();
break;
}
}
+ // If |host_id_| wasn't in |changed_hosts|, then the script for this injection
+ // should be guaranteed to exist.
+ DCHECK(script_);
}
UserScript::InjectionType UserScriptInjector::script_type() const {
« no previous file with comments | « no previous file | extensions/renderer/user_script_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698