2015-09-02 19:20:30 +03: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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
#include "StructuredCloneData.h"
|
2015-09-02 19:20:30 +03:00
|
|
|
|
|
|
|
#include "nsIDOMDOMException.h"
|
|
|
|
#include "nsIMutable.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
|
2015-10-23 00:10:14 +03:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2015-09-02 19:20:30 +03:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "mozilla/dom/BlobBinding.h"
|
|
|
|
#include "mozilla/dom/File.h"
|
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsJSEnvironment.h"
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "StructuredCloneTags.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2015-09-10 23:50:58 +03:00
|
|
|
namespace ipc {
|
2015-09-02 19:20:30 +03:00
|
|
|
|
|
|
|
bool
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData::Copy(const StructuredCloneData& aData)
|
2015-09-02 19:20:30 +03:00
|
|
|
{
|
2016-04-22 13:04:20 +03:00
|
|
|
if (!aData.mInitialized) {
|
2015-09-02 19:20:30 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-10 23:32:20 +03:00
|
|
|
if (aData.SharedData()) {
|
|
|
|
mSharedData = aData.SharedData();
|
|
|
|
} else {
|
|
|
|
mSharedData =
|
2016-04-22 13:04:20 +03:00
|
|
|
SharedJSAllocatedData::CreateFromExternalData(aData.Data());
|
2015-10-10 23:32:20 +03:00
|
|
|
NS_ENSURE_TRUE(mSharedData, false);
|
2015-09-02 19:20:30 +03:00
|
|
|
}
|
|
|
|
|
2016-11-07 16:38:02 +03:00
|
|
|
if (mSupportsTransferring) {
|
|
|
|
PortIdentifiers().AppendElements(aData.PortIdentifiers());
|
|
|
|
}
|
2016-02-15 21:43:00 +03:00
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
MOZ_ASSERT(BlobImpls().IsEmpty());
|
2015-09-10 23:50:58 +03:00
|
|
|
BlobImpls().AppendElements(aData.BlobImpls());
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2015-12-18 09:52:16 +03:00
|
|
|
MOZ_ASSERT(GetSurfaces().IsEmpty());
|
2016-10-28 15:44:04 +03:00
|
|
|
MOZ_ASSERT(WasmModules().IsEmpty());
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2016-04-22 13:04:20 +03:00
|
|
|
mInitialized = true;
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData::Read(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aValue,
|
|
|
|
ErrorResult &aRv)
|
2015-09-02 19:20:30 +03:00
|
|
|
{
|
2016-04-22 13:04:20 +03:00
|
|
|
MOZ_ASSERT(mInitialized);
|
2015-09-02 19:20:30 +03:00
|
|
|
|
|
|
|
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
2016-04-22 13:04:20 +03:00
|
|
|
ReadFromBuffer(global, aCx, Data(), aValue, aRv);
|
2015-09-02 19:20:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData::Write(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
ErrorResult &aRv)
|
2016-02-01 00:48:00 +03:00
|
|
|
{
|
|
|
|
Write(aCx, aValue, JS::UndefinedHandleValue, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::Write(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aTransfer,
|
|
|
|
ErrorResult &aRv)
|
2015-09-02 19:20:30 +03:00
|
|
|
{
|
2016-04-22 13:04:20 +03:00
|
|
|
MOZ_ASSERT(!mInitialized);
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2016-10-24 16:14:45 +03:00
|
|
|
StructuredCloneHolder::Write(aCx, aValue, aTransfer,
|
|
|
|
JS::CloneDataPolicy().denySharedArrayBuffer(), aRv);
|
2015-09-02 19:20:30 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-22 13:04:20 +03:00
|
|
|
JSStructuredCloneData data;
|
|
|
|
mBuffer->abandon();
|
|
|
|
mBuffer->steal(&data);
|
2015-09-02 19:20:30 +03:00
|
|
|
mBuffer = nullptr;
|
2016-04-22 13:04:20 +03:00
|
|
|
mSharedData = new SharedJSAllocatedData(Move(data));
|
|
|
|
mInitialized = true;
|
2015-09-02 19:20:30 +03:00
|
|
|
}
|
|
|
|
|
2016-11-07 16:38:02 +03:00
|
|
|
enum ActorFlavorEnum {
|
|
|
|
Parent = 0,
|
|
|
|
Child,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ManagerFlavorEnum {
|
|
|
|
ContentProtocol = 0,
|
|
|
|
BackgroundProtocol
|
|
|
|
};
|
|
|
|
|
|
|
|
template <ActorFlavorEnum>
|
|
|
|
struct BlobTraits
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct BlobTraits<Parent>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::BlobParent BlobType;
|
|
|
|
typedef mozilla::dom::PBlobParent ProtocolType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct BlobTraits<Child>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::BlobChild BlobType;
|
|
|
|
typedef mozilla::dom::PBlobChild ProtocolType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <ActorFlavorEnum, ManagerFlavorEnum>
|
|
|
|
struct ParentManagerTraits
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParentManagerTraits<Parent, ContentProtocol>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::nsIContentParent ConcreteContentManagerType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParentManagerTraits<Child, ContentProtocol>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::nsIContentChild ConcreteContentManagerType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParentManagerTraits<Parent, BackgroundProtocol>
|
|
|
|
{
|
|
|
|
typedef mozilla::ipc::PBackgroundParent ConcreteContentManagerType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct ParentManagerTraits<Child, BackgroundProtocol>
|
|
|
|
{
|
|
|
|
typedef mozilla::ipc::PBackgroundChild ConcreteContentManagerType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<ActorFlavorEnum>
|
|
|
|
struct DataBlobs
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct DataBlobs<Parent>
|
|
|
|
{
|
|
|
|
typedef BlobTraits<Parent>::ProtocolType ProtocolType;
|
|
|
|
|
|
|
|
static InfallibleTArray<ProtocolType*>& Blobs(ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const InfallibleTArray<ProtocolType*>& Blobs(const ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsParent();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct DataBlobs<Child>
|
|
|
|
{
|
|
|
|
typedef BlobTraits<Child>::ProtocolType ProtocolType;
|
|
|
|
|
|
|
|
static InfallibleTArray<ProtocolType*>& Blobs(ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const InfallibleTArray<ProtocolType*>& Blobs(const ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsChild();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<ActorFlavorEnum Flavor, ManagerFlavorEnum ManagerFlavor>
|
|
|
|
static bool
|
|
|
|
BuildClonedMessageData(typename ParentManagerTraits<Flavor, ManagerFlavor>::ConcreteContentManagerType* aManager,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
|
|
|
|
auto iter = aData.Data().Iter();
|
|
|
|
size_t size = aData.Data().Size();
|
|
|
|
bool success;
|
|
|
|
buffer.data = aData.Data().Borrow<js::SystemAllocPolicy>(iter, size, &success);
|
|
|
|
if (NS_WARN_IF(!success)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (aData.SupportsTransferring()) {
|
|
|
|
aClonedData.identfiers().AppendElements(aData.PortIdentifiers());
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsTArray<RefPtr<BlobImpl>>& blobImpls = aData.BlobImpls();
|
|
|
|
|
|
|
|
if (!blobImpls.IsEmpty()) {
|
|
|
|
typedef typename BlobTraits<Flavor>::BlobType BlobType;
|
|
|
|
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
|
|
|
|
InfallibleTArray<ProtocolType*>& blobList = DataBlobs<Flavor>::Blobs(aClonedData);
|
|
|
|
uint32_t length = blobImpls.Length();
|
|
|
|
blobList.SetCapacity(length);
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
BlobType* protocolActor = BlobType::GetOrCreate(aManager, blobImpls[i]);
|
|
|
|
if (!protocolActor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
blobList.AppendElement(protocolActor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StructuredCloneData::BuildClonedMessageDataForParent(
|
|
|
|
nsIContentParent* aParent,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
return BuildClonedMessageData<Parent, ContentProtocol>(aParent, *this, aClonedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StructuredCloneData::BuildClonedMessageDataForChild(
|
|
|
|
nsIContentChild* aChild,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
return BuildClonedMessageData<Child, ContentProtocol>(aChild, *this, aClonedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StructuredCloneData::BuildClonedMessageDataForBackgroundParent(
|
|
|
|
PBackgroundParent* aParent,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
return BuildClonedMessageData<Parent, BackgroundProtocol>(aParent, *this, aClonedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StructuredCloneData::BuildClonedMessageDataForBackgroundChild(
|
|
|
|
PBackgroundChild* aChild,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
return BuildClonedMessageData<Child, BackgroundProtocol>(aChild, *this, aClonedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
// See the StructuredCloneData class block comment for the meanings of each val.
|
|
|
|
enum MemoryFlavorEnum {
|
|
|
|
BorrowMemory = 0,
|
|
|
|
CopyMemory,
|
|
|
|
StealMemory
|
|
|
|
};
|
|
|
|
|
|
|
|
template<MemoryFlavorEnum>
|
|
|
|
struct MemoryTraits
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct MemoryTraits<BorrowMemory>
|
|
|
|
{
|
|
|
|
typedef const mozilla::dom::ClonedMessageData ClonedMessageType;
|
|
|
|
|
|
|
|
static void ProvideBuffer(const ClonedMessageData& aClonedData,
|
|
|
|
StructuredCloneData& aData)
|
|
|
|
{
|
|
|
|
const SerializedStructuredCloneBuffer& buffer = aClonedData.data();
|
|
|
|
aData.UseExternalData(buffer.data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct MemoryTraits<CopyMemory>
|
|
|
|
{
|
|
|
|
typedef const mozilla::dom::ClonedMessageData ClonedMessageType;
|
|
|
|
|
|
|
|
static void ProvideBuffer(const ClonedMessageData& aClonedData,
|
|
|
|
StructuredCloneData& aData)
|
|
|
|
{
|
|
|
|
const SerializedStructuredCloneBuffer& buffer = aClonedData.data();
|
|
|
|
aData.CopyExternalData(buffer.data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct MemoryTraits<StealMemory>
|
|
|
|
{
|
|
|
|
// note: not const!
|
|
|
|
typedef mozilla::dom::ClonedMessageData ClonedMessageType;
|
|
|
|
|
|
|
|
static void ProvideBuffer(ClonedMessageData& aClonedData,
|
|
|
|
StructuredCloneData& aData)
|
|
|
|
{
|
|
|
|
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
|
|
|
|
aData.StealExternalData(buffer.data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Note that there isn't actually a difference between Parent/BackgroundParent
|
|
|
|
// and Child/BackgroundChild in this implementation. The calling methods,
|
|
|
|
// however, do maintain the distinction for code-reading purposes and are backed
|
|
|
|
// by assertions to enforce there is no misuse.
|
|
|
|
template<MemoryFlavorEnum MemoryFlavor, ActorFlavorEnum Flavor>
|
|
|
|
static void
|
|
|
|
UnpackClonedMessageData(typename MemoryTraits<MemoryFlavor>::ClonedMessageType& aClonedData,
|
|
|
|
StructuredCloneData& aData)
|
|
|
|
{
|
|
|
|
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
|
|
|
|
const InfallibleTArray<ProtocolType*>& blobs = DataBlobs<Flavor>::Blobs(aClonedData);
|
|
|
|
const InfallibleTArray<MessagePortIdentifier>& identifiers = aClonedData.identfiers();
|
|
|
|
|
|
|
|
MemoryTraits<MemoryFlavor>::ProvideBuffer(aClonedData, aData);
|
|
|
|
|
|
|
|
if (aData.SupportsTransferring()) {
|
|
|
|
aData.PortIdentifiers().AppendElements(identifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!blobs.IsEmpty()) {
|
|
|
|
uint32_t length = blobs.Length();
|
|
|
|
aData.BlobImpls().SetCapacity(length);
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
auto* blob =
|
|
|
|
static_cast<typename BlobTraits<Flavor>::BlobType*>(blobs[i]);
|
|
|
|
MOZ_ASSERT(blob);
|
|
|
|
|
|
|
|
RefPtr<BlobImpl> blobImpl = blob->GetBlobImpl();
|
|
|
|
MOZ_ASSERT(blobImpl);
|
|
|
|
|
|
|
|
aData.BlobImpls().AppendElement(blobImpl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::BorrowFromClonedMessageDataForParent(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
// PContent parent is always main thread and actor constraints demand we're
|
|
|
|
// likewise on that thread.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
UnpackClonedMessageData<BorrowMemory, Parent>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::BorrowFromClonedMessageDataForChild(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
// PContent child is always main thread and actor constraints demand we're
|
|
|
|
// likewise on that thread.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
UnpackClonedMessageData<BorrowMemory, Child>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::BorrowFromClonedMessageDataForBackgroundParent(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsOnBackgroundThread());
|
|
|
|
UnpackClonedMessageData<BorrowMemory, Parent>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::BorrowFromClonedMessageDataForBackgroundChild(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
// No thread assertion; BackgroundChild can happen on any thread.
|
|
|
|
UnpackClonedMessageData<BorrowMemory, Child>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::CopyFromClonedMessageDataForParent(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
UnpackClonedMessageData<CopyMemory, Parent>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::CopyFromClonedMessageDataForChild(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
UnpackClonedMessageData<CopyMemory, Child>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::CopyFromClonedMessageDataForBackgroundParent(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsOnBackgroundThread());
|
|
|
|
UnpackClonedMessageData<BorrowMemory, Parent>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::CopyFromClonedMessageDataForBackgroundChild(const ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
UnpackClonedMessageData<CopyMemory, Child>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::StealFromClonedMessageDataForParent(ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
UnpackClonedMessageData<StealMemory, Parent>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::StealFromClonedMessageDataForChild(ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
UnpackClonedMessageData<StealMemory, Child>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::StealFromClonedMessageDataForBackgroundParent(ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsOnBackgroundThread());
|
|
|
|
UnpackClonedMessageData<StealMemory, Parent>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StructuredCloneData::StealFromClonedMessageDataForBackgroundChild(ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
UnpackClonedMessageData<StealMemory, Child>(aClonedData, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-09 10:10:32 +03:00
|
|
|
void
|
2015-10-23 00:10:14 +03:00
|
|
|
StructuredCloneData::WriteIPCParams(IPC::Message* aMsg) const
|
2015-09-09 10:10:32 +03:00
|
|
|
{
|
2016-04-22 13:04:20 +03:00
|
|
|
WriteParam(aMsg, Data());
|
2015-09-09 10:10:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData::ReadIPCParams(const IPC::Message* aMsg,
|
2016-04-21 07:09:15 +03:00
|
|
|
PickleIterator* aIter)
|
2015-09-09 10:10:32 +03:00
|
|
|
{
|
2016-04-22 13:04:20 +03:00
|
|
|
MOZ_ASSERT(!mInitialized);
|
|
|
|
JSStructuredCloneData data;
|
|
|
|
if (!ReadParam(aMsg, aIter, &data)) {
|
2015-09-09 10:10:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-22 13:04:20 +03:00
|
|
|
mSharedData = new SharedJSAllocatedData(Move(data));
|
|
|
|
mInitialized = true;
|
2015-09-09 10:10:32 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 10:11:38 +03:00
|
|
|
bool
|
2016-04-22 13:04:20 +03:00
|
|
|
StructuredCloneData::CopyExternalData(const char* aData,
|
2015-09-10 23:50:58 +03:00
|
|
|
size_t aDataLength)
|
2015-09-09 10:11:38 +03:00
|
|
|
{
|
2016-04-22 13:04:20 +03:00
|
|
|
MOZ_ASSERT(!mInitialized);
|
2015-10-10 23:32:20 +03:00
|
|
|
mSharedData = SharedJSAllocatedData::CreateFromExternalData(aData,
|
|
|
|
aDataLength);
|
|
|
|
NS_ENSURE_TRUE(mSharedData, false);
|
2016-04-22 13:04:20 +03:00
|
|
|
mInitialized = true;
|
2015-09-09 10:11:38 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-07 16:38:02 +03:00
|
|
|
bool
|
|
|
|
StructuredCloneData::CopyExternalData(const JSStructuredCloneData& aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mInitialized);
|
|
|
|
mSharedData = SharedJSAllocatedData::CreateFromExternalData(aData);
|
|
|
|
NS_ENSURE_TRUE(mSharedData, false);
|
|
|
|
mInitialized = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
StructuredCloneData::StealExternalData(JSStructuredCloneData& aData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mInitialized);
|
|
|
|
mSharedData = new SharedJSAllocatedData(Move(aData));
|
|
|
|
mInitialized = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
} // namespace ipc
|
2015-09-02 19:20:30 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|