summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/api/cookies/cookies_api.cc2
-rw-r--r--chrome/browser/extensions/api/downloads/downloads_api.cc3
-rw-r--r--chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.cc3
-rw-r--r--chrome/browser/extensions/api/web_navigation/web_navigation_api.cc45
-rw-r--r--chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc12
-rw-r--r--chrome/browser/extensions/api/web_request/web_request_api.cc3
-rw-r--r--chrome/browser/extensions/event_listener_map.cc240
-rw-r--r--chrome/browser/extensions/event_listener_map.h159
-rw-r--r--chrome/browser/extensions/event_listener_map_unittest.cc298
-rw-r--r--chrome/browser/extensions/extension_browser_event_router.cc2
-rw-r--r--chrome/browser/extensions/extension_devtools_bridge.cc6
-rw-r--r--chrome/browser/extensions/extension_event_router.cc423
-rw-r--r--chrome/browser/extensions/extension_event_router.h122
-rw-r--r--chrome/browser/extensions/extension_event_router_forwarder.cc5
-rw-r--r--chrome/browser/extensions/extension_idle_api.cc2
-rw-r--r--chrome/browser/extensions/extension_managed_mode_api.cc5
-rw-r--r--chrome/browser/extensions/extension_management_api.cc2
-rw-r--r--chrome/browser/extensions/extension_messages_apitest.cc12
-rw-r--r--chrome/browser/extensions/extension_prefs.cc57
-rw-r--r--chrome/browser/extensions/extension_prefs.h15
-rw-r--r--chrome/browser/extensions/extension_processes_api.cc2
-rw-r--r--chrome/browser/extensions/lazy_background_page_apitest.cc16
-rw-r--r--chrome/browser/extensions/system/system_api.cc2
23 files changed, 255 insertions, 1181 deletions
diff --git a/chrome/browser/extensions/api/cookies/cookies_api.cc b/chrome/browser/extensions/api/cookies/cookies_api.cc
index cb17f30..e2cb2b0 100644
--- a/chrome/browser/extensions/api/cookies/cookies_api.cc
+++ b/chrome/browser/extensions/api/cookies/cookies_api.cc
@@ -115,7 +115,7 @@ void ExtensionCookiesEventRouter::DispatchEvent(Profile* profile,
GURL& cookie_domain) {
if (profile && profile->GetExtensionEventRouter()) {
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- event_name, json_args, profile, cookie_domain, EventFilteringInfo());
+ event_name, json_args, profile, cookie_domain);
}
}
diff --git a/chrome/browser/extensions/api/downloads/downloads_api.cc b/chrome/browser/extensions/api/downloads/downloads_api.cc
index 49e8f77..ca56cf9 100644
--- a/chrome/browser/extensions/api/downloads/downloads_api.cc
+++ b/chrome/browser/extensions/api/downloads/downloads_api.cc
@@ -1090,8 +1090,7 @@ void ExtensionDownloadsEventRouter::DispatchEvent(
event_name,
json_args,
profile_,
- GURL(),
- extensions::EventFilteringInfo());
+ GURL());
DownloadsNotificationSource notification_source;
notification_source.event_name = event_name;
diff --git a/chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.cc b/chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.cc
index 28bb985..5d3c596 100644
--- a/chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.cc
+++ b/chrome/browser/extensions/api/offscreen_tabs/offscreen_tabs_api.cc
@@ -276,8 +276,7 @@ void OffscreenTab::Observe(int type,
// event.
Profile* profile = parent_tab_->tab_contents()->profile();
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- events::kOnOffscreenTabUpdated, json_args, profile, GURL(),
- extensions::EventFilteringInfo());
+ events::kOnOffscreenTabUpdated, json_args, profile, GURL());
}
ParentTab::ParentTab() : tab_contents_(NULL) {}
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
index 82fe920..906294a 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_api.cc
@@ -20,7 +20,6 @@
#include "chrome/browser/view_type_utils.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/extensions/api/web_navigation.h"
-#include "chrome/common/extensions/event_filtering_info.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/resource_request_details.h"
#include "content/public/browser/navigation_details.h"
@@ -75,18 +74,11 @@ double MilliSecondsFromTime(const base::Time& time) {
// Dispatches events to the extension message service.
void DispatchEvent(BrowserContext* browser_context,
const char* event_name,
- const ListValue& args,
- const GURL& url) {
- std::string json_args;
- base::JSONWriter::Write(&args, &json_args);
-
- extensions::EventFilteringInfo info;
- info.SetURL(url);
-
+ const std::string& json_args) {
Profile* profile = Profile::FromBrowserContext(browser_context);
if (profile && profile->GetExtensionEventRouter()) {
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- event_name, json_args, profile, GURL(), info);
+ event_name, json_args, profile, GURL());
}
}
@@ -103,10 +95,11 @@ void DispatchOnBeforeNavigate(WebContents* web_contents,
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
+ std::string json_args;
+ base::JSONWriter::Write(&args, &json_args);
DispatchEvent(web_contents->GetBrowserContext(),
keys::kOnBeforeNavigate,
- args,
- validated_url);
+ json_args);
}
// Constructs and dispatches an onCommitted or onReferenceFragmentUpdated
@@ -138,7 +131,9 @@ void DispatchOnCommitted(const char* event_name,
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
- DispatchEvent(web_contents->GetBrowserContext(), event_name, args, url);
+ std::string json_args;
+ base::JSONWriter::Write(&args, &json_args);
+ DispatchEvent(web_contents->GetBrowserContext(), event_name, json_args);
}
// Constructs and dispatches an onDOMContentLoaded event.
@@ -155,10 +150,11 @@ void DispatchOnDOMContentLoaded(WebContents* web_contents,
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
+ std::string json_args;
+ base::JSONWriter::Write(&args, &json_args);
DispatchEvent(web_contents->GetBrowserContext(),
keys::kOnDOMContentLoaded,
- args,
- url);
+ json_args);
}
// Constructs and dispatches an onCompleted event.
@@ -175,8 +171,10 @@ void DispatchOnCompleted(WebContents* web_contents,
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
- DispatchEvent(web_contents->GetBrowserContext(), keys::kOnCompleted, args,
- url);
+ std::string json_args;
+ base::JSONWriter::Write(&args, &json_args);
+ DispatchEvent(web_contents->GetBrowserContext(),
+ keys::kOnCompleted, json_args);
}
// Constructs and dispatches an onCreatedNavigationTarget event.
@@ -206,8 +204,10 @@ void DispatchOnCreatedNavigationTarget(
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
- DispatchEvent(browser_context, keys::kOnCreatedNavigationTarget, args,
- target_url);
+ std::string json_args;
+ base::JSONWriter::Write(&args, &json_args);
+ DispatchEvent(
+ browser_context, keys::kOnCreatedNavigationTarget, json_args);
}
// Constructs and dispatches an onErrorOccurred event.
@@ -225,8 +225,11 @@ void DispatchOnErrorOccurred(WebContents* web_contents,
dict->SetDouble(keys::kTimeStampKey, MilliSecondsFromTime(base::Time::Now()));
args.Append(dict);
- DispatchEvent(web_contents->GetBrowserContext(), keys::kOnErrorOccurred,
- args, url);
+ std::string json_args;
+ base::JSONWriter::Write(&args, &json_args);
+ DispatchEvent(web_contents->GetBrowserContext(),
+ keys::kOnErrorOccurred,
+ json_args);
}
} // namespace
diff --git a/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc b/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc
index 28c0f32..e793f9c 100644
--- a/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc
+++ b/chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc
@@ -33,7 +33,6 @@ using content::WebContents;
#define MAYBE_WebNavigationReferenceFragment \
DISABLED_WebNavigationReferenceFragment
#define MAYBE_WebNavigationOpenTab DISABLED_WebNavigationOpenTab
-#define MAYBE_WebNavigationFilteredTest DISABLED_WebNavigationFilteredTest
#else
#define MAYBE_WebNavigationIFrame WebNavigationIFrame
#define MAYBE_WebNavigationFailures WebNavigationFailures
@@ -43,7 +42,6 @@ using content::WebContents;
#define MAYBE_WebNavigationSimpleLoad WebNavigationSimpleLoad
#define MAYBE_WebNavigationReferenceFragment WebNavigationReferenceFragment
#define MAYBE_WebNavigationOpenTab WebNavigationOpenTab
-#define MAYBE_WebNavigationFilteredTest WebNavigationFilteredTest
#endif
namespace extensions {
@@ -176,16 +174,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationFailures) {
RunExtensionSubtest("webnavigation", "test_failures.html")) << message_;
}
-IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebNavigationFilteredTest) {
- FrameNavigationState::set_allow_extension_scheme(true);
-
- CommandLine::ForCurrentProcess()->AppendSwitch(
- switches::kAllowLegacyExtensionManifests);
-
- ASSERT_TRUE(
- RunExtensionSubtest("webnavigation", "test_filtered.html")) << message_;
-}
-
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationUserAction) {
FrameNavigationState::set_allow_extension_scheme(true);
diff --git a/chrome/browser/extensions/api/web_request/web_request_api.cc b/chrome/browser/extensions/api/web_request/web_request_api.cc
index fb5aa99..d79316e 100644
--- a/chrome/browser/extensions/api/web_request/web_request_api.cc
+++ b/chrome/browser/extensions/api/web_request/web_request_api.cc
@@ -937,8 +937,7 @@ bool ExtensionWebRequestEventRouter::DispatchEvent(
ExtensionEventRouter::DispatchEvent(
(*it)->ipc_sender.get(), (*it)->extension_id, (*it)->sub_event_name,
- json_args, GURL(), ExtensionEventRouter::USER_GESTURE_UNKNOWN,
- EventFilteringInfo());
+ json_args, GURL(), ExtensionEventRouter::USER_GESTURE_UNKNOWN);
if ((*it)->extra_info_spec &
(ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) {
(*it)->blocked_requests.insert(request->identifier());
diff --git a/chrome/browser/extensions/event_listener_map.cc b/chrome/browser/extensions/event_listener_map.cc
deleted file mode 100644
index 5384d97..0000000
--- a/chrome/browser/extensions/event_listener_map.cc
+++ /dev/null
@@ -1,240 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/extensions/event_listener_map.h"
-
-#include "base/values.h"
-
-#include "chrome/browser/extensions/extension_event_router.h"
-
-namespace extensions {
-
-typedef EventFilter::MatcherID MatcherID;
-
-EventListener::EventListener(const std::string& event_name,
- const std::string& extension_id,
- content::RenderProcessHost* process,
- scoped_ptr<DictionaryValue> filter)
- : event_name(event_name),
- extension_id(extension_id),
- process(process),
- filter(filter.Pass()),
- matcher_id(-1) {}
-
-EventListener::~EventListener() {}
-
-bool EventListener::Equals(const EventListener* other) const {
- // We don't check matcher_id equality because we want a listener with a
- // filter that hasn't been added to EventFilter to match one that is
- // equivalent but has.
- return event_name == other->event_name &&
- extension_id == other->extension_id &&
- process == other->process &&
- ((!!filter.get()) == (!!other->filter.get())) &&
- (!filter.get() || filter->Equals(other->filter.get()));
-}
-
-scoped_ptr<EventListener> EventListener::Copy() const {
- scoped_ptr<DictionaryValue> filter_copy;
- if (filter.get())
- filter_copy.reset(filter->DeepCopy());
- return scoped_ptr<EventListener>(new EventListener(event_name, extension_id,
- process,
- filter_copy.Pass()));
-}
-
-EventListenerMap::EventListenerMap(Delegate* delegate)
- : delegate_(delegate) {
-}
-
-EventListenerMap::~EventListenerMap() {}
-
-bool EventListenerMap::AddListener(scoped_ptr<EventListener> listener) {
- if (HasListener(listener.get()))
- return false;
- if (listener->filter.get()) {
- scoped_ptr<EventMatcher> matcher(ParseEventMatcher(listener->filter.get()));
- MatcherID id = event_filter_.AddEventMatcher(listener->event_name,
- matcher.Pass());
- listener->matcher_id = id;
- listeners_by_matcher_id_[id] = listener.get();
- filtered_events_.insert(listener->event_name);
- }
- linked_ptr<EventListener> listener_ptr(listener.release());
- listeners_[listener_ptr->event_name].push_back(listener_ptr);
-
- delegate_->OnListenerAdded(listener_ptr.get());
-
- return true;
-}
-
-scoped_ptr<EventMatcher> EventListenerMap::ParseEventMatcher(
- DictionaryValue* filter_dict) {
- return scoped_ptr<EventMatcher>(new EventMatcher(
- scoped_ptr<DictionaryValue>(filter_dict->DeepCopy())));
-}
-
-bool EventListenerMap::RemoveListener(const EventListener* listener) {
- ListenerList& listeners = listeners_[listener->event_name];
- for (ListenerList::iterator it = listeners.begin(); it != listeners.end();
- it++) {
- if ((*it)->Equals(listener)) {
- delegate_->OnListenerRemoved(it->get());
- CleanupListener(it->get());
- // Popping from the back should be cheaper than erase(it).
- std::swap(*it, listeners.back());
- listeners.pop_back();
- return true;
- }
- }
- return false;
-}
-
-bool EventListenerMap::HasListenerForEvent(const std::string& event_name) {
- ListenerMap::iterator it = listeners_.find(event_name);
- return it != listeners_.end() && !it->second.empty();
-}
-
-bool EventListenerMap::HasListenerForExtension(
- const std::string& extension_id,
- const std::string& event_name) {
- ListenerMap::iterator it = listeners_.find(event_name);
- if (it == listeners_.end())
- return false;
-
- for (ListenerList::iterator it2 = it->second.begin();
- it2 != it->second.end(); it2++) {
- if ((*it2)->extension_id == extension_id)
- return true;
- }
- return false;
-}
-
-bool EventListenerMap::HasListener(const EventListener* listener) {
- ListenerMap::iterator it = listeners_.find(listener->event_name);
- if (it == listeners_.end())
- return false;
- for (ListenerList::iterator it2 = it->second.begin();
- it2 != it->second.end(); it2++) {
- if ((*it2)->Equals(listener)) {
- return true;
- }
- }
- return false;
-}
-
-bool EventListenerMap::HasProcessListener(content::RenderProcessHost* process,
- const std::string& extension_id) {
- for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end();
- it++) {
- for (ListenerList::iterator it2 = it->second.begin();
- it2 != it->second.end(); it2++) {
- if ((*it2)->process == process && (*it2)->extension_id == extension_id)
- return true;
- }
- }
- return false;
-}
-
-void EventListenerMap::RemoveLazyListenersForExtension(
- const std::string& extension_id) {
- for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end();
- it++) {
- for (ListenerList::iterator it2 = it->second.begin();
- it2 != it->second.end();) {
- if (!(*it2)->process && (*it2)->extension_id == extension_id) {
- CleanupListener(it2->get());
- it2 = it->second.erase(it2);
- } else {
- it2++;
- }
- }
- }
-}
-
-void EventListenerMap::LoadUnfilteredLazyListeners(
- const std::string& extension_id,
- const std::set<std::string>& event_names) {
- for (std::set<std::string>::const_iterator it = event_names.begin();
- it != event_names.end(); ++it) {
- AddListener(scoped_ptr<EventListener>(new EventListener(
- *it, extension_id, NULL, scoped_ptr<DictionaryValue>())));
- }
-}
-
-void EventListenerMap::LoadFilteredLazyListeners(
- const std::string& extension_id,
- const DictionaryValue& filtered) {
- for (DictionaryValue::key_iterator it = filtered.begin_keys();
- it != filtered.end_keys(); ++it) {
- // We skip entries if they are malformed.
- ListValue* filter_list = NULL;
- if (!filtered.GetList(*it, &filter_list))
- continue;
- for (size_t i = 0; i < filter_list->GetSize(); i++) {
- DictionaryValue* filter = NULL;
- if (!filter_list->GetDictionary(i, &filter))
- continue;
- AddListener(scoped_ptr<EventListener>(new EventListener(
- *it, extension_id, NULL,
- scoped_ptr<DictionaryValue>(filter->DeepCopy()))));
- }
- }
-}
-
-std::set<const EventListener*> EventListenerMap::GetEventListeners(
- const ExtensionEvent& event) {
- std::set<const EventListener*> interested_listeners;
- if (IsFilteredEvent(event)) {
- // Look up the interested listeners via the EventFilter.
- std::set<MatcherID> ids =
- event_filter_.MatchEvent(event.event_name, event.info);
- for (std::set<MatcherID>::iterator id = ids.begin(); id != ids.end();
- id++) {
- EventListener* listener = listeners_by_matcher_id_[*id];
- CHECK(listener);
- interested_listeners.insert(listener);
- }
- } else {
- ListenerList& listeners = listeners_[event.event_name];
- for (ListenerList::const_iterator it = listeners.begin();
- it != listeners.end(); it++) {
- interested_listeners.insert(it->get());
- }
- }
-
- return interested_listeners;
-}
-
-void EventListenerMap::RemoveListenersForProcess(
- const content::RenderProcessHost* process) {
- CHECK(process);
- for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end();
- it++) {
- for (ListenerList::iterator it2 = it->second.begin();
- it2 != it->second.end();) {
- if ((*it2)->process == process) {
- delegate_->OnListenerRemoved(it2->get());
- CleanupListener(it2->get());
- it2 = it->second.erase(it2);
- } else {
- it2++;
- }
- }
- }
-}
-
-void EventListenerMap::CleanupListener(EventListener* listener) {
- // If the listener doesn't have a filter then we have nothing to clean up.
- if (listener->matcher_id == -1)
- return;
- event_filter_.RemoveEventMatcher(listener->matcher_id);
- CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id));
-}
-
-bool EventListenerMap::IsFilteredEvent(const ExtensionEvent& event) const {
- return filtered_events_.count(event.event_name) > 0u;
-}
-
-} // namespace extensions
diff --git a/chrome/browser/extensions/event_listener_map.h b/chrome/browser/extensions/event_listener_map.h
deleted file mode 100644
index 1965598..0000000
--- a/chrome/browser/extensions/event_listener_map.h
+++ /dev/null
@@ -1,159 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_EXTENSIONS_EVENT_LISTENER_MAP_H_
-#define CHROME_BROWSER_EXTENSIONS_EVENT_LISTENER_MAP_H_
-#pragma once
-
-#include "base/memory/scoped_ptr.h"
-#include "chrome/common/extensions/event_filter.h"
-
-#include <map>
-#include <set>
-#include <string>
-#include <vector>
-
-namespace base {
-class DictionaryValue;
-}
-
-namespace content {
-class RenderProcessHost;
-}
-
-struct ExtensionEvent;
-class ListenerRemovalListener;
-
-using base::DictionaryValue;
-
-namespace extensions {
-
-// A listener for an extension event. A listener is essentially an endpoint
-// that an event can be dispatched to. This is a lazy listener if |process| is
-// NULL and a filtered listener if |filter| is defined.
-//
-// A lazy listener is added to an event to indicate that a lazy background page
-// is listening to the event. It is associated with no process, so to dispatch
-// an event to a lazy listener one must start a process running the associated
-// extension and dispatch the event to that.
-//
-struct EventListener {
- // |filter| represents a generic filter structure that EventFilter knows how
- // to filter events with. A typical filter instance will look like
- //
- // {
- // url: [{hostSuffix: 'google.com'}],
- // tabId: 5
- // }
- EventListener(const std::string& event_name,
- const std::string& extension_id,
- content::RenderProcessHost* process,
- scoped_ptr<DictionaryValue> filter);
- ~EventListener();
-
- bool Equals(const EventListener* other) const;
-
- scoped_ptr<EventListener> Copy() const;
-
- const std::string event_name;
- const std::string extension_id;
- content::RenderProcessHost* process;
- scoped_ptr<DictionaryValue> filter;
- EventFilter::MatcherID matcher_id;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(EventListener);
-};
-
-// Holds listeners for extension events and can answer questions about which
-// listeners are interested in what events.
-class EventListenerMap {
- public:
- typedef std::vector<linked_ptr<EventListener> > ListenerList;
-
- class Delegate {
- public:
- virtual ~Delegate() {}
- virtual void OnListenerAdded(const EventListener* listener) = 0;
- virtual void OnListenerRemoved(const EventListener* listener) = 0;
- };
-
- explicit EventListenerMap(Delegate* delegate);
- ~EventListenerMap();
-
- // Add a listener for a particular event. GetEventListeners() will include a
- // weak pointer to |listener| in its results if passed a relevant
- // ExtensionEvent.
- // Returns true if the listener was added (in the case that it has never been
- // seen before).
- bool AddListener(scoped_ptr<EventListener> listener);
-
- // Remove a listener that .Equals() |listener|.
- // Returns true if the listener was removed .
- bool RemoveListener(const EventListener* listener);
-
- // Returns the set of listeners that want to be notified of |event|.
- std::set<const EventListener*> GetEventListeners(
- const ExtensionEvent& event);
-
- // Removes all listeners with process equal to |process|.
- void RemoveListenersForProcess(const content::RenderProcessHost* process);
-
- // Returns true if there are any listeners on the event named |event_name|.
- bool HasListenerForEvent(const std::string& event_name);
-
- // Returns true if there are any listeners on |event_name| from
- // |extension_id|.
- bool HasListenerForExtension(const std::string& extension_id,
- const std::string& event_name);
-
- // Returns true if this map contains an EventListener that .Equals()
- // |listener|.
- bool HasListener(const EventListener* listener);
-
- // Returns true if there is a listener for |extension_id| in |process|.
- bool HasProcessListener(content::RenderProcessHost* process,
- const std::string& extension_id);
-
- // Removes any lazy listeners that |extension_id| has added.
- void RemoveLazyListenersForExtension(const std::string& extension_id);
-
- // Adds unfiltered lazy listeners as described their serialised descriptions.
- // |event_names| the names of the lazy events.
- // Note that we can only load lazy listeners in this fashion, because there
- // is no way to serialise a RenderProcessHost*.
- void LoadUnfilteredLazyListeners(const std::string& extension_id,
- const std::set<std::string>& event_names);
-
- // Adds filtered lazy listeners as described their serialised descriptions.
- // |filtered| contains a map from event names to filters, each pairing
- // defining a lazy filtered listener.
- void LoadFilteredLazyListeners(
- const std::string& extension_id,
- const DictionaryValue& filtered);
-
- private:
- // The key here is an event name.
- typedef std::map<std::string, ListenerList> ListenerMap;
-
- void CleanupListener(EventListener* listener);
- bool IsFilteredEvent(const ExtensionEvent& event) const;
- scoped_ptr<EventMatcher> ParseEventMatcher(DictionaryValue* filter_dict);
-
- // Listens for removals from this map.
- Delegate* delegate_;
-
- std::set<std::string> filtered_events_;
- ListenerMap listeners_;
-
- std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_;
-
- EventFilter event_filter_;
-
- DISALLOW_COPY_AND_ASSIGN(EventListenerMap);
-};
-
-} // namespace extensions
-
-#endif // CHROME_BROWSER_EXTENSIONS_EVENT_LISTENER_MAP_H_
diff --git a/chrome/browser/extensions/event_listener_map_unittest.cc b/chrome/browser/extensions/event_listener_map_unittest.cc
deleted file mode 100644
index 3cb2511..0000000
--- a/chrome/browser/extensions/event_listener_map_unittest.cc
+++ /dev/null
@@ -1,298 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "testing/gtest/include/gtest/gtest.h"
-
-#include "chrome/browser/extensions/event_listener_map.h"
-#include "chrome/browser/extensions/extension_event_router.h"
-#include "content/public/test/mock_render_process_host.h"
-#include "content/public/test/test_browser_context.h"
-
-namespace {
-
-const char kExt1Id[] = "extension_1";
-const char kExt2Id[] = "extension_2";
-const char kEvent1Name[] = "event1";
-const char kEvent2Name[] = "event2";
-
-class EmptyDelegate : public EventListenerMap::Delegate {
- virtual void OnListenerAdded(const EventListener* listener) OVERRIDE {};
- virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE {};
-};
-
-class EventListenerMapUnittest : public testing::Test {
- public:
- EventListenerMapUnittest()
- : delegate_(new EmptyDelegate),
- listeners_(new EventListenerMap(delegate_.get())),
- process_(new content::MockRenderProcessHost(
- new content::TestBrowserContext)) {
- }
-
- scoped_ptr<DictionaryValue> CreateHostSuffixFilter(
- const std::string& suffix) {
- scoped_ptr<DictionaryValue> filter(new DictionaryValue);
- scoped_ptr<ListValue> filter_list(new ListValue);
- scoped_ptr<DictionaryValue> filter_dict(new DictionaryValue);
-
- filter_dict->Set("hostSuffix", new StringValue(suffix));
-
- filter_list->Append(filter_dict.release());
- filter->Set("url", filter_list.release());
- return filter.Pass();
- }
-
- scoped_ptr<ExtensionEvent> CreateNamedEvent(const std::string& event_name) {
- return CreateEvent(event_name, GURL());
- }
-
- scoped_ptr<ExtensionEvent> CreateEvent(const std::string& event_name,
- const GURL& url) {
- EventFilteringInfo info;
- info.SetURL(url);
- scoped_ptr<ExtensionEvent> result(new ExtensionEvent(event_name, "", GURL(),
- NULL, "", ExtensionEventRouter::USER_GESTURE_UNKNOWN, info));
- return result.Pass();
- }
-
- protected:
- scoped_ptr<EventListenerMap::Delegate> delegate_;
- scoped_ptr<EventListenerMap> listeners_;
- scoped_ptr<content::MockRenderProcessHost> process_;
-};
-
-TEST_F(EventListenerMapUnittest, UnfilteredEventsGoToAllListeners) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, scoped_ptr<DictionaryValue>())));
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(1u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, FilteredEventsGoToAllMatchingListeners) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, scoped_ptr<DictionaryValue>(
- new DictionaryValue))));
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- event->info.SetURL(GURL("http://www.google.com"));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(2u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, FilteredEventsOnlyGoToMatchingListeners) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("yahoo.com"))));
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- event->info.SetURL(GURL("http://www.google.com"));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(1u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, LazyAndUnlazyListenersGetReturned) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
-
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, process_.get(),
- CreateHostSuffixFilter("google.com"))));
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- event->info.SetURL(GURL("http://www.google.com"));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(2u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, TestRemovingByProcess) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
-
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, process_.get(),
- CreateHostSuffixFilter("google.com"))));
-
- listeners_->RemoveListenersForProcess(process_.get());
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- event->info.SetURL(GURL("http://www.google.com"));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(1u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, TestRemovingByListener) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
-
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, process_.get(),
- CreateHostSuffixFilter("google.com"))));
-
- scoped_ptr<EventListener> listener(new EventListener(kEvent1Name, kExt1Id,
- process_.get(), CreateHostSuffixFilter("google.com")));
- listeners_->RemoveListener(listener.get());
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- event->info.SetURL(GURL("http://www.google.com"));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(1u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, TestLazyDoubleAddIsUndoneByRemove) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
-
- scoped_ptr<EventListener> listener(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com")));
- listeners_->RemoveListener(listener.get());
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- event->info.SetURL(GURL("http://www.google.com"));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(0u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, HostSuffixFilterEquality) {
- scoped_ptr<DictionaryValue> filter1(CreateHostSuffixFilter("google.com"));
- scoped_ptr<DictionaryValue> filter2(CreateHostSuffixFilter("google.com"));
- ASSERT_TRUE(filter1->Equals(filter2.get()));
-}
-
-TEST_F(EventListenerMapUnittest, RemoveLazyListenersForExtension) {
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent1Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
- listeners_->AddListener(scoped_ptr<EventListener>(new EventListener(
- kEvent2Name, kExt1Id, NULL, CreateHostSuffixFilter("google.com"))));
-
- listeners_->RemoveLazyListenersForExtension(kExt1Id);
-
- scoped_ptr<ExtensionEvent> event(CreateNamedEvent(kEvent1Name));
- event->info.SetURL(GURL("http://www.google.com"));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(0u, targets.size());
-
- event->event_name = kEvent2Name;
- targets = listeners_->GetEventListeners(*event);
- ASSERT_EQ(0u, targets.size());
-}
-
-TEST_F(EventListenerMapUnittest, AddExistingFilteredListener) {
- bool first_new = listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, NULL,
- CreateHostSuffixFilter("google.com"))));
- bool second_new = listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, NULL,
- CreateHostSuffixFilter("google.com"))));
-
- ASSERT_TRUE(first_new);
- ASSERT_FALSE(second_new);
-}
-
-TEST_F(EventListenerMapUnittest, AddExistingUnfilteredListener) {
- bool first_add = listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, NULL,
- scoped_ptr<DictionaryValue>())));
- bool second_add = listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, NULL,
- scoped_ptr<DictionaryValue>())));
-
- scoped_ptr<EventListener> listener(
- new EventListener(kEvent1Name, kExt1Id, NULL,
- scoped_ptr<DictionaryValue>()));
- bool first_remove = listeners_->RemoveListener(listener.get());
- bool second_remove = listeners_->RemoveListener(listener.get());
-
- ASSERT_TRUE(first_add);
- ASSERT_FALSE(second_add);
- ASSERT_TRUE(first_remove);
- ASSERT_FALSE(second_remove);
-}
-
-TEST_F(EventListenerMapUnittest, RemovingRouters) {
- listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, process_.get(),
- scoped_ptr<DictionaryValue>())));
- listeners_->RemoveListenersForProcess(process_.get());
- ASSERT_FALSE(listeners_->HasListenerForEvent(kEvent1Name));
-}
-
-TEST_F(EventListenerMapUnittest, HasListenerForEvent) {
- ASSERT_FALSE(listeners_->HasListenerForEvent(kEvent1Name));
-
- listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, process_.get(),
- scoped_ptr<DictionaryValue>())));
-
- ASSERT_FALSE(listeners_->HasListenerForEvent(kEvent2Name));
- ASSERT_TRUE(listeners_->HasListenerForEvent(kEvent1Name));
- listeners_->RemoveListenersForProcess(process_.get());
- ASSERT_FALSE(listeners_->HasListenerForEvent(kEvent1Name));
-}
-
-TEST_F(EventListenerMapUnittest, HasListenerForExtension) {
- ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name));
-
- // Non-lazy listener.
- listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, process_.get(),
- scoped_ptr<DictionaryValue>())));
- // Lazy listener.
- listeners_->AddListener(scoped_ptr<EventListener>(
- new EventListener(kEvent1Name, kExt1Id, NULL,
- scoped_ptr<DictionaryValue>())));
-
- ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent2Name));
- ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name));
- ASSERT_FALSE(listeners_->HasListenerForExtension(kExt2Id, kEvent1Name));
- listeners_->RemoveListenersForProcess(process_.get());
- ASSERT_TRUE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name));
- listeners_->RemoveLazyListenersForExtension(kExt1Id);
- ASSERT_FALSE(listeners_->HasListenerForExtension(kExt1Id, kEvent1Name));
-}
-
-TEST_F(EventListenerMapUnittest, AddLazyListenersFromPreferences) {
- scoped_ptr<DictionaryValue> filter1(CreateHostSuffixFilter("google.com"));
- scoped_ptr<DictionaryValue> filter2(CreateHostSuffixFilter("yahoo.com"));
-
- DictionaryValue filtered_listeners;
- ListValue* filter_list = new ListValue();
- filtered_listeners.Set(kEvent1Name, filter_list);
-
- filter_list->Append(filter1.release());
- filter_list->Append(filter2.release());
-
- listeners_->LoadFilteredLazyListeners(kExt1Id, filtered_listeners);
-
- scoped_ptr<ExtensionEvent> event(CreateEvent(kEvent1Name,
- GURL("http://www.google.com")));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(1u, targets.size());
- scoped_ptr<EventListener> listener(new EventListener(kEvent1Name, kExt1Id,
- NULL, CreateHostSuffixFilter("google.com")));
- ASSERT_TRUE((*targets.begin())->Equals(listener.get()));
-}
-
-TEST_F(EventListenerMapUnittest, CorruptedExtensionPrefsShouldntCrash) {
- scoped_ptr<DictionaryValue> filter1(CreateHostSuffixFilter("google.com"));
-
- DictionaryValue filtered_listeners;
- // kEvent1Name should be associated with a list, not a dictionary.
- filtered_listeners.Set(kEvent1Name, filter1.release());
-
- listeners_->LoadFilteredLazyListeners(kExt1Id, filtered_listeners);
-
- scoped_ptr<ExtensionEvent> event(CreateEvent(kEvent1Name,
- GURL("http://www.google.com")));
- std::set<const EventListener*> targets(listeners_->GetEventListeners(*event));
- ASSERT_EQ(0u, targets.size());
-}
-
-} // namespace
diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc
index 3d814ce..021c1ee 100644
--- a/chrome/browser/extensions/extension_browser_event_router.cc
+++ b/chrome/browser/extensions/extension_browser_event_router.cc
@@ -453,7 +453,7 @@ void ExtensionBrowserEventRouter::DispatchEvent(Profile* profile,
return;
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- event_name, json_args, profile, GURL(), extensions::EventFilteringInfo());
+ event_name, json_args, profile, GURL());
}
void ExtensionBrowserEventRouter::DispatchEventToExtension(
diff --git a/chrome/browser/extensions/extension_devtools_bridge.cc b/chrome/browser/extensions/extension_devtools_bridge.cc
index ff331b7..bdd4f91 100644
--- a/chrome/browser/extensions/extension_devtools_bridge.cc
+++ b/chrome/browser/extensions/extension_devtools_bridge.cc
@@ -107,8 +107,7 @@ void ExtensionDevToolsBridge::InspectedContentsClosing() {
// event in extensions.
std::string json("[{}]");
profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
- on_tab_close_event_name_, json, profile_, GURL(),
- extensions::EventFilteringInfo());
+ on_tab_close_event_name_, json, profile_, GURL());
// This may result in this object being destroyed.
extension_devtools_manager_->BridgeClosingForTab(tab_id_);
@@ -120,8 +119,7 @@ void ExtensionDevToolsBridge::DispatchOnInspectorFrontend(
std::string json = base::StringPrintf("[%s]", data.c_str());
profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
- on_page_event_name_, json, profile_, GURL(),
- extensions::EventFilteringInfo());
+ on_page_event_name_, json, profile_, GURL());
}
void ExtensionDevToolsBridge::ContentsReplaced(WebContents* new_contents) {
diff --git a/chrome/browser/extensions/extension_event_router.cc b/chrome/browser/extensions/extension_event_router.cc
index ae763ec..166d378 100644
--- a/chrome/browser/extensions/extension_event_router.cc
+++ b/chrome/browser/extensions/extension_event_router.cc
@@ -65,46 +65,88 @@ struct ExtensionEventRouter::ListenerProcess {
}
};
+struct ExtensionEventRouter::ExtensionEvent {
+ std::string event_name;
+ scoped_ptr<Value> event_args;
+ GURL event_url;
+ Profile* restrict_to_profile;
+ scoped_ptr<Value> cross_incognito_args;
+ UserGestureState user_gesture;
+
+ ExtensionEvent(const std::string& event_name,
+ const Value& event_args,
+ const GURL& event_url,
+ Profile* restrict_to_profile,
+ const Value& cross_incognito_args,
+ UserGestureState user_gesture)
+ : event_name(event_name),
+ event_args(event_args.DeepCopy()),
+ event_url(event_url),
+ restrict_to_profile(restrict_to_profile),
+ cross_incognito_args(cross_incognito_args.DeepCopy()),
+ user_gesture(user_gesture) {}
+
+ ExtensionEvent(const std::string& event_name,
+ const Value& event_args,
+ const GURL& event_url,
+ Profile* restrict_to_profile,
+ UserGestureState user_gesture)
+ : event_name(event_name),
+ event_args(event_args.DeepCopy()),
+ event_url(event_url),
+ restrict_to_profile(restrict_to_profile),
+ cross_incognito_args(NULL),
+ user_gesture(user_gesture) {}
+
+ // TODO(gdk): This variant should be retired once the callers are switched to
+ // providing Values instead of just strings.
+ ExtensionEvent(const std::string& event_name,
+ const std::string& event_args,
+ const GURL& event_url,
+ Profile* restrict_to_profile,
+ const std::string& cross_incognito_args,
+ UserGestureState user_gesture)
+ : event_name(event_name),
+ event_args(Value::CreateStringValue(event_args)),
+ event_url(event_url),
+ restrict_to_profile(restrict_to_profile),
+ cross_incognito_args(Value::CreateStringValue(cross_incognito_args)),
+ user_gesture(user_gesture) {}
+};
+
// static
-void ExtensionEventRouter::DispatchEvent(
- IPC::Sender* ipc_sender,
- const std::string& extension_id,
- const std::string& event_name,
- const Value& event_args,
- const GURL& event_url,
- UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info) {
+void ExtensionEventRouter::DispatchEvent(IPC::Sender* ipc_sender,
+ const std::string& extension_id,
+ const std::string& event_name,
+ const Value& event_args,
+ const GURL& event_url,
+ UserGestureState user_gesture) {
// TODO(gdk): Reduce number of DeepCopy() calls throughout the event dispatch
// chain, starting by replacing the event_args with a Value*.
ListValue args;
args.Set(0, Value::CreateStringValue(event_name));
args.Set(1, event_args.DeepCopy());
- args.Set(2, info.AsValue().release());
-
ipc_sender->Send(new ExtensionMsg_MessageInvoke(MSG_ROUTING_CONTROL,
extension_id, kDispatchEvent, args, event_url,
user_gesture == USER_GESTURE_ENABLED));
}
// static
-void ExtensionEventRouter::DispatchEvent(
- IPC::Sender* ipc_sender,
- const std::string& extension_id,
- const std::string& event_name,
- const std::string& event_args,
- const GURL& event_url,
- UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info) {
+void ExtensionEventRouter::DispatchEvent(IPC::Sender* ipc_sender,
+ const std::string& extension_id,
+ const std::string& event_name,
+ const std::string& event_args,
+ const GURL& event_url,
+ UserGestureState user_gesture) {
scoped_ptr<Value> event_args_value(Value::CreateStringValue(event_args));
DispatchEvent(ipc_sender, extension_id, event_name, *event_args_value.get(),
- event_url, user_gesture, info);
+ event_url, user_gesture);
}
ExtensionEventRouter::ExtensionEventRouter(Profile* profile)
: profile_(profile),
extension_devtools_manager_(
- ExtensionSystem::Get(profile)->devtools_manager()),
- listeners_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ ExtensionSystem::Get(profile)->devtools_manager()) {
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllSources());
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
@@ -123,46 +165,37 @@ void ExtensionEventRouter::AddEventListener(
const std::string& event_name,
content::RenderProcessHost* process,
const std::string& extension_id) {
- listeners_.AddListener(scoped_ptr<EventListener>(new EventListener(
- event_name, extension_id, process, scoped_ptr<DictionaryValue>())));
-}
-
-void ExtensionEventRouter::RemoveEventListener(
- const std::string& event_name,
- content::RenderProcessHost* process,
- const std::string& extension_id) {
- EventListener listener(event_name, extension_id, process,
- scoped_ptr<DictionaryValue>());
- listeners_.RemoveListener(&listener);
-}
-
-void ExtensionEventRouter::OnListenerAdded(const EventListener* listener) {
- // We don't care about lazy events being added.
- if (!listener->process)
- return;
+ ListenerProcess listener(process, extension_id);
+ DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name;
+ listeners_[event_name].insert(listener);
if (extension_devtools_manager_.get())
- extension_devtools_manager_->AddEventListener(listener->event_name,
- listener->process->GetID());
+ extension_devtools_manager_->AddEventListener(event_name,
+ process->GetID());
// We lazily tell the TaskManager to start updating when listeners to the
// processes.onUpdated or processes.onUpdatedWithMemory events arrive.
- const std::string& event_name = listener->event_name;
if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0 ||
event_name.compare(
extension_processes_api_constants::kOnUpdatedWithMemory) == 0)
ExtensionProcessesEventRouter::GetInstance()->ListenerAdded();
}
-void ExtensionEventRouter::OnListenerRemoved(const EventListener* listener) {
- // We don't care about lazy events being removed.
- if (!listener->process)
- return;
+void ExtensionEventRouter::RemoveEventListener(
+ const std::string& event_name,
+ content::RenderProcessHost* process,
+ const std::string& extension_id) {
+ ListenerProcess listener(process, extension_id);
+ DCHECK_EQ(listeners_[event_name].count(listener), 1u) <<
+ " PID=" << process->GetID() << " extension=" << extension_id <<
+ " event=" << event_name;
+ listeners_[event_name].erase(listener);
+ // Note: extension_id may point to data in the now-deleted listeners_ object.
+ // Do not use.
- const std::string& event_name = listener->event_name;
if (extension_devtools_manager_.get())
- extension_devtools_manager_->RemoveEventListener(
- event_name, listener->process->GetID());
+ extension_devtools_manager_->RemoveEventListener(event_name,
+ process->GetID());
// If a processes.onUpdated or processes.onUpdatedWithMemory event listener
// is removed (or a process with one exits), then we let the extension API
@@ -176,16 +209,14 @@ void ExtensionEventRouter::OnListenerRemoved(const EventListener* listener) {
BrowserThread::IO, FROM_HERE,
base::Bind(
&NotifyEventListenerRemovedOnIOThread,
- profile_, listener->extension_id, listener->event_name));
+ profile_, listener.extension_id, event_name));
}
void ExtensionEventRouter::AddLazyEventListener(
const std::string& event_name,
const std::string& extension_id) {
- scoped_ptr<EventListener> listener(new EventListener(
- event_name, extension_id, NULL, scoped_ptr<DictionaryValue>()));
- bool is_new = listeners_.AddListener(listener.Pass());
-
+ ListenerProcess lazy_listener(NULL, extension_id);
+ bool is_new = lazy_listeners_[event_name].insert(lazy_listener).second;
if (is_new) {
ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
std::set<std::string> events = prefs->GetRegisteredEvents(extension_id);
@@ -198,10 +229,8 @@ void ExtensionEventRouter::AddLazyEventListener(
void ExtensionEventRouter::RemoveLazyEventListener(
const std::string& event_name,
const std::string& extension_id) {
- EventListener listener(event_name, extension_id, NULL,
- scoped_ptr<DictionaryValue>());
- bool did_exist = listeners_.RemoveListener(&listener);
-
+ ListenerProcess lazy_listener(NULL, extension_id);
+ bool did_exist = lazy_listeners_[event_name].erase(lazy_listener) > 0;
if (did_exist) {
ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs();
std::set<std::string> events = prefs->GetRegisteredEvents(extension_id);
@@ -211,59 +240,15 @@ void ExtensionEventRouter::RemoveLazyEventListener(
}
}
-void ExtensionEventRouter::AddFilteredEventListener(
- const std::string& event_name,
- content::RenderProcessHost* process,
- const std::string& extension_id,
- const base::DictionaryValue& filter,
- bool add_lazy_listener) {
- listeners_.AddListener(scoped_ptr<EventListener>(new EventListener(
- event_name, extension_id, process,
- scoped_ptr<DictionaryValue>(filter.DeepCopy()))));
-
- if (add_lazy_listener) {
- bool added = listeners_.AddListener(scoped_ptr<EventListener>(
- new EventListener(event_name, extension_id, NULL,
- scoped_ptr<DictionaryValue>(filter.DeepCopy()))));
-
- if (added) {
- ExtensionPrefs* prefs =
- profile_->GetExtensionService()->extension_prefs();
- prefs->AddFilterToEvent(event_name, extension_id, &filter);
- }
- }
-}
-
-void ExtensionEventRouter::RemoveFilteredEventListener(
- const std::string& event_name,
- content::RenderProcessHost* process,
- const std::string& extension_id,
- const base::DictionaryValue& filter,
- bool remove_lazy_listener) {
- EventListener listener(event_name, extension_id, process,
- scoped_ptr<DictionaryValue>(filter.DeepCopy()));
-
- listeners_.RemoveListener(&listener);
-
- if (remove_lazy_listener) {
- listener.process = NULL;
- bool removed = listeners_.RemoveListener(&listener);
-
- if (removed) {
- ExtensionPrefs* prefs =
- profile_->GetExtensionService()->extension_prefs();
- prefs->RemoveFilterFromEvent(event_name, extension_id, &filter);
- }
- }
-}
-
bool ExtensionEventRouter::HasEventListener(const std::string& event_name) {
- return listeners_.HasListenerForEvent(event_name);
+ return (HasEventListenerImpl(listeners_, "", event_name) ||
+ HasEventListenerImpl(lazy_listeners_, "", event_name));
}
bool ExtensionEventRouter::ExtensionHasEventListener(
const std::string& extension_id, const std::string& event_name) {
- return listeners_.HasListenerForExtension(extension_id, event_name);
+ return (HasEventListenerImpl(listeners_, extension_id, event_name) ||
+ HasEventListenerImpl(lazy_listeners_, extension_id, event_name));
}
bool ExtensionEventRouter::HasEventListenerImpl(
@@ -290,25 +275,13 @@ void ExtensionEventRouter::DispatchEventToRenderers(
const std::string& event_name,
const std::string& event_args,
Profile* restrict_to_profile,
- const GURL& event_url,
- extensions::EventFilteringInfo info) {
- DCHECK(!event_args.empty());
- StringValue event_args_value(event_args);
+ const GURL& event_url) {
linked_ptr<ExtensionEvent> event(
- new ExtensionEvent(event_name, event_args_value, event_url,
- restrict_to_profile, USER_GESTURE_UNKNOWN, info));
+ new ExtensionEvent(event_name, event_args, event_url,
+ restrict_to_profile, "", USER_GESTURE_UNKNOWN));
DispatchEventImpl("", event);
}
-void ExtensionEventRouter::DispatchEventToRenderers(
- const std::string& event_name,
- const std::string& event_args,
- Profile* restrict_to_profile,
- const GURL& event_url) {
- DispatchEventToRenderers(event_name, event_args, restrict_to_profile,
- event_url, extensions::EventFilteringInfo());
-}
-
void ExtensionEventRouter::DispatchEventToExtension(
const std::string& extension_id,
const std::string& event_name,
@@ -318,8 +291,7 @@ void ExtensionEventRouter::DispatchEventToExtension(
DCHECK(!extension_id.empty());
linked_ptr<ExtensionEvent> event(
new ExtensionEvent(event_name, event_args, event_url,
- restrict_to_profile, USER_GESTURE_UNKNOWN,
- EventFilteringInfo()));
+ restrict_to_profile, USER_GESTURE_UNKNOWN));
DispatchEventImpl(extension_id, event);
}
@@ -329,8 +301,8 @@ void ExtensionEventRouter::DispatchEventToExtension(
const std::string& event_args,
Profile* restrict_to_profile,
const GURL& event_url) {
- StringValue event_args_value(event_args);
- DispatchEventToExtension(extension_id, event_name, event_args_value,
+ scoped_ptr<Value> event_args_value(Value::CreateStringValue(event_args));
+ DispatchEventToExtension(extension_id, event_name, *event_args_value.get(),
restrict_to_profile, event_url);
}
@@ -342,11 +314,9 @@ void ExtensionEventRouter::DispatchEventToExtension(
const GURL& event_url,
UserGestureState user_gesture) {
DCHECK(!extension_id.empty());
- StringValue event_args_value(event_args);
linked_ptr<ExtensionEvent> event(
- new ExtensionEvent(event_name, event_args_value, event_url,
- restrict_to_profile, user_gesture,
- EventFilteringInfo()));
+ new ExtensionEvent(event_name, event_args, event_url,
+ restrict_to_profile, "", user_gesture));
DispatchEventImpl(extension_id, event);
}
@@ -359,57 +329,39 @@ void ExtensionEventRouter::DispatchEventsToRenderersAcrossIncognito(
linked_ptr<ExtensionEvent> event(
new ExtensionEvent(event_name, event_args, event_url,
restrict_to_profile, cross_incognito_args,
- USER_GESTURE_UNKNOWN, EventFilteringInfo()));
+ USER_GESTURE_UNKNOWN));
DispatchEventImpl("", event);
}
void ExtensionEventRouter::DispatchEventImpl(
- const std::string& restrict_to_extension_id,
+ const std::string& extension_id,
const linked_ptr<ExtensionEvent>& event) {
// We don't expect to get events from a completely different profile.
DCHECK(!event->restrict_to_profile ||
profile_->IsSameProfile(event->restrict_to_profile));
- std::set<const EventListener*> listeners(
- listeners_.GetEventListeners(*event));
- for (std::set<const EventListener*>::iterator it = listeners.begin();
- it != listeners.end(); it++) {
- const EventListener* listener = *it;
- if (listener->process) {
- if (restrict_to_extension_id.empty() ||
- restrict_to_extension_id == listener->extension_id)
- DispatchEventToProcess(listener->extension_id, listener->process,
- event);
- } else {
- DispatchLazyEvent(listener->extension_id, event);
- }
- }
-}
+ LoadLazyBackgroundPagesForEvent(extension_id, event);
-void ExtensionEventRouter::DispatchLazyEvent(
- const std::string& extension_id,
- const linked_ptr<ExtensionEvent>& event) {
- ExtensionService* service = profile_->GetExtensionService();
- // Check both the original and the incognito profile to see if we
- // should load a lazy bg page to handle the event. The latter case
- // occurs in the case of split-mode extensions.
- const Extension* extension = service->extensions()->GetByID(extension_id);
- if (extension) {
- MaybeLoadLazyBackgroundPageToDispatchEvent(profile_, extension, event);
- if (profile_->HasOffTheRecordProfile() &&
- extension->incognito_split_mode()) {
- MaybeLoadLazyBackgroundPageToDispatchEvent(
- profile_->GetOffTheRecordProfile(), extension, event);
- }
+ ListenerMap::iterator it = listeners_.find(event->event_name);
+ if (it == listeners_.end())
+ return;
+
+ std::set<ListenerProcess>& listeners = it->second;
+ for (std::set<ListenerProcess>::iterator listener = listeners.begin();
+ listener != listeners.end(); ++listener) {
+ if (!extension_id.empty() && extension_id != listener->extension_id)
+ continue;
+
+ DispatchEventToListener(*listener, event);
}
}
-void ExtensionEventRouter::DispatchEventToProcess(
- const std::string& extension_id,
- content::RenderProcessHost* process,
+void ExtensionEventRouter::DispatchEventToListener(
+ const ListenerProcess& listener,
const linked_ptr<ExtensionEvent>& event) {
ExtensionService* service = profile_->GetExtensionService();
- const Extension* extension = service->extensions()->GetByID(extension_id);
+ const Extension* extension = service->extensions()->GetByID(
+ listener.extension_id);
// The extension could have been removed, but we do not unregister it until
// the extension process is unloaded.
@@ -417,13 +369,13 @@ void ExtensionEventRouter::DispatchEventToProcess(
return;
Profile* listener_profile = Profile::FromBrowserContext(
- process->GetBrowserContext());
+ listener.process->GetBrowserContext());
extensions::ProcessMap* process_map =
listener_profile->GetExtensionService()->process_map();
// If the event is privileged, only send to extension processes. Otherwise,
// it's OK to send to normal renderers (e.g., for content scripts).
if (ExtensionAPI::GetSharedInstance()->IsPrivileged(event->event_name) &&
- !process_map->Contains(extension->id(), process->GetID())) {
+ !process_map->Contains(extension->id(), listener.process->GetID())) {
return;
}
@@ -433,10 +385,9 @@ void ExtensionEventRouter::DispatchEventToProcess(
return;
}
- DispatchEvent(process, extension_id,
+ DispatchEvent(listener.process, listener.extension_id,
event->event_name, *event_args,
- event->event_url, event->user_gesture,
- event->info);
+ event->event_url, event->user_gesture);
IncrementInFlightEvents(listener_profile, extension);
}
@@ -463,7 +414,38 @@ bool ExtensionEventRouter::CanDispatchEventToProfile(
return true;
}
-void ExtensionEventRouter::MaybeLoadLazyBackgroundPageToDispatchEvent(
+void ExtensionEventRouter::LoadLazyBackgroundPagesForEvent(
+ const std::string& extension_id,
+ const linked_ptr<ExtensionEvent>& event) {
+ ExtensionService* service = profile_->GetExtensionService();
+
+ ListenerMap::iterator it = lazy_listeners_.find(event->event_name);
+ if (it == lazy_listeners_.end())
+ return;
+
+ std::set<ListenerProcess>& listeners = it->second;
+ for (std::set<ListenerProcess>::iterator listener = listeners.begin();
+ listener != listeners.end(); ++listener) {
+ if (!extension_id.empty() && extension_id != listener->extension_id)
+ continue;
+
+ // Check both the original and the incognito profile to see if we
+ // should load a lazy bg page to handle the event. The latter case
+ // occurs in the case of split-mode extensions.
+ const Extension* extension = service->extensions()->GetByID(
+ listener->extension_id);
+ if (extension) {
+ MaybeLoadLazyBackgroundPage(profile_, extension, event);
+ if (profile_->HasOffTheRecordProfile() &&
+ extension->incognito_split_mode()) {
+ MaybeLoadLazyBackgroundPage(
+ profile_->GetOffTheRecordProfile(), extension, event);
+ }
+ }
+ }
+}
+
+void ExtensionEventRouter::MaybeLoadLazyBackgroundPage(
Profile* profile,
const Extension* extension,
const linked_ptr<ExtensionEvent>& event) {
@@ -509,15 +491,14 @@ void ExtensionEventRouter::OnEventAck(
}
void ExtensionEventRouter::DispatchPendingEvent(
- const linked_ptr<ExtensionEvent>& event,
- ExtensionHost* host) {
+ const linked_ptr<ExtensionEvent>& event, ExtensionHost* host) {
if (!host)
return;
- if (listeners_.HasProcessListener(host->render_process_host(),
- host->extension()->id()))
- DispatchEventToProcess(host->extension()->id(),
- host->render_process_host(), event);
+ ListenerProcess listener(host->render_process_host(),
+ host->extension()->id());
+ if (listeners_[event->event_name].count(listener) > 0u)
+ DispatchEventToListener(listener, event);
}
void ExtensionEventRouter::Observe(
@@ -530,30 +511,45 @@ void ExtensionEventRouter::Observe(
content::RenderProcessHost* renderer =
content::Source<content::RenderProcessHost>(source).ptr();
// Remove all event listeners associated with this renderer.
- listeners_.RemoveListenersForProcess(renderer);
+ for (ListenerMap::iterator it = listeners_.begin();
+ it != listeners_.end(); ) {
+ ListenerMap::iterator current_it = it++;
+ for (std::set<ListenerProcess>::iterator jt =
+ current_it->second.begin();
+ jt != current_it->second.end(); ) {
+ std::set<ListenerProcess>::iterator current_jt = jt++;
+ if (current_jt->process == renderer) {
+ RemoveEventListener(current_it->first,
+ current_jt->process,
+ current_jt->extension_id);
+ }
+ }
+ }
break;
}
case chrome::NOTIFICATION_EXTENSION_LOADED: {
// Add all registered lazy listeners to our cache.
const Extension* extension =
content::Details<const Extension>(details).ptr();
- ExtensionPrefs* prefs =
- profile_->GetExtensionService()->extension_prefs();
std::set<std::string> registered_events =
- prefs->GetRegisteredEvents(extension->id());
- listeners_.LoadUnfilteredLazyListeners(extension->id(),
- registered_events);
- const DictionaryValue* filtered_events =
- prefs->GetFilteredEvents(extension->id());
- if (filtered_events)
- listeners_.LoadFilteredLazyListeners(extension->id(), *filtered_events);
+ profile_->GetExtensionService()->extension_prefs()->
+ GetRegisteredEvents(extension->id());
+ ListenerProcess lazy_listener(NULL, extension->id());
+ for (std::set<std::string>::iterator it = registered_events.begin();
+ it != registered_events.end(); ++it) {
+ lazy_listeners_[*it].insert(lazy_listener);
+ }
break;
}
case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
// Remove all registered lazy listeners from our cache.
extensions::UnloadedExtensionInfo* unloaded =
content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
- listeners_.RemoveLazyListenersForExtension(unloaded->extension->id());
+ ListenerProcess lazy_listener(NULL, unloaded->extension->id());
+ for (ListenerMap::iterator it = lazy_listeners_.begin();
+ it != lazy_listeners_.end(); ++it) {
+ it->second.erase(lazy_listener);
+ }
break;
}
case chrome::NOTIFICATION_EXTENSION_INSTALLED: {
@@ -570,56 +566,3 @@ void ExtensionEventRouter::Observe(
return;
}
}
-
-ExtensionEvent::ExtensionEvent(
- const std::string& event_name,
- const Value& event_args,
- const GURL& event_url,
- Profile* restrict_to_profile,
- const Value& cross_incognito_args,
- ExtensionEventRouter::UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info)
- : event_name(event_name),
- event_args(event_args.DeepCopy()),
- event_url(event_url),
- restrict_to_profile(restrict_to_profile),
- cross_incognito_args(cross_incognito_args.DeepCopy()),
- user_gesture(user_gesture),
- info(info) {
-}
-
-ExtensionEvent::ExtensionEvent(
- const std::string& event_name,
- const std::string& event_args,
- const GURL& event_url,
- Profile* restrict_to_profile,
- const std::string& cross_incognito_args,
- ExtensionEventRouter::UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info)
- : event_name(event_name),
- event_args(Value::CreateStringValue(event_args)),
- event_url(event_url),
- restrict_to_profile(restrict_to_profile),
- cross_incognito_args(Value::CreateStringValue(cross_incognito_args)),
- user_gesture(user_gesture),
- info(info) {
-}
-
-ExtensionEvent::ExtensionEvent(
- const std::string& event_name,
- const Value& event_args,
- const GURL& event_url,
- Profile* restrict_to_profile,
- ExtensionEventRouter::UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info)
- : event_name(event_name),
- event_args(event_args.DeepCopy()),
- event_url(event_url),
- restrict_to_profile(restrict_to_profile),
- cross_incognito_args(NULL),
- user_gesture(user_gesture),
- info(info) {
-}
-
-ExtensionEvent::~ExtensionEvent() {
-}
diff --git a/chrome/browser/extensions/extension_event_router.h b/chrome/browser/extensions/extension_event_router.h
index 4afc4a2..4bcfc0e 100644
--- a/chrome/browser/extensions/extension_event_router.h
+++ b/chrome/browser/extensions/extension_event_router.h
@@ -14,8 +14,6 @@
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/values.h"
-#include "chrome/browser/extensions/event_listener_map.h"
-#include "chrome/common/extensions/event_filtering_info.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ipc/ipc_sender.h"
@@ -33,14 +31,7 @@ namespace extensions {
class Extension;
}
-struct ExtensionEvent;
-
-using extensions::EventFilteringInfo;
-using extensions::EventListener;
-using extensions::EventListenerMap;
-
-class ExtensionEventRouter : public content::NotificationObserver,
- public extensions::EventListenerMap::Delegate {
+class ExtensionEventRouter : public content::NotificationObserver {
public:
// These constants convey the state of our knowledge of whether we're in
// a user-caused gesture as part of DispatchEvent.
@@ -57,8 +48,7 @@ class ExtensionEventRouter : public content::NotificationObserver,
const std::string& event_name,
const base::Value& event_args,
const GURL& event_url,
- UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info);
+ UserGestureState user_gesture);
// This invocation is deprecated. All future consumers of this API should be
// sending Values as event arguments, using the above version.
@@ -67,8 +57,7 @@ class ExtensionEventRouter : public content::NotificationObserver,
const std::string& event_name,
const std::string& event_args,
const GURL& event_url,
- UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info);
+ UserGestureState user_gesture);
explicit ExtensionEventRouter(Profile* profile);
virtual ~ExtensionEventRouter();
@@ -93,21 +82,6 @@ class ExtensionEventRouter : public content::NotificationObserver,
void RemoveLazyEventListener(const std::string& event_name,
const std::string& extension_id);
- // If |add_lazy_listener| is true also add the lazy version of this listener.
- void AddFilteredEventListener(const std::string& event_name,
- content::RenderProcessHost* process,
- const std::string& extension_id,
- const base::DictionaryValue& filter,
- bool add_lazy_listener);
-
- // If |remove_lazy_listener| is true also remove the lazy version of this
- // listener.
- void RemoveFilteredEventListener(const std::string& event_name,
- content::RenderProcessHost* process,
- const std::string& extension_id,
- const base::DictionaryValue& filter,
- bool remove_lazy_listener);
-
// Returns true if there is at least one listener for the given event.
bool HasEventListener(const std::string& event_name);
@@ -125,14 +99,6 @@ class ExtensionEventRouter : public content::NotificationObserver,
const std::string& event_name,
const std::string& event_args,
Profile* restrict_to_profile,
- const GURL& event_url,
- extensions::EventFilteringInfo info);
-
- // As above, but defaults |info| to EventFilteringInfo().
- void DispatchEventToRenderers(
- const std::string& event_name,
- const std::string& event_args,
- Profile* restrict_to_profile,
const GURL& event_url);
// Same as above, except only send the event to the given extension.
@@ -180,6 +146,9 @@ class ExtensionEventRouter : public content::NotificationObserver,
void OnEventAck(Profile* profile, const std::string& extension_id);
private:
+ // The details of an event to be dispatched.
+ struct ExtensionEvent;
+
// The extension and process that contains the event listener for a given
// event.
struct ListenerProcess;
@@ -199,21 +168,16 @@ class ExtensionEventRouter : public content::NotificationObserver,
const std::string& extension_id,
const std::string& event_name);
- // Shared by DispatchEvent*. If |restrict_to_extension_id| is empty, the
- // event is broadcast.
+ // Shared by DispatchEvent*. If |extension_id| is empty, the event is
+ // broadcast. If |process| is non-NULL, the event is only dispatched to that
+ // particular process.
// An event that just came off the pending list may not be delayed again.
- void DispatchEventImpl(const std::string& restrict_to_extension_id,
- const linked_ptr<ExtensionEvent>& event);
-
- // Ensures that all lazy background pages that are interested in the given
- // event are loaded, and queues the event if the page is not ready yet.
- void DispatchLazyEvent(const std::string& extension_id,
+ void DispatchEventImpl(const std::string& extension_id,
const linked_ptr<ExtensionEvent>& event);
- // Dispatches the event to the specified extension running in |process|.
- void DispatchEventToProcess(const std::string& extension_id,
- content::RenderProcessHost* process,
- const linked_ptr<ExtensionEvent>& event);
+ // Dispatches the event to a single listener process.
+ void DispatchEventToListener(const ListenerProcess& listener,
+ const linked_ptr<ExtensionEvent>& event);
// Returns false when the event is scoped to a profile and the listening
// extension does not have access to events from that profile. Also fills
@@ -225,9 +189,17 @@ class ExtensionEventRouter : public content::NotificationObserver,
const linked_ptr<ExtensionEvent>& event,
const base::Value** event_args);
+ // Ensures that all lazy background pages that are interested in the given
+ // event are loaded, and queues the event if the page is not ready yet.
+ // If |extension_id| is non-empty, we load only that extension's page
+ // (assuming it is interested in the event).
+ void LoadLazyBackgroundPagesForEvent(
+ const std::string& extension_id,
+ const linked_ptr<ExtensionEvent>& event);
+
// Possibly loads given extension's background page in preparation to
// dispatch an event.
- void MaybeLoadLazyBackgroundPageToDispatchEvent(
+ void MaybeLoadLazyBackgroundPage(
Profile* profile,
const extensions::Extension* extension,
const linked_ptr<ExtensionEvent>& event);
@@ -240,57 +212,21 @@ class ExtensionEventRouter : public content::NotificationObserver,
void DispatchPendingEvent(const linked_ptr<ExtensionEvent>& event,
ExtensionHost* host);
- // Implementation of extensions::EventListenerMap::Delegate.
- virtual void OnListenerAdded(const EventListener* listener) OVERRIDE;
- virtual void OnListenerRemoved(const EventListener* listener) OVERRIDE;
-
Profile* profile_;
content::NotificationRegistrar registrar_;
scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_;
- EventListenerMap listeners_;
+ // The list of active extension processes that are listening to events.
+ ListenerMap listeners_;
- DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter);
-};
+ // The list of all the lazy (non-persistent) background pages that are
+ // listening to events. This is just a cache of the real list, which is
+ // stored on disk in the extension prefs.
+ ListenerMap lazy_listeners_;
-struct ExtensionEvent {
- std::string event_name;
- scoped_ptr<Value> event_args;
- GURL event_url;
- Profile* restrict_to_profile;
- scoped_ptr<Value> cross_incognito_args;
- ExtensionEventRouter::UserGestureState user_gesture;
- extensions::EventFilteringInfo info;
-
- ExtensionEvent(const std::string& event_name,
- const Value& event_args,
- const GURL& event_url,
- Profile* restrict_to_profile,
- const Value& cross_incognito_args,
- ExtensionEventRouter::UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info);
-
- // TODO(gdk): This variant should be retired once the callers are switched to
- // providing Values instead of just strings.
- ExtensionEvent(const std::string& event_name,
- const std::string& event_args,
- const GURL& event_url,
- Profile* restrict_to_profile,
- const std::string& cross_incognito_args,
- ExtensionEventRouter::UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info);
-
- ExtensionEvent(const std::string& event_name,
- const Value& event_args,
- const GURL& event_url,
- Profile* restrict_to_profile,
- ExtensionEventRouter::UserGestureState user_gesture,
- const extensions::EventFilteringInfo& info);
-
- ~ExtensionEvent();
+ DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter);
};
-
#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_
diff --git a/chrome/browser/extensions/extension_event_router_forwarder.cc b/chrome/browser/extensions/extension_event_router_forwarder.cc
index 5231324..f654d12 100644
--- a/chrome/browser/extensions/extension_event_router_forwarder.cc
+++ b/chrome/browser/extensions/extension_event_router_forwarder.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -114,8 +114,7 @@ void ExtensionEventRouterForwarder::CallExtensionEventRouter(
if (extension_id.empty()) {
profile->GetExtensionEventRouter()->
DispatchEventToRenderers(
- event_name, event_args, restrict_to_profile, event_url,
- extensions::EventFilteringInfo());
+ event_name, event_args, restrict_to_profile, event_url);
} else {
profile->GetExtensionEventRouter()->
DispatchEventToExtension(
diff --git a/chrome/browser/extensions/extension_idle_api.cc b/chrome/browser/extensions/extension_idle_api.cc
index 87ce764..8df6ac8 100644
--- a/chrome/browser/extensions/extension_idle_api.cc
+++ b/chrome/browser/extensions/extension_idle_api.cc
@@ -145,7 +145,7 @@ void ExtensionIdleEventRouter::OnIdleStateChange(Profile* profile,
base::JSONWriter::Write(&args, &json_args);
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- keys::kOnStateChanged, json_args, profile, GURL(), EventFilteringInfo());
+ keys::kOnStateChanged, json_args, profile, GURL());
}
bool ExtensionIdleQueryStateFunction::RunImpl() {
diff --git a/chrome/browser/extensions/extension_managed_mode_api.cc b/chrome/browser/extensions/extension_managed_mode_api.cc
index 11e9f6f..efa05f8 100644
--- a/chrome/browser/extensions/extension_managed_mode_api.cc
+++ b/chrome/browser/extensions/extension_managed_mode_api.cc
@@ -66,9 +66,8 @@ void ExtensionManagedModeEventRouter::Observe(
std::string json_args;
base::JSONWriter::Write(&args, &json_args);
ExtensionEventRouter* event_router = profile_->GetExtensionEventRouter();
- event_router->DispatchEventToRenderers(kChangeEventName, json_args, NULL,
- GURL(),
- extensions::EventFilteringInfo());
+ event_router->DispatchEventToRenderers(kChangeEventName, json_args,
+ NULL, GURL());
}
GetManagedModeFunction::~GetManagedModeFunction() { }
diff --git a/chrome/browser/extensions/extension_management_api.cc b/chrome/browser/extensions/extension_management_api.cc
index 6dfe438..3c5a998 100644
--- a/chrome/browser/extensions/extension_management_api.cc
+++ b/chrome/browser/extensions/extension_management_api.cc
@@ -589,5 +589,5 @@ void ExtensionManagementEventRouter::Observe(
base::JSONWriter::Write(&args, &args_json);
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- event_name, args_json, NULL, GURL(), extensions::EventFilteringInfo());
+ event_name, args_json, NULL, GURL());
}
diff --git a/chrome/browser/extensions/extension_messages_apitest.cc b/chrome/browser/extensions/extension_messages_apitest.cc
index a61882d..afb94ca 100644
--- a/chrome/browser/extensions/extension_messages_apitest.cc
+++ b/chrome/browser/extensions/extension_messages_apitest.cc
@@ -31,23 +31,19 @@ class MessageSender : public content::NotificationObserver {
event_router->DispatchEventToRenderers("test.onMessage",
"[{\"lastMessage\":false,\"data\":\"no restriction\"}]",
content::Source<Profile>(source).ptr(),
- GURL(),
- EventFilteringInfo());
+ GURL());
event_router->DispatchEventToRenderers("test.onMessage",
"[{\"lastMessage\":false,\"data\":\"http://a.com/\"}]",
content::Source<Profile>(source).ptr(),
- GURL("http://a.com/"),
- EventFilteringInfo());
+ GURL("http://a.com/"));
event_router->DispatchEventToRenderers("test.onMessage",
"[{\"lastMessage\":false,\"data\":\"http://b.com/\"}]",
content::Source<Profile>(source).ptr(),
- GURL("http://b.com/"),
- EventFilteringInfo());
+ GURL("http://b.com/"));
event_router->DispatchEventToRenderers("test.onMessage",
"[{\"lastMessage\":true,\"data\":\"last message\"}]",
content::Source<Profile>(source).ptr(),
- GURL(),
- EventFilteringInfo());
+ GURL());
}
content::NotificationRegistrar registrar_;
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc
index 7d210b9..19e01db 100644
--- a/chrome/browser/extensions/extension_prefs.cc
+++ b/chrome/browser/extensions/extension_prefs.cc
@@ -179,10 +179,6 @@ const char kPrefIncognitoContentSettings[] = "incognito_content_settings";
// background page.
const char kRegisteredEvents[] = "events";
-// A dictionary of event names to lists of filters that this extension has
-// registered from its lazy background page.
-const char kFilteredEvents[] = "filtered_events";
-
// Persisted value for omnibox.setDefaultSuggestion.
const char kOmniboxDefaultSuggestion[] = "omnibox_default_suggestion";
@@ -990,59 +986,6 @@ std::set<std::string> ExtensionPrefs::GetRegisteredEvents(
return events;
}
-void ExtensionPrefs::AddFilterToEvent(const std::string& event_name,
- const std::string& extension_id,
- const DictionaryValue* filter) {
- ScopedExtensionPrefUpdate update(prefs_, extension_id);
- DictionaryValue* extension_dict = update.Get();
- DictionaryValue* filtered_events = NULL;
- if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events)) {
- filtered_events = new DictionaryValue;
- extension_dict->Set(kFilteredEvents, filtered_events);
- }
- ListValue* filter_list = NULL;
- if (!filtered_events->GetList(event_name, &filter_list)) {
- filter_list = new ListValue;
- filtered_events->Set(event_name, filter_list);
- }
-
- filter_list->Append(filter->DeepCopy());
-}
-
-void ExtensionPrefs::RemoveFilterFromEvent(const std::string& event_name,
- const std::string& extension_id,
- const DictionaryValue* filter) {
- ScopedExtensionPrefUpdate update(prefs_, extension_id);
- DictionaryValue* extension_dict = update.Get();
- DictionaryValue* filtered_events = NULL;
-
- if (!extension_dict->GetDictionary(kFilteredEvents, &filtered_events))
- return;
- ListValue* filter_list = NULL;
- if (!filtered_events->GetList(event_name, &filter_list))
- return;
-
- for (size_t i = 0; i < filter_list->GetSize(); i++) {
- DictionaryValue* filter;
- CHECK(filter_list->GetDictionary(i, &filter));
- if (filter->Equals(filter)) {
- filter_list->Remove(i, NULL);
- break;
- }
- }
-}
-
-const DictionaryValue* ExtensionPrefs::GetFilteredEvents(
- const std::string& extension_id) const {
- const DictionaryValue* extension = GetExtensionPref(extension_id);
- if (!extension)
- return NULL;
- DictionaryValue* result = NULL;
- if (!extension->GetDictionary(kFilteredEvents, &result))
- return NULL;
- return result;
-}
-
void ExtensionPrefs::SetRegisteredEvents(
const std::string& extension_id, const std::set<std::string>& events) {
ListValue* value = new ListValue();
diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h
index e142fe1..c5735c4 100644
--- a/chrome/browser/extensions/extension_prefs.h
+++ b/chrome/browser/extensions/extension_prefs.h
@@ -279,21 +279,6 @@ class ExtensionPrefs : public extensions::ContentSettingsStore::Observer,
void SetRegisteredEvents(const std::string& extension_id,
const std::set<std::string>& events);
- // Adds a filter to an event.
- void AddFilterToEvent(const std::string& event_name,
- const std::string& extension_id,
- const DictionaryValue* filter);
-
- // Removes a filter from an event.
- void RemoveFilterFromEvent(const std::string& event_name,
- const std::string& extension_id,
- const DictionaryValue* filter);
-
- // Returns the dictionary of event filters that the given extension has
- // registered.
- const DictionaryValue* GetFilteredEvents(
- const std::string& extension_id) const;
-
// Controls the omnibox default suggestion as set by the extension.
extensions::ExtensionOmniboxSuggestion GetOmniboxDefaultSuggestion(
const std::string& extension_id);
diff --git a/chrome/browser/extensions/extension_processes_api.cc b/chrome/browser/extensions/extension_processes_api.cc
index c853495..4607c50 100644
--- a/chrome/browser/extensions/extension_processes_api.cc
+++ b/chrome/browser/extensions/extension_processes_api.cc
@@ -489,7 +489,7 @@ void ExtensionProcessesEventRouter::DispatchEvent(
const std::string& json_args) {
if (profile && profile->GetExtensionEventRouter()) {
profile->GetExtensionEventRouter()->DispatchEventToRenderers(
- event_name, json_args, NULL, GURL(), EventFilteringInfo());
+ event_name, json_args, NULL, GURL());
}
}
diff --git a/chrome/browser/extensions/lazy_background_page_apitest.cc b/chrome/browser/extensions/lazy_background_page_apitest.cc
index 23a067c..5a54454 100644
--- a/chrome/browser/extensions/lazy_background_page_apitest.cc
+++ b/chrome/browser/extensions/lazy_background_page_apitest.cc
@@ -167,22 +167,6 @@ IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) {
GetLocationBarForTesting()->PageActionVisibleCount());
}
-IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) {
- const Extension* extension = LoadExtensionAndWait("filters");
- ASSERT_TRUE(extension);
-
- // Lazy Background Page doesn't exist yet.
- ExtensionProcessManager* pm =
- browser()->profile()->GetExtensionProcessManager();
- EXPECT_FALSE(pm->GetBackgroundHostForExtension(last_loaded_extension_id_));
-
- // Open a tab to a URL that will fire a webNavigation event.
- LazyBackgroundObserver page_complete;
- ui_test_utils::NavigateToURL(
- browser(), test_server()->GetURL("files/extensions/test_file.html"));
- page_complete.Wait();
-}
-
// Tests that the lazy background page receives the onInstalled event and shuts
// down.
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) {
diff --git a/chrome/browser/extensions/system/system_api.cc b/chrome/browser/extensions/system/system_api.cc
index 042eb35..b80538f 100644
--- a/chrome/browser/extensions/system/system_api.cc
+++ b/chrome/browser/extensions/system/system_api.cc
@@ -60,7 +60,7 @@ void DispatchEvent(const std::string& event_name, const ListValue& args) {
std::string json_args;
base::JSONWriter::Write(&args, &json_args);
extension_event_router->DispatchEventToRenderers(
- event_name, json_args, NULL, GURL(), extensions::EventFilteringInfo());
+ event_name, json_args, NULL, GURL());
}
} // namespace