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,12 +344,13 @@ static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
JS_WriteBytes(aWriter, aBaseDomain.get(), aBaseDomain.Length()); JS_WriteBytes(aWriter, aBaseDomain.get(), aBaseDomain.Length());
} }
static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter, /* static */
bool nsJSPrincipals::WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
const PrincipalInfo& aInfo) { const PrincipalInfo& aInfo) {
if (aInfo.type() == PrincipalInfo::TNullPrincipalInfo) { if (aInfo.type() == PrincipalInfo::TNullPrincipalInfo) {
const NullPrincipalInfo& nullInfo = aInfo; const NullPrincipalInfo& nullInfo = aInfo;
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_NULL_PRINCIPAL, 0) && return JS_WriteUint32Pair(aWriter, SCTAG_DOM_NULL_PRINCIPAL, 0) &&
WritePrincipalInfo(aWriter, nullInfo.attrs(), nullInfo.spec(), ::WritePrincipalInfo(aWriter, nullInfo.attrs(), nullInfo.spec(),
EmptyCString(), EmptyCString()); EmptyCString(), EmptyCString());
} }
if (aInfo.type() == PrincipalInfo::TSystemPrincipalInfo) { if (aInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
@ -373,7 +374,7 @@ static bool WritePrincipalInfo(JSStructuredCloneWriter* aWriter,
MOZ_ASSERT(aInfo.type() == PrincipalInfo::TContentPrincipalInfo); MOZ_ASSERT(aInfo.type() == PrincipalInfo::TContentPrincipalInfo);
const ContentPrincipalInfo& cInfo = aInfo; const ContentPrincipalInfo& cInfo = aInfo;
return JS_WriteUint32Pair(aWriter, SCTAG_DOM_CONTENT_PRINCIPAL, 0) && return JS_WriteUint32Pair(aWriter, SCTAG_DOM_CONTENT_PRINCIPAL, 0) &&
WritePrincipalInfo(aWriter, cInfo.attrs(), cInfo.spec(), ::WritePrincipalInfo(aWriter, cInfo.attrs(), cInfo.spec(),
cInfo.originNoSuffix(), cInfo.baseDomain()); cInfo.originNoSuffix(), cInfo.baseDomain());
} }

View file

@ -9,6 +9,12 @@
#include "jsapi.h" #include "jsapi.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
namespace mozilla {
namespace ipc {
class PrincipalInfo;
} // namespace ipc
} // namespace mozilla
class nsJSPrincipals : public nsIPrincipal, public JSPrincipals { class nsJSPrincipals : public nsIPrincipal, public JSPrincipals {
public: public:
/* SpiderMonkey security callbacks. */ /* SpiderMonkey security callbacks. */
@ -24,6 +30,9 @@ class nsJSPrincipals : public nsIPrincipal, public JSPrincipals {
uint32_t aTag, uint32_t aTag,
JSPrincipals** aOutPrincipals); 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 // 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. // 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 // DOM workers do not use principals from Gecko's point of view, and any

View file

@ -6,7 +6,7 @@
#include "WorkletPrincipals.h" #include "WorkletPrincipals.h"
#include "mozilla/Assertions.h" #include "nsJSPrincipals.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -20,8 +20,11 @@ WorkletPrincipals::~WorkletPrincipals() = default;
bool WorkletPrincipals::write(JSContext* aCx, bool WorkletPrincipals::write(JSContext* aCx,
JSStructuredCloneWriter* aWriter) { JSStructuredCloneWriter* aWriter) {
MOZ_CRASH("WorkletPrincipals::write not implemented"); // This is a serialization of the NullPrincipal corresponding to the worklet
return false; // 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) { void WorkletPrincipals::Destroy(JSPrincipals* aPrincipals) {