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
|
|
|
|
2020-04-29 17:48:13 +03:00
|
|
|
#include "mozilla/AntiTrackingUtils.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"
|
2018-08-30 01:21:25 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2020-01-20 17:58:52 +03:00
|
|
|
#include "mozilla/dom/BrowsingContextGroup.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"
|
2019-10-15 19:19:16 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2020-04-11 01:14:51 +03:00
|
|
|
#include "mozilla/dom/SecurityPolicyViolationEvent.h"
|
2021-03-23 21:01:21 +03:00
|
|
|
#include "mozilla/dom/SessionStoreRestoreData.h"
|
2021-03-26 11:59:33 +03:00
|
|
|
#include "mozilla/dom/SessionStoreDataCollector.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"
|
2020-01-20 17:58:52 +03:00
|
|
|
#include "mozilla/dom/WindowContext.h"
|
2020-06-25 20:50:51 +03:00
|
|
|
#include "mozilla/dom/InProcessChild.h"
|
|
|
|
#include "mozilla/dom/InProcessParent.h"
|
2020-11-23 19:06:42 +03:00
|
|
|
#include "mozilla/ipc/Endpoint.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2021-04-06 10:34:00 +03:00
|
|
|
#include "mozilla/ScopeExit.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-04-03 20:31:00 +03:00
|
|
|
#include "nsDocShell.h"
|
2019-11-13 00:52:18 +03:00
|
|
|
#include "nsFocusManager.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"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "nsNetUtil.h"
|
2019-04-18 22:37:15 +03:00
|
|
|
#include "nsQueryObject.h"
|
2019-06-21 08:58:40 +03:00
|
|
|
#include "nsSerializationHelper.h"
|
2019-09-11 11:09:58 +03:00
|
|
|
#include "nsFrameLoader.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"
|
2020-04-30 19:42:53 +03:00
|
|
|
#include "mozilla/dom/JSActorService.h"
|
2019-04-09 23:10:13 +03:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2019-10-11 05:28:08 +03:00
|
|
|
#include "nsIURIMutator.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
|
2021-03-04 17:32:14 +03:00
|
|
|
#ifdef MOZ_GECKO_PROFILER
|
|
|
|
# include "GeckoProfiler.h"
|
|
|
|
#endif
|
|
|
|
|
2019-04-03 20:31:00 +03:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::dom::ipc;
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
WindowGlobalChild::WindowGlobalChild(dom::WindowContext* aWindowContext,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsIURI* aDocumentURI)
|
|
|
|
: mWindowContext(aWindowContext),
|
|
|
|
mDocumentPrincipal(aPrincipal),
|
|
|
|
mDocumentURI(aDocumentURI) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mWindowContext);
|
2019-08-08 19:06:54 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mDocumentPrincipal);
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
if (!mDocumentURI) {
|
|
|
|
NS_NewURI(getter_AddRefs(mDocumentURI), "about:blank");
|
|
|
|
}
|
2020-05-27 03:28:59 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_GECKO_PROFILER
|
|
|
|
// Registers a DOM Window with the profiler. It re-registers the same Inner
|
|
|
|
// Window ID with different URIs because when a Browsing context is first
|
|
|
|
// loaded, the first url loaded in it will be about:blank. This call keeps the
|
|
|
|
// first non-about:blank registration of window and discards the previous one.
|
|
|
|
uint64_t embedderInnerWindowID = 0;
|
|
|
|
if (BrowsingContext()->GetParent()) {
|
|
|
|
embedderInnerWindowID = BrowsingContext()->GetEmbedderInnerWindowId();
|
|
|
|
}
|
2021-03-25 15:52:11 +03:00
|
|
|
profiler_register_page(BrowsingContext()->BrowserId(), InnerWindowId(),
|
2020-05-27 03:28:59 +03:00
|
|
|
aDocumentURI->GetSpecOrDefault(),
|
|
|
|
embedderInnerWindowID);
|
|
|
|
#endif
|
2019-08-08 19:06:54 +03:00
|
|
|
}
|
2018-12-10 22:23:16 +03:00
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
already_AddRefed<WindowGlobalChild> WindowGlobalChild::Create(
|
|
|
|
nsGlobalWindowInner* aWindow) {
|
2020-05-01 14:36:03 +03:00
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
// Opener policy is set when we start to load a document. Here, we ensure we
|
|
|
|
// have set the correct Opener policy so that it will be available in the
|
|
|
|
// parent process through window global child.
|
2019-09-25 03:39:17 +03:00
|
|
|
nsCOMPtr<nsIChannel> chan = aWindow->GetDocument()->GetChannel();
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = chan ? chan->LoadInfo() : nullptr;
|
|
|
|
nsCOMPtr<nsIHttpChannelInternal> httpChan = do_QueryInterface(chan);
|
2019-04-09 23:10:13 +03:00
|
|
|
nsILoadInfo::CrossOriginOpenerPolicy policy;
|
2019-09-25 03:39:17 +03:00
|
|
|
if (httpChan &&
|
|
|
|
loadInfo->GetExternalContentPolicyType() ==
|
2021-01-15 15:07:16 +03:00
|
|
|
ExtContentPolicy::TYPE_DOCUMENT &&
|
2020-01-18 20:14:07 +03:00
|
|
|
NS_SUCCEEDED(httpChan->GetCrossOriginOpenerPolicy(&policy))) {
|
2020-05-08 23:44:12 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(policy ==
|
|
|
|
aWindow->GetBrowsingContext()->GetOpenerPolicy());
|
2019-04-09 23:10:13 +03:00
|
|
|
}
|
2020-05-01 14:36:03 +03:00
|
|
|
#endif
|
2019-04-09 23:10:13 +03:00
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
WindowGlobalInit init = WindowGlobalActor::WindowInitializer(aWindow);
|
|
|
|
RefPtr<WindowGlobalChild> wgc = CreateDisconnected(init);
|
2019-04-15 17:57:09 +03:00
|
|
|
|
2019-08-08 19:06:56 +03:00
|
|
|
// Send the link constructor over PBrowser, or link over PInProcess.
|
2018-08-30 01:21:25 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2019-08-08 19:06:56 +03:00
|
|
|
InProcessChild* ipChild = InProcessChild::Singleton();
|
|
|
|
InProcessParent* ipParent = InProcessParent::Singleton();
|
|
|
|
if (!ipChild || !ipParent) {
|
2018-08-30 01:21:25 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:06:56 +03:00
|
|
|
ManagedEndpoint<PWindowGlobalParent> endpoint =
|
2019-08-08 19:46:20 +03:00
|
|
|
ipChild->OpenPWindowGlobalEndpoint(wgc);
|
2020-05-08 23:44:12 +03:00
|
|
|
ipParent->BindPWindowGlobalEndpoint(std::move(endpoint),
|
|
|
|
wgc->WindowContext()->Canonical());
|
2018-08-30 01:21:25 +03:00
|
|
|
} else {
|
2020-04-06 22:03:02 +03:00
|
|
|
RefPtr<BrowserChild> browserChild =
|
|
|
|
BrowserChild::GetFrom(static_cast<mozIDOMWindow*>(aWindow));
|
|
|
|
MOZ_ASSERT(browserChild);
|
|
|
|
|
2020-09-02 05:48:51 +03:00
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2020-08-11 00:21:58 +03:00
|
|
|
dom::BrowsingContext* bc = aWindow->GetBrowsingContext();
|
2020-09-02 05:48:51 +03:00
|
|
|
#endif
|
2020-08-11 00:21:58 +03:00
|
|
|
|
2020-08-31 21:51:54 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(bc->AncestorsAreCurrent());
|
2020-08-11 00:21:58 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(bc->IsInProcess());
|
2020-07-17 17:59:23 +03:00
|
|
|
|
2019-08-08 19:06:56 +03:00
|
|
|
ManagedEndpoint<PWindowGlobalParent> endpoint =
|
2020-04-06 22:03:02 +03:00
|
|
|
browserChild->OpenPWindowGlobalEndpoint(wgc);
|
2019-08-08 19:06:56 +03:00
|
|
|
browserChild->SendNewWindowGlobal(std::move(endpoint), init);
|
2019-07-18 22:38:14 +03:00
|
|
|
}
|
|
|
|
|
2020-04-06 22:03:02 +03:00
|
|
|
wgc->Init();
|
2020-05-08 23:44:12 +03:00
|
|
|
wgc->InitWindowGlobal(aWindow);
|
2019-08-08 19:07:05 +03:00
|
|
|
return wgc.forget();
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
already_AddRefed<WindowGlobalChild> WindowGlobalChild::CreateDisconnected(
|
|
|
|
const WindowGlobalInit& aInit) {
|
|
|
|
RefPtr<dom::BrowsingContext> browsingContext =
|
|
|
|
dom::BrowsingContext::Get(aInit.context().mBrowsingContextId);
|
2019-08-08 19:07:05 +03:00
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
RefPtr<dom::WindowContext> windowContext =
|
|
|
|
dom::WindowContext::GetById(aInit.context().mInnerWindowId);
|
|
|
|
MOZ_RELEASE_ASSERT(!windowContext, "Creating duplicate WindowContext");
|
|
|
|
|
|
|
|
// Create our new WindowContext
|
2020-01-20 17:58:52 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2021-03-18 22:24:50 +03:00
|
|
|
windowContext = WindowGlobalParent::CreateDisconnected(aInit);
|
2020-01-20 17:58:52 +03:00
|
|
|
} else {
|
2020-07-22 17:07:26 +03:00
|
|
|
dom::WindowContext::FieldValues fields = aInit.context().mFields;
|
2021-03-18 22:24:50 +03:00
|
|
|
windowContext = new dom::WindowContext(
|
|
|
|
browsingContext, aInit.context().mInnerWindowId,
|
|
|
|
aInit.context().mOuterWindowId, std::move(fields));
|
2020-01-20 17:58:52 +03:00
|
|
|
}
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
RefPtr<WindowGlobalChild> windowChild = new WindowGlobalChild(
|
|
|
|
windowContext, aInit.principal(), aInit.documentURI());
|
2021-03-24 17:11:49 +03:00
|
|
|
windowContext->mIsInProcess = true;
|
2021-03-18 22:24:50 +03:00
|
|
|
windowContext->mWindowGlobalChild = windowChild;
|
2020-05-08 23:44:12 +03:00
|
|
|
return windowChild.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowGlobalChild::Init() {
|
2021-03-18 22:24:50 +03:00
|
|
|
MOZ_ASSERT(mWindowContext->mWindowGlobalChild == this);
|
2020-05-08 23:44:12 +03:00
|
|
|
mWindowContext->Init();
|
2019-07-18 22:38:22 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:07:12 +03:00
|
|
|
void WindowGlobalChild::InitWindowGlobal(nsGlobalWindowInner* aWindow) {
|
|
|
|
mWindowGlobal = aWindow;
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:42:06 +03:00
|
|
|
void WindowGlobalChild::OnNewDocument(Document* aDocument) {
|
|
|
|
MOZ_RELEASE_ASSERT(mWindowGlobal);
|
|
|
|
MOZ_RELEASE_ASSERT(aDocument);
|
|
|
|
|
|
|
|
// Send a series of messages to update document-specific state on
|
2020-05-27 03:27:30 +03:00
|
|
|
// WindowGlobalParent, when we change documents on an existing WindowGlobal.
|
|
|
|
// This data is also all sent when we construct a WindowGlobal, so anything
|
|
|
|
// added here should also be added to WindowGlobalActor::WindowInitializer.
|
|
|
|
|
2020-05-08 23:42:06 +03:00
|
|
|
// FIXME: Perhaps these should be combined into a smaller number of messages?
|
|
|
|
SetDocumentURI(aDocument->GetDocumentURI());
|
2021-05-21 11:43:54 +03:00
|
|
|
SetDocumentPrincipal(aDocument->NodePrincipal());
|
2020-05-27 03:28:59 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsITransportSecurityInfo> securityInfo;
|
|
|
|
if (nsCOMPtr<nsIChannel> channel = aDocument->GetChannel()) {
|
|
|
|
nsCOMPtr<nsISupports> securityInfoSupports;
|
|
|
|
channel->GetSecurityInfo(getter_AddRefs(securityInfoSupports));
|
|
|
|
securityInfo = do_QueryInterface(securityInfoSupports);
|
|
|
|
}
|
|
|
|
SendUpdateDocumentSecurityInfo(securityInfo);
|
|
|
|
|
2020-05-08 23:42:06 +03:00
|
|
|
SendUpdateDocumentCspSettings(aDocument->GetBlockAllMixedContent(false),
|
|
|
|
aDocument->GetUpgradeInsecureRequests(false));
|
|
|
|
SendUpdateSandboxFlags(aDocument->GetSandboxFlags());
|
|
|
|
|
|
|
|
net::CookieJarSettingsArgs csArgs;
|
|
|
|
net::CookieJarSettings::Cast(aDocument->CookieJarSettings())
|
|
|
|
->Serialize(csArgs);
|
|
|
|
if (!SendUpdateCookieJarSettings(csArgs)) {
|
|
|
|
NS_WARNING(
|
|
|
|
"Failed to update document's cookie jar settings on the "
|
|
|
|
"WindowGlobalParent");
|
|
|
|
}
|
|
|
|
|
2020-05-26 14:45:21 +03:00
|
|
|
SendUpdateHttpsOnlyStatus(aDocument->HttpsOnlyStatus());
|
|
|
|
|
2020-05-08 23:42:06 +03:00
|
|
|
// Update window context fields for the newly loaded Document.
|
|
|
|
WindowContext::Transaction txn;
|
|
|
|
txn.SetCookieBehavior(
|
|
|
|
Some(aDocument->CookieJarSettings()->GetCookieBehavior()));
|
|
|
|
txn.SetIsOnContentBlockingAllowList(
|
|
|
|
aDocument->CookieJarSettings()->GetIsOnContentBlockingAllowList());
|
2020-06-17 23:18:23 +03:00
|
|
|
txn.SetIsThirdPartyWindow(aDocument->HasThirdPartyChannel());
|
2020-05-08 23:42:06 +03:00
|
|
|
txn.SetIsThirdPartyTrackingResourceWindow(
|
|
|
|
nsContentUtils::IsThirdPartyTrackingResourceWindow(mWindowGlobal));
|
2020-05-14 00:52:39 +03:00
|
|
|
txn.SetIsSecureContext(mWindowGlobal->IsSecureContext());
|
2021-04-12 21:04:12 +03:00
|
|
|
if (auto policy = aDocument->GetEmbedderPolicy()) {
|
|
|
|
txn.SetEmbedderPolicy(*policy);
|
2020-05-11 21:41:16 +03:00
|
|
|
}
|
2020-05-08 23:42:06 +03:00
|
|
|
|
2020-09-22 20:41:34 +03:00
|
|
|
if (nsCOMPtr<nsIChannel> channel = aDocument->GetChannel()) {
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo(channel->LoadInfo());
|
|
|
|
txn.SetIsOriginalFrameSource(loadInfo->GetOriginalFrameSrcLoad());
|
|
|
|
} else {
|
|
|
|
txn.SetIsOriginalFrameSource(false);
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:42:06 +03:00
|
|
|
// Init Mixed Content Fields
|
2020-06-16 12:05:54 +03:00
|
|
|
nsCOMPtr<nsIURI> innerDocURI =
|
|
|
|
NS_GetInnermostURI(aDocument->GetDocumentURI());
|
|
|
|
if (innerDocURI) {
|
|
|
|
txn.SetIsSecure(innerDocURI->SchemeIs("https"));
|
|
|
|
}
|
2020-07-31 16:37:13 +03:00
|
|
|
|
2020-12-10 23:45:54 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mDocumentPrincipal->GetIsLocalIpAddress() ==
|
|
|
|
mWindowContext->IsLocalIP());
|
|
|
|
|
2020-07-31 16:37:13 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(txn.Commit(mWindowContext));
|
2020-05-08 23:42:06 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<WindowGlobalChild> WindowGlobalChild::GetByInnerWindowId(
|
|
|
|
uint64_t aInnerWindowId) {
|
2021-03-18 22:24:50 +03:00
|
|
|
if (RefPtr<dom::WindowContext> context =
|
|
|
|
dom::WindowContext::GetById(aInnerWindowId)) {
|
|
|
|
return do_AddRef(context->GetWindowGlobalChild());
|
2018-10-20 23:04:00 +03:00
|
|
|
}
|
2021-03-18 22:24:50 +03:00
|
|
|
return nullptr;
|
2018-10-20 23:04:00 +03:00
|
|
|
}
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
dom::BrowsingContext* WindowGlobalChild::BrowsingContext() {
|
|
|
|
return mWindowContext->GetBrowsingContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t WindowGlobalChild::InnerWindowId() {
|
|
|
|
return mWindowContext->InnerWindowId();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t WindowGlobalChild::OuterWindowId() {
|
|
|
|
return mWindowContext->OuterWindowId();
|
|
|
|
}
|
|
|
|
|
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() {
|
2020-04-06 22:03:02 +03:00
|
|
|
if (IsInProcess() || !CanSend()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
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()) {
|
2020-09-22 01:40:51 +03:00
|
|
|
Unused << mWindowContext->SetHasBeforeUnload(true);
|
2019-07-15 20:30:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mBeforeUnloadListeners++;
|
|
|
|
MOZ_ASSERT(mBeforeUnloadListeners > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowGlobalChild::BeforeUnloadRemoved() {
|
|
|
|
mBeforeUnloadListeners--;
|
|
|
|
MOZ_ASSERT(mBeforeUnloadListeners >= 0);
|
|
|
|
|
2020-09-22 01:40:51 +03:00
|
|
|
if (mBeforeUnloadListeners == 0) {
|
|
|
|
Unused << mWindowContext->SetHasBeforeUnload(false);
|
2019-07-15 20:30:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 21:09:13 +03:00
|
|
|
void WindowGlobalChild::Destroy() {
|
2020-10-29 17:24:43 +03:00
|
|
|
JSActorWillDestroy();
|
|
|
|
|
2021-03-18 22:24:49 +03:00
|
|
|
mWindowContext->Discard();
|
|
|
|
|
2020-10-29 17:24:43 +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()) {
|
|
|
|
SendDestroy();
|
|
|
|
}
|
2021-03-26 11:59:33 +03:00
|
|
|
|
|
|
|
if (mSessionStoreDataCollector) {
|
|
|
|
mSessionStoreDataCollector->Cancel();
|
|
|
|
mSessionStoreDataCollector = nullptr;
|
|
|
|
}
|
2019-01-28 21:09:13 +03:00
|
|
|
}
|
|
|
|
|
2019-10-15 19:19:16 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvMakeFrameLocal(
|
2020-02-21 02:30:35 +03:00
|
|
|
const MaybeDiscarded<dom::BrowsingContext>& aFrameContext,
|
|
|
|
uint64_t aPendingSwitchId) {
|
2019-10-15 19:19:16 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(XRE_IsContentProcess());
|
|
|
|
|
2020-02-21 02:30:35 +03:00
|
|
|
MOZ_LOG(BrowsingContext::GetLog(), LogLevel::Debug,
|
|
|
|
("RecvMakeFrameLocal ID=%" PRIx64, aFrameContext.ContextId()));
|
2019-10-15 19:19:16 +03:00
|
|
|
|
2020-02-21 02:30:35 +03:00
|
|
|
if (NS_WARN_IF(aFrameContext.IsNullOrDiscarded())) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
dom::BrowsingContext* frameContext = aFrameContext.get();
|
|
|
|
|
|
|
|
RefPtr<Element> embedderElt = frameContext->GetEmbedderElement();
|
2019-10-15 19:19:16 +03:00
|
|
|
if (NS_WARN_IF(!embedderElt)) {
|
2019-10-22 16:57:00 +03:00
|
|
|
return IPC_OK();
|
2019-04-17 03:53:32 +03:00
|
|
|
}
|
|
|
|
|
2020-03-24 02:03:50 +03:00
|
|
|
if (NS_WARN_IF(embedderElt->GetOwnerGlobal() != GetWindowGlobal())) {
|
2019-10-22 16:57:00 +03:00
|
|
|
return IPC_OK();
|
2019-04-17 03:53:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsFrameLoaderOwner> flo = do_QueryObject(embedderElt);
|
2019-10-15 19:19:16 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(flo, "Embedder must be a nsFrameLoaderOwner");
|
2019-04-17 03:53:32 +03:00
|
|
|
|
2019-10-15 19:19:16 +03:00
|
|
|
// Trigger a process switch into the current process.
|
2019-04-17 03:53:32 +03:00
|
|
|
RemotenessOptions options;
|
2020-07-08 23:16:04 +03:00
|
|
|
options.mRemoteType = NOT_REMOTE_TYPE;
|
2019-04-17 03:53:32 +03:00
|
|
|
options.mPendingSwitchID.Construct(aPendingSwitchId);
|
2020-06-16 02:23:58 +03:00
|
|
|
options.mSwitchingInProgressLoad = true;
|
2019-10-15 19:19:16 +03:00
|
|
|
flo->ChangeRemoteness(options, IgnoreErrors());
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2019-04-17 03:53:32 +03:00
|
|
|
|
2019-10-15 19:19:16 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvMakeFrameRemote(
|
2020-02-21 02:30:35 +03:00
|
|
|
const MaybeDiscarded<dom::BrowsingContext>& aFrameContext,
|
2019-10-15 19:19:16 +03:00
|
|
|
ManagedEndpoint<PBrowserBridgeChild>&& aEndpoint, const TabId& aTabId,
|
2020-05-25 09:06:30 +03:00
|
|
|
const LayersId& aLayersId, MakeFrameRemoteResolver&& aResolve) {
|
2019-10-15 19:19:16 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(XRE_IsContentProcess());
|
2019-10-02 04:14:53 +03:00
|
|
|
|
2020-02-21 02:30:35 +03:00
|
|
|
MOZ_LOG(BrowsingContext::GetLog(), LogLevel::Debug,
|
|
|
|
("RecvMakeFrameRemote ID=%" PRIx64, aFrameContext.ContextId()));
|
2019-04-17 03:53:32 +03:00
|
|
|
|
2020-05-25 09:06:30 +03:00
|
|
|
if (!aLayersId.IsValid()) {
|
|
|
|
return IPC_FAIL(this, "Received an invalid LayersId");
|
|
|
|
}
|
|
|
|
|
2021-03-31 19:51:58 +03:00
|
|
|
// Resolve the promise when this function exits, as we'll have fully unloaded
|
|
|
|
// at that point.
|
|
|
|
auto scopeExit = MakeScopeExit([&] { aResolve(true); });
|
|
|
|
|
2020-02-21 02:30:35 +03:00
|
|
|
// Get a BrowsingContext if we're not null or discarded. We don't want to
|
|
|
|
// early-return before we connect the BrowserBridgeChild, as otherwise we'll
|
|
|
|
// never break the channel in the parent.
|
|
|
|
RefPtr<dom::BrowsingContext> frameContext;
|
|
|
|
if (!aFrameContext.IsDiscarded()) {
|
|
|
|
frameContext = aFrameContext.get();
|
|
|
|
}
|
|
|
|
|
2019-10-22 16:57:00 +03:00
|
|
|
// Immediately construct the BrowserBridgeChild so we can destroy it cleanly
|
|
|
|
// if the process switch fails.
|
|
|
|
RefPtr<BrowserBridgeChild> bridge =
|
2020-05-25 09:06:30 +03:00
|
|
|
new BrowserBridgeChild(frameContext, aTabId, aLayersId);
|
2019-10-22 16:57:00 +03:00
|
|
|
RefPtr<BrowserChild> manager = GetBrowserChild();
|
|
|
|
if (NS_WARN_IF(
|
|
|
|
!manager->BindPBrowserBridgeEndpoint(std::move(aEndpoint), bridge))) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2021-03-31 19:51:58 +03:00
|
|
|
auto deleteBridge =
|
|
|
|
MakeScopeExit([&] { BrowserBridgeChild::Send__delete__(bridge); });
|
|
|
|
|
2020-02-21 02:30:35 +03:00
|
|
|
// Immediately tear down the actor if we don't have a valid FrameContext.
|
|
|
|
if (NS_WARN_IF(aFrameContext.IsNullOrDiscarded())) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> embedderElt = frameContext->GetEmbedderElement();
|
2019-10-15 19:19:16 +03:00
|
|
|
if (NS_WARN_IF(!embedderElt)) {
|
2019-10-22 16:57:00 +03:00
|
|
|
return IPC_OK();
|
2019-10-04 00:40:24 +03:00
|
|
|
}
|
2019-10-02 04:14:53 +03:00
|
|
|
|
2020-03-24 02:03:50 +03:00
|
|
|
if (NS_WARN_IF(embedderElt->GetOwnerGlobal() != GetWindowGlobal())) {
|
2019-10-22 16:57:00 +03:00
|
|
|
return IPC_OK();
|
2019-10-15 19:19:16 +03:00
|
|
|
}
|
2019-10-05 00:08:33 +03:00
|
|
|
|
2019-10-15 19:19:16 +03:00
|
|
|
RefPtr<nsFrameLoaderOwner> flo = do_QueryObject(embedderElt);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(flo, "Embedder must be a nsFrameLoaderOwner");
|
2019-04-17 03:53:32 +03:00
|
|
|
|
2019-10-15 19:19:16 +03:00
|
|
|
// Trgger a process switch into the specified process.
|
2019-10-22 16:57:00 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
flo->ChangeRemotenessWithBridge(bridge, rv);
|
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2021-03-31 19:51:58 +03:00
|
|
|
// Everything succeeded, so don't delete the bridge.
|
|
|
|
deleteBridge.release();
|
|
|
|
|
2019-04-17 03:53:32 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvDrawSnapshot(
|
|
|
|
const Maybe<IntRect>& aRect, const float& aScale,
|
2019-08-14 13:23:39 +03:00
|
|
|
const nscolor& aBackgroundColor, const uint32_t& aFlags,
|
|
|
|
DrawSnapshotResolver&& aResolve) {
|
2020-12-11 18:43:19 +03:00
|
|
|
aResolve(gfx::PaintFragment::Record(BrowsingContext(), aRect, aScale,
|
|
|
|
aBackgroundColor,
|
2019-08-14 13:23:39 +03:00
|
|
|
(gfx::CrossProcessPaintFlags)aFlags));
|
2019-07-10 19:45:46 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-06-03 09:12:06 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
WindowGlobalChild::RecvSaveStorageAccessPermissionGranted() {
|
2020-05-18 14:04:50 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> inner = GetWindowGlobal();
|
|
|
|
if (inner) {
|
2020-06-03 09:10:58 +03:00
|
|
|
inner->SaveStorageAccessPermissionGranted();
|
2020-04-29 17:48:13 +03:00
|
|
|
}
|
|
|
|
|
2020-05-18 14:04:48 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> outer =
|
|
|
|
nsPIDOMWindowOuter::GetFromCurrentInner(inner);
|
|
|
|
if (outer) {
|
2020-06-03 09:10:58 +03:00
|
|
|
nsGlobalWindowOuter::Cast(outer)->SetStorageAccessPermissionGranted(true);
|
2020-05-18 14:04:48 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 17:48:13 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2020-04-11 01:14:51 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvDispatchSecurityPolicyViolation(
|
|
|
|
const nsString& aViolationEventJSON) {
|
|
|
|
nsGlobalWindowInner* window = GetWindowGlobal();
|
|
|
|
if (!window) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
Document* doc = window->GetDocument();
|
|
|
|
if (!doc) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
SecurityPolicyViolationEventInit violationEvent;
|
|
|
|
if (!violationEvent.Init(aViolationEventJSON)) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Event> event = SecurityPolicyViolationEvent::Constructor(
|
|
|
|
doc, u"securitypolicyviolation"_ns, violationEvent);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
doc->DispatchEvent(*event, IgnoreErrors());
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2020-06-25 07:32:28 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvAddBlockedFrameNodeByClassifier(
|
|
|
|
const MaybeDiscardedBrowsingContext& aNode) {
|
|
|
|
if (aNode.IsNullOrDiscarded()) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGlobalWindowInner* window = GetWindowGlobal();
|
|
|
|
if (!window) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
Document* doc = window->GetDocument();
|
|
|
|
if (!doc) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aNode.get()->GetEmbedderElement()->OwnerDoc() == doc);
|
|
|
|
doc->AddBlockedNodeByClassifier(aNode.get()->GetEmbedderElement());
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2020-10-29 01:48:57 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvResetScalingZoom() {
|
|
|
|
if (Document* doc = mWindowGlobal->GetExtantDoc()) {
|
|
|
|
if (PresShell* ps = doc->GetPresShell()) {
|
|
|
|
ps->SetResolutionAndScaleTo(1.0,
|
|
|
|
ResolutionChangeOrigin::MainThreadAdjustment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2021-01-14 14:15:24 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvSetContainerFeaturePolicy(
|
|
|
|
dom::FeaturePolicy* aContainerFeaturePolicy) {
|
|
|
|
mContainerFeaturePolicy = aContainerFeaturePolicy;
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2021-05-03 21:16:41 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvRestoreDocShellState(
|
|
|
|
const dom::sessionstore::DocShellRestoreState& aState,
|
|
|
|
RestoreDocShellStateResolver&& aResolve) {
|
|
|
|
if (mWindowGlobal) {
|
|
|
|
SessionStoreUtils::RestoreDocShellState(mWindowGlobal->GetDocShell(),
|
|
|
|
aState);
|
|
|
|
}
|
|
|
|
aResolve(true);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2021-03-23 21:01:21 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvRestoreTabContent(
|
|
|
|
dom::SessionStoreRestoreData* aData, RestoreTabContentResolver&& aResolve) {
|
|
|
|
aData->RestoreInto(BrowsingContext());
|
|
|
|
aResolve(true);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2020-10-13 20:43:56 +03:00
|
|
|
IPCResult WindowGlobalChild::RecvRawMessage(
|
|
|
|
const JSActorMessageMeta& aMeta, const Maybe<ClonedMessageData>& aData,
|
|
|
|
const Maybe<ClonedMessageData>& aStack) {
|
|
|
|
Maybe<StructuredCloneData> data;
|
|
|
|
if (aData) {
|
|
|
|
data.emplace();
|
|
|
|
data->BorrowFromClonedMessageDataForChild(*aData);
|
|
|
|
}
|
|
|
|
Maybe<StructuredCloneData> stack;
|
|
|
|
if (aStack) {
|
|
|
|
stack.emplace();
|
|
|
|
stack->BorrowFromClonedMessageDataForChild(*aStack);
|
|
|
|
}
|
2019-12-07 21:59:23 +03:00
|
|
|
ReceiveRawMessage(aMeta, std::move(data), std::move(stack));
|
2019-02-08 16:02:08 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:06:54 +03:00
|
|
|
void WindowGlobalChild::SetDocumentURI(nsIURI* aDocumentURI) {
|
2019-10-09 23:57:51 +03:00
|
|
|
#ifdef MOZ_GECKO_PROFILER
|
|
|
|
// Registers a DOM Window with the profiler. It re-registers the same Inner
|
|
|
|
// Window ID with different URIs because when a Browsing context is first
|
|
|
|
// loaded, the first url loaded in it will be about:blank. This call keeps the
|
|
|
|
// first non-about:blank registration of window and discards the previous one.
|
2019-10-10 00:25:19 +03:00
|
|
|
uint64_t embedderInnerWindowID = 0;
|
2020-05-08 23:44:12 +03:00
|
|
|
if (BrowsingContext()->GetParent()) {
|
|
|
|
embedderInnerWindowID = BrowsingContext()->GetEmbedderInnerWindowId();
|
2019-10-10 00:25:19 +03:00
|
|
|
}
|
2021-03-25 15:52:11 +03:00
|
|
|
profiler_register_page(BrowsingContext()->BrowserId(), InnerWindowId(),
|
2019-10-09 23:57:51 +03:00
|
|
|
aDocumentURI->GetSpecOrDefault(),
|
2019-10-10 00:25:19 +03:00
|
|
|
embedderInnerWindowID);
|
2019-10-09 23:57:51 +03:00
|
|
|
#endif
|
2019-08-08 19:06:54 +03:00
|
|
|
mDocumentURI = aDocumentURI;
|
|
|
|
SendUpdateDocumentURI(aDocumentURI);
|
2019-05-03 21:12:55 +03:00
|
|
|
}
|
|
|
|
|
2020-04-15 21:53:06 +03:00
|
|
|
void WindowGlobalChild::SetDocumentPrincipal(
|
2021-05-21 11:43:54 +03:00
|
|
|
nsIPrincipal* aNewDocumentPrincipal) {
|
2020-04-15 21:53:06 +03:00
|
|
|
MOZ_ASSERT(mDocumentPrincipal->Equals(aNewDocumentPrincipal));
|
|
|
|
mDocumentPrincipal = aNewDocumentPrincipal;
|
2021-05-21 11:43:54 +03:00
|
|
|
SendUpdateDocumentPrincipal(aNewDocumentPrincipal);
|
2020-04-15 21:53:06 +03:00
|
|
|
}
|
|
|
|
|
2020-07-08 23:15:59 +03:00
|
|
|
const nsACString& WindowGlobalChild::GetRemoteType() {
|
2019-05-03 21:12:55 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
return ContentChild::GetSingleton()->GetRemoteType();
|
|
|
|
}
|
|
|
|
|
2020-07-08 23:16:04 +03:00
|
|
|
return NOT_REMOTE_TYPE;
|
2019-05-03 21:12:55 +03:00
|
|
|
}
|
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
already_AddRefed<JSWindowActorChild> WindowGlobalChild::GetActor(
|
2020-08-05 00:38:47 +03:00
|
|
|
JSContext* aCx, const nsACString& aName, ErrorResult& aRv) {
|
|
|
|
return JSActorManager::GetActor(aCx, aName, aRv)
|
|
|
|
.downcast<JSWindowActorChild>();
|
2020-07-08 17:22:22 +03:00
|
|
|
}
|
2020-07-08 04:09:27 +03:00
|
|
|
|
2021-05-11 20:29:24 +03:00
|
|
|
already_AddRefed<JSWindowActorChild> WindowGlobalChild::GetExistingActor(
|
|
|
|
const nsACString& aName) {
|
|
|
|
return JSActorManager::GetExistingActor(aName).downcast<JSWindowActorChild>();
|
|
|
|
}
|
|
|
|
|
2020-07-08 17:22:22 +03:00
|
|
|
already_AddRefed<JSActor> WindowGlobalChild::InitJSActor(
|
|
|
|
JS::HandleObject aMaybeActor, const nsACString& aName, ErrorResult& aRv) {
|
2019-01-28 22:02:02 +03:00
|
|
|
RefPtr<JSWindowActorChild> actor;
|
2020-07-08 17:22:22 +03:00
|
|
|
if (aMaybeActor.get()) {
|
|
|
|
aRv = UNWRAP_OBJECT(JSWindowActorChild, aMaybeActor.get(), actor);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actor = new JSWindowActorChild();
|
2019-01-28 22:02:02 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
return actor.forget();
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
void WindowGlobalChild::ActorDestroy(ActorDestroyReason aWhy) {
|
2020-02-04 21:16:07 +03:00
|
|
|
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Destroying WindowGlobalChild can run script");
|
|
|
|
|
2021-03-18 22:24:49 +03:00
|
|
|
// If our WindowContext hasn't been marked as discarded yet, ensure it's
|
|
|
|
// marked as discarded at this point.
|
|
|
|
mWindowContext->Discard();
|
|
|
|
|
2019-10-09 23:57:51 +03:00
|
|
|
#ifdef MOZ_GECKO_PROFILER
|
2020-05-08 23:44:12 +03:00
|
|
|
profiler_unregister_page(InnerWindowId());
|
2019-10-09 23:57:51 +03:00
|
|
|
#endif
|
|
|
|
|
2020-04-30 19:42:53 +03:00
|
|
|
// Destroy our JSActors, and reject any pending queries.
|
2020-07-08 17:22:22 +03:00
|
|
|
JSActorDidDestroy();
|
2018-08-30 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
2020-10-22 22:42:33 +03:00
|
|
|
bool WindowGlobalChild::IsSameOriginWith(
|
|
|
|
const dom::WindowContext* aOther) const {
|
|
|
|
if (aOther == WindowContext()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(WindowContext()->Group() == aOther->Group());
|
|
|
|
if (nsGlobalWindowInner* otherWin = aOther->GetInnerWindow()) {
|
|
|
|
return mDocumentPrincipal->Equals(otherWin->GetPrincipal());
|
2020-09-16 19:29:37 +03:00
|
|
|
}
|
2020-10-22 22:42:33 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowGlobalChild::SameOriginWithTop() {
|
|
|
|
return IsSameOriginWith(WindowContext()->TopWindowContext());
|
2020-09-16 19:29:37 +03:00
|
|
|
}
|
|
|
|
|
2021-04-19 17:50:54 +03:00
|
|
|
void WindowGlobalChild::UnblockBFCacheFor(BFCacheStatus aStatus) {
|
|
|
|
SendUpdateBFCacheStatus(0, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowGlobalChild::BlockBFCacheFor(BFCacheStatus aStatus) {
|
|
|
|
SendUpdateBFCacheStatus(aStatus, 0);
|
|
|
|
}
|
|
|
|
|
2021-03-18 22:24:50 +03:00
|
|
|
WindowGlobalChild::~WindowGlobalChild() = default;
|
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());
|
|
|
|
}
|
|
|
|
|
2021-03-26 11:59:33 +03:00
|
|
|
void WindowGlobalChild::SetSessionStoreDataCollector(
|
|
|
|
SessionStoreDataCollector* aCollector) {
|
|
|
|
mSessionStoreDataCollector = aCollector;
|
|
|
|
}
|
|
|
|
|
|
|
|
SessionStoreDataCollector* WindowGlobalChild::GetSessionStoreDataCollector()
|
|
|
|
const {
|
|
|
|
return mSessionStoreDataCollector;
|
|
|
|
}
|
|
|
|
|
2021-03-24 17:11:49 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WEAK_PTR(WindowGlobalChild, mWindowGlobal,
|
|
|
|
mContainerFeaturePolicy,
|
2021-03-26 11:59:33 +03:00
|
|
|
mWindowContext,
|
|
|
|
mSessionStoreDataCollector)
|
2019-05-03 21:12:55 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WindowGlobalChild)
|
2020-01-20 17:58:52 +03:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2018-10-20 02:02:56 +03:00
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(WindowGlobalChild)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(WindowGlobalChild)
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|