OLD | NEW |
---|---|
(Empty) | |
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 CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_ATTRIBUTE_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_ATTRIBUTE_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/memory/linked_ptr.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "tools/json_schema_compiler/any.h" | |
16 | |
17 namespace base{ | |
18 class Value; | |
19 } | |
20 | |
21 namespace net { | |
22 class URLRequest; | |
23 } | |
24 | |
25 namespace extensions { | |
26 | |
27 // Base class for all condition attributes of the declarative Web Request API | |
28 // except for condition attribute to test URLPatterns. | |
29 class WebRequestConditionAttribute { | |
30 public: | |
31 enum Type { | |
32 CONDITION_HAS_SCHEME | |
33 }; | |
34 | |
35 WebRequestConditionAttribute(); | |
36 virtual ~WebRequestConditionAttribute(); | |
37 | |
38 // Returns a bit vector representing extensions::RequestStages. The bit vector | |
39 // contains a 1 for each request stage during which the condition attribute | |
40 // can be tested. | |
41 virtual int GetStages() const = 0; | |
42 | |
43 // Returns whether the condition is fulfilled for this request. | |
44 virtual bool IsFulfilled(net::URLRequest* request) = 0; | |
45 | |
46 virtual Type type() const = 0; | |
Matt Perry
2012/03/26 20:21:20
underscore_style applies to inline methods only. S
battre
2012/03/26 20:38:10
Done.
| |
47 | |
48 // Returns whether condition attributes of type |instance_type| are known | |
49 // and can be instantiated by Create(). | |
50 static bool IsKnownType(const std::string& instance_type); | |
51 | |
52 // Factory method that creates a WebRequestConditionAttribute for the JSON | |
53 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and | |
54 // returns NULL if something fails. | |
55 // The ownership of |value| remains at the caller. | |
56 static scoped_ptr<WebRequestConditionAttribute> Create( | |
57 const std::string& name, | |
58 const base::Value* value, | |
59 std::string* error); | |
60 | |
61 private: | |
62 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute); | |
63 }; | |
64 | |
65 typedef std::vector<linked_ptr<WebRequestConditionAttribute> > | |
66 WebRequestConditionAttributes; | |
67 | |
68 // | |
69 // The following are concrete condition attributes. | |
70 // | |
71 | |
72 // Condition that checks whether a URL has a specific scheme. | |
73 // TODO(battre): Generalize this to allow checking for multiple schemes. | |
74 // TODO(battre): Alternatively, move the scheme check into the URLMatcher. | |
75 class WebRequestConditionAttributeHasScheme | |
76 : public WebRequestConditionAttribute { | |
77 public: | |
78 virtual ~WebRequestConditionAttributeHasScheme(); | |
79 | |
80 static bool IsMatchingType(const std::string& instance_type); | |
81 | |
82 // Factory method, see WebRequestConditionAttribute::Create. | |
83 static scoped_ptr<WebRequestConditionAttribute> Create( | |
84 const std::string& name, | |
85 const base::Value* value, | |
86 std::string* error); | |
87 | |
88 // Implementation of WebRequestConditionAttribute: | |
89 virtual int GetStages() const OVERRIDE; | |
90 virtual bool IsFulfilled(net::URLRequest* request) OVERRIDE; | |
91 virtual Type type() const OVERRIDE; | |
92 | |
93 private: | |
94 explicit WebRequestConditionAttributeHasScheme(const std::string& pattern); | |
95 | |
96 std::string pattern_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeHasScheme); | |
99 }; | |
100 | |
101 } // namespace extensions | |
102 | |
103 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_ | |
OLD | NEW |