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

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

Issue 10874029: Adding condition attributes for response headers to Declarative WebRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup Created 8 years, 4 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
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..042c0c5952759096e3b3f266d9f4b99bcb65c646 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,86 @@ 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 {
+ public:
+ // Takes ownership of |data|, which must not be NULL.
+ MatchTest(scoped_ptr<const std::string> data, MatchType type);
battre 2012/08/24 16:24:41 Please pass |data| just as a const ref. The cost t
vabr (Chromium) 2012/08/27 12:11:50 Done. To document this decision: pros of the scope
+ ~MatchTest();
+ const std::string& data() const {
+ return *(data_.get());
+ }
+ // Does |str| pass |*this| MatchTest?
+ bool Matches(const std::string& str) const;
+ private:
+ const scoped_ptr<const std::string> data_;
+ const MatchType type_;
+ DISALLOW_COPY_AND_ASSIGN(MatchTest);
+ };
+
+ class TestGroup {
+ public:
+ TestGroup(ScopedVector<const MatchTest>* name,
battre 2012/08/24 16:24:41 Please add comment, that ownership is taken over.
vabr (Chromium) 2012/08/27 12:11:50 Done.
+ 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);
+ };
+
+ explicit WebRequestConditionAttributeResponseHeaders(bool positive_test);
+
+ // Gets the tests' description in |tests| and creates the corresponding
+ // TestGroup. Returns NULL on failure.
+ static scoped_ptr<const TestGroup> GetTests(
battre 2012/08/24 16:24:41 nit: s/Get/Create/?
vabr (Chromium) 2012/08/27 12:11:50 Done.
+ const base::DictionaryValue* tests,
+ std::string* error);
+ // Helper to GetTests. Never returns NULL, except for memory failures.
+ static scoped_ptr<const MatchTest> GetMatchTest(const Value* content,
+ bool is_name_test,
+ MatchType match_type);
battre 2012/08/24 16:24:41 nit: s/Get/Create/ (also in line 203)
vabr (Chromium) 2012/08/27 12:11:50 Done.
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698