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 3 // found in the LICENSE file. 4 5 #include "extensions/common/event_matcher.h" 6 7 #include "extensions/common/event_filtering_info.h" 8 9 namespace { 10 const char kUrlFiltersKey[] = "url"; 11 } 12 13 namespace extensions { 14 15 EventMatcher::EventMatcher(scoped_ptr<base::DictionaryValue> filter, 16 int routing_id) 17 : filter_(filter.Pass()), 18 routing_id_(routing_id) { 19 } 20 21 EventMatcher::~EventMatcher() { 22 } 23 24 bool EventMatcher::MatchNonURLCriteria( 25 const EventFilteringInfo& event_info) const { 26 if (!event_info.has_instance_id()) 27 return true; 28 29 return event_info.instance_id() == GetInstanceID(); 30 } 31 32 int EventMatcher::GetURLFilterCount() const { 33 base::ListValue* url_filters = NULL; 34 if (filter_->GetList(kUrlFiltersKey, &url_filters)) 35 return url_filters->GetSize(); 36 return 0; 37 } 38 39 bool EventMatcher::GetURLFilter(int i, base::DictionaryValue** url_filter_out) { 40 base::ListValue* url_filters = NULL; 41 if (filter_->GetList(kUrlFiltersKey, &url_filters)) { 42 return url_filters->GetDictionary(i, url_filter_out); 43 } 44 return false; 45 } 46 47 int EventMatcher::HasURLFilters() const { 48 return GetURLFilterCount() != 0; 49 } 50 51 int EventMatcher::GetInstanceID() const { 52 int instance_id = 0; 53 filter_->GetInteger("instanceId", &instance_id); 54 return instance_id; 55 } 56 57 int EventMatcher::GetRoutingID() const { 58 return routing_id_; 59 } 60 61 } // namespace extensions 62