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 "base/callback.h" | |
6 | |
5 #include "extensions/common/event_matcher.h" | 7 #include "extensions/common/event_matcher.h" |
6 | 8 |
7 #include "extensions/common/event_filtering_info.h" | 9 #include "extensions/common/event_filtering_info.h" |
8 | 10 |
9 namespace { | 11 namespace { |
10 const char kUrlFiltersKey[] = "url"; | 12 const char kUrlFiltersKey[] = "url"; |
13 const char kWindowTypesKey[] = "windowTypes"; | |
14 | |
15 const char* const kDefaultWindowTypes[] = {"normal", "panel", "popup"}; | |
11 } | 16 } |
12 | 17 |
13 namespace extensions { | 18 namespace extensions { |
14 | 19 |
15 const char kEventFilterServiceTypeKey[] = "serviceType"; | 20 const char kEventFilterServiceTypeKey[] = "serviceType"; |
16 | 21 |
17 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter, | 22 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter, |
18 int routing_id) | 23 int routing_id) |
19 : filter_(filter.Pass()), | 24 : filter_(filter.Pass()), |
20 routing_id_(routing_id) { | 25 routing_id_(routing_id) { |
21 } | 26 } |
22 | 27 |
23 EventMatcher::~EventMatcher() { | 28 EventMatcher::~EventMatcher() { |
24 } | 29 } |
25 | 30 |
26 bool EventMatcher::MatchNonURLCriteria( | 31 bool EventMatcher::MatchNonURLCriteria( |
27 const EventFilteringInfo& event_info) const { | 32 const EventFilteringInfo& event_info) const { |
28 if (event_info.has_instance_id()) { | 33 if (event_info.has_instance_id()) { |
29 return event_info.instance_id() == GetInstanceID(); | 34 return event_info.instance_id() == GetInstanceID(); |
30 } | 35 } |
31 | 36 |
37 if (event_info.has_window_type()) { | |
38 for (int i = 0; i < GetWindowTypeCount(); i++) { | |
39 std::string window_type; | |
40 if (GetWindowType(i, &window_type) && | |
41 window_type == event_info.window_type()) | |
42 return true; | |
43 } | |
44 return false; | |
45 } | |
46 | |
32 const std::string& service_type_filter = GetServiceTypeFilter(); | 47 const std::string& service_type_filter = GetServiceTypeFilter(); |
33 return service_type_filter.empty() || | 48 return service_type_filter.empty() || |
34 service_type_filter == event_info.service_type(); | 49 service_type_filter == event_info.service_type(); |
35 } | 50 } |
36 | 51 |
37 int EventMatcher::GetURLFilterCount() const { | 52 int EventMatcher::GetURLFilterCount() const { |
38 base::ListValue* url_filters = NULL; | 53 base::ListValue* url_filters = NULL; |
39 if (filter_->GetList(kUrlFiltersKey, &url_filters)) | 54 if (filter_->GetList(kUrlFiltersKey, &url_filters)) |
40 return url_filters->GetSize(); | 55 return url_filters->GetSize(); |
41 return 0; | 56 return 0; |
(...skipping 16 matching lines...) Expand all Loading... | |
58 filter_->GetStringASCII(kEventFilterServiceTypeKey, &service_type_filter); | 73 filter_->GetStringASCII(kEventFilterServiceTypeKey, &service_type_filter); |
59 return service_type_filter; | 74 return service_type_filter; |
60 } | 75 } |
61 | 76 |
62 int EventMatcher::GetInstanceID() const { | 77 int EventMatcher::GetInstanceID() const { |
63 int instance_id = 0; | 78 int instance_id = 0; |
64 filter_->GetInteger("instanceId", &instance_id); | 79 filter_->GetInteger("instanceId", &instance_id); |
65 return instance_id; | 80 return instance_id; |
66 } | 81 } |
67 | 82 |
83 int EventMatcher::GetWindowTypeCount() const { | |
84 base::ListValue* window_type_filters = NULL; | |
not at google - send to devlin
2015/07/31 21:48:03
NULL --> nullptr
llandwerlin-old
2015/08/03 10:11:54
Done.
| |
85 if (filter_->GetList(kWindowTypesKey, &window_type_filters)) | |
86 return window_type_filters->GetSize(); | |
87 return arraysize(kDefaultWindowTypes); | |
88 } | |
89 | |
90 bool EventMatcher::GetWindowType(int i, std::string* window_type_out) const { | |
91 base::ListValue* window_types = NULL; | |
92 if (filter_->GetList(kWindowTypesKey, &window_types)) { | |
93 return window_types->GetString(i, window_type_out); | |
94 } else if (i >= 0 && i < static_cast<int>(arraysize(kDefaultWindowTypes))) { | |
not at google - send to devlin
2015/07/31 21:48:03
In this case I think it's clearer if you don't put
llandwerlin-old
2015/08/03 10:11:54
Done, fyi arraysize is defined using sizeof which
| |
95 *window_type_out = kDefaultWindowTypes[i]; | |
96 return true; | |
97 } | |
98 return false; | |
99 } | |
100 | |
68 int EventMatcher::GetRoutingID() const { | 101 int EventMatcher::GetRoutingID() const { |
69 return routing_id_; | 102 return routing_id_; |
70 } | 103 } |
71 | 104 |
72 } // namespace extensions | 105 } // namespace extensions |
OLD | NEW |