Bug 1829125 - Add a PHCExhaustion test r=glandium
[gecko.git] / dom / worklet / WorkletImpl.h
blob2bc8742ab55c1c0e9a57a50ea09bacc1c0825b14
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;
19 class nsIPrincipal;
20 class nsIRunnable;
22 namespace mozilla {
24 namespace dom {
26 class Worklet;
27 class WorkletGlobalScope;
28 class WorkletThread;
30 } // namespace dom
32 class WorkletLoadInfo {
33 public:
34 explicit WorkletLoadInfo(nsPIDOMWindowInner* aWindow);
36 uint64_t OuterWindowID() const { return mOuterWindowID; }
37 uint64_t InnerWindowID() const { return mInnerWindowID; }
39 private:
40 // Modified only in constructor.
41 uint64_t mOuterWindowID;
42 const uint64_t mInnerWindowID;
45 /**
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
50 * collected.
52 class WorkletImpl {
53 using RFPTarget = mozilla::RFPTarget;
55 public:
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();
72 // Any thread.
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());
93 // empty base impl
96 virtual void OnAddModulePromiseSettled() const {
97 MOZ_ASSERT(NS_IsMainThread());
98 // empty base impl
101 protected:
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;
115 bool mTerminated;
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