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 "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"
|
2018-06-30 08:50:41 +03:00
|
|
|
#include "mozilla/dom/DOMTypes.h"
|
2015-09-02 19:20:30 +03:00
|
|
|
#include "mozilla/dom/File.h"
|
2018-06-30 08:50:41 +03:00
|
|
|
#include "mozilla/dom/IPCBlobUtils.h"
|
|
|
|
#include "mozilla/ipc/BackgroundParent.h"
|
2017-04-05 20:02:57 +03:00
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
2015-09-02 19:20:30 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsJSEnvironment.h"
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "StructuredCloneTags.h"
|
|
|
|
#include "jsapi.h"
|
|
|
|
|
2018-06-30 08:50:41 +03:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2015-09-10 23:50:58 +03:00
|
|
|
namespace ipc {
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2018-06-23 06:35:49 +03:00
|
|
|
using mozilla::ipc::AutoIPCStream;
|
|
|
|
using mozilla::ipc::IPCStream;
|
|
|
|
using mozilla::ipc::PBackgroundChild;
|
|
|
|
using mozilla::ipc::PBackgroundParent;
|
|
|
|
|
2017-04-05 20:02:57 +03:00
|
|
|
StructuredCloneData::StructuredCloneData()
|
|
|
|
: StructuredCloneData(StructuredCloneHolder::TransferringSupported) {}
|
|
|
|
|
|
|
|
StructuredCloneData::StructuredCloneData(StructuredCloneData&& aOther)
|
|
|
|
: StructuredCloneData(StructuredCloneHolder::TransferringSupported) {
|
2018-05-30 22:15:35 +03:00
|
|
|
*this = std::move(aOther);
|
2017-04-05 20:02:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StructuredCloneData::StructuredCloneData(
|
|
|
|
TransferringSupport aSupportsTransferring)
|
|
|
|
: StructuredCloneHolder(
|
|
|
|
StructuredCloneHolder::CloningSupported, aSupportsTransferring,
|
|
|
|
StructuredCloneHolder::StructuredCloneScope::DifferentProcess),
|
2018-04-03 21:17:33 +03:00
|
|
|
mExternalData(JS::StructuredCloneScope::DifferentProcess),
|
2017-04-05 20:02:57 +03:00
|
|
|
mInitialized(false) {}
|
|
|
|
|
|
|
|
StructuredCloneData::~StructuredCloneData() {}
|
|
|
|
|
|
|
|
StructuredCloneData& StructuredCloneData::operator=(
|
|
|
|
StructuredCloneData&& aOther) {
|
2018-07-20 04:14:13 +03:00
|
|
|
mBlobImplArray = std::move(aOther.mBlobImplArray);
|
2018-05-30 22:15:35 +03:00
|
|
|
mExternalData = std::move(aOther.mExternalData);
|
|
|
|
mSharedData = std::move(aOther.mSharedData);
|
|
|
|
mIPCStreams = std::move(aOther.mIPCStreams);
|
2017-04-05 20:02:57 +03:00
|
|
|
mInitialized = aOther.mInitialized;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
bool StructuredCloneData::Copy(const StructuredCloneData& aData) {
|
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 {
|
2016-04-22 13:04:20 +03:00
|
|
|
mSharedData = 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
|
|
|
|
2017-04-05 20:02:57 +03:00
|
|
|
MOZ_ASSERT(InputStreams().IsEmpty());
|
|
|
|
InputStreams().AppendElements(aData.InputStreams());
|
|
|
|
|
2016-04-22 13:04:20 +03:00
|
|
|
mInitialized = true;
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
void StructuredCloneData::Read(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aValue,
|
|
|
|
ErrorResult& aRv) {
|
2016-04-22 13:04:20 +03:00
|
|
|
MOZ_ASSERT(mInitialized);
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2018-07-11 15:07:02 +03:00
|
|
|
nsIGlobalObject* global = xpc::CurrentNativeGlobal(aCx);
|
2015-09-02 19:20:30 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
void 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) {
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-03 21:17:33 +03:00
|
|
|
JSStructuredCloneData data(mBuffer->scope());
|
2016-04-22 13:04:20 +03:00
|
|
|
mBuffer->abandon();
|
|
|
|
mBuffer->steal(&data);
|
2015-09-02 19:20:30 +03:00
|
|
|
mBuffer = nullptr;
|
2018-05-30 22:15:35 +03:00
|
|
|
mSharedData = new SharedJSAllocatedData(std::move(data));
|
2016-04-22 13:04:20 +03:00
|
|
|
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 };
|
|
|
|
|
2017-04-24 13:09:40 +03:00
|
|
|
template <typename M>
|
|
|
|
bool BuildClonedMessageData(M* aManager, StructuredCloneData& aData,
|
2016-11-07 16:38:02 +03:00
|
|
|
ClonedMessageData& aClonedData) {
|
|
|
|
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
|
2018-03-16 02:56:09 +03:00
|
|
|
auto iter = aData.Data().Start();
|
2016-11-07 16:38:02 +03:00
|
|
|
size_t size = aData.Data().Size();
|
|
|
|
bool success;
|
2018-04-03 21:17:33 +03:00
|
|
|
buffer.data = aData.Data().Borrow(iter, size, &success);
|
2016-11-07 16:38:02 +03:00
|
|
|
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()) {
|
2017-04-24 13:09:40 +03:00
|
|
|
if (NS_WARN_IF(
|
|
|
|
!aClonedData.blobs().SetLength(blobImpls.Length(), fallible))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < blobImpls.Length(); ++i) {
|
|
|
|
nsresult rv = IPCBlobUtils::Serialize(blobImpls[i], aManager,
|
|
|
|
aClonedData.blobs()[i]);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-11-07 16:38:02 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-05 20:02:57 +03:00
|
|
|
|
|
|
|
const nsTArray<nsCOMPtr<nsIInputStream>>& inputStreams = aData.InputStreams();
|
|
|
|
if (!inputStreams.IsEmpty()) {
|
2017-04-24 13:09:40 +03:00
|
|
|
if (NS_WARN_IF(
|
|
|
|
!aData.IPCStreams().SetCapacity(inputStreams.Length(), fallible))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-05 20:02:57 +03:00
|
|
|
InfallibleTArray<IPCStream>& streams = aClonedData.inputStreams();
|
|
|
|
uint32_t length = inputStreams.Length();
|
|
|
|
streams.SetCapacity(length);
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
AutoIPCStream* stream = aData.IPCStreams().AppendElement(fallible);
|
|
|
|
if (NS_WARN_IF(!stream)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stream->Serialize(inputStreams[i], aManager)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
streams.AppendElement(stream->TakeValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-07 16:38:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StructuredCloneData::BuildClonedMessageDataForParent(
|
2019-02-25 19:19:38 +03:00
|
|
|
nsIContentParent* aParent, ClonedMessageData& aClonedData) {
|
2017-04-24 13:09:40 +03:00
|
|
|
return BuildClonedMessageData(aParent, *this, aClonedData);
|
2016-11-07 16:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StructuredCloneData::BuildClonedMessageDataForChild(
|
2019-02-25 19:19:38 +03:00
|
|
|
nsIContentChild* aChild, ClonedMessageData& aClonedData) {
|
2017-04-24 13:09:40 +03:00
|
|
|
return BuildClonedMessageData(aChild, *this, aClonedData);
|
2016-11-07 16:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StructuredCloneData::BuildClonedMessageDataForBackgroundParent(
|
|
|
|
PBackgroundParent* aParent, ClonedMessageData& aClonedData) {
|
2017-04-24 13:09:40 +03:00
|
|
|
return BuildClonedMessageData(aParent, *this, aClonedData);
|
2016-11-07 16:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool StructuredCloneData::BuildClonedMessageDataForBackgroundChild(
|
|
|
|
PBackgroundChild* aChild, ClonedMessageData& aClonedData) {
|
2017-04-24 13:09:40 +03:00
|
|
|
return BuildClonedMessageData(aChild, *this, aClonedData);
|
2016-11-07 16:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
const InfallibleTArray<MessagePortIdentifier>& identifiers =
|
|
|
|
aClonedData.identfiers();
|
|
|
|
|
|
|
|
MemoryTraits<MemoryFlavor>::ProvideBuffer(aClonedData, aData);
|
|
|
|
|
|
|
|
if (aData.SupportsTransferring()) {
|
|
|
|
aData.PortIdentifiers().AppendElements(identifiers);
|
|
|
|
}
|
|
|
|
|
2017-04-24 13:09:40 +03:00
|
|
|
const nsTArray<IPCBlob>& blobs = aClonedData.blobs();
|
2016-11-07 16:38:02 +03:00
|
|
|
if (!blobs.IsEmpty()) {
|
|
|
|
uint32_t length = blobs.Length();
|
|
|
|
aData.BlobImpls().SetCapacity(length);
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2017-04-24 13:09:40 +03:00
|
|
|
RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(blobs[i]);
|
2016-11-07 16:38:02 +03:00
|
|
|
MOZ_ASSERT(blobImpl);
|
|
|
|
|
|
|
|
aData.BlobImpls().AppendElement(blobImpl);
|
|
|
|
}
|
|
|
|
}
|
2017-04-05 20:02:57 +03:00
|
|
|
|
|
|
|
const InfallibleTArray<IPCStream>& streams = aClonedData.inputStreams();
|
|
|
|
if (!streams.IsEmpty()) {
|
|
|
|
uint32_t length = streams.Length();
|
|
|
|
aData.InputStreams().SetCapacity(length);
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
|
|
|
nsCOMPtr<nsIInputStream> stream = DeserializeIPCStream(streams[i]);
|
|
|
|
aData.InputStreams().AppendElement(stream);
|
|
|
|
}
|
|
|
|
}
|
2016-11-07 16:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2018-06-25 17:03:18 +03:00
|
|
|
UnpackClonedMessageData<CopyMemory, Parent>(aClonedData, *this);
|
2016-11-07 16:38:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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-10-23 00:10:14 +03:00
|
|
|
void StructuredCloneData::WriteIPCParams(IPC::Message* aMsg) const {
|
2016-04-22 13:04:20 +03:00
|
|
|
WriteParam(aMsg, Data());
|
2015-09-09 10:10:32 +03:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
bool StructuredCloneData::ReadIPCParams(const IPC::Message* aMsg,
|
2016-04-21 07:09:15 +03:00
|
|
|
PickleIterator* aIter) {
|
2016-04-22 13:04:20 +03:00
|
|
|
MOZ_ASSERT(!mInitialized);
|
2018-04-03 21:17:33 +03:00
|
|
|
JSStructuredCloneData data(JS::StructuredCloneScope::DifferentProcess);
|
2016-04-22 13:04:20 +03:00
|
|
|
if (!ReadParam(aMsg, aIter, &data)) {
|
2015-09-09 10:10:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-05-30 22:15:35 +03:00
|
|
|
mSharedData = new SharedJSAllocatedData(std::move(data));
|
2016-04-22 13:04:20 +03:00
|
|
|
mInitialized = true;
|
2015-09-09 10:10:32 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-22 13:04:20 +03:00
|
|
|
bool StructuredCloneData::CopyExternalData(const char* aData,
|
2015-09-10 23:50:58 +03:00
|
|
|
size_t aDataLength) {
|
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);
|
2018-05-30 22:15:35 +03:00
|
|
|
mSharedData = new SharedJSAllocatedData(std::move(aData));
|
2016-11-07 16:38:02 +03:00
|
|
|
mInitialized = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:03:18 +03:00
|
|
|
already_AddRefed<SharedJSAllocatedData> StructuredCloneData::TakeSharedData() {
|
|
|
|
return mSharedData.forget();
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
} // namespace ipc
|
2015-09-02 19:20:30 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|