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

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

Issue 185133005: Move referrer stripping into GURL::GetAsReferrer(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore the behavior of setting the referrer when it's invalid in URLRequest::SetReferrer. Created 6 years, 9 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
« no previous file with comments | « chrome/browser/ui/android/context_menu_helper.cc ('k') | url/gurl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 if ((http_status_code == 303 && method != "HEAD") || 601 if ((http_status_code == 303 && method != "HEAD") ||
602 ((http_status_code == 301 || http_status_code == 302) && 602 ((http_status_code == 301 || http_status_code == 302) &&
603 method == "POST")) { 603 method == "POST")) {
604 return "GET"; 604 return "GET";
605 } 605 }
606 return method; 606 return method;
607 } 607 }
608 608
609 void URLRequest::SetReferrer(const std::string& referrer) { 609 void URLRequest::SetReferrer(const std::string& referrer) {
610 DCHECK(!is_pending_); 610 DCHECK(!is_pending_);
611 referrer_ = referrer;
612 // Ensure that we do not send URL fragment, username and password
613 // fields in the referrer.
614 GURL referrer_url(referrer); 611 GURL referrer_url(referrer);
615 UMA_HISTOGRAM_BOOLEAN("Net.URLRequest_SetReferrer_IsEmptyOrValid", 612 UMA_HISTOGRAM_BOOLEAN("Net.URLRequest_SetReferrer_IsEmptyOrValid",
616 referrer_url.is_empty() || referrer_url.is_valid()); 613 referrer_url.is_empty() || referrer_url.is_valid());
617 if (referrer_url.is_valid() && (referrer_url.has_ref() || 614 if (referrer_url.is_valid()) {
618 referrer_url.has_username() || referrer_url.has_password())) { 615 referrer_ = referrer_url.GetAsReferrer().spec();
619 GURL::Replacements referrer_mods; 616 } else {
620 referrer_mods.ClearRef(); 617 referrer_ = referrer;
621 referrer_mods.ClearUsername();
622 referrer_mods.ClearPassword();
623 referrer_url = referrer_url.ReplaceComponents(referrer_mods);
624 referrer_ = referrer_url.spec();
625 } 618 }
626 } 619 }
627 620
628 void URLRequest::set_referrer_policy(ReferrerPolicy referrer_policy) { 621 void URLRequest::set_referrer_policy(ReferrerPolicy referrer_policy) {
629 DCHECK(!is_pending_); 622 DCHECK(!is_pending_);
630 referrer_policy_ = referrer_policy; 623 referrer_policy_ = referrer_policy;
631 } 624 }
632 625
633 void URLRequest::set_delegate(Delegate* delegate) { 626 void URLRequest::set_delegate(Delegate* delegate) {
634 delegate_ = delegate; 627 delegate_ = delegate;
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 new base::debug::StackTrace(NULL, 0); 1249 new base::debug::StackTrace(NULL, 0);
1257 *stack_trace_copy = stack_trace; 1250 *stack_trace_copy = stack_trace;
1258 stack_trace_.reset(stack_trace_copy); 1251 stack_trace_.reset(stack_trace_copy);
1259 } 1252 }
1260 1253
1261 const base::debug::StackTrace* URLRequest::stack_trace() const { 1254 const base::debug::StackTrace* URLRequest::stack_trace() const {
1262 return stack_trace_.get(); 1255 return stack_trace_.get();
1263 } 1256 }
1264 1257
1265 } // namespace net 1258 } // namespace net
OLDNEW
« no previous file with comments | « chrome/browser/ui/android/context_menu_helper.cc ('k') | url/gurl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698