Bug 1804093 - Part 3: Stop asserting main thread when reading WorkletImpl::Principal, r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D163854
This commit is contained in:
Nika Layzell 2022-12-12 22:08:35 +00:00
parent 6c15719086
commit a61cde7275
2 changed files with 5 additions and 16 deletions

View File

@ -39,7 +39,6 @@ WorkletLoadInfo::WorkletLoadInfo(nsPIDOMWindowInner* aWindow)
WorkletImpl::WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal)
: mPrincipal(NullPrincipal::CreateWithInheritedAttributes(aPrincipal)),
mIsSystemPrincipal(mPrincipal->IsSystemPrincipal()),
mWorkletLoadInfo(aWindow),
mTerminated(false),
mFinishedOnExecutionThread(false),
@ -58,10 +57,7 @@ WorkletImpl::WorkletImpl(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal)
aWindow->AsGlobal()->ShouldResistFingerprinting();
}
WorkletImpl::~WorkletImpl() {
MOZ_ASSERT(!mGlobalScope);
MOZ_ASSERT(!mPrincipal || NS_IsMainThread());
}
WorkletImpl::~WorkletImpl() { MOZ_ASSERT(!mGlobalScope); }
JSObject* WorkletImpl::WrapWorklet(JSContext* aCx, dom::Worklet* aWorklet,
JS::Handle<JSObject*> aGivenProto) {
@ -120,7 +116,6 @@ void WorkletImpl::NotifyWorkletFinished() {
mWorkletThread->Terminate();
mWorkletThread = nullptr;
}
mPrincipal = nullptr;
}
nsresult WorkletImpl::SendControlMessage(

View File

@ -8,6 +8,7 @@
#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"
@ -58,11 +59,6 @@ class WorkletImpl {
virtual nsresult SendControlMessage(already_AddRefed<nsIRunnable> aRunnable);
nsIPrincipal* Principal() const {
MOZ_ASSERT(NS_IsMainThread());
return mPrincipal;
}
void NotifyWorkletFinished();
virtual nsContentPolicyType ContentPolicyType() const = 0;
@ -75,14 +71,15 @@ class WorkletImpl {
const OriginTrials& Trials() const { return mTrials; }
const WorkletLoadInfo& LoadInfo() const { return mWorkletLoadInfo; }
const OriginAttributes& OriginAttributesRef() const {
return mPrincipalInfo.get_NullPrincipalInfo().attrs();
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 mIsSystemPrincipal; }
bool IsSystemPrincipal() const { return mPrincipal->IsSystemPrincipal(); }
bool ShouldResistFingerprinting() const {
return mShouldResistFingerprinting;
}
@ -105,10 +102,7 @@ class WorkletImpl {
// Modified only in constructor.
ipc::PrincipalInfo mPrincipalInfo;
// Accessed on only worklet parent thread.
nsCOMPtr<nsIPrincipal> mPrincipal;
// For off-main-thread checks
bool mIsSystemPrincipal;
const WorkletLoadInfo mWorkletLoadInfo;