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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api_helpers.h

Issue 10447090: Support Cookie modifications in Declarative WebRequest API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT 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 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 // Helper classes and functions used for the WebRequest API. 5 // Helper classes and functions used for the WebRequest API.
6 6
7 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ 7 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_
8 #define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ 8 #define CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_
9 9
10 #include <list> 10 #include <list>
(...skipping 22 matching lines...) Expand all
33 namespace net { 33 namespace net {
34 class BoundNetLog; 34 class BoundNetLog;
35 class URLRequest; 35 class URLRequest;
36 } 36 }
37 37
38 namespace extension_web_request_api_helpers { 38 namespace extension_web_request_api_helpers {
39 39
40 typedef std::pair<std::string, std::string> ResponseHeader; 40 typedef std::pair<std::string, std::string> ResponseHeader;
41 typedef std::vector<ResponseHeader> ResponseHeaders; 41 typedef std::vector<ResponseHeader> ResponseHeaders;
42 42
43 // Data container for RequestCookies as defined in the declarative WebRequest
44 // API definition.
45 struct RequestCookie {
46 RequestCookie();
47 ~RequestCookie();
48 scoped_ptr<std::string> name;
49 scoped_ptr<std::string> value;
50 private:
51 DISALLOW_COPY_AND_ASSIGN(RequestCookie);
52 };
53
54 // Data container for ResponseCookies as defined in the declarative WebRequest
55 // API definition.
56 struct ResponseCookie {
57 ResponseCookie();
58 ~ResponseCookie();
59 scoped_ptr<std::string> name;
60 scoped_ptr<std::string> value;
61 scoped_ptr<std::string> expires;
62 scoped_ptr<int> max_age;
63 scoped_ptr<std::string> domain;
64 scoped_ptr<std::string> path;
65 scoped_ptr<bool> secure;
66 scoped_ptr<bool> http_only;
67 private:
68 DISALLOW_COPY_AND_ASSIGN(ResponseCookie);
69 };
70
71 enum CookieModificationType {
72 ADD,
73 EDIT,
74 REMOVE,
75 };
76
77 struct RequestCookieModification {
78 RequestCookieModification();
79 ~RequestCookieModification();
80 CookieModificationType type;
81 // Used for EDIT and REMOVE. NULL for ADD.
82 scoped_ptr<RequestCookie> filter;
83 // Used for ADD and EDIT. NULL for REMOVE.
84 scoped_ptr<RequestCookie> modification;
85 private:
86 DISALLOW_COPY_AND_ASSIGN(RequestCookieModification);
87 };
88
89 struct ResponseCookieModification {
90 ResponseCookieModification();
91 ~ResponseCookieModification();
92 CookieModificationType type;
93 // Used for EDIT and REMOVE.
94 scoped_ptr<ResponseCookie> filter;
95 // Used for ADD and EDIT.
96 scoped_ptr<ResponseCookie> modification;
97 private:
98 DISALLOW_COPY_AND_ASSIGN(ResponseCookieModification);
99 };
100
101 typedef std::vector<linked_ptr<RequestCookieModification> >
102 RequestCookieModifications;
103 typedef std::vector<linked_ptr<ResponseCookieModification> >
104 ResponseCookieModifications;
105
43 // Contains the modification an extension wants to perform on an event. 106 // Contains the modification an extension wants to perform on an event.
44 struct EventResponseDelta { 107 struct EventResponseDelta {
45 // ID of the extension that sent this response. 108 // ID of the extension that sent this response.
46 std::string extension_id; 109 std::string extension_id;
47 110
48 // The time that the extension was installed. Used for deciding order of 111 // The time that the extension was installed. Used for deciding order of
49 // precedence in case multiple extensions respond with conflicting 112 // precedence in case multiple extensions respond with conflicting
50 // decisions. 113 // decisions.
51 base::Time extension_install_time; 114 base::Time extension_install_time;
52 115
(...skipping 10 matching lines...) Expand all
63 // Headers that were added to the response. A modification of a header 126 // Headers that were added to the response. A modification of a header
64 // corresponds to a deletion and subsequent addition of the new header. 127 // corresponds to a deletion and subsequent addition of the new header.
65 ResponseHeaders added_response_headers; 128 ResponseHeaders added_response_headers;
66 129
67 // Headers that were deleted from the response. 130 // Headers that were deleted from the response.
68 ResponseHeaders deleted_response_headers; 131 ResponseHeaders deleted_response_headers;
69 132
70 // Authentication Credentials to use. 133 // Authentication Credentials to use.
71 scoped_ptr<net::AuthCredentials> auth_credentials; 134 scoped_ptr<net::AuthCredentials> auth_credentials;
72 135
136 // Modifications to cookies in request headers.
137 RequestCookieModifications request_cookie_modifications;
138
139 // Modifications to cookies in response headers.
140 ResponseCookieModifications response_cookie_modifications;
141
73 EventResponseDelta(const std::string& extension_id, 142 EventResponseDelta(const std::string& extension_id,
74 const base::Time& extension_install_time); 143 const base::Time& extension_install_time);
75 ~EventResponseDelta(); 144 ~EventResponseDelta();
76 145
77 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); 146 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta);
78 }; 147 };
79 148
80 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas; 149 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas;
81 150
82 // Comparison operator that returns true if the extension that caused 151 // Comparison operator that returns true if the extension that caused
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 bool* canceled, 206 bool* canceled,
138 const net::BoundNetLog* net_log); 207 const net::BoundNetLog* net_log);
139 // Stores in |*new_url| the redirect request of the extension with highest 208 // Stores in |*new_url| the redirect request of the extension with highest
140 // precedence. Extensions that did not command to redirect the request are 209 // precedence. Extensions that did not command to redirect the request are
141 // ignored in this logic. 210 // ignored in this logic.
142 void MergeOnBeforeRequestResponses( 211 void MergeOnBeforeRequestResponses(
143 const EventResponseDeltas& deltas, 212 const EventResponseDeltas& deltas,
144 GURL* new_url, 213 GURL* new_url,
145 std::set<std::string>* conflicting_extensions, 214 std::set<std::string>* conflicting_extensions,
146 const net::BoundNetLog* net_log); 215 const net::BoundNetLog* net_log);
216 // Modifies the "Cookie" header in |request_headers| according to
217 // |deltas.request_cookie_modifications|. Conflicts are currently ignored
218 // silently.
219 void MergeCookiesInOnBeforeSendHeadersResponses(
220 const EventResponseDeltas& deltas,
221 net::HttpRequestHeaders* request_headers,
222 std::set<std::string>* conflicting_extensions,
223 const net::BoundNetLog* net_log);
147 // Modifies the headers in |request_headers| according to |deltas|. Conflicts 224 // Modifies the headers in |request_headers| according to |deltas|. Conflicts
148 // are tried to be resolved. 225 // are tried to be resolved.
149 void MergeOnBeforeSendHeadersResponses( 226 void MergeOnBeforeSendHeadersResponses(
150 const EventResponseDeltas& deltas, 227 const EventResponseDeltas& deltas,
151 net::HttpRequestHeaders* request_headers, 228 net::HttpRequestHeaders* request_headers,
152 std::set<std::string>* conflicting_extensions, 229 std::set<std::string>* conflicting_extensions,
153 const net::BoundNetLog* net_log); 230 const net::BoundNetLog* net_log);
231 // Modifies the "Set-Cookie" headers in |override_response_headers| according to
232 // |deltas.response_cookie_modifications|. If |override_response_headers| is
233 // NULL, a copy of |original_response_headers| is created. Conflicts are
234 // currently ignored silently.
235 void MergeCookiesInOnHeadersReceivedResponses(
236 const EventResponseDeltas& deltas,
237 const net::HttpResponseHeaders* original_response_headers,
238 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
239 std::set<std::string>* conflicting_extensions,
240 const net::BoundNetLog* net_log);
154 // Stores a copy of |original_response_header| into |override_response_headers| 241 // Stores a copy of |original_response_header| into |override_response_headers|
155 // that is modified according to |deltas|. If |deltas| does not instruct to 242 // that is modified according to |deltas|. If |deltas| does not instruct to
156 // modify the response headers, |override_response_headers| remains empty. 243 // modify the response headers, |override_response_headers| remains empty.
157 void MergeOnHeadersReceivedResponses( 244 void MergeOnHeadersReceivedResponses(
158 const EventResponseDeltas& deltas, 245 const EventResponseDeltas& deltas,
159 const net::HttpResponseHeaders* original_response_headers, 246 const net::HttpResponseHeaders* original_response_headers,
160 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, 247 scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
161 std::set<std::string>* conflicting_extensions, 248 std::set<std::string>* conflicting_extensions,
162 const net::BoundNetLog* net_log); 249 const net::BoundNetLog* net_log);
163 // Merge the responses of blocked onAuthRequired handlers. The first 250 // Merge the responses of blocked onAuthRequired handlers. The first
(...skipping 24 matching lines...) Expand all
188 275
189 // Returns whether |extension| may access |url| based on host permissions. 276 // Returns whether |extension| may access |url| based on host permissions.
190 // In addition to that access is granted to about: URLs and extension URLs 277 // In addition to that access is granted to about: URLs and extension URLs
191 // that are in the scope of |extension|. 278 // that are in the scope of |extension|.
192 bool CanExtensionAccessURL(const extensions::Extension* extension, 279 bool CanExtensionAccessURL(const extensions::Extension* extension,
193 const GURL& url); 280 const GURL& url);
194 281
195 } // namespace extension_web_request_api_helpers 282 } // namespace extension_web_request_api_helpers
196 283
197 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ 284 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698