15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_URL_REQUEST_URL_REQUEST_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_URL_REQUEST_URL_REQUEST_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/debug/leak_tracker.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/memory/scoped_ptr.h" 15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/supports_user_data.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/non_thread_safe.h" 18eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/completion_callback.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/load_states.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/load_timing_info.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_log.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/network_delegate.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/request_priority.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/upload_progress.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/canonical_cookie.h" 29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "net/cookies/cookie_store.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_request_headers.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_response_info.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_status.h" 337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h" 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class Value; 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace debug { 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StackTrace; 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace debug 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace base 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface. 45c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace content { 46e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochclass AppCacheInterceptor; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CookieOptions; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HostPortPair; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IOBuffer; 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct LoadTimingInfo; 556e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)struct RedirectInfo; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLCertRequestInfo; 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLInfo; 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class UploadDataStream; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestContext; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestJob; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class X509Certificate; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This stores the values of the Set-Cookie headers received during the request. 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Each item in the vector corresponds to a Set-Cookie: line received, 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// excluding the "Set-Cookie:" part. 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<std::string> ResponseCookies; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//----------------------------------------------------------------------------- 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A class representing the asynchronous load of a data stream from an URL. 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The lifetime of an instance of this class is completely controlled by the 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// consumer, and the instance is not required to live on the heap or be 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// allocated in any special way. It is also valid to delete an URLRequest 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// object during the handling of a callback to its delegate. Of course, once 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the URLRequest is deleted, no further callbacks to its delegate will occur. 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: All usage of all instances of this class should be on the same thread. 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public base::SupportsUserData { 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback function implemented by protocol handlers to create new jobs. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The factory may return NULL to indicate an error, which will cause other 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // factories to be queried. If no factory handles the request, then the 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // default job will be used. 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NetworkDelegate* network_delegate, 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& scheme); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // HTTP request/response header IDs (via some preprocessor fun) for use with 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetRequestHeaderById and GetResponseHeaderById. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum { 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define HTTP_ATOM(x) HTTP_ ## x, 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_atom_list.h" 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#undef HTTP_ATOM 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Referrer policies (see set_referrer_policy): During server redirects, the 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // referrer header might be cleared, if the protocol changes from HTTPS to 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // HTTP. This is the default behavior of URLRequest, corresponding to 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE. Alternatively, the 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // referrer policy can be set to never change the referrer header. This 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NEVER_CLEAR_REFERRER when implementing the meta-referrer support 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // non-default referrer policy. Only the default referrer policy requires 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the referrer to be cleared on transitions from HTTPS to HTTP. 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum ReferrerPolicy { 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEVER_CLEAR_REFERRER, 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // First-party URL redirect policy: During server redirects, the first-party 1146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // URL for cookies normally doesn't change. However, if the request is a 1156e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // top-level first-party request, the first-party URL should be updated to the 1166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // URL on every redirect. 1176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) enum FirstPartyURLPolicy { 1186e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) NEVER_CHANGE_FIRST_PARTY_URL, 1196e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) UPDATE_FIRST_PARTY_URL_ON_REDIRECT, 1206e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) }; 1216e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This class handles network interception. Use with 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (Un)RegisterRequestInterceptor. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class NET_EXPORT Interceptor { 125cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) public: 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Interceptor() {} 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called for every request made. Should return a new job to handle the 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request if it should be intercepted, or NULL to allow the request to 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be handled in the normal manner. 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual URLRequestJob* MaybeIntercept( 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, NetworkDelegate* network_delegate) = 0; 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called after having received a redirect response, but prior to the 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the request delegate being informed of the redirect. Can return a new 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // job to replace the existing job if it should be intercepted, or NULL 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to allow the normal handling to continue. If a new job is provided, 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the delegate never sees the original redirect response, instead the 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response produced by the intercept job will be returned. 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual URLRequestJob* MaybeInterceptRedirect( 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NetworkDelegate* network_delegate, 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& location); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called after having received a final response, but prior to the 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the request delegate being informed of the response. This is also 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // called when there is no server response at all to allow interception 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on dns or network errors. Can return a new job to replace the existing 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // job if it should be intercepted, or NULL to allow the normal handling to 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // continue. If a new job is provided, the delegate never sees the original 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response, instead the response produced by the intercept job will be 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returned. 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual URLRequestJob* MaybeInterceptResponse( 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, NetworkDelegate* network_delegate); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deprecated interfaces in net::URLRequest. They have been moved to 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLRequest's private section to prevent new uses. Existing uses are 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // explicitly friended here and should be removed over time. 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class NET_EXPORT Deprecated { 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(willchan): Kill off these friend declarations. 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class TestInterceptor; 164e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch friend class content::AppCacheInterceptor; 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(pauljensen): Remove this when AppCacheInterceptor is a 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ProtocolHandler, see crbug.com/161547. 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void RegisterRequestInterceptor(Interceptor* interceptor); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void UnregisterRequestInterceptor(Interceptor* interceptor); 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_IMPLICIT_CONSTRUCTORS(Deprecated); 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The delegate's methods are called from the message loop of the thread 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on which the request's Start() method is called. See above for the 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ordering of callbacks. 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The callbacks will be called in the following order: 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Start() 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnCertificateRequested* (zero or more calls, if the SSL server and/or 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SSL proxy requests a client certificate for authentication) 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnSSLCertificateError* (zero or one call, if the SSL server's 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // certificate has an error) 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnReceivedRedirect* (zero or more calls, for the number of redirects) 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnAuthRequired* (zero or more calls, for the number of 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // authentication failures) 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnResponseStarted 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read() initiated by delegate 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnReadCompleted* (zero or more calls until all data is read) 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read() must be called at least once. Read() returns true when it completed 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // immediately, and false if an IO is pending or if there is an error. When 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read() returns false, the caller can check the Request's status() to see 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if an error occurred, or if the IO is just pending. When Read() returns 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true with zero bytes read, it indicates the end of the response. 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class NET_EXPORT Delegate { 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1996e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Called upon receiving a redirect. The delegate may call the request's 2006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Cancel method to prevent the redirect from being followed. Since there 2016e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // may be multiple chained redirects, there may also be more than one 2026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // redirect call. 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When this function is called, the request will still contain the 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // original URL, the destination of the redirect is provided in 'new_url'. 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the delegate does not cancel the request and |*defer_redirect| is 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false, then the redirect will be followed, and the request's URL will be 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // changed to the new URL. Otherwise if the delegate does not cancel the 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request and |*defer_redirect| is true, then the redirect will be 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // followed once FollowDeferredRedirect is called on the URLRequest. 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The caller must set |*defer_redirect| to false, so that delegates do not 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // need to set it if they are happy with the default behavior of not 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // deferring redirect. 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnReceivedRedirect(URLRequest* request, 2166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) const RedirectInfo& redirect_info, 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* defer_redirect); 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when we receive an authentication failure. The delegate should 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // call request->SetAuth() with the user's credentials once it obtains them, 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or request->CancelAuth() to cancel the login and display the error page. 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When it does so, the request will be reissued, restarting the sequence 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of On* callbacks. 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnAuthRequired(URLRequest* request, 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthChallengeInfo* auth_info); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when we receive an SSL CertificateRequest message for client 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // authentication. The delegate should call 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request->ContinueWithCertificate() with the client certificate the user 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // selected, or request->ContinueWithCertificate(NULL) to continue the SSL 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // handshake without a client certificate. 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnCertificateRequested( 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SSLCertRequestInfo* cert_request_info); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when using SSL and the server responds with a certificate with 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // an error, for example, whose common name does not match the common name 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // we were expecting for that host. The delegate should either do the 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // safe thing and Cancel() the request or decide to proceed by calling 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ContinueDespiteLastError(). cert_error is a ERR_* error code 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // indicating what's wrong with the certificate. 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |fatal| is true then the host in question demands a higher level 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of security (due e.g. to HTTP Strict Transport Security, user 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // preference, or built-in policy). In this case, errors must not be 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bypassable by the user. 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnSSLCertificateError(URLRequest* request, 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SSLInfo& ssl_info, 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool fatal); 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Called to notify that the request must use the network to complete the 2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // request and is about to do so. This is called at most once per 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // URLRequest, and by default does not defer. If deferred, call 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // ResumeNetworkStart() to continue or Cancel() to cancel. 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void OnBeforeNetworkStart(URLRequest* request, bool* defer); 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // After calling Start(), the delegate will receive an OnResponseStarted 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // callback when the request has completed. If an error occurred, the 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request->status() will be set. On success, all redirects have been 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // followed and the final response is beginning to arrive. At this point, 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // meta data about the response is available, including for example HTTP 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response headers if this is a request for a HTTP resource. 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnResponseStarted(URLRequest* request) = 0; 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the a Read of the response body is completed after an 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IO_PENDING status from a Read() call. 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The data read is filled into the buffer which the caller passed 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to Read() previously. 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If an error occurred, request->status() will contain the error, 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and bytes read will be -1. 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Delegate() {} 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If destroyed after Start() has been called but while IO is pending, 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // then the request will be effectively canceled and the delegate 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will not have any more of its methods called. 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~URLRequest(); 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Changes the default cookie policy from allowing all cookies to blocking all 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cookies. Embedders that want to implement a more flexible policy should 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // change the default to blocking all cookies, and provide a NetworkDelegate 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // with the URLRequestContext that maintains the CookieStore. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The cookie policy default has to be set before the first URLRequest is 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // started. Once it was set to block all cookies, it cannot be changed back. 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void SetDefaultCookiePolicyToBlock(); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the scheme can be handled by URLRequest. False otherwise. 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsHandledProtocol(const std::string& scheme); 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the url can be handled by URLRequest. False otherwise. 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The function returns true for invalid urls because URLRequest knows how 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to handle those. 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: This will also return true for URLs that are handled by 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ProtocolFactories that only work for requests that are scoped to a 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Profile. 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsHandledURL(const GURL& url); 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The original url is the url used to initialize the request, and it may 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // differ from the url if the request was redirected. 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& original_url() const { return url_chain_.front(); } 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The chain of urls traversed by this request. If the request had no 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // redirects, this vector will contain one element. 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::vector<GURL>& url_chain() const { return url_chain_; } 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url() const { return url_chain_.back(); } 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The URL that should be consulted for the third-party cookie blocking 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // policy. 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WARNING: This URL must only be used for the third-party cookie blocking 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // policy. It MUST NEVER be used for any kind of SECURITY check. 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For example, if a top-level navigation is redirected, the 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first-party for cookies will be the URL of the first URL in the 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // redirect chain throughout the whole redirect. If it was used for 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a security check, an attacker might try to get around this check 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // by starting from some page that redirects to the 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // host-to-be-attacked. 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& first_party_for_cookies() const { 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return first_party_for_cookies_; 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // This method may only be called before Start(). 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_first_party_for_cookies(const GURL& first_party_for_cookies); 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // The first-party URL policy to apply when updating the first party URL 3286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // during redirects. The first-party URL policy may only be changed before 3296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Start() is called. 3306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) FirstPartyURLPolicy first_party_url_policy() const { 3316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) return first_party_url_policy_; 3326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) } 3336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void set_first_party_url_policy(FirstPartyURLPolicy first_party_url_policy); 3346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request method, as an uppercase string. "GET" is the default value. 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request method may only be changed before Start() is called and 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // should only be assigned an uppercase value. 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& method() const { return method_; } 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_method(const std::string& method); 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3419ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // Determines the new method of the request afer following a redirect. 3429ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // |method| is the method used to arrive at the redirect, 3439ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // |http_status_code| is the status code associated with the redirect. 3449ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch static std::string ComputeMethodForRedirect(const std::string& method, 3459ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch int http_status_code); 3469ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The referrer URL for the request. This header may actually be suppressed 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from the underlying network request for security reasons (e.g., a HTTPS 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL will not be sent as the referrer for a HTTP request). The referrer 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // may only be changed before Start() is called. 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& referrer() const { return referrer_; } 352c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Referrer is sanitized to remove URL fragment, user name and password. 353c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void SetReferrer(const std::string& referrer); 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The referrer policy to apply when updating the referrer during redirects. 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The referrer policy may only be changed before Start() is called. 3576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) ReferrerPolicy referrer_policy() const { return referrer_policy_; } 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_referrer_policy(ReferrerPolicy referrer_policy); 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the delegate of the request. This value may be changed at any time, 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and it is permissible for it to be null. 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_delegate(Delegate* delegate); 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates that the request body should be sent using chunked transfer 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // encoding. This method may only be called before Start() is called. 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void EnableChunkedUpload(); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Appends the given bytes to the request's upload data to be sent 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // immediately via chunked transfer encoding. When all data has been sent, 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // call MarkEndOfChunks() to indicate the end of upload data. 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method may be called only after calling EnableChunkedUpload(). 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AppendChunkToUpload(const char* bytes, 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int bytes_len, 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_last_chunk); 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the upload data. 3782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void set_upload(scoped_ptr<UploadDataStream> upload); 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets the upload data. 3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const UploadDataStream* get_upload() const; 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the request has a non-empty message body to upload. 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_upload() const; 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set an extra request header by ID or name, or remove one by name. These 3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // methods may only be called before Start() is called, or before a new 3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // redirect in the request chain. 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetExtraRequestHeaderById(int header_id, const std::string& value, 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool overwrite); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetExtraRequestHeaderByName(const std::string& name, 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& value, bool overwrite); 3932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void RemoveRequestHeaderByName(const std::string& name); 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets all extra request headers. Any extra request headers set by other 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // methods are overwritten by this method. This method may only be called 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // before Start() is called. It is an error to call it later. 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetExtraRequestHeaders(const HttpRequestHeaders& headers); 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const HttpRequestHeaders& extra_request_headers() const { 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extra_request_headers_; 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 404eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Gets the full request headers sent to the server. 405eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 406eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Return true and overwrites headers if it can get the request headers; 407eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // otherwise, returns false and does not modify headers. (Always returns 408eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // false for request types that don't have headers, like file requests.) 409eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 410eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // This is guaranteed to succeed if: 411eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 412eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 1. A redirect or auth callback is currently running. Once it ends, the 413eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // headers may become unavailable as a new request with the new address 414eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // or credentials is made. 415eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 416eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 2. The OnResponseStarted callback is currently running or has run. 417eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool GetFullRequestHeaders(HttpRequestHeaders* headers) const; 418eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Gets the total amount of data received from network after SSL decoding and 4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // proxy handling. 4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int64 GetTotalReceivedBytes() const; 4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 423a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Returns the current load state for the request. The returned value's 424a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |param| field is an optional parameter describing details related to the 425a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // load state. Not all load states have a parameter. 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoadStateWithParam GetLoadState() const; 4271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 4281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns a partial representation of the request's state as a value, for 4291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // debugging. Caller takes ownership of returned value. 4301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::Value* GetStateAsValue() const; 4311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 432a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Logs information about the what external object currently blocking the 433a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // request. LogUnblocked must be called before resuming the request. This 434a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // can be called multiple times in a row either with or without calling 435a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // LogUnblocked between calls. |blocked_by| must not be NULL or have length 436a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 0. 437a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void LogBlockedBy(const char* blocked_by); 438a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 439a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Just like LogBlockedBy, but also makes GetLoadState return source as the 440a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |param| in the value returned by GetLoadState. Calling LogUnblocked or 441a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // LogBlockedBy will clear the load param. |blocked_by| must not be NULL or 442a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // have length 0. 443a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void LogAndReportBlockedBy(const char* blocked_by); 444a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 445a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Logs that the request is no longer blocked by the last caller to 446a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // LogBlockedBy. 447a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void LogUnblocked(); 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the current upload progress in bytes. When the upload data is 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // chunked, size is set to zero, but position will not be. 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UploadProgress GetUploadProgress() const; 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get response header(s) by ID or name. These methods may only be called 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // once the delegate's OnResponseStarted method has been called. Headers 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that appear more than once in the response are coalesced, with values 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // separated by commas (per RFC 2616). This will not work with cookies since 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // comma can be used in cookie values. 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(darin): add API to enumerate response headers. 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetResponseHeaderById(int header_id, std::string* value); 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetResponseHeaderByName(const std::string& name, std::string* value); 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get all response headers, \n-delimited and \n\0-terminated. This includes 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the response status line. Restrictions on GetResponseHeaders apply. 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetAllResponseHeaders(std::string* headers); 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time when |this| was constructed. 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks creation_time() const { return creation_time_; } 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the returned response was requested. For cached 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // responses, this is the last time the cache entry was validated. 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Time& request_time() const { 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.request_time; 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the returned response was generated. For cached 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // responses, this is the last time the cache entry was validated. 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Time& response_time() const { 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.response_time; 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicate if this response was fetched from disk cache. 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_cached() const { return response_info_.was_cached; } 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the URLRequest was delivered through a proxy. 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_fetched_via_proxy() const { 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.was_fetched_via_proxy; 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns true if the URLRequest was delivered over SPDY. 4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool was_fetched_via_spdy() const { 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return response_info_.was_fetched_via_spdy; 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the host and port that the content was fetched from. See 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http_response_info.h for caveats relating to cached content. 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HostPortPair GetSocketAddress() const; 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get all response headers, as a HttpResponseHeaders object. See comments 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in HttpResponseHeaders class as to the format of the data. 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseHeaders* response_headers() const; 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the SSL connection info. 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SSLInfo& ssl_info() const { 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.ssl_info; 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets timing information related to the request. Events that have not yet 5082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // occurred are left uninitialized. After a second request starts, due to 5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // a redirect or authentication, values will be reset. 5102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // LoadTimingInfo only contains ConnectTiming information and socket IDs for 5122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // non-cached HTTP responses. 5132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const; 5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the cookie values included in the response, if the request is one 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that can have cookies. Returns true if the request is a cookie-bearing 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // type, false otherwise. This method may only be called once the 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // delegate's OnResponseStarted method has been called. 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetResponseCookies(ResponseCookies* cookies); 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the mime type. This method may only be called once the delegate's 5225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // OnResponseStarted method has been called. 523116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void GetMimeType(std::string* mime_type) const; 5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the charset (character encoding). This method may only be called once 5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the delegate's OnResponseStarted method has been called. 527116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void GetCharset(std::string* charset) const; 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the HTTP response code (e.g., 200, 404, and so on). This method 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // may only be called once the delegate's OnResponseStarted method has been 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // called. For non-HTTP requests, this method returns -1. 53258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) int GetResponseCode() const; 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the HTTP response info in its entirety. 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const HttpResponseInfo& response_info() const { return response_info_; } 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Access the LOAD_* flags modifying this request (see load_flags.h). 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int load_flags() const { return load_flags_; } 539f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 540f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The new flags may change the IGNORE_LIMITS flag only when called 541f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // before Start() is called, it must only set the flag, and if set, 542f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the priority of this request must already be MAXIMUM_PRIORITY. 543f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void SetLoadFlags(int flags); 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the request is "pending" (i.e., if Start() has been called, 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and the response has not yet been called). 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_pending() const { return is_pending_; } 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the request is in the process of redirecting to a new 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL but has not yet initiated the new request. 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_redirecting() const { return is_redirecting_; } 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the error status of the request. 5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const URLRequestStatus& status() const { return status_; } 5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a globally unique identifier for this request. 5575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64 identifier() const { return identifier_; } 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is called to start the request. The delegate will receive 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a OnResponseStarted callback when the request is started. 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Start(); 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method may be called at any time after Start() has been called to 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancel the request. This method may be called many times, and it has 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no effect once the response has completed. It is guaranteed that no 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // methods of the delegate will be called after the request has been 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancelled, except that this may call the delegate's OnReadCompleted() 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // during the call to Cancel itself. 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Cancel(); 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels the request and sets the error to |error| (see net_error_list.h 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for values). 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CancelWithError(int error); 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels the request and sets the error to |error| (see net_error_list.h 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for values) and attaches |ssl_info| as the SSLInfo for that request. This 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is useful to attach a certificate and certificate error to a canceled 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request. 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CancelWithSSLError(int error, const SSLInfo& ssl_info); 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read initiates an asynchronous read from the response, and must only 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be called after the OnResponseStarted callback is received with a 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // successful status. 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If data is available, Read will return true, and the data and length will 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be returned immediately. If data is not available, Read returns false, 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and an asynchronous Read is initiated. The Read is finished when 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the caller receives the OnReadComplete callback. Unless the request was 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancelled, OnReadComplete will always be called, even if the read failed. 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The buf parameter is a buffer to receive the data. If the operation 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // completes asynchronously, the implementation will reference the buffer 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // until OnReadComplete is called. The buffer must be at least max_bytes in 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // length. 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The max_bytes parameter is the maximum number of bytes to read. 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The bytes_read parameter is an output parameter containing the 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the number of bytes read. A value of 0 indicates that there is no 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // more data available to read from the stream. 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If a read error occurs, Read returns false and the request->status 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be set to an error. 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Read(IOBuffer* buf, int max_bytes, int* bytes_read); 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this request is being cached by the HTTP cache, stop subsequent caching. 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that this method has no effect on other (simultaneous or not) requests 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same resource. The typical example is a request that results in 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the data being stored to disk (downloaded instead of rendered) so we don't 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // want to store it twice. 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StopCaching(); 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method may be called to follow a redirect that was deferred in 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response to an OnReceivedRedirect call. 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void FollowDeferredRedirect(); 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // This method must be called to resume network communications that were 6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // deferred in response to an OnBeforeNetworkStart call. 6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void ResumeNetworkStart(); 6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // One of the following two methods should be called in response to an 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // OnAuthRequired() callback (and only then). 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetAuth will reissue the request with the given credentials. 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // CancelAuth will give up and display the error page. 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetAuth(const AuthCredentials& credentials); 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CancelAuth(); 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method can be called after the user selects a client certificate to 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // instruct this URLRequest to continue with the request with the 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // certificate. Pass NULL if the user doesn't have a client certificate. 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ContinueWithCertificate(X509Certificate* client_cert); 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method can be called after some error notifications to instruct this 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLRequest to ignore the current error and continue with the request. To 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancel the request instead, call Cancel(). 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ContinueDespiteLastError(); 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used to specify the context (cookie store, cache) for this request. 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const URLRequestContext* context() const; 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const BoundNetLog& net_log() const { return net_log_; } 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the expected content size if available 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 GetExpectedContentSize() const; 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the priority level for this request. 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestPriority priority() const { return priority_; } 6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 648f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Sets the priority level for this request and any related 649f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // jobs. Must not change the priority to anything other than 650f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // MAXIMUM_PRIORITY if the IGNORE_LIMITS load flag is set. 6512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetPriority(RequestPriority priority); 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true iff this request would be internally redirected to HTTPS 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // due to HSTS. If so, |redirect_url| is rewritten to the new HTTPS URL. 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetHSTSRedirect(GURL* redirect_url) const; 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(willchan): Undo this. Only temporarily public. 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_delegate() const { return delegate_ != NULL; } 6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE(willchan): This is just temporary for debugging 6615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http://crbug.com/90971. 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allows to setting debug info into the URLRequest. 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_stack_trace(const base::debug::StackTrace& stack_trace); 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::debug::StackTrace* stack_trace() const; 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_received_response_content_length(int64 received_content_length) { 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) received_response_content_length_ = received_content_length; 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int64 received_response_content_length() const { 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return received_response_content_length_; 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 673f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Available at NetworkDelegate::NotifyHeadersReceived() time, which is before 674f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // the more general response_info() is available, even though it is a subset. 675f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const HostPortPair& proxy_server() const { 676f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) return proxy_server_; 677f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) } 678f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow the URLRequestJob class to control the is_pending() flag. 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_is_pending(bool value) { is_pending_ = value; } 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow the URLRequestJob class to set our status too 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_status(const URLRequestStatus& value) { status_ = value; } 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci CookieStore* cookie_store() const { return cookie_store_.get(); } 687a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow the URLRequestJob to redirect this request. Returns OK if 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // successful, otherwise an error code is returned. 6906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) int Redirect(const RedirectInfo& redirect_info); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by URLRequestJob to allow interception when a redirect occurs. 6936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) void NotifyReceivedRedirect(const RedirectInfo& redirect_info, 6946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool* defer_redirect); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Called by URLRequestHttpJob (note, only HTTP(S) jobs will call this) to 6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // allow deferral of network initialization. 6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void NotifyBeforeNetworkStart(bool* defer); 6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow an interceptor's URLRequestJob to restart this request. 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should only be called if the original job has not started a response. 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Restart(); 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class URLRequestJob; 7061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci friend class URLRequestContext; 7071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 7081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // URLRequests are always created by calling URLRequestContext::CreateRequest. 7091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // 7101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // If no cookie store or network delegate are passed in, will use the ones 7111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // from the URLRequestContext. 7121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci URLRequest(const GURL& url, 7131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci RequestPriority priority, 7141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Delegate* delegate, 7151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const URLRequestContext* context, 7161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci CookieStore* cookie_store, 7171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci NetworkDelegate* network_delegate); 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Registers or unregisters a network interception class. 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void RegisterRequestInterceptor(Interceptor* interceptor); 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void UnregisterRequestInterceptor(Interceptor* interceptor); 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // handler. If |blocked| is true, the request is blocked and an error page is 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returned indicating so. This should only be called after Start is called 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and OnBeforeRequest returns true (signalling that the request should be 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // paused). 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void BeforeRequestComplete(int error); 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StartJob(URLRequestJob* job); 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restarting involves replacing the current job with a new one such as what 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // happens when following a HTTP redirect. 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RestartWithJob(URLRequestJob* job); 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void PrepareToRestart(); 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Detaches the job from this request in preparation for this object going 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // away or the job being replaced. The job will not call us back when it has 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // been orphaned. 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OrphanJob(); 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels the request and set the error and ssl info for this request to the 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // passed values. 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DoCancel(int error, const SSLInfo& ssl_info); 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called by the URLRequestJob when the headers are received, before any other 7472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // method, to allow caching of load timing information. 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnHeadersComplete(); 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notifies the network delegate that the request has been completed. 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This does not imply a successful completion. Also a canceled request is 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // considered completed. 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyRequestCompleted(); 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by URLRequestJob to allow interception when the final response 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // occurs. 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyResponseStarted(); 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These functions delegate to |delegate_| and may only be used if 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |delegate_| is not NULL. See URLRequest::Delegate for the meaning 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of these functions. 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyAuthRequired(AuthChallengeInfo* auth_info); 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyAuthRequiredComplete(NetworkDelegate::AuthRequiredResponse result); 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyCertificateRequested(SSLCertRequestInfo* cert_request_info); 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifySSLCertificateError(const SSLInfo& ssl_info, bool fatal); 7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyReadCompleted(int bytes_read); 7672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These functions delegate to |network_delegate_| if it is not NULL. 7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If |network_delegate_| is NULL, cookies can be used unless 7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // SetDefaultCookiePolicyToBlock() has been called. 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanGetCookies(const CookieList& cookie_list) const; 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanSetCookie(const std::string& cookie_line, 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CookieOptions* options) const; 77490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool CanEnablePrivacyMode() const; 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Called just before calling a delegate that may block a request. 7771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void OnCallToDelegate(); 7781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Called when the delegate lets a request continue. Also called on 7791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // cancellation. 7801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void OnCallToDelegateComplete(); 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Contextual information used for this request. Cannot be NULL. This contains 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // most of the dependencies which are shared between requests (disk cache, 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cookie store, socket pool, etc.) 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const URLRequestContext* context_; 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NetworkDelegate* network_delegate_; 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tracks the time spent in various load states throughout this request. 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BoundNetLog net_log_; 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<URLRequestJob> job_; 7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<UploadDataStream> upload_data_stream_; 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<GURL> url_chain_; 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL first_party_for_cookies_; 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL delegate_redirect_url_; 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string method_; // "GET", "POST", etc. Should be all uppercase. 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string referrer_; 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ReferrerPolicy referrer_policy_; 8006e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) FirstPartyURLPolicy first_party_url_policy_; 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpRequestHeaders extra_request_headers_; 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int load_flags_; // Flags indicating the request type for the load; 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // expected values are LOAD_* enums above. 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Never access methods of the |delegate_| directly. Always use the 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notify... methods for this. 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate_; 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Current error status of the job. When no error has been encountered, this 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be SUCCESS. If multiple errors have been encountered, this will be 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the first non-SUCCESS status seen. 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequestStatus status_; 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The HTTP response info, lazily initialized. 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo response_info_; 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tells us whether the job is outstanding. This is true from the time 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Start() is called to the time we dispatch RequestComplete and indicates 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // whether the job is active. 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_pending_; 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates if the request is in the process of redirecting to a new 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // location. It is true from the time the headers complete until a 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // new request begins. 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_redirecting_; 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Number of times we're willing to redirect. Used to guard against 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // infinite redirects. 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int redirect_limit_; 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cached value for use after we've orphaned the job handling the 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first transaction in a request involving redirects. 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UploadProgress final_upload_progress_; 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The priority level for this request. Objects like 836f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // ClientSocketPool use this to determine which URLRequest to 837f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // allocate sockets to first. 8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestPriority priority_; 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(battre): The only consumer of the identifier_ is currently the 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // web request API. We need to match identifiers of requests between the 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // web request API and the web navigation API. As the URLRequest does not 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // exist when the web navigation API is triggered, the tracking probably 8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // needs to be done outside of the URLRequest anyway. Therefore, this 8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // identifier should be deleted here. http://crbug.com/89321 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A globally unique identifier for this request. 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64 identifier_; 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // True if this request is currently calling a delegate, or is blocked waiting 8501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // for the URL request or network delegate to resume it. 8511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool calling_delegate_; 8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 853a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // An optional parameter that provides additional information about what 854a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // |this| is currently being blocked by. 855a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) std::string blocked_by_; 856a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool use_blocked_by_as_load_param_; 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::debug::LeakTracker<URLRequest> leak_tracker_; 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback passed to the network delegate to notify us when a blocked request 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is ready to be resumed or canceled. 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CompletionCallback before_request_callback_; 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Safe-guard to ensure that we do not send multiple "I am completed" 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // messages to network delegate. 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(battre): Remove this. http://crbug.com/89049 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_notified_completion_; 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Authentication data used by the NetworkDelegate for this request, 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if one is present. |auth_credentials_| may be filled in when calling 8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |NotifyAuthRequired| on the NetworkDelegate. |auth_info_| holds 8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the authentication challenge being handled by |NotifyAuthRequired|. 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthCredentials auth_credentials_; 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<AuthChallengeInfo> auth_info_; 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 received_response_content_length_; 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks creation_time_; 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Timing information for the most recent request. Its start times are 8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // populated during Start(), and the rest are populated in OnResponseReceived. 8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LoadTimingInfo load_timing_info_; 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<const base::debug::StackTrace> stack_trace_; 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Keeps track of whether or not OnBeforeNetworkStart has been called yet. 8875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool notified_before_network_start_; 8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 889a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The cookie store to be used for this request. 890a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_refptr<CookieStore> cookie_store_; 891a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 892f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // The proxy server used for this request, if any. 893f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) HostPortPair proxy_server_; 894f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(URLRequest); 8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_URL_REQUEST_URL_REQUEST_H_ 901