2018-08-30 01:21:25 +03:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 ft=cpp : */
|
|
|
|
/* 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/WindowGlobalChild.h"
|
2019-04-03 20:31:00 +03:00
|
|
|
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2019-04-10 01:38:11 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
2019-07-23 05:13:32 +03:00
|
|
|
#include "mozilla/ipc/InProcessChild.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2019-04-18 22:37:15 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2019-04-17 03:53:32 +03:00
|
|
|
#include "mozilla/dom/MozFrameLoaderOwnerBinding.h"
|
2019-04-10 01:39:01 +03:00
|
|
|
#include "mozilla/dom/BrowserChild.h"
|
2019-04-10 01:38:11 +03:00
|
|
|
#include "mozilla/dom/BrowserBridgeChild.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2018-10-20 02:02:56 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalActorsBinding.h"
|
2019-04-03 20:31:00 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
|
|
|
#include "mozilla/ipc/InProcessChild.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-04-03 20:31:00 +03:00
|
|
|
#include "nsDocShell.h"
|
2019-04-10 01:38:11 +03:00
|
|
|
#include "nsFrameLoaderOwner.h"
|
2019-04-03 20:31:00 +03:00
|
|
|
#include "nsGlobalWindowInner.h"
|
2019-04-18 22:37:15 +03:00
|
|
|
#include "nsFrameLoaderOwner.h"
|
|
|
|
#include "nsQueryObject.h"
|
2019-06-21 08:58:40 +03:00
|
|
|
#include "nsSerializationHelper.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
#include "mozilla/dom/JSWindowActorBinding.h"
|
|
|
|
#include "mozilla/dom/JSWindowActorChild.h"
|
|
|
|
#include "mozilla/dom/JSWindowActorService.h"
|
2019-04-09 23:10:13 +03:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
|
2019-04-03 20:31:00 +03:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::dom::ipc;
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
typedef nsRefPtrHashtable<nsUint64HashKey, WindowGlobalChild> WGCByIdMap;
|
|
|
|
static StaticAutoPtr<WGCByIdMap> gWindowGlobalChildById;
|
|
|
|
|
2019-08-08 19:06:54 +03:00
|
|
|
WindowGlobalChild::WindowGlobalChild(const WindowGlobalInit& aInit,
|
|
|
|
nsGlobalWindowInner* aWindow)
|
2018-08-30 01:21:25 +03:00
|
|
|
: mWindowGlobal(aWindow),
|
2019-08-08 19:06:54 +03:00
|
|
|
mBrowsingContext(aInit.browsingContext()),
|
|
|
|
mDocumentPrincipal(aInit.principal()),
|
|
|
|
mDocumentURI(aInit.documentURI()),
|
|
|
|
mInnerWindowId(aInit.innerWindowId()),
|
|
|
|
mOuterWindowId(aInit.outerWindowId()),
|
|
|
|
mBeforeUnloadListeners(0) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mBrowsingContext);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mDocumentPrincipal);
|
|
|
|
|
|
|
|
MOZ_ASSERT(mInnerWindowId == aWindow->WindowID());
|
|
|
|
MOZ_ASSERT(mOuterWindowId == aWindow->GetOuterWindow()->WindowID());
|
|
|
|
}
|
2018-12-10 22:23:16 +03:00
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
already_AddRefed<WindowGlobalChild> WindowGlobalChild::Create(
|
|
|
|
nsGlobalWindowInner* aWindow) {
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = aWindow->GetPrincipal();
|
|
|
|
MOZ_ASSERT(principal);
|
|
|
|
|
|
|
|
RefPtr<nsDocShell> docshell = nsDocShell::Cast(aWindow->GetDocShell());
|
|
|
|
MOZ_ASSERT(docshell);
|
|
|
|
|
|
|
|
// Initalize our WindowGlobalChild object.
|
|
|
|
RefPtr<dom::BrowsingContext> bc = docshell->GetBrowsingContext();
|
2019-04-09 23:10:13 +03:00
|
|
|
|
|
|
|
// When creating a new window global child we also need to look at the
|
|
|
|
// channel's Cross-Origin-Opener-Policy and set it on the browsing context
|
|
|
|
// so it's available in the parent process.
|
|
|
|
nsCOMPtr<nsIHttpChannelInternal> chan =
|
|
|
|
do_QueryInterface(aWindow->GetDocument()->GetChannel());
|
|
|
|
nsILoadInfo::CrossOriginOpenerPolicy policy;
|
|
|
|
if (chan && NS_SUCCEEDED(chan->GetCrossOriginOpenerPolicy(&policy))) {
|
|
|
|
bc->SetOpenerPolicy(policy);
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:06:54 +03:00
|
|
|
WindowGlobalInit init(principal, aWindow->GetDocumentURI(), bc,
|
|
|
|
aWindow->WindowID(),
|
|
|
|
aWindow->GetOuterWindow()->WindowID());
|
|
|
|
|
|
|
|
auto wgc = MakeRefPtr<WindowGlobalChild>(init, aWindow);
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2019-07-08 20:27:27 +03:00
|
|
|
// If we have already closed our browsing context, return a pre-destroyed
|
2019-04-15 17:57:09 +03:00
|
|
|
// WindowGlobalChild actor.
|
2019-07-08 20:27:27 +03:00
|
|
|
if (bc->IsDiscarded()) {
|
2019-04-15 17:57:09 +03:00
|
|
|
wgc->ActorDestroy(FailedConstructor);
|
|
|
|
return wgc.forget();
|
|
|
|
}
|
|
|
|
|
2019-07-23 05:13:32 +03:00
|
|
|
// Send the link constructor over PInProcessChild or PBrowser.
|
2018-08-30 01:21:25 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2019-07-23 05:13:32 +03:00
|
|
|
InProcessChild* ipc = InProcessChild::Singleton();
|
|
|
|
if (!ipc) {
|
2018-08-30 01:21:25 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: ref is released in DeallocPWindowGlobalChild
|
2019-07-23 05:13:32 +03:00
|
|
|
ipc->SendPWindowGlobalConstructor(do_AddRef(wgc).take(), init);
|
2018-08-30 01:21:25 +03:00
|
|
|
} else {
|
2019-04-10 01:39:01 +03:00
|
|
|
RefPtr<BrowserChild> browserChild =
|
|
|
|
BrowserChild::GetFrom(static_cast<mozIDOMWindow*>(aWindow));
|
|
|
|
MOZ_ASSERT(browserChild);
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
// Note: ref is released in DeallocPWindowGlobalChild
|
2019-07-23 05:13:32 +03:00
|
|
|
browserChild->SendPWindowGlobalConstructor(do_AddRef(wgc).take(), init);
|
2019-07-18 22:38:14 +03:00
|
|
|
}
|
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
// Register this WindowGlobal in the gWindowGlobalParentsById map.
|
|
|
|
if (!gWindowGlobalChildById) {
|
|
|
|
gWindowGlobalChildById = new WGCByIdMap();
|
|
|
|
ClearOnShutdown(&gWindowGlobalChildById);
|
|
|
|
}
|
2019-07-23 05:13:32 +03:00
|
|
|
auto entry = gWindowGlobalChildById->LookupForAdd(wgc->mInnerWindowId);
|
2018-10-20 23:04:00 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!entry, "Duplicate WindowGlobalChild entry for ID!");
|
2019-07-23 05:13:32 +03:00
|
|
|
entry.OrInsert([&] { return wgc; });
|
2019-07-16 21:47:56 +03:00
|
|
|
|
2019-07-23 05:13:32 +03:00
|
|
|
return wgc.forget();
|
2019-07-18 22:38:22 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<WindowGlobalChild> WindowGlobalChild::GetByInnerWindowId(
|
|
|
|
uint64_t aInnerWindowId) {
|
2018-10-20 23:04:00 +03:00
|
|
|
if (!gWindowGlobalChildById) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return gWindowGlobalChildById->Get(aInnerWindowId);
|
|
|
|
}
|
|
|
|
|
2018-11-27 23:03:05 +03:00
|
|
|
bool WindowGlobalChild::IsCurrentGlobal() {
|
2019-08-08 19:06:52 +03:00
|
|
|
return CanSend() && mWindowGlobal->IsCurrentInnerWindow();
|
2018-11-27 23:03:05 +03:00
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
already_AddRefed<WindowGlobalParent> WindowGlobalChild::GetParentActor() {
|
2019-08-08 19:06:52 +03:00
|
|
|
if (!CanSend()) {
|
2018-08-30 01:21:25 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
IProtocol* otherSide = InProcessChild::ParentActorFor(this);
|
|
|
|
return do_AddRef(static_cast<WindowGlobalParent*>(otherSide));
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
already_AddRefed<BrowserChild> WindowGlobalChild::GetBrowserChild() {
|
2019-08-08 19:06:52 +03:00
|
|
|
if (IsInProcess() || !CanSend()) {
|
2019-01-28 21:09:13 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
return do_AddRef(static_cast<BrowserChild*>(Manager()));
|
2019-01-28 21:09:13 +03:00
|
|
|
}
|
|
|
|
|
2019-05-27 21:42:35 +03:00
|
|
|
uint64_t WindowGlobalChild::ContentParentId() {
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ContentChild::GetSingleton()->GetID();
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:42:37 +03:00
|
|
|
// A WindowGlobalChild is the root in its process if it has no parent, or its
|
|
|
|
// embedder is in a different process.
|
|
|
|
bool WindowGlobalChild::IsProcessRoot() {
|
|
|
|
if (!BrowsingContext()->GetParent()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !BrowsingContext()->GetEmbedderElement();
|
|
|
|
}
|
|
|
|
|
2019-07-15 20:30:26 +03:00
|
|
|
void WindowGlobalChild::BeforeUnloadAdded() {
|
|
|
|
// Don't bother notifying the parent if we don't have an IPC link open.
|
2019-08-08 19:06:52 +03:00
|
|
|
if (mBeforeUnloadListeners == 0 && CanSend()) {
|
2019-07-15 20:30:26 +03:00
|
|
|
SendSetHasBeforeUnload(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
mBeforeUnloadListeners++;
|
|
|
|
MOZ_ASSERT(mBeforeUnloadListeners > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowGlobalChild::BeforeUnloadRemoved() {
|
|
|
|
mBeforeUnloadListeners--;
|
|
|
|
MOZ_ASSERT(mBeforeUnloadListeners >= 0);
|
|
|
|
|
|
|
|
// Don't bother notifying the parent if we don't have an IPC link open.
|
2019-08-08 19:06:52 +03:00
|
|
|
if (mBeforeUnloadListeners == 0 && CanSend()) {
|
2019-07-15 20:30:26 +03:00
|
|
|
SendSetHasBeforeUnload(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 21:09:13 +03:00
|
|
|
void WindowGlobalChild::Destroy() {
|
2019-04-10 01:39:01 +03:00
|
|
|
// Perform async IPC shutdown unless we're not in-process, and our
|
|
|
|
// BrowserChild is in the process of being destroyed, which will destroy us as
|
|
|
|
// well.
|
|
|
|
RefPtr<BrowserChild> browserChild = GetBrowserChild();
|
|
|
|
if (!browserChild || !browserChild->IsDestroyed()) {
|
2019-05-10 18:01:33 +03:00
|
|
|
// Make a copy so that we can avoid potential iterator invalidation when
|
|
|
|
// calling the user-provided Destroy() methods.
|
|
|
|
nsTArray<RefPtr<JSWindowActorChild>> windowActors(mWindowActors.Count());
|
|
|
|
for (auto iter = mWindowActors.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
windowActors.AppendElement(iter.UserData());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& windowActor : windowActors) {
|
|
|
|
windowActor->StartDestroy();
|
|
|
|
}
|
2019-01-28 21:09:13 +03:00
|
|
|
SendDestroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 03:53:32 +03:00
|
|
|
static nsresult ChangeFrameRemoteness(WindowGlobalChild* aWgc,
|
|
|
|
BrowsingContext* aBc,
|
|
|
|
const nsString& aRemoteType,
|
|
|
|
uint64_t aPendingSwitchId,
|
|
|
|
BrowserBridgeChild** aBridge) {
|
|
|
|
MOZ_ASSERT(XRE_IsContentProcess(), "This doesn't make sense in the parent");
|
|
|
|
|
|
|
|
// Get the target embedder's FrameLoaderOwner, and make sure we're in the
|
|
|
|
// right place.
|
|
|
|
RefPtr<Element> embedderElt = aBc->GetEmbedderElement();
|
|
|
|
if (!embedderElt) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(embedderElt->GetOwnerGlobal() != aWgc->WindowGlobal())) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsFrameLoaderOwner> flo = do_QueryObject(embedderElt);
|
|
|
|
MOZ_ASSERT(flo, "Embedder must be a nsFrameLoaderOwner!");
|
|
|
|
|
|
|
|
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
|
|
|
|
|
|
|
// Actually perform the remoteness swap.
|
|
|
|
RemotenessOptions options;
|
|
|
|
options.mPendingSwitchID.Construct(aPendingSwitchId);
|
|
|
|
|
2019-06-21 19:34:30 +03:00
|
|
|
// Only set mRemoteType if it doesn't match the current process' remote type.
|
|
|
|
if (!ContentChild::GetSingleton()->GetRemoteType().Equals(aRemoteType)) {
|
|
|
|
options.mRemoteType.Construct(aRemoteType);
|
|
|
|
}
|
|
|
|
|
2019-04-17 03:53:32 +03:00
|
|
|
ErrorResult error;
|
|
|
|
flo->ChangeRemoteness(options, error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we successfully created either an in-process nsDocShell or a
|
|
|
|
// cross-process BrowserBridgeChild. If we didn't, produce an error.
|
|
|
|
RefPtr<nsFrameLoader> frameLoader = flo->GetFrameLoader();
|
|
|
|
if (NS_WARN_IF(!frameLoader)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<BrowserBridgeChild> bbc;
|
|
|
|
if (frameLoader->IsRemoteFrame()) {
|
|
|
|
bbc = frameLoader->GetBrowserBridgeChild();
|
|
|
|
if (NS_WARN_IF(!bbc)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsDocShell* ds = frameLoader->GetDocShell(error);
|
|
|
|
if (NS_WARN_IF(error.Failed())) {
|
|
|
|
return error.StealNSResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!ds)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bbc.forget(aBridge);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPCResult WindowGlobalChild::RecvChangeFrameRemoteness(
|
|
|
|
dom::BrowsingContext* aBc, const nsString& aRemoteType,
|
|
|
|
uint64_t aPendingSwitchId, ChangeFrameRemotenessResolver&& aResolver) {
|
|
|
|
MOZ_ASSERT(XRE_IsContentProcess(), "This doesn't make sense in the parent");
|
|
|
|
|
|
|
|
RefPtr<BrowserBridgeChild> bbc;
|
|
|
|
nsresult rv = ChangeFrameRemoteness(this, aBc, aRemoteType, aPendingSwitchId,
|
|
|
|
getter_AddRefs(bbc));
|
|
|
|
|
|
|
|
// To make the type system happy, we've gotta do some gymnastics.
|
|
|
|
aResolver(Tuple<const nsresult&, PBrowserBridgeChild*>(rv, bbc));
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvDrawSnapshot(
|
|
|
|
const Maybe<IntRect>& aRect, const float& aScale,
|
|
|
|
const nscolor& aBackgroundColor, DrawSnapshotResolver&& aResolve) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = BrowsingContext()->GetDocShell();
|
|
|
|
if (!docShell) {
|
|
|
|
aResolve(gfx::PaintFragment{});
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
aResolve(
|
|
|
|
gfx::PaintFragment::Record(docShell, aRect, aScale, aBackgroundColor));
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-06-21 08:58:40 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvGetSecurityInfo(
|
|
|
|
GetSecurityInfoResolver&& aResolve) {
|
|
|
|
Maybe<nsCString> result;
|
|
|
|
|
|
|
|
if (nsCOMPtr<Document> doc = mWindowGlobal->GetDoc()) {
|
|
|
|
nsCOMPtr<nsISupports> secInfo;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// First check if there's a failed channel, in case of a certificate
|
|
|
|
// error.
|
|
|
|
if (nsIChannel* failedChannel = doc->GetFailedChannel()) {
|
|
|
|
rv = failedChannel->GetSecurityInfo(getter_AddRefs(secInfo));
|
|
|
|
} else {
|
|
|
|
// When there's no failed channel we should have a regular
|
|
|
|
// security info on the document. In some cases there's no
|
|
|
|
// security info at all, i.e. on HTTP sites.
|
|
|
|
secInfo = doc->GetSecurityInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && secInfo) {
|
|
|
|
nsCOMPtr<nsISerializable> secInfoSer = do_QueryInterface(secInfo);
|
|
|
|
result.emplace();
|
|
|
|
NS_SerializeToString(secInfoSer, result.ref());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aResolve(result);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-04-18 22:37:15 +03:00
|
|
|
IPCResult WindowGlobalChild::RecvRawMessage(
|
|
|
|
const JSWindowActorMessageMeta& aMeta, const ClonedMessageData& aData) {
|
2019-02-08 16:02:08 +03:00
|
|
|
StructuredCloneData data;
|
|
|
|
data.BorrowFromClonedMessageDataForChild(aData);
|
2019-04-18 22:37:15 +03:00
|
|
|
ReceiveRawMessage(aMeta, std::move(data));
|
2019-02-08 16:02:08 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-04-18 22:37:15 +03:00
|
|
|
void WindowGlobalChild::ReceiveRawMessage(const JSWindowActorMessageMeta& aMeta,
|
|
|
|
StructuredCloneData&& aData) {
|
|
|
|
RefPtr<JSWindowActorChild> actor =
|
|
|
|
GetActor(aMeta.actorName(), IgnoreErrors());
|
|
|
|
if (actor) {
|
|
|
|
actor->ReceiveRawMessage(aMeta, std::move(aData));
|
2019-02-08 16:02:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:06:54 +03:00
|
|
|
void WindowGlobalChild::SetDocumentURI(nsIURI* aDocumentURI) {
|
|
|
|
mDocumentURI = aDocumentURI;
|
|
|
|
SendUpdateDocumentURI(aDocumentURI);
|
2019-05-03 21:12:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& WindowGlobalChild::GetRemoteType() {
|
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
return ContentChild::GetSingleton()->GetRemoteType();
|
|
|
|
}
|
|
|
|
|
|
|
|
return VoidString();
|
|
|
|
}
|
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
already_AddRefed<JSWindowActorChild> WindowGlobalChild::GetActor(
|
|
|
|
const nsAString& aName, ErrorResult& aRv) {
|
2019-08-08 19:06:52 +03:00
|
|
|
if (!CanSend()) {
|
2019-04-18 22:37:15 +03:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
// Check if this actor has already been created, and return it if it has.
|
|
|
|
if (mWindowActors.Contains(aName)) {
|
|
|
|
return do_AddRef(mWindowActors.GetWeak(aName));
|
|
|
|
}
|
|
|
|
|
2019-05-03 21:12:55 +03:00
|
|
|
// Otherwise, we want to create a new instance of this actor.
|
2019-01-28 22:02:02 +03:00
|
|
|
JS::RootedObject obj(RootingCx());
|
2019-05-03 21:12:55 +03:00
|
|
|
ConstructActor(aName, &obj, aRv);
|
2019-01-28 22:02:02 +03:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unwrap our actor to a JSWindowActorChild object.
|
|
|
|
RefPtr<JSWindowActorChild> actor;
|
|
|
|
if (NS_FAILED(UNWRAP_OBJECT(JSWindowActorChild, &obj, actor))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-06-06 13:13:30 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!actor->GetManager(),
|
2019-01-28 22:02:02 +03:00
|
|
|
"mManager was already initialized once!");
|
2019-02-21 22:53:59 +03:00
|
|
|
actor->Init(aName, this);
|
2019-01-28 22:02:02 +03:00
|
|
|
mWindowActors.Put(aName, actor);
|
|
|
|
return actor.forget();
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
void WindowGlobalChild::ActorDestroy(ActorDestroyReason aWhy) {
|
2018-10-20 23:04:00 +03:00
|
|
|
gWindowGlobalChildById->Remove(mInnerWindowId);
|
2019-04-18 22:37:15 +03:00
|
|
|
|
|
|
|
// Destroy our JSWindowActors, and reject any pending queries.
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, JSWindowActorChild> windowActors;
|
|
|
|
mWindowActors.SwapElements(windowActors);
|
|
|
|
for (auto iter = windowActors.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
iter.Data()->RejectPendingQueries();
|
2019-05-10 18:01:33 +03:00
|
|
|
iter.Data()->AfterDestroy();
|
2019-04-18 22:37:15 +03:00
|
|
|
}
|
2019-05-10 18:01:33 +03:00
|
|
|
windowActors.Clear();
|
2018-08-30 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
WindowGlobalChild::~WindowGlobalChild() {
|
2018-10-20 23:04:00 +03:00
|
|
|
MOZ_ASSERT(!gWindowGlobalChildById ||
|
|
|
|
!gWindowGlobalChildById->Contains(mInnerWindowId));
|
2019-05-10 18:01:33 +03:00
|
|
|
MOZ_ASSERT(!mWindowActors.Count());
|
2018-08-30 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-20 02:02:56 +03:00
|
|
|
JSObject* WindowGlobalChild::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return WindowGlobalChild_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsISupports* WindowGlobalChild::GetParentObject() {
|
|
|
|
return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
|
|
|
|
}
|
|
|
|
|
2019-05-03 21:12:55 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(WindowGlobalChild, WindowGlobalActor,
|
|
|
|
mWindowGlobal, mBrowsingContext,
|
|
|
|
mWindowActors)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(WindowGlobalChild,
|
|
|
|
WindowGlobalActor)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WindowGlobalChild)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(WindowGlobalActor)
|
2018-10-20 02:02:56 +03:00
|
|
|
|
2019-05-03 21:12:55 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(WindowGlobalChild, WindowGlobalActor)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(WindowGlobalChild, WindowGlobalActor)
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
2019-04-03 20:31:00 +03:00
|
|
|
} // namespace mozilla
|