Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2889)

Unified Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h

Issue 10923002: Extracting header testing code from WebRequestConditionAttributeResponseHeaders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correction of a negated condition and more unit-tests Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..cc5d2518e12746e82ef3fda3903e03f2cf3d99cc 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 HeaderMatcher;
+
// 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 HeaderMatcher
+// to handle the actual tests, in connection with a boolean positiveness
+// flag. If that flag is set to true, then IsFulfilled() returns true iff
+// |header_matcher_| matches at least one header. Otherwise IsFulfilled()
+// returns true iff the |header_matcher_| matches no header.
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 HeaderMatcher>* header_matcher, 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 HeaderMatcher> header_matcher_;
+ const bool positive_;
DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders);
};
« no previous file with comments | « no previous file | chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698