#include "base/lazy_instance.h"
#include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h"
-#include "base/metrics/histogram.h"
#include "base/metrics/stats_counters.h"
#include "base/metrics/user_metrics.h"
#include "base/stl_util.h"
#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"
// URLRequest::Delegate
void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request,
- const GURL& new_url,
+ const RedirectInfo& redirect_info,
bool* defer_redirect) {
}
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;
return job_->GetResponseCookies(cookies);
}
-void URLRequest::GetMimeType(string* mime_type) {
+void URLRequest::GetMimeType(string* mime_type) const {
DCHECK(job_.get());
job_->GetMimeType(mime_type);
}
-void URLRequest::GetCharset(string* charset) {
+void URLRequest::GetCharset(string* charset) const {
DCHECK(job_.get());
job_->GetCharset(charset);
}
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;
void URLRequest::SetReferrer(const std::string& referrer) {
DCHECK(!is_pending_);
GURL referrer_url(referrer);
- UMA_HISTOGRAM_BOOLEAN("Net.URLRequest_SetReferrer_IsEmptyOrValid",
- referrer_url.is_empty() || referrer_url.is_valid());
if (referrer_url.is_valid()) {
referrer_ = referrer_url.GetAsReferrer().spec();
} else {
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.new_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.
}
}
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.new_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.new_url);
if (redirect_limit_ <= 0) {
DVLOG(1) << "disallowing redirect: exceeds limit";
return ERR_TOO_MANY_REDIRECTS;
}
- if (!location.is_valid())
+ if (!redirect_info.new_url.is_valid())
return ERR_INVALID_URL;
- if (!job_->IsSafeRedirect(location)) {
+ if (!job_->IsSafeRedirect(redirect_info.new_url)) {
DVLOG(1) << "disallowing redirect: unsafe protocol";
return ERR_UNSAFE_REDIRECT;
}
final_upload_progress_ = job_->GetUploadProgress();
PrepareToRestart();
- std::string new_method(ComputeMethodForRedirect(method_, http_status_code));
- if (new_method != method_) {
+ if (redirect_info.new_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
StripPostSpecificHeaders(&extra_request_headers_);
}
upload_data_stream_.reset();
- method_.swap(new_method);
+ method_ = redirect_info.new_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.new_referrer;
+ first_party_for_cookies_ = redirect_info.new_first_party_for_cookies;
- url_chain_.push_back(location);
+ url_chain_.push_back(redirect_info.new_url);
--redirect_limit_;
Start();