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
|
|
|
#ifndef mozilla_dom_ipc_StructuredCloneData_h
|
|
|
|
#define mozilla_dom_ipc_StructuredCloneData_h
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2015-09-30 15:22:08 +03:00
|
|
|
#include "mozilla/dom/StructuredCloneHolder.h"
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2015-09-09 10:10:32 +03:00
|
|
|
namespace IPC {
|
|
|
|
class Message;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-09-30 15:22:08 +03:00
|
|
|
class StructuredCloneData : public StructuredCloneHolder
|
2015-09-02 19:20:30 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData()
|
2015-09-30 15:22:08 +03:00
|
|
|
: StructuredCloneHolder(StructuredCloneHolder::CloningSupported,
|
|
|
|
StructuredCloneHolder::TransferringNotSupported,
|
|
|
|
StructuredCloneHolder::DifferentProcess)
|
2015-09-02 19:20:30 +03:00
|
|
|
, mData(nullptr)
|
|
|
|
, mDataLength(0)
|
|
|
|
, mDataOwned(eNone)
|
|
|
|
{}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData(const StructuredCloneData&) = delete;
|
2015-09-09 10:10:32 +03:00
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
~StructuredCloneData()
|
2015-09-02 19:20:30 +03:00
|
|
|
{
|
2015-09-09 10:11:38 +03:00
|
|
|
if (mDataOwned == eJSAllocated) {
|
2015-09-02 19:20:30 +03:00
|
|
|
js_free(mData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData&
|
|
|
|
operator=(const StructuredCloneData& aOther) = delete;
|
2015-09-09 10:10:32 +03:00
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
const nsTArray<nsRefPtr<BlobImpl>>& BlobImpls() const
|
|
|
|
{
|
|
|
|
return mBlobImplArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<BlobImpl>>& BlobImpls()
|
|
|
|
{
|
|
|
|
return mBlobImplArray;
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
bool Copy(const StructuredCloneData& aData);
|
2015-09-02 19:20:30 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-09-09 10:11:38 +03:00
|
|
|
bool CopyExternalData(const void* aData, size_t aDataLength);
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
uint64_t* Data() const
|
|
|
|
{
|
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t DataLength() const
|
|
|
|
{
|
|
|
|
return mDataLength;
|
|
|
|
}
|
|
|
|
|
2015-09-09 10:10:32 +03:00
|
|
|
// For IPC serialization
|
|
|
|
void WriteIPCParams(IPC::Message* aMessage) const;
|
|
|
|
bool ReadIPCParams(const IPC::Message* aMessage, void** aIter);
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
private:
|
|
|
|
uint64_t* mData;
|
|
|
|
size_t mDataLength;
|
|
|
|
enum {
|
|
|
|
eNone,
|
2015-09-09 10:11:38 +03:00
|
|
|
eJSAllocated,
|
2015-09-02 19:20:30 +03:00
|
|
|
} mDataOwned;
|
|
|
|
};
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
} // namespace ipc
|
2015-09-02 19:20:30 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
#endif // mozilla_dom_ipc_StructuredCloneData_h
|