Bug 1578623 implement WorkletPrincipals::write() r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D44605

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Karl Tomlinson 2019-09-06 02:10:31 +00:00
parent 079bad8d41
commit 18d04e5d8f
3 changed files with 22 additions and 9 deletions

View file

@ -344,13 +344,14 @@ static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
JS_WriteBytes(aWriter, aBaseDomain.get(), aBaseDomain.Length());
}
static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
const PrincipalInfo& aInfo) {
/* static */
bool nsJSPrincipals::WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
const PrincipalInfo& aInfo) {
if (aInfo.type() == PrincipalInfo::TNullPrincipalInfo) {
const NullPrincipalInfo& nullInfo = aInfo;
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_NULL_PRINCIPAL, 0) &&
WritePrincipalInfo(aWriter, nullInfo.attrs(), nullInfo.spec(),
EmptyCString(), EmptyCString());
::WritePrincipalInfo(aWriter, nullInfo.attrs(), nullInfo.spec(),
EmptyCString(), EmptyCString());
}
if (aInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_SYSTEM_PRINCIPAL, 0);
@ -373,8 +374,8 @@ static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
MOZ_ASSERT(aInfo.type() == PrincipalInfo::TContentPrincipalInfo);
const ContentPrincipalInfo& cInfo = aInfo;
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_CONTENT_PRINCIPAL, 0) &&
WritePrincipalInfo(aWriter, cInfo.attrs(), cInfo.spec(),
cInfo.originNoSuffix(), cInfo.baseDomain());
::WritePrincipalInfo(aWriter, cInfo.attrs(), cInfo.spec(),
cInfo.originNoSuffix(), cInfo.baseDomain());
}
bool nsJSPrincipals::write(JSContext* aCx, JSStructuredCloneWriter* aWriter) {

View file

@ -9,6 +9,12 @@
#include "jsapi.h"
#include "nsIPrincipal.h"
namespace mozilla {
namespace ipc {
class PrincipalInfo;
} // namespace ipc
} // namespace mozilla
class nsJSPrincipals : public nsIPrincipal, public JSPrincipals {
public:
/* SpiderMonkey security callbacks. */
@ -24,6 +30,9 @@ class nsJSPrincipals : public nsIPrincipal, public JSPrincipals {
uint32_t aTag,
JSPrincipals** aOutPrincipals);
/* For write() implementations of off-main-thread JSPrincipals. */
static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
const mozilla::ipc::PrincipalInfo& aInfo);
// This class is used on the main thread to specify which principal to use
// when reading principals data that was set on a DOM worker thread.
// DOM workers do not use principals from Gecko's point of view, and any

View file

@ -6,7 +6,7 @@
#include "WorkletPrincipals.h"
#include "mozilla/Assertions.h"
#include "nsJSPrincipals.h"
namespace mozilla {
namespace dom {
@ -20,8 +20,11 @@ WorkletPrincipals::~WorkletPrincipals() = default;
bool WorkletPrincipals::write(JSContext* aCx,
JSStructuredCloneWriter* aWriter) {
MOZ_CRASH("WorkletPrincipals::write not implemented");
return false;
// This is a serialization of the NullPrincipal corresponding to the worklet
// environment settings object for the WorkletGlobalScope.
// https://drafts.css-houdini.org/worklets/#set-up-a-worklet-environment-settings-object
return nsJSPrincipals::WritePrincipalInfo(aWriter,
mWorkletImpl->PrincipalInfo());
}
void WorkletPrincipals::Destroy(JSPrincipals* aPrincipals) {