[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 5 | #ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_ |
| 6 | #define COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_ |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 7 | |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 8 | #include <memory> |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 9 | #include <string> |
| 10 | |
Dan Sanders | ab2a4716 | 2022-04-27 20:12:00 | [diff] [blame^] | 11 | #include "base/values.h" |
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 12 | #include "components/url_matcher/url_matcher.h" |
| 13 | #include "components/url_matcher/url_matcher_export.h" |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 14 | |
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 15 | namespace url_matcher { |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 16 | |
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 17 | class URL_MATCHER_EXPORT URLMatcherFactory { |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 18 | public: |
Peter Boström | 9f667c38 | 2021-10-01 20:09:31 | [diff] [blame] | 19 | URLMatcherFactory() = delete; |
| 20 | URLMatcherFactory(const URLMatcherFactory&) = delete; |
| 21 | URLMatcherFactory& operator=(const URLMatcherFactory&) = delete; |
| 22 | |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 23 | // Creates a URLMatcherConditionSet from a UrlFilter dictionary as defined in |
| 24 | // the declarative API. |url_fetcher_dict| contains the dictionary passed |
| 25 | // by the extension, |id| is the identifier assigned to the created |
| 26 | // URLMatcherConditionSet. In case of an error, |error| is set to contain |
| 27 | // an error message. |
[email protected] | dc94898 | 2012-05-17 01:57:15 | [diff] [blame] | 28 | // |
| 29 | // Note: In case this function fails or if you don't register the |
| 30 | // URLMatcherConditionSet to the URLMatcher, you need to call |
| 31 | // URLMatcher::ClearUnusedConditionSets() on the URLMatcher that owns this |
| 32 | // URLMatcherFactory. Otherwise you leak memory. |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 33 | static scoped_refptr<URLMatcherConditionSet> CreateFromURLFilterDictionary( |
| 34 | URLMatcherConditionFactory* url_matcher_condition_factory, |
Dan Sanders | ab2a4716 | 2022-04-27 20:12:00 | [diff] [blame^] | 35 | const base::Value::Dict& url_filter_dict, |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 36 | URLMatcherConditionSet::ID id, |
| 37 | std::string* error); |
| 38 | |
| 39 | private: |
| 40 | // Returns whether a condition attribute with name |condition_attribute_name| |
| 41 | // needs to be handled by the URLMatcher. |
| 42 | static bool IsURLMatcherConditionAttribute( |
| 43 | const std::string& condition_attribute_name); |
| 44 | |
| 45 | // Factory method of for URLMatcherConditions. |
| 46 | static URLMatcherCondition CreateURLMatcherCondition( |
| 47 | URLMatcherConditionFactory* url_matcher_condition_factory, |
| 48 | const std::string& condition_attribute_name, |
| 49 | const base::Value* value, |
| 50 | std::string* error); |
| 51 | |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 52 | static std::unique_ptr<URLMatcherSchemeFilter> CreateURLMatcherScheme( |
| 53 | const base::Value* value, |
| 54 | std::string* error); |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 55 | |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 56 | static std::unique_ptr<URLMatcherPortFilter> CreateURLMatcherPorts( |
| 57 | const base::Value* value, |
| 58 | std::string* error); |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 59 | }; |
| 60 | |
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 61 | } // namespace url_matcher |
[email protected] | dc1e47142 | 2012-04-18 19:54:31 | [diff] [blame] | 62 | |
[email protected] | 716c016 | 2013-12-13 20:36:53 | [diff] [blame] | 63 | #endif // COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_ |