diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-21 23:24:16 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-21 23:24:16 +0000 |
commit | a7ab1b782edde4b8558ccba857ea64cb1e8e8d1c (patch) | |
tree | be43e81cd80302d91ed9d0c9ddc4079f0e557b5a /chrome/browser/extensions/extension_event_router.h | |
parent | 3a8d2de3be5629f532f4b26a4ddb7c0961cb25d7 (diff) | |
download | chromium_src-a7ab1b782edde4b8558ccba857ea64cb1e8e8d1c.zip chromium_src-a7ab1b782edde4b8558ccba857ea64cb1e8e8d1c.tar.gz chromium_src-a7ab1b782edde4b8558ccba857ea64cb1e8e8d1c.tar.bz2 |
Part 2 of extension event refactor.
Extension events are no longer broadcast to an entire process. They are
filtered by extension. This allows me to move the cross-incognito check into
the browser, and remove a bunch of cruft associated with that.
BUG=58214
TEST=no functional change
Review URL: http://codereview.chromium.org/3775015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63448 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_event_router.h')
-rw-r--r-- | chrome/browser/extensions/extension_event_router.h | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/chrome/browser/extensions/extension_event_router.h b/chrome/browser/extensions/extension_event_router.h index 5fb29e4..5e1ca97 100644 --- a/chrome/browser/extensions/extension_event_router.h +++ b/chrome/browser/extensions/extension_event_router.h @@ -24,37 +24,52 @@ class ExtensionEventRouter : public NotificationObserver { explicit ExtensionEventRouter(Profile* profile); ~ExtensionEventRouter(); - // Returns the event name for an event that is extension-specific. - static std::string GetPerExtensionEventName(const std::string& event_name, - const std::string& extension_id); - - // Add or remove |render_process_id| as a listener for |event_name|. + // Add or remove the process/extension pair as a listener for |event_name|. + // Note that multiple extensions can share a process due to process + // collapsing. Also, a single extension can have 2 processes if it is a split + // mode extension. void AddEventListener(const std::string& event_name, - int render_process_id); + RenderProcessHost* process, + const std::string& extension_id); void RemoveEventListener(const std::string& event_name, - int render_process_id); + RenderProcessHost* process, + const std::string& extension_id); // Returns true if there is at least one listener for the given event. bool HasEventListener(const std::string& event_name); + // Returns true if the extension is listening to the given event. + bool ExtensionHasEventListener(const std::string& extension_id, + const std::string& event_name); + // Send an event to every registered extension renderer. If // |restrict_to_profile| is non-NULL, then the event will not be sent to other // profiles unless the extension has permission (e.g. incognito tab update -> // normal profile only works if extension is allowed incognito access). If // |event_url| is not empty, the event is only sent to extension with host // permissions for this url. - virtual void DispatchEventToRenderers( + void DispatchEventToRenderers( const std::string& event_name, const std::string& event_args, Profile* restrict_to_profile, const GURL& event_url); - // Same as above, except use the extension-specific naming scheme for the - // event. This is used by events that are per-extension. + // Same as above, except only send the event to the given extension. void DispatchEventToExtension( const std::string& extension_id, const std::string& event_name, const std::string& event_args, Profile* restrict_to_profile, const GURL& event_url); + protected: + // Shared by DispatchEvent*. If |extension_id| is empty, the event is + // broadcast. + virtual void DispatchEventImpl( + const std::string& extension_id, + const std::string& event_name, const std::string& event_args, + Profile* restrict_to_profile, const GURL& event_url); + private: + // An extension listening to an event. + struct EventListener; + virtual void Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details); @@ -65,9 +80,9 @@ class ExtensionEventRouter : public NotificationObserver { scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; - // A map between an event name and a set of process id's that are listening + // A map between an event name and a set of extensions that are listening // to that event. - typedef std::map<std::string, std::set<int> > ListenerMap; + typedef std::map<std::string, std::set<EventListener> > ListenerMap; ListenerMap listeners_; DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |