2017-10-27 01:08:41 +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: */
|
2015-06-17 13:44:27 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2020-01-24 10:59:36 +03:00
|
|
|
#ifndef mozilla_dom_SharedMessageBody_h
|
|
|
|
#define mozilla_dom_SharedMessageBody_h
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2016-11-08 12:50:51 +03:00
|
|
|
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
2020-01-24 19:19:59 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2015-06-17 13:44:27 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2020-01-24 10:59:36 +03:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PBackgroundChild;
|
|
|
|
}
|
|
|
|
|
2015-06-17 13:44:27 +03:00
|
|
|
namespace dom {
|
|
|
|
|
2020-01-24 10:59:36 +03:00
|
|
|
class MessagePort;
|
2020-01-24 10:58:34 +03:00
|
|
|
class RefMessageBody;
|
|
|
|
class RefMessageBodyService;
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 10:59:36 +03:00
|
|
|
class SharedMessageBody final {
|
2015-06-17 13:44:27 +03:00
|
|
|
public:
|
2020-01-24 10:59:36 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(SharedMessageBody)
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 19:19:59 +03:00
|
|
|
SharedMessageBody(
|
|
|
|
StructuredCloneHolder::TransferringSupport aSupportsTransferring,
|
|
|
|
const Maybe<nsID>& aAgentClusterId);
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 10:58:21 +03:00
|
|
|
// Note that the populated MessageData borrows the underlying
|
2020-01-24 10:59:36 +03:00
|
|
|
// JSStructuredCloneData from the SharedMessageBody, so the caller is
|
2020-01-24 10:58:21 +03:00
|
|
|
// required to ensure that the MessageData instances are destroyed prior to
|
2020-01-24 10:59:36 +03:00
|
|
|
// the SharedMessageBody instances.
|
2020-01-24 11:00:08 +03:00
|
|
|
static void FromSharedToMessageChild(
|
|
|
|
mozilla::ipc::PBackgroundChild* aBackgroundManager,
|
|
|
|
SharedMessageBody* aData, MessageData& aMessage);
|
2015-06-17 13:44:27 +03:00
|
|
|
static void FromSharedToMessagesChild(
|
2020-01-24 10:59:36 +03:00
|
|
|
mozilla::ipc::PBackgroundChild* aBackgroundManager,
|
|
|
|
const nsTArray<RefPtr<SharedMessageBody>>& aData,
|
2020-01-24 10:58:21 +03:00
|
|
|
nsTArray<MessageData>& aArray);
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 11:00:08 +03:00
|
|
|
// Const MessageData.
|
|
|
|
static already_AddRefed<SharedMessageBody> FromMessageToSharedChild(
|
|
|
|
MessageData& aMessage,
|
|
|
|
StructuredCloneHolder::TransferringSupport aSupportsTransferring =
|
|
|
|
StructuredCloneHolder::TransferringSupported);
|
|
|
|
// Non-const MessageData.
|
|
|
|
static already_AddRefed<SharedMessageBody> FromMessageToSharedChild(
|
|
|
|
const MessageData& aMessage,
|
|
|
|
StructuredCloneHolder::TransferringSupport aSupportsTransferring =
|
|
|
|
StructuredCloneHolder::TransferringSupported);
|
|
|
|
// Array of MessageData objects
|
2015-06-17 13:44:27 +03:00
|
|
|
static bool FromMessagesToSharedChild(
|
2020-01-24 10:58:21 +03:00
|
|
|
nsTArray<MessageData>& aArray,
|
2020-01-24 11:00:08 +03:00
|
|
|
FallibleTArray<RefPtr<SharedMessageBody>>& aData,
|
|
|
|
StructuredCloneHolder::TransferringSupport aSupportsTransferring =
|
|
|
|
StructuredCloneHolder::TransferringSupported);
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 10:58:21 +03:00
|
|
|
// Note that the populated MessageData borrows the underlying
|
2020-01-24 10:59:36 +03:00
|
|
|
// JSStructuredCloneData from the SharedMessageBody, so the caller is
|
2020-01-24 10:58:21 +03:00
|
|
|
// required to ensure that the MessageData instances are destroyed prior to
|
2020-01-24 10:59:36 +03:00
|
|
|
// the SharedMessageBody instances.
|
2015-06-17 13:44:27 +03:00
|
|
|
static bool FromSharedToMessagesParent(
|
2020-01-24 10:59:36 +03:00
|
|
|
mozilla::ipc::PBackgroundParent* aManager,
|
|
|
|
const nsTArray<RefPtr<SharedMessageBody>>& aData,
|
2020-05-07 11:10:14 +03:00
|
|
|
nsTArray<MessageData>& aArray);
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 11:00:08 +03:00
|
|
|
static already_AddRefed<SharedMessageBody> FromMessageToSharedParent(
|
|
|
|
MessageData& aMessage,
|
|
|
|
StructuredCloneHolder::TransferringSupport aSupportsTransferring =
|
|
|
|
StructuredCloneHolder::TransferringSupported);
|
2015-06-17 13:44:27 +03:00
|
|
|
static bool FromMessagesToSharedParent(
|
2020-01-24 10:58:21 +03:00
|
|
|
nsTArray<MessageData>& aArray,
|
2020-01-24 11:00:08 +03:00
|
|
|
FallibleTArray<RefPtr<SharedMessageBody>>& aData,
|
|
|
|
StructuredCloneHolder::TransferringSupport aSupportsTransferring =
|
|
|
|
StructuredCloneHolder::TransferringSupported);
|
|
|
|
|
|
|
|
enum ReadMethod {
|
|
|
|
StealRefMessageBody,
|
|
|
|
KeepRefMessageBody,
|
|
|
|
};
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 10:58:34 +03:00
|
|
|
void Read(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
|
2020-01-24 11:00:08 +03:00
|
|
|
RefMessageBodyService* aRefMessageBodyService,
|
|
|
|
ReadMethod aReadMethod, ErrorResult& aRv);
|
2020-01-24 10:58:34 +03:00
|
|
|
|
|
|
|
void Write(JSContext* aCx, JS::Handle<JS::Value> aValue,
|
|
|
|
JS::Handle<JS::Value> aTransfers, nsID& aPortID,
|
|
|
|
RefMessageBodyService* aRefMessageBodyService, ErrorResult& aRv);
|
|
|
|
|
|
|
|
bool TakeTransferredPortsAsSequence(
|
|
|
|
Sequence<OwningNonNull<mozilla::dom::MessagePort>>& aPorts);
|
|
|
|
|
2015-06-17 13:44:27 +03:00
|
|
|
private:
|
2020-01-24 10:59:36 +03:00
|
|
|
~SharedMessageBody() = default;
|
2020-01-24 10:58:34 +03:00
|
|
|
|
|
|
|
UniquePtr<ipc::StructuredCloneData> mCloneData;
|
|
|
|
|
|
|
|
RefPtr<RefMessageBody> mRefData;
|
2020-01-24 19:19:59 +03:00
|
|
|
Maybe<nsID> mRefDataId;
|
|
|
|
|
|
|
|
const StructuredCloneHolder::TransferringSupport mSupportsTransferring;
|
|
|
|
const Maybe<nsID> mAgentClusterId;
|
2015-06-17 13:44:27 +03:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2015-06-17 13:44:27 +03:00
|
|
|
|
2020-01-24 10:59:36 +03:00
|
|
|
#endif // mozilla_dom_SharedMessageBody_h
|