Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h |
diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h |
index f9aa4e058313d306bd499f82d71d7912451c96a3..8adf51dd3e3c326ba4c6f7b32e6a7858b6cd5df0 100644 |
--- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h |
+++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h |
@@ -11,6 +11,7 @@ |
#include "base/basictypes.h" |
#include "base/memory/linked_ptr.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/scoped_vector.h" |
#include "chrome/browser/extensions/api/declarative_webrequest/request_stage.h" |
#include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rule.h" |
#include "chrome/common/extensions/api/events.h" |
@@ -32,7 +33,8 @@ class WebRequestConditionAttribute { |
public: |
enum Type { |
CONDITION_RESOURCE_TYPE, |
- CONDITION_CONTENT_TYPE |
+ CONDITION_CONTENT_TYPE, |
+ CONDITION_REQUEST_HEADERS |
}; |
WebRequestConditionAttribute(); |
@@ -53,7 +55,8 @@ class WebRequestConditionAttribute { |
virtual int GetStages() const = 0; |
// Returns whether the condition is fulfilled for this request. |
- virtual bool IsFulfilled(const WebRequestRule::RequestData& request_data) = 0; |
+ virtual bool IsFulfilled( |
+ const WebRequestRule::RequestData& request_data) const = 0; |
virtual Type GetType() const = 0; |
@@ -88,8 +91,8 @@ class WebRequestConditionAttributeResourceType |
// Implementation of WebRequestConditionAttribute: |
virtual int GetStages() const OVERRIDE; |
- virtual bool IsFulfilled(const WebRequestRule::RequestData& request_data) |
- OVERRIDE; |
+ virtual bool IsFulfilled( |
+ const WebRequestRule::RequestData& request_data) const OVERRIDE; |
virtual Type GetType() const OVERRIDE; |
private: |
@@ -118,8 +121,8 @@ class WebRequestConditionAttributeContentType |
// Implementation of WebRequestConditionAttribute: |
virtual int GetStages() const OVERRIDE; |
- virtual bool IsFulfilled(const WebRequestRule::RequestData& request_data) |
- OVERRIDE; |
+ virtual bool IsFulfilled( |
+ const WebRequestRule::RequestData& request_data) const OVERRIDE; |
virtual Type GetType() const OVERRIDE; |
private: |
@@ -133,6 +136,85 @@ class WebRequestConditionAttributeContentType |
DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContentType); |
}; |
+// Condition that performs matches against response headers' names and values. |
+// In the comments below there is a distinction between when this condition is |
+// "satisfied" and when it is "fulfilled". See the comments at |tests_| for |
+// "satisfied" and the comment at |positive_test_| for "fulfilled". |
+class WebRequestConditionAttributeResponseHeaders |
+ : public WebRequestConditionAttribute { |
+ public: |
+ virtual ~WebRequestConditionAttributeResponseHeaders(); |
+ |
+ static bool IsMatchingType(const std::string& instance_type); |
+ |
+ // Factory method, see WebRequestConditionAttribute::Create. |
+ static scoped_ptr<WebRequestConditionAttribute> Create( |
+ const std::string& name, |
+ const base::Value* value, |
+ std::string* error); |
+ |
+ // Implementation of WebRequestConditionAttribute: |
+ virtual int GetStages() const OVERRIDE; |
+ virtual bool IsFulfilled( |
+ const WebRequestRule::RequestData& request_data) const OVERRIDE; |
+ virtual Type GetType() const OVERRIDE; |
+ |
+ private: |
+ enum MatchType { kPrefix, kSuffix, kEquals, kContains }; |
+ |
+ class MatchTest { |
battre
2012/08/27 17:16:25
opt: StringMatchTest?
vabr (Chromium)
2012/08/28 17:59:09
Done.
|
+ public: |
+ MatchTest(const std::string& data, MatchType type); |
+ ~MatchTest(); |
+ |
+ // Does |str| pass |*this| MatchTest? |
+ bool Matches(const std::string& str) const; |
battre
2012/08/27 17:16:25
nit: newline before private: (also below)
vabr (Chromium)
2012/08/28 17:59:09
Done.
|
+ private: |
+ const std::string data_; |
+ const MatchType type_; |
+ DISALLOW_COPY_AND_ASSIGN(MatchTest); |
+ }; |
+ |
+ class TestGroup { |
battre
2012/08/27 17:16:25
opt: HeaderMatchTest?
vabr (Chromium)
2012/08/28 17:59:09
Done.
|
+ public: |
+ // Takes ownership of both |name| and |value|. |
battre
2012/08/27 17:16:25
actually this should be "Takes ownership of the co
vabr (Chromium)
2012/08/28 17:59:09
Done.
|
+ TestGroup(ScopedVector<const MatchTest>* name, |
+ ScopedVector<const MatchTest>* value); |
+ ~TestGroup(); |
+ // Does the header |name|: |value| match all tests in this test group? |
+ bool Matches(const std::string& name, const std::string& value) const; |
+ private: |
+ // Tests to be passed by a header's name. |
+ const ScopedVector<const MatchTest> name_; |
+ // Tests to be passed by a header's value. |
+ const ScopedVector<const MatchTest> value_; |
+ DISALLOW_COPY_AND_ASSIGN(TestGroup); |
+ }; |
+ |
+ WebRequestConditionAttributeResponseHeaders( |
+ bool positive_test, ScopedVector<const TestGroup>* tests); |
+ |
+ // Gets the tests' description in |tests| and creates the corresponding |
+ // TestGroup. Returns NULL on failure. |
+ static scoped_ptr<const TestGroup> CreateTests( |
+ const base::DictionaryValue* tests, |
+ std::string* error); |
+ // Helper to CreateTests. Never returns NULL, except for memory failures. |
+ static scoped_ptr<const MatchTest> CreateMatchTest(const Value* content, |
+ bool is_name_test, |
+ MatchType match_type); |
+ |
+ // The condition is satisfied if there is a header and its value such that for |
+ // some |i| the header passes all the tests from |tests_[i]|. |
+ ScopedVector<const TestGroup> tests_; |
+ |
+ // True means that IsFulfilled() reports whether the condition is satisfied. |
+ // False means that it reports whether the condition is NOT satisfied. |
+ bool positive_test_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders); |
+}; |
+ |
} // namespace extensions |
#endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITION_ATTRIBUTE_H_ |