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 https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_worklet_WorkletImpl_h
8 #define mozilla_dom_worklet_WorkletImpl_h
10 #include "MainThreadUtils.h"
11 #include "mozilla/BasePrincipal.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/OriginAttributes.h"
14 #include "mozilla/OriginTrials.h"
15 #include "mozilla/ipc/PBackgroundSharedTypes.h"
16 #include "nsRFPService.h"
18 class nsPIDOMWindowInner
;
27 class WorkletGlobalScope
;
32 class WorkletLoadInfo
{
34 explicit WorkletLoadInfo(nsPIDOMWindowInner
* aWindow
);
36 uint64_t OuterWindowID() const { return mOuterWindowID
; }
37 uint64_t InnerWindowID() const { return mInnerWindowID
; }
40 // Modified only in constructor.
41 uint64_t mOuterWindowID
;
42 const uint64_t mInnerWindowID
;
46 * WorkletImpl is accessed from both the worklet's parent thread (on which the
47 * Worklet object lives) and the worklet's execution thread. It is owned by
48 * Worklet and WorkletGlobalScope. No parent thread cycle collected objects
49 * are owned indefinitely by WorkletImpl because WorkletImpl is not cycle
53 using RFPTarget
= mozilla::RFPTarget
;
56 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WorkletImpl
);
58 // Methods for parent thread only:
60 virtual JSObject
* WrapWorklet(JSContext
* aCx
, dom::Worklet
* aWorklet
,
61 JS::Handle
<JSObject
*> aGivenProto
);
63 virtual nsresult
SendControlMessage(already_AddRefed
<nsIRunnable
> aRunnable
);
65 void NotifyWorkletFinished();
67 virtual nsContentPolicyType
ContentPolicyType() const = 0;
69 // Execution thread only.
70 dom::WorkletGlobalScope
* GetGlobalScope();
74 const OriginTrials
& Trials() const { return mTrials
; }
75 const WorkletLoadInfo
& LoadInfo() const { return mWorkletLoadInfo
; }
76 const OriginAttributes
& OriginAttributesRef() const {
77 return mPrincipal
->OriginAttributesRef();
79 nsIPrincipal
* Principal() const { return mPrincipal
; }
80 const ipc::PrincipalInfo
& PrincipalInfo() const { return mPrincipalInfo
; }
82 const Maybe
<nsID
>& GetAgentClusterId() const { return mAgentClusterId
; }
84 bool IsSharedMemoryAllowed() const { return mSharedMemoryAllowed
; }
85 bool IsSystemPrincipal() const { return mPrincipal
->IsSystemPrincipal(); }
86 bool ShouldResistFingerprinting(RFPTarget aTarget
) const {
87 return mShouldResistFingerprinting
&&
88 nsRFPService::IsRFPEnabledFor(aTarget
);
91 virtual void OnAddModuleStarted() const {
92 MOZ_ASSERT(NS_IsMainThread());
96 virtual void OnAddModulePromiseSettled() const {
97 MOZ_ASSERT(NS_IsMainThread());
102 WorkletImpl(nsPIDOMWindowInner
* aWindow
, nsIPrincipal
* aPrincipal
);
103 virtual ~WorkletImpl();
105 virtual already_AddRefed
<dom::WorkletGlobalScope
> ConstructGlobalScope() = 0;
107 // Modified only in constructor.
108 ipc::PrincipalInfo mPrincipalInfo
;
109 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
111 const WorkletLoadInfo mWorkletLoadInfo
;
113 // Parent thread only.
114 RefPtr
<dom::WorkletThread
> mWorkletThread
;
117 // Execution thread only.
118 RefPtr
<dom::WorkletGlobalScope
> mGlobalScope
;
119 bool mFinishedOnExecutionThread
;
121 Maybe
<nsID
> mAgentClusterId
;
123 bool mSharedMemoryAllowed
;
124 bool mShouldResistFingerprinting
;
126 const OriginTrials mTrials
;
129 } // namespace mozilla
131 #endif // mozilla_dom_worklet_WorkletImpl_h