Skip to content

Commit

Permalink
Bug 1655866: Part 2 - Move HasBeforeUnload flag to WindowContext. r=nika
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaglione committed Sep 21, 2020
1 parent bd46b49 commit cafc571
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
6 changes: 6 additions & 0 deletions docshell/base/WindowContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ bool WindowContext::CanSet(FieldIndex<IDX_AllowMixedContent>,
return CheckOnlyOwningProcessCanSet(aSource);
}

bool WindowContext::CanSet(FieldIndex<IDX_HasBeforeUnload>,
const bool& aHasBeforeUnload,
ContentParent* aSource) {
return CheckOnlyOwningProcessCanSet(aSource);
}

bool WindowContext::CanSet(FieldIndex<IDX_CookieBehavior>,
const Maybe<uint32_t>& aValue,
ContentParent* aSource) {
Expand Down
8 changes: 8 additions & 0 deletions docshell/base/WindowContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class BrowsingContextGroup;
/* Whether the user has overriden the mixed content blocker to allow \
* mixed content loads to happen */ \
FIELD(AllowMixedContent, bool) \
/* Whether this window has registered a "beforeunload" event \
* handler */ \
FIELD(HasBeforeUnload, bool) \
/* Controls whether the WindowContext is currently considered to be \
* activated by a gesture */ \
FIELD(UserActivationState, UserActivation::State) \
Expand Down Expand Up @@ -97,6 +100,8 @@ class WindowContext : public nsISupports, public nsWrapperCache {

bool IsInProcess() const { return mInProcess; }

bool HasBeforeUnload() const { return GetHasBeforeUnload(); }

nsGlobalWindowInner* GetInnerWindow() const;
Document* GetDocument() const;

Expand Down Expand Up @@ -189,6 +194,9 @@ class WindowContext : public nsISupports, public nsWrapperCache {
bool CanSet(FieldIndex<IDX_AllowMixedContent>, const bool& aAllowMixedContent,
ContentParent* aSource);

bool CanSet(FieldIndex<IDX_HasBeforeUnload>, const bool& aHasBeforeUnload,
ContentParent* aSource);

bool CanSet(FieldIndex<IDX_CookieBehavior>, const Maybe<uint32_t>& aValue,
ContentParent* aSource);

Expand Down
6 changes: 3 additions & 3 deletions dom/chrome-webidl/WindowGlobalActors.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ interface WindowContext {
readonly attribute WindowContext? parentWindowContext;

readonly attribute WindowContext topWindowContext;

// True if this window has registered a "beforeunload" event handler.
readonly attribute boolean hasBeforeUnload;
};

[Exposed=Window, ChromeOnly]
Expand All @@ -37,9 +40,6 @@ interface WindowGlobalParent : WindowContext {
// embedder is in a different process.
readonly attribute boolean isProcessRoot;

// True if this window has registered a "beforeunload" event handler.
readonly attribute boolean hasBeforeUnload;

// Is the document loaded in this WindowGlobalParent the initial document
// implicitly created while "creating a new browsing context".
// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-browsing-context
Expand Down
4 changes: 0 additions & 4 deletions dom/ipc/PWindowGlobal.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ parent:
/// Send down initial document bit to the parent.
async SetIsInitialDocument(bool aIsInitialDocument);

/// Tell the parent if this WindowGlobal has any "beforeunload" event
/// listeners.
async SetHasBeforeUnload(bool aHasBeforeUnload);

// Attempts to perform a "Web Share".
async Share(IPCWebShareData aData) returns (nsresult rv);

Expand Down
7 changes: 3 additions & 4 deletions dom/ipc/WindowGlobalChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ bool WindowGlobalChild::IsProcessRoot() {
void WindowGlobalChild::BeforeUnloadAdded() {
// Don't bother notifying the parent if we don't have an IPC link open.
if (mBeforeUnloadListeners == 0 && CanSend()) {
SendSetHasBeforeUnload(true);
Unused << mWindowContext->SetHasBeforeUnload(true);
}

mBeforeUnloadListeners++;
Expand All @@ -315,9 +315,8 @@ void WindowGlobalChild::BeforeUnloadRemoved() {
mBeforeUnloadListeners--;
MOZ_ASSERT(mBeforeUnloadListeners >= 0);

// Don't bother notifying the parent if we don't have an IPC link open.
if (mBeforeUnloadListeners == 0 && CanSend()) {
SendSetHasBeforeUnload(false);
if (mBeforeUnloadListeners == 0) {
Unused << mWindowContext->SetHasBeforeUnload(false);
}
}

Expand Down
6 changes: 0 additions & 6 deletions dom/ipc/WindowGlobalParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ WindowGlobalParent::WindowGlobalParent(
: WindowContext(aBrowsingContext, aInnerWindowId, aOuterWindowId,
aInProcess, std::move(aInit)),
mIsInitialDocument(false),
mHasBeforeUnload(false),
mSandboxFlags(0),
mDocumentHasLoaded(false),
mDocumentHasUserInteracted(false),
Expand Down Expand Up @@ -392,11 +391,6 @@ IPCResult WindowGlobalParent::RecvUpdateDocumentCspSettings(
return IPC_OK();
}

IPCResult WindowGlobalParent::RecvSetHasBeforeUnload(bool aHasBeforeUnload) {
mHasBeforeUnload = aHasBeforeUnload;
return IPC_OK();
}

mozilla::ipc::IPCResult WindowGlobalParent::RecvSetClientInfo(
const IPCClientInfo& aIPCClientInfo) {
mClientInfo = Some(ClientInfo(aIPCClientInfo));
Expand Down
3 changes: 0 additions & 3 deletions dom/ipc/WindowGlobalParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ class WindowGlobalParent final : public WindowContext,

bool IsInitialDocument() { return mIsInitialDocument; }

bool HasBeforeUnload() { return mHasBeforeUnload; }

already_AddRefed<mozilla::dom::Promise> DrawSnapshot(
const DOMRect* aRect, double aScale, const nsACString& aBackgroundColor,
mozilla::ErrorResult& aRv);
Expand Down Expand Up @@ -225,7 +223,6 @@ class WindowGlobalParent final : public WindowContext,
}
mozilla::ipc::IPCResult RecvUpdateDocumentSecurityInfo(
nsITransportSecurityInfo* aSecurityInfo);
mozilla::ipc::IPCResult RecvSetHasBeforeUnload(bool aHasBeforeUnload);
mozilla::ipc::IPCResult RecvSetClientInfo(
const IPCClientInfo& aIPCClientInfo);
mozilla::ipc::IPCResult RecvDestroy();
Expand Down

0 comments on commit cafc571

Please sign in to comment.