2019-01-28 22:02:02 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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 "mozilla/dom/JSWindowActorBinding.h"
|
|
|
|
#include "mozilla/dom/JSWindowActorParent.h"
|
2020-05-27 03:28:59 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2020-03-20 12:11:32 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2020-10-28 15:31:35 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalChild.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
2019-02-08 16:02:08 +03:00
|
|
|
#include "mozilla/dom/MessageManagerBinding.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2019-01-28 22:02:02 +03:00
|
|
|
|
2019-05-10 18:01:33 +03:00
|
|
|
JSWindowActorParent::~JSWindowActorParent() { MOZ_ASSERT(!mManager); }
|
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
JSObject* JSWindowActorParent::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return JSWindowActorParent_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
2019-06-06 13:13:30 +03:00
|
|
|
WindowGlobalParent* JSWindowActorParent::GetManager() const { return mManager; }
|
2019-01-28 22:02:02 +03:00
|
|
|
|
2021-09-03 18:26:13 +03:00
|
|
|
WindowContext* JSWindowActorParent::GetWindowContext() const {
|
|
|
|
return mManager;
|
|
|
|
}
|
|
|
|
|
2020-04-17 13:56:22 +03:00
|
|
|
void JSWindowActorParent::Init(const nsACString& aName,
|
2019-02-21 22:53:59 +03:00
|
|
|
WindowGlobalParent* aManager) {
|
2019-01-28 22:02:02 +03:00
|
|
|
MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorParent twice!");
|
2019-04-18 22:37:15 +03:00
|
|
|
SetName(aName);
|
2019-01-28 22:02:02 +03:00
|
|
|
mManager = aManager;
|
2020-05-12 10:55:39 +03:00
|
|
|
|
|
|
|
InvokeCallback(CallbackFunction::ActorCreated);
|
2019-01-28 22:02:02 +03:00
|
|
|
}
|
|
|
|
|
2020-10-13 20:43:56 +03:00
|
|
|
void JSWindowActorParent::SendRawMessage(
|
|
|
|
const JSActorMessageMeta& aMeta, Maybe<ipc::StructuredCloneData>&& aData,
|
|
|
|
Maybe<ipc::StructuredCloneData>&& aStack, ErrorResult& aRv) {
|
2020-07-08 17:22:22 +03:00
|
|
|
if (NS_WARN_IF(!CanSend() || !mManager || !mManager->CanSend())) {
|
2020-10-13 20:43:56 +03:00
|
|
|
aRv.ThrowInvalidStateError("JSWindowActorParent cannot send at the moment");
|
2019-02-08 16:02:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mManager->IsInProcess()) {
|
2020-07-08 17:22:22 +03:00
|
|
|
SendRawMessageInProcess(
|
|
|
|
aMeta, std::move(aData), std::move(aStack),
|
|
|
|
[manager{mManager}]() { return manager->GetChildActor(); });
|
2019-02-08 16:02:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-13 20:43:56 +03:00
|
|
|
size_t length = 0;
|
|
|
|
if (aData) {
|
|
|
|
length += aData->DataLength();
|
|
|
|
}
|
|
|
|
if (aStack) {
|
|
|
|
length += aStack->DataLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!AllowMessage(aMeta, length))) {
|
|
|
|
aRv.ThrowDataCloneError(
|
|
|
|
nsPrintfCString("JSWindowActorParent serialization error: data too "
|
|
|
|
"large, in actor '%s'",
|
|
|
|
PromiseFlatCString(aMeta.actorName()).get()));
|
2019-12-20 00:17:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-18 22:37:15 +03:00
|
|
|
// Cross-process case - send data over WindowGlobalParent to other side.
|
2019-05-08 22:34:47 +03:00
|
|
|
RefPtr<BrowserParent> browserParent = mManager->GetBrowserParent();
|
2019-04-10 00:38:15 +03:00
|
|
|
ContentParent* cp = browserParent->Manager();
|
2020-10-13 20:43:56 +03:00
|
|
|
|
|
|
|
Maybe<ClonedMessageData> msgData;
|
|
|
|
if (aData) {
|
|
|
|
msgData.emplace();
|
|
|
|
if (NS_WARN_IF(!aData->BuildClonedMessageDataForParent(cp, *msgData))) {
|
|
|
|
aRv.ThrowDataCloneError(
|
|
|
|
nsPrintfCString("JSWindowActorParent serialization error: cannot "
|
|
|
|
"clone, in actor '%s'",
|
|
|
|
PromiseFlatCString(aMeta.actorName()).get()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Maybe<ClonedMessageData> stackData;
|
|
|
|
if (aStack) {
|
|
|
|
stackData.emplace();
|
|
|
|
if (!aStack->BuildClonedMessageDataForParent(cp, *stackData)) {
|
|
|
|
stackData.reset();
|
|
|
|
}
|
2019-02-08 16:02:08 +03:00
|
|
|
}
|
|
|
|
|
2019-12-07 21:59:23 +03:00
|
|
|
if (NS_WARN_IF(!mManager->SendRawMessage(aMeta, msgData, stackData))) {
|
2020-10-13 20:43:56 +03:00
|
|
|
aRv.ThrowOperationError(
|
|
|
|
nsPrintfCString("JSWindowActorParent send error in actor '%s'",
|
|
|
|
PromiseFlatCString(aMeta.actorName()).get()));
|
2019-02-08 16:02:08 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 19:59:56 +03:00
|
|
|
CanonicalBrowsingContext* JSWindowActorParent::GetBrowsingContext(
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
if (!mManager) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mManager->BrowsingContext();
|
|
|
|
}
|
|
|
|
|
2020-07-08 17:22:22 +03:00
|
|
|
void JSWindowActorParent::ClearManager() { mManager = nullptr; }
|
2019-05-10 18:01:33 +03:00
|
|
|
|
2020-04-30 19:42:53 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(JSWindowActorParent, JSActor, mManager)
|
2019-03-05 20:12:40 +03:00
|
|
|
|
2020-04-30 19:42:53 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(JSWindowActorParent, JSActor)
|
2019-04-18 22:37:15 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSWindowActorParent)
|
2020-04-30 19:42:53 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(JSActor)
|
2019-01-28 22:02:02 +03:00
|
|
|
|
2020-04-30 19:42:53 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(JSWindowActorParent, JSActor)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(JSWindowActorParent, JSActor)
|
2019-01-28 22:02:02 +03:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|