| 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 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "chrome/browser/extensions/extension_warning_set.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 #include "net/base/auth.h" | 20 #include "net/base/auth.h" |
| 20 #include "net/http/http_request_headers.h" | 21 #include "net/http/http_request_headers.h" |
| 21 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 22 #include "webkit/glue/resource_type.h" | 23 #include "webkit/glue/resource_type.h" |
| 23 | 24 |
| 24 namespace base { | 25 namespace base { |
| 25 class ListValue; | 26 class ListValue; |
| 26 class Value; | 27 class Value; |
| 27 } | 28 } |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 void MergeCancelOfResponses( | 217 void MergeCancelOfResponses( |
| 217 const EventResponseDeltas& deltas, | 218 const EventResponseDeltas& deltas, |
| 218 bool* canceled, | 219 bool* canceled, |
| 219 const net::BoundNetLog* net_log); | 220 const net::BoundNetLog* net_log); |
| 220 // Stores in |*new_url| the redirect request of the extension with highest | 221 // Stores in |*new_url| the redirect request of the extension with highest |
| 221 // precedence. Extensions that did not command to redirect the request are | 222 // precedence. Extensions that did not command to redirect the request are |
| 222 // ignored in this logic. | 223 // ignored in this logic. |
| 223 void MergeOnBeforeRequestResponses( | 224 void MergeOnBeforeRequestResponses( |
| 224 const EventResponseDeltas& deltas, | 225 const EventResponseDeltas& deltas, |
| 225 GURL* new_url, | 226 GURL* new_url, |
| 226 std::set<std::string>* conflicting_extensions, | 227 extensions::ExtensionWarningSet* conflicting_extensions, |
| 227 const net::BoundNetLog* net_log); | 228 const net::BoundNetLog* net_log); |
| 228 // Modifies the "Cookie" header in |request_headers| according to | 229 // Modifies the "Cookie" header in |request_headers| according to |
| 229 // |deltas.request_cookie_modifications|. Conflicts are currently ignored | 230 // |deltas.request_cookie_modifications|. Conflicts are currently ignored |
| 230 // silently. | 231 // silently. |
| 231 void MergeCookiesInOnBeforeSendHeadersResponses( | 232 void MergeCookiesInOnBeforeSendHeadersResponses( |
| 232 const EventResponseDeltas& deltas, | 233 const EventResponseDeltas& deltas, |
| 233 net::HttpRequestHeaders* request_headers, | 234 net::HttpRequestHeaders* request_headers, |
| 234 std::set<std::string>* conflicting_extensions, | 235 extensions::ExtensionWarningSet* conflicting_extensions, |
| 235 const net::BoundNetLog* net_log); | 236 const net::BoundNetLog* net_log); |
| 236 // Modifies the headers in |request_headers| according to |deltas|. Conflicts | 237 // Modifies the headers in |request_headers| according to |deltas|. Conflicts |
| 237 // are tried to be resolved. | 238 // are tried to be resolved. |
| 238 void MergeOnBeforeSendHeadersResponses( | 239 void MergeOnBeforeSendHeadersResponses( |
| 239 const EventResponseDeltas& deltas, | 240 const EventResponseDeltas& deltas, |
| 240 net::HttpRequestHeaders* request_headers, | 241 net::HttpRequestHeaders* request_headers, |
| 241 std::set<std::string>* conflicting_extensions, | 242 extensions::ExtensionWarningSet* conflicting_extensions, |
| 242 const net::BoundNetLog* net_log); | 243 const net::BoundNetLog* net_log); |
| 243 // Modifies the "Set-Cookie" headers in |override_response_headers| according to | 244 // Modifies the "Set-Cookie" headers in |override_response_headers| according to |
| 244 // |deltas.response_cookie_modifications|. If |override_response_headers| is | 245 // |deltas.response_cookie_modifications|. If |override_response_headers| is |
| 245 // NULL, a copy of |original_response_headers| is created. Conflicts are | 246 // NULL, a copy of |original_response_headers| is created. Conflicts are |
| 246 // currently ignored silently. | 247 // currently ignored silently. |
| 247 void MergeCookiesInOnHeadersReceivedResponses( | 248 void MergeCookiesInOnHeadersReceivedResponses( |
| 248 const EventResponseDeltas& deltas, | 249 const EventResponseDeltas& deltas, |
| 249 const net::HttpResponseHeaders* original_response_headers, | 250 const net::HttpResponseHeaders* original_response_headers, |
| 250 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 251 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 251 std::set<std::string>* conflicting_extensions, | 252 extensions::ExtensionWarningSet* conflicting_extensions, |
| 252 const net::BoundNetLog* net_log); | 253 const net::BoundNetLog* net_log); |
| 253 // Stores a copy of |original_response_header| into |override_response_headers| | 254 // Stores a copy of |original_response_header| into |override_response_headers| |
| 254 // that is modified according to |deltas|. If |deltas| does not instruct to | 255 // that is modified according to |deltas|. If |deltas| does not instruct to |
| 255 // modify the response headers, |override_response_headers| remains empty. | 256 // modify the response headers, |override_response_headers| remains empty. |
| 256 void MergeOnHeadersReceivedResponses( | 257 void MergeOnHeadersReceivedResponses( |
| 257 const EventResponseDeltas& deltas, | 258 const EventResponseDeltas& deltas, |
| 258 const net::HttpResponseHeaders* original_response_headers, | 259 const net::HttpResponseHeaders* original_response_headers, |
| 259 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, | 260 scoped_refptr<net::HttpResponseHeaders>* override_response_headers, |
| 260 std::set<std::string>* conflicting_extensions, | 261 extensions::ExtensionWarningSet* conflicting_extensions, |
| 261 const net::BoundNetLog* net_log); | 262 const net::BoundNetLog* net_log); |
| 262 // Merge the responses of blocked onAuthRequired handlers. The first | 263 // Merge the responses of blocked onAuthRequired handlers. The first |
| 263 // registered listener that supplies authentication credentials in a response, | 264 // registered listener that supplies authentication credentials in a response, |
| 264 // if any, will have its authentication credentials used. |request| must be | 265 // if any, will have its authentication credentials used. |request| must be |
| 265 // non-NULL, and contain |deltas| that are sorted in decreasing order of | 266 // non-NULL, and contain |deltas| that are sorted in decreasing order of |
| 266 // precedence. | 267 // precedence. |
| 267 // Returns whether authentication credentials are set. | 268 // Returns whether authentication credentials are set. |
| 268 bool MergeOnAuthRequiredResponses( | 269 bool MergeOnAuthRequiredResponses( |
| 269 const EventResponseDeltas& deltas, | 270 const EventResponseDeltas& deltas, |
| 270 net::AuthCredentials* auth_credentials, | 271 net::AuthCredentials* auth_credentials, |
| 271 std::set<std::string>* conflicting_extensions, | 272 extensions::ExtensionWarningSet* conflicting_extensions, |
| 272 const net::BoundNetLog* net_log); | 273 const net::BoundNetLog* net_log); |
| 273 | 274 |
| 274 // Returns whether |type| is a ResourceType that is handled by the web request | 275 // Returns whether |type| is a ResourceType that is handled by the web request |
| 275 // API. | 276 // API. |
| 276 bool IsRelevantResourceType(ResourceType::Type type); | 277 bool IsRelevantResourceType(ResourceType::Type type); |
| 277 | 278 |
| 278 // Returns a string representation of |type| or |other| if |type| is not handled | 279 // Returns a string representation of |type| or |other| if |type| is not handled |
| 279 // by the web request API. | 280 // by the web request API. |
| 280 const char* ResourceTypeToString(ResourceType::Type type); | 281 const char* ResourceTypeToString(ResourceType::Type type); |
| 281 | 282 |
| 282 // Stores a |ResourceType::Type| representation in |type| if |type_str| is | 283 // Stores a |ResourceType::Type| representation in |type| if |type_str| is |
| 283 // a resource type handled by the web request API. Returns true in case of | 284 // a resource type handled by the web request API. Returns true in case of |
| 284 // success. | 285 // success. |
| 285 bool ParseResourceType(const std::string& type_str, | 286 bool ParseResourceType(const std::string& type_str, |
| 286 ResourceType::Type* type); | 287 ResourceType::Type* type); |
| 287 | 288 |
| 288 // Triggers clearing each renderer's in-memory cache the next time it navigates. | 289 // Triggers clearing each renderer's in-memory cache the next time it navigates. |
| 289 void ClearCacheOnNavigation(); | 290 void ClearCacheOnNavigation(); |
| 290 | 291 |
| 291 } // namespace extension_web_request_api_helpers | 292 } // namespace extension_web_request_api_helpers |
| 292 | 293 |
| 293 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ | 294 #endif // CHROME_BROWSER_EXTENSIONS_API_WEB_REQUEST_WEB_REQUEST_API_HELPERS_H_ |
| OLD | NEW |