1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef js_loader_ScriptFecthOptions_h
8 #define js_loader_ScriptFecthOptions_h
10 #include "mozilla/CORSMode.h"
11 #include "mozilla/dom/Element.h"
12 #include "mozilla/dom/ReferrerPolicyBinding.h"
13 #include "mozilla/dom/RequestBinding.h" // RequestPriority
15 #include "nsIPrincipal.h"
17 namespace JS::loader
{
19 // https://fetch.spec.whatwg.org/#concept-request-parser-metadata
20 // All scripts are either "parser-inserted" or "not-parser-inserted", so
21 // the empty string is not necessary.
22 enum class ParserMetadata
{
28 * ScriptFetchOptions loosely corresponds to HTML's "script fetch options",
29 * https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options
30 * with the exception of the following properties:
32 * The integrity metadata used for the initial fetch. This is
33 * implemented in ScriptLoadRequest, as it changes for every
37 * For a module script, its referrerPolicy will be updated if there is a
38 * HTTP Response 'REFERRER-POLICY' header, given this value may be different
39 * for every ScriptLoadRequest, so we store it directly in
42 * In the case of classic scripts without dynamic import, this object is
43 * used once. For modules, this object is propogated throughout the module
44 * tree. If there is a dynamically imported module in any type of script,
45 * the ScriptFetchOptions object will be propogated from its importer.
48 class ScriptFetchOptions
{
49 ~ScriptFetchOptions();
52 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(ScriptFetchOptions
)
53 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(ScriptFetchOptions
)
55 ScriptFetchOptions(mozilla::CORSMode aCORSMode
, const nsAString
& aNonce
,
56 mozilla::dom::RequestPriority aFetchPriority
,
57 const ParserMetadata aParserMetadata
,
58 nsIPrincipal
* aTriggeringPrincipal
,
59 mozilla::dom::Element
* aElement
= nullptr);
62 * The credentials mode used for the initial fetch (for module scripts)
63 * and for fetching any imported modules (for both module scripts and
66 const mozilla::CORSMode mCORSMode
;
69 * The cryptographic nonce metadata used for the initial fetch and for
70 * fetching any imported modules.
72 const nsString mNonce
;
75 * <https://html.spec.whatwg.org/multipage/webappapis.html#script-fetch-options>.
77 const mozilla::dom::RequestPriority mFetchPriority
;
80 * The parser metadata used for the initial fetch and for fetching any
83 const ParserMetadata mParserMetadata
;
86 * Used to determine CSP and if we are on the About page.
87 * Only used in DOM content scripts.
88 * TODO: Move to ScriptLoadContext
90 nsCOMPtr
<nsIPrincipal
> mTriggeringPrincipal
;
92 * Represents fields populated by DOM elements (nonce, parser metadata)
93 * Leave this field as a nullptr for any fetch that requires the
94 * default classic script options.
95 * (https://html.spec.whatwg.org/multipage/webappapis.html#default-classic-script-fetch-options)
96 * TODO: extract necessary fields rather than passing this object
98 nsCOMPtr
<mozilla::dom::Element
> mElement
;
101 } // namespace JS::loader
103 #endif // js_loader_ScriptFetchOptions_h