| 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 #ifndef CHROME_COMMON_EXTENSIONS_EVENT_MATCHER_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_EVENT_MATCHER_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_EVENT_MATCHER_H_ | 6 #define CHROME_COMMON_EXTENSIONS_EVENT_MATCHER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 | 13 |
| 14 class EventFilteringInfo; | 14 class EventFilteringInfo; |
| 15 | 15 |
| 16 // Matches EventFilteringInfos against a set of criteria. This is intended to | 16 // Matches EventFilteringInfos against a set of criteria. This is intended to |
| 17 // be used by EventFilter which performs efficient URL matching across | 17 // be used by EventFilter which performs efficient URL matching across |
| 18 // potentially many EventMatchers itself. This is why this class only exposes | 18 // potentially many EventMatchers itself. This is why this class only exposes |
| 19 // MatchNonURLCriteria() - URL matching is handled by EventFilter. | 19 // MatchNonURLCriteria() - URL matching is handled by EventFilter. |
| 20 class EventMatcher { | 20 class EventMatcher { |
| 21 public: | 21 public: |
| 22 EventMatcher(); | 22 explicit EventMatcher(scoped_ptr<base::DictionaryValue> filter); |
| 23 ~EventMatcher(); | 23 ~EventMatcher(); |
| 24 | 24 |
| 25 // Returns true if |event_info| satisfies this matcher's criteria, not taking | 25 // Returns true if |event_info| satisfies this matcher's criteria, not taking |
| 26 // into consideration any URL criteria. | 26 // into consideration any URL criteria. |
| 27 bool MatchNonURLCriteria(const EventFilteringInfo& event_info) const; | 27 bool MatchNonURLCriteria(const EventFilteringInfo& event_info) const; |
| 28 | 28 |
| 29 void set_url_filters(scoped_ptr<base::ListValue> url_filters) { | 29 int GetURLFilterCount() const; |
| 30 url_filters_ = url_filters.Pass(); | 30 bool GetURLFilter(int i, base::DictionaryValue** url_filter_out); |
| 31 |
| 32 int HasURLFilters() const { |
| 33 return GetURLFilterCount() != 0; |
| 31 } | 34 } |
| 32 | 35 |
| 33 // Returns NULL if no url_filters have been specified. | 36 base::DictionaryValue* value() const { |
| 34 base::ListValue* url_filters() const { | 37 return filter_.get(); |
| 35 return url_filters_.get(); | |
| 36 } | |
| 37 | |
| 38 bool has_url_filters() const { | |
| 39 return url_filters_.get() && !url_filters_->empty(); | |
| 40 } | 38 } |
| 41 | 39 |
| 42 private: | 40 private: |
| 43 scoped_ptr<base::ListValue> url_filters_; | 41 scoped_ptr<base::DictionaryValue> filter_; |
| 44 | 42 |
| 45 DISALLOW_COPY_AND_ASSIGN(EventMatcher); | 43 DISALLOW_COPY_AND_ASSIGN(EventMatcher); |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 } // namespace extensions | 46 } // namespace extensions |
| 49 | 47 |
| 50 #endif // CHROME_COMMON_EXTENSIONS_EVENT_MATCHER_H_ | 48 #endif // CHROME_COMMON_EXTENSIONS_EVENT_MATCHER_H_ |
| OLD | NEW |