Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: net/url_request/url_request_job.cc

Issue 2918313002: Implement new referrer policies (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 std::string referrer_policy_header; 81 std::string referrer_policy_header;
82 request->GetResponseHeaderByName("Referrer-Policy", &referrer_policy_header); 82 request->GetResponseHeaderByName("Referrer-Policy", &referrer_policy_header);
83 std::vector<std::string> policy_tokens = 83 std::vector<std::string> policy_tokens =
84 base::SplitString(referrer_policy_header, ",", base::TRIM_WHITESPACE, 84 base::SplitString(referrer_policy_header, ",", base::TRIM_WHITESPACE,
85 base::SPLIT_WANT_NONEMPTY); 85 base::SPLIT_WANT_NONEMPTY);
86 86
87 UMA_HISTOGRAM_BOOLEAN("Net.URLRequest.ReferrerPolicyHeaderPresentOnRedirect", 87 UMA_HISTOGRAM_BOOLEAN("Net.URLRequest.ReferrerPolicyHeaderPresentOnRedirect",
88 !policy_tokens.empty()); 88 !policy_tokens.empty());
89 89
90 for (const auto& token : policy_tokens) { 90 for (const auto& token : policy_tokens) {
mmenke 2017/06/07 21:03:59 Random question: Is it right to take the last pol
estark 2017/06/08 18:42:58 Yeah, that is intentional per spec: https://w3c.gi
mmenke 2017/06/08 19:11:28 Hrm...The spec looks ambiguous to me. It says whe
91 if (base::CompareCaseInsensitiveASCII(token, "no-referrer") == 0) { 91 if (base::CompareCaseInsensitiveASCII(token, "no-referrer") == 0) {
92 new_policy = URLRequest::NO_REFERRER; 92 new_policy = URLRequest::NO_REFERRER;
93 continue; 93 continue;
94 } 94 }
95 95
96 if (base::CompareCaseInsensitiveASCII(token, 96 if (base::CompareCaseInsensitiveASCII(token,
97 "no-referrer-when-downgrade") == 0) { 97 "no-referrer-when-downgrade") == 0) {
98 new_policy = 98 new_policy =
99 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE; 99 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
100 continue; 100 continue;
101 } 101 }
102 102
103 if (base::CompareCaseInsensitiveASCII(token, "origin") == 0) { 103 if (base::CompareCaseInsensitiveASCII(token, "origin") == 0) {
104 new_policy = URLRequest::ORIGIN; 104 new_policy = URLRequest::ORIGIN;
105 continue; 105 continue;
106 } 106 }
107 107
108 if (base::CompareCaseInsensitiveASCII(token, "origin-when-cross-origin") == 108 if (base::CompareCaseInsensitiveASCII(token, "origin-when-cross-origin") ==
109 0) { 109 0) {
110 new_policy = URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN; 110 new_policy = URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN;
111 continue; 111 continue;
112 } 112 }
113 113
114 if (base::CompareCaseInsensitiveASCII(token, "unsafe-url") == 0) { 114 if (base::CompareCaseInsensitiveASCII(token, "unsafe-url") == 0) {
115 new_policy = URLRequest::NEVER_CLEAR_REFERRER; 115 new_policy = URLRequest::NEVER_CLEAR_REFERRER;
116 continue; 116 continue;
117 } 117 }
118
119 if (base::CompareCaseInsensitiveASCII(token, "same-origin") == 0) {
120 new_policy = URLRequest::CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN;
mmenke 2017/06/07 21:03:58 Hrm...Wonder if it's better to have clearer policy
estark 2017/06/08 18:42:58 Agree, I think it would be better to match the tok
121 continue;
122 }
123
124 if (base::CompareCaseInsensitiveASCII(token, "strict-origin") == 0) {
125 new_policy =
126 URLRequest::ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE;
127 continue;
128 }
129
130 if (base::CompareCaseInsensitiveASCII(
131 token, "strict-origin-when-cross-origin") == 0) {
132 new_policy =
133 URLRequest::REDUCE_REFERRER_GRANULARITY_ON_TRANSITION_CROSS_ORIGIN;
134 continue;
135 }
118 } 136 }
119 return new_policy; 137 return new_policy;
120 } 138 }
121 139
122 } // namespace 140 } // namespace
123 141
124 // Each SourceStreams own the previous SourceStream in the chain, but the 142 // Each SourceStreams own the previous SourceStream in the chain, but the
125 // ultimate source is URLRequestJob, which has other ownership semantics, so 143 // ultimate source is URLRequestJob, which has other ownership semantics, so
126 // this class is a proxy for URLRequestJob that is owned by the first stream 144 // this class is a proxy for URLRequestJob that is owned by the first stream
127 // (in dataflow order). 145 // (in dataflow order).
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 return referrer_origin.GetURL(); 404 return referrer_origin.GetURL();
387 } 405 }
388 406
389 case URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN: 407 case URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN:
390 return same_origin ? original_referrer : referrer_origin.GetURL(); 408 return same_origin ? original_referrer : referrer_origin.GetURL();
391 409
392 case URLRequest::NEVER_CLEAR_REFERRER: 410 case URLRequest::NEVER_CLEAR_REFERRER:
393 return original_referrer; 411 return original_referrer;
394 case URLRequest::ORIGIN: 412 case URLRequest::ORIGIN:
395 return referrer_origin.GetURL(); 413 return referrer_origin.GetURL();
414 case URLRequest::CLEAR_REFERRER_ON_TRANSITION_CROSS_ORIGIN:
415 if (same_origin)
416 return original_referrer;
417 return GURL();
418 case URLRequest::ORIGIN_CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE:
419 if (secure_referrer_but_insecure_destination)
420 return GURL();
421 return referrer_origin.GetURL();
396 case URLRequest::NO_REFERRER: 422 case URLRequest::NO_REFERRER:
397 return GURL(); 423 return GURL();
398 case URLRequest::MAX_REFERRER_POLICY: 424 case URLRequest::MAX_REFERRER_POLICY:
399 NOTREACHED(); 425 NOTREACHED();
400 return GURL(); 426 return GURL();
401 } 427 }
402 428
403 NOTREACHED(); 429 NOTREACHED();
404 return GURL(); 430 return GURL();
405 } 431 }
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 int64_t total_sent_bytes = GetTotalSentBytes(); 899 int64_t total_sent_bytes = GetTotalSentBytes();
874 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); 900 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_);
875 if (total_sent_bytes > last_notified_total_sent_bytes_) { 901 if (total_sent_bytes > last_notified_total_sent_bytes_) {
876 network_delegate_->NotifyNetworkBytesSent( 902 network_delegate_->NotifyNetworkBytesSent(
877 request_, total_sent_bytes - last_notified_total_sent_bytes_); 903 request_, total_sent_bytes - last_notified_total_sent_bytes_);
878 } 904 }
879 last_notified_total_sent_bytes_ = total_sent_bytes; 905 last_notified_total_sent_bytes_ = total_sent_bytes;
880 } 906 }
881 907
882 } // namespace net 908 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698