event_matcher.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef EXTENSIONS_COMMON_EVENT_MATCHER_H_
  5. #define EXTENSIONS_COMMON_EVENT_MATCHER_H_
  6. #include <memory>
  7. #include "base/values.h"
  8. #include "extensions/common/mojom/event_dispatcher.mojom-forward.h"
  9. namespace extensions {
  10. extern const char kEventFilterServiceTypeKey[];
  11. // Matches EventFilteringInfos against a set of criteria. This is intended to
  12. // be used by EventFilter which performs efficient URL matching across
  13. // potentially many EventMatchers itself. This is why this class only exposes
  14. // MatchNonURLCriteria() - URL matching is handled by EventFilter.
  15. class EventMatcher {
  16. public:
  17. EventMatcher(std::unique_ptr<base::DictionaryValue> filter, int routing_id);
  18. EventMatcher(const EventMatcher&) = delete;
  19. EventMatcher& operator=(const EventMatcher&) = delete;
  20. ~EventMatcher();
  21. // Returns true if |event_info| satisfies this matcher's criteria, not taking
  22. // into consideration any URL criteria.
  23. bool MatchNonURLCriteria(const mojom::EventFilteringInfo& event_info) const;
  24. int GetURLFilterCount() const;
  25. const base::Value::Dict* GetURLFilter(int i);
  26. int GetWindowTypeCount() const;
  27. bool GetWindowType(int i, std::string* window_type_out) const;
  28. std::string GetServiceTypeFilter() const;
  29. bool HasURLFilters() const;
  30. bool HasWindowTypes() const;
  31. int GetInstanceID() const;
  32. int GetRoutingID() const;
  33. base::DictionaryValue* value() const {
  34. return filter_.get();
  35. }
  36. private:
  37. // Contains a dictionary that corresponds to a single event filter, eg:
  38. //
  39. // {url: [{hostSuffix: 'google.com'}]}
  40. //
  41. // The valid filter keys are event-specific.
  42. const std::unique_ptr<base::DictionaryValue> filter_;
  43. const int routing_id_;
  44. };
  45. } // namespace extensions
  46. #endif // EXTENSIONS_COMMON_EVENT_MATCHER_H_