Stop sending events and messages to content script contexts after their

extension has been unloaded.

BUG=168263


Review URL: https://chromiumcodereview.appspot.com/11882035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177070 0039d316-1c4b-4281-b951-d872f2087c98
parent 0bdb88a8
......@@ -385,10 +385,6 @@ void UserScriptMaster::Observe(int type,
}
user_scripts_ = new_user_scripts;
should_start_load = true;
// TODO(aa): Do we want to do something smarter for the scripts that have
// already been injected?
break;
}
case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
......
......@@ -80,8 +80,7 @@ void ChromeV8ContextSet::Remove(ChromeV8Context* context) {
}
}
ChromeV8ContextSet::ContextSet ChromeV8ContextSet::GetAll()
const {
ChromeV8ContextSet::ContextSet ChromeV8ContextSet::GetAll() const {
return contexts_;
}
......@@ -151,4 +150,19 @@ void ChromeV8ContextSet::DispatchChromeHiddenMethod(
}
}
void ChromeV8ContextSet::OnExtensionUnloaded(const std::string& extension_id) {
ContextSet contexts = GetAll();
// Clean up contexts belonging to the unloaded extension. This is done so
// that content scripts (which remain injected into the page) don't continue
// receiving events and sending messages.
for (ContextSet::iterator it = contexts.begin(); it != contexts.end();
++it) {
if ((*it)->extension() && (*it)->extension()->id() == extension_id) {
(*it)->DispatchOnUnloadEvent();
Remove(*it);
}
}
}
} // namespace extensions
......@@ -69,6 +69,9 @@ class ChromeV8ContextSet {
content::RenderView* render_view,
const GURL& event_url) const;
// Cleans up contexts belonging to an unloaded extension.
void OnExtensionUnloaded(const std::string& extension_id);
private:
ContextSet contexts_;
......
......@@ -504,6 +504,8 @@ void Dispatcher::OnUnloaded(const std::string& id) {
// changed origin whitelist.
user_script_slave_->RemoveIsolatedWorld(id);
v8_context_set_.OnExtensionUnloaded(id);
// We don't do anything with existing platform-app stylesheets. They will
// stay resident, but the URL pattern corresponding to the unloaded
// extension's URL just won't match anything anymore.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment