OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/common/event_matcher.h" | 5 #include "extensions/common/event_matcher.h" |
6 | 6 |
7 #include "extensions/common/event_filtering_info.h" | 7 #include "extensions/common/event_filtering_info.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 const char kUrlFiltersKey[] = "url"; | 10 const char kUrlFiltersKey[] = "url"; |
11 } | 11 } |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter) | 15 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter) |
16 : filter_(filter.Pass()) { | 16 : filter_(filter.Pass()) { |
17 } | 17 } |
18 | 18 |
19 EventMatcher::~EventMatcher() { | 19 EventMatcher::~EventMatcher() { |
20 } | 20 } |
21 | 21 |
22 bool EventMatcher::MatchNonURLCriteria( | 22 bool EventMatcher::MatchNonURLCriteria( |
23 const EventFilteringInfo& event_info) const { | 23 const EventFilteringInfo& event_info) const { |
24 // There is currently no criteria apart from URL criteria. | 24 if (!event_info.has_instance_id()) |
25 return true; | 25 return true; |
26 return event_info.instance_id() == GetInstanceID(); | |
26 } | 27 } |
27 | 28 |
28 int EventMatcher::GetURLFilterCount() const { | 29 int EventMatcher::GetURLFilterCount() const { |
29 base::ListValue* url_filters = NULL; | 30 base::ListValue* url_filters = NULL; |
30 if (filter_->GetList(kUrlFiltersKey, &url_filters)) | 31 if (filter_->GetList(kUrlFiltersKey, &url_filters)) |
31 return url_filters->GetSize(); | 32 return url_filters->GetSize(); |
32 return 0; | 33 return 0; |
33 } | 34 } |
34 | 35 |
35 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) { | 36 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) { |
36 base::ListValue* url_filters = NULL; | 37 base::ListValue* url_filters = NULL; |
37 if (filter_->GetList(kUrlFiltersKey, &url_filters)) { | 38 if (filter_->GetList(kUrlFiltersKey, &url_filters)) { |
38 return url_filters->GetDictionary(i, url_filter_out); | 39 return url_filters->GetDictionary(i, url_filter_out); |
39 } | 40 } |
40 return false; | 41 return false; |
41 } | 42 } |
42 | 43 |
43 int EventMatcher::HasURLFilters() const { | 44 int EventMatcher::HasURLFilters() const { |
44 return GetURLFilterCount() != 0; | 45 return GetURLFilterCount() != 0; |
45 } | 46 } |
46 | 47 |
48 int EventMatcher::GetInstanceID() const { | |
49 int instance_id = 0; | |
50 filter_->GetInteger("instanceId", &instance_id); | |
Matt Perry
2013/06/18 23:29:02
Is 0 an invalid instanceId? (I'm wondering what wi
Fady Samuel
2013/06/19 01:15:16
Yes, 0 is an invalid instanceId. If a listener doe
| |
51 return instance_id; | |
52 } | |
53 | |
47 } // namespace extensions | 54 } // namespace extensions |
OLD | NEW |