Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / declarative_content / content_predicate.h
blob0f1c8172fa11a7e787f117f556846f595eced9ec
1 // Copyright 2015 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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_PREDICATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_PREDICATE_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
13 namespace base {
14 class Value;
17 namespace extensions {
19 class ContentPredicateEvaluator;
20 class Extension;
22 // Represents a predicate that is part of a declarative rule condition in the
23 // Declarative Content API. This is created and can be evaluated by its
24 // associated ContentPredicateEvaluator subclass.
26 // For example, given the sample code at
27 // https://developer.chrome.com/extensions/declarativeContent#rules, the
28 // entities { hostEquals: 'www.google.com', schemes: ['https'] } and
29 // ["input[type='password']"] are both represented by ContentPredicate
30 // subclasses.
31 class ContentPredicate {
32 public:
33 virtual ~ContentPredicate();
35 // Returns true if this predicate should be ignored during evaluation. By
36 // default predicates are not ignored.
37 virtual bool IsIgnored() const;
39 // Returns the evaluator associated with this predicate.
40 virtual ContentPredicateEvaluator* GetEvaluator() const = 0;
42 protected:
43 ContentPredicate();
45 private:
46 DISALLOW_COPY_AND_ASSIGN(ContentPredicate);
49 // Defines the interface for objects that create predicates.
51 // Given the sample code at
52 // https://developer.chrome.com/extensions/declarativeContent#rules,
53 // ContentPredicateFactories are directly responsible for creating individual
54 // predicates from the { hostEquals: 'www.google.com', schemes: ['https'] } and
55 // ["input[type='password']"] JSON entities encoded in |value|.
56 class ContentPredicateFactory {
57 public:
58 virtual ~ContentPredicateFactory();
60 // Creates a new predicate from |value|, as specified in the declarative
61 // API. Sets *|error| and returns null if creation failed for any reason.
62 virtual scoped_ptr<const ContentPredicate> CreatePredicate(
63 const Extension* extension,
64 const base::Value& value,
65 std::string* error) = 0;
67 protected:
68 ContentPredicateFactory();
70 private:
71 DISALLOW_COPY_AND_ASSIGN(ContentPredicateFactory);
74 } // namespace extensions
76 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CONTENT_PREDICATE_H_