1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "content/public/common/content_switches.h"
7 #include "content/public/common/referrer.h"
12 Referrer
Referrer::SanitizeForRequest(const GURL
& request
,
13 const Referrer
& referrer
) {
14 Referrer
sanitized_referrer(referrer
.url
.GetAsReferrer(), referrer
.policy
);
16 if (!request
.SchemeIsHTTPOrHTTPS() ||
17 !sanitized_referrer
.url
.SchemeIsHTTPOrHTTPS()) {
18 sanitized_referrer
.url
= GURL();
19 return sanitized_referrer
;
23 sanitized_referrer
.url
.SchemeIsSecure() && !request
.SchemeIsSecure();
25 switch (sanitized_referrer
.policy
) {
26 case blink::WebReferrerPolicyDefault
:
28 sanitized_referrer
.url
= GURL();
29 } else if (request
.GetOrigin() != sanitized_referrer
.url
.GetOrigin() &&
30 base::CommandLine::ForCurrentProcess()->HasSwitch(
31 switches::kReducedReferrerGranularity
)) {
32 sanitized_referrer
.url
= sanitized_referrer
.url
.GetOrigin();
35 case blink::WebReferrerPolicyNoReferrerWhenDowngrade
:
37 sanitized_referrer
.url
= GURL();
39 case blink::WebReferrerPolicyAlways
:
41 case blink::WebReferrerPolicyNever
:
42 sanitized_referrer
.url
= GURL();
44 case blink::WebReferrerPolicyOrigin
:
45 sanitized_referrer
.url
= sanitized_referrer
.url
.GetOrigin();
51 return sanitized_referrer
;
54 } // namespace content