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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition_attribute.h

Issue 11038031: Adding condition attributes for request headers to Declarative WebRequest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Dominic's comments addressed Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 18 matching lines...) Expand all
29 29
30 class HeaderMatcher; 30 class HeaderMatcher;
31 31
32 // Base class for all condition attributes of the declarative Web Request API 32 // Base class for all condition attributes of the declarative Web Request API
33 // except for condition attribute to test URLPatterns. 33 // except for condition attribute to test URLPatterns.
34 class WebRequestConditionAttribute { 34 class WebRequestConditionAttribute {
35 public: 35 public:
36 enum Type { 36 enum Type {
37 CONDITION_RESOURCE_TYPE, 37 CONDITION_RESOURCE_TYPE,
38 CONDITION_CONTENT_TYPE, 38 CONDITION_CONTENT_TYPE,
39 CONDITION_REQUEST_HEADERS,
39 CONDITION_RESPONSE_HEADERS 40 CONDITION_RESPONSE_HEADERS
40 }; 41 };
41 42
42 WebRequestConditionAttribute(); 43 WebRequestConditionAttribute();
43 virtual ~WebRequestConditionAttribute(); 44 virtual ~WebRequestConditionAttribute();
44 45
45 // Factory method that creates a WebRequestConditionAttribute for the JSON 46 // Factory method that creates a WebRequestConditionAttribute for the JSON
46 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and 47 // dictionary {|name|: |value|} passed by the extension API. Sets |error| and
47 // returns NULL if something fails. 48 // returns NULL if something fails.
48 // The ownership of |value| remains at the caller. 49 // The ownership of |value| remains at the caller.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 explicit WebRequestConditionAttributeContentType( 132 explicit WebRequestConditionAttributeContentType(
132 const std::vector<std::string>& include_content_types, 133 const std::vector<std::string>& include_content_types,
133 bool inclusive); 134 bool inclusive);
134 135
135 std::vector<std::string> content_types_; 136 std::vector<std::string> content_types_;
136 bool inclusive_; 137 bool inclusive_;
137 138
138 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContentType); 139 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeContentType);
139 }; 140 };
140 141
142 // Condition attribute for matching against request headers. Uses HeaderMatcher
143 // to handle the actual tests, in connection with a boolean positiveness
144 // flag. If that flag is set to true, then IsFulfilled() returns true iff
145 // |header_matcher_| matches at least one header. Otherwise IsFulfilled()
146 // returns true iff the |header_matcher_| matches no header.
147 class WebRequestConditionAttributeRequestHeaders
148 : public WebRequestConditionAttribute {
149 public:
150 virtual ~WebRequestConditionAttributeRequestHeaders();
151
152 static bool IsMatchingType(const std::string& instance_type);
153
154 // Factory method, see WebRequestConditionAttribute::Create.
155 static scoped_ptr<WebRequestConditionAttribute> Create(
156 const std::string& name,
157 const base::Value* value,
158 std::string* error);
159
160 // Implementation of WebRequestConditionAttribute:
161 virtual int GetStages() const OVERRIDE;
162 virtual bool IsFulfilled(
163 const WebRequestRule::RequestData& request_data) const OVERRIDE;
164 virtual Type GetType() const OVERRIDE;
165
166 private:
167 WebRequestConditionAttributeRequestHeaders(
168 scoped_ptr<const HeaderMatcher> header_matcher, bool positive);
169
170 const scoped_ptr<const HeaderMatcher> header_matcher_;
171 const bool positive_;
172
173 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeRequestHeaders);
174 };
175
141 // Condition attribute for matching against response headers. Uses HeaderMatcher 176 // Condition attribute for matching against response headers. Uses HeaderMatcher
142 // to handle the actual tests, in connection with a boolean positiveness 177 // to handle the actual tests, in connection with a boolean positiveness
143 // flag. If that flag is set to true, then IsFulfilled() returns true iff 178 // flag. If that flag is set to true, then IsFulfilled() returns true iff
144 // |header_matcher_| matches at least one header. Otherwise IsFulfilled() 179 // |header_matcher_| matches at least one header. Otherwise IsFulfilled()
145 // returns true iff the |header_matcher_| matches no header. 180 // returns true iff the |header_matcher_| matches no header.
146 class WebRequestConditionAttributeResponseHeaders 181 class WebRequestConditionAttributeResponseHeaders
147 : public WebRequestConditionAttribute { 182 : public WebRequestConditionAttribute {
148 public: 183 public:
149 virtual ~WebRequestConditionAttributeResponseHeaders(); 184 virtual ~WebRequestConditionAttributeResponseHeaders();
150 185
151 static bool IsMatchingType(const std::string& instance_type); 186 static bool IsMatchingType(const std::string& instance_type);
152 187
153 // Factory method, see WebRequestConditionAttribute::Create. 188 // Factory method, see WebRequestConditionAttribute::Create.
154 static scoped_ptr<WebRequestConditionAttribute> Create( 189 static scoped_ptr<WebRequestConditionAttribute> Create(
155 const std::string& name, 190 const std::string& name,
156 const base::Value* value, 191 const base::Value* value,
157 std::string* error); 192 std::string* error);
158 193
159 // Implementation of WebRequestConditionAttribute: 194 // Implementation of WebRequestConditionAttribute:
160 virtual int GetStages() const OVERRIDE; 195 virtual int GetStages() const OVERRIDE;
161 virtual bool IsFulfilled( 196 virtual bool IsFulfilled(
162 const WebRequestRule::RequestData& request_data) const OVERRIDE; 197 const WebRequestRule::RequestData& request_data) const OVERRIDE;
163 virtual Type GetType() const OVERRIDE; 198 virtual Type GetType() const OVERRIDE;
164 199
165 private: 200 private:
166 WebRequestConditionAttributeResponseHeaders( 201 WebRequestConditionAttributeResponseHeaders(
167 scoped_ptr<const HeaderMatcher>* header_matcher, bool positive); 202 scoped_ptr<const HeaderMatcher> header_matcher, bool positive);
168 203
169 const scoped_ptr<const HeaderMatcher> header_matcher_; 204 const scoped_ptr<const HeaderMatcher> header_matcher_;
170 const bool positive_; 205 const bool positive_;
171 206
172 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders); 207 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionAttributeResponseHeaders);
173 }; 208 };
174 209
175 } // namespace extensions 210 } // namespace extensions
176 211
177 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_ 212 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_ATTRIBUTE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698