blob: 8ae9b0d24e37831fab538da84dbc78c689263c23 [file] [log] [blame]
[email protected]716c0162013-12-13 20:36:531// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]dc1e471422012-04-18 19:54:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]716c0162013-12-13 20:36:535#ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_
6#define COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_
[email protected]dc1e471422012-04-18 19:54:317
dcheng3f767dc32016-04-25 22:54:228#include <memory>
[email protected]dc1e471422012-04-18 19:54:319#include <string>
10
Dan Sandersab2a47162022-04-27 20:12:0011#include "base/values.h"
[email protected]716c0162013-12-13 20:36:5312#include "components/url_matcher/url_matcher.h"
13#include "components/url_matcher/url_matcher_export.h"
[email protected]dc1e471422012-04-18 19:54:3114
[email protected]716c0162013-12-13 20:36:5315namespace url_matcher {
[email protected]dc1e471422012-04-18 19:54:3116
[email protected]716c0162013-12-13 20:36:5317class URL_MATCHER_EXPORT URLMatcherFactory {
[email protected]dc1e471422012-04-18 19:54:3118 public:
Peter Boström9f667c382021-10-01 20:09:3119 URLMatcherFactory() = delete;
20 URLMatcherFactory(const URLMatcherFactory&) = delete;
21 URLMatcherFactory& operator=(const URLMatcherFactory&) = delete;
22
[email protected]dc1e471422012-04-18 19:54:3123 // 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]dc948982012-05-17 01:57:1528 //
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]dc1e471422012-04-18 19:54:3133 static scoped_refptr<URLMatcherConditionSet> CreateFromURLFilterDictionary(
34 URLMatcherConditionFactory* url_matcher_condition_factory,
Dan Sandersab2a47162022-04-27 20:12:0035 const base::Value::Dict& url_filter_dict,
[email protected]dc1e471422012-04-18 19:54:3136 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
dcheng3f767dc32016-04-25 22:54:2252 static std::unique_ptr<URLMatcherSchemeFilter> CreateURLMatcherScheme(
53 const base::Value* value,
54 std::string* error);
[email protected]dc1e471422012-04-18 19:54:3155
dcheng3f767dc32016-04-25 22:54:2256 static std::unique_ptr<URLMatcherPortFilter> CreateURLMatcherPorts(
57 const base::Value* value,
58 std::string* error);
[email protected]dc1e471422012-04-18 19:54:3159};
60
[email protected]716c0162013-12-13 20:36:5361} // namespace url_matcher
[email protected]dc1e471422012-04-18 19:54:3162
[email protected]716c0162013-12-13 20:36:5363#endif // COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_