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/WindowGlobalParent.h"
|
2019-04-03 20:30:27 +03:00
|
|
|
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
#include "mozilla/ipc/InProcessParent.h"
|
2019-04-17 03:53:32 +03:00
|
|
|
#include "mozilla/dom/BrowserBridgeParent.h"
|
2019-01-29 20:32:28 +03:00
|
|
|
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
2019-04-03 20:30:27 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2019-05-08 22:34:47 +03:00
|
|
|
#include "mozilla/dom/BrowserHost.h"
|
2019-04-10 00:38:15 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2018-10-20 02:02:56 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalActorsBinding.h"
|
2019-04-03 20:30:27 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalChild.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
#include "mozilla/dom/ChromeUtils.h"
|
2019-04-03 20:30:27 +03:00
|
|
|
#include "mozilla/dom/ipc/IdType.h"
|
|
|
|
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "mozilla/ServoCSSParser.h"
|
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
#include "mozJSComponentLoader.h"
|
|
|
|
#include "nsContentUtils.h"
|
2019-04-03 20:30:27 +03:00
|
|
|
#include "nsDocShell.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
#include "nsError.h"
|
2019-04-03 20:31:00 +03:00
|
|
|
#include "nsFrameLoader.h"
|
2019-04-03 20:30:27 +03:00
|
|
|
#include "nsFrameLoaderOwner.h"
|
|
|
|
#include "nsGlobalWindowInner.h"
|
2019-02-16 01:20:53 +03:00
|
|
|
#include "nsQueryObject.h"
|
2019-04-10 01:38:11 +03:00
|
|
|
#include "nsFrameLoaderOwner.h"
|
2019-06-21 08:58:40 +03:00
|
|
|
#include "nsSerializationHelper.h"
|
|
|
|
#include "nsITransportSecurityInfo.h"
|
2019-10-09 13:57:11 +03:00
|
|
|
#include "nsISharePicker.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/DOMException.h"
|
|
|
|
#include "mozilla/dom/DOMExceptionBinding.h"
|
2019-01-28 22:02:02 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/JSWindowActorBinding.h"
|
|
|
|
#include "mozilla/dom/JSWindowActorParent.h"
|
|
|
|
#include "mozilla/dom/JSWindowActorService.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
2019-04-03 20:30:27 +03:00
|
|
|
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, WindowGlobalParent> WGPByIdMap;
|
|
|
|
static StaticAutoPtr<WGPByIdMap> gWindowGlobalParentsById;
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
WindowGlobalParent::WindowGlobalParent(const WindowGlobalInit& aInit,
|
|
|
|
bool aInProcess)
|
2018-10-20 01:00:59 +03:00
|
|
|
: mDocumentPrincipal(aInit.principal()),
|
2019-04-09 14:58:35 +03:00
|
|
|
mDocumentURI(aInit.documentURI()),
|
2018-10-20 23:04:00 +03:00
|
|
|
mInnerWindowId(aInit.innerWindowId()),
|
|
|
|
mOuterWindowId(aInit.outerWindowId()),
|
2018-08-30 01:21:25 +03:00
|
|
|
mInProcess(aInProcess),
|
2019-07-15 20:30:26 +03:00
|
|
|
mIsInitialDocument(false),
|
|
|
|
mHasBeforeUnload(false) {
|
2018-08-30 01:21:25 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(), "Parent process only");
|
|
|
|
MOZ_RELEASE_ASSERT(mDocumentPrincipal, "Must have a valid principal");
|
2018-10-20 01:00:59 +03:00
|
|
|
|
|
|
|
// NOTE: mBrowsingContext initialized in Init()
|
2019-02-14 00:02:55 +03:00
|
|
|
MOZ_RELEASE_ASSERT(aInit.browsingContext(),
|
2018-10-20 01:00:59 +03:00
|
|
|
"Must be made in BrowsingContext");
|
2018-08-30 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-20 01:00:59 +03:00
|
|
|
void WindowGlobalParent::Init(const WindowGlobalInit& aInit) {
|
2018-08-30 01:21:25 +03:00
|
|
|
MOZ_ASSERT(Manager(), "Should have a manager!");
|
2019-07-23 05:13:32 +03:00
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
// Register this WindowGlobal in the gWindowGlobalParentsById map.
|
|
|
|
if (!gWindowGlobalParentsById) {
|
|
|
|
gWindowGlobalParentsById = new WGPByIdMap();
|
|
|
|
ClearOnShutdown(&gWindowGlobalParentsById);
|
|
|
|
}
|
|
|
|
auto entry = gWindowGlobalParentsById->LookupForAdd(mInnerWindowId);
|
|
|
|
MOZ_RELEASE_ASSERT(!entry, "Duplicate WindowGlobalParent entry for ID!");
|
|
|
|
entry.OrInsert([&] { return this; });
|
|
|
|
|
2018-10-20 01:00:59 +03:00
|
|
|
// Determine which content process the window global is coming from.
|
2019-05-27 21:42:35 +03:00
|
|
|
dom::ContentParentId processId(0);
|
2018-10-20 01:00:59 +03:00
|
|
|
if (!mInProcess) {
|
2019-08-08 19:07:09 +03:00
|
|
|
ContentParent* cp = static_cast<ContentParent*>(Manager()->Manager());
|
|
|
|
processId = cp->ChildID();
|
|
|
|
|
|
|
|
// Ensure the content process has permissions for this principal.
|
|
|
|
cp->TransmitPermissionsForPrincipal(mDocumentPrincipal);
|
2018-10-20 01:00:59 +03:00
|
|
|
}
|
|
|
|
|
2019-02-14 00:02:55 +03:00
|
|
|
mBrowsingContext = CanonicalBrowsingContext::Cast(aInit.browsingContext());
|
2018-10-20 01:00:59 +03:00
|
|
|
MOZ_ASSERT(mBrowsingContext);
|
|
|
|
|
2019-07-30 17:45:47 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
!mBrowsingContext->GetParent() ||
|
2019-09-26 19:16:32 +03:00
|
|
|
mBrowsingContext->GetEmbedderInnerWindowId(),
|
2019-07-30 17:45:47 +03:00
|
|
|
"When creating a non-root WindowGlobalParent, the WindowGlobalParent "
|
|
|
|
"for our embedder should've already been created.");
|
|
|
|
|
2018-10-20 01:00:59 +03:00
|
|
|
// Attach ourself to the browsing context.
|
|
|
|
mBrowsingContext->RegisterWindowGlobal(this);
|
|
|
|
|
2019-04-17 03:51:36 +03:00
|
|
|
// If there is no current window global, assume we're about to become it
|
|
|
|
// optimistically.
|
|
|
|
if (!mBrowsingContext->GetCurrentWindowGlobal()) {
|
|
|
|
mBrowsingContext->SetCurrentWindowGlobal(this);
|
|
|
|
}
|
|
|
|
|
2019-08-08 19:07:05 +03:00
|
|
|
// Ensure we have a document URI
|
|
|
|
if (!mDocumentURI) {
|
|
|
|
NS_NewURI(getter_AddRefs(mDocumentURI), "about:blank");
|
|
|
|
}
|
|
|
|
|
2019-01-09 01:54:42 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(this, "window-global-created", nullptr);
|
|
|
|
}
|
2018-08-30 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:05:29 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<WindowGlobalParent> WindowGlobalParent::GetByInnerWindowId(
|
|
|
|
uint64_t aInnerWindowId) {
|
2018-10-20 23:04:00 +03:00
|
|
|
if (!gWindowGlobalParentsById) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return gWindowGlobalParentsById->Get(aInnerWindowId);
|
|
|
|
}
|
|
|
|
|
2018-10-20 02:02:56 +03:00
|
|
|
already_AddRefed<WindowGlobalChild> WindowGlobalParent::GetChildActor() {
|
2019-08-08 19:06:52 +03:00
|
|
|
if (!CanSend()) {
|
2018-08-30 01:21:25 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
IProtocol* otherSide = InProcessParent::ChildActorFor(this);
|
|
|
|
return do_AddRef(static_cast<WindowGlobalChild*>(otherSide));
|
|
|
|
}
|
|
|
|
|
2019-05-08 22:34:47 +03:00
|
|
|
already_AddRefed<BrowserParent> WindowGlobalParent::GetBrowserParent() {
|
2019-08-08 19:06:52 +03:00
|
|
|
if (IsInProcess() || !CanSend()) {
|
2019-01-28 21:09:13 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-04-10 00:38:15 +03:00
|
|
|
return do_AddRef(static_cast<BrowserParent*>(Manager()));
|
2019-01-28 21:09:13 +03:00
|
|
|
}
|
|
|
|
|
2019-08-08 19:07:14 +03:00
|
|
|
already_AddRefed<nsFrameLoader> WindowGlobalParent::GetRootFrameLoader() {
|
|
|
|
dom::BrowsingContext* top = BrowsingContext()->Top();
|
|
|
|
|
|
|
|
RefPtr<nsFrameLoaderOwner> frameLoaderOwner =
|
|
|
|
do_QueryObject(top->GetEmbedderElement());
|
|
|
|
if (frameLoaderOwner) {
|
|
|
|
return frameLoaderOwner->GetFrameLoader();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:42:35 +03:00
|
|
|
uint64_t WindowGlobalParent::ContentParentId() {
|
|
|
|
RefPtr<BrowserParent> browserParent = GetBrowserParent();
|
|
|
|
return browserParent ? browserParent->Manager()->ChildID() : 0;
|
|
|
|
}
|
|
|
|
|
2019-06-14 18:42:39 +03:00
|
|
|
int32_t WindowGlobalParent::OsPid() {
|
|
|
|
RefPtr<BrowserParent> browserParent = GetBrowserParent();
|
|
|
|
return browserParent ? browserParent->Manager()->Pid() : -1;
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:42:37 +03:00
|
|
|
// A WindowGlobalPaernt is the root in its process if it has no parent, or its
|
|
|
|
// embedder is in a different process.
|
|
|
|
bool WindowGlobalParent::IsProcessRoot() {
|
|
|
|
if (!BrowsingContext()->GetParent()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-26 19:16:32 +03:00
|
|
|
RefPtr<WindowGlobalParent> embedder =
|
|
|
|
BrowsingContext()->GetEmbedderWindowGlobal();
|
2019-07-22 11:43:14 +03:00
|
|
|
if (NS_WARN_IF(!embedder)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-27 21:42:37 +03:00
|
|
|
return ContentParentId() != embedder->ContentParentId();
|
|
|
|
}
|
|
|
|
|
2019-08-02 04:00:32 +03:00
|
|
|
mozilla::ipc::IPCResult WindowGlobalParent::RecvLoadURI(
|
2019-10-11 05:27:05 +03:00
|
|
|
dom::BrowsingContext* aTargetBC, nsDocShellLoadState* aLoadState,
|
|
|
|
bool aSetNavigating) {
|
2019-08-02 04:00:32 +03:00
|
|
|
if (!aTargetBC || aTargetBC->IsDiscarded()) {
|
|
|
|
MOZ_LOG(
|
|
|
|
BrowsingContext::GetLog(), LogLevel::Debug,
|
|
|
|
("ParentIPC: Trying to send a message with dead or detached context"));
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: For cross-process loads, we should double check CanAccess() for the
|
|
|
|
// source browsing context in the parent process.
|
|
|
|
|
|
|
|
if (aTargetBC->Group() != BrowsingContext()->Group()) {
|
|
|
|
return IPC_FAIL(this, "Illegal cross-group BrowsingContext load");
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We should really initiate the load in the parent before bouncing
|
|
|
|
// back down to the child.
|
|
|
|
|
|
|
|
WindowGlobalParent* wgp = aTargetBC->Canonical()->GetCurrentWindowGlobal();
|
|
|
|
if (!wgp) {
|
2019-09-26 19:16:32 +03:00
|
|
|
MOZ_LOG(BrowsingContext::GetLog(), LogLevel::Debug,
|
|
|
|
("ParentIPC: Target BrowsingContext has no WindowGlobalParent"));
|
2019-08-02 04:00:32 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-10-11 05:27:05 +03:00
|
|
|
Unused << wgp->SendLoadURIInChild(aLoadState, aSetNavigating);
|
2019-08-02 04:00:32 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
IPCResult WindowGlobalParent::RecvUpdateDocumentURI(nsIURI* aURI) {
|
|
|
|
// XXX(nika): Assert that the URI change was one which makes sense (either
|
|
|
|
// about:blank -> a real URI, or a legal push/popstate URI change?)
|
|
|
|
mDocumentURI = aURI;
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-07-15 20:30:26 +03:00
|
|
|
IPCResult WindowGlobalParent::RecvSetHasBeforeUnload(bool aHasBeforeUnload) {
|
|
|
|
mHasBeforeUnload = aHasBeforeUnload;
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2018-11-27 23:03:05 +03:00
|
|
|
IPCResult WindowGlobalParent::RecvBecomeCurrentWindowGlobal() {
|
|
|
|
mBrowsingContext->SetCurrentWindowGlobal(this);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-01-28 21:09:13 +03:00
|
|
|
IPCResult WindowGlobalParent::RecvDestroy() {
|
2019-08-08 19:06:52 +03:00
|
|
|
if (CanSend()) {
|
2019-05-08 22:34:47 +03:00
|
|
|
RefPtr<BrowserParent> browserParent = GetBrowserParent();
|
2019-04-10 00:38:15 +03:00
|
|
|
if (!browserParent || !browserParent->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<JSWindowActorParent>> 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
|
|
|
Unused << Send__delete__(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-04-18 22:37:15 +03:00
|
|
|
IPCResult WindowGlobalParent::RecvRawMessage(
|
|
|
|
const JSWindowActorMessageMeta& aMeta, const ClonedMessageData& aData) {
|
2019-02-08 16:02:08 +03:00
|
|
|
StructuredCloneData data;
|
|
|
|
data.BorrowFromClonedMessageDataForParent(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();
|
2018-11-27 23:03:05 +03:00
|
|
|
}
|
|
|
|
|
2019-04-18 22:37:15 +03:00
|
|
|
void WindowGlobalParent::ReceiveRawMessage(
|
|
|
|
const JSWindowActorMessageMeta& aMeta, StructuredCloneData&& aData) {
|
|
|
|
RefPtr<JSWindowActorParent> actor =
|
|
|
|
GetActor(aMeta.actorName(), IgnoreErrors());
|
|
|
|
if (actor) {
|
|
|
|
actor->ReceiveRawMessage(aMeta, std::move(aData));
|
2019-02-08 16:02:08 +03:00
|
|
|
}
|
2018-08-30 01:21:25 +03:00
|
|
|
}
|
|
|
|
|
2019-05-03 21:12:55 +03:00
|
|
|
const nsAString& WindowGlobalParent::GetRemoteType() {
|
2019-05-08 22:34:47 +03:00
|
|
|
if (RefPtr<BrowserParent> browserParent = GetBrowserParent()) {
|
2019-05-03 21:12:55 +03:00
|
|
|
return browserParent->Manager()->GetRemoteType();
|
|
|
|
}
|
|
|
|
|
|
|
|
return VoidString();
|
|
|
|
}
|
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
already_AddRefed<JSWindowActorParent> WindowGlobalParent::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 JSWindowActorParent object.
|
|
|
|
RefPtr<JSWindowActorParent> actor;
|
|
|
|
if (NS_FAILED(UNWRAP_OBJECT(JSWindowActorParent, &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();
|
|
|
|
}
|
|
|
|
|
2019-02-08 16:02:08 +03:00
|
|
|
bool WindowGlobalParent::IsCurrentGlobal() {
|
2019-08-08 19:06:52 +03:00
|
|
|
return CanSend() && mBrowsingContext->GetCurrentWindowGlobal() == this;
|
2019-02-08 16:02:08 +03:00
|
|
|
}
|
|
|
|
|
2019-10-09 13:57:11 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ShareHandler final : public PromiseNativeHandler {
|
|
|
|
public:
|
|
|
|
explicit ShareHandler(
|
|
|
|
mozilla::dom::WindowGlobalParent::ShareResolver&& aResolver)
|
|
|
|
: mResolver(std::move(aResolver)) {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void ResolvedCallback(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue) override {
|
|
|
|
mResolver(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void RejectedCallback(JSContext* aCx,
|
|
|
|
JS::Handle<JS::Value> aValue) override {
|
|
|
|
if (NS_WARN_IF(!aValue.isObject())) {
|
|
|
|
mResolver(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsresult is stored as Exception internally in Promise
|
|
|
|
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
|
|
|
|
RefPtr<DOMException> unwrapped;
|
|
|
|
nsresult rv = UNWRAP_OBJECT(DOMException, &obj, unwrapped);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
mResolver(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mResolver(unwrapped->GetResult());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~ShareHandler() = default;
|
|
|
|
|
|
|
|
mozilla::dom::WindowGlobalParent::ShareResolver mResolver;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS0(ShareHandler)
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult WindowGlobalParent::RecvShare(
|
|
|
|
IPCWebShareData&& aData, WindowGlobalParent::ShareResolver&& aResolver) {
|
|
|
|
// Widget Layer handoff...
|
|
|
|
nsCOMPtr<nsISharePicker> sharePicker =
|
|
|
|
do_GetService("@mozilla.org/sharepicker;1");
|
|
|
|
if (!sharePicker) {
|
|
|
|
aResolver(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-10-15 03:52:09 +03:00
|
|
|
// Initialize the ShareWidget
|
|
|
|
RefPtr<BrowserParent> parent = GetBrowserParent();
|
|
|
|
if (NS_WARN_IF(!parent)) {
|
|
|
|
aResolver(NS_ERROR_FAILURE);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
nsCOMPtr<mozIDOMWindowProxy> openerWindow = parent->GetParentWindowOuter();
|
|
|
|
if (!openerWindow) {
|
|
|
|
aResolver(NS_ERROR_FAILURE);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
sharePicker->Init(openerWindow);
|
|
|
|
|
2019-10-09 13:57:11 +03:00
|
|
|
// And finally share the data...
|
|
|
|
RefPtr<Promise> promise;
|
|
|
|
nsresult rv = sharePicker->Share(aData.title(), aData.text(), aData.url(),
|
|
|
|
getter_AddRefs(promise));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aResolver(rv);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handler finally awaits response...
|
|
|
|
RefPtr<ShareHandler> handler = new ShareHandler(std::move(aResolver));
|
|
|
|
promise->AppendNativeHandler(handler);
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
already_AddRefed<mozilla::dom::Promise> WindowGlobalParent::DrawSnapshot(
|
|
|
|
const DOMRect* aRect, double aScale, const nsAString& aBackgroundColor,
|
|
|
|
mozilla::ErrorResult& aRv) {
|
|
|
|
nsIGlobalObject* global = GetParentObject();
|
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscolor color;
|
|
|
|
if (NS_WARN_IF(!ServoCSSParser::ComputeColor(nullptr, NS_RGB(0, 0, 0),
|
|
|
|
aBackgroundColor, &color,
|
|
|
|
nullptr, nullptr))) {
|
|
|
|
aRv = NS_ERROR_FAILURE;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gfx::CrossProcessPaint::Start(this, aRect, (float)aScale, color,
|
2019-08-14 13:23:39 +03:00
|
|
|
gfx::CrossProcessPaintFlags::None,
|
2019-07-10 19:45:46 +03:00
|
|
|
promise)) {
|
|
|
|
aRv = NS_ERROR_FAILURE;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowGlobalParent::DrawSnapshotInternal(gfx::CrossProcessPaint* aPaint,
|
|
|
|
const Maybe<IntRect>& aRect,
|
|
|
|
float aScale,
|
2019-08-14 13:23:39 +03:00
|
|
|
nscolor aBackgroundColor,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
auto promise = SendDrawSnapshot(aRect, aScale, aBackgroundColor, aFlags);
|
2019-07-10 19:45:46 +03:00
|
|
|
|
|
|
|
RefPtr<gfx::CrossProcessPaint> paint(aPaint);
|
|
|
|
RefPtr<WindowGlobalParent> wgp(this);
|
|
|
|
promise->Then(
|
|
|
|
GetMainThreadSerialEventTarget(), __func__,
|
|
|
|
[paint, wgp](PaintFragment&& aFragment) {
|
|
|
|
paint->ReceiveFragment(wgp, std::move(aFragment));
|
|
|
|
},
|
|
|
|
[paint, wgp](ResponseRejectReason&& aReason) {
|
|
|
|
paint->LostFragment(wgp);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-21 08:58:40 +03:00
|
|
|
already_AddRefed<Promise> WindowGlobalParent::GetSecurityInfo(
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
RefPtr<BrowserParent> browserParent = GetBrowserParent();
|
|
|
|
if (NS_WARN_IF(!browserParent)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
nsIGlobalObject* global = GetParentObject();
|
2019-06-21 08:58:40 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendGetSecurityInfo(
|
|
|
|
[promise](Maybe<nsCString>&& aResult) {
|
|
|
|
if (aResult) {
|
|
|
|
nsCOMPtr<nsISupports> infoObj;
|
|
|
|
nsresult rv =
|
|
|
|
NS_DeserializeObject(aResult.value(), getter_AddRefs(infoObj));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
promise->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsITransportSecurityInfo> info = do_QueryInterface(infoObj);
|
|
|
|
if (!info) {
|
|
|
|
promise->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
promise->MaybeResolve(info);
|
|
|
|
} else {
|
|
|
|
promise->MaybeResolveWithUndefined();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[promise](ResponseRejectReason&& aReason) {
|
|
|
|
promise->MaybeReject(NS_ERROR_FAILURE);
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2019-02-08 16:02:08 +03:00
|
|
|
void WindowGlobalParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|
|
|
gWindowGlobalParentsById->Remove(mInnerWindowId);
|
|
|
|
mBrowsingContext->UnregisterWindowGlobal(this);
|
|
|
|
|
2019-04-18 22:37:15 +03:00
|
|
|
// Destroy our JSWindowActors, and reject any pending queries.
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, JSWindowActorParent> 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();
|
2019-04-18 22:37:15 +03:00
|
|
|
|
2019-02-08 16:02:08 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(this, "window-global-destroyed", nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
WindowGlobalParent::~WindowGlobalParent() {
|
2018-10-20 23:04:00 +03:00
|
|
|
MOZ_ASSERT(!gWindowGlobalParentsById ||
|
|
|
|
!gWindowGlobalParentsById->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* WindowGlobalParent::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return WindowGlobalParent_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
nsIGlobalObject* WindowGlobalParent::GetParentObject() {
|
2018-10-20 02:02:56 +03:00
|
|
|
return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
|
|
|
|
}
|
|
|
|
|
2019-05-03 21:12:55 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(WindowGlobalParent, WindowGlobalActor,
|
2019-08-08 19:07:14 +03:00
|
|
|
mBrowsingContext, mWindowActors)
|
2019-05-03 21:12:55 +03:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(WindowGlobalParent,
|
|
|
|
WindowGlobalActor)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2019-05-03 18:55:51 +03:00
|
|
|
|
2019-05-03 21:12:55 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WindowGlobalParent)
|
|
|
|
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(WindowGlobalParent, WindowGlobalActor)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(WindowGlobalParent, WindowGlobalActor)
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|