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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_WindowGlobalParent_h
|
|
|
|
#define mozilla_dom_WindowGlobalParent_h
|
|
|
|
|
|
|
|
#include "mozilla/RefPtr.h"
|
2019-07-10 19:45:46 +03:00
|
|
|
#include "mozilla/dom/DOMRect.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
#include "mozilla/dom/PWindowGlobalParent.h"
|
2019-04-10 00:38:15 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2019-04-12 03:38:57 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2018-10-20 02:02:56 +03:00
|
|
|
#include "nsWrapperCache.h"
|
2019-01-09 01:54:42 +03:00
|
|
|
#include "nsISupports.h"
|
2019-05-03 21:12:55 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalActor.h"
|
|
|
|
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
class nsIPrincipal;
|
|
|
|
class nsIURI;
|
|
|
|
class nsFrameLoader;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2019-07-10 19:45:46 +03:00
|
|
|
|
|
|
|
namespace gfx {
|
|
|
|
class CrossProcessPaint;
|
|
|
|
} // namespace gfx
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class WindowGlobalChild;
|
2019-01-28 22:02:02 +03:00
|
|
|
class JSWindowActorParent;
|
2019-04-18 22:37:15 +03:00
|
|
|
class JSWindowActorMessageMeta;
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A handle in the parent process to a specific nsGlobalWindowInner object.
|
|
|
|
*/
|
2019-05-03 21:12:55 +03:00
|
|
|
class WindowGlobalParent final : public WindowGlobalActor,
|
2018-10-20 02:02:56 +03:00
|
|
|
public PWindowGlobalParent {
|
2019-07-10 19:45:46 +03:00
|
|
|
friend class gfx::CrossProcessPaint;
|
2019-02-06 18:57:37 +03:00
|
|
|
friend class PWindowGlobalParent;
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
public:
|
2019-05-03 21:12:55 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(WindowGlobalParent,
|
|
|
|
WindowGlobalActor)
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
static already_AddRefed<WindowGlobalParent> GetByInnerWindowId(
|
|
|
|
uint64_t aInnerWindowId);
|
|
|
|
|
|
|
|
static already_AddRefed<WindowGlobalParent> GetByInnerWindowId(
|
|
|
|
const GlobalObject& aGlobal, uint64_t aInnerWindowId) {
|
|
|
|
return GetByInnerWindowId(aInnerWindowId);
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// Has this actor been shut down
|
2019-08-08 19:06:52 +03:00
|
|
|
bool IsClosed() { return !CanSend(); }
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
// Check if this actor is managed by PInProcess, as-in the document is loaded
|
|
|
|
// in-process.
|
|
|
|
bool IsInProcess() { return mInProcess; }
|
|
|
|
|
|
|
|
// Get the other side of this actor if it is an in-process actor. Returns
|
|
|
|
// |nullptr| if the actor has been torn down, or is not in-process.
|
2018-10-20 02:02:56 +03:00
|
|
|
already_AddRefed<WindowGlobalChild> GetChildActor();
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
// Get a JS actor object by name.
|
|
|
|
already_AddRefed<JSWindowActorParent> GetActor(const nsAString& aName,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2019-01-28 21:09:13 +03:00
|
|
|
// Get this actor's manager if it is not an in-process actor. Returns
|
|
|
|
// |nullptr| if the actor has been torn down, or is in-process.
|
2019-05-08 22:34:47 +03:00
|
|
|
already_AddRefed<BrowserParent> GetBrowserParent();
|
2019-01-28 21:09:13 +03:00
|
|
|
|
2019-04-18 22:37:15 +03:00
|
|
|
void ReceiveRawMessage(const JSWindowActorMessageMeta& aMeta,
|
2019-12-07 21:59:23 +03:00
|
|
|
ipc::StructuredCloneData&& aData,
|
|
|
|
ipc::StructuredCloneData&& aStack);
|
2019-02-08 16:02:08 +03:00
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// The principal of this WindowGlobal. This value will not change over the
|
|
|
|
// lifetime of the WindowGlobal object, even to reflect changes in
|
|
|
|
// |document.domain|.
|
|
|
|
nsIPrincipal* DocumentPrincipal() { return mDocumentPrincipal; }
|
|
|
|
|
|
|
|
// The BrowsingContext which this WindowGlobal has been loaded into.
|
2019-05-03 21:12:55 +03:00
|
|
|
CanonicalBrowsingContext* BrowsingContext() override {
|
|
|
|
return mBrowsingContext;
|
|
|
|
}
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
// Get the root nsFrameLoader object for the tree of BrowsingContext nodes
|
|
|
|
// which this WindowGlobal is a part of. This will be the nsFrameLoader
|
2019-04-10 00:38:15 +03:00
|
|
|
// holding the BrowserParent for remote tabs, and the root content frameloader
|
|
|
|
// for non-remote tabs.
|
2019-08-08 19:07:14 +03:00
|
|
|
already_AddRefed<nsFrameLoader> GetRootFrameLoader();
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
// The current URI which loaded in the document.
|
2019-05-03 21:12:55 +03:00
|
|
|
nsIURI* GetDocumentURI() override { return mDocumentURI; }
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
// Window IDs for inner/outer windows.
|
|
|
|
uint64_t OuterWindowId() { return mOuterWindowId; }
|
|
|
|
uint64_t InnerWindowId() { return mInnerWindowId; }
|
|
|
|
|
2019-05-27 21:42:35 +03:00
|
|
|
uint64_t ContentParentId();
|
|
|
|
|
2019-06-14 18:42:39 +03:00
|
|
|
int32_t OsPid();
|
|
|
|
|
2018-11-27 23:03:05 +03:00
|
|
|
bool IsCurrentGlobal();
|
|
|
|
|
2019-05-27 21:42:37 +03:00
|
|
|
bool IsProcessRoot();
|
|
|
|
|
2019-06-06 17:57:32 +03:00
|
|
|
bool IsInitialDocument() { return mIsInitialDocument; }
|
|
|
|
|
2019-07-15 20:30:26 +03:00
|
|
|
bool HasBeforeUnload() { return mHasBeforeUnload; }
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
already_AddRefed<mozilla::dom::Promise> DrawSnapshot(
|
|
|
|
const DOMRect* aRect, double aScale, const nsAString& aBackgroundColor,
|
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
2019-06-21 08:58:40 +03:00
|
|
|
already_AddRefed<Promise> GetSecurityInfo(ErrorResult& aRv);
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// Create a WindowGlobalParent from over IPC. This method should not be called
|
|
|
|
// from outside of the IPC constructors.
|
|
|
|
WindowGlobalParent(const WindowGlobalInit& aInit, bool aInProcess);
|
|
|
|
|
|
|
|
// Initialize the mFrameLoader fields for a created WindowGlobalParent. Must
|
|
|
|
// be called after setting the Manager actor.
|
2018-10-20 01:00:59 +03:00
|
|
|
void Init(const WindowGlobalInit& aInit);
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
nsIGlobalObject* GetParentObject();
|
2018-10-20 02:02:56 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
protected:
|
2019-05-03 21:12:55 +03:00
|
|
|
const nsAString& GetRemoteType() override;
|
|
|
|
JSWindowActor::Type GetSide() override { return JSWindowActor::Type::Parent; }
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// IPC messages
|
2019-08-02 04:00:32 +03:00
|
|
|
mozilla::ipc::IPCResult RecvLoadURI(dom::BrowsingContext* aTargetBC,
|
2019-10-11 05:27:05 +03:00
|
|
|
nsDocShellLoadState* aLoadState,
|
|
|
|
bool aSetNavigating);
|
2019-11-13 00:52:18 +03:00
|
|
|
mozilla::ipc::IPCResult RecvInternalLoad(dom::BrowsingContext* aTargetBC,
|
|
|
|
nsDocShellLoadState* aLoadState);
|
2019-02-06 18:58:43 +03:00
|
|
|
mozilla::ipc::IPCResult RecvUpdateDocumentURI(nsIURI* aURI);
|
2019-06-06 17:57:32 +03:00
|
|
|
mozilla::ipc::IPCResult RecvSetIsInitialDocument(bool aIsInitialDocument) {
|
|
|
|
mIsInitialDocument = aIsInitialDocument;
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2019-07-15 20:30:26 +03:00
|
|
|
mozilla::ipc::IPCResult RecvSetHasBeforeUnload(bool aHasBeforeUnload);
|
2019-02-06 18:58:43 +03:00
|
|
|
mozilla::ipc::IPCResult RecvBecomeCurrentWindowGlobal();
|
|
|
|
mozilla::ipc::IPCResult RecvDestroy();
|
2019-04-18 22:37:15 +03:00
|
|
|
mozilla::ipc::IPCResult RecvRawMessage(const JSWindowActorMessageMeta& aMeta,
|
2019-12-07 21:59:23 +03:00
|
|
|
const ClonedMessageData& aData,
|
|
|
|
const ClonedMessageData& aStack);
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
void ActorDestroy(ActorDestroyReason aWhy) override;
|
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
void DrawSnapshotInternal(gfx::CrossProcessPaint* aPaint,
|
|
|
|
const Maybe<IntRect>& aRect, float aScale,
|
2019-08-14 13:23:39 +03:00
|
|
|
nscolor aBackgroundColor, uint32_t aFlags);
|
2019-07-10 19:45:46 +03:00
|
|
|
|
2019-10-09 13:57:11 +03:00
|
|
|
// WebShare API - try to share
|
|
|
|
mozilla::ipc::IPCResult RecvShare(IPCWebShareData&& aData,
|
|
|
|
ShareResolver&& aResolver);
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
private:
|
|
|
|
~WindowGlobalParent();
|
|
|
|
|
|
|
|
// NOTE: This document principal doesn't reflect possible |document.domain|
|
|
|
|
// mutations which may have been made in the actual document.
|
|
|
|
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
|
|
|
|
nsCOMPtr<nsIURI> mDocumentURI;
|
2019-01-29 20:32:28 +03:00
|
|
|
RefPtr<CanonicalBrowsingContext> mBrowsingContext;
|
2019-01-28 22:02:02 +03:00
|
|
|
nsRefPtrHashtable<nsStringHashKey, JSWindowActorParent> mWindowActors;
|
2018-10-20 23:04:00 +03:00
|
|
|
uint64_t mInnerWindowId;
|
|
|
|
uint64_t mOuterWindowId;
|
2018-08-30 01:21:25 +03:00
|
|
|
bool mInProcess;
|
2019-06-06 17:57:32 +03:00
|
|
|
bool mIsInitialDocument;
|
2019-07-15 20:30:26 +03:00
|
|
|
|
|
|
|
// True if this window has a "beforeunload" event listener.
|
|
|
|
bool mHasBeforeUnload;
|
2018-08-30 01:21:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // !defined(mozilla_dom_WindowGlobalParent_h)
|