| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" | 15 #include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" |
| 16 #include "chrome/common/extensions/api/events.h" | 16 #include "chrome/common/extensions/api/events.h" |
| 17 #include "webkit/glue/resource_type.h" | 17 #include "webkit/glue/resource_type.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 class Value; | 20 class Value; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 class URLRequest; | 24 class URLRequest; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace extensions { | 27 namespace extensions { |
| 28 | 28 |
| 29 class HeaderMatcher; | 29 class HeaderMatcher; |
| 30 struct DeclarativeWebRequestData; | 30 struct WebRequestData; |
| 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, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 54 const base::Value* value, | 54 const base::Value* value, |
| 55 std::string* error); | 55 std::string* error); |
| 56 | 56 |
| 57 // Returns a bit vector representing extensions::RequestStage. The bit vector | 57 // Returns a bit vector representing extensions::RequestStage. The bit vector |
| 58 // contains a 1 for each request stage during which the condition attribute | 58 // contains a 1 for each request stage during which the condition attribute |
| 59 // can be tested. | 59 // can be tested. |
| 60 virtual int GetStages() const = 0; | 60 virtual int GetStages() const = 0; |
| 61 | 61 |
| 62 // Returns whether the condition is fulfilled for this request. | 62 // Returns whether the condition is fulfilled for this request. |
| 63 virtual bool IsFulfilled( | 63 virtual bool IsFulfilled( |
| 64 const DeclarativeWebRequestData& request_data) const = 0; | 64 const WebRequestData& request_data) const = 0; |
| 65 | 65 |
| 66 virtual Type GetType() const = 0; | 66 virtual Type GetType() const = 0; |
| 67 | 67 |
| 68 // Returns whether condition attributes of type |instance_type| are known | 68 // Returns whether condition attributes of type |instance_type| are known |
| 69 // and can be instantiated by Create(). | 69 // and can be instantiated by Create(). |
| 70 static bool IsKnownType(const std::string& instance_type); | 70 static bool IsKnownType(const std::string& instance_type); |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute); | 73 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttribute); |
| 74 }; | 74 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 | 90 |
| 91 // Factory method, see WebRequestConditionAttribute::Create. | 91 // Factory method, see WebRequestConditionAttribute::Create. |
| 92 static scoped_ptr<WebRequestConditionAttribute> Create( | 92 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 93 const std::string& name, | 93 const std::string& name, |
| 94 const base::Value* value, | 94 const base::Value* value, |
| 95 std::string* error); | 95 std::string* error); |
| 96 | 96 |
| 97 // Implementation of WebRequestConditionAttribute: | 97 // Implementation of WebRequestConditionAttribute: |
| 98 virtual int GetStages() const OVERRIDE; | 98 virtual int GetStages() const OVERRIDE; |
| 99 virtual bool IsFulfilled( | 99 virtual bool IsFulfilled( |
| 100 const DeclarativeWebRequestData& request_data) const OVERRIDE; | 100 const WebRequestData& request_data) const OVERRIDE; |
| 101 virtual Type GetType() const OVERRIDE; | 101 virtual Type GetType() const OVERRIDE; |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 explicit WebRequestConditionAttributeResourceType( | 104 explicit WebRequestConditionAttributeResourceType( |
| 105 const std::vector<ResourceType::Type>& types); | 105 const std::vector<ResourceType::Type>& types); |
| 106 | 106 |
| 107 std::vector<ResourceType::Type> types_; | 107 std::vector<ResourceType::Type> types_; |
| 108 | 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResourceType); | 109 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResourceType); |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // Condition that checks whether a response's Content-Type header has a | 112 // Condition that checks whether a response's Content-Type header has a |
| 113 // certain MIME media type. | 113 // certain MIME media type. |
| 114 class WebRequestConditionAttributeContentType | 114 class WebRequestConditionAttributeContentType |
| 115 : public WebRequestConditionAttribute { | 115 : public WebRequestConditionAttribute { |
| 116 public: | 116 public: |
| 117 virtual ~WebRequestConditionAttributeContentType(); | 117 virtual ~WebRequestConditionAttributeContentType(); |
| 118 | 118 |
| 119 static bool IsMatchingType(const std::string& instance_type); | 119 static bool IsMatchingType(const std::string& instance_type); |
| 120 | 120 |
| 121 // Factory method, see WebRequestConditionAttribute::Create. | 121 // Factory method, see WebRequestConditionAttribute::Create. |
| 122 static scoped_ptr<WebRequestConditionAttribute> Create( | 122 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 123 const std::string& name, | 123 const std::string& name, |
| 124 const base::Value* value, | 124 const base::Value* value, |
| 125 std::string* error); | 125 std::string* error); |
| 126 | 126 |
| 127 // Implementation of WebRequestConditionAttribute: | 127 // Implementation of WebRequestConditionAttribute: |
| 128 virtual int GetStages() const OVERRIDE; | 128 virtual int GetStages() const OVERRIDE; |
| 129 virtual bool IsFulfilled( | 129 virtual bool IsFulfilled( |
| 130 const DeclarativeWebRequestData& request_data) const OVERRIDE; | 130 const WebRequestData& request_data) const OVERRIDE; |
| 131 virtual Type GetType() const OVERRIDE; | 131 virtual Type GetType() const OVERRIDE; |
| 132 | 132 |
| 133 private: | 133 private: |
| 134 explicit WebRequestConditionAttributeContentType( | 134 explicit WebRequestConditionAttributeContentType( |
| 135 const std::vector<std::string>& include_content_types, | 135 const std::vector<std::string>& include_content_types, |
| 136 bool inclusive); | 136 bool inclusive); |
| 137 | 137 |
| 138 std::vector<std::string> content_types_; | 138 std::vector<std::string> content_types_; |
| 139 bool inclusive_; | 139 bool inclusive_; |
| 140 | 140 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 155 | 155 |
| 156 // Factory method, see WebRequestConditionAttribute::Create. | 156 // Factory method, see WebRequestConditionAttribute::Create. |
| 157 static scoped_ptr<WebRequestConditionAttribute> Create( | 157 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 158 const std::string& name, | 158 const std::string& name, |
| 159 const base::Value* value, | 159 const base::Value* value, |
| 160 std::string* error); | 160 std::string* error); |
| 161 | 161 |
| 162 // Implementation of WebRequestConditionAttribute: | 162 // Implementation of WebRequestConditionAttribute: |
| 163 virtual int GetStages() const OVERRIDE; | 163 virtual int GetStages() const OVERRIDE; |
| 164 virtual bool IsFulfilled( | 164 virtual bool IsFulfilled( |
| 165 const DeclarativeWebRequestData& request_data) const OVERRIDE; | 165 const WebRequestData& request_data) const OVERRIDE; |
| 166 virtual Type GetType() const OVERRIDE; | 166 virtual Type GetType() const OVERRIDE; |
| 167 | 167 |
| 168 private: | 168 private: |
| 169 WebRequestConditionAttributeRequestHeaders( | 169 WebRequestConditionAttributeRequestHeaders( |
| 170 scoped_ptr<const HeaderMatcher> header_matcher, bool positive); | 170 scoped_ptr<const HeaderMatcher> header_matcher, bool positive); |
| 171 | 171 |
| 172 const scoped_ptr<const HeaderMatcher> header_matcher_; | 172 const scoped_ptr<const HeaderMatcher> header_matcher_; |
| 173 const bool positive_; | 173 const bool positive_; |
| 174 | 174 |
| 175 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeRequestHeaders); | 175 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeRequestHeaders); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 189 | 189 |
| 190 // Factory method, see WebRequestConditionAttribute::Create. | 190 // Factory method, see WebRequestConditionAttribute::Create. |
| 191 static scoped_ptr<WebRequestConditionAttribute> Create( | 191 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 192 const std::string& name, | 192 const std::string& name, |
| 193 const base::Value* value, | 193 const base::Value* value, |
| 194 std::string* error); | 194 std::string* error); |
| 195 | 195 |
| 196 // Implementation of WebRequestConditionAttribute: | 196 // Implementation of WebRequestConditionAttribute: |
| 197 virtual int GetStages() const OVERRIDE; | 197 virtual int GetStages() const OVERRIDE; |
| 198 virtual bool IsFulfilled( | 198 virtual bool IsFulfilled( |
| 199 const DeclarativeWebRequestData& request_data) const OVERRIDE; | 199 const WebRequestData& request_data) const OVERRIDE; |
| 200 virtual Type GetType() const OVERRIDE; | 200 virtual Type GetType() const OVERRIDE; |
| 201 | 201 |
| 202 private: | 202 private: |
| 203 WebRequestConditionAttributeResponseHeaders( | 203 WebRequestConditionAttributeResponseHeaders( |
| 204 scoped_ptr<const HeaderMatcher> header_matcher, bool positive); | 204 scoped_ptr<const HeaderMatcher> header_matcher, bool positive); |
| 205 | 205 |
| 206 const scoped_ptr<const HeaderMatcher> header_matcher_; | 206 const scoped_ptr<const HeaderMatcher> header_matcher_; |
| 207 const bool positive_; | 207 const bool positive_; |
| 208 | 208 |
| 209 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders); | 209 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders); |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 // This condition tests whether the request origin is third-party. | 212 // This condition tests whether the request origin is third-party. |
| 213 class WebRequestConditionAttributeThirdParty | 213 class WebRequestConditionAttributeThirdParty |
| 214 : public WebRequestConditionAttribute { | 214 : public WebRequestConditionAttribute { |
| 215 public: | 215 public: |
| 216 virtual ~WebRequestConditionAttributeThirdParty(); | 216 virtual ~WebRequestConditionAttributeThirdParty(); |
| 217 | 217 |
| 218 static bool IsMatchingType(const std::string& instance_type); | 218 static bool IsMatchingType(const std::string& instance_type); |
| 219 | 219 |
| 220 // Factory method, see WebRequestConditionAttribute::Create. | 220 // Factory method, see WebRequestConditionAttribute::Create. |
| 221 static scoped_ptr<WebRequestConditionAttribute> Create( | 221 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 222 const std::string& name, | 222 const std::string& name, |
| 223 const base::Value* value, | 223 const base::Value* value, |
| 224 std::string* error); | 224 std::string* error); |
| 225 | 225 |
| 226 // Implementation of WebRequestConditionAttribute: | 226 // Implementation of WebRequestConditionAttribute: |
| 227 virtual int GetStages() const OVERRIDE; | 227 virtual int GetStages() const OVERRIDE; |
| 228 virtual bool IsFulfilled( | 228 virtual bool IsFulfilled( |
| 229 const DeclarativeWebRequestData& request_data) const OVERRIDE; | 229 const WebRequestData& request_data) const OVERRIDE; |
| 230 virtual Type GetType() const OVERRIDE; | 230 virtual Type GetType() const OVERRIDE; |
| 231 | 231 |
| 232 private: | 232 private: |
| 233 explicit WebRequestConditionAttributeThirdParty(bool match_third_party); | 233 explicit WebRequestConditionAttributeThirdParty(bool match_third_party); |
| 234 | 234 |
| 235 const bool match_third_party_; | 235 const bool match_third_party_; |
| 236 | 236 |
| 237 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeThirdParty); | 237 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeThirdParty); |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 // This condition is used as a filter for request stages. It is true exactly in | 240 // This condition is used as a filter for request stages. It is true exactly in |
| 241 // stages specified on construction. | 241 // stages specified on construction. |
| 242 class WebRequestConditionAttributeStages | 242 class WebRequestConditionAttributeStages |
| 243 : public WebRequestConditionAttribute { | 243 : public WebRequestConditionAttribute { |
| 244 public: | 244 public: |
| 245 virtual ~WebRequestConditionAttributeStages(); | 245 virtual ~WebRequestConditionAttributeStages(); |
| 246 | 246 |
| 247 static bool IsMatchingType(const std::string& instance_type); | 247 static bool IsMatchingType(const std::string& instance_type); |
| 248 | 248 |
| 249 // Factory method, see WebRequestConditionAttribute::Create. | 249 // Factory method, see WebRequestConditionAttribute::Create. |
| 250 static scoped_ptr<WebRequestConditionAttribute> Create( | 250 static scoped_ptr<WebRequestConditionAttribute> Create( |
| 251 const std::string& name, | 251 const std::string& name, |
| 252 const base::Value* value, | 252 const base::Value* value, |
| 253 std::string* error); | 253 std::string* error); |
| 254 | 254 |
| 255 // Implementation of WebRequestConditionAttribute: | 255 // Implementation of WebRequestConditionAttribute: |
| 256 virtual int GetStages() const OVERRIDE; | 256 virtual int GetStages() const OVERRIDE; |
| 257 virtual bool IsFulfilled( | 257 virtual bool IsFulfilled( |
| 258 const DeclarativeWebRequestData& request_data) const OVERRIDE; | 258 const WebRequestData& request_data) const OVERRIDE; |
| 259 virtual Type GetType() const OVERRIDE; | 259 virtual Type GetType() const OVERRIDE; |
| 260 | 260 |
| 261 private: | 261 private: |
| 262 explicit WebRequestConditionAttributeStages(int allowed_stages); | 262 explicit WebRequestConditionAttributeStages(int allowed_stages); |
| 263 | 263 |
| 264 const int allowed_stages_; // Composition of RequestStage values. | 264 const int allowed_stages_; // Composition of RequestStage values. |
| 265 | 265 |
| 266 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeStages); | 266 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeStages); |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 } // namespace extensions | 269 } // namespace extensions |
| 270 | 270 |
| 271 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI
TION_ATTRIBUTE_H_ | 271 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI
TION_ATTRIBUTE_H_ |
| OLD | NEW |