diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /dom/worklet/WorkletImpl.h | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/worklet/WorkletImpl.h')
-rw-r--r-- | dom/worklet/WorkletImpl.h | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/dom/worklet/WorkletImpl.h b/dom/worklet/WorkletImpl.h new file mode 100644 index 0000000000..b49cd2043e --- /dev/null +++ b/dom/worklet/WorkletImpl.h @@ -0,0 +1,127 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_worklet_WorkletImpl_h +#define mozilla_dom_worklet_WorkletImpl_h + +#include "MainThreadUtils.h" +#include "mozilla/BasePrincipal.h" +#include "mozilla/Maybe.h" +#include "mozilla/OriginAttributes.h" +#include "mozilla/OriginTrials.h" +#include "mozilla/ipc/PBackgroundSharedTypes.h" + +class nsPIDOMWindowInner; +class nsIPrincipal; +class nsIRunnable; + +namespace mozilla { + +namespace dom { + +class Worklet; +class WorkletGlobalScope; +class WorkletThread; + +} // namespace dom + +class WorkletLoadInfo { + public: + explicit WorkletLoadInfo(nsPIDOMWindowInner* aWindow); + + uint64_t OuterWindowID() const { return mOuterWindowID; } + uint64_t InnerWindowID() const { return mInnerWindowID; } + + private: + // Modified only in constructor. + uint64_t mOuterWindowID; + const uint64_t mInnerWindowID; +}; + +/** + * WorkletImpl is accessed from both the worklet's parent thread (on which the + * Worklet object lives) and the worklet's execution thread. It is owned by + * Worklet and WorkletGlobalScope. No parent thread cycle collected objects + * are owned indefinitely by WorkletImpl because WorkletImpl is not cycle + * collected. + */ +class WorkletImpl { + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WorkletImpl); + + // Methods for parent thread only: + + virtual JSObject* WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet, + JS::Handle<JSObject*> aGivenProto); + + virtual nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable); + + void NotifyWorkletFinished(); + + virtual nsContentPolicyType ContentPolicyType() const = 0; + + // Execution thread only. + dom::WorkletGlobalScope* GetGlobalScope(); + + // Any thread. + + const OriginTrials& Trials() const { return mTrials; } + const WorkletLoadInfo& LoadInfo() const { return mWorkletLoadInfo; } + const OriginAttributes& OriginAttributesRef() const { + return mPrincipal->OriginAttributesRef(); + } + nsIPrincipal* Principal() const { return mPrincipal; } + const ipc::PrincipalInfo& PrincipalInfo() const { return mPrincipalInfo; } + + const Maybe<nsID>& GetAgentClusterId() const { return mAgentClusterId; } + + bool IsSharedMemoryAllowed() const { return mSharedMemoryAllowed; } + bool IsSystemPrincipal() const { return mPrincipal->IsSystemPrincipal(); } + bool ShouldResistFingerprinting() const { + return mShouldResistFingerprinting; + } + + virtual void OnAddModuleStarted() const { + MOZ_ASSERT(NS_IsMainThread()); + // empty base impl + } + + virtual void OnAddModulePromiseSettled() const { + MOZ_ASSERT(NS_IsMainThread()); + // empty base impl + } + + protected: + WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal); + virtual ~WorkletImpl(); + + virtual already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() = 0; + + // Modified only in constructor. + ipc::PrincipalInfo mPrincipalInfo; + nsCOMPtr<nsIPrincipal> mPrincipal; + + const WorkletLoadInfo mWorkletLoadInfo; + + // Parent thread only. + RefPtr<dom::WorkletThread> mWorkletThread; + bool mTerminated; + + // Execution thread only. + RefPtr<dom::WorkletGlobalScope> mGlobalScope; + bool mFinishedOnExecutionThread; + + Maybe<nsID> mAgentClusterId; + + bool mSharedMemoryAllowed; + bool mShouldResistFingerprinting; + + const OriginTrials mTrials; +}; + +} // namespace mozilla + +#endif // mozilla_dom_worklet_WorkletImpl_h |