OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO
N_ATTRIBUTE_H_ | 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_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO
N_ATTRIBUTE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 class HeaderMatcher; | 30 class HeaderMatcher; |
31 | 31 |
32 // Base class for all condition attributes of the declarative Web Request API | 32 // Base class for all condition attributes of the declarative Web Request API |
33 // except for condition attribute to test URLPatterns. | 33 // except for condition attribute to test URLPatterns. |
34 class WebRequestConditionAttribute { | 34 class WebRequestConditionAttribute { |
35 public: | 35 public: |
36 enum Type { | 36 enum Type { |
37 CONDITION_RESOURCE_TYPE, | 37 CONDITION_RESOURCE_TYPE, |
38 CONDITION_CONTENT_TYPE, | 38 CONDITION_CONTENT_TYPE, |
39 CONDITION_RESPONSE_HEADERS, | 39 CONDITION_RESPONSE_HEADERS, |
40 CONDITION_THIRD_PARTY | 40 CONDITION_THIRD_PARTY, |
| 41 CONDITION_REQUEST_HEADERS |
41 }; | 42 }; |
42 | 43 |
43 WebRequestConditionAttribute(); | 44 WebRequestConditionAttribute(); |
44 virtual ~WebRequestConditionAttribute(); | 45 virtual ~WebRequestConditionAttribute(); |
45 | 46 |
46 // Factory method that creates a WebRequestConditionAttribute for the JSON | 47 // Factory method that creates a WebRequestConditionAttribute for the JSON |
47 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and | 48 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and |
48 // returns NULL if something fails. | 49 // returns NULL if something fails. |
49 // The ownership of |value| remains at the caller. | 50 // The ownership of |value| remains at the caller. |
50 static scoped_ptr<WebRequestConditionAttribute> Create( | 51 static scoped_ptr<WebRequestConditionAttribute> Create( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 explicit WebRequestConditionAttributeContentType( | 133 explicit WebRequestConditionAttributeContentType( |
133 const std::vector<std::string>& include_content_types, | 134 const std::vector<std::string>& include_content_types, |
134 bool inclusive); | 135 bool inclusive); |
135 | 136 |
136 std::vector<std::string> content_types_; | 137 std::vector<std::string> content_types_; |
137 bool inclusive_; | 138 bool inclusive_; |
138 | 139 |
139 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContentType); | 140 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContentType); |
140 }; | 141 }; |
141 | 142 |
| 143 // Condition attribute for matching against request headers. Uses HeaderMatcher |
| 144 // to handle the actual tests, in connection with a boolean positiveness |
| 145 // flag. If that flag is set to true, then IsFulfilled() returns true iff |
| 146 // |header_matcher_| matches at least one header. Otherwise IsFulfilled() |
| 147 // returns true iff the |header_matcher_| matches no header. |
| 148 class WebRequestConditionAttributeRequestHeaders |
| 149 : public WebRequestConditionAttribute { |
| 150 public: |
| 151 virtual ~WebRequestConditionAttributeRequestHeaders(); |
| 152 |
| 153 static bool IsMatchingType(const std::string& instance_type); |
| 154 |
| 155 // Factory method, see WebRequestConditionAttribute::Create. |
| 156 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 157 const std::string& name, |
| 158 const base::Value* value, |
| 159 std::string* error); |
| 160 |
| 161 // Implementation of WebRequestConditionAttribute: |
| 162 virtual int GetStages() const OVERRIDE; |
| 163 virtual bool IsFulfilled( |
| 164 const WebRequestRule::RequestData& request_data) const OVERRIDE; |
| 165 virtual Type GetType() const OVERRIDE; |
| 166 |
| 167 private: |
| 168 WebRequestConditionAttributeRequestHeaders( |
| 169 scoped_ptr<const HeaderMatcher> header_matcher, bool positive); |
| 170 |
| 171 const scoped_ptr<const HeaderMatcher> header_matcher_; |
| 172 const bool positive_; |
| 173 |
| 174 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeRequestHeaders); |
| 175 }; |
| 176 |
142 // Condition attribute for matching against response headers. Uses HeaderMatcher | 177 // Condition attribute for matching against response headers. Uses HeaderMatcher |
143 // to handle the actual tests, in connection with a boolean positiveness | 178 // to handle the actual tests, in connection with a boolean positiveness |
144 // flag. If that flag is set to true, then IsFulfilled() returns true iff | 179 // flag. If that flag is set to true, then IsFulfilled() returns true iff |
145 // |header_matcher_| matches at least one header. Otherwise IsFulfilled() | 180 // |header_matcher_| matches at least one header. Otherwise IsFulfilled() |
146 // returns true iff the |header_matcher_| matches no header. | 181 // returns true iff the |header_matcher_| matches no header. |
147 class WebRequestConditionAttributeResponseHeaders | 182 class WebRequestConditionAttributeResponseHeaders |
148 : public WebRequestConditionAttribute { | 183 : public WebRequestConditionAttribute { |
149 public: | 184 public: |
150 virtual ~WebRequestConditionAttributeResponseHeaders(); | 185 virtual ~WebRequestConditionAttributeResponseHeaders(); |
151 | 186 |
152 static bool IsMatchingType(const std::string& instance_type); | 187 static bool IsMatchingType(const std::string& instance_type); |
153 | 188 |
154 // Factory method, see WebRequestConditionAttribute::Create. | 189 // Factory method, see WebRequestConditionAttribute::Create. |
155 static scoped_ptr<WebRequestConditionAttribute> Create( | 190 static scoped_ptr<WebRequestConditionAttribute> Create( |
156 const std::string& name, | 191 const std::string& name, |
157 const base::Value* value, | 192 const base::Value* value, |
158 std::string* error); | 193 std::string* error); |
159 | 194 |
160 // Implementation of WebRequestConditionAttribute: | 195 // Implementation of WebRequestConditionAttribute: |
161 virtual int GetStages() const OVERRIDE; | 196 virtual int GetStages() const OVERRIDE; |
162 virtual bool IsFulfilled( | 197 virtual bool IsFulfilled( |
163 const WebRequestRule::RequestData& request_data) const OVERRIDE; | 198 const WebRequestRule::RequestData& request_data) const OVERRIDE; |
164 virtual Type GetType() const OVERRIDE; | 199 virtual Type GetType() const OVERRIDE; |
165 | 200 |
166 private: | 201 private: |
167 WebRequestConditionAttributeResponseHeaders( | 202 WebRequestConditionAttributeResponseHeaders( |
168 scoped_ptr<const HeaderMatcher>* header_matcher, bool positive); | 203 scoped_ptr<const HeaderMatcher> header_matcher, bool positive); |
169 | 204 |
170 const scoped_ptr<const HeaderMatcher> header_matcher_; | 205 const scoped_ptr<const HeaderMatcher> header_matcher_; |
171 const bool positive_; | 206 const bool positive_; |
172 | 207 |
173 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders); | 208 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders); |
174 }; | 209 }; |
175 | 210 |
176 // This condition tests whether the request origin is third-party. | 211 // This condition tests whether the request origin is third-party. |
177 class WebRequestConditionAttributeThirdParty | 212 class WebRequestConditionAttributeThirdParty |
178 : public WebRequestConditionAttribute { | 213 : public WebRequestConditionAttribute { |
(...skipping 18 matching lines...) Expand all Loading... |
197 explicit WebRequestConditionAttributeThirdParty(bool match_third_party); | 232 explicit WebRequestConditionAttributeThirdParty(bool match_third_party); |
198 | 233 |
199 const bool match_third_party_; | 234 const bool match_third_party_; |
200 | 235 |
201 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeThirdParty); | 236 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeThirdParty); |
202 }; | 237 }; |
203 | 238 |
204 } // namespace extensions | 239 } // namespace extensions |
205 | 240 |
206 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI
TION_ATTRIBUTE_H_ | 241 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI
TION_ATTRIBUTE_H_ |
OLD | NEW |