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

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

Issue 1099553002: extensions: windows: list all windows from the current profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 4 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/event_bindings.cc » ('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 "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 = nullptr;
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;
42 } 57 }
43 58
44 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) { 59 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) {
45 base::ListValue* url_filters = NULL; 60 base::ListValue* url_filters = nullptr;
46 if (filter_->GetList(kUrlFiltersKey, &url_filters)) { 61 if (filter_->GetList(kUrlFiltersKey, &url_filters)) {
47 return url_filters->GetDictionary(i, url_filter_out); 62 return url_filters->GetDictionary(i, url_filter_out);
48 } 63 }
49 return false; 64 return false;
50 } 65 }
51 66
52 int EventMatcher::HasURLFilters() const { 67 int EventMatcher::HasURLFilters() const {
53 return GetURLFilterCount() != 0; 68 return GetURLFilterCount() != 0;
54 } 69 }
55 70
56 std::string EventMatcher::GetServiceTypeFilter() const { 71 std::string EventMatcher::GetServiceTypeFilter() const {
57 std::string service_type_filter; 72 std::string service_type_filter;
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 = nullptr;
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 = nullptr;
92 if (filter_->GetList(kWindowTypesKey, &window_types)) {
93 return window_types->GetString(i, window_type_out);
94 }
95 if (i >= 0 && i < static_cast<int>(arraysize(kDefaultWindowTypes))) {
96 *window_type_out = kDefaultWindowTypes[i];
97 return true;
98 }
99 return false;
100 }
101
68 int EventMatcher::GetRoutingID() const { 102 int EventMatcher::GetRoutingID() const {
69 return routing_id_; 103 return routing_id_;
70 } 104 }
71 105
72 } // namespace extensions 106 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/event_matcher.h ('k') | extensions/renderer/event_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698