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"
|
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"
|
2019-04-03 20:31:00 +03:00
|
|
|
#include "mozilla/ipc/InProcessChild.h"
|
2019-08-08 19:06:56 +03:00
|
|
|
#include "mozilla/ipc/InProcessParent.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"
|
|
|
|
#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
|
|
|
|
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;
|
|
|
|
|
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");
|
|
|
|
}
|
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() ==
|
|
|
|
nsIContentPolicy::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);
|
|
|
|
|
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()) {
|
2020-05-08 23:44:12 +03:00
|
|
|
windowContext =
|
|
|
|
WindowGlobalParent::CreateDisconnected(aInit, /* aInProcess */ true);
|
2020-01-20 17:58:52 +03:00
|
|
|
} else {
|
2020-05-08 23:44:12 +03:00
|
|
|
dom::WindowContext::FieldTuple fields = aInit.context().mFields;
|
|
|
|
windowContext =
|
|
|
|
new dom::WindowContext(browsingContext, aInit.context().mInnerWindowId,
|
|
|
|
aInit.context().mOuterWindowId,
|
|
|
|
/* aInProcess */ true, 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());
|
|
|
|
return windowChild.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowGlobalChild::Init() {
|
|
|
|
mWindowContext->Init();
|
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
// Register this WindowGlobal in the gWindowGlobalParentsById map.
|
|
|
|
if (!gWindowGlobalChildById) {
|
|
|
|
gWindowGlobalChildById = new WGCByIdMap();
|
|
|
|
ClearOnShutdown(&gWindowGlobalChildById);
|
|
|
|
}
|
2020-05-08 23:44:12 +03:00
|
|
|
auto entry = gWindowGlobalChildById->LookupForAdd(InnerWindowId());
|
2018-10-20 23:04:00 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!entry, "Duplicate WindowGlobalChild entry for ID!");
|
2019-08-08 19:07:05 +03:00
|
|
|
entry.OrInsert([&] { return this; });
|
2019-07-18 22:38:22 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:07:12 +03:00
|
|
|
void WindowGlobalChild::InitWindowGlobal(nsGlobalWindowInner* aWindow) {
|
|
|
|
mWindowGlobal = aWindow;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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()) {
|
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() {
|
2020-02-04 21:16:07 +03:00
|
|
|
// Destroying a WindowGlobalChild requires running script, so hold off on
|
|
|
|
// doing it until we can safely run JS callbacks.
|
|
|
|
nsContentUtils::AddScriptRunner(NS_NewRunnableFunction(
|
|
|
|
"WindowGlobalChild::Destroy", [self = RefPtr<WindowGlobalChild>(this)]() {
|
|
|
|
// Make a copy so that we can avoid potential iterator invalidation when
|
|
|
|
// calling the user-provided Destroy() methods.
|
|
|
|
nsTArray<RefPtr<JSWindowActorChild>> windowActors(
|
|
|
|
self->mWindowActors.Count());
|
|
|
|
for (auto iter = self->mWindowActors.Iter(); !iter.Done();
|
|
|
|
iter.Next()) {
|
|
|
|
windowActors.AppendElement(iter.UserData());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& windowActor : windowActors) {
|
|
|
|
windowActor->StartDestroy();
|
|
|
|
}
|
|
|
|
|
2020-04-06 22:03:02 +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 = self->GetBrowserChild();
|
|
|
|
if (!browserChild || !browserChild->IsDestroyed()) {
|
|
|
|
self->SendDestroy();
|
|
|
|
}
|
2020-02-04 21:16:07 +03:00
|
|
|
}));
|
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;
|
2019-10-15 19:19:16 +03:00
|
|
|
options.mRemoteType.Assign(VoidString());
|
2019-04-17 03:53:32 +03:00
|
|
|
options.mPendingSwitchID.Construct(aPendingSwitchId);
|
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,
|
|
|
|
MakeFrameRemoteResolver&& aResolve) {
|
|
|
|
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
|
|
|
|
2019-10-15 19:19:16 +03:00
|
|
|
// Immediately resolve the promise, acknowledging the request.
|
|
|
|
aResolve(true);
|
2019-10-05 00:08:33 +03:00
|
|
|
|
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-02-21 02:30:35 +03:00
|
|
|
new BrowserBridgeChild(frameContext, aTabId);
|
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();
|
|
|
|
}
|
|
|
|
|
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())) {
|
|
|
|
BrowserBridgeChild::Send__delete__(bridge);
|
|
|
|
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
|
|
|
BrowserBridgeChild::Send__delete__(bridge);
|
|
|
|
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
|
|
|
BrowserBridgeChild::Send__delete__(bridge);
|
|
|
|
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())) {
|
|
|
|
BrowserBridgeChild::Send__delete__(bridge);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-07-10 19:45:46 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = BrowsingContext()->GetDocShell();
|
|
|
|
if (!docShell) {
|
|
|
|
aResolve(gfx::PaintFragment{});
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-08-14 13:23:39 +03:00
|
|
|
aResolve(gfx::PaintFragment::Record(docShell, aRect, aScale, aBackgroundColor,
|
|
|
|
(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-04-29 17:48:13 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalChild::RecvSaveStorageAccessGranted(
|
|
|
|
const nsCString& aPermissionKey) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = GetWindowGlobal();
|
|
|
|
if (!window) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsAutoCString trackingOrigin;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal = DocumentPrincipal();
|
|
|
|
if (principal && NS_SUCCEEDED(principal->GetOriginNoSuffix(trackingOrigin))) {
|
|
|
|
nsAutoCString permissionKey;
|
|
|
|
AntiTrackingUtils::CreateStoragePermissionKey(trackingOrigin,
|
|
|
|
permissionKey);
|
|
|
|
MOZ_ASSERT(permissionKey == aPermissionKey);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
window->SaveStorageAccessGranted(aPermissionKey);
|
|
|
|
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, NS_LITERAL_STRING("securitypolicyviolation"), violationEvent);
|
|
|
|
event->SetTrusted(true);
|
|
|
|
doc->DispatchEvent(*event, IgnoreErrors());
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2020-05-07 10:22:17 +03:00
|
|
|
IPCResult WindowGlobalChild::RecvRawMessage(const JSActorMessageMeta& aMeta,
|
|
|
|
const ClonedMessageData& aData,
|
|
|
|
const ClonedMessageData& aStack) {
|
2019-02-08 16:02:08 +03:00
|
|
|
StructuredCloneData data;
|
|
|
|
data.BorrowFromClonedMessageDataForChild(aData);
|
2019-12-07 21:59:23 +03:00
|
|
|
StructuredCloneData stack;
|
|
|
|
stack.BorrowFromClonedMessageDataForChild(aStack);
|
|
|
|
ReceiveRawMessage(aMeta, std::move(data), std::move(stack));
|
2019-02-08 16:02:08 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2020-04-30 19:42:53 +03:00
|
|
|
void WindowGlobalChild::ReceiveRawMessage(const JSActorMessageMeta& aMeta,
|
2019-12-07 21:59:23 +03:00
|
|
|
StructuredCloneData&& aData,
|
|
|
|
StructuredCloneData&& aStack) {
|
2019-04-18 22:37:15 +03:00
|
|
|
RefPtr<JSWindowActorChild> actor =
|
|
|
|
GetActor(aMeta.actorName(), IgnoreErrors());
|
|
|
|
if (actor) {
|
2019-12-07 21:59:23 +03:00
|
|
|
actor->ReceiveRawMessage(aMeta, std::move(aData), std::move(aStack));
|
2019-02-08 16:02:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2020-05-08 23:44:12 +03:00
|
|
|
profiler_register_page(BrowsingContext()->Id(), 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(
|
|
|
|
nsIPrincipal* aNewDocumentPrincipal) {
|
|
|
|
MOZ_ASSERT(mDocumentPrincipal->Equals(aNewDocumentPrincipal));
|
|
|
|
mDocumentPrincipal = aNewDocumentPrincipal;
|
|
|
|
SendUpdateDocumentPrincipal(aNewDocumentPrincipal);
|
|
|
|
}
|
|
|
|
|
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(
|
2020-04-17 13:56:22 +03:00
|
|
|
const nsACString& 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);
|
2020-02-25 20:03:36 +03:00
|
|
|
mWindowActors.Put(aName, RefPtr{actor});
|
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");
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
gWindowGlobalChildById->Remove(InnerWindowId());
|
2019-04-18 22:37:15 +03:00
|
|
|
|
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-04-17 13:56:22 +03:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorChild> windowActors;
|
2019-04-18 22:37:15 +03:00
|
|
|
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 ||
|
2020-05-08 23:44:12 +03:00
|
|
|
!gWindowGlobalChildById->Contains(InnerWindowId()));
|
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());
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WindowGlobalChild, mWindowGlobal,
|
2020-05-08 23:44:12 +03:00
|
|
|
mWindowActors)
|
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
|
|
|
|
|
|
|
} // namespace dom
|
2019-04-03 20:31:00 +03:00
|
|
|
} // namespace mozilla
|