blob: 91dcc51508e0761ba6dd80bbc99936d77e82c4d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// Copyright (c) 2012 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.
#ifndef CONTENT_PUBLIC_COMMON_REFERRER_H_
#define CONTENT_PUBLIC_COMMON_REFERRER_H_
#include "content/common/content_export.h"
#include "net/url_request/url_request.h"
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
#include "third_party/blink/public/mojom/referrer.mojom-forward.h"
#include "url/gurl.h"
namespace content {
// This struct holds a referrer URL, as well as the referrer policy to be
// applied to this URL. When passing around referrers that will eventually end
// up being used for URL requests, always use this struct.
//
// TODO(leonhsl): Replace this struct everywhere with blink::mojom::Referrer.
struct CONTENT_EXPORT Referrer {
Referrer(const GURL& url, network::mojom::ReferrerPolicy policy)
: url(url), policy(policy) {}
Referrer() : policy(network::mojom::ReferrerPolicy::kDefault) {}
explicit Referrer(const blink::mojom::Referrer& referrer);
GURL url;
network::mojom::ReferrerPolicy policy;
static Referrer SanitizeForRequest(const GURL& request,
const Referrer& referrer);
static blink::mojom::ReferrerPtr SanitizeForRequest(
const GURL& request,
const blink::mojom::Referrer& referrer);
// Returns |initiator| origin sanitized by |policy| so that it can be used
// when requesting |request| URL.
//
// Note that the URL-based sanitization (e.g. SanitizeForRequest above) cannot
// be used for cases where the referrer URL is missing (e.g. about:blank) but
// the initiator origin still needs to be used (e.g. when calculating the
// value of the `Origin` header to use in a POST request).
static url::Origin SanitizeOriginForRequest(
const GURL& request,
const url::Origin& initiator,
network::mojom::ReferrerPolicy policy);
static net::URLRequest::ReferrerPolicy ReferrerPolicyForUrlRequest(
network::mojom::ReferrerPolicy referrer_policy);
static network::mojom::ReferrerPolicy NetReferrerPolicyToBlinkReferrerPolicy(
net::URLRequest::ReferrerPolicy net_policy);
static net::URLRequest::ReferrerPolicy GetDefaultReferrerPolicy();
// Configures retaining the pre-M80 default referrer
// policy of no-referrer-when-downgrade.
// TODO(crbug.com/1016541): After M82, remove when the corresponding
// enterprise policy has been deleted.
static void SetForceLegacyDefaultReferrerPolicy(bool force);
static bool ShouldForceLegacyDefaultReferrerPolicy();
// Validates |policy| to make sure it represents one of the valid
// net::mojom::ReferrerPolicy enum values and returns it. The relatively safe
// |kNever| value is returned if |policy| is not a valid value.
static network::mojom::ReferrerPolicy ConvertToPolicy(int32_t policy);
};
} // namespace content
#endif // CONTENT_PUBLIC_COMMON_REFERRER_H_
|