diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index 2621699c92ef..a26990a00d31 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -43,6 +43,7 @@ #include "mozilla/ErrorResult.h" #include "mozilla/Preferences.h" #include "mozilla/WeakPtr.h" +#include "mozilla/StaticPrefs_dom.h" #include "mozilla/StaticPrefs_javascript.h" #include "mozilla/StyleSheet.h" #include "mozilla/StyleSheetInlines.h" @@ -127,10 +128,6 @@ using namespace mozilla; using namespace mozilla::dom; -#define BEFOREUNLOAD_DISABLED_PREFNAME "dom.disable_beforeunload" -#define BEFOREUNLOAD_REQUIRES_INTERACTION_PREFNAME \ - "dom.require_user_interaction_for_beforeunload" - //----------------------------------------------------- // LOGGING #include "LayoutLogging.h" @@ -1262,18 +1259,6 @@ nsresult nsDocumentViewer::PermitUnloadInternal(uint32_t* aPermitUnloadFlags, return NS_OK; } - static bool sIsBeforeUnloadDisabled; - static bool sBeforeUnloadRequiresInteraction; - static bool sBeforeUnloadPrefsCached = false; - - if (!sBeforeUnloadPrefsCached) { - sBeforeUnloadPrefsCached = true; - Preferences::AddBoolVarCache(&sIsBeforeUnloadDisabled, - BEFOREUNLOAD_DISABLED_PREFNAME); - Preferences::AddBoolVarCache(&sBeforeUnloadRequiresInteraction, - BEFOREUNLOAD_REQUIRES_INTERACTION_PREFNAME); - } - // First, get the script global object from the document... nsPIDOMWindowOuter* window = mDocument->GetWindow(); @@ -1330,7 +1315,7 @@ nsresult nsDocumentViewer::PermitUnloadInternal(uint32_t* aPermitUnloadFlags, nsAutoString text; event->GetReturnValue(text); - if (sIsBeforeUnloadDisabled) { + if (StaticPrefs::dom_disable_beforeunload()) { *aPermitUnloadFlags = eDontPromptAndUnload; } @@ -1338,7 +1323,8 @@ nsresult nsDocumentViewer::PermitUnloadInternal(uint32_t* aPermitUnloadFlags, // the event being dispatched. if (*aPermitUnloadFlags != eDontPromptAndUnload && dialogsAreEnabled && mDocument && !(mDocument->GetSandboxFlags() & SANDBOXED_MODALS) && - (!sBeforeUnloadRequiresInteraction || mDocument->UserHasInteracted()) && + (!StaticPrefs::dom_require_user_interaction_for_beforeunload() || + mDocument->UserHasInteracted()) && (event->WidgetEventPtr()->DefaultPrevented() || !text.IsEmpty())) { // If the consumer wants prompt requests to just stop unloading, we don't // need to prompt and can return immediately. diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index eea2978e0b43..9ee927ae6ab8 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -1494,6 +1494,16 @@ value: false mirror: always +- name: dom.disable_beforeunload + type: bool + value: false + mirror: always + +- name: dom.require_user_interaction_for_beforeunload + type: bool + value: true + mirror: always + # If set this to true, `Document.execCommand` may be performed nestedly. # Otherwise, nested calls just return false. - name: dom.document.exec_command.nested_calls_allowed diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 1f1f29e3a815..08711bcbc549 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -995,7 +995,6 @@ pref("editor.resizing.preserve_ratio", true); pref("editor.positioning.offset", 0); // Scripts & Windows prefs -pref("dom.disable_beforeunload", false); pref("dom.beforeunload_timeout_ms", 1000); pref("dom.disable_window_flip", false); pref("dom.disable_window_move_resize", false); @@ -1012,8 +1011,6 @@ pref("dom.disable_window_open_feature.status", true); pref("dom.allow_scripts_to_close_windows", false); -pref("dom.require_user_interaction_for_beforeunload", true); - pref("dom.popup_allowed_events", "change click dblclick auxclick mouseup pointerup notificationclick reset submit touchend contextmenu"); pref("dom.serviceWorkers.disable_open_click_delay", 1000);