Chromium Code Reviews| 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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace extensions { | 27 namespace extensions { |
| 28 | 28 |
| 29 // Base class for all condition attributes of the declarative Web Request API | 29 // Base class for all condition attributes of the declarative Web Request API |
| 30 // except for condition attribute to test URLPatterns. | 30 // except for condition attribute to test URLPatterns. |
| 31 class WebRequestConditionAttribute { | 31 class WebRequestConditionAttribute { |
| 32 public: | 32 public: |
| 33 enum Type { | 33 enum Type { |
| 34 CONDITION_RESOURCE_TYPE, | 34 CONDITION_RESOURCE_TYPE, |
| 35 CONDITION_CONTENT_TYPE | 35 CONDITION_CONTENT_TYPE, |
| 36 CONDITION_CONTAINS_HEADERS | |
|
battre
2012/08/23 12:32:11
We need support for request and response headers.
vabr (Chromium)
2012/08/24 14:48:59
Done. I don't think a condition attribute for requ
| |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 WebRequestConditionAttribute(); | 39 WebRequestConditionAttribute(); |
| 39 virtual ~WebRequestConditionAttribute(); | 40 virtual ~WebRequestConditionAttribute(); |
| 40 | 41 |
| 41 // Factory method that creates a WebRequestConditionAttribute for the JSON | 42 // Factory method that creates a WebRequestConditionAttribute for the JSON |
| 42 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and | 43 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and |
| 43 // returns NULL if something fails. | 44 // returns NULL if something fails. |
| 44 // The ownership of |value| remains at the caller. | 45 // The ownership of |value| remains at the caller. |
| 45 static scoped_ptr<WebRequestConditionAttribute> Create( | 46 static scoped_ptr<WebRequestConditionAttribute> Create( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 explicit WebRequestConditionAttributeContentType( | 127 explicit WebRequestConditionAttributeContentType( |
| 127 const std::vector<std::string>& include_content_types, | 128 const std::vector<std::string>& include_content_types, |
| 128 bool inclusive); | 129 bool inclusive); |
| 129 | 130 |
| 130 std::vector<std::string> content_types_; | 131 std::vector<std::string> content_types_; |
| 131 bool inclusive_; | 132 bool inclusive_; |
| 132 | 133 |
| 133 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContentType); | 134 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContentType); |
| 134 }; | 135 }; |
| 135 | 136 |
| 137 // Condition that performs matches against response headers' names and values. | |
| 138 // In the comments below there is a distinction between when this condition is | |
| 139 // "satisfied" and when it is "fulfilled". See the comments at PushMatchTests | |
| 140 // and |tests_| for "satisfied" and the comment at |positive_test_| for | |
| 141 // "fulfilled". | |
| 142 class WebRequestConditionAttributeContainsHeaders | |
|
battre
2012/08/23 12:32:11
I would suggest to rename this to WebRequestCondit
vabr (Chromium)
2012/08/24 14:48:59
Done.
| |
| 143 : public WebRequestConditionAttribute { | |
| 144 public: | |
| 145 virtual ~WebRequestConditionAttributeContainsHeaders(); | |
| 146 | |
| 147 static bool IsMatchingType(const std::string& instance_type); | |
| 148 | |
| 149 // Factory method, see WebRequestConditionAttribute::Create. | |
| 150 static scoped_ptr<WebRequestConditionAttribute> Create( | |
| 151 const std::string& name, | |
| 152 const base::Value* value, | |
| 153 std::string* error); | |
| 154 | |
| 155 // Implementation of WebRequestConditionAttribute: | |
| 156 virtual int GetStages() const OVERRIDE; | |
| 157 virtual bool IsFulfilled(const WebRequestRule::RequestData& request_data) | |
| 158 OVERRIDE; | |
| 159 virtual Type GetType() const OVERRIDE; | |
| 160 | |
| 161 private: | |
| 162 enum MatchType { kPrefix, kSuffix, kEqual, kContains }; | |
|
battre
2012/08/23 12:32:11
kEquals to match the parameter of the attribute
vabr (Chromium)
2012/08/24 14:48:59
Done.
| |
| 163 class MatchTest { | |
| 164 public: | |
| 165 explicit MatchTest(MatchType type) : type_(type) {} | |
| 166 std::string& data() { | |
| 167 return data_; | |
|
battre
2012/08/23 12:32:11
I'd prefer if you moved this to the constructor, e
vabr (Chromium)
2012/08/24 14:48:59
Done. And retaining the number of copy operations
| |
| 168 } | |
| 169 // Does |str| pass |*this| MatchTest? | |
| 170 bool Matches(const std::string& str); | |
|
battre
2012/08/23 12:32:11
nit: const
vabr (Chromium)
2012/08/24 14:48:59
Done.
| |
| 171 private: | |
| 172 std::string data_; | |
| 173 MatchType type_; | |
|
battre
2012/08/23 12:32:11
nit: DISALLOW_COPY_AND_ASSIGN due to non-trivial d
vabr (Chromium)
2012/08/24 14:48:59
Done.
| |
| 174 }; | |
| 175 struct TestGroup { | |
| 176 TestGroup(); | |
| 177 ~TestGroup(); | |
| 178 // Tests to be passed by a header's name. | |
| 179 std::vector<MatchTest> name; | |
|
battre
2012/08/23 12:32:11
This should become a ScopedVector if you add the D
vabr (Chromium)
2012/08/24 14:48:59
Done.
| |
| 180 // Tests to be passed by a header's value. | |
| 181 std::vector<MatchTest> value; | |
|
battre
2012/08/23 12:32:11
nit: DISALLOW_COPY_AND_ASSIGN due to non-trivial d
vabr (Chromium)
2012/08/24 14:48:59
Done.
| |
| 182 }; | |
| 183 | |
| 184 explicit WebRequestConditionAttributeContainsHeaders(bool positive_test); | |
| 185 | |
| 186 // Pushes another group of tests on our tests stack |tests_|. The whole | |
| 187 // condition is satisfied if there is a group of tests pushed by some call to | |
| 188 // PushMatchTests, and a header with a value which satisfies all of the tests | |
| 189 // from that group. | |
| 190 bool PushMatchTests(const base::DictionaryValue* tests, std::string* error); | |
|
battre
2012/08/23 12:32:11
How about s/Push/Append/ to match the ListValue no
vabr (Chromium)
2012/08/24 14:48:59
I ended up with GetTests and GetMatchTest, because
| |
| 191 // Helper to PushMatchTests. | |
| 192 void PushOneMatchTest( | |
| 193 const Value* content, bool is_name_test, MatchType match_type); | |
| 194 | |
| 195 // The condition is satisfied if there is a header and its value such that for | |
| 196 // some |i| the header passes all the tests from |tests_[i]|. | |
| 197 std::vector< TestGroup > tests_; | |
|
battre
2012/08/23 12:32:11
nit: no spaces
battre
2012/08/23 12:32:11
This should become a ScopedVector if you add the D
vabr (Chromium)
2012/08/24 14:48:59
Done.
vabr (Chromium)
2012/08/24 14:48:59
Done.
| |
| 198 | |
| 199 // True means that IsFulfilled() reports whether the condition is satisfied. | |
| 200 // False means that it reports whether the condition is NOT satisfied. | |
| 201 bool positive_test_; | |
| 202 | |
| 203 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContainsHeaders); | |
| 204 }; | |
| 205 | |
| 136 } // namespace extensions | 206 } // namespace extensions |
| 137 | 207 |
| 138 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_ | 208 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_ |
| OLD | NEW |