1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/JSWindowActorBinding.h"
8 #include "mozilla/dom/JSWindowActorParent.h"
9 #include "mozilla/dom/BrowserParent.h"
10 #include "mozilla/dom/ContentParent.h"
11 #include "mozilla/dom/WindowGlobalChild.h"
12 #include "mozilla/dom/WindowGlobalParent.h"
13 #include "mozilla/dom/MessageManagerBinding.h"
15 namespace mozilla::dom
{
17 JSWindowActorParent::~JSWindowActorParent() { MOZ_ASSERT(!mManager
); }
19 JSObject
* JSWindowActorParent::WrapObject(JSContext
* aCx
,
20 JS::Handle
<JSObject
*> aGivenProto
) {
21 return JSWindowActorParent_Binding::Wrap(aCx
, this, aGivenProto
);
24 WindowGlobalParent
* JSWindowActorParent::GetManager() const { return mManager
; }
26 WindowContext
* JSWindowActorParent::GetWindowContext() const {
30 void JSWindowActorParent::Init(const nsACString
& aName
,
31 WindowGlobalParent
* aManager
) {
32 MOZ_ASSERT(!mManager
, "Cannot Init() a JSWindowActorParent twice!");
36 InvokeCallback(CallbackFunction::ActorCreated
);
39 void JSWindowActorParent::SendRawMessage(
40 const JSActorMessageMeta
& aMeta
, Maybe
<ipc::StructuredCloneData
>&& aData
,
41 Maybe
<ipc::StructuredCloneData
>&& aStack
, ErrorResult
& aRv
) {
42 if (NS_WARN_IF(!CanSend() || !mManager
|| !mManager
->CanSend())) {
43 aRv
.ThrowInvalidStateError("JSWindowActorParent cannot send at the moment");
47 if (mManager
->IsInProcess()) {
48 SendRawMessageInProcess(
49 aMeta
, std::move(aData
), std::move(aStack
),
50 [manager
{mManager
}]() { return manager
->GetChildActor(); });
54 Maybe
<ClonedMessageData
> msgData
;
57 if (NS_WARN_IF(!aData
->BuildClonedMessageData(*msgData
))) {
58 aRv
.ThrowDataCloneError(
59 nsPrintfCString("JSWindowActorParent serialization error: cannot "
60 "clone, in actor '%s'",
61 PromiseFlatCString(aMeta
.actorName()).get()));
66 Maybe
<ClonedMessageData
> stackData
;
69 if (!aStack
->BuildClonedMessageData(*stackData
)) {
74 if (NS_WARN_IF(!mManager
->SendRawMessage(aMeta
, msgData
, stackData
))) {
75 aRv
.ThrowOperationError(
76 nsPrintfCString("JSWindowActorParent send error in actor '%s'",
77 PromiseFlatCString(aMeta
.actorName()).get()));
82 CanonicalBrowsingContext
* JSWindowActorParent::GetBrowsingContext(
85 aRv
.Throw(NS_ERROR_DOM_INVALID_STATE_ERR
);
89 return mManager
->BrowsingContext();
92 void JSWindowActorParent::ClearManager() { mManager
= nullptr; }
94 NS_IMPL_CYCLE_COLLECTION_INHERITED(JSWindowActorParent
, JSActor
, mManager
)
96 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSWindowActorParent
)
97 NS_INTERFACE_MAP_END_INHERITING(JSActor
)
99 NS_IMPL_ADDREF_INHERITED(JSWindowActorParent
, JSActor
)
100 NS_IMPL_RELEASE_INHERITED(JSWindowActorParent
, JSActor
)
102 } // namespace mozilla::dom