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

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

Issue 17419004: <webview>: Add support for filtering extension events by instanceId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@filter_listener
Patch Set: Updated Created 7 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') | no next file » | 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 "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);
51 return instance_id;
52 }
53
47 } // namespace extensions 54 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/event_matcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698