url_matcher_factory.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2013 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 COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_
  5. #define COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/values.h"
  9. #include "components/url_matcher/url_matcher.h"
  10. #include "components/url_matcher/url_matcher_export.h"
  11. namespace url_matcher {
  12. class URL_MATCHER_EXPORT URLMatcherFactory {
  13. public:
  14. URLMatcherFactory() = delete;
  15. URLMatcherFactory(const URLMatcherFactory&) = delete;
  16. URLMatcherFactory& operator=(const URLMatcherFactory&) = delete;
  17. // Creates a URLMatcherConditionSet from a UrlFilter dictionary as defined in
  18. // the declarative API. |url_fetcher_dict| contains the dictionary passed
  19. // by the extension, |id| is the identifier assigned to the created
  20. // URLMatcherConditionSet. In case of an error, |error| is set to contain
  21. // an error message.
  22. //
  23. // Note: In case this function fails or if you don't register the
  24. // URLMatcherConditionSet to the URLMatcher, you need to call
  25. // URLMatcher::ClearUnusedConditionSets() on the URLMatcher that owns this
  26. // URLMatcherFactory. Otherwise you leak memory.
  27. static scoped_refptr<URLMatcherConditionSet> CreateFromURLFilterDictionary(
  28. URLMatcherConditionFactory* url_matcher_condition_factory,
  29. const base::Value::Dict& url_filter_dict,
  30. base::MatcherStringPattern::ID id,
  31. std::string* error);
  32. private:
  33. // Returns whether a condition attribute with name |condition_attribute_name|
  34. // needs to be handled by the URLMatcher.
  35. static bool IsURLMatcherConditionAttribute(
  36. const std::string& condition_attribute_name);
  37. // Factory method of for URLMatcherConditions.
  38. static URLMatcherCondition CreateURLMatcherCondition(
  39. URLMatcherConditionFactory* url_matcher_condition_factory,
  40. const std::string& condition_attribute_name,
  41. const base::Value* value,
  42. std::string* error);
  43. static std::unique_ptr<URLMatcherSchemeFilter> CreateURLMatcherScheme(
  44. const base::Value* value,
  45. std::string* error);
  46. static std::unique_ptr<URLMatcherPortFilter> CreateURLMatcherPorts(
  47. const base::Value* value,
  48. std::string* error);
  49. };
  50. } // namespace url_matcher
  51. #endif // COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_