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