diff options
author | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-10 02:31:40 +0000 |
---|---|---|
committer | fsamuel@chromium.org <fsamuel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-10 02:31:40 +0000 |
commit | a97472a4d37cd0fae0fea068fc695cd886d0e6f1 (patch) | |
tree | 8fd3a2a7182465094f3fb40e6132178024cfd20b /extensions | |
parent | 5a9e5cfdd75a2f5f994687395ce34ae5d0154e24 (diff) | |
download | chromium_src-a97472a4d37cd0fae0fea068fc695cd886d0e6f1.zip chromium_src-a97472a4d37cd0fae0fea068fc695cd886d0e6f1.tar.gz chromium_src-a97472a4d37cd0fae0fea068fc695cd886d0e6f1.tar.bz2 |
<webview>: Don't attempt to dispatch events to all app windows.
This CL associates a routingId with each event listener. This ensures that when dispatching events from the browser process, only event listeners associated with the current RenderView are fired.
BUG=166165
Test=manually by opening a two Chrome app windows in the same app with webviews
Verify that there is no error spew in either console output.
Review URL: https://chromiumcodereview.appspot.com/18858005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210725 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/common/event_filter.cc | 11 | ||||
-rw-r--r-- | extensions/common/event_filter.h | 3 | ||||
-rw-r--r-- | extensions/common/event_filter_unittest.cc | 43 | ||||
-rw-r--r-- | extensions/common/event_matcher.cc | 11 | ||||
-rw-r--r-- | extensions/common/event_matcher.h | 7 |
5 files changed, 53 insertions, 22 deletions
diff --git a/extensions/common/event_filter.cc b/extensions/common/event_filter.cc index e5d6b1d..70915b9 100644 --- a/extensions/common/event_filter.cc +++ b/extensions/common/event_filter.cc @@ -5,6 +5,7 @@ #include "extensions/common/event_filter.h" #include "extensions/common/matcher/url_matcher_factory.h" +#include "ipc/ipc_message.h" namespace extensions { @@ -126,8 +127,10 @@ std::string EventFilter::RemoveEventMatcher(MatcherID id) { } std::set<EventFilter::MatcherID> EventFilter::MatchEvent( - const std::string& event_name, const EventFilteringInfo& event_info) { + const std::string& event_name, const EventFilteringInfo& event_info, + int routing_id) { std::set<MatcherID> matchers; + EventMatcherMultiMap::iterator it = event_matchers_.find(event_name); if (it == event_matchers_.end()) return matchers; @@ -152,6 +155,12 @@ std::set<EventFilter::MatcherID> EventFilter::MatchEvent( continue; } const EventMatcher* event_matcher = matcher_entry->second->event_matcher(); + // The context that installed the event listener should be the same context + // as the one where the event listener is called. + if ((routing_id != MSG_ROUTING_NONE) && + (event_matcher->GetRoutingID() != routing_id)) { + continue; + } if (event_matcher->MatchNonURLCriteria(event_info)) { CHECK(!event_matcher->HasURLFilters() || event_info.has_url()); matchers.insert(id); diff --git a/extensions/common/event_filter.h b/extensions/common/event_filter.h index efde6035..6ef136c 100644 --- a/extensions/common/event_filter.h +++ b/extensions/common/event_filter.h @@ -44,7 +44,8 @@ class EventFilter { // event matchers that matched the event. // TODO(koz): Add a std::string* parameter for retrieving error messages. std::set<MatcherID> MatchEvent(const std::string& event_name, - const EventFilteringInfo& event_info); + const EventFilteringInfo& event_info, + int routing_id); int GetMatcherCountForEvent(const std::string& event_name); diff --git a/extensions/common/event_filter_unittest.cc b/extensions/common/event_filter_unittest.cc index 9b7f4ba..3f7f12b 100644 --- a/extensions/common/event_filter_unittest.cc +++ b/extensions/common/event_filter_unittest.cc @@ -7,6 +7,7 @@ #include "extensions/common/event_filter.h" #include "extensions/common/event_filtering_info.h" #include "extensions/common/event_matcher.h" +#include "ipc/ipc_message.h" #include "testing/gtest/include/gtest/gtest.h" namespace extensions { @@ -35,7 +36,7 @@ class EventFilterUnittest : public testing::Test { scoped_ptr<EventMatcher> AllURLs() { return scoped_ptr<EventMatcher>(new EventMatcher( - scoped_ptr<DictionaryValue>(new DictionaryValue))); + scoped_ptr<DictionaryValue>(new DictionaryValue), MSG_ROUTING_NONE)); } scoped_ptr<EventMatcher> HostSuffixMatcher(const std::string& host_suffix) { @@ -46,7 +47,8 @@ class EventFilterUnittest : public testing::Test { scoped_ptr<ListValue> url_filter_list) { scoped_ptr<DictionaryValue> filter_dict(new DictionaryValue); filter_dict->Set("url", url_filter_list.release()); - return scoped_ptr<EventMatcher>(new EventMatcher(filter_dict.Pass())); + return scoped_ptr<EventMatcher>( + new EventMatcher(filter_dict.Pass(), MSG_ROUTING_NONE)); } EventFilter event_filter_; @@ -59,7 +61,8 @@ class EventFilterUnittest : public testing::Test { TEST_F(EventFilterUnittest, NoMatchersMatchIfEmpty) { std::set<int> matches = event_filter_.MatchEvent("some-event", - empty_event_); + empty_event_, + MSG_ROUTING_NONE); ASSERT_EQ(0u, matches.size()); } @@ -71,14 +74,15 @@ TEST_F(EventFilterUnittest, DontMatchAgainstMatchersForDifferentEvents) { event_filter_.AddEventMatcher("event1", AllURLs()); std::set<int> matches = event_filter_.MatchEvent("event2", - empty_event_); + empty_event_, + MSG_ROUTING_NONE); ASSERT_EQ(0u, matches.size()); } TEST_F(EventFilterUnittest, DoMatchAgainstMatchersForSameEvent) { int id = event_filter_.AddEventMatcher("event1", AllURLs()); std::set<int> matches = event_filter_.MatchEvent("event1", - google_event_); + google_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id)); } @@ -87,7 +91,8 @@ TEST_F(EventFilterUnittest, DontMatchUnlessMatcherMatches) { EventFilteringInfo info; info.SetURL(GURL("http://www.yahoo.com")); event_filter_.AddEventMatcher("event1", HostSuffixMatcher("google.com")); - std::set<int> matches = event_filter_.MatchEvent("event1", info); + std::set<int> matches = event_filter_.MatchEvent( + "event1", info, MSG_ROUTING_NONE); ASSERT_TRUE(matches.empty()); } @@ -95,7 +100,8 @@ TEST_F(EventFilterUnittest, RemovingAnEventMatcherStopsItMatching) { int id = event_filter_.AddEventMatcher("event1", AllURLs()); event_filter_.RemoveEventMatcher(id); std::set<int> matches = event_filter_.MatchEvent("event1", - empty_event_); + empty_event_, + MSG_ROUTING_NONE); ASSERT_TRUE(matches.empty()); } @@ -103,7 +109,7 @@ TEST_F(EventFilterUnittest, MultipleEventMatches) { int id1 = event_filter_.AddEventMatcher("event1", AllURLs()); int id2 = event_filter_.AddEventMatcher("event1", AllURLs()); std::set<int> matches = event_filter_.MatchEvent("event1", - google_event_); + google_event_, MSG_ROUTING_NONE); ASSERT_EQ(2u, matches.size()); ASSERT_EQ(1u, matches.count(id1)); ASSERT_EQ(1u, matches.count(id2)); @@ -114,7 +120,8 @@ TEST_F(EventFilterUnittest, TestURLMatching) { info.SetURL(GURL("http://www.google.com")); int id = event_filter_.AddEventMatcher("event1", HostSuffixMatcher("google.com")); - std::set<int> matches = event_filter_.MatchEvent("event1", info); + std::set<int> matches = event_filter_.MatchEvent( + "event1", info, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id)); } @@ -129,19 +136,19 @@ TEST_F(EventFilterUnittest, TestMultipleURLFiltersMatchOnAny) { { std::set<int> matches = event_filter_.MatchEvent("event1", - google_event_); + google_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id)); } { std::set<int> matches = event_filter_.MatchEvent("event1", - yahoo_event_); + yahoo_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id)); } { std::set<int> matches = event_filter_.MatchEvent("event1", - random_url_event_); + random_url_event_, MSG_ROUTING_NONE); ASSERT_EQ(0u, matches.size()); } } @@ -153,7 +160,7 @@ TEST_F(EventFilterUnittest, TestStillMatchesAfterRemoval) { event_filter_.RemoveEventMatcher(id1); { std::set<int> matches = event_filter_.MatchEvent("event1", - google_event_); + google_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id2)); } @@ -165,7 +172,7 @@ TEST_F(EventFilterUnittest, TestMatchesOnlyAgainstPatternsForCorrectEvent) { { std::set<int> matches = event_filter_.MatchEvent("event1", - google_event_); + google_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id1)); } @@ -209,7 +216,7 @@ TEST_F(EventFilterUnittest, EmptyListOfURLFiltersMatchesAllURLs) { scoped_ptr<ListValue>(new ListValue))); int id = event_filter_.AddEventMatcher("event1", matcher.Pass()); std::set<int> matches = event_filter_.MatchEvent("event1", - google_event_); + google_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id)); } @@ -226,7 +233,8 @@ TEST_F(EventFilterUnittest, TEST_F(EventFilterUnittest, EmptyURLsShouldBeMatchedByEmptyURLFilters) { int id = event_filter_.AddEventMatcher("event1", AllURLs()); - std::set<int> matches = event_filter_.MatchEvent("event1", empty_url_event_); + std::set<int> matches = event_filter_.MatchEvent( + "event1", empty_url_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id)); } @@ -236,7 +244,8 @@ TEST_F(EventFilterUnittest, scoped_ptr<EventMatcher> matcher(MatcherFromURLFilterList(ValueAsList( scoped_ptr<Value>(new DictionaryValue())))); int id = event_filter_.AddEventMatcher("event1", matcher.Pass()); - std::set<int> matches = event_filter_.MatchEvent("event1", empty_url_event_); + std::set<int> matches = event_filter_.MatchEvent( + "event1", empty_url_event_, MSG_ROUTING_NONE); ASSERT_EQ(1u, matches.size()); ASSERT_EQ(1u, matches.count(id)); } diff --git a/extensions/common/event_matcher.cc b/extensions/common/event_matcher.cc index 937c783..ad76c89 100644 --- a/extensions/common/event_matcher.cc +++ b/extensions/common/event_matcher.cc @@ -12,8 +12,10 @@ const char kUrlFiltersKey[] = "url"; namespace extensions { -EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter) - : filter_(filter.Pass()) { +EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter, + int routing_id) + : filter_(filter.Pass()), + routing_id_(routing_id) { } EventMatcher::~EventMatcher() { @@ -23,6 +25,7 @@ bool EventMatcher::MatchNonURLCriteria( const EventFilteringInfo& event_info) const { if (!event_info.has_instance_id()) return true; + return event_info.instance_id() == GetInstanceID(); } @@ -51,4 +54,8 @@ int EventMatcher::GetInstanceID() const { return instance_id; } +int EventMatcher::GetRoutingID() const { + return routing_id_; +} + } // namespace extensions diff --git a/extensions/common/event_matcher.h b/extensions/common/event_matcher.h index dadb6ef..7843fce 100644 --- a/extensions/common/event_matcher.h +++ b/extensions/common/event_matcher.h @@ -18,7 +18,8 @@ class EventFilteringInfo; // MatchNonURLCriteria() - URL matching is handled by EventFilter. class EventMatcher { public: - explicit EventMatcher(scoped_ptr<base::DictionaryValue> filter); + EventMatcher(scoped_ptr<base::DictionaryValue> filter, + int routing_id); ~EventMatcher(); // Returns true if |event_info| satisfies this matcher's criteria, not taking @@ -32,6 +33,8 @@ class EventMatcher { int GetInstanceID() const; + int GetRoutingID() const; + base::DictionaryValue* value() const { return filter_.get(); } @@ -44,6 +47,8 @@ class EventMatcher { // The valid filter keys are event-specific. scoped_ptr<base::DictionaryValue> filter_; + int routing_id_; + DISALLOW_COPY_AND_ASSIGN(EventMatcher); }; |