OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSION_WEBREQUEST_API_HELPERS_H_ | 7 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_HELPERS_H_ |
8 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_HELPERS_H_ | 8 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_HELPERS_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
23 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class ListValue; | 26 class ListValue; |
27 class Value; | 27 class Value; |
28 } | 28 } |
29 | 29 |
30 namespace extension_webrequest_api_helpers { | 30 namespace extension_webrequest_api_helpers { |
31 | 31 |
| 32 typedef std::pair<std::string, std::string> ResponseHeader; |
| 33 typedef std::vector<ResponseHeader> ResponseHeaders; |
| 34 |
32 // Contains the modification an extension wants to perform on an event. | 35 // Contains the modification an extension wants to perform on an event. |
33 struct EventResponseDelta { | 36 struct EventResponseDelta { |
34 // ID of the extension that sent this response. | 37 // ID of the extension that sent this response. |
35 std::string extension_id; | 38 std::string extension_id; |
36 | 39 |
37 // The time that the extension was installed. Used for deciding order of | 40 // The time that the extension was installed. Used for deciding order of |
38 // precedence in case multiple extensions respond with conflicting | 41 // precedence in case multiple extensions respond with conflicting |
39 // decisions. | 42 // decisions. |
40 base::Time extension_install_time; | 43 base::Time extension_install_time; |
41 | 44 |
42 // Response values. These are mutually exclusive. | 45 // Response values. These are mutually exclusive. |
43 bool cancel; | 46 bool cancel; |
44 GURL new_url; | 47 GURL new_url; |
45 | 48 |
46 // Newly introduced or overridden request headers. | 49 // Newly introduced or overridden request headers. |
47 net::HttpRequestHeaders modified_request_headers; | 50 net::HttpRequestHeaders modified_request_headers; |
48 | 51 |
49 // Keys of request headers to be deleted. | 52 // Keys of request headers to be deleted. |
50 std::vector<std::string> deleted_request_headers; | 53 std::vector<std::string> deleted_request_headers; |
51 | 54 |
52 // Complete set of response headers that will replace the original ones. | 55 // Headers that were added to the response. A modification of a header |
53 scoped_refptr<net::HttpResponseHeaders> new_response_headers; | 56 // corresponds to a deletion and subsequent addition of the new header. |
| 57 ResponseHeaders added_response_headers; |
| 58 |
| 59 // Headers that were deleted from the response. |
| 60 ResponseHeaders deleted_response_headers; |
54 | 61 |
55 // Authentication Credentials to use. | 62 // Authentication Credentials to use. |
56 scoped_ptr<net::AuthCredentials> auth_credentials; | 63 scoped_ptr<net::AuthCredentials> auth_credentials; |
57 | 64 |
58 EventResponseDelta(const std::string& extension_id, | 65 EventResponseDelta(const std::string& extension_id, |
59 const base::Time& extension_install_time); | 66 const base::Time& extension_install_time); |
60 ~EventResponseDelta(); | 67 ~EventResponseDelta(); |
61 | 68 |
62 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); | 69 DISALLOW_COPY_AND_ASSIGN(EventResponseDelta); |
63 }; | 70 }; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 const std::string& extension_id, | 110 const std::string& extension_id, |
104 const base::Time& extension_install_time, | 111 const base::Time& extension_install_time, |
105 bool cancel, | 112 bool cancel, |
106 const GURL& new_url); | 113 const GURL& new_url); |
107 EventResponseDelta* CalculateOnBeforeSendHeadersDelta( | 114 EventResponseDelta* CalculateOnBeforeSendHeadersDelta( |
108 const std::string& extension_id, | 115 const std::string& extension_id, |
109 const base::Time& extension_install_time, | 116 const base::Time& extension_install_time, |
110 bool cancel, | 117 bool cancel, |
111 net::HttpRequestHeaders* old_headers, | 118 net::HttpRequestHeaders* old_headers, |
112 net::HttpRequestHeaders* new_headers); | 119 net::HttpRequestHeaders* new_headers); |
113 // |status_line| contains the status line of the original request. Together | |
114 // with |response_headers_string| we can assemble a complete new response | |
115 // header. |response_headers_string| contains all headers with \n as line | |
116 // separator. It terminates with two \n. | |
117 EventResponseDelta* CalculateOnHeadersReceivedDelta( | 120 EventResponseDelta* CalculateOnHeadersReceivedDelta( |
118 const std::string& extension_id, | 121 const std::string& extension_id, |
119 const base::Time& extension_install_time, | 122 const base::Time& extension_install_time, |
120 bool cancel, | 123 bool cancel, |
121 const std::string& status_line, | 124 net::HttpResponseHeaders* old_response_headers, |
122 const std::string& response_headers_string); | 125 ResponseHeaders* new_response_headers); |
123 // Destructively moves the auth credentials from |auth_credentials| to the | 126 // Destructively moves the auth credentials from |auth_credentials| to the |
124 // returned EventResponseDelta. | 127 // returned EventResponseDelta. |
125 EventResponseDelta* CalculateOnAuthRequiredDelta( | 128 EventResponseDelta* CalculateOnAuthRequiredDelta( |
126 const std::string& extension_id, | 129 const std::string& extension_id, |
127 const base::Time& extension_install_time, | 130 const base::Time& extension_install_time, |
128 bool cancel, | 131 bool cancel, |
129 scoped_ptr<net::AuthCredentials>* auth_credentials); | 132 scoped_ptr<net::AuthCredentials>* auth_credentials); |
130 | 133 |
131 // These functions merge the responses (the |deltas|) of request handlers. | 134 // These functions merge the responses (the |deltas|) of request handlers. |
132 // The |deltas| need to be sorted in decreasing order of precedence of | 135 // The |deltas| need to be sorted in decreasing order of precedence of |
(...skipping 14 matching lines...) Expand all Loading... |
147 GURL* new_url, | 150 GURL* new_url, |
148 std::set<std::string>* conflicting_extensions, | 151 std::set<std::string>* conflicting_extensions, |
149 EventLogEntries* event_log_entries); | 152 EventLogEntries* event_log_entries); |
150 // Modifies the headers in |request_headers| according to |deltas|. Conflicts | 153 // Modifies the headers in |request_headers| according to |deltas|. Conflicts |
151 // are tried to be resolved. | 154 // are tried to be resolved. |
152 void MergeOnBeforeSendHeadersResponses( | 155 void MergeOnBeforeSendHeadersResponses( |
153 const EventResponseDeltas& deltas, | 156 const EventResponseDeltas& deltas, |
154 net::HttpRequestHeaders* request_headers, | 157 net::HttpRequestHeaders* request_headers, |
155 std::set<std::string>* conflicting_extensions, | 158 std::set<std::string>* conflicting_extensions, |
156 EventLogEntries* event_log_entries); | 159 EventLogEntries* event_log_entries); |
157 // Overrides |override_response_headers| with the response headers returned | 160 // Stores a copy of |original_response_header| into |override_response_headers| |
158 // by the extension with the highest precedence. | 161 // that is modified according to |deltas|. If |deltas| does not instruct to |
159 // TODO(battre) Implement merging of response header modifications. | 162 // modify the response headers, |override_response_headers| remains empty. |
160 void MergeOnHeadersReceivedResponses( | 163 void MergeOnHeadersReceivedResponses( |
161 const EventResponseDeltas& deltas, | 164 const EventResponseDeltas& deltas, |
| 165 const net::HttpResponseHeaders* original_response_headers, |
162 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 166 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
163 std::set<std::string>* conflicting_extensions, | 167 std::set<std::string>* conflicting_extensions, |
164 EventLogEntries* event_log_entries); | 168 EventLogEntries* event_log_entries); |
165 // Merge the responses of blocked onAuthRequired handlers. The first | 169 // Merge the responses of blocked onAuthRequired handlers. The first |
166 // registered listener that supplies authentication credentials in a response, | 170 // registered listener that supplies authentication credentials in a response, |
167 // if any, will have its authentication credentials used. |request| must be | 171 // if any, will have its authentication credentials used. |request| must be |
168 // non-NULL, and contain |deltas| that are sorted in decreasing order of | 172 // non-NULL, and contain |deltas| that are sorted in decreasing order of |
169 // precedence. | 173 // precedence. |
170 // Returns whether authentication credentials are set. | 174 // Returns whether authentication credentials are set. |
171 bool MergeOnAuthRequiredResponses( | 175 bool MergeOnAuthRequiredResponses( |
172 const EventResponseDeltas& deltas, | 176 const EventResponseDeltas& deltas, |
173 net::AuthCredentials* auth_credentials, | 177 net::AuthCredentials* auth_credentials, |
174 std::set<std::string>* conflicting_extensions, | 178 std::set<std::string>* conflicting_extensions, |
175 EventLogEntries* event_log_entries); | 179 EventLogEntries* event_log_entries); |
176 | 180 |
177 } // namespace extension_webrequest_api_helpers | 181 } // namespace extension_webrequest_api_helpers |
178 | 182 |
179 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_HELPERS_H_ | 183 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBREQUEST_API_HELPERS_H_ |
OLD | NEW |