Bug 1198795 - ipc/StructuredCloneUtils should be merged with StructuredCloneHelper, r=smaug

This commit is contained in:
Andrea Marchesini 2015-09-02 17:20:30 +01:00
parent 647b24a490
commit 8d4eb66ee6
38 changed files with 437 additions and 395 deletions

View File

@ -28,7 +28,8 @@ PostMessageEvent::PostMessageEvent(nsGlobalWindow* aSource,
nsGlobalWindow* aTargetWindow,
nsIPrincipal* aProvidedPrincipal,
bool aTrustedCaller)
: StructuredCloneHelper(CloningSupported, TransferringSupported),
: StructuredCloneHelper(CloningSupported, TransferringSupported,
SameProcessSameThread),
mSource(aSource),
mCallerOrigin(aCallerOrigin),
mTargetWindow(aTargetWindow),

View File

@ -167,7 +167,13 @@ StructuredCloneHelperInternal::Write(JSContext* aCx,
MOZ_ASSERT(!mShutdownCalled, "This method cannot be called after Shutdown.");
mBuffer = new JSAutoStructuredCloneBuffer(&gCallbacks, this);
return mBuffer->write(aCx, aValue, aTransfer, &gCallbacks, this);
if (!mBuffer->write(aCx, aValue, aTransfer, &gCallbacks, this)) {
mBuffer = nullptr;
return false;
}
return true;
}
bool
@ -217,10 +223,15 @@ StructuredCloneHelperInternal::FreeTransferCallback(uint32_t aTag,
// StructuredCloneHelper class
StructuredCloneHelper::StructuredCloneHelper(CloningSupport aSupportsCloning,
TransferringSupport aSupportsTransferring)
TransferringSupport aSupportsTransferring,
ContextSupport aContext)
: mSupportsCloning(aSupportsCloning == CloningSupported)
, mSupportsTransferring(aSupportsTransferring == TransferringSupported)
, mContext(aContext)
, mParent(nullptr)
#ifdef DEBUG
, mCreationThread(NS_GetCurrentThread())
#endif
{}
StructuredCloneHelper::~StructuredCloneHelper()
@ -232,25 +243,26 @@ StructuredCloneHelper::~StructuredCloneHelper()
void
StructuredCloneHelper::Write(JSContext* aCx,
JS::Handle<JS::Value> aValue,
bool aMaybeToDifferentThread,
ErrorResult& aRv)
{
Write(aCx, aValue, JS::UndefinedHandleValue, aMaybeToDifferentThread, aRv);
Write(aCx, aValue, JS::UndefinedHandleValue, aRv);
}
void
StructuredCloneHelper::Write(JSContext* aCx,
JS::Handle<JS::Value> aValue,
JS::Handle<JS::Value> aTransfer,
bool aMaybeToDifferentThread,
ErrorResult& aRv)
{
MOZ_ASSERT_IF(mContext == SameProcessSameThread,
mCreationThread == NS_GetCurrentThread());
if (!StructuredCloneHelperInternal::Write(aCx, aValue, aTransfer)) {
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
return;
}
if (aMaybeToDifferentThread) {
if (mContext != SameProcessSameThread) {
for (uint32_t i = 0, len = mBlobImplArray.Length(); i < len; ++i) {
if (!mBlobImplArray[i]->MayBeClonedToOtherThreads()) {
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
@ -266,6 +278,9 @@ StructuredCloneHelper::Read(nsISupports* aParent,
JS::MutableHandle<JS::Value> aValue,
ErrorResult& aRv)
{
MOZ_ASSERT_IF(mContext == SameProcessSameThread,
mCreationThread == NS_GetCurrentThread());
mozilla::AutoRestore<nsISupports*> guard(mParent);
mParent = aParent;
@ -303,6 +318,9 @@ StructuredCloneHelper::ReadFromBuffer(nsISupports* aParent,
JS::MutableHandle<JS::Value> aValue,
ErrorResult& aRv)
{
MOZ_ASSERT_IF(mContext == SameProcessSameThread,
mCreationThread == NS_GetCurrentThread());
MOZ_ASSERT(!mBuffer, "ReadFromBuffer() must be called without a Write().");
MOZ_ASSERT(aBuffer);
@ -320,6 +338,9 @@ void
StructuredCloneHelper::MoveBufferDataToArray(FallibleTArray<uint8_t>& aArray,
ErrorResult& aRv)
{
MOZ_ASSERT_IF(mContext == SameProcessSameThread,
mCreationThread == NS_GetCurrentThread());
MOZ_ASSERT(mBuffer, "MoveBuffer() cannot be called without a Write().");
if (NS_WARN_IF(!aArray.SetLength(BufferSize(), mozilla::fallible))) {
@ -719,6 +740,9 @@ StructuredCloneHelper::ReadCallback(JSContext* aCx,
}
if (aTag == SCTAG_DOM_IMAGEBITMAP) {
MOZ_ASSERT(mContext == SameProcessSameThread ||
mContext == SameProcessDifferentThread);
// Get the current global object.
// This can be null.
nsCOMPtr<nsIGlobalObject> parent = do_QueryInterface(mParent);
@ -772,7 +796,8 @@ StructuredCloneHelper::WriteCallback(JSContext* aCx,
}
// See if this is an ImageBitmap object.
{
if (mContext == SameProcessSameThread ||
mContext == SameProcessDifferentThread) {
ImageBitmap* imageBitmap = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(ImageBitmap, aObj, imageBitmap))) {
return ImageBitmap::WriteStructuredClone(aWriter,

View File

@ -125,25 +125,35 @@ public:
TransferringNotSupported
};
enum ContextSupport
{
SameProcessSameThread,
SameProcessDifferentThread,
DifferentProcess
};
// If cloning is supported, this object will clone objects such as Blobs,
// FileList, ImageData, etc.
// If transferring is supported, we will transfer MessagePorts and in the
// future other transferrable objects.
// The ContextSupport is useful to know where the cloned/transferred data can
// be read and written. Additional checks about the nature of the objects
// will be done based on this context value because not all the objects can
// be sent between threads or processes.
explicit StructuredCloneHelper(CloningSupport aSupportsCloning,
TransferringSupport aSupportsTransferring);
TransferringSupport aSupportsTransferring,
ContextSupport aContextSupport);
virtual ~StructuredCloneHelper();
// Normally you should just use Write() and Read().
void Write(JSContext* aCx,
JS::Handle<JS::Value> aValue,
bool aMaybeToDifferentThread,
ErrorResult &aRv);
void Write(JSContext* aCx,
JS::Handle<JS::Value> aValue,
JS::Handle<JS::Value> aTransfer,
bool aMaybeToDifferentThread,
ErrorResult &aRv);
void Read(nsISupports* aParent,
@ -246,9 +256,10 @@ public:
JS::TransferableOwnership aOwnership,
void* aContent,
uint64_t aExtraData) override;
private:
protected:
bool mSupportsCloning;
bool mSupportsTransferring;
ContextSupport mContext;
// Useful for the structured clone algorithm:
@ -272,6 +283,10 @@ private:
// are able to reconnect the new transferred ports with the other
// MessageChannel ports.
nsTArray<MessagePortIdentifier> mPortIdentifiers;
#ifdef DEBUG
nsCOMPtr<nsIThread> mCreationThread;
#endif
};
} // dom namespace

View File

@ -92,7 +92,7 @@
#include "nsSandboxFlags.h"
#include "mozilla/layers/CompositorChild.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/StructuredCloneIPCHelper.h"
#include "mozilla/WebBrowserPersistLocalDocument.h"
#ifdef MOZ_XUL
@ -2411,10 +2411,10 @@ public:
nsAsyncMessageToChild(JSContext* aCx,
nsFrameLoader* aFrameLoader,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aHelper, aCpows, aPrincipal)
, mFrameLoader(aFrameLoader)
{
}
@ -2436,7 +2436,7 @@ public:
bool
nsFrameLoader::DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
@ -2444,7 +2444,7 @@ nsFrameLoader::DoSendAsyncMessage(JSContext* aCx,
if (tabParent) {
ClonedMessageData data;
nsIContentParent* cp = tabParent->Manager();
if (!BuildClonedMessageDataForParent(cp, aData, data)) {
if (!BuildClonedMessageDataForParent(cp, aHelper, data)) {
return false;
}
InfallibleTArray<mozilla::jsipc::CpowEntry> cpows;
@ -2458,7 +2458,7 @@ nsFrameLoader::DoSendAsyncMessage(JSContext* aCx,
if (mChildMessageManager) {
nsCOMPtr<nsIRunnable> ev = new nsAsyncMessageToChild(aCx, this, aMessage,
aData, aCpows,
aHelper, aCpows,
aPrincipal);
NS_DispatchToCurrentThread(ev);
return true;

View File

@ -41,8 +41,8 @@ namespace mozilla {
namespace dom {
class ContentParent;
class PBrowserParent;
class StructuredCloneIPCHelper;
class TabParent;
struct StructuredCloneData;
} // namespace dom
namespace layout {
@ -90,7 +90,7 @@ public:
bool aRunInGlobalScope) override;
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
mozilla::dom::StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override;
virtual bool CheckPermission(const nsAString& aPermission) override;

View File

@ -37,7 +37,7 @@
#include "mozilla/dom/ProcessGlobal.h"
#include "mozilla/dom/SameProcessMessageQueue.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/StructuredCloneIPCHelper.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/dom/DOMStringList.h"
@ -276,13 +276,14 @@ struct DataBlobs<Child>
template<ActorFlavorEnum Flavor>
static bool
BuildClonedMessageData(typename BlobTraits<Flavor>::ConcreteContentManagerType* aManager,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
ClonedMessageData& aClonedData)
{
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsRefPtr<BlobImpl>>& blobImpls = aData.mClosure.mBlobImpls;
buffer.data = aHelper.Data();
buffer.dataLength = aHelper.DataLength();
const nsTArray<nsRefPtr<BlobImpl>>& blobImpls = aHelper.BlobImpls();
if (!blobImpls.IsEmpty()) {
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
InfallibleTArray<ProtocolType*>& blobList = DataBlobs<Flavor>::Blobs(aClonedData);
@ -302,33 +303,34 @@ BuildClonedMessageData(typename BlobTraits<Flavor>::ConcreteContentManagerType*
bool
MessageManagerCallback::BuildClonedMessageDataForParent(nsIContentParent* aParent,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
ClonedMessageData& aClonedData)
{
return BuildClonedMessageData<Parent>(aParent, aData, aClonedData);
return BuildClonedMessageData<Parent>(aParent, aHelper, aClonedData);
}
bool
MessageManagerCallback::BuildClonedMessageDataForChild(nsIContentChild* aChild,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
ClonedMessageData& aClonedData)
{
return BuildClonedMessageData<Child>(aChild, aData, aClonedData);
return BuildClonedMessageData<Child>(aChild, aHelper, aClonedData);
}
template<ActorFlavorEnum Flavor>
static StructuredCloneData
UnpackClonedMessageData(const ClonedMessageData& aData)
static void
UnpackClonedMessageData(const ClonedMessageData& aData,
StructuredCloneIPCHelper& aHelper)
{
const SerializedStructuredCloneBuffer& buffer = aData.data();
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
const InfallibleTArray<ProtocolType*>& blobs = DataBlobs<Flavor>::Blobs(aData);
StructuredCloneData cloneData;
cloneData.mData = buffer.data;
cloneData.mDataLength = buffer.dataLength;
aHelper.UseExternalData(buffer.data, buffer.dataLength);
if (!blobs.IsEmpty()) {
uint32_t length = blobs.Length();
cloneData.mClosure.mBlobImpls.SetCapacity(length);
aHelper.BlobImpls().SetCapacity(length);
for (uint32_t i = 0; i < length; ++i) {
auto* blob =
static_cast<typename BlobTraits<Flavor>::BlobType*>(blobs[i]);
@ -337,22 +339,23 @@ UnpackClonedMessageData(const ClonedMessageData& aData)
nsRefPtr<BlobImpl> blobImpl = blob->GetBlobImpl();
MOZ_ASSERT(blobImpl);
cloneData.mClosure.mBlobImpls.AppendElement(blobImpl);
aHelper.BlobImpls().AppendElement(blobImpl);
}
}
return cloneData;
}
StructuredCloneData
mozilla::dom::ipc::UnpackClonedMessageDataForParent(const ClonedMessageData& aData)
void
mozilla::dom::ipc::UnpackClonedMessageDataForParent(const ClonedMessageData& aData,
StructuredCloneIPCHelper& aHelper)
{
return UnpackClonedMessageData<Parent>(aData);
UnpackClonedMessageData<Parent>(aData, aHelper);
}
StructuredCloneData
mozilla::dom::ipc::UnpackClonedMessageDataForChild(const ClonedMessageData& aData)
void
mozilla::dom::ipc::UnpackClonedMessageDataForChild(const ClonedMessageData& aData,
StructuredCloneIPCHelper& aHelper)
{
return UnpackClonedMessageData<Child>(aData);
UnpackClonedMessageData<Child>(aData, aHelper);
}
bool
@ -650,14 +653,17 @@ JSONCreator(const char16_t* aBuf, uint32_t aLen, void* aData)
static bool
GetParamsForMessage(JSContext* aCx,
const JS::Value& aData,
JSAutoStructuredCloneBuffer& aBuffer,
StructuredCloneClosure& aClosure)
StructuredCloneIPCHelper& aHelper)
{
// First try to use structured clone on the whole thing.
JS::RootedValue v(aCx, aData);
if (WriteStructuredClone(aCx, v, aBuffer, aClosure)) {
ErrorResult rv;
aHelper.Write(aCx, v, rv);
if (!rv.Failed()) {
return true;
}
rv.SuppressException();
JS_ClearPendingException(aCx);
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
@ -685,7 +691,13 @@ GetParamsForMessage(JSContext* aCx,
NS_ENSURE_TRUE(JS_ParseJSON(aCx, static_cast<const char16_t*>(json.get()),
json.Length(), &val), false);
return WriteStructuredClone(aCx, val, aBuffer, aClosure);
aHelper.Write(aCx, val, rv);
if (NS_WARN_IF(rv.Failed())) {
rv.SuppressException();
return false;
}
return true;
}
@ -741,14 +753,10 @@ nsFrameMessageManager::SendMessage(const nsAString& aMessageName,
return NS_ERROR_UNEXPECTED;
}
StructuredCloneData data;
JSAutoStructuredCloneBuffer buffer;
if (aArgc >= 2 &&
!GetParamsForMessage(aCx, aJSON, buffer, data.mClosure)) {
StructuredCloneIPCHelper helper;
if (aArgc >= 2 && !GetParamsForMessage(aCx, aJSON, helper)) {
return NS_ERROR_DOM_DATA_CLONE_ERR;
}
data.mData = buffer.data();
data.mDataLength = buffer.nbytes();
JS::Rooted<JSObject*> objects(aCx);
if (aArgc >= 3 && aObjects.isObject()) {
@ -758,13 +766,13 @@ nsFrameMessageManager::SendMessage(const nsAString& aMessageName,
nsTArray<OwningSerializedStructuredCloneBuffer> retval;
sSendingSyncMessage |= aIsSync;
bool rv = mCallback->DoSendBlockingMessage(aCx, aMessageName, data, objects,
bool ok = mCallback->DoSendBlockingMessage(aCx, aMessageName, helper, objects,
aPrincipal, &retval, aIsSync);
if (aIsSync) {
sSendingSyncMessage = false;
}
if (!rv) {
if (!ok) {
return NS_OK;
}
@ -791,7 +799,7 @@ nsFrameMessageManager::SendMessage(const nsAString& aMessageName,
nsresult
nsFrameMessageManager::DispatchAsyncMessageInternal(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
@ -799,7 +807,7 @@ nsFrameMessageManager::DispatchAsyncMessageInternal(JSContext* aCx,
int32_t len = mChildManagers.Count();
for (int32_t i = 0; i < len; ++i) {
static_cast<nsFrameMessageManager*>(mChildManagers[i])->
DispatchAsyncMessageInternal(aCx, aMessage, aData, aCpows, aPrincipal);
DispatchAsyncMessageInternal(aCx, aMessage, aHelper, aCpows, aPrincipal);
}
return NS_OK;
}
@ -808,7 +816,7 @@ nsFrameMessageManager::DispatchAsyncMessageInternal(JSContext* aCx,
return NS_ERROR_NOT_INITIALIZED;
}
if (!mCallback->DoSendAsyncMessage(aCx, aMessage, aData, aCpows, aPrincipal)) {
if (!mCallback->DoSendAsyncMessage(aCx, aMessage, aHelper, aCpows, aPrincipal)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
@ -822,11 +830,8 @@ nsFrameMessageManager::DispatchAsyncMessage(const nsAString& aMessageName,
JSContext* aCx,
uint8_t aArgc)
{
StructuredCloneData data;
JSAutoStructuredCloneBuffer buffer;
if (aArgc >= 2 &&
!GetParamsForMessage(aCx, aJSON, buffer, data.mClosure)) {
StructuredCloneIPCHelper helper;
if (aArgc >= 2 && !GetParamsForMessage(aCx, aJSON, helper)) {
return NS_ERROR_DOM_DATA_CLONE_ERR;
}
@ -835,10 +840,7 @@ nsFrameMessageManager::DispatchAsyncMessage(const nsAString& aMessageName,
objects = &aObjects.toObject();
}
data.mData = buffer.data();
data.mDataLength = buffer.nbytes();
return DispatchAsyncMessageInternal(aCx, aMessageName, data, objects,
return DispatchAsyncMessageInternal(aCx, aMessageName, helper, objects,
aPrincipal);
}
@ -1067,13 +1069,13 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
nsIFrameLoader* aTargetFrameLoader,
const nsAString& aMessage,
bool aIsSync,
const StructuredCloneData* aCloneData,
StructuredCloneIPCHelper* aCloneHelper,
mozilla::jsipc::CpowHolder* aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal)
{
return ReceiveMessage(aTarget, aTargetFrameLoader, mClosed, aMessage, aIsSync,
aCloneData, aCpows, aPrincipal, aRetVal);
aCloneHelper, aCpows, aPrincipal, aRetVal);
}
nsresult
@ -1082,7 +1084,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
bool aTargetClosed,
const nsAString& aMessage,
bool aIsSync,
const StructuredCloneData* aCloneData,
StructuredCloneIPCHelper* aCloneHelper,
mozilla::jsipc::CpowHolder* aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal)
@ -1166,10 +1168,14 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
JS::Rooted<JS::Value> cpowsv(cx, JS::ObjectValue(*cpows));
JS::Rooted<JS::Value> json(cx, JS::NullValue());
if (aCloneData && aCloneData->mDataLength &&
!ReadStructuredClone(cx, *aCloneData, &json)) {
JS_ClearPendingException(cx);
return NS_OK;
if (aCloneHelper && aCloneHelper->DataLength()) {
ErrorResult rv;
aCloneHelper->Read(cx, &json, rv);
if (NS_WARN_IF(rv.Failed())) {
rv.SuppressException();
JS_ClearPendingException(cx);
return NS_OK;
}
}
JS::Rooted<JSString*> jsMessage(cx,
JS_NewUCStringCopyN(cx,
@ -1285,7 +1291,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
nsRefPtr<nsFrameMessageManager> kungfuDeathGrip = mParentManager;
return mParentManager ? mParentManager->ReceiveMessage(aTarget, aTargetFrameLoader,
aTargetClosed, aMessage,
aIsSync, aCloneData,
aIsSync, aCloneHelper,
aCpows, aPrincipal,
aRetVal) : NS_OK;
}
@ -1889,10 +1895,10 @@ class nsAsyncMessageToSameProcessChild : public nsSameProcessAsyncMessageBase,
public:
nsAsyncMessageToSameProcessChild(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aHelper, aCpows, aPrincipal)
{
}
@ -1931,12 +1937,12 @@ public:
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override
{
nsCOMPtr<nsIRunnable> ev =
new nsAsyncMessageToSameProcessChild(aCx, aMessage, aData, aCpows,
new nsAsyncMessageToSameProcessChild(aCx, aMessage, aHelper, aCpows,
aPrincipal);
NS_DispatchToCurrentThread(ev);
return true;
@ -1985,7 +1991,7 @@ public:
virtual bool DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
@ -1997,7 +2003,7 @@ public:
return true;
}
ClonedMessageData data;
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
if (!BuildClonedMessageDataForChild(cc, aHelper, data)) {
return false;
}
InfallibleTArray<mozilla::jsipc::CpowEntry> cpows;
@ -2014,7 +2020,7 @@ public:
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override
{
@ -2024,7 +2030,7 @@ public:
return true;
}
ClonedMessageData data;
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
if (!BuildClonedMessageDataForChild(cc, aHelper, data)) {
return false;
}
InfallibleTArray<mozilla::jsipc::CpowEntry> cpows;
@ -2044,10 +2050,10 @@ class nsAsyncMessageToSameProcessParent : public nsSameProcessAsyncMessageBase,
public:
nsAsyncMessageToSameProcessParent(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aHelper, aCpows, aPrincipal)
{
}
@ -2076,7 +2082,7 @@ public:
virtual bool DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
@ -2089,20 +2095,20 @@ public:
SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows);
nsRefPtr<nsFrameMessageManager> ppm = nsFrameMessageManager::sSameProcessParentManager;
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), nullptr, aMessage,
true, &aData, &cpows, aPrincipal, aRetVal);
true, &aHelper, &cpows, aPrincipal, aRetVal);
}
return true;
}
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override
{
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
nsRefPtr<nsAsyncMessageToSameProcessParent> ev =
new nsAsyncMessageToSameProcessParent(aCx, aMessage, aData, aCpows, aPrincipal);
new nsAsyncMessageToSameProcessParent(aCx, aMessage, aHelper, aCpows, aPrincipal);
queue->Push(ev);
return true;
}
@ -2202,7 +2208,7 @@ nsFrameMessageManager::MarkForCC()
nsSameProcessAsyncMessageBase::nsSameProcessAsyncMessageBase(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject*> aCpows,
nsIPrincipal* aPrincipal)
: mRuntime(js::GetRuntime(aCx)),
@ -2210,14 +2216,13 @@ nsSameProcessAsyncMessageBase::nsSameProcessAsyncMessageBase(JSContext* aCx,
mCpows(aCx, aCpows),
mPrincipal(aPrincipal)
{
if (aData.mDataLength && !mData.copy(aData.mData, aData.mDataLength)) {
if (!mHelper.Copy(aHelper)) {
#ifdef MOZ_CRASHREPORTER
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("AsyncMessageOOM"),
NS_ConvertUTF16toUTF8(aMessage));
#endif
NS_ABORT_OOM(aData.mDataLength);
NS_ABORT_OOM(aHelper.DataLength());
}
mClosure = aData.mClosure;
}
void
@ -2226,15 +2231,10 @@ nsSameProcessAsyncMessageBase::ReceiveMessage(nsISupports* aTarget,
nsFrameMessageManager* aManager)
{
if (aManager) {
StructuredCloneData data;
data.mData = mData.data();
data.mDataLength = mData.nbytes();
data.mClosure = mClosure;
SameProcessCpowHolder cpows(mRuntime, mCpows);
nsRefPtr<nsFrameMessageManager> mm = aManager;
mm->ReceiveMessage(aTarget, aTargetFrameLoader, mMessage, false, &data, &cpows,
mPrincipal, nullptr);
mm->ReceiveMessage(aTarget, aTargetFrameLoader, mMessage, false, &mHelper,
&cpows, mPrincipal, nullptr);
}
}

View File

@ -28,7 +28,7 @@
#include "js/RootingAPI.h"
#include "nsTObserverArray.h"
#include "mozilla/dom/SameProcessMessageQueue.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/StructuredCloneIPCHelper.h"
#include "mozilla/jsipc/CpowHolder.h"
class nsIFrameLoader;
@ -70,7 +70,7 @@ public:
virtual bool DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject*> aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
@ -81,7 +81,7 @@ public:
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject*> aCpows,
nsIPrincipal* aPrincipal)
{
@ -116,15 +116,18 @@ public:
protected:
bool BuildClonedMessageDataForParent(nsIContentParent* aParent,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
ClonedMessageData& aClonedData);
bool BuildClonedMessageDataForChild(nsIContentChild* aChild,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
ClonedMessageData& aClonedData);
};
StructuredCloneData UnpackClonedMessageDataForParent(const ClonedMessageData& aData);
StructuredCloneData UnpackClonedMessageDataForChild(const ClonedMessageData& aData);
void UnpackClonedMessageDataForParent(const ClonedMessageData& aData,
StructuredCloneIPCHelper& aHelper);
void UnpackClonedMessageDataForChild(const ClonedMessageData& aData,
StructuredCloneIPCHelper& aHelper);
} // namespace ipc
} // namespace dom
@ -166,7 +169,7 @@ class nsFrameMessageManager final : public nsIContentFrameMessageManager,
public nsIProcessChecker
{
friend class mozilla::dom::MessageManagerReporter;
typedef mozilla::dom::StructuredCloneData StructuredCloneData;
typedef mozilla::dom::StructuredCloneIPCHelper StructuredCloneIPCHelper;
typedef mozilla::OwningSerializedStructuredCloneBuffer OwningSerializedStructuredCloneBuffer;
public:
nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback,
@ -196,7 +199,7 @@ public:
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
const nsAString& aMessage,
bool aIsSync, const StructuredCloneData* aCloneData,
bool aIsSync, StructuredCloneIPCHelper* aCloneHelper,
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal);
@ -223,7 +226,7 @@ public:
uint8_t aArgc);
nsresult DispatchAsyncMessageInternal(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject*> aCpows,
nsIPrincipal* aPrincipal);
void RemoveFromParent();
@ -264,7 +267,7 @@ private:
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
bool aTargetClosed, const nsAString& aMessage,
bool aIsSync, const StructuredCloneData* aCloneData,
bool aIsSync, StructuredCloneIPCHelper* aCloneHelper,
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal);
@ -329,14 +332,12 @@ private:
*/
class nsSameProcessAsyncMessageBase
{
typedef mozilla::dom::StructuredCloneClosure StructuredCloneClosure;
public:
typedef mozilla::dom::StructuredCloneData StructuredCloneData;
typedef mozilla::dom::StructuredCloneIPCHelper StructuredCloneIPCHelper;
nsSameProcessAsyncMessageBase(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject*> aCpows,
nsIPrincipal* aPrincipal);
@ -348,8 +349,7 @@ private:
JSRuntime* mRuntime;
nsString mMessage;
JSAutoStructuredCloneBuffer mData;
StructuredCloneClosure mClosure;
StructuredCloneIPCHelper mHelper;
JS::PersistentRooted<JSObject*> mCpows;
nsCOMPtr<nsIPrincipal> mPrincipal;
};

View File

@ -8652,7 +8652,7 @@ nsGlobalWindow::PostMessageMozOuter(JSContext* aCx, JS::Handle<JS::Value> aMessa
JS::Rooted<JS::Value> message(aCx, aMessage);
JS::Rooted<JS::Value> transfer(aCx, aTransfer);
event->Write(aCx, message, transfer, false, aError);
event->Write(aCx, message, transfer, aError);
if (NS_WARN_IF(aError.Failed())) {
return;
}

View File

@ -18,18 +18,14 @@
#include "nsDOMClassInfoID.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/SameProcessMessageQueue.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "js/StructuredClone.h"
using mozilla::dom::StructuredCloneData;
using mozilla::dom::StructuredCloneClosure;
using namespace mozilla;
using namespace mozilla::dom;
bool
nsInProcessTabChildGlobal::DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const dom::StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
@ -42,7 +38,7 @@ nsInProcessTabChildGlobal::DoSendBlockingMessage(JSContext* aCx,
SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows);
nsRefPtr<nsFrameMessageManager> mm = mChromeMessageManager;
nsCOMPtr<nsIFrameLoader> fl = GetFrameLoader();
mm->ReceiveMessage(mOwner, fl, aMessage, true, &aData, &cpows, aPrincipal,
mm->ReceiveMessage(mOwner, fl, aMessage, true, &aHelper, &cpows, aPrincipal,
aRetVal);
}
return true;
@ -55,10 +51,10 @@ public:
nsAsyncMessageToParent(JSContext* aCx,
nsInProcessTabChildGlobal* aTabChild,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal),
: nsSameProcessAsyncMessageBase(aCx, aMessage, aHelper, aCpows, aPrincipal),
mTabChild(aTabChild)
{
}
@ -75,13 +71,13 @@ public:
bool
nsInProcessTabChildGlobal::DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
nsRefPtr<nsAsyncMessageToParent> ev =
new nsAsyncMessageToParent(aCx, this, aMessage, aData, aCpows, aPrincipal);
new nsAsyncMessageToParent(aCx, this, aMessage, aHelper, aCpows, aPrincipal);
queue->Push(ev);
return true;
}

View File

@ -83,14 +83,14 @@ public:
*/
virtual bool DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
mozilla::dom::StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
bool aIsSync) override;
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
mozilla::dom::StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override;

View File

@ -31,7 +31,8 @@ NS_INTERFACE_MAP_BEGIN(nsStructuredCloneContainer)
NS_INTERFACE_MAP_END
nsStructuredCloneContainer::nsStructuredCloneContainer()
: StructuredCloneHelper(CloningSupported, TransferringNotSupported)
: StructuredCloneHelper(CloningSupported, TransferringNotSupported,
DifferentProcess)
, mState(eNotInitialized) , mData(nullptr), mSize(0), mVersion(0)
{
}
@ -52,7 +53,7 @@ nsStructuredCloneContainer::InitFromJSVal(JS::Handle<JS::Value> aData,
}
ErrorResult rv;
Write(aCx, aData, true, rv);
Write(aCx, aData, rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}

View File

@ -37,7 +37,8 @@ public:
NS_INLINE_DECL_REFCOUNTING(BroadcastChannelMessage)
BroadcastChannelMessage()
: StructuredCloneHelper(CloningSupported, TransferringNotSupported)
: StructuredCloneHelper(CloningSupported, TransferringNotSupported,
DifferentProcess)
{}
private:
@ -454,7 +455,7 @@ BroadcastChannel::PostMessageInternal(JSContext* aCx,
{
nsRefPtr<BroadcastChannelMessage> data = new BroadcastChannelMessage();
data->Write(aCx, aMessage, true, aRv);
data->Write(aCx, aMessage, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

View File

@ -88,7 +88,8 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
JSContext* cx = jsapi.cx();
const SerializedStructuredCloneBuffer& buffer = aData.data();
StructuredCloneHelper cloneHelper(StructuredCloneHelper::CloningSupported,
StructuredCloneHelper::TransferringNotSupported);
StructuredCloneHelper::TransferringNotSupported,
StructuredCloneHelper::DifferentProcess);
cloneHelper.BlobImpls().AppendElements(blobs);

View File

@ -7,7 +7,6 @@
#include "mozilla/dom/ContentBridgeChild.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"

View File

@ -178,7 +178,7 @@
#endif
#include "ProcessUtils.h"
#include "StructuredCloneUtils.h"
#include "StructuredCloneIPCHelper.h"
#include "URIUtils.h"
#include "nsContentUtils.h"
#include "nsIPrincipal.h"
@ -2082,10 +2082,11 @@ ContentChild::RecvAsyncMessage(const nsString& aMsg,
{
nsRefPtr<nsFrameMessageManager> cpm = nsFrameMessageManager::GetChildProcessManager();
if (cpm) {
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForChild(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForChild(aData, helper);
CrossProcessCpowHolder cpows(this, aCpows);
cpm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(cpm.get()), nullptr,
aMsg, false, &cloneData, &cpows, aPrincipal, nullptr);
aMsg, false, &helper, &cpows, aPrincipal, nullptr);
}
return true;
}
@ -2867,4 +2868,3 @@ ContentChild::RecvTestGraphicsDeviceReset(const uint32_t& aResetReason)
} // namespace dom
} // namespace mozilla

View File

@ -153,7 +153,7 @@
#include "SandboxHal.h"
#include "ScreenManagerParent.h"
#include "SourceSurfaceRawData.h"
#include "StructuredCloneUtils.h"
#include "StructuredCloneIPCHelper.h"
#include "TabParent.h"
#include "URIUtils.h"
#include "nsIWebBrowserChrome.h"
@ -4455,12 +4455,12 @@ ContentParent::DoLoadMessageManagerScript(const nsAString& aURL,
bool
ContentParent::DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
ClonedMessageData data;
if (!BuildClonedMessageDataForParent(this, aData, data)) {
if (!BuildClonedMessageDataForParent(this, aHelper, data)) {
return false;
}
InfallibleTArray<CpowEntry> cpows;

View File

@ -202,7 +202,7 @@ public:
bool aRunInGlobalScope) override;
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
mozilla::dom::StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override;
virtual bool CheckPermission(const nsAString& aPermission) override;

View File

@ -0,0 +1,83 @@
/* -*- 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/. */
#include "StructuredCloneIPCHelper.h"
#include "nsIDOMDOMException.h"
#include "nsIMutable.h"
#include "nsIXPConnect.h"
#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 {
bool
StructuredCloneIPCHelper::Copy(const StructuredCloneIPCHelper& aHelper)
{
if (!aHelper.mData) {
return true;
}
uint64_t* data = static_cast<uint64_t*>(malloc(aHelper.mDataLength));
if (!data) {
return false;
}
memcpy(data, aHelper.mData, aHelper.mDataLength);
mData = data;
mDataLength = aHelper.mDataLength;
mDataOwned = eAllocated;
MOZ_ASSERT(BlobImpls().IsEmpty());
BlobImpls().AppendElements(aHelper.BlobImpls());
MOZ_ASSERT(GetImages().IsEmpty());
return true;
}
void
StructuredCloneIPCHelper::Read(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
ErrorResult &aRv)
{
MOZ_ASSERT(mData);
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
MOZ_ASSERT(global);
ReadFromBuffer(global, aCx, mData, mDataLength, aValue, aRv);
}
void
StructuredCloneIPCHelper::Write(JSContext* aCx,
JS::Handle<JS::Value> aValue,
ErrorResult &aRv)
{
MOZ_ASSERT(!mData);
StructuredCloneHelper::Write(aCx, aValue, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
mBuffer->steal(&mData, &mDataLength);
mBuffer = nullptr;
mDataOwned = eJSAllocated;
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,87 @@
/* -*- 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/. */
#ifndef mozilla_dom_StructuredCloneIPCHelper_h
#define mozilla_dom_StructuredCloneIPCHelper_h
#include "mozilla/dom/StructuredCloneHelper.h"
namespace mozilla {
namespace dom {
class StructuredCloneIPCHelper final : public StructuredCloneHelper
{
public:
StructuredCloneIPCHelper()
: StructuredCloneHelper(StructuredCloneHelper::CloningSupported,
StructuredCloneHelper::TransferringNotSupported,
StructuredCloneHelper::DifferentProcess)
, mData(nullptr)
, mDataLength(0)
, mDataOwned(eNone)
{}
~StructuredCloneIPCHelper()
{
if (mDataOwned == eAllocated) {
free(mData);
} else if (mDataOwned == eJSAllocated) {
js_free(mData);
}
}
const nsTArray<nsRefPtr<BlobImpl>>& BlobImpls() const
{
return mBlobImplArray;
}
nsTArray<nsRefPtr<BlobImpl>>& BlobImpls()
{
return mBlobImplArray;
}
bool Copy(const StructuredCloneIPCHelper& aHelper);
void Read(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
ErrorResult &aRv);
void Write(JSContext* aCx,
JS::Handle<JS::Value> aValue,
ErrorResult &aRv);
void UseExternalData(uint64_t* aData, size_t aDataLength)
{
MOZ_ASSERT(!mData);
mData = aData;
mDataLength = aDataLength;
MOZ_ASSERT(mDataOwned == eNone);
}
uint64_t* Data() const
{
return mData;
}
size_t DataLength() const
{
return mDataLength;
}
private:
uint64_t* mData;
size_t mDataLength;
enum {
eNone,
eAllocated,
eJSAllocated
} mDataOwned;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_StructuredCloneIPCHelper_h

View File

@ -1,140 +0,0 @@
/* -*- 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/. */
#include "StructuredCloneUtils.h"
#include "nsIDOMDOMException.h"
#include "nsIMutable.h"
#include "nsIXPConnect.h"
#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"
using namespace mozilla::dom;
namespace {
void
Error(JSContext* aCx, uint32_t aErrorId)
{
if (NS_IsMainThread()) {
NS_DOMStructuredCloneError(aCx, aErrorId);
} else {
Throw(aCx, NS_ERROR_DOM_DATA_CLONE_ERR);
}
}
JSObject*
Read(JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag,
uint32_t aData, void* aClosure)
{
MOZ_ASSERT(aClosure);
StructuredCloneClosure* closure =
static_cast<StructuredCloneClosure*>(aClosure);
if (aTag == SCTAG_DOM_BLOB) {
// nsRefPtr<File> needs to go out of scope before toObjectOrNull() is
// called because the static analysis thinks dereferencing XPCOM objects
// can GC (because in some cases it can!), and a return statement with a
// JSObject* type means that JSObject* is on the stack as a raw pointer
// while destructors are running.
JS::Rooted<JS::Value> val(aCx);
{
MOZ_ASSERT(aData < closure->mBlobImpls.Length());
nsRefPtr<BlobImpl> blobImpl = closure->mBlobImpls[aData];
#ifdef DEBUG
{
// Blob should not be mutable.
bool isMutable;
MOZ_ASSERT(NS_SUCCEEDED(blobImpl->GetMutable(&isMutable)));
MOZ_ASSERT(!isMutable);
}
#endif
// Let's create a new blob with the correct parent.
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
MOZ_ASSERT(global);
nsRefPtr<Blob> newBlob = Blob::Create(global, blobImpl);
if (!ToJSValue(aCx, newBlob, &val)) {
return nullptr;
}
}
return &val.toObject();
}
return NS_DOMReadStructuredClone(aCx, aReader, aTag, aData, nullptr);
}
bool
Write(JSContext* aCx, JSStructuredCloneWriter* aWriter,
JS::Handle<JSObject*> aObj, void* aClosure)
{
MOZ_ASSERT(aClosure);
StructuredCloneClosure* closure =
static_cast<StructuredCloneClosure*>(aClosure);
// See if the wrapped native is a File/Blob.
{
Blob* blob = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) &&
NS_SUCCEEDED(blob->SetMutable(false)) &&
JS_WriteUint32Pair(aWriter, SCTAG_DOM_BLOB,
closure->mBlobImpls.Length())) {
closure->mBlobImpls.AppendElement(blob->Impl());
return true;
}
}
return NS_DOMWriteStructuredClone(aCx, aWriter, aObj, nullptr);
}
const JSStructuredCloneCallbacks gCallbacks = {
Read,
Write,
Error,
nullptr,
nullptr,
nullptr
};
} // namespace
namespace mozilla {
namespace dom {
bool
ReadStructuredClone(JSContext* aCx, uint64_t* aData, size_t aDataLength,
const StructuredCloneClosure& aClosure,
JS::MutableHandle<JS::Value> aClone)
{
void* closure = &const_cast<StructuredCloneClosure&>(aClosure);
return !!JS_ReadStructuredClone(aCx, aData, aDataLength,
JS_STRUCTURED_CLONE_VERSION, aClone,
&gCallbacks, closure);
}
bool
WriteStructuredClone(JSContext* aCx, JS::Handle<JS::Value> aSource,
JSAutoStructuredCloneBuffer& aBuffer,
StructuredCloneClosure& aClosure)
{
return aBuffer.write(aCx, aSource, &gCallbacks, &aClosure);
}
} // namespace dom
} // namespace mozilla

View File

@ -1,55 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_dom_StructuredCloneUtils_h
#define mozilla_dom_StructuredCloneUtils_h
#include "nsCOMPtr.h"
#include "nsTArray.h"
#include "mozilla/dom/File.h"
#include "js/StructuredClone.h"
namespace mozilla {
namespace dom {
struct
StructuredCloneClosure
{
nsTArray<nsRefPtr<BlobImpl>> mBlobImpls;
};
struct
StructuredCloneData
{
StructuredCloneData() : mData(nullptr), mDataLength(0) {}
uint64_t* mData;
size_t mDataLength;
StructuredCloneClosure mClosure;
};
bool
ReadStructuredClone(JSContext* aCx, uint64_t* aData, size_t aDataLength,
const StructuredCloneClosure& aClosure,
JS::MutableHandle<JS::Value> aClone);
inline bool
ReadStructuredClone(JSContext* aCx, const StructuredCloneData& aData,
JS::MutableHandle<JS::Value> aClone)
{
return ReadStructuredClone(aCx, aData.mData, aData.mDataLength,
aData.mClosure, aClone);
}
bool
WriteStructuredClone(JSContext* aCx, JS::Handle<JS::Value> aSource,
JSAutoStructuredCloneBuffer& aBuffer,
StructuredCloneClosure& aClosure);
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_StructuredCloneUtils_h

View File

@ -83,7 +83,7 @@
#include "nsWindowWatcher.h"
#include "PermissionMessageUtils.h"
#include "PuppetWidget.h"
#include "StructuredCloneUtils.h"
#include "StructuredCloneIPCHelper.h"
#include "nsViewportInfo.h"
#include "nsILoadContext.h"
#include "ipc/nsGUIEventIPC.h"
@ -237,15 +237,16 @@ TabChildBase::DispatchMessageManagerMessage(const nsAString& aMessageName,
{
AutoSafeJSContext cx;
JS::Rooted<JS::Value> json(cx, JS::NullValue());
StructuredCloneData cloneData;
JSAutoStructuredCloneBuffer buffer;
StructuredCloneIPCHelper helper;
if (JS_ParseJSON(cx,
static_cast<const char16_t*>(aJSONData.BeginReading()),
aJSONData.Length(),
&json)) {
WriteStructuredClone(cx, json, buffer, cloneData.mClosure);
cloneData.mData = buffer.data();
cloneData.mDataLength = buffer.nbytes();
ErrorResult rv;
helper.Write(cx, json, rv);
if (NS_WARN_IF(rv.Failed())) {
return;
}
}
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal());
@ -254,7 +255,7 @@ TabChildBase::DispatchMessageManagerMessage(const nsAString& aMessageName,
nsRefPtr<nsFrameMessageManager> mm =
static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get());
mm->ReceiveMessage(static_cast<EventTarget*>(mTabChildGlobal), nullptr,
aMessageName, false, &cloneData, nullptr, nullptr, nullptr);
aMessageName, false, &helper, nullptr, nullptr, nullptr);
}
bool
@ -2452,12 +2453,13 @@ TabChild::RecvAsyncMessage(const nsString& aMessage,
{
if (mTabChildGlobal) {
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal());
StructuredCloneData cloneData = UnpackClonedMessageDataForChild(aData);
StructuredCloneIPCHelper helper;
UnpackClonedMessageDataForChild(aData, helper);
nsRefPtr<nsFrameMessageManager> mm =
static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get());
CrossProcessCpowHolder cpows(Manager(), aCpows);
mm->ReceiveMessage(static_cast<EventTarget*>(mTabChildGlobal), nullptr,
aMessage, false, &cloneData, &cpows, aPrincipal, nullptr);
aMessage, false, &helper, &cpows, aPrincipal, nullptr);
}
return true;
}
@ -2887,14 +2889,14 @@ TabChild::SetTabId(const TabId& aTabId)
bool
TabChild::DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
bool aIsSync)
{
ClonedMessageData data;
if (!BuildClonedMessageDataForChild(Manager(), aData, data)) {
if (!BuildClonedMessageDataForChild(Manager(), aHelper, data)) {
return false;
}
InfallibleTArray<CpowEntry> cpows;
@ -2913,12 +2915,12 @@ TabChild::DoSendBlockingMessage(JSContext* aCx,
bool
TabChild::DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const StructuredCloneData& aData,
StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal)
{
ClonedMessageData data;
if (!BuildClonedMessageDataForChild(Manager(), aData, data)) {
if (!BuildClonedMessageDataForChild(Manager(), aHelper, data)) {
return false;
}
InfallibleTArray<CpowEntry> cpows;

View File

@ -277,14 +277,14 @@ public:
*/
virtual bool DoSendBlockingMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
mozilla::dom::StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal,
bool aIsSync) override;
virtual bool DoSendAsyncMessage(JSContext* aCx,
const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData,
mozilla::dom::StructuredCloneIPCHelper& aHelper,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) override;
virtual bool DoUpdateZoomConstraints(const uint32_t& aPresShellId,

View File

@ -79,7 +79,7 @@
#include "nsWindowWatcher.h"
#include "private/pprio.h"
#include "PermissionMessageUtils.h"
#include "StructuredCloneUtils.h"
#include "StructuredCloneIPCHelper.h"
#include "ColorPickerParent.h"
#include "FilePickerParent.h"
#include "TabChild.h"
@ -1847,9 +1847,11 @@ TabParent::RecvSyncMessage(const nsString& aMessage,
}
}
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForParent(aData, helper);
CrossProcessCpowHolder cpows(Manager(), aCpows);
return ReceiveMessage(aMessage, true, &cloneData, &cpows, aPrincipal, aRetVal);
return ReceiveMessage(aMessage, true, &helper, &cpows, aPrincipal, aRetVal);
}
bool
@ -1869,9 +1871,11 @@ TabParent::RecvRpcMessage(const nsString& aMessage,
}
}
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForParent(aData, helper);
CrossProcessCpowHolder cpows(Manager(), aCpows);
return ReceiveMessage(aMessage, true, &cloneData, &cpows, aPrincipal, aRetVal);
return ReceiveMessage(aMessage, true, &helper, &cpows, aPrincipal, aRetVal);
}
bool
@ -1890,9 +1894,11 @@ TabParent::RecvAsyncMessage(const nsString& aMessage,
}
}
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForParent(aData, helper);
CrossProcessCpowHolder cpows(Manager(), aCpows);
return ReceiveMessage(aMessage, false, &cloneData, &cpows, aPrincipal, nullptr);
return ReceiveMessage(aMessage, false, &helper, &cpows, aPrincipal, nullptr);
}
bool
@ -2626,7 +2632,7 @@ TabParent::RecvDispatchFocusToTopLevelWindow()
bool
TabParent::ReceiveMessage(const nsString& aMessage,
bool aSync,
const StructuredCloneData* aCloneData,
StructuredCloneIPCHelper* aHelper,
CpowHolder* aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aRetVal)
@ -2640,7 +2646,7 @@ TabParent::ReceiveMessage(const nsString& aMessage,
frameLoader,
aMessage,
aSync,
aCloneData,
aHelper,
aCpows,
aPrincipal,
aRetVal);

View File

@ -67,7 +67,7 @@ class ClonedMessageData;
class nsIContentParent;
class Element;
class DataTransfer;
struct StructuredCloneData;
class StructuredCloneIPCHelper;
class TabParent final : public PBrowserParent
, public nsIDOMEventListener
@ -443,7 +443,7 @@ public:
protected:
bool ReceiveMessage(const nsString& aMessage,
bool aSync,
const StructuredCloneData* aCloneData,
StructuredCloneIPCHelper* aHelper,
mozilla::jsipc::CpowHolder* aCpows,
nsIPrincipal* aPrincipal,
nsTArray<OwningSerializedStructuredCloneBuffer>* aJSONRetVal = nullptr);

View File

@ -37,7 +37,7 @@ EXPORTS.mozilla.dom += [
'NuwaChild.h',
'NuwaParent.h',
'PermissionMessageUtils.h',
'StructuredCloneUtils.h',
'StructuredCloneIPCHelper.h',
'TabChild.h',
'TabContext.h',
'TabMessageUtils.h',
@ -70,7 +70,7 @@ UNIFIED_SOURCES += [
'PreallocatedProcessManager.cpp',
'ProcessPriorityManager.cpp',
'ScreenManagerParent.cpp',
'StructuredCloneUtils.cpp',
'StructuredCloneIPCHelper.cpp',
'TabChild.cpp',
'TabContext.cpp',
'TabMessageUtils.cpp',

View File

@ -10,7 +10,7 @@
#include "mozilla/dom/DOMTypes.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/StructuredCloneIPCHelper.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/ipc/InputStreamUtils.h"
@ -117,10 +117,12 @@ nsIContentChild::RecvAsyncMessage(const nsString& aMsg,
{
nsRefPtr<nsFrameMessageManager> cpm = nsFrameMessageManager::GetChildProcessManager();
if (cpm) {
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForChild(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForChild(aData, helper);
CrossProcessCpowHolder cpows(this, aCpows);
cpm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(cpm.get()), nullptr,
aMsg, false, &cloneData, &cpows, aPrincipal, nullptr);
aMsg, false, &helper, &cpows, aPrincipal, nullptr);
}
return true;
}

View File

@ -13,7 +13,7 @@
#include "mozilla/dom/ContentBridgeParent.h"
#include "mozilla/dom/PTabContext.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/StructuredCloneUtils.h"
#include "mozilla/dom/StructuredCloneIPCHelper.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
@ -201,10 +201,12 @@ nsIContentParent::RecvSyncMessage(const nsString& aMsg,
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
if (ppm) {
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForParent(aData, helper);
CrossProcessCpowHolder cpows(this, aCpows);
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), nullptr,
aMsg, true, &cloneData, &cpows, aPrincipal, aRetvals);
aMsg, true, &helper, &cpows, aPrincipal, aRetvals);
}
return true;
}
@ -228,10 +230,12 @@ nsIContentParent::RecvRpcMessage(const nsString& aMsg,
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
if (ppm) {
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForParent(aData, helper);
CrossProcessCpowHolder cpows(this, aCpows);
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), nullptr,
aMsg, true, &cloneData, &cpows, aPrincipal, aRetvals);
aMsg, true, &helper, &cpows, aPrincipal, aRetvals);
}
return true;
}
@ -254,10 +258,12 @@ nsIContentParent::RecvAsyncMessage(const nsString& aMsg,
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
if (ppm) {
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
StructuredCloneIPCHelper helper;
ipc::UnpackClonedMessageDataForParent(aData, helper);
CrossProcessCpowHolder cpows(this, aCpows);
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), nullptr,
aMsg, false, &cloneData, &cpows, aPrincipal, nullptr);
aMsg, false, &helper, &cpows, aPrincipal, nullptr);
}
return true;
}

View File

@ -46,7 +46,7 @@ SharedMessagePortMessage::Write(JSContext* aCx,
JS::Handle<JS::Value> aTransfer,
ErrorResult& aRv)
{
StructuredCloneHelper::Write(aCx, aValue, aTransfer, true, aRv);
StructuredCloneHelper::Write(aCx, aValue, aTransfer, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

View File

@ -23,7 +23,8 @@ public:
nsTArray<uint8_t> mData;
SharedMessagePortMessage()
: StructuredCloneHelper(CloningSupported, TransferringSupported)
: StructuredCloneHelper(CloningSupported, TransferringSupported,
DifferentProcess)
{}
void Read(nsISupports* aParent,

View File

@ -21,6 +21,7 @@
#include "mozilla/dom/ScriptSettings.h"
#include "jsfriendapi.h"
#include "js/StructuredClone.h"
#include "nsContentUtils.h"
#include "nsGlobalWindow.h"
#include "nsIScriptObjectPrincipal.h"

View File

@ -20,6 +20,7 @@
#include "nsIPrincipal.h"
#include "nsIPushClient.h"
#include "nsComponentManagerUtils.h"
#include "nsFrameMessageManager.h"
#include "nsContentCID.h"

View File

@ -224,7 +224,8 @@ public:
const nsAString& aRevisionId,
ErrorResult& aRv)
: DataStoreProxyRunnable(aWorkerPrivate, aBackingStore, aWorkerPromise)
, StructuredCloneHelper(CloningNotSupported, TransferringNotSupported)
, StructuredCloneHelper(CloningNotSupported, TransferringNotSupported,
SameProcessDifferentThread)
, mId(aId)
, mRevisionId(aRevisionId)
, mRv(aRv)
@ -233,7 +234,7 @@ public:
aWorkerPrivate->AssertIsOnWorkerThread();
// This needs to be structured cloned while it's still on the worker thread.
Write(aCx, aObj, true, mRv);
Write(aCx, aObj, mRv);
NS_WARN_IF(mRv.Failed());
}
@ -285,7 +286,8 @@ public:
const nsAString& aRevisionId,
ErrorResult& aRv)
: DataStoreProxyRunnable(aWorkerPrivate, aBackingStore, aWorkerPromise)
, StructuredCloneHelper(CloningNotSupported, TransferringNotSupported)
, StructuredCloneHelper(CloningNotSupported, TransferringNotSupported,
SameProcessDifferentThread)
, mId(aId)
, mRevisionId(aRevisionId)
, mRv(aRv)
@ -294,7 +296,7 @@ public:
aWorkerPrivate->AssertIsOnWorkerThread();
// This needs to be structured cloned while it's still on the worker thread.
Write(aCx, aObj, true, mRv);
Write(aCx, aObj, mRv);
NS_WARN_IF(mRv.Failed());
}

View File

@ -80,7 +80,8 @@ class ServiceWorkerClientPostMessageRunnable final
public:
explicit ServiceWorkerClientPostMessageRunnable(uint64_t aWindowId)
: StructuredCloneHelper(CloningSupported, TransferringSupported)
: StructuredCloneHelper(CloningSupported, TransferringSupported,
SameProcessDifferentThread)
, mWindowId(aWindowId)
{}
@ -189,7 +190,7 @@ ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
nsRefPtr<ServiceWorkerClientPostMessageRunnable> runnable =
new ServiceWorkerClientPostMessageRunnable(mWindowId);
runnable->Write(aCx, aMessage, transferable, true, aRv);
runnable->Write(aCx, aMessage, transferable, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

View File

@ -35,6 +35,7 @@
#include "mozilla/dom/DOMError.h"
#include "mozilla/dom/ErrorEvent.h"
#include "mozilla/dom/Headers.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/indexedDB/IDBFactory.h"
#include "mozilla/dom/InternalHeaders.h"
#include "mozilla/dom/Navigator.h"

View File

@ -605,7 +605,8 @@ public:
TargetAndBusyBehavior aBehavior,
bool aToMessagePort, uint64_t aMessagePortSerial)
: WorkerRunnable(aWorkerPrivate, aBehavior)
, StructuredCloneHelper(CloningSupported, TransferringSupported)
, StructuredCloneHelper(CloningSupported, TransferringSupported,
SameProcessDifferentThread)
, mMessagePortSerial(aMessagePortSerial)
, mToMessagePort(aToMessagePort)
{
@ -2799,7 +2800,7 @@ WorkerPrivateParent<Derived>::PostMessageInternal(
WorkerRunnable::WorkerThreadModifyBusyCount,
aToMessagePort, aMessagePortSerial);
runnable->Write(aCx, aMessage, transferable, true, aRv);
runnable->Write(aCx, aMessage, transferable, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
@ -5556,7 +5557,7 @@ WorkerPrivate::PostMessageToParentInternal(
WorkerRunnable::ParentThreadUnchangedBusyCount,
aToMessagePort, aMessagePortSerial);
runnable->Write(aCx, aMessage, transferable, true, aRv);
runnable->Write(aCx, aMessage, transferable, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

View File

@ -261,7 +261,8 @@ public:
SendRunnable(WorkerPrivate* aWorkerPrivate, Proxy* aProxy,
const nsAString& aStringBody)
: WorkerThreadProxySyncRunnable(aWorkerPrivate, aProxy)
, StructuredCloneHelper(CloningSupported, TransferringNotSupported)
, StructuredCloneHelper(CloningSupported, TransferringNotSupported,
SameProcessDifferentThread)
, mStringBody(aStringBody)
, mHasUploadListeners(false)
{
@ -566,7 +567,8 @@ public:
EventRunnable(Proxy* aProxy, bool aUploadEvent, const nsString& aType,
bool aLengthComputable, uint64_t aLoaded, uint64_t aTotal)
: MainThreadProxyRunnable(aProxy->mWorkerPrivate, aProxy),
StructuredCloneHelper(CloningSupported, TransferringNotSupported),
StructuredCloneHelper(CloningSupported, TransferringNotSupported,
SameProcessDifferentThread),
mType(aType), mResponse(JS::UndefinedValue()), mLoaded(aLoaded),
mTotal(aTotal), mEventStreamId(aProxy->mInnerEventStreamId), mStatus(0),
mReadyState(0), mUploadEvent(aUploadEvent), mProgressEvent(true),
@ -576,7 +578,8 @@ public:
EventRunnable(Proxy* aProxy, bool aUploadEvent, const nsString& aType)
: MainThreadProxyRunnable(aProxy->mWorkerPrivate, aProxy),
StructuredCloneHelper(CloningSupported, TransferringNotSupported),
StructuredCloneHelper(CloningSupported, TransferringNotSupported,
SameProcessDifferentThread),
mType(aType), mResponse(JS::UndefinedValue()), mLoaded(0), mTotal(0),
mEventStreamId(aProxy->mInnerEventStreamId), mStatus(0), mReadyState(0),
mUploadEvent(aUploadEvent), mProgressEvent(false), mLengthComputable(0),
@ -1232,7 +1235,7 @@ EventRunnable::PreDispatch(JSContext* aCx, WorkerPrivate* aWorkerPrivate)
if (doClone) {
ErrorResult rv;
Write(aCx, response, transferable, false, rv);
Write(aCx, response, transferable, rv);
if (NS_WARN_IF(rv.Failed())) {
NS_WARNING("Failed to clone response!");
mResponseResult = rv.StealNSResult();
@ -2152,7 +2155,7 @@ XMLHttpRequest::Send(JS::Handle<JSObject*> aBody, ErrorResult& aRv)
nsRefPtr<SendRunnable> sendRunnable =
new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
sendRunnable->Write(cx, valToClone, false, aRv);
sendRunnable->Write(cx, valToClone, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
@ -2193,7 +2196,7 @@ XMLHttpRequest::Send(Blob& aBody, ErrorResult& aRv)
nsRefPtr<SendRunnable> sendRunnable =
new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
sendRunnable->Write(cx, value, false, aRv);
sendRunnable->Write(cx, value, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
@ -2226,7 +2229,7 @@ XMLHttpRequest::Send(nsFormData& aBody, ErrorResult& aRv)
nsRefPtr<SendRunnable> sendRunnable =
new SendRunnable(mWorkerPrivate, mProxy, EmptyString());
sendRunnable->Write(cx, value, false, aRv);
sendRunnable->Write(cx, value, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}

View File

@ -14,6 +14,7 @@
#include "nsISupportsPrimitives.h"
#include "nsComponentManagerUtils.h"
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsStringStream.h"
#include "nsXULAppAPI.h"