From 824fb768e1448b254b4e78b0634811e195cfb57e Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 9 Oct 2020 18:29:34 +0000 Subject: [PATCH] Bug 1655866: Part 9 - Use the same PermitUnloadAction enum in WGP and nsIContentViewer. r=nika Differential Revision: https://phabricator.services.mozilla.com/D90939 --- docshell/base/nsIContentViewer.idl | 28 +++++---------------- dom/chrome-webidl/WindowGlobalActors.webidl | 1 - dom/ipc/DocShellMessageUtils.h | 10 ++++---- dom/ipc/PWindowGlobal.ipdl | 4 +-- dom/ipc/WindowGlobalParent.cpp | 15 ++++++----- dom/ipc/WindowGlobalParent.h | 2 +- layout/base/nsDocumentViewer.cpp | 6 ++--- 7 files changed, 24 insertions(+), 42 deletions(-) diff --git a/docshell/base/nsIContentViewer.idl b/docshell/base/nsIContentViewer.idl index d1eddcc74779..c2090007ef65 100644 --- a/docshell/base/nsIContentViewer.idl +++ b/docshell/base/nsIContentViewer.idl @@ -14,6 +14,8 @@ webidl Node; #include "nsTArray.h" #include "nsRect.h" +#include "mozilla/dom/WindowGlobalActorsBinding.h" + class nsIWidget; class nsPresContext; class nsView; @@ -35,6 +37,7 @@ class WindowGlobalChild; [ptr] native Encoding(const mozilla::Encoding); [ptr] native PresShellPtr(mozilla::PresShell); [ptr] native WindowGlobalChildPtr(mozilla::dom::WindowGlobalChild); +native PermitUnloadAction(mozilla::dom::PermitUnloadAction); [scriptable, builtinclass, uuid(2da17016-7851-4a45-a7a8-00b360e01595)] interface nsIContentViewer : nsISupports @@ -51,23 +54,6 @@ interface nsIContentViewer : nsISupports [notxpcom,nostdcall] readonly attribute boolean isStopped; - /** - * aAction is passed to PermitUnload to indicate what action to take - * if a beforeunload handler wants to prompt the user. - * - * ePrompt: Prompt and return the user's choice (default). - * eDontPromptAndDontUnload: Don't prompt and return false (unload not permitted) - * if the document (or its children) asks us to prompt. - * eDontPromptAndUnload: Don't prompt and return true (unload permitted) no matter what. - * - * NOTE: Keep this in sync with PermitUnloadAction in WindowGlobalActors.webidl. - */ - cenum PermitUnloadAction : 8 { - ePrompt = 0, - eDontPromptAndDontUnload = 1, - eDontPromptAndUnload = 2 - }; - /** * The result of dispatching a "beforeunload" event. If `eAllowNavigation`, * no "beforeunload" listener requested to prevent the navigation, or its @@ -80,12 +66,11 @@ interface nsIContentViewer : nsISupports }; /** - * Overload PermitUnload method for C++ consumers with no aPermitUnloadFlags - * argument. + * Overload PermitUnload method for C++ consumers with no aAction argument. */ %{C++ nsresult PermitUnload(bool* canUnload) { - return PermitUnload(ePrompt, canUnload); + return PermitUnload(mozilla::dom::PermitUnloadAction::Prompt, canUnload); } %} @@ -94,7 +79,7 @@ interface nsIContentViewer : nsISupports * the document. * The result is returned. */ - boolean permitUnload([optional] in nsIContentViewer_PermitUnloadAction aAction); + boolean permitUnload([optional] in PermitUnloadAction aAction); /** * Exposes whether we're blocked in a call to permitUnload. @@ -340,7 +325,6 @@ interface nsIContentViewer : nsISupports namespace mozilla { namespace dom { -using XPCOMPermitUnloadAction = nsIContentViewer::PermitUnloadAction; using PermitUnloadResult = nsIContentViewer::PermitUnloadResult; } // namespace dom diff --git a/dom/chrome-webidl/WindowGlobalActors.webidl b/dom/chrome-webidl/WindowGlobalActors.webidl index 2a0798d9ae13..8dfc1048d556 100644 --- a/dom/chrome-webidl/WindowGlobalActors.webidl +++ b/dom/chrome-webidl/WindowGlobalActors.webidl @@ -24,7 +24,6 @@ interface WindowContext { readonly attribute boolean hasBeforeUnload; }; -// Keep this in sync with nsIContentViewer::PermitUnloadAction. enum PermitUnloadAction { "prompt", "dontUnload", diff --git a/dom/ipc/DocShellMessageUtils.h b/dom/ipc/DocShellMessageUtils.h index 3156e4f63a2b..bf7004edee55 100644 --- a/dom/ipc/DocShellMessageUtils.h +++ b/dom/ipc/DocShellMessageUtils.h @@ -43,11 +43,11 @@ struct ParamTraits mozilla::dom::PermitUnloadResult::eRequestBlockNavigation> {}; template <> -struct ParamTraits - : public ContiguousEnumSerializerInclusive< - mozilla::dom::XPCOMPermitUnloadAction, - mozilla::dom::XPCOMPermitUnloadAction::ePrompt, - mozilla::dom::XPCOMPermitUnloadAction::eDontPromptAndUnload> {}; +struct ParamTraits + : public ContiguousEnumSerializer< + mozilla::dom::PermitUnloadAction, + mozilla::dom::PermitUnloadAction(0), + mozilla::dom::PermitUnloadAction::EndGuard_> {}; } // namespace IPC diff --git a/dom/ipc/PWindowGlobal.ipdl b/dom/ipc/PWindowGlobal.ipdl index 46a6daf9cf4f..93ca2f78ceb7 100644 --- a/dom/ipc/PWindowGlobal.ipdl +++ b/dom/ipc/PWindowGlobal.ipdl @@ -20,7 +20,7 @@ using mozilla::gfx::IntRect from "mozilla/gfx/Rect.h"; using moveonly mozilla::gfx::PaintFragment from "mozilla/gfx/CrossProcessPaint.h"; using nscolor from "nsColor.h"; using refcounted class nsDocShellLoadState from "nsDocShellLoadState.h"; -using mozilla::dom::XPCOMPermitUnloadAction from "mozilla/dom/DocShellMessageUtils.h"; +using mozilla::dom::PermitUnloadAction from "mozilla/dom/DocShellMessageUtils.h"; using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h"; using mozilla::layers::LayersId from "mozilla/layers/LayersTypes.h"; using refcounted class nsITransportSecurityInfo from "nsITransportSecurityInfo.h"; @@ -165,7 +165,7 @@ parent: // values). The sender is responsible for checking documents in its own // process, and passing true for `aHasInProcessBlocker` if any exist. Windows // hosted outside of the caller process will be checked automatically. - async CheckPermitUnload(bool aHasInProcessBlocker, XPCOMPermitUnloadAction aAction) + async CheckPermitUnload(bool aHasInProcessBlocker, PermitUnloadAction aAction) returns (bool permitUnload); async Destroy(); diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index 3d0605d7916d..6ff026f1a484 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -679,7 +679,7 @@ class CheckPermitUnloadRequest final : public PromiseNativeHandler, public nsITimerCallback { public: CheckPermitUnloadRequest(WindowGlobalParent* aWGP, bool aHasInProcessBlocker, - nsIContentViewer::PermitUnloadAction aAction, + PermitUnloadAction aAction, std::function&& aResolver) : mResolver(std::move(aResolver)), mWGP(aWGP), @@ -765,10 +765,10 @@ class CheckPermitUnloadRequest final : public PromiseNativeHandler, auto action = mAction; if (StaticPrefs::dom_disable_beforeunload()) { - action = nsIContentViewer::eDontPromptAndUnload; + action = PermitUnloadAction::Unload; } - if (action != nsIContentViewer::ePrompt) { - SendReply(action == nsIContentViewer::eDontPromptAndUnload); + if (action != PermitUnloadAction::Prompt) { + SendReply(action == PermitUnloadAction::Unload); return; } @@ -835,7 +835,7 @@ class CheckPermitUnloadRequest final : public PromiseNativeHandler, uint32_t mPendingRequests = 0; - nsIContentViewer::PermitUnloadAction mAction; + PermitUnloadAction mAction; State mState = State::UNINITIALIZED; @@ -847,7 +847,7 @@ NS_IMPL_ISUPPORTS(CheckPermitUnloadRequest, nsITimerCallback) } // namespace mozilla::ipc::IPCResult WindowGlobalParent::RecvCheckPermitUnload( - bool aHasInProcessBlocker, XPCOMPermitUnloadAction aAction, + bool aHasInProcessBlocker, PermitUnloadAction aAction, CheckPermitUnloadResolver&& aResolver) { if (!IsCurrentGlobal()) { aResolver(false); @@ -870,8 +870,7 @@ already_AddRefed WindowGlobalParent::PermitUnload( } auto request = MakeRefPtr( - this, /* aHasInProcessBlocker */ false, - nsIContentViewer::PermitUnloadAction(aAction), + this, /* aHasInProcessBlocker */ false, aAction, [promise](bool aAllow) { promise->MaybeResolve(aAllow); }); request->Run(/* aIgnoreProcess */ nullptr, aTimeout); diff --git a/dom/ipc/WindowGlobalParent.h b/dom/ipc/WindowGlobalParent.h index 81c1fcebd149..0855544d3abd 100644 --- a/dom/ipc/WindowGlobalParent.h +++ b/dom/ipc/WindowGlobalParent.h @@ -259,7 +259,7 @@ class WindowGlobalParent final : public WindowContext, uint32_t aMillis); mozilla::ipc::IPCResult RecvCheckPermitUnload( - bool aHasInProcessBlocker, XPCOMPermitUnloadAction aAction, + bool aHasInProcessBlocker, PermitUnloadAction aAction, CheckPermitUnloadResolver&& aResolver); private: diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 4402e894ce2e..854cc5397319 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -1207,7 +1207,7 @@ nsDocumentViewer::PermitUnload(PermitUnloadAction aAction, RefPtr kungFuDeathGrip(this); if (StaticPrefs::dom_disable_beforeunload()) { - aAction = eDontPromptAndUnload; + aAction = PermitUnloadAction::Unload; } *aPermitUnload = true; @@ -1245,8 +1245,8 @@ nsDocumentViewer::PermitUnload(PermitUnloadAction aAction, if (!foundBlocker) { return NS_OK; } - if (aAction != ePrompt) { - *aPermitUnload = aAction == eDontPromptAndUnload; + if (aAction != PermitUnloadAction::Prompt) { + *aPermitUnload = aAction == PermitUnloadAction::Unload; return NS_OK; } }