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