url_request.h revision f2477e01787aa58f445919b809d89e252beef54f
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" 14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/supports_user_data.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/non_thread_safe.h" 17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/completion_callback.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/load_states.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/load_timing_info.h" 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_log.h" 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/network_delegate.h" 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/request_priority.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/upload_progress.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/canonical_cookie.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_request_headers.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_response_info.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/url_request/url_request_status.h" 317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h" 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ChildProcessSecurityPolicyTest; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestAutomationProvider; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestAutomationJob; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class Value; 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace debug { 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class StackTrace; 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace debug 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} // namespace base 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface. 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace appcache { 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheInterceptor; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheRequestHandlerTest; 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AppCacheURLRequestJobTest; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ResourceDispatcherHostTest; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace fileapi { 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemDirURLRequestJobTest; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileSystemURLRequestJobTest; 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FileWriterDelegateTest; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Temporary layering violation to allow existing users of a deprecated 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// interface. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace webkit_blob { 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BlobURLRequestJobTest; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CookieOptions; 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HostPortPair; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IOBuffer; 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct LoadTimingInfo; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLCertRequestInfo; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLInfo; 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class UploadDataStream; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestContext; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestJob; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class X509Certificate; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This stores the values of the Set-Cookie headers received during the request. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Each item in the vector corresponds to a Set-Cookie: line received, 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// excluding the "Set-Cookie:" part. 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<std::string> ResponseCookies; 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//----------------------------------------------------------------------------- 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A class representing the asynchronous load of a data stream from an URL. 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The lifetime of an instance of this class is completely controlled by the 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// consumer, and the instance is not required to live on the heap or be 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// allocated in any special way. It is also valid to delete an URLRequest 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// object during the handling of a callback to its delegate. Of course, once 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the URLRequest is deleted, no further callbacks to its delegate will occur. 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: All usage of all instances of this class should be on the same thread. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public base::SupportsUserData { 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback function implemented by protocol handlers to create new jobs. 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The factory may return NULL to indicate an error, which will cause other 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // factories to be queried. If no factory handles the request, then the 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // default job will be used. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef URLRequestJob* (ProtocolFactory)(URLRequest* request, 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NetworkDelegate* network_delegate, 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& scheme); 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // HTTP request/response header IDs (via some preprocessor fun) for use with 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetRequestHeaderById and GetResponseHeaderById. 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum { 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define HTTP_ATOM(x) HTTP_ ## x, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_atom_list.h" 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#undef HTTP_ATOM 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Referrer policies (see set_referrer_policy): During server redirects, the 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // referrer header might be cleared, if the protocol changes from HTTPS to 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // HTTP. This is the default behavior of URLRequest, corresponding to 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE. Alternatively, the 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // referrer policy can be set to never change the referrer header. This 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // behavior corresponds to NEVER_CLEAR_REFERRER. Embedders will want to use 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NEVER_CLEAR_REFERRER when implementing the meta-referrer support 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (http://wiki.whatwg.org/wiki/Meta_referrer) and sending requests with a 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // non-default referrer policy. Only the default referrer policy requires 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the referrer to be cleared on transitions from HTTPS to HTTP. 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum ReferrerPolicy { 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NEVER_CLEAR_REFERRER, 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Used with SetDelegateInfo to indicate how the string should be used. 1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // DELEGATE_INFO_DEBUG_ONLY indicates it should only be used when logged to 1401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NetLog, while DELEGATE_INFO_DISPLAY_TO_USER indicates it should also be 1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // returned by calls to GetLoadState for display to the user. 1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) enum DelegateInfoUsage { 1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DELEGATE_INFO_DEBUG_ONLY, 1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DELEGATE_INFO_DISPLAY_TO_USER, 1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }; 1461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This class handles network interception. Use with 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (Un)RegisterRequestInterceptor. 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class NET_EXPORT Interceptor { 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Interceptor() {} 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called for every request made. Should return a new job to handle the 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request if it should be intercepted, or NULL to allow the request to 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be handled in the normal manner. 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual URLRequestJob* MaybeIntercept( 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, NetworkDelegate* network_delegate) = 0; 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called after having received a redirect response, but prior to the 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the request delegate being informed of the redirect. Can return a new 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // job to replace the existing job if it should be intercepted, or NULL 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to allow the normal handling to continue. If a new job is provided, 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the delegate never sees the original redirect response, instead the 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response produced by the intercept job will be returned. 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual URLRequestJob* MaybeInterceptRedirect( 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NetworkDelegate* network_delegate, 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& location); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called after having received a final response, but prior to the 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the request delegate being informed of the response. This is also 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // called when there is no server response at all to allow interception 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on dns or network errors. Can return a new job to replace the existing 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // job if it should be intercepted, or NULL to allow the normal handling to 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // continue. If a new job is provided, the delegate never sees the original 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response, instead the response produced by the intercept job will be 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returned. 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual URLRequestJob* MaybeInterceptResponse( 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, NetworkDelegate* network_delegate); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Deprecated interfaces in net::URLRequest. They have been moved to 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLRequest's private section to prevent new uses. Existing uses are 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // explicitly friended here and should be removed over time. 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class NET_EXPORT Deprecated { 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(willchan): Kill off these friend declarations. 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class ::ChildProcessSecurityPolicyTest; 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class ::TestAutomationProvider; 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class ::URLRequestAutomationJob; 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class TestInterceptor; 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class URLRequestFilter; 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class appcache::AppCacheInterceptor; 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class appcache::AppCacheRequestHandlerTest; 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class appcache::AppCacheURLRequestJobTest; 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class content::ResourceDispatcherHostTest; 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class fileapi::FileSystemDirURLRequestJobTest; 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class fileapi::FileSystemURLRequestJobTest; 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class fileapi::FileWriterDelegateTest; 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class webkit_blob::BlobURLRequestJobTest; 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use URLRequestJobFactory::ProtocolHandler instead. 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProtocolFactory* factory); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(pauljensen): Remove this when AppCacheInterceptor is a 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // ProtocolHandler, see crbug.com/161547. 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void RegisterRequestInterceptor(Interceptor* interceptor); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void UnregisterRequestInterceptor(Interceptor* interceptor); 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_IMPLICIT_CONSTRUCTORS(Deprecated); 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The delegate's methods are called from the message loop of the thread 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on which the request's Start() method is called. See above for the 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ordering of callbacks. 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The callbacks will be called in the following order: 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Start() 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnCertificateRequested* (zero or more calls, if the SSL server and/or 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SSL proxy requests a client certificate for authentication) 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnSSLCertificateError* (zero or one call, if the SSL server's 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // certificate has an error) 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnReceivedRedirect* (zero or more calls, for the number of redirects) 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnAuthRequired* (zero or more calls, for the number of 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // authentication failures) 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnResponseStarted 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read() initiated by delegate 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // - OnReadCompleted* (zero or more calls until all data is read) 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read() must be called at least once. Read() returns true when it completed 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // immediately, and false if an IO is pending or if there is an error. When 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read() returns false, the caller can check the Request's status() to see 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if an error occurred, or if the IO is just pending. When Read() returns 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // true with zero bytes read, it indicates the end of the response. 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class NET_EXPORT Delegate { 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called upon a server-initiated redirect. The delegate may call the 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request's Cancel method to prevent the redirect from being followed. 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Since there may be multiple chained redirects, there may also be more 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // than one redirect call. 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When this function is called, the request will still contain the 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // original URL, the destination of the redirect is provided in 'new_url'. 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the delegate does not cancel the request and |*defer_redirect| is 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false, then the redirect will be followed, and the request's URL will be 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // changed to the new URL. Otherwise if the delegate does not cancel the 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request and |*defer_redirect| is true, then the redirect will be 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // followed once FollowDeferredRedirect is called on the URLRequest. 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The caller must set |*defer_redirect| to false, so that delegates do not 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // need to set it if they are happy with the default behavior of not 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // deferring redirect. 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnReceivedRedirect(URLRequest* request, 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& new_url, 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool* defer_redirect); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when we receive an authentication failure. The delegate should 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // call request->SetAuth() with the user's credentials once it obtains them, 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or request->CancelAuth() to cancel the login and display the error page. 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When it does so, the request will be reissued, restarting the sequence 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of On* callbacks. 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnAuthRequired(URLRequest* request, 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthChallengeInfo* auth_info); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when we receive an SSL CertificateRequest message for client 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // authentication. The delegate should call 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request->ContinueWithCertificate() with the client certificate the user 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // selected, or request->ContinueWithCertificate(NULL) to continue the SSL 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // handshake without a client certificate. 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnCertificateRequested( 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest* request, 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SSLCertRequestInfo* cert_request_info); 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when using SSL and the server responds with a certificate with 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // an error, for example, whose common name does not match the common name 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // we were expecting for that host. The delegate should either do the 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // safe thing and Cancel() the request or decide to proceed by calling 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ContinueDespiteLastError(). cert_error is a ERR_* error code 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // indicating what's wrong with the certificate. 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |fatal| is true then the host in question demands a higher level 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of security (due e.g. to HTTP Strict Transport Security, user 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // preference, or built-in policy). In this case, errors must not be 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // bypassable by the user. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnSSLCertificateError(URLRequest* request, 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SSLInfo& ssl_info, 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool fatal); 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // After calling Start(), the delegate will receive an OnResponseStarted 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // callback when the request has completed. If an error occurred, the 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request->status() will be set. On success, all redirects have been 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // followed and the final response is beginning to arrive. At this point, 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // meta data about the response is available, including for example HTTP 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response headers if this is a request for a HTTP resource. 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnResponseStarted(URLRequest* request) = 0; 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called when the a Read of the response body is completed after an 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IO_PENDING status from a Read() call. 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The data read is filled into the buffer which the caller passed 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to Read() previously. 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If an error occurred, request->status() will contain the error, 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and bytes read will be -1. 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~Delegate() {} 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequest(const GURL& url, 3120f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) RequestPriority priority, 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate, 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const URLRequestContext* context); 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If destroyed after Start() has been called but while IO is pending, 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // then the request will be effectively canceled and the delegate 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will not have any more of its methods called. 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~URLRequest(); 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Changes the default cookie policy from allowing all cookies to blocking all 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cookies. Embedders that want to implement a more flexible policy should 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // change the default to blocking all cookies, and provide a NetworkDelegate 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // with the URLRequestContext that maintains the CookieStore. 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The cookie policy default has to be set before the first URLRequest is 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // started. Once it was set to block all cookies, it cannot be changed back. 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void SetDefaultCookiePolicyToBlock(); 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the scheme can be handled by URLRequest. False otherwise. 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsHandledProtocol(const std::string& scheme); 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the url can be handled by URLRequest. False otherwise. 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The function returns true for invalid urls because URLRequest knows how 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to handle those. 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: This will also return true for URLs that are handled by 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ProtocolFactories that only work for requests that are scoped to a 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Profile. 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsHandledURL(const GURL& url); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The original url is the url used to initialize the request, and it may 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // differ from the url if the request was redirected. 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& original_url() const { return url_chain_.front(); } 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The chain of urls traversed by this request. If the request had no 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // redirects, this vector will contain one element. 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::vector<GURL>& url_chain() const { return url_chain_; } 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url() const { return url_chain_.back(); } 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The URL that should be consulted for the third-party cookie blocking 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // policy. 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WARNING: This URL must only be used for the third-party cookie blocking 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // policy. It MUST NEVER be used for any kind of SECURITY check. 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For example, if a top-level navigation is redirected, the 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first-party for cookies will be the URL of the first URL in the 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // redirect chain throughout the whole redirect. If it was used for 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a security check, an attacker might try to get around this check 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // by starting from some page that redirects to the 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // host-to-be-attacked. 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& first_party_for_cookies() const { 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return first_party_for_cookies_; 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method may be called before Start() or FollowDeferredRedirect() is 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // called. 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_first_party_for_cookies(const GURL& first_party_for_cookies); 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request method, as an uppercase string. "GET" is the default value. 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The request method may only be changed before Start() is called and 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // should only be assigned an uppercase value. 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& method() const { return method_; } 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_method(const std::string& method); 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3739ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // Determines the new method of the request afer following a redirect. 3749ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // |method| is the method used to arrive at the redirect, 3759ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch // |http_status_code| is the status code associated with the redirect. 3769ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch static std::string ComputeMethodForRedirect(const std::string& method, 3779ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch int http_status_code); 3789ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The referrer URL for the request. This header may actually be suppressed 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // from the underlying network request for security reasons (e.g., a HTTPS 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL will not be sent as the referrer for a HTTP request). The referrer 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // may only be changed before Start() is called. 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& referrer() const { return referrer_; } 384c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Referrer is sanitized to remove URL fragment, user name and password. 385c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void SetReferrer(const std::string& referrer); 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The referrer policy to apply when updating the referrer during redirects. 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The referrer policy may only be changed before Start() is called. 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_referrer_policy(ReferrerPolicy referrer_policy); 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the delegate of the request. This value may be changed at any time, 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and it is permissible for it to be null. 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_delegate(Delegate* delegate); 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates that the request body should be sent using chunked transfer 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // encoding. This method may only be called before Start() is called. 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void EnableChunkedUpload(); 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Appends the given bytes to the request's upload data to be sent 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // immediately via chunked transfer encoding. When all data has been sent, 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // call MarkEndOfChunks() to indicate the end of upload data. 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method may be called only after calling EnableChunkedUpload(). 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AppendChunkToUpload(const char* bytes, 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int bytes_len, 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_last_chunk); 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the upload data. 4092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void set_upload(scoped_ptr<UploadDataStream> upload); 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets the upload data. 4122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const UploadDataStream* get_upload() const; 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the request has a non-empty message body to upload. 4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_upload() const; 4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Set an extra request header by ID or name, or remove one by name. These 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // methods may only be called before Start() is called, or before a new 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // redirect in the request chain. 4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetExtraRequestHeaderById(int header_id, const std::string& value, 4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool overwrite); 4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetExtraRequestHeaderByName(const std::string& name, 4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& value, bool overwrite); 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void RemoveRequestHeaderByName(const std::string& name); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets all extra request headers. Any extra request headers set by other 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // methods are overwritten by this method. This method may only be called 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // before Start() is called. It is an error to call it later. 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetExtraRequestHeaders(const HttpRequestHeaders& headers); 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const HttpRequestHeaders& extra_request_headers() const { 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return extra_request_headers_; 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 435eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Gets the full request headers sent to the server. 436eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 437eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // Return true and overwrites headers if it can get the request headers; 438eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // otherwise, returns false and does not modify headers. (Always returns 439eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // false for request types that don't have headers, like file requests.) 440eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 441eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // This is guaranteed to succeed if: 442eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 443eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 1. A redirect or auth callback is currently running. Once it ends, the 444eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // headers may become unavailable as a new request with the new address 445eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // or credentials is made. 446eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 447eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch // 2. The OnResponseStarted callback is currently running or has run. 448eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch bool GetFullRequestHeaders(HttpRequestHeaders* headers) const; 449eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the current load state for the request. |param| is an optional 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // parameter describing details related to the load state. Not all load states 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // have a parameter. 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LoadStateWithParam GetLoadState() const; 4541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 4551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Returns a partial representation of the request's state as a value, for 4561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // debugging. Caller takes ownership of returned value. 4571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) base::Value* GetStateAsValue() const; 4581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 4591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Logs information about the delegate currently blocking the request. 4601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // The delegate info must be cleared by sending NULL before resuming a 4611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // request. |delegate_info| will be copied as needed. |delegate_info_usage| 4621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // is used to indicate whether the value should be returned in the param field 4631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // of GetLoadState. |delegate_info_usage_| is ignored when |delegate_info| is 4641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // NULL. 4651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void SetDelegateInfo(const char* delegate_info, 4661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DelegateInfoUsage delegate_info_usage); 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the current upload progress in bytes. When the upload data is 4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // chunked, size is set to zero, but position will not be. 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UploadProgress GetUploadProgress() const; 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get response header(s) by ID or name. These methods may only be called 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // once the delegate's OnResponseStarted method has been called. Headers 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that appear more than once in the response are coalesced, with values 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // separated by commas (per RFC 2616). This will not work with cookies since 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // comma can be used in cookie values. 4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(darin): add API to enumerate response headers. 4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetResponseHeaderById(int header_id, std::string* value); 4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetResponseHeaderByName(const std::string& name, std::string* value); 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get all response headers, \n-delimited and \n\0-terminated. This includes 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the response status line. Restrictions on GetResponseHeaders apply. 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetAllResponseHeaders(std::string* headers); 4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time when |this| was constructed. 4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks creation_time() const { return creation_time_; } 4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the returned response was requested. For cached 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // responses, this is the last time the cache entry was validated. 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Time& request_time() const { 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.request_time; 4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the returned response was generated. For cached 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // responses, this is the last time the cache entry was validated. 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::Time& response_time() const { 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.response_time; 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicate if this response was fetched from disk cache. 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_cached() const { return response_info_.was_cached; } 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the URLRequest was delivered through a proxy. 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_fetched_via_proxy() const { 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.was_fetched_via_proxy; 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the host and port that the content was fetched from. See 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http_response_info.h for caveats relating to cached content. 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HostPortPair GetSocketAddress() const; 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get all response headers, as a HttpResponseHeaders object. See comments 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in HttpResponseHeaders class as to the format of the data. 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseHeaders* response_headers() const; 5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the SSL connection info. 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SSLInfo& ssl_info() const { 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return response_info_.ssl_info; 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Gets timing information related to the request. Events that have not yet 5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // occurred are left uninitialized. After a second request starts, due to 5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // a redirect or authentication, values will be reset. 5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 5252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // LoadTimingInfo only contains ConnectTiming information and socket IDs for 5262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // non-cached HTTP responses. 5272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const; 5282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the cookie values included in the response, if the request is one 5305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that can have cookies. Returns true if the request is a cookie-bearing 5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // type, false otherwise. This method may only be called once the 5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // delegate's OnResponseStarted method has been called. 5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetResponseCookies(ResponseCookies* cookies); 5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the mime type. This method may only be called once the delegate's 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // OnResponseStarted method has been called. 5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetMimeType(std::string* mime_type); 5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the charset (character encoding). This method may only be called once 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the delegate's OnResponseStarted method has been called. 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetCharset(std::string* charset); 5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the HTTP response code (e.g., 200, 404, and so on). This method 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // may only be called once the delegate's OnResponseStarted method has been 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // called. For non-HTTP requests, this method returns -1. 54658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) int GetResponseCode() const; 5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the HTTP response info in its entirety. 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const HttpResponseInfo& response_info() const { return response_info_; } 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Access the LOAD_* flags modifying this request (see load_flags.h). 5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int load_flags() const { return load_flags_; } 553f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 554f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The new flags may change the IGNORE_LIMITS flag only when called 555f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // before Start() is called, it must only set the flag, and if set, 556f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // the priority of this request must already be MAXIMUM_PRIORITY. 557f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void SetLoadFlags(int flags); 5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the request is "pending" (i.e., if Start() has been called, 5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and the response has not yet been called). 5615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_pending() const { return is_pending_; } 5625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the request is in the process of redirecting to a new 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL but has not yet initiated the new request. 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_redirecting() const { return is_redirecting_; } 5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the error status of the request. 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const URLRequestStatus& status() const { return status_; } 5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a globally unique identifier for this request. 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64 identifier() const { return identifier_; } 5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method is called to start the request. The delegate will receive 5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a OnResponseStarted callback when the request is started. 5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Start(); 5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method may be called at any time after Start() has been called to 5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancel the request. This method may be called many times, and it has 5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no effect once the response has completed. It is guaranteed that no 5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // methods of the delegate will be called after the request has been 5815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancelled, except that this may call the delegate's OnReadCompleted() 5825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // during the call to Cancel itself. 5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Cancel(); 5845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels the request and sets the error to |error| (see net_error_list.h 5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for values). 5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CancelWithError(int error); 5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels the request and sets the error to |error| (see net_error_list.h 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for values) and attaches |ssl_info| as the SSLInfo for that request. This 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is useful to attach a certificate and certificate error to a canceled 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request. 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CancelWithSSLError(int error, const SSLInfo& ssl_info); 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Read initiates an asynchronous read from the response, and must only 5965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be called after the OnResponseStarted callback is received with a 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // successful status. 5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If data is available, Read will return true, and the data and length will 5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be returned immediately. If data is not available, Read returns false, 6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and an asynchronous Read is initiated. The Read is finished when 6015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the caller receives the OnReadComplete callback. Unless the request was 6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancelled, OnReadComplete will always be called, even if the read failed. 6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The buf parameter is a buffer to receive the data. If the operation 6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // completes asynchronously, the implementation will reference the buffer 6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // until OnReadComplete is called. The buffer must be at least max_bytes in 6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // length. 6085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The max_bytes parameter is the maximum number of bytes to read. 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The bytes_read parameter is an output parameter containing the 6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the number of bytes read. A value of 0 indicates that there is no 6135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // more data available to read from the stream. 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If a read error occurs, Read returns false and the request->status 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be set to an error. 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool Read(IOBuffer* buf, int max_bytes, int* bytes_read); 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this request is being cached by the HTTP cache, stop subsequent caching. 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note that this method has no effect on other (simultaneous or not) requests 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for the same resource. The typical example is a request that results in 6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the data being stored to disk (downloaded instead of rendered) so we don't 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // want to store it twice. 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StopCaching(); 6255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method may be called to follow a redirect that was deferred in 6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // response to an OnReceivedRedirect call. 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void FollowDeferredRedirect(); 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // One of the following two methods should be called in response to an 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // OnAuthRequired() callback (and only then). 6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetAuth will reissue the request with the given credentials. 6335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // CancelAuth will give up and display the error page. 6345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetAuth(const AuthCredentials& credentials); 6355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CancelAuth(); 6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method can be called after the user selects a client certificate to 6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // instruct this URLRequest to continue with the request with the 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // certificate. Pass NULL if the user doesn't have a client certificate. 6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ContinueWithCertificate(X509Certificate* client_cert); 6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This method can be called after some error notifications to instruct this 6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLRequest to ignore the current error and continue with the request. To 6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cancel the request instead, call Cancel(). 6455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ContinueDespiteLastError(); 6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used to specify the context (cookie store, cache) for this request. 6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const URLRequestContext* context() const; 6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const BoundNetLog& net_log() const { return net_log_; } 6515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the expected content size if available 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 GetExpectedContentSize() const; 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the priority level for this request. 6565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestPriority priority() const { return priority_; } 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 658f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Sets the priority level for this request and any related 659f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // jobs. Must not change the priority to anything other than 660f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // MAXIMUM_PRIORITY if the IGNORE_LIMITS load flag is set. 6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void SetPriority(RequestPriority priority); 6625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true iff this request would be internally redirected to HTTPS 6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // due to HSTS. If so, |redirect_url| is rewritten to the new HTTPS URL. 6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetHSTSRedirect(GURL* redirect_url) const; 6665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(willchan): Undo this. Only temporarily public. 6685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_delegate() const { return delegate_ != NULL; } 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE(willchan): This is just temporary for debugging 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // http://crbug.com/90971. 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allows to setting debug info into the URLRequest. 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_stack_trace(const base::debug::StackTrace& stack_trace); 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const base::debug::StackTrace* stack_trace() const; 6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_received_response_content_length(int64 received_content_length) { 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) received_response_content_length_ = received_content_length; 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 received_response_content_length() { 6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return received_response_content_length_; 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow the URLRequestJob class to control the is_pending() flag. 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_is_pending(bool value) { is_pending_ = value; } 6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow the URLRequestJob class to set our status too 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_status(const URLRequestStatus& value) { status_ = value; } 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow the URLRequestJob to redirect this request. Returns OK if 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // successful, otherwise an error code is returned. 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int Redirect(const GURL& location, int http_status_code); 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by URLRequestJob to allow interception when a redirect occurs. 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect); 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Allow an interceptor's URLRequestJob to restart this request. 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Should only be called if the original job has not started a response. 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Restart(); 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class URLRequestJob; 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Registers a new protocol handler for the given scheme. If the scheme is 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // already handled, this will overwrite the given factory. To delete the 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // protocol factory, use NULL for the factory BUT this WILL NOT put back 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // any previously registered protocol factory. It will have returned 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the previously registered factory (or NULL if none is registered) when 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the scheme was first registered so that the caller can manually put it 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // back if desired. 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The scheme must be all-lowercase ASCII. See the ProtocolFactory 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // declaration for its requirements. 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The registered protocol factory may return NULL, which will cause the 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // regular "built-in" protocol factory to be used. 7175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ProtocolFactory* factory); 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Registers or unregisters a network interception class. 7225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void RegisterRequestInterceptor(Interceptor* interceptor); 7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void UnregisterRequestInterceptor(Interceptor* interceptor); 7245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // handler. If |blocked| is true, the request is blocked and an error page is 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returned indicating so. This should only be called after Start is called 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and OnBeforeRequest returns true (signalling that the request should be 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // paused). 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void BeforeRequestComplete(int error); 7315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StartJob(URLRequestJob* job); 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Restarting involves replacing the current job with a new one such as what 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // happens when following a HTTP redirect. 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RestartWithJob(URLRequestJob* job); 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void PrepareToRestart(); 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Detaches the job from this request in preparation for this object going 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // away or the job being replaced. The job will not call us back when it has 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // been orphaned. 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OrphanJob(); 7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cancels the request and set the error and ssl info for this request to the 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // passed values. 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DoCancel(int error, const SSLInfo& ssl_info); 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called by the URLRequestJob when the headers are received, before any other 7492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // method, to allow caching of load timing information. 7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnHeadersComplete(); 7512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notifies the network delegate that the request has been completed. 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This does not imply a successful completion. Also a canceled request is 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // considered completed. 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyRequestCompleted(); 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called by URLRequestJob to allow interception when the final response 7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // occurs. 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyResponseStarted(); 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These functions delegate to |delegate_| and may only be used if 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |delegate_| is not NULL. See URLRequest::Delegate for the meaning 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of these functions. 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyAuthRequired(AuthChallengeInfo* auth_info); 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyAuthRequiredComplete(NetworkDelegate::AuthRequiredResponse result); 7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifyCertificateRequested(SSLCertRequestInfo* cert_request_info); 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NotifySSLCertificateError(const SSLInfo& ssl_info, bool fatal); 7682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void NotifyReadCompleted(int bytes_read); 7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // These functions delegate to |network_delegate_| if it is not NULL. 7712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If |network_delegate_| is NULL, cookies can be used unless 7722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // SetDefaultCookiePolicyToBlock() has been called. 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanGetCookies(const CookieList& cookie_list) const; 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool CanSetCookie(const std::string& cookie_line, 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CookieOptions* options) const; 77690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool CanEnablePrivacyMode() const; 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Called just before calling a delegate that may block a request. 7791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void OnCallToDelegate(); 7801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Called when the delegate lets a request continue. Also called on 7811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // cancellation. 7821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void OnCallToDelegateComplete(); 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Contextual information used for this request. Cannot be NULL. This contains 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // most of the dependencies which are shared between requests (disk cache, 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cookie store, socket pool, etc.) 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const URLRequestContext* context_; 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NetworkDelegate* network_delegate_; 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tracks the time spent in various load states throughout this request. 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BoundNetLog net_log_; 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<URLRequestJob> job_; 7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<UploadDataStream> upload_data_stream_; 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<GURL> url_chain_; 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL first_party_for_cookies_; 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL delegate_redirect_url_; 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string method_; // "GET", "POST", etc. Should be all uppercase. 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string referrer_; 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ReferrerPolicy referrer_policy_; 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpRequestHeaders extra_request_headers_; 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int load_flags_; // Flags indicating the request type for the load; 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // expected values are LOAD_* enums above. 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Never access methods of the |delegate_| directly. Always use the 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Notify... methods for this. 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Delegate* delegate_; 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Current error status of the job. When no error has been encountered, this 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be SUCCESS. If multiple errors have been encountered, this will be 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the first non-SUCCESS status seen. 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) URLRequestStatus status_; 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The HTTP response info, lazily initialized. 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo response_info_; 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tells us whether the job is outstanding. This is true from the time 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Start() is called to the time we dispatch RequestComplete and indicates 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // whether the job is active. 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_pending_; 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Indicates if the request is in the process of redirecting to a new 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // location. It is true from the time the headers complete until a 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // new request begins. 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_redirecting_; 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Number of times we're willing to redirect. Used to guard against 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // infinite redirects. 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int redirect_limit_; 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cached value for use after we've orphaned the job handling the 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // first transaction in a request involving redirects. 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UploadProgress final_upload_progress_; 8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 836f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // The priority level for this request. Objects like 837f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // ClientSocketPool use this to determine which URLRequest to 838f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // allocate sockets to first. 8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RequestPriority priority_; 8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(battre): The only consumer of the identifier_ is currently the 8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // web request API. We need to match identifiers of requests between the 8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // web request API and the web navigation API. As the URLRequest does not 8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // exist when the web navigation API is triggered, the tracking probably 8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // needs to be done outside of the URLRequest anyway. Therefore, this 8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // identifier should be deleted here. http://crbug.com/89321 8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A globally unique identifier for this request. 8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const uint64 identifier_; 8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // True if this request is currently calling a delegate, or is blocked waiting 8511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // for the URL request or network delegate to resume it. 8521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool calling_delegate_; 8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // An optional parameter that provides additional information about the 8551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // delegate |this| is currently blocked on. 8561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string delegate_info_; 8571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DelegateInfoUsage delegate_info_usage_; 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::debug::LeakTracker<URLRequest> leak_tracker_; 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback passed to the network delegate to notify us when a blocked request 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is ready to be resumed or canceled. 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CompletionCallback before_request_callback_; 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Safe-guard to ensure that we do not send multiple "I am completed" 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // messages to network delegate. 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(battre): Remove this. http://crbug.com/89049 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool has_notified_completion_; 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Authentication data used by the NetworkDelegate for this request, 8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // if one is present. |auth_credentials_| may be filled in when calling 8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |NotifyAuthRequired| on the NetworkDelegate. |auth_info_| holds 8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the authentication challenge being handled by |NotifyAuthRequired|. 8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AuthCredentials auth_credentials_; 8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<AuthChallengeInfo> auth_info_; 8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 received_response_content_length_; 8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks creation_time_; 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Timing information for the most recent request. Its start times are 8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // populated during Start(), and the rest are populated in OnResponseReceived. 8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) LoadTimingInfo load_timing_info_; 8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<const base::debug::StackTrace> stack_trace_; 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(URLRequest); 8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_URL_REQUEST_URL_REQUEST_H_ 893