Chromium Code Reviews| 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 a8ead5ada2c5085bfa26bdd3d7f5d17a56502b16..aae61004b7df00b48c7e1c4d1b279cb4a9112f26 100644 |
| --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h |
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h |
| @@ -27,6 +27,8 @@ class URLRequest; |
| namespace extensions { |
| +class TestManager; |
|
Yoyo Zhou
2012/09/01 19:44:50
This name is kind of unclear. My first impression
vabr (Chromium)
2012/09/03 07:37:05
Good point. I decided to get rid of "test" in the
|
| + |
| // Base class for all condition attributes of the declarative Web Request API |
| // except for condition attribute to test URLPatterns. |
| class WebRequestConditionAttribute { |
| @@ -136,10 +138,11 @@ 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". |
| +// Condition attribute for matching against response headers. Uses TestManager |
| +// to handle the actual tests, in connection with a boolean positiveness |
| +// flag. If that flag is set to true, then IsFulfilled() returns true iff |
| +// TestManager tests pass for at least one header. Otherwise IsFulfilled() |
| +// returns true iff no header passes the TestManager. |
| class WebRequestConditionAttributeResponseHeaders |
| : public WebRequestConditionAttribute { |
| public: |
| @@ -160,61 +163,11 @@ class WebRequestConditionAttributeResponseHeaders |
| virtual Type GetType() const OVERRIDE; |
| private: |
| - enum MatchType { kPrefix, kSuffix, kEquals, kContains }; |
| - |
| - class StringMatchTest { |
| - public: |
| - StringMatchTest(const std::string& data, MatchType type); |
| - ~StringMatchTest(); |
| - |
| - // Does |str| pass |*this| StringMatchTest? |
| - bool Matches(const std::string& str) const; |
| - |
| - private: |
| - const std::string data_; |
| - const MatchType type_; |
| - DISALLOW_COPY_AND_ASSIGN(StringMatchTest); |
| - }; |
| - |
| - class HeaderMatchTest { |
| - public: |
| - // Takes ownership of the content of both |name| and |value|. |
| - HeaderMatchTest(ScopedVector<const StringMatchTest>* name, |
| - ScopedVector<const StringMatchTest>* value); |
| - ~HeaderMatchTest(); |
| - // Does the header |name|: |value| match all tests in this header test? |
| - bool Matches(const std::string& name, const std::string& value) const; |
| - |
| - private: |
| - // Tests to be passed by a header's name. |
| - const ScopedVector<const StringMatchTest> name_; |
| - // Tests to be passed by a header's value. |
| - const ScopedVector<const StringMatchTest> value_; |
| - DISALLOW_COPY_AND_ASSIGN(HeaderMatchTest); |
| - }; |
| - |
| WebRequestConditionAttributeResponseHeaders( |
| - bool positive_test, ScopedVector<const HeaderMatchTest>* tests); |
| + scoped_ptr<const TestManager>* test_manager, bool positive); |
| - // Gets the tests' description in |tests| and creates the corresponding |
| - // HeaderMatchTest. Returns NULL on failure. |
| - static scoped_ptr<const HeaderMatchTest> CreateHeaderMatchTest( |
| - const base::DictionaryValue* tests, |
| - std::string* error); |
| - // Helper to CreateHeaderMatchTest. Never returns NULL, except for memory |
| - // failures. |
| - static scoped_ptr<const StringMatchTest> CreateStringMatchTest( |
| - 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 HeaderMatchTest> 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_; |
| + const scoped_ptr<const TestManager> test_manager_; |
| + const bool positive_; |
| DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders); |
| }; |