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_WindowGlobalChild_h
|
|
|
|
#define mozilla_dom_WindowGlobalChild_h
|
|
|
|
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "mozilla/dom/PWindowGlobalChild.h"
|
2019-04-12 03:38:57 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2018-10-20 02:02:56 +03:00
|
|
|
#include "nsWrapperCache.h"
|
2019-05-03 21:12:55 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalActor.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
class nsGlobalWindowInner;
|
|
|
|
class nsDocShell;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class BrowsingContext;
|
2021-01-14 14:15:24 +03:00
|
|
|
class FeaturePolicy;
|
2020-01-20 17:58:52 +03:00
|
|
|
class WindowContext;
|
2018-08-30 01:21:25 +03:00
|
|
|
class WindowGlobalParent;
|
2019-01-28 22:02:02 +03:00
|
|
|
class JSWindowActorChild;
|
2020-04-30 19:42:53 +03:00
|
|
|
class JSActorMessageMeta;
|
2019-04-10 01:39:01 +03:00
|
|
|
class BrowserChild;
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Actor for a single nsGlobalWindowInner. This actor is used to communicate
|
|
|
|
* information to the parent process asynchronously.
|
|
|
|
*/
|
2019-05-03 21:12:55 +03:00
|
|
|
class WindowGlobalChild final : public WindowGlobalActor,
|
2020-01-20 17:58:52 +03:00
|
|
|
public nsWrapperCache,
|
2019-05-03 21:12:55 +03:00
|
|
|
public PWindowGlobalChild {
|
2019-02-08 16:02:08 +03:00
|
|
|
friend class PWindowGlobalChild;
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
public:
|
2020-01-20 17:58:52 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WindowGlobalChild)
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
static already_AddRefed<WindowGlobalChild> GetByInnerWindowId(
|
|
|
|
uint64_t aInnerWindowId);
|
|
|
|
|
|
|
|
static already_AddRefed<WindowGlobalChild> GetByInnerWindowId(
|
|
|
|
const GlobalObject& aGlobal, uint64_t aInnerWindowId) {
|
|
|
|
return GetByInnerWindowId(aInnerWindowId);
|
|
|
|
}
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
dom::BrowsingContext* BrowsingContext() override;
|
2020-10-22 22:42:33 +03:00
|
|
|
dom::WindowContext* WindowContext() const { return mWindowContext; }
|
|
|
|
nsGlobalWindowInner* GetWindowGlobal() const { return mWindowGlobal; }
|
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(); }
|
2019-01-28 21:09:13 +03:00
|
|
|
void Destroy();
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
// Check if this actor is managed by PInProcess, as-in the document is loaded
|
|
|
|
// in the chrome process.
|
2020-03-06 22:31:48 +03:00
|
|
|
bool IsInProcess() { return XRE_IsParentProcess(); }
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2019-08-08 19:06:54 +03:00
|
|
|
nsIURI* GetDocumentURI() override { return mDocumentURI; }
|
|
|
|
void SetDocumentURI(nsIURI* aDocumentURI);
|
2020-04-15 21:53:06 +03:00
|
|
|
// See the corresponding comment for `UpdateDocumentPrincipal` in
|
|
|
|
// PWindowGlobal on why and when this is allowed
|
|
|
|
void SetDocumentPrincipal(nsIPrincipal* aNewDocumentPrincipal);
|
2019-08-08 19:06:54 +03:00
|
|
|
|
2019-08-08 19:07:12 +03:00
|
|
|
nsIPrincipal* DocumentPrincipal() { return mDocumentPrincipal; }
|
|
|
|
|
2018-10-20 23:04:00 +03:00
|
|
|
// The Window ID for this WindowGlobal
|
2020-05-08 23:44:12 +03:00
|
|
|
uint64_t InnerWindowId();
|
|
|
|
uint64_t OuterWindowId();
|
2018-10-20 23:04:00 +03:00
|
|
|
|
2019-05-27 21:42:35 +03:00
|
|
|
uint64_t ContentParentId();
|
|
|
|
|
2019-07-15 20:30:26 +03:00
|
|
|
int64_t BeforeUnloadListeners() { return mBeforeUnloadListeners; }
|
|
|
|
void BeforeUnloadAdded();
|
|
|
|
void BeforeUnloadRemoved();
|
|
|
|
|
2018-11-27 23:03:05 +03:00
|
|
|
bool IsCurrentGlobal();
|
2019-05-27 21:42:37 +03:00
|
|
|
|
|
|
|
bool IsProcessRoot();
|
2018-11-27 23:03:05 +03:00
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// 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<WindowGlobalParent> GetParentActor();
|
2018-08-30 01:21:25 +03:00
|
|
|
|
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-04-10 01:39:01 +03:00
|
|
|
already_AddRefed<BrowserChild> GetBrowserChild();
|
2019-01-28 21:09:13 +03:00
|
|
|
|
2019-01-28 22:02:02 +03:00
|
|
|
// Get a JS actor object by name.
|
2020-08-05 00:38:47 +03:00
|
|
|
already_AddRefed<JSWindowActorChild> GetActor(JSContext* aCx,
|
|
|
|
const nsACString& aName,
|
2019-01-28 22:02:02 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// Create and initialize the WindowGlobalChild object.
|
|
|
|
static already_AddRefed<WindowGlobalChild> Create(
|
|
|
|
nsGlobalWindowInner* aWindow);
|
2020-05-08 23:44:12 +03:00
|
|
|
static already_AddRefed<WindowGlobalChild> CreateDisconnected(
|
|
|
|
const WindowGlobalInit& aInit);
|
2019-08-08 19:06:54 +03:00
|
|
|
|
2020-04-06 22:03:02 +03:00
|
|
|
void Init();
|
2019-08-08 19:07:05 +03:00
|
|
|
|
2019-08-08 19:07:12 +03:00
|
|
|
void InitWindowGlobal(nsGlobalWindowInner* aWindow);
|
|
|
|
|
2020-05-08 23:42:06 +03:00
|
|
|
// Called when a new document is loaded in this WindowGlobalChild.
|
|
|
|
void OnNewDocument(Document* aNewDocument);
|
|
|
|
|
2020-10-22 22:42:33 +03:00
|
|
|
// Returns true if this WindowGlobal is same-origin with the given
|
|
|
|
// WindowContext. Out-of-process WindowContexts are supported, and are assumed
|
|
|
|
// to be cross-origin.
|
|
|
|
//
|
|
|
|
// The given WindowContext must be in the same BrowsingContextGroup as this
|
|
|
|
// window global.
|
|
|
|
bool IsSameOriginWith(const dom::WindowContext* aOther) const;
|
|
|
|
|
2020-09-16 19:29:37 +03:00
|
|
|
bool SameOriginWithTop();
|
|
|
|
|
2018-10-20 02:02:56 +03:00
|
|
|
nsISupports* GetParentObject();
|
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
2021-01-14 14:15:24 +03:00
|
|
|
dom::FeaturePolicy* GetContainerFeaturePolicy() const {
|
|
|
|
return mContainerFeaturePolicy;
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
protected:
|
2020-07-08 23:15:59 +03:00
|
|
|
const nsACString& GetRemoteType() override;
|
2020-07-08 17:22:22 +03:00
|
|
|
|
|
|
|
already_AddRefed<JSActor> InitJSActor(JS::HandleObject aMaybeActor,
|
|
|
|
const nsACString& aName,
|
|
|
|
ErrorResult& aRv) override;
|
|
|
|
mozilla::ipc::IProtocol* AsNativeActor() override { return this; }
|
2019-05-03 21:12:55 +03:00
|
|
|
|
2019-02-08 16:02:08 +03:00
|
|
|
// IPC messages
|
2020-10-13 20:43:56 +03:00
|
|
|
mozilla::ipc::IPCResult RecvRawMessage(
|
|
|
|
const JSActorMessageMeta& aMeta, const Maybe<ClonedMessageData>& aData,
|
|
|
|
const Maybe<ClonedMessageData>& aStack);
|
2019-02-08 16:02:08 +03:00
|
|
|
|
2019-10-15 19:19:16 +03:00
|
|
|
mozilla::ipc::IPCResult 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
|
|
|
|
|
|
|
mozilla::ipc::IPCResult 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-09 09:13:03 +03:00
|
|
|
|
2019-07-10 19:45:46 +03:00
|
|
|
mozilla::ipc::IPCResult RecvDrawSnapshot(const Maybe<IntRect>& aRect,
|
|
|
|
const float& aScale,
|
|
|
|
const nscolor& aBackgroundColor,
|
2019-08-14 13:23:39 +03:00
|
|
|
const uint32_t& aFlags,
|
2019-07-10 19:45:46 +03:00
|
|
|
DrawSnapshotResolver&& aResolve);
|
|
|
|
|
2020-04-11 01:14:51 +03:00
|
|
|
mozilla::ipc::IPCResult RecvDispatchSecurityPolicyViolation(
|
|
|
|
const nsString& aViolationEventJSON);
|
|
|
|
|
2019-06-21 08:58:40 +03:00
|
|
|
mozilla::ipc::IPCResult RecvGetSecurityInfo(
|
|
|
|
GetSecurityInfoResolver&& aResolve);
|
|
|
|
|
2020-06-03 09:12:06 +03:00
|
|
|
mozilla::ipc::IPCResult RecvSaveStorageAccessPermissionGranted();
|
2020-04-29 17:48:13 +03:00
|
|
|
|
2020-06-25 07:32:28 +03:00
|
|
|
mozilla::ipc::IPCResult RecvAddBlockedFrameNodeByClassifier(
|
|
|
|
const MaybeDiscardedBrowsingContext& aNode);
|
|
|
|
|
2020-10-29 01:48:57 +03:00
|
|
|
mozilla::ipc::IPCResult RecvResetScalingZoom();
|
|
|
|
|
2021-01-14 14:15:24 +03:00
|
|
|
mozilla::ipc::IPCResult RecvSetContainerFeaturePolicy(
|
|
|
|
dom::FeaturePolicy* aContainerFeaturePolicy);
|
|
|
|
|
2021-03-23 21:01:21 +03:00
|
|
|
mozilla::ipc::IPCResult RecvRestoreTabContent(
|
|
|
|
dom::SessionStoreRestoreData* aData,
|
|
|
|
RestoreTabContentResolver&& aResolve);
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
|
|
|
|
|
|
|
private:
|
2020-05-08 23:44:12 +03:00
|
|
|
WindowGlobalChild(dom::WindowContext* aWindowContext,
|
|
|
|
nsIPrincipal* aPrincipal, nsIURI* aURI);
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
~WindowGlobalChild();
|
|
|
|
|
|
|
|
RefPtr<nsGlobalWindowInner> mWindowGlobal;
|
2020-01-20 17:58:52 +03:00
|
|
|
RefPtr<dom::WindowContext> mWindowContext;
|
2019-08-08 19:06:54 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
|
2021-01-14 14:15:24 +03:00
|
|
|
RefPtr<dom::FeaturePolicy> mContainerFeaturePolicy;
|
2019-08-08 19:06:54 +03:00
|
|
|
nsCOMPtr<nsIURI> mDocumentURI;
|
2020-05-08 23:44:12 +03:00
|
|
|
int64_t mBeforeUnloadListeners = 0;
|
2018-08-30 01:21:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // !defined(mozilla_dom_WindowGlobalChild_h)
|