| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_request.h" | 5 #include "net/url_request/url_request.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 DCHECK(!is_pending_); | 448 DCHECK(!is_pending_); |
| 449 first_party_for_cookies_ = first_party_for_cookies; | 449 first_party_for_cookies_ = first_party_for_cookies; |
| 450 } | 450 } |
| 451 | 451 |
| 452 void URLRequest::set_first_party_url_policy( | 452 void URLRequest::set_first_party_url_policy( |
| 453 FirstPartyURLPolicy first_party_url_policy) { | 453 FirstPartyURLPolicy first_party_url_policy) { |
| 454 DCHECK(!is_pending_); | 454 DCHECK(!is_pending_); |
| 455 first_party_url_policy_ = first_party_url_policy; | 455 first_party_url_policy_ = first_party_url_policy; |
| 456 } | 456 } |
| 457 | 457 |
| 458 void URLRequest::set_insecure_request_policy( |
| 459 InsecureRequestPolicy insecure_request_policy) { |
| 460 DCHECK(!is_pending_); |
| 461 insecure_request_policy_ = insecure_request_policy; |
| 462 } |
| 463 |
| 458 void URLRequest::set_initiator(const url::Origin& initiator) { | 464 void URLRequest::set_initiator(const url::Origin& initiator) { |
| 459 DCHECK(!is_pending_); | 465 DCHECK(!is_pending_); |
| 460 initiator_ = initiator; | 466 initiator_ = initiator; |
| 461 } | 467 } |
| 462 | 468 |
| 463 void URLRequest::set_method(const std::string& method) { | 469 void URLRequest::set_method(const std::string& method) { |
| 464 DCHECK(!is_pending_); | 470 DCHECK(!is_pending_); |
| 465 method_ = method; | 471 method_ = method; |
| 466 } | 472 } |
| 467 | 473 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 | 1020 |
| 1015 priority_ = priority; | 1021 priority_ = priority; |
| 1016 if (job_.get()) { | 1022 if (job_.get()) { |
| 1017 net_log_.AddEvent( | 1023 net_log_.AddEvent( |
| 1018 NetLog::TYPE_URL_REQUEST_SET_PRIORITY, | 1024 NetLog::TYPE_URL_REQUEST_SET_PRIORITY, |
| 1019 NetLog::StringCallback("priority", RequestPriorityToString(priority_))); | 1025 NetLog::StringCallback("priority", RequestPriorityToString(priority_))); |
| 1020 job_->SetPriority(priority_); | 1026 job_->SetPriority(priority_); |
| 1021 } | 1027 } |
| 1022 } | 1028 } |
| 1023 | 1029 |
| 1024 bool URLRequest::GetHSTSRedirect(GURL* redirect_url) const { | 1030 bool URLRequest::GetSecureRedirect(GURL* redirect_url, std::string* redirect_typ
e) const { |
| 1025 const GURL& url = this->url(); | 1031 const GURL& url = this->url(); |
| 1026 bool scheme_is_http = url.SchemeIs("http"); | 1032 bool scheme_is_http = url.SchemeIs("http"); |
| 1027 if (!scheme_is_http && !url.SchemeIs("ws")) | 1033 if (!scheme_is_http && !url.SchemeIs("ws")) |
| 1028 return false; | 1034 return false; |
| 1029 TransportSecurityState* state = context()->transport_security_state(); | 1035 |
| 1030 if (state && state->ShouldUpgradeToSSL(url.host())) { | 1036 // Upgrade-Insecure-Requests applies if the policy upgrades all insecure reque
sts, or |
| 1037 // if the policy upgrades requests whose hosts match the initiator's origin's
host. |
| 1038 bool upgrade_applies = insecure_request_policy_ == UPGRADE_ALL_INSECURE_REQUES
TS || (insecure_request_policy_ == UPGRADE_SAME_HOST_INSECURE_REQUESTS && url.ho
st() == initiator_.host()); |
| 1039 bool hsts_applies = false; |
| 1040 |
| 1041 // Skip the HSTS check if we already know that we're upgrading the request. |
| 1042 if (!upgrade_applies) { |
| 1043 TransportSecurityState* state = context()->transport_security_state(); |
| 1044 hsts_applies = state && state->ShouldUpgradeToSSL(url.host()); |
| 1045 } |
| 1046 |
| 1047 if (hsts_applies || upgrade_applies) { |
| 1031 GURL::Replacements replacements; | 1048 GURL::Replacements replacements; |
| 1032 const char* new_scheme = scheme_is_http ? "https" : "wss"; | 1049 const char* new_scheme = scheme_is_http ? "https" : "wss"; |
| 1033 replacements.SetSchemeStr(new_scheme); | 1050 replacements.SetSchemeStr(new_scheme); |
| 1034 *redirect_url = url.ReplaceComponents(replacements); | 1051 *redirect_url = url.ReplaceComponents(replacements); |
| 1052 *redirect_type = upgrade_applies ? "Upgrade" : "HSTS"; |
| 1035 return true; | 1053 return true; |
| 1036 } | 1054 } |
| 1037 return false; | 1055 return false; |
| 1038 } | 1056 } |
| 1039 | 1057 |
| 1040 void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) { | 1058 void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) { |
| 1041 NetworkDelegate::AuthRequiredResponse rv = | 1059 NetworkDelegate::AuthRequiredResponse rv = |
| 1042 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; | 1060 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; |
| 1043 auth_info_ = auth_info; | 1061 auth_info_ = auth_info; |
| 1044 if (network_delegate_) { | 1062 if (network_delegate_) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 } | 1218 } |
| 1201 | 1219 |
| 1202 void URLRequest::GetConnectionAttempts(ConnectionAttempts* out) const { | 1220 void URLRequest::GetConnectionAttempts(ConnectionAttempts* out) const { |
| 1203 if (job_) | 1221 if (job_) |
| 1204 job_->GetConnectionAttempts(out); | 1222 job_->GetConnectionAttempts(out); |
| 1205 else | 1223 else |
| 1206 out->clear(); | 1224 out->clear(); |
| 1207 } | 1225 } |
| 1208 | 1226 |
| 1209 } // namespace net | 1227 } // namespace net |
| OLD | NEW |