- add sources.
[platform/framework/web/crosswalk.git] / src / extensions / common / matcher / url_matcher_factory.h
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
5 #ifndef EXTENSIONS_COMMON_MATCHER_URL_MATCHER_FACTORY_H_
6 #define EXTENSIONS_COMMON_MATCHER_URL_MATCHER_FACTORY_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "extensions/common/matcher/url_matcher.h"
12
13 namespace base {
14 class DictionaryValue;
15 class Value;
16 }
17
18 namespace extensions {
19
20 class URLMatcherFactory {
21  public:
22   // Creates a URLMatcherConditionSet from a UrlFilter dictionary as defined in
23   // the declarative API. |url_fetcher_dict| contains the dictionary passed
24   // by the extension, |id| is the identifier assigned to the created
25   // URLMatcherConditionSet. In case of an error, |error| is set to contain
26   // an error message.
27   //
28   // Note: In case this function fails or if you don't register the
29   // URLMatcherConditionSet to the URLMatcher, you need to call
30   // URLMatcher::ClearUnusedConditionSets() on the URLMatcher that owns this
31   // URLMatcherFactory. Otherwise you leak memory.
32   static scoped_refptr<URLMatcherConditionSet> CreateFromURLFilterDictionary(
33       URLMatcherConditionFactory* url_matcher_condition_factory,
34       const base::DictionaryValue* url_filter_dict,
35       URLMatcherConditionSet::ID id,
36       std::string* error);
37
38  private:
39   // Returns whether a condition attribute with name |condition_attribute_name|
40   // needs to be handled by the URLMatcher.
41   static bool IsURLMatcherConditionAttribute(
42       const std::string& condition_attribute_name);
43
44   // Factory method of for URLMatcherConditions.
45   static URLMatcherCondition CreateURLMatcherCondition(
46       URLMatcherConditionFactory* url_matcher_condition_factory,
47       const std::string& condition_attribute_name,
48       const base::Value* value,
49       std::string* error);
50
51   static scoped_ptr<URLMatcherSchemeFilter> CreateURLMatcherScheme(
52       const base::Value* value, std::string* error);
53
54   static scoped_ptr<URLMatcherPortFilter> CreateURLMatcherPorts(
55       const base::Value* value, std::string* error);
56
57   DISALLOW_IMPLICIT_CONSTRUCTORS(URLMatcherFactory);
58 };
59
60 }  // namespace extensions
61
62 #endif  // EXTENSIONS_COMMON_MATCHER_URL_MATCHER_FACTORY_H_