Bug 1626388 - Convert two prefs in nsDocumentViewer to static pref r=njn

Converts `dom.disable_beforeunload` and `dom.require_user_interaction_for_beforeunload` to static pref.

Differential Revision: https://phabricator.services.mozilla.com/D69600
This commit is contained in:
Kristen Wright
2020-04-06 19:57:01 +00:00
parent fb4f6b749f
commit 3aa2d68e11
3 changed files with 14 additions and 21 deletions

View File

@@ -43,6 +43,7 @@
#include "mozilla/ErrorResult.h" #include "mozilla/ErrorResult.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/WeakPtr.h" #include "mozilla/WeakPtr.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_javascript.h" #include "mozilla/StaticPrefs_javascript.h"
#include "mozilla/StyleSheet.h" #include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h" #include "mozilla/StyleSheetInlines.h"
@@ -127,10 +128,6 @@
using namespace mozilla; using namespace mozilla;
using namespace mozilla::dom; using namespace mozilla::dom;
#define BEFOREUNLOAD_DISABLED_PREFNAME "dom.disable_beforeunload"
#define BEFOREUNLOAD_REQUIRES_INTERACTION_PREFNAME \
"dom.require_user_interaction_for_beforeunload"
//----------------------------------------------------- //-----------------------------------------------------
// LOGGING // LOGGING
#include "LayoutLogging.h" #include "LayoutLogging.h"
@@ -1262,18 +1259,6 @@ nsresult nsDocumentViewer::PermitUnloadInternal(uint32_t* aPermitUnloadFlags,
return NS_OK; 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... // First, get the script global object from the document...
nsPIDOMWindowOuter* window = mDocument->GetWindow(); nsPIDOMWindowOuter* window = mDocument->GetWindow();
@@ -1330,7 +1315,7 @@ nsresult nsDocumentViewer::PermitUnloadInternal(uint32_t* aPermitUnloadFlags,
nsAutoString text; nsAutoString text;
event->GetReturnValue(text); event->GetReturnValue(text);
if (sIsBeforeUnloadDisabled) { if (StaticPrefs::dom_disable_beforeunload()) {
*aPermitUnloadFlags = eDontPromptAndUnload; *aPermitUnloadFlags = eDontPromptAndUnload;
} }
@@ -1338,7 +1323,8 @@ nsresult nsDocumentViewer::PermitUnloadInternal(uint32_t* aPermitUnloadFlags,
// the event being dispatched. // the event being dispatched.
if (*aPermitUnloadFlags != eDontPromptAndUnload && dialogsAreEnabled && if (*aPermitUnloadFlags != eDontPromptAndUnload && dialogsAreEnabled &&
mDocument && !(mDocument->GetSandboxFlags() & SANDBOXED_MODALS) && mDocument && !(mDocument->GetSandboxFlags() & SANDBOXED_MODALS) &&
(!sBeforeUnloadRequiresInteraction || mDocument->UserHasInteracted()) && (!StaticPrefs::dom_require_user_interaction_for_beforeunload() ||
mDocument->UserHasInteracted()) &&
(event->WidgetEventPtr()->DefaultPrevented() || !text.IsEmpty())) { (event->WidgetEventPtr()->DefaultPrevented() || !text.IsEmpty())) {
// If the consumer wants prompt requests to just stop unloading, we don't // If the consumer wants prompt requests to just stop unloading, we don't
// need to prompt and can return immediately. // need to prompt and can return immediately.

View File

@@ -1494,6 +1494,16 @@
value: false value: false
mirror: always 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. # If set this to true, `Document.execCommand` may be performed nestedly.
# Otherwise, nested calls just return false. # Otherwise, nested calls just return false.
- name: dom.document.exec_command.nested_calls_allowed - name: dom.document.exec_command.nested_calls_allowed

View File

@@ -995,7 +995,6 @@ pref("editor.resizing.preserve_ratio", true);
pref("editor.positioning.offset", 0); pref("editor.positioning.offset", 0);
// Scripts & Windows prefs // Scripts & Windows prefs
pref("dom.disable_beforeunload", false);
pref("dom.beforeunload_timeout_ms", 1000); pref("dom.beforeunload_timeout_ms", 1000);
pref("dom.disable_window_flip", false); pref("dom.disable_window_flip", false);
pref("dom.disable_window_move_resize", 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.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.popup_allowed_events", "change click dblclick auxclick mouseup pointerup notificationclick reset submit touchend contextmenu");
pref("dom.serviceWorkers.disable_open_click_delay", 1000); pref("dom.serviceWorkers.disable_open_click_delay", 1000);