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