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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kristen Wright 2020-04-06 19:57:01 +00:00
Родитель 37d15858db
Коммит d433a32b2d
3 изменённых файлов: 14 добавлений и 21 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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

Просмотреть файл

@ -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);