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
|
|
|
|
|
2020-03-10 02:36:39 +03:00
|
|
|
#include "mozilla/ContentBlockingLog.h"
|
2020-03-10 02:36:37 +03:00
|
|
|
#include "mozilla/ContentBlockingNotifier.h"
|
2020-05-22 03:34:17 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2018-08-30 01:21:25 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2020-03-10 23:25:57 +03:00
|
|
|
#include "mozilla/dom/ClientInfo.h"
|
|
|
|
#include "mozilla/dom/ClientIPCTypes.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"
|
2020-01-20 17:58:52 +03:00
|
|
|
#include "mozilla/dom/WindowContext.h"
|
2020-05-22 03:34:17 +03:00
|
|
|
#include "nsDataHashtable.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"
|
2020-03-20 12:11:32 +03:00
|
|
|
#include "nsIContentParent.h"
|
2019-05-03 21:12:55 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalActor.h"
|
|
|
|
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
2020-04-15 21:53:06 +03:00
|
|
|
#include "mozilla/net/CookieJarSettings.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;
|
2020-04-30 19:42:53 +03:00
|
|
|
class JSActorMessageMeta;
|
2018-08-30 01:21:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A handle in the parent process to a specific nsGlobalWindowInner object.
|
|
|
|
*/
|
2020-01-20 17:58:52 +03:00
|
|
|
class WindowGlobalParent final : public WindowContext,
|
|
|
|
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,
|
2020-01-20 17:58:52 +03:00
|
|
|
WindowContext)
|
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);
|
|
|
|
}
|
|
|
|
|
2020-05-04 17:26:34 +03:00
|
|
|
// The same as the corresponding methods on `WindowContext`, except that the
|
|
|
|
// return types are already cast to their parent-process type variants, such
|
|
|
|
// as `WindowGlobalParent` or `CanonicalBrowsingContext`.
|
|
|
|
WindowGlobalParent* GetParentWindowContext() {
|
|
|
|
return static_cast<WindowGlobalParent*>(
|
|
|
|
WindowContext::GetParentWindowContext());
|
|
|
|
}
|
|
|
|
WindowGlobalParent* TopWindowContext() {
|
|
|
|
return static_cast<WindowGlobalParent*>(WindowContext::TopWindowContext());
|
|
|
|
}
|
|
|
|
CanonicalBrowsingContext* GetBrowsingContext() {
|
|
|
|
return CanonicalBrowsingContext::Cast(WindowContext::GetBrowsingContext());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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.
|
2020-04-17 13:56:22 +03:00
|
|
|
already_AddRefed<JSWindowActorParent> GetActor(const nsACString& aName,
|
2019-01-28 22:02:02 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2020-04-06 22:03:02 +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.
|
|
|
|
already_AddRefed<BrowserParent> GetBrowserParent();
|
2019-01-28 21:09:13 +03:00
|
|
|
|
2020-04-30 19:42:53 +03:00
|
|
|
void ReceiveRawMessage(const JSActorMessageMeta& 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; }
|
|
|
|
|
2020-03-25 16:22:02 +03:00
|
|
|
nsIPrincipal* ContentBlockingAllowListPrincipal() {
|
|
|
|
return mDocContentBlockingAllowListPrincipal;
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// The BrowsingContext which this WindowGlobal has been loaded into.
|
2020-02-26 21:21:07 +03:00
|
|
|
// FIXME: It's quite awkward that this method has a slightly different name
|
|
|
|
// than the one on WindowContext.
|
2019-05-03 21:12:55 +03:00
|
|
|
CanonicalBrowsingContext* BrowsingContext() override {
|
2020-05-04 17:26:34 +03:00
|
|
|
return GetBrowsingContext();
|
2019-05-03 21:12:55 +03:00
|
|
|
}
|
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
|
|
|
|
2020-05-19 16:42:18 +03:00
|
|
|
void GetDocumentTitle(nsAString& aTitle) const { aTitle = mDocumentTitle; }
|
2020-02-20 22:04:23 +03:00
|
|
|
|
2020-03-01 22:25:01 +03:00
|
|
|
nsIPrincipal* GetContentBlockingAllowListPrincipal() const {
|
|
|
|
return mDocContentBlockingAllowListPrincipal;
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:25:57 +03:00
|
|
|
Maybe<ClientInfo> GetClientInfo() { return mClientInfo; }
|
|
|
|
|
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-12-17 14:25:25 +03:00
|
|
|
uint32_t ContentBlockingEvents();
|
|
|
|
|
2019-12-17 14:31:28 +03:00
|
|
|
void GetContentBlockingLog(nsAString& aLog);
|
|
|
|
|
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(
|
2020-01-08 04:21:30 +03:00
|
|
|
const DOMRect* aRect, double aScale, const nsACString& aBackgroundColor,
|
2019-07-10 19:45:46 +03:00
|
|
|
mozilla::ErrorResult& aRv);
|
|
|
|
|
2019-06-21 08:58:40 +03:00
|
|
|
already_AddRefed<Promise> GetSecurityInfo(ErrorResult& aRv);
|
|
|
|
|
2020-05-08 23:44:12 +03:00
|
|
|
static already_AddRefed<WindowGlobalParent> CreateDisconnected(
|
|
|
|
const WindowGlobalInit& aInit, bool aInProcess = false);
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2020-04-06 22:03:02 +03:00
|
|
|
// Initialize the mFrameLoader fields for a created WindowGlobalParent. Must
|
|
|
|
// be called after setting the Manager actor.
|
2020-05-08 23:44:12 +03:00
|
|
|
void Init() final;
|
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;
|
|
|
|
|
2020-01-13 17:06:50 +03:00
|
|
|
void NotifyContentBlockingEvent(
|
2020-02-11 12:33:32 +03:00
|
|
|
uint32_t aEvent, nsIRequest* aRequest, bool aBlocked,
|
|
|
|
const nsACString& aTrackingOrigin,
|
2020-01-13 17:06:50 +03:00
|
|
|
const nsTArray<nsCString>& aTrackingFullHashes,
|
2020-03-10 02:36:37 +03:00
|
|
|
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>&
|
|
|
|
aReason = Nothing());
|
2020-01-13 17:06:50 +03:00
|
|
|
|
|
|
|
ContentBlockingLog* GetContentBlockingLog() { return &mContentBlockingLog; }
|
|
|
|
|
2020-04-06 22:03:02 +03:00
|
|
|
nsIContentParent* GetContentParent();
|
|
|
|
|
2020-04-15 21:53:06 +03:00
|
|
|
nsICookieJarSettings* CookieJarSettings() { return mCookieJarSettings; }
|
|
|
|
|
|
|
|
bool DocumentHasLoaded() { return mDocumentHasLoaded; }
|
|
|
|
|
|
|
|
bool DocumentHasUserInteracted() { return mDocumentHasUserInteracted; }
|
|
|
|
|
|
|
|
uint32_t SandboxFlags() { return mSandboxFlags; }
|
|
|
|
|
|
|
|
bool GetDocumentBlockAllMixedContent() { return mBlockAllMixedContent; }
|
|
|
|
|
|
|
|
bool GetDocumentUpgradeInsecureRequests() { return mUpgradeInsecureRequests; }
|
|
|
|
|
2020-05-22 03:34:17 +03:00
|
|
|
void DidBecomeCurrentWindowGlobal(bool aCurrent);
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
protected:
|
2019-05-03 21:12:55 +03:00
|
|
|
const nsAString& GetRemoteType() override;
|
2020-04-30 19:42:53 +03:00
|
|
|
JSActor::Type GetSide() override { return JSActor::Type::Parent; }
|
2019-05-03 21:12:55 +03:00
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// IPC messages
|
2020-02-21 02:30:35 +03:00
|
|
|
mozilla::ipc::IPCResult RecvLoadURI(
|
|
|
|
const MaybeDiscarded<dom::BrowsingContext>& aTargetBC,
|
|
|
|
nsDocShellLoadState* aLoadState, bool aSetNavigating);
|
|
|
|
mozilla::ipc::IPCResult RecvInternalLoad(
|
|
|
|
const MaybeDiscarded<dom::BrowsingContext>& aTargetBC,
|
|
|
|
nsDocShellLoadState* aLoadState);
|
2019-02-06 18:58:43 +03:00
|
|
|
mozilla::ipc::IPCResult RecvUpdateDocumentURI(nsIURI* aURI);
|
2020-04-15 21:53:06 +03:00
|
|
|
mozilla::ipc::IPCResult RecvUpdateDocumentPrincipal(
|
|
|
|
nsIPrincipal* aNewDocumentPrincipal);
|
|
|
|
mozilla::ipc::IPCResult RecvUpdateDocumentHasLoaded(bool aDocumentHasLoaded);
|
|
|
|
mozilla::ipc::IPCResult RecvUpdateDocumentHasUserInteracted(
|
|
|
|
bool aDocumentHasUserInteracted);
|
|
|
|
mozilla::ipc::IPCResult RecvUpdateSandboxFlags(uint32_t aSandboxFlags);
|
|
|
|
mozilla::ipc::IPCResult RecvUpdateDocumentCspSettings(
|
|
|
|
bool aBlockAllMixedContent, bool aUpgradeInsecureRequests);
|
2020-02-20 22:04:23 +03:00
|
|
|
mozilla::ipc::IPCResult RecvUpdateDocumentTitle(const nsString& aTitle);
|
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);
|
2020-03-10 23:25:57 +03:00
|
|
|
mozilla::ipc::IPCResult RecvSetClientInfo(
|
|
|
|
const IPCClientInfo& aIPCClientInfo);
|
2019-02-06 18:58:43 +03:00
|
|
|
mozilla::ipc::IPCResult RecvDestroy();
|
2020-04-30 19:42:53 +03:00
|
|
|
mozilla::ipc::IPCResult RecvRawMessage(const JSActorMessageMeta& aMeta,
|
2019-12-07 21:59:23 +03:00
|
|
|
const ClonedMessageData& aData,
|
|
|
|
const ClonedMessageData& aStack);
|
2018-08-30 01:21:25 +03:00
|
|
|
|
2019-12-17 14:05:06 +03:00
|
|
|
mozilla::ipc::IPCResult RecvGetContentBlockingEvents(
|
|
|
|
GetContentBlockingEventsResolver&& aResolver);
|
2020-04-15 21:53:06 +03:00
|
|
|
mozilla::ipc::IPCResult RecvUpdateCookieJarSettings(
|
|
|
|
const CookieJarSettingsArgs& aCookieJarSettingsArgs);
|
2019-12-17 14:05:06 +03:00
|
|
|
|
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:
|
2020-05-08 23:44:12 +03:00
|
|
|
WindowGlobalParent(CanonicalBrowsingContext* aBrowsingContext,
|
|
|
|
uint64_t aInnerWindowId, uint64_t aOuterWindowId,
|
|
|
|
bool aInProcess, FieldTuple&& aFields);
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
~WindowGlobalParent();
|
|
|
|
|
2020-05-22 03:34:17 +03:00
|
|
|
bool ShouldTrackSiteOriginTelemetry();
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
// NOTE: This document principal doesn't reflect possible |document.domain|
|
|
|
|
// mutations which may have been made in the actual document.
|
|
|
|
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
|
2020-03-01 22:25:01 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mDocContentBlockingAllowListPrincipal;
|
2018-08-30 01:21:25 +03:00
|
|
|
nsCOMPtr<nsIURI> mDocumentURI;
|
2020-02-20 22:04:23 +03:00
|
|
|
nsString mDocumentTitle;
|
|
|
|
|
2020-04-17 13:56:22 +03:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorParent> mWindowActors;
|
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;
|
2020-01-13 17:06:50 +03:00
|
|
|
|
|
|
|
// The log of all content blocking actions taken on the document related to
|
|
|
|
// this WindowGlobalParent. This is only stored on top-level documents and
|
|
|
|
// includes the activity log for all of the nested subdocuments as well.
|
|
|
|
ContentBlockingLog mContentBlockingLog;
|
2020-03-10 23:25:57 +03:00
|
|
|
|
|
|
|
Maybe<ClientInfo> mClientInfo;
|
2020-04-15 21:53:06 +03:00
|
|
|
// Fields being mirrored from the corresponding document
|
|
|
|
nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
|
|
|
|
uint32_t mSandboxFlags;
|
2020-05-22 03:34:17 +03:00
|
|
|
|
|
|
|
struct OriginCounter {
|
|
|
|
void UpdateSiteOriginsFrom(WindowGlobalParent* aParent, bool aIncrease);
|
|
|
|
void Accumulate();
|
|
|
|
|
|
|
|
nsDataHashtable<nsCStringHashKey, int32_t> mOriginMap;
|
|
|
|
uint32_t mMaxOrigins = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Used to collect unique site origin telemetry.
|
|
|
|
//
|
|
|
|
// Is only Some() on top-level content windows.
|
|
|
|
Maybe<OriginCounter> mOriginCounter;
|
|
|
|
|
2020-04-15 21:53:06 +03:00
|
|
|
bool mDocumentHasLoaded;
|
|
|
|
bool mDocumentHasUserInteracted;
|
|
|
|
bool mBlockAllMixedContent;
|
|
|
|
bool mUpgradeInsecureRequests;
|
2018-08-30 01:21:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
inline nsISupports* ToSupports(
|
|
|
|
mozilla::dom::WindowGlobalParent* aWindowGlobal) {
|
|
|
|
return static_cast<mozilla::dom::WindowContext*>(aWindowGlobal);
|
|
|
|
}
|
|
|
|
|
2018-08-30 01:21:25 +03:00
|
|
|
#endif // !defined(mozilla_dom_WindowGlobalParent_h)
|