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 // 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 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 namespace net { | 30 namespace net { |
31 class BoundNetLog; | 31 class BoundNetLog; |
32 class URLRequest; | 32 class URLRequest; |
33 } | 33 } |
34 | 34 |
35 namespace extension_web_request_api_helpers { | 35 namespace extension_web_request_api_helpers { |
36 | 36 |
37 typedef std::pair<std::string, std::string> ResponseHeader; | 37 typedef std::pair<std::string, std::string> ResponseHeader; |
38 typedef std::vector<ResponseHeader> ResponseHeaders; | 38 typedef std::vector<ResponseHeader> ResponseHeaders; |
39 | 39 |
| 40 // Data container for RequestCookies as defined in the declarative WebRequest |
| 41 // API definition. |
| 42 struct RequestCookie { |
| 43 RequestCookie(); |
| 44 ~RequestCookie(); |
| 45 scoped_ptr<std::string> name; |
| 46 scoped_ptr<std::string> value; |
| 47 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(RequestCookie); |
| 49 }; |
| 50 |
| 51 // Data container for ResponseCookies as defined in the declarative WebRequest |
| 52 // API definition. |
| 53 struct ResponseCookie { |
| 54 ResponseCookie(); |
| 55 ~ResponseCookie(); |
| 56 scoped_ptr<std::string> name; |
| 57 scoped_ptr<std::string> value; |
| 58 scoped_ptr<std::string> expires; |
| 59 scoped_ptr<int> max_age; |
| 60 scoped_ptr<std::string> domain; |
| 61 scoped_ptr<std::string> path; |
| 62 scoped_ptr<bool> secure; |
| 63 scoped_ptr<bool> http_only; |
| 64 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(ResponseCookie); |
| 66 }; |
| 67 |
| 68 enum CookieModificationType { |
| 69 ADD, |
| 70 EDIT, |
| 71 REMOVE, |
| 72 }; |
| 73 |
| 74 struct RequestCookieModification { |
| 75 RequestCookieModification(); |
| 76 ~RequestCookieModification(); |
| 77 CookieModificationType type; |
| 78 // Used for EDIT and REMOVE. NULL for ADD. |
| 79 scoped_ptr<RequestCookie> filter; |
| 80 // Used for ADD and EDIT. NULL for REMOVE. |
| 81 scoped_ptr<RequestCookie> modification; |
| 82 private: |
| 83 DISALLOW_COPY_AND_ASSIGN(RequestCookieModification); |
| 84 }; |
| 85 |
| 86 struct ResponseCookieModification { |
| 87 ResponseCookieModification(); |
| 88 ~ResponseCookieModification(); |
| 89 CookieModificationType type; |
| 90 // Used for EDIT and REMOVE. |
| 91 scoped_ptr<ResponseCookie> filter; |
| 92 // Used for ADD and EDIT. |
| 93 scoped_ptr<ResponseCookie> modification; |
| 94 private: |
| 95 DISALLOW_COPY_AND_ASSIGN(ResponseCookieModification); |
| 96 }; |
| 97 |
| 98 typedef std::vector<linked_ptr<RequestCookieModification> > |
| 99 RequestCookieModifications; |
| 100 typedef std::vector<linked_ptr<ResponseCookieModification> > |
| 101 ResponseCookieModifications; |
| 102 |
40 // Contains the modification an extension wants to perform on an event. | 103 // Contains the modification an extension wants to perform on an event. |
41 struct EventResponseDelta { | 104 struct EventResponseDelta { |
42 // ID of the extension that sent this response. | 105 // ID of the extension that sent this response. |
43 std::string extension_id; | 106 std::string extension_id; |
44 | 107 |
45 // The time that the extension was installed. Used for deciding order of | 108 // The time that the extension was installed. Used for deciding order of |
46 // precedence in case multiple extensions respond with conflicting | 109 // precedence in case multiple extensions respond with conflicting |
47 // decisions. | 110 // decisions. |
48 base::Time extension_install_time; | 111 base::Time extension_install_time; |
49 | 112 |
(...skipping 10 matching lines...) Expand all Loading... |
60 // Headers that were added to the response. A modification of a header | 123 // Headers that were added to the response. A modification of a header |
61 // corresponds to a deletion and subsequent addition of the new header. | 124 // corresponds to a deletion and subsequent addition of the new header. |
62 ResponseHeaders added_response_headers; | 125 ResponseHeaders added_response_headers; |
63 | 126 |
64 // Headers that were deleted from the response. | 127 // Headers that were deleted from the response. |
65 ResponseHeaders deleted_response_headers; | 128 ResponseHeaders deleted_response_headers; |
66 | 129 |
67 // Authentication Credentials to use. | 130 // Authentication Credentials to use. |
68 scoped_ptr<net::AuthCredentials> auth_credentials; | 131 scoped_ptr<net::AuthCredentials> auth_credentials; |
69 | 132 |
| 133 // Modifications to cookies in request headers. |
| 134 RequestCookieModifications request_cookie_modifications; |
| 135 |
| 136 // Modifications to cookies in response headers. |
| 137 ResponseCookieModifications response_cookie_modifications; |
| 138 |
70 EventResponseDelta(const std::string& extension_id, | 139 EventResponseDelta(const std::string& extension_id, |
71 const base::Time& extension_install_time); | 140 const base::Time& extension_install_time); |
72 ~EventResponseDelta(); | 141 ~EventResponseDelta(); |
73 | 142 |
74 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); | 143 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); |
75 }; | 144 }; |
76 | 145 |
77 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas; | 146 typedef std::list<linked_ptr<EventResponseDelta> > EventResponseDeltas; |
78 | 147 |
79 // Comparison operator that returns true if the extension that caused | 148 // Comparison operator that returns true if the extension that caused |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 bool* canceled, | 203 bool* canceled, |
135 const net::BoundNetLog* net_log); | 204 const net::BoundNetLog* net_log); |
136 // Stores in |*new_url| the redirect request of the extension with highest | 205 // Stores in |*new_url| the redirect request of the extension with highest |
137 // precedence. Extensions that did not command to redirect the request are | 206 // precedence. Extensions that did not command to redirect the request are |
138 // ignored in this logic. | 207 // ignored in this logic. |
139 void MergeOnBeforeRequestResponses( | 208 void MergeOnBeforeRequestResponses( |
140 const EventResponseDeltas& deltas, | 209 const EventResponseDeltas& deltas, |
141 GURL* new_url, | 210 GURL* new_url, |
142 std::set<std::string>* conflicting_extensions, | 211 std::set<std::string>* conflicting_extensions, |
143 const net::BoundNetLog* net_log); | 212 const net::BoundNetLog* net_log); |
| 213 // Modifies the "Cookie" header in |request_headers| according to |
| 214 // |deltas.request_cookie_modifications|. Conflicts are currently ignored |
| 215 // silently. |
| 216 void MergeCookiesInOnBeforeSendHeadersResponses( |
| 217 const EventResponseDeltas& deltas, |
| 218 net::HttpRequestHeaders* request_headers, |
| 219 std::set<std::string>* conflicting_extensions, |
| 220 const net::BoundNetLog* net_log); |
144 // Modifies the headers in |request_headers| according to |deltas|. Conflicts | 221 // Modifies the headers in |request_headers| according to |deltas|. Conflicts |
145 // are tried to be resolved. | 222 // are tried to be resolved. |
146 void MergeOnBeforeSendHeadersResponses( | 223 void MergeOnBeforeSendHeadersResponses( |
147 const EventResponseDeltas& deltas, | 224 const EventResponseDeltas& deltas, |
148 net::HttpRequestHeaders* request_headers, | 225 net::HttpRequestHeaders* request_headers, |
149 std::set<std::string>* conflicting_extensions, | 226 std::set<std::string>* conflicting_extensions, |
150 const net::BoundNetLog* net_log); | 227 const net::BoundNetLog* net_log); |
| 228 // Modifies the "Set-Cookie" headers in |override_response_headers| according to |
| 229 // |deltas.response_cookie_modifications|. If |override_response_headers| is |
| 230 // NULL, a copy of |original_response_headers| is created. Conflicts are |
| 231 // currently ignored silently. |
| 232 void MergeCookiesInOnHeadersReceivedResponses( |
| 233 const EventResponseDeltas& deltas, |
| 234 const net::HttpResponseHeaders* original_response_headers, |
| 235 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 236 std::set<std::string>* conflicting_extensions, |
| 237 const net::BoundNetLog* net_log); |
151 // Stores a copy of |original_response_header| into |override_response_headers| | 238 // Stores a copy of |original_response_header| into |override_response_headers| |
152 // that is modified according to |deltas|. If |deltas| does not instruct to | 239 // that is modified according to |deltas|. If |deltas| does not instruct to |
153 // modify the response headers, |override_response_headers| remains empty. | 240 // modify the response headers, |override_response_headers| remains empty. |
154 void MergeOnHeadersReceivedResponses( | 241 void MergeOnHeadersReceivedResponses( |
155 const EventResponseDeltas& deltas, | 242 const EventResponseDeltas& deltas, |
156 const net::HttpResponseHeaders* original_response_headers, | 243 const net::HttpResponseHeaders* original_response_headers, |
157 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 244 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
158 std::set<std::string>* conflicting_extensions, | 245 std::set<std::string>* conflicting_extensions, |
159 const net::BoundNetLog* net_log); | 246 const net::BoundNetLog* net_log); |
160 // Merge the responses of blocked onAuthRequired handlers. The first | 247 // Merge the responses of blocked onAuthRequired handlers. The first |
(...skipping 21 matching lines...) Expand all Loading... |
182 | 269 |
183 // Stores a |ResourceType::Type| representation in |type| if |type_str| is | 270 // Stores a |ResourceType::Type| representation in |type| if |type_str| is |
184 // a resource type handled by the web request API. Returns true in case of | 271 // a resource type handled by the web request API. Returns true in case of |
185 // success. | 272 // success. |
186 bool ParseResourceType(const std::string& type_str, | 273 bool ParseResourceType(const std::string& type_str, |
187 ResourceType::Type* type); | 274 ResourceType::Type* type); |
188 | 275 |
189 } // namespace extension_web_request_api_helpers | 276 } // namespace extension_web_request_api_helpers |
190 | 277 |
191 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ | 278 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ |
OLD | NEW |