Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / net / url_request / url_request.h
index c6b5f6a..d8df8fe 100644 (file)
@@ -11,6 +11,7 @@
 #include "base/debug/leak_tracker.h"
 #include "base/logging.h"
 #include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
 #include "base/strings/string16.h"
 #include "base/supports_user_data.h"
 #include "base/threading/non_thread_safe.h"
 #include "net/url_request/url_request_status.h"
 #include "url/gurl.h"
 
-// Temporary layering violation to allow existing users of a deprecated
-// interface.
-class ChildProcessSecurityPolicyTest;
-
 namespace base {
 class Value;
 
@@ -47,13 +44,6 @@ class StackTrace;
 // interface.
 namespace content {
 class AppCacheInterceptor;
-class AppCacheURLRequestJobTest;
-class AppCacheRequestHandlerTest;
-class BlobURLRequestJobTest;
-class FileSystemDirURLRequestJobTest;
-class FileSystemURLRequestJobTest;
-class FileWriterDelegateTest;
-class ResourceDispatcherHostTest;
 }
 
 namespace net {
@@ -62,6 +52,7 @@ class CookieOptions;
 class HostPortPair;
 class IOBuffer;
 struct LoadTimingInfo;
+struct RedirectInfo;
 class SSLCertRequestInfo;
 class SSLInfo;
 class UploadDataStream;
@@ -119,10 +110,19 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
     NEVER_CLEAR_REFERRER,
   };
 
+  // First-party URL redirect policy: During server redirects, the first-party
+  // URL for cookies normally doesn't change. However, if the request is a
+  // top-level first-party request, the first-party URL should be updated to the
+  // URL on every redirect.
+  enum FirstPartyURLPolicy {
+    NEVER_CHANGE_FIRST_PARTY_URL,
+    UPDATE_FIRST_PARTY_URL_ON_REDIRECT,
+  };
+
   // This class handles network interception.  Use with
   // (Un)RegisterRequestInterceptor.
   class NET_EXPORT Interceptor {
-  public:
+   public:
     virtual ~Interceptor() {}
 
     // Called for every request made.  Should return a new job to handle the
@@ -160,21 +160,8 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
   class NET_EXPORT Deprecated {
    private:
     // TODO(willchan): Kill off these friend declarations.
-    friend class ::ChildProcessSecurityPolicyTest;
     friend class TestInterceptor;
-    friend class URLRequestFilter;
     friend class content::AppCacheInterceptor;
-    friend class content::AppCacheRequestHandlerTest;
-    friend class content::AppCacheURLRequestJobTest;
-    friend class content::BlobURLRequestJobTest;
-    friend class content::FileSystemDirURLRequestJobTest;
-    friend class content::FileSystemURLRequestJobTest;
-    friend class content::FileWriterDelegateTest;
-    friend class content::ResourceDispatcherHostTest;
-
-    // Use URLRequestJobFactory::ProtocolHandler instead.
-    static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
-                                                    ProtocolFactory* factory);
 
     // TODO(pauljensen): Remove this when AppCacheInterceptor is a
     // ProtocolHandler, see crbug.com/161547.
@@ -209,10 +196,10 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
   //
   class NET_EXPORT Delegate {
    public:
-    // Called upon a server-initiated redirect.  The delegate may call the
-    // request's Cancel method to prevent the redirect from being followed.
-    // Since there may be multiple chained redirects, there may also be more
-    // than one redirect call.
+    // Called upon receiving a redirect.  The delegate may call the request's
+    // Cancel method to prevent the redirect from being followed.  Since there
+    // may be multiple chained redirects, there may also be more than one
+    // redirect call.
     //
     // When this function is called, the request will still contain the
     // original URL, the destination of the redirect is provided in 'new_url'.
@@ -226,7 +213,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
     // need to set it if they are happy with the default behavior of not
     // deferring redirect.
     virtual void OnReceivedRedirect(URLRequest* request,
-                                    const GURL& new_url,
+                                    const RedirectInfo& redirect_info,
                                     bool* defer_redirect);
 
     // Called when we receive an authentication failure.  The delegate should
@@ -287,20 +274,6 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
     virtual ~Delegate() {}
   };
 
-  // TODO(tburkard): we should get rid of this constructor, and have each
-  // creator of a URLRequest specifically list the cookie store to be used.
-  // For now, this constructor will use the cookie store in |context|.
-  URLRequest(const GURL& url,
-             RequestPriority priority,
-             Delegate* delegate,
-             const URLRequestContext* context);
-
-  URLRequest(const GURL& url,
-             RequestPriority priority,
-             Delegate* delegate,
-             const URLRequestContext* context,
-             CookieStore* cookie_store);
-
   // If destroyed after Start() has been called but while IO is pending,
   // then the request will be effectively canceled and the delegate
   // will not have any more of its methods called.
@@ -348,10 +321,17 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
   const GURL& first_party_for_cookies() const {
     return first_party_for_cookies_;
   }
-  // This method may be called before Start() or FollowDeferredRedirect() is
-  // called.
+  // This method may only be called before Start().
   void set_first_party_for_cookies(const GURL& first_party_for_cookies);
 
+  // The first-party URL policy to apply when updating the first party URL
+  // during redirects. The first-party URL policy may only be changed before
+  // Start() is called.
+  FirstPartyURLPolicy first_party_url_policy() const {
+    return first_party_url_policy_;
+  }
+  void set_first_party_url_policy(FirstPartyURLPolicy first_party_url_policy);
+
   // The request method, as an uppercase string.  "GET" is the default value.
   // The request method may only be changed before Start() is called and
   // should only be assigned an uppercase value.
@@ -374,6 +354,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
 
   // The referrer policy to apply when updating the referrer during redirects.
   // The referrer policy may only be changed before Start() is called.
+  ReferrerPolicy referrer_policy() const { return referrer_policy_; }
   void set_referrer_policy(ReferrerPolicy referrer_policy);
 
   // Sets the delegate of the request.  This value may be changed at any time,
@@ -539,11 +520,11 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
 
   // Get the mime type.  This method may only be called once the delegate's
   // OnResponseStarted method has been called.
-  void GetMimeType(std::string* mime_type);
+  void GetMimeType(std::string* mime_type) const;
 
   // Get the charset (character encoding).  This method may only be called once
   // the delegate's OnResponseStarted method has been called.
-  void GetCharset(std::string* charset);
+  void GetCharset(std::string* charset) const;
 
   // Returns the HTTP response code (e.g., 200, 404, and so on).  This method
   // may only be called once the delegate's OnResponseStarted method has been
@@ -685,10 +666,16 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
   void set_received_response_content_length(int64 received_content_length) {
     received_response_content_length_ = received_content_length;
   }
-  int64 received_response_content_length() {
+  int64 received_response_content_length() const {
     return received_response_content_length_;
   }
 
+  // Available at NetworkDelegate::NotifyHeadersReceived() time, which is before
+  // the more general response_info() is available, even though it is a subset.
+  const HostPortPair& proxy_server() const {
+    return proxy_server_;
+  }
+
  protected:
   // Allow the URLRequestJob class to control the is_pending() flag.
   void set_is_pending(bool value) { is_pending_ = value; }
@@ -696,14 +683,15 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
   // Allow the URLRequestJob class to set our status too
   void set_status(const URLRequestStatus& value) { status_ = value; }
 
-  CookieStore* cookie_store() const { return cookie_store_; }
+  CookieStore* cookie_store() const { return cookie_store_.get(); }
 
   // Allow the URLRequestJob to redirect this request.  Returns OK if
   // successful, otherwise an error code is returned.
-  int Redirect(const GURL& location, int http_status_code);
+  int Redirect(const RedirectInfo& redirect_info);
 
   // Called by URLRequestJob to allow interception when a redirect occurs.
-  void NotifyReceivedRedirect(const GURL& location, bool* defer_redirect);
+  void NotifyReceivedRedirect(const RedirectInfo& redirect_info,
+                              bool* defer_redirect);
 
   // Called by URLRequestHttpJob (note, only HTTP(S) jobs will call this) to
   // allow deferral of network initialization.
@@ -715,37 +703,23 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
 
  private:
   friend class URLRequestJob;
+  friend class URLRequestContext;
 
-  // Registers a new protocol handler for the given scheme. If the scheme is
-  // already handled, this will overwrite the given factory. To delete the
-  // protocol factory, use NULL for the factory BUT this WILL NOT put back
-  // any previously registered protocol factory. It will have returned
-  // the previously registered factory (or NULL if none is registered) when
-  // the scheme was first registered so that the caller can manually put it
-  // back if desired.
-  //
-  // The scheme must be all-lowercase ASCII. See the ProtocolFactory
-  // declaration for its requirements.
-  //
-  // The registered protocol factory may return NULL, which will cause the
-  // regular "built-in" protocol factory to be used.
+  // URLRequests are always created by calling URLRequestContext::CreateRequest.
   //
-  static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme,
-                                                  ProtocolFactory* factory);
+  // If no cookie store or network delegate are passed in, will use the ones
+  // from the URLRequestContext.
+  URLRequest(const GURL& url,
+             RequestPriority priority,
+             Delegate* delegate,
+             const URLRequestContext* context,
+             CookieStore* cookie_store,
+             NetworkDelegate* network_delegate);
 
   // Registers or unregisters a network interception class.
   static void RegisterRequestInterceptor(Interceptor* interceptor);
   static void UnregisterRequestInterceptor(Interceptor* interceptor);
 
-  // Initializes the URLRequest. Code shared between the two constructors.
-  // TODO(tburkard): This can ultimately be folded into a single constructor
-  // again.
-  void Init(const GURL& url,
-            RequestPriority priotity,
-            Delegate* delegate,
-            const URLRequestContext* context,
-            CookieStore* cookie_store);
-
   // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest
   // handler. If |blocked| is true, the request is blocked and an error page is
   // returned indicating so. This should only be called after Start is called
@@ -823,6 +797,7 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
   std::string method_;  // "GET", "POST", etc. Should be all uppercase.
   std::string referrer_;
   ReferrerPolicy referrer_policy_;
+  FirstPartyURLPolicy first_party_url_policy_;
   HttpRequestHeaders extra_request_headers_;
   int load_flags_;  // Flags indicating the request type for the load;
                     // expected values are LOAD_* enums above.
@@ -914,6 +889,9 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe),
   // The cookie store to be used for this request.
   scoped_refptr<CookieStore> cookie_store_;
 
+  // The proxy server used for this request, if any.
+  HostPortPair proxy_server_;
+
   DISALLOW_COPY_AND_ASSIGN(URLRequest);
 };