Chromium Code Reviews| Index: content/public/common/referrer.cc |
| diff --git a/content/public/common/referrer.cc b/content/public/common/referrer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..98e25a2b9be766f6c3a0c99a6d23c38105dfe610 |
| --- /dev/null |
| +++ b/content/public/common/referrer.cc |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +#include "content/public/common/referrer.h" |
| + |
| +#include <string> |
| + |
| +#include "base/command_line.h" |
| +#include "base/logging.h" |
| +#include "content/public/common/content_switches.h" |
| + |
| +namespace { |
| + |
| +GURL ReferrerForHeader(const GURL& referrer) { |
|
Kibeom Kim (inactive)
2014/04/30 00:58:56
From ios/web/public/referrer_util.cc .
https://ch
|
| + DCHECK(referrer.is_valid()); |
| + GURL::Replacements replacements; |
| + replacements.ClearUsername(); |
| + replacements.ClearPassword(); |
| + replacements.ClearRef(); |
| + return referrer.ReplaceComponents(replacements); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace content { |
| + |
| +GURL Referrer::ReferrerHeaderUrlForNavigation(const GURL& destination) const { |
| + GURL referrer_url; |
| + |
| + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoReferrers)) |
| + return referrer_url; |
| + |
| + // Make sure that we're covering all the cases. |
| + DCHECK(blink::WebReferrerPolicyLast == 3); |
| + |
| + switch (policy) { |
| + case blink::WebReferrerPolicyDefault: |
| + if (url.SchemeIsSecure() && !destination.SchemeIsSecure()) |
| + break; |
| + // Purposeful fall through. |
| + case blink::WebReferrerPolicyAlways: |
| + referrer_url = ReferrerForHeader(url); |
| + break; |
| + case blink::WebReferrerPolicyOrigin: |
| + referrer_url = url.GetOrigin(); |
| + break; |
| + case blink::WebReferrerPolicyNever: |
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| + |
| + return referrer_url; |
| +} |
| + |
| +} // namespace content |