diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 22:21:30 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 22:21:30 +0000 |
commit | 3540c591c0fc870a976edd6bbf5c01c530b67d90 (patch) | |
tree | cb91a5ad06959e36d488230f27a1f94e146f68b4 /chrome/browser/extensions/user_script_master.cc | |
parent | b5b0687ff4386ba964ea6c7b5dd1f3e541b7708b (diff) | |
download | chromium_src-3540c591c0fc870a976edd6bbf5c01c530b67d90.zip chromium_src-3540c591c0fc870a976edd6bbf5c01c530b67d90.tar.gz chromium_src-3540c591c0fc870a976edd6bbf5c01c530b67d90.tar.bz2 |
Hook up more of extension uninstall.
Also removed all external dependencies from ExtensionsService.
It now only sends out notifications, which other services
consume. This should allow us to unit test the
ExtensionsService frontend, but I haven't added that yet.
Review URL: http://codereview.chromium.org/113493
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16547 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/user_script_master.cc')
-rw-r--r-- | chrome/browser/extensions/user_script_master.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc index 8b5e4d9..e1ed5db 100644 --- a/chrome/browser/extensions/user_script_master.cc +++ b/chrome/browser/extensions/user_script_master.cc @@ -14,6 +14,8 @@ #include "base/string_util.h" #include "base/thread.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/extensions/extension.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/common/notification_service.h" #include "chrome/common/url_constants.h" #include "net/base/net_util.h" @@ -257,6 +259,11 @@ UserScriptMaster::UserScriptMaster(MessageLoop* worker_loop, pending_scan_(false) { if (!user_script_dir_.value().empty()) AddWatchedPath(script_dir); + + registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, + NotificationService::AllSources()); } UserScriptMaster::~UserScriptMaster() { @@ -313,6 +320,55 @@ void UserScriptMaster::OnDirectoryChanged(const FilePath& path) { StartScan(); } +void UserScriptMaster::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::EXTENSIONS_LOADED: { + // TODO(aa): Fix race here. A page could need a content script on startup, + // before the extension has loaded. We need to freeze the renderer in + // that case. + // See: http://code.google.com/p/chromium/issues/detail?id=11547. + + // Add any content scripts inside the extension. + ExtensionList* extensions = Details<ExtensionList>(details).ptr(); + for (ExtensionList::iterator extension_iterator = extensions->begin(); + extension_iterator != extensions->end(); ++extension_iterator) { + Extension* extension = *extension_iterator; + const UserScriptList& scripts = extension->content_scripts(); + for (UserScriptList::const_iterator iter = scripts.begin(); + iter != scripts.end(); ++iter) { + lone_scripts_.push_back(*iter); + } + } + StartScan(); + break; + } + + case NotificationType::EXTENSION_UNLOADED: { + // Remove any content scripts. + Extension* extension = Details<Extension>(details).ptr(); + UserScriptList new_lone_scripts; + for (UserScriptList::iterator iter = lone_scripts_.begin(); + iter != lone_scripts_.end(); ++iter) { + if (iter->extension_id() != extension->id()) { + new_lone_scripts.push_back(*iter); + } + } + lone_scripts_ = new_lone_scripts; + StartScan(); + + // TODO(aa): Do we want to do something smarter for the scripts that have + // already been injected? + + break; + } + + default: + DCHECK(false); + } +} + void UserScriptMaster::StartScan() { if (!script_reloader_) script_reloader_ = new ScriptReloader(this); |