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 BackstagePass_h__
8 #define BackstagePass_h__
10 #include "js/loader/ModuleLoaderBase.h"
11 #include "mozilla/BasePrincipal.h"
12 #include "mozilla/SchedulerGroup.h"
13 #include "mozilla/StorageAccess.h"
14 #include "nsISupports.h"
15 #include "nsWeakReference.h"
16 #include "nsIGlobalObject.h"
17 #include "nsIScriptObjectPrincipal.h"
18 #include "nsIXPCScriptable.h"
20 #include "js/HeapAPI.h"
22 class XPCWrappedNative
;
24 class BackstagePass final
: public nsIGlobalObject
,
25 public nsIScriptObjectPrincipal
,
26 public nsIXPCScriptable
,
28 public nsSupportsWeakReference
{
33 NS_DECL_NSIXPCSCRIPTABLE
36 using ModuleLoaderBase
= JS::loader::ModuleLoaderBase
;
38 nsIPrincipal
* GetPrincipal() override
{ return mPrincipal
; }
40 nsIPrincipal
* GetEffectiveCookiePrincipal() override
{ return mPrincipal
; }
42 nsIPrincipal
* GetEffectiveStoragePrincipal() override
{ return mPrincipal
; }
44 nsIPrincipal
* PartitionedPrincipal() override
{ return mPrincipal
; }
46 mozilla::OriginTrials
Trials() const override
{ return {}; }
48 JSObject
* GetGlobalJSObject() override
;
49 JSObject
* GetGlobalJSObjectPreserveColor() const override
;
51 ModuleLoaderBase
* GetModuleLoader(JSContext
* aCx
) override
{
55 mozilla::StorageAccess
GetStorageAccess() final
{
56 MOZ_ASSERT(NS_IsMainThread());
57 return mozilla::StorageAccess::eAllow
;
60 mozilla::Result
<mozilla::ipc::PrincipalInfo
, nsresult
> GetStorageKey()
63 void ForgetGlobalObject() { mWrapper
= nullptr; }
65 void SetGlobalObject(JSObject
* global
);
67 void InitModuleLoader(ModuleLoaderBase
* aModuleLoader
) {
68 MOZ_ASSERT(!mModuleLoader
);
69 mModuleLoader
= aModuleLoader
;
72 nsISerialEventTarget
* SerialEventTarget() const final
{
73 return mozilla::GetMainThreadSerialEventTarget();
75 nsresult
Dispatch(already_AddRefed
<nsIRunnable
>&& aRunnable
) const final
{
76 return mozilla::SchedulerGroup::Dispatch(std::move(aRunnable
));
79 bool ShouldResistFingerprinting(RFPTarget aTarget
) const override
{
80 // BackstagePass is always the System Principal
81 MOZ_RELEASE_ASSERT(mPrincipal
->IsSystemPrincipal());
86 virtual ~BackstagePass() = default;
88 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
89 XPCWrappedNative
* mWrapper
;
91 RefPtr
<JS::loader::ModuleLoaderBase
> mModuleLoader
;
94 #endif // BackstagePass_h__