2018-09-18 09:36:38 +00:00
|
|
|
/* -*- 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"
|
2022-12-12 22:08:35 +00:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2020-02-06 13:45:47 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2018-09-18 09:36:38 +00:00
|
|
|
#include "mozilla/OriginAttributes.h"
|
2022-03-15 23:16:14 +00:00
|
|
|
#include "mozilla/OriginTrials.h"
|
2019-09-09 00:41:57 +00:00
|
|
|
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
2023-03-21 14:14:48 +00:00
|
|
|
#include "nsRFPService.h"
|
2018-09-18 09:36:38 +00:00
|
|
|
|
|
|
|
class nsPIDOMWindowInner;
|
|
|
|
class nsIPrincipal;
|
2018-09-18 09:29:15 +00:00
|
|
|
class nsIRunnable;
|
2018-09-18 09:36:38 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class Worklet;
|
|
|
|
class WorkletGlobalScope;
|
|
|
|
class WorkletThread;
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
class WorkletLoadInfo {
|
|
|
|
public:
|
2019-09-09 00:42:05 +00:00
|
|
|
explicit WorkletLoadInfo(nsPIDOMWindowInner* aWindow);
|
2018-09-18 09:36:38 +00:00
|
|
|
|
|
|
|
uint64_t OuterWindowID() const { return mOuterWindowID; }
|
|
|
|
uint64_t InnerWindowID() const { return mInnerWindowID; }
|
|
|
|
|
|
|
|
private:
|
2018-09-18 09:34:11 +00:00
|
|
|
// Modified only in constructor.
|
2018-09-18 09:36:38 +00:00
|
|
|
uint64_t mOuterWindowID;
|
2018-09-18 09:34:11 +00:00
|
|
|
const uint64_t mInnerWindowID;
|
2018-09-18 09:36:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2018-09-18 09:33:49 +00:00
|
|
|
* Worklet and WorkletGlobalScope. No parent thread cycle collected objects
|
|
|
|
* are owned indefinitely by WorkletImpl because WorkletImpl is not cycle
|
|
|
|
* collected.
|
2018-09-18 09:36:38 +00:00
|
|
|
*/
|
|
|
|
class WorkletImpl {
|
2023-03-21 14:14:48 +00:00
|
|
|
using RFPTarget = mozilla::RFPTarget;
|
|
|
|
|
2018-09-18 09:36:38 +00:00
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WorkletImpl);
|
|
|
|
|
|
|
|
// Methods for parent thread only:
|
|
|
|
|
|
|
|
virtual JSObject* WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet,
|
|
|
|
JS::Handle<JSObject*> aGivenProto);
|
|
|
|
|
2018-12-20 07:58:13 +00:00
|
|
|
virtual nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable);
|
2018-11-28 23:47:01 +00:00
|
|
|
|
2018-11-28 23:45:04 +00:00
|
|
|
void NotifyWorkletFinished();
|
2018-09-18 09:36:38 +00:00
|
|
|
|
2020-03-17 22:24:39 +00:00
|
|
|
virtual nsContentPolicyType ContentPolicyType() const = 0;
|
|
|
|
|
2018-09-18 09:36:38 +00:00
|
|
|
// Execution thread only.
|
2019-04-01 16:54:58 +00:00
|
|
|
dom::WorkletGlobalScope* GetGlobalScope();
|
2018-09-18 09:36:38 +00:00
|
|
|
|
|
|
|
// Any thread.
|
2018-09-18 09:29:15 +00:00
|
|
|
|
2022-03-15 23:16:14 +00:00
|
|
|
const OriginTrials& Trials() const { return mTrials; }
|
2018-09-18 09:36:38 +00:00
|
|
|
const WorkletLoadInfo& LoadInfo() const { return mWorkletLoadInfo; }
|
2019-09-09 00:42:05 +00:00
|
|
|
const OriginAttributes& OriginAttributesRef() const {
|
2022-12-12 22:08:35 +00:00
|
|
|
return mPrincipal->OriginAttributesRef();
|
2019-09-09 00:42:05 +00:00
|
|
|
}
|
2022-12-12 22:08:35 +00:00
|
|
|
nsIPrincipal* Principal() const { return mPrincipal; }
|
2019-09-09 00:41:57 +00:00
|
|
|
const ipc::PrincipalInfo& PrincipalInfo() const { return mPrincipalInfo; }
|
2018-09-18 09:36:38 +00:00
|
|
|
|
2020-02-06 13:45:47 +00:00
|
|
|
const Maybe<nsID>& GetAgentClusterId() const { return mAgentClusterId; }
|
|
|
|
|
2020-02-06 13:50:11 +00:00
|
|
|
bool IsSharedMemoryAllowed() const { return mSharedMemoryAllowed; }
|
2022-12-12 22:08:35 +00:00
|
|
|
bool IsSystemPrincipal() const { return mPrincipal->IsSystemPrincipal(); }
|
2023-05-31 09:46:54 +00:00
|
|
|
bool ShouldResistFingerprinting(RFPTarget aTarget) const {
|
2023-03-21 14:14:48 +00:00
|
|
|
return mShouldResistFingerprinting &&
|
2023-12-18 18:39:33 +00:00
|
|
|
nsRFPService::IsRFPEnabledFor(mIsPrivateBrowsing, aTarget,
|
2023-10-17 22:02:30 +00:00
|
|
|
mOverriddenFingerprintingSettings);
|
2022-11-29 13:34:13 +00:00
|
|
|
}
|
2020-02-06 13:50:11 +00:00
|
|
|
|
2021-08-26 09:15:38 +00:00
|
|
|
virtual void OnAddModuleStarted() const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// empty base impl
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnAddModulePromiseSettled() const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// empty base impl
|
|
|
|
}
|
|
|
|
|
2018-09-20 11:34:01 +00:00
|
|
|
protected:
|
|
|
|
WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
|
|
|
|
virtual ~WorkletImpl();
|
|
|
|
|
|
|
|
virtual already_AddRefed<dom::WorkletGlobalScope> ConstructGlobalScope() = 0;
|
2018-09-18 09:36:38 +00:00
|
|
|
|
2019-09-09 00:41:57 +00:00
|
|
|
// Modified only in constructor.
|
|
|
|
ipc::PrincipalInfo mPrincipalInfo;
|
2019-09-09 00:42:05 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
|
|
|
const WorkletLoadInfo mWorkletLoadInfo;
|
2018-09-18 09:36:38 +00:00
|
|
|
|
|
|
|
// Parent thread only.
|
|
|
|
RefPtr<dom::WorkletThread> mWorkletThread;
|
2023-12-18 18:39:33 +00:00
|
|
|
bool mTerminated : 1;
|
2019-04-01 16:54:58 +00:00
|
|
|
|
|
|
|
// Execution thread only.
|
|
|
|
RefPtr<dom::WorkletGlobalScope> mGlobalScope;
|
2023-12-18 18:39:33 +00:00
|
|
|
bool mFinishedOnExecutionThread : 1;
|
2020-02-06 13:45:47 +00:00
|
|
|
|
|
|
|
Maybe<nsID> mAgentClusterId;
|
2020-02-06 13:50:11 +00:00
|
|
|
|
2023-12-18 18:39:33 +00:00
|
|
|
bool mSharedMemoryAllowed : 1;
|
|
|
|
bool mShouldResistFingerprinting : 1;
|
|
|
|
bool mIsPrivateBrowsing : 1;
|
2023-10-17 22:02:29 +00:00
|
|
|
// The granular fingerprinting protection overrides applied to the worklet.
|
|
|
|
// This will only get populated if these is one that comes from the local
|
|
|
|
// granular override pref or WebCompat. Otherwise, a value of Nothing()
|
|
|
|
// indicates no granular overrides are present for this workerlet.
|
|
|
|
Maybe<RFPTarget> mOverriddenFingerprintingSettings;
|
2022-03-15 23:16:14 +00:00
|
|
|
|
|
|
|
const OriginTrials mTrials;
|
2018-09-18 09:36:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_worklet_WorkletImpl_h
|