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

Unified Diff: chrome/browser/extensions/declarative_user_script_manager.cc

Issue 822453002: Introduce HostID and de-couple Extensions from "script injection System" [browser side] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 5 years, 11 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: chrome/browser/extensions/declarative_user_script_manager.cc
diff --git a/chrome/browser/extensions/declarative_user_script_manager.cc b/chrome/browser/extensions/declarative_user_script_manager.cc
index e740b5b4f4e25c94889afcea7c8d1f92cecc1eb6..2065502887f8661a2bfda30929f0e48cb1cecfec 100644
--- a/chrome/browser/extensions/declarative_user_script_manager.cc
+++ b/chrome/browser/extensions/declarative_user_script_manager.cc
@@ -5,11 +5,14 @@
#include "chrome/browser/extensions/declarative_user_script_manager.h"
#include "chrome/browser/extensions/declarative_user_script_master.h"
+#include "chrome/browser/profiles/profile.h"
+#include "extensions/browser/extension_registry.h"
namespace extensions {
DeclarativeUserScriptManager::DeclarativeUserScriptManager(Profile* profile)
- : profile_(profile) {
+ : profile_(profile), extension_registry_observer_(this) {
+ extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
}
DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
@@ -17,16 +20,34 @@ DeclarativeUserScriptManager::~DeclarativeUserScriptManager() {
DeclarativeUserScriptMaster*
DeclarativeUserScriptManager::GetDeclarativeUserScriptMasterByID(
- const std::string& id) {
- UserScriptMasterMap::iterator it = declarative_user_script_masters_.find(id);
+ const HostID& host_id) {
+ UserScriptMasterMap::iterator it =
+ declarative_user_script_masters_.find(host_id);
if (it != declarative_user_script_masters_.end())
return it->second.get();
+ return CreateDeclarativeUserScriptMaster(host_id);
+}
+
+DeclarativeUserScriptMaster*
+DeclarativeUserScriptManager::CreateDeclarativeUserScriptMaster(
+ const HostID& host_id) {
linked_ptr<DeclarativeUserScriptMaster> master(
- new DeclarativeUserScriptMaster(profile_, id));
- declarative_user_script_masters_[id] = master;
+ new DeclarativeUserScriptMaster(profile_, host_id));
+ declarative_user_script_masters_[host_id] = master;
return master.get();
}
-} // extensions
+void DeclarativeUserScriptManager::OnExtensionUnloaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension,
+ UnloadedExtensionInfo::Reason reason) {
+ for (const auto& val : declarative_user_script_masters_) {
+ DeclarativeUserScriptMaster* master = val.second.get();
+ if (master->host_id().id() == extension->id())
+ master->ClearScripts();
+ }
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698