Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: extensions/common/event_matcher.cc

Issue 2937623002: [Extensions] Simplify EventFilteringInfo (Closed)
Patch Set: karan's Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/common/event_matcher.h ('k') | extensions/renderer/api_event_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "extensions/common/event_filtering_info.h" 10 #include "extensions/common/event_filtering_info.h"
11 11
12 namespace { 12 namespace {
13 const char kUrlFiltersKey[] = "url"; 13 const char kUrlFiltersKey[] = "url";
14 const char kWindowTypesKey[] = "windowTypes"; 14 const char kWindowTypesKey[] = "windowTypes";
15 } 15 }
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 const char kEventFilterServiceTypeKey[] = "serviceType"; 19 const char kEventFilterServiceTypeKey[] = "serviceType";
20 20
21 EventMatcher::EventMatcher(std::unique_ptr<base::DictionaryValue> filter, 21 EventMatcher::EventMatcher(std::unique_ptr<base::DictionaryValue> filter,
22 int routing_id) 22 int routing_id)
23 : filter_(std::move(filter)), routing_id_(routing_id) {} 23 : filter_(std::move(filter)), routing_id_(routing_id) {}
24 24
25 EventMatcher::~EventMatcher() { 25 EventMatcher::~EventMatcher() {
26 } 26 }
27 27
28 bool EventMatcher::MatchNonURLCriteria( 28 bool EventMatcher::MatchNonURLCriteria(
29 const EventFilteringInfo& event_info) const { 29 const EventFilteringInfo& event_info) const {
30 if (event_info.has_instance_id()) { 30 if (event_info.instance_id) {
31 return event_info.instance_id() == GetInstanceID(); 31 return *event_info.instance_id == GetInstanceID();
32 } 32 }
33 33
34 if (event_info.has_window_type()) { 34 if (event_info.window_type) {
35 int window_type_count = GetWindowTypeCount(); 35 int window_type_count = GetWindowTypeCount();
36 for (int i = 0; i < window_type_count; i++) { 36 for (int i = 0; i < window_type_count; i++) {
37 std::string window_type; 37 std::string window_type;
38 if (GetWindowType(i, &window_type) && 38 if (GetWindowType(i, &window_type) &&
39 window_type == event_info.window_type()) { 39 window_type == *event_info.window_type) {
40 return true; 40 return true;
41 } 41 }
42 } 42 }
43 return false; 43 return false;
44 } 44 }
45 45
46 if (event_info.has_window_exposed_by_default()) { 46 if (event_info.window_exposed_by_default) {
47 // An event with a |window_exposed_by_default| set is only 47 // An event with a |window_exposed_by_default| set is only
48 // relevant to the listener if no window type filter is set. 48 // relevant to the listener if no window type filter is set.
49 if (HasWindowTypes()) 49 if (HasWindowTypes())
50 return false; 50 return false;
51 return event_info.window_exposed_by_default(); 51 return *event_info.window_exposed_by_default;
52 } 52 }
53 53
54 const std::string& service_type_filter = GetServiceTypeFilter(); 54 const std::string& service_type_filter = GetServiceTypeFilter();
55 return service_type_filter.empty() || 55 return service_type_filter.empty() ||
56 service_type_filter == event_info.service_type(); 56 (event_info.service_type &&
57 service_type_filter == *event_info.service_type);
57 } 58 }
58 59
59 int EventMatcher::GetURLFilterCount() const { 60 int EventMatcher::GetURLFilterCount() const {
60 base::ListValue* url_filters = nullptr; 61 base::ListValue* url_filters = nullptr;
61 if (filter_->GetList(kUrlFiltersKey, &url_filters)) 62 if (filter_->GetList(kUrlFiltersKey, &url_filters))
62 return url_filters->GetSize(); 63 return url_filters->GetSize();
63 return 0; 64 return 0;
64 } 65 }
65 66
66 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) { 67 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 105
105 bool EventMatcher::HasWindowTypes() const { 106 bool EventMatcher::HasWindowTypes() const {
106 return GetWindowTypeCount() != 0; 107 return GetWindowTypeCount() != 0;
107 } 108 }
108 109
109 int EventMatcher::GetRoutingID() const { 110 int EventMatcher::GetRoutingID() const {
110 return routing_id_; 111 return routing_id_;
111 } 112 }
112 113
113 } // namespace extensions 114 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/event_matcher.h ('k') | extensions/renderer/api_event_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698