Home | History | Annotate | Download | only in url_matcher
      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 
      5 #ifndef COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_
      6 #define COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "components/url_matcher/url_matcher.h"
     12 #include "components/url_matcher/url_matcher_export.h"
     13 
     14 namespace base {
     15 class DictionaryValue;
     16 class Value;
     17 }
     18 
     19 namespace url_matcher {
     20 
     21 class URL_MATCHER_EXPORT URLMatcherFactory {
     22  public:
     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.
     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.
     33   static scoped_refptr<URLMatcherConditionSet> CreateFromURLFilterDictionary(
     34       URLMatcherConditionFactory* url_matcher_condition_factory,
     35       const base::DictionaryValue* url_filter_dict,
     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 
     52   static scoped_ptr<URLMatcherSchemeFilter> CreateURLMatcherScheme(
     53       const base::Value* value, std::string* error);
     54 
     55   static scoped_ptr<URLMatcherPortFilter> CreateURLMatcherPorts(
     56       const base::Value* value, std::string* error);
     57 
     58   DISALLOW_IMPLICIT_CONSTRUCTORS(URLMatcherFactory);
     59 };
     60 
     61 }  // namespace url_matcher
     62 
     63 #endif  // COMPONENTS_URL_MATCHER_URL_MATCHER_FACTORY_H_
     64