summaryrefslogtreecommitdiffstats
path: root/dom/interfaces/security/nsIReferrerInfo.idl
blob: 07e2f603bccd4c539aef5435614bf4f7778a4d2d (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"
#include "nsISerializable.idl"

%{C++
namespace mozilla::dom {
enum class ReferrerPolicy : uint8_t;
}
%}

interface nsIURI;
webidl Document;
webidl Element;

native ReferrerPolicy(mozilla::dom::ReferrerPolicy);
native URIRef(already_AddRefed<nsIURI>);

[scriptable, builtinclass, uuid(081cdc36-f2e2-4f94-87bf-78578f06f1eb)]
interface nsIReferrerInfo : nsISerializable
{
  /**
   * Unfortunately we can not query the ReferrerPolicy values defined within
   * ReferrerPolicy.webidl directly from xpidl. Hence we define the enum value
   * ReferrerPolicyIDL to set up the ReferrerInfo object from JS. If you need
   * ReferrerPolicy in native code, please directly query it from
   * ReferrerPolicy.webidl.
   *
   * Note that the deserialization code assumes that the ReferrerPolicyIDL only
   * uses one byte. If we would need to change the format here, we should also
   * update the deserialization code.
   */
  cenum ReferrerPolicyIDL : 8 {
  /**
   * The undefined state, or no referrer policy, usually causing a fallback to a
   * referrer policy definded in higher level policy. For example: request by
   * clicking <a> element with empty referrer policy will be sent with the
   * referrer policy of the a element’s node document.
   * If there is no higher-level policy available, we fall back to the default
   * value, which usually is "no-referrer-when-downgrade".
   */
  EMPTY = 0,
  /**
   * Do not send referrer from https->http
   */
  NO_REFERRER_WHEN_DOWNGRADE = 1,
  /**
   * Do not send referrer at all.
   */
  NO_REFERRER = 2,
  /**
   * Only send the origin of the referring URL
   */
  ORIGIN = 3,
  /**
   * Send origin when cross-origin.
   */
  ORIGIN_WHEN_CROSS_ORIGIN = 4,
  /**
   * Always sends the referrer, even on downgrade.
   */
  UNSAFE_URL = 5,
  /**
   * Send referrer when same-origin, no referrer when cross-origin
   */
  SAME_ORIGIN = 6,
  /**
   * Send origin when request from https->https or http->http(s). No referrer
   * when request from https->http.
   */
  STRICT_ORIGIN = 7,
  /**
   * Send referrer when same-origin, send origin when cross-origin from
   * https->https or http->http(s). No referrer when request from https->http.
   */
  STRICT_ORIGIN_WHEN_CROSS_ORIGIN = 8,
  };

  /**
   * The original referrer URI which indicates the full referrer before applying
   * referrer policy
   */
  [infallible] readonly attribute nsIURI originalReferrer;

  /**
   * Referrer policy which is applied to the referrer
   */
  [implicit_jscontext] readonly attribute nsIReferrerInfo_ReferrerPolicyIDL referrerPolicy;

  /**
   * C++ friendly version of referrerPolicy getter
   */
  [noscript, notxpcom, nostdcall, binaryname(ReferrerPolicy)]
  ReferrerPolicy binaryReferrerPolicy();

  /**
   * Get referrer policy as string
   */
  ACString getReferrerPolicyString();

  /**
   * Indicates if the referrer should not be sent or not even when it's available.
   */
  [infallible] readonly attribute boolean sendReferrer;

  /**
  * Indicates if the referrer should not be sent or not even when it's available.
  */
  readonly attribute AString computedReferrerSpec;

  /**
   * Get the computed referrer, if one has been set. The computed referrer is
   * the original referrer manipulated by the referrer-policy. Use the result of
   * this function as the actual referrer value for the channel.
   */
  [must_use, noscript, nostdcall, notxpcom]
  URIRef GetComputedReferrer();

  /**
   * Returns whether the other referrerInfo is equivalent to this referrerInfo.
   */
  boolean equals(in nsIReferrerInfo other);

  /**
   * Initialize method to create ReferrerInfo object from JS
   * @param aReferrerPolicy referrer policy of the created object
   * @param aSendReferrer sendReferrer of the created object, defaults to false
   * @param aOriginalReferrer the original referrer, defaults to null.
   */
  void init(in nsIReferrerInfo_ReferrerPolicyIDL aReferrerPolicy,
           [optional] in boolean aSendReferrer,
           [optional] in nsIURI aOriginalReferrer);

  /**
   * Initialize with a given document.
   * @param aDocument the document to init referrerInfo object
   */
  void initWithDocument([const] in Document aDocument);

  /**
   * Initialize with a given node. It you are working with node which supports
   * referrerpolicy attribute: <a>, <img>, <area>, <script>, <iframe>, please
   * try to use this init instead of initWithDocument, because referrer policy
   * from rel and attribute has a higher priority.
   * @param aNode the element to init referrerInfo object
   */
  void initWithElement([const] in Element aNode);
};