Source code
Revision control
Copy as Markdown
Other Tools
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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
#ifndef mozilla_dom_BrowsingContext_h
#define mozilla_dom_BrowsingContext_h
#include <tuple>
#include "GVAutoplayRequestUtils.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/HalScreenConfiguration.h"
#include "mozilla/LinkedList.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Span.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/LocationBase.h"
#include "mozilla/dom/MaybeDiscarded.h"
#include "mozilla/dom/PopupBlocker.h"
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/BrowsingContextBinding.h"
#include "mozilla/dom/ScreenOrientationBinding.h"
#include "mozilla/dom/SyncedContext.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDocShell.h"
#include "nsTArray.h"
#include "nsWrapperCache.h"
#include "nsILoadInfo.h"
#include "nsILoadContext.h"
#include "nsThreadUtils.h"
class nsDocShellLoadState;
class nsGlobalWindowInner;
class nsGlobalWindowOuter;
class nsIPrincipal;
class nsOuterWindowProxy;
struct nsPoint;
class PickleIterator;
namespace IPC {
class Message;
class MessageReader;
class MessageWriter;
} // namespace IPC
namespace mozilla {
class ErrorResult;
class LogModule;
namespace ipc {
class IProtocol;
class IPCResult;
template <typename T>
struct IPDLParamTraits;
} // namespace ipc
namespace dom {
class BrowsingContent;
class BrowsingContextGroup;
class CanonicalBrowsingContext;
class ChildSHistory;
class ContentParent;
class Element;
struct LoadingSessionHistoryInfo;
class Location;
template <typename>
struct Nullable;
template <typename T>
class Sequence;
class SessionHistoryInfo;
class SessionStorageManager;
class StructuredCloneHolder;
class WindowContext;
class WindowGlobalChild;
struct WindowPostMessageOptions;
class WindowProxyHolder;
enum class ExplicitActiveStatus : uint8_t {
None,
Active,
Inactive,
EndGuard_,
};
struct EmbedderColorSchemes {
PrefersColorSchemeOverride mUsed{};
PrefersColorSchemeOverride mPreferred{};
bool operator==(const EmbedderColorSchemes& aOther) const {
return mUsed == aOther.mUsed && mPreferred == aOther.mPreferred;
}
bool operator!=(const EmbedderColorSchemes& aOther) const {
return !(*this == aOther);
}
};
// Fields are, by default, settable by any process and readable by any process.
// Racy sets will be resolved as-if they occurred in the order the parent
// process finds out about them.
//
// The `DidSet` and `CanSet` methods may be overloaded to provide different
// behavior for a specific field.
// * `DidSet` is called to run code in every process whenever the value is
// updated (This currently occurs even if the value didn't change, though
// this may change in the future).
// * `CanSet` is called before attempting to set the value, in both the process
// which calls `Set`, and the parent process, and will kill the misbehaving
// process if it fails.
#define MOZ_EACH_BC_FIELD(FIELD) \
FIELD(Name, nsString) \
FIELD(Closed, bool) \
FIELD(ExplicitActive, ExplicitActiveStatus) \
/* Top()-only. If true, new-playing media will be suspended when in an \
* inactive browsing context. */ \
FIELD(SuspendMediaWhenInactive, bool) \
/* If true, we're within the nested event loop in window.open, and this \
* context may not be used as the target of a load */ \
FIELD(PendingInitialization, bool) \
/* Indicates if the browser window is active for the purpose of the \
* :-moz-window-inactive pseudoclass. Only read from or set on the \
* top BrowsingContext. */ \
FIELD(IsActiveBrowserWindowInternal, bool) \
FIELD(OpenerPolicy, nsILoadInfo::CrossOriginOpenerPolicy) \
/* Current opener for the BrowsingContext. Weak reference */ \
FIELD(OpenerId, uint64_t) \
FIELD(OnePermittedSandboxedNavigatorId, uint64_t) \
/* WindowID of the inner window which embeds this BC */ \
FIELD(EmbedderInnerWindowId, uint64_t) \
FIELD(CurrentInnerWindowId, uint64_t) \
FIELD(HadOriginalOpener, bool) \
/* Was this window created by a webpage through window.open or an anchor \
* link? In general, windows created this way may be manipulated (e.g. \
* closed, resized or moved) by content JS. */ \
FIELD(TopLevelCreatedByWebContent, bool) \
FIELD(IsPopupSpam, bool) \
/* Hold the audio muted state and should be used on top level browsing \
* contexts only */ \
FIELD(Muted, bool) \
/* Hold the pinned/app-tab state and should be used on top level browsing \
* contexts only */ \
FIELD(IsAppTab, bool) \
/* Whether there's more than 1 tab / toplevel browsing context in this \
* parent window. Used to determine if a given BC is allowed to resize \
* and/or move the window or not. */ \
FIELD(HasSiblings, bool) \
/* Indicate that whether we should delay media playback, which would only \
be done on an unvisited tab. And this should only be used on the top \
level browsing contexts */ \
FIELD(ShouldDelayMediaFromStart, bool) \
/* See nsSandboxFlags.h for the possible flags. */ \
FIELD(SandboxFlags, uint32_t) \
/* The value of SandboxFlags when the BrowsingContext is first created. \
* Used for sandboxing the initial about:blank document. */ \
FIELD(InitialSandboxFlags, uint32_t) \
/* A non-zero unique identifier for the browser element that is hosting \
* this \
* BrowsingContext tree. Every BrowsingContext in the element's tree will \
* return the same ID in all processes and it will remain stable \
* regardless of process changes. When a browser element's frameloader is \
* switched to another browser element this ID will remain the same but \
* hosted under the under the new browser element. */ \
FIELD(BrowserId, uint64_t) \
FIELD(HistoryID, nsID) \
FIELD(InRDMPane, bool) \
FIELD(Loading, bool) \
/* A field only set on top browsing contexts, which indicates that either: \
* \
* * This is a browsing context created explicitly for printing or print \
* preview (thus hosting static documents). \
* \
* * This is a browsing context where something in this tree is calling \
* window.print() (and thus showing a modal dialog). \
* \
* We use it exclusively to block navigation for both of these cases. */ \
FIELD(IsPrinting, bool) \
FIELD(AncestorLoading, bool) \
FIELD(AllowContentRetargeting, bool) \
FIELD(AllowContentRetargetingOnChildren, bool) \
FIELD(ForceEnableTrackingProtection, bool) \
FIELD(UseGlobalHistory, bool) \
FIELD(TargetTopLevelLinkClicksToBlankInternal, bool) \
FIELD(FullscreenAllowedByOwner, bool) \
FIELD(ForceDesktopViewport, bool) \
/* \
* "is popup" in the spec. \
* Set only on top browsing contexts. \
* This doesn't indicate whether this is actually a popup or not, \
* but whether this browsing context is created by requesting popup or not. \
* See also: nsWindowWatcher::ShouldOpenPopup. \
*/ \
FIELD(IsPopupRequested, bool) \
/* These field are used to store the states of autoplay media request on \
* GeckoView only, and it would only be modified on the top level browsing \
* context. */ \
FIELD(GVAudibleAutoplayRequestStatus, GVAutoplayRequestStatus) \
FIELD(GVInaudibleAutoplayRequestStatus, GVAutoplayRequestStatus) \
/* ScreenOrientation-related APIs */ \
FIELD(CurrentOrientationAngle, float) \
FIELD(CurrentOrientationType, mozilla::dom::OrientationType) \
FIELD(OrientationLock, mozilla::hal::ScreenOrientation) \
FIELD(UserAgentOverride, nsString) \
FIELD(TouchEventsOverrideInternal, mozilla::dom::TouchEventsOverride) \
FIELD(EmbedderElementType, Maybe<nsString>) \
FIELD(MessageManagerGroup, nsString) \
FIELD(MaxTouchPointsOverride, uint8_t) \
FIELD(FullZoom, float) \
FIELD(WatchedByDevToolsInternal, bool) \
FIELD(TextZoom, float) \
FIELD(OverrideDPPX, float) \
/* The current in-progress load. */ \
FIELD(CurrentLoadIdentifier, Maybe<uint64_t>) \
/* See nsIRequest for possible flags. */ \
FIELD(DefaultLoadFlags, uint32_t) \
/* Signals that session history is enabled for this browsing context tree. \
* This is only ever set to true on the top BC, so consumers need to get \
* the value from the top BC! */ \
FIELD(HasSessionHistory, bool) \
/* Tracks if this context is the only top-level document in the session \
* history of the context. */ \
FIELD(IsSingleToplevelInHistory, bool) \
FIELD(UseErrorPages, bool) \
FIELD(PlatformOverride, nsString) \
/* Specifies if this BC has loaded documents besides the initial \
* about:blank document. about:privatebrowsing, about:home, about:newtab \
* and non-initial about:blank are not considered to be initial \
* documents. */ \
FIELD(HasLoadedNonInitialDocument, bool) \
/* Default value for nsIDocumentViewer::authorStyleDisabled in any new \
* browsing contexts created as a descendant of this one. Valid only for \
* top BCs. */ \
FIELD(AuthorStyleDisabledDefault, bool) \
FIELD(ServiceWorkersTestingEnabled, bool) \
FIELD(MediumOverride, nsString) \
/* DevTools override for prefers-color-scheme */ \
FIELD(PrefersColorSchemeOverride, dom::PrefersColorSchemeOverride) \
/* DevTools override for forced-colors */ \
FIELD(ForcedColorsOverride, dom::ForcedColorsOverride) \
/* prefers-color-scheme override based on the color-scheme style of our \
* <browser> embedder element. */ \
FIELD(EmbedderColorSchemes, EmbedderColorSchemes) \
FIELD(DisplayMode, dom::DisplayMode) \
/* The number of entries added to the session history because of this \
* browsing context. */ \
FIELD(HistoryEntryCount, uint32_t) \
/* Don't use the getter of the field, but IsInBFCache() method */ \
FIELD(IsInBFCache, bool) \
FIELD(HasRestoreData, bool) \
FIELD(SessionStoreEpoch, uint32_t) \
/* Whether we can execute scripts in this BrowsingContext. Has no effect \
* unless scripts are also allowed in the parent WindowContext. */ \
FIELD(AllowJavascript, bool) \
/* The count of request that are used to prevent the browsing context tree \
* from being suspended, which would ONLY be modified on the top level \
* context in the chrome process because that's a non-atomic counter */ \
FIELD(PageAwakeRequestCount, uint32_t) \
/* This field only gets incrememented when we start navigations in the \
* parent process. This is used for keeping track of the racing navigations \
* between the parent and content processes. */ \
FIELD(ParentInitiatedNavigationEpoch, uint64_t) \
/* This browsing context is for a synthetic image document wrapping an \
* image embedded in <object> or <embed>. */ \
FIELD(IsSyntheticDocumentContainer, bool) \
/* If true, this document is embedded within a content document, either \
* loaded in the parent (e.g. about:addons or the devtools toolbox), or in \
* a content process. */ \
FIELD(EmbeddedInContentDocument, bool) \
/* If true, this browsing context is within a hidden embedded document. */ \
FIELD(IsUnderHiddenEmbedderElement, bool) \
/* If true, this browsing context is offline */ \
FIELD(ForceOffline, bool) \
/* Used to propagate window.top's inner size for RFPTarget::Window* \
* protections */ \
FIELD(TopInnerSizeForRFP, CSSIntSize)
// BrowsingContext, in this context, is the cross process replicated
// environment in which information about documents is stored. In
// particular the tree structure of nested browsing contexts is
// represented by the tree of BrowsingContexts.
//
// The tree of BrowsingContexts is created in step with its
// corresponding nsDocShell, and when nsDocShells are connected
// through a parent/child relationship, so are BrowsingContexts. The
// major difference is that BrowsingContexts are replicated (synced)
// to the parent process, making it possible to traverse the
// BrowsingContext tree for a tab, in both the parent and the child
// process.
//
// Trees of BrowsingContexts should only ever contain nodes of the
// same BrowsingContext::Type. This is enforced by asserts in the
// BrowsingContext::Create* methods.
class BrowsingContext : public nsILoadContext, public nsWrapperCache {