Index: net/url_request/url_request.cc |
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc |
index 5466be1b58943f2dd311a8faf190581b7e25b4d8..72397e99d83d1dae5702d4d0052b58960fbf280a 100644 |
--- a/net/url_request/url_request.cc |
+++ b/net/url_request/url_request.cc |
@@ -30,6 +30,7 @@ |
#include "net/http/http_response_headers.h" |
#include "net/http/http_util.h" |
#include "net/ssl/ssl_cert_request_info.h" |
+#include "net/url_request/redirect_info.h" |
#include "net/url_request/url_request_context.h" |
#include "net/url_request/url_request_error_job.h" |
#include "net/url_request/url_request_job.h" |
@@ -169,7 +170,7 @@ URLRequestJob* URLRequest::Interceptor::MaybeInterceptResponse( |
// URLRequest::Delegate |
void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request, |
- const GURL& new_url, |
+ const RedirectInfo& redirect_info, |
bool* defer_redirect) { |
} |
@@ -259,6 +260,7 @@ void URLRequest::Init(const GURL& url, |
url_chain_.push_back(url); |
method_ = "GET"; |
referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE; |
+ first_party_url_policy_ = NEVER_CHANGE_FIRST_PARTY_URL; |
load_flags_ = LOAD_NORMAL; |
delegate_ = delegate; |
is_pending_ = false; |
@@ -563,9 +565,16 @@ bool URLRequest::IsHandledURL(const GURL& url) { |
void URLRequest::set_first_party_for_cookies( |
const GURL& first_party_for_cookies) { |
+ DCHECK(!is_pending_); |
first_party_for_cookies_ = first_party_for_cookies; |
} |
+void URLRequest::set_first_party_url_policy( |
+ FirstPartyURLPolicy first_party_url_policy) { |
+ DCHECK(!is_pending_); |
+ first_party_url_policy_ = first_party_url_policy; |
+} |
+ |
void URLRequest::set_method(const std::string& method) { |
DCHECK(!is_pending_); |
method_ = method; |
@@ -822,18 +831,19 @@ void URLRequest::StopCaching() { |
job_->StopCaching(); |
} |
-void URLRequest::NotifyReceivedRedirect(const GURL& location, |
+void URLRequest::NotifyReceivedRedirect(const RedirectInfo& redirect_info, |
bool* defer_redirect) { |
is_redirecting_ = true; |
+ // TODO(davidben): Pass the full RedirectInfo down to MaybeInterceptRedirect? |
URLRequestJob* job = |
URLRequestJobManager::GetInstance()->MaybeInterceptRedirect( |
- this, network_delegate_, location); |
+ this, network_delegate_, redirect_info.url); |
if (job) { |
RestartWithJob(job); |
} else if (delegate_) { |
OnCallToDelegate(); |
- delegate_->OnReceivedRedirect(this, location, defer_redirect); |
+ delegate_->OnReceivedRedirect(this, redirect_info, defer_redirect); |
// |this| may be have been destroyed here. |
} |
} |
@@ -956,27 +966,29 @@ void URLRequest::OrphanJob() { |
job_ = NULL; |
} |
-int URLRequest::Redirect(const GURL& location, int http_status_code) { |
+int URLRequest::Redirect(const RedirectInfo& redirect_info) { |
// Matches call in NotifyReceivedRedirect. |
OnCallToDelegateComplete(); |
if (net_log_.IsLogging()) { |
net_log_.AddEvent( |
NetLog::TYPE_URL_REQUEST_REDIRECTED, |
- NetLog::StringCallback("location", &location.possibly_invalid_spec())); |
+ NetLog::StringCallback("location", |
+ &redirect_info.url.possibly_invalid_spec())); |
} |
+ // TODO(davidben): Pass the full RedirectInfo to the NetworkDelegate. |
if (network_delegate_) |
- network_delegate_->NotifyBeforeRedirect(this, location); |
+ network_delegate_->NotifyBeforeRedirect(this, redirect_info.url); |
if (redirect_limit_ <= 0) { |
DVLOG(1) << "disallowing redirect: exceeds limit"; |
return ERR_TOO_MANY_REDIRECTS; |
} |
- if (!location.is_valid()) |
+ if (!redirect_info.url.is_valid()) |
return ERR_INVALID_URL; |
- if (!job_->IsSafeRedirect(location)) { |
+ if (!job_->IsSafeRedirect(redirect_info.url)) { |
DVLOG(1) << "disallowing redirect: unsafe protocol"; |
return ERR_UNSAFE_REDIRECT; |
} |
@@ -985,8 +997,8 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { |
final_upload_progress_ = job_->GetUploadProgress(); |
PrepareToRestart(); |
- std::string new_method(ComputeMethodForRedirect(method_, http_status_code)); |
- if (new_method != method_) { |
+ if (redirect_info.method != method_) { |
+ // TODO(davidben): This logic still needs to be replicated at the consumers. |
if (method_ == "POST") { |
// If being switched from POST, must remove headers that were specific to |
// the POST and don't have meaning in other methods. For example the |
@@ -996,17 +1008,13 @@ int URLRequest::Redirect(const GURL& location, int http_status_code) { |
StripPostSpecificHeaders(&extra_request_headers_); |
} |
upload_data_stream_.reset(); |
- method_.swap(new_method); |
+ method_ = redirect_info.method; |
} |
- // Suppress the referrer if we're redirecting out of https. |
- if (referrer_policy_ == |
- CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE && |
- GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure()) { |
- referrer_.clear(); |
- } |
+ referrer_ = redirect_info.referrer; |
+ first_party_for_cookies_ = redirect_info.first_party_for_cookies; |
- url_chain_.push_back(location); |
+ url_chain_.push_back(redirect_info.url); |
--redirect_limit_; |
Start(); |