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