Bug 1419144 - Part 15: Move PopupControlState into nsContentUtils, r=smaug

MozReview-Commit-ID: Kt2moF5nsDg
This commit is contained in:
Nika Layzell 2017-11-17 17:09:20 -05:00
Родитель ef26b1acf5
Коммит 920ec9caac
7 изменённых файлов: 45 добавлений и 49 удалений

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

@ -587,7 +587,7 @@ TimeoutManager::SetTimeout(nsITimeoutHandler* aHandler,
}
if (gRunningTimeoutDepth == 0 &&
mWindow.GetPopupControlState() < openBlocked) {
nsContentUtils::GetPopupControlState() < openBlocked) {
// This timeout is *not* set from another timeout and it's set
// while popups are enabled. Propagate the state to the timeout if
// its delay (interval) is equal to or less than what
@ -597,7 +597,7 @@ TimeoutManager::SetTimeout(nsITimeoutHandler* aHandler,
// because our lower bound for |realInterval| could be pretty high
// in some cases.
if (interval <= gDisableOpenClickDelay) {
timeout->mPopupState = mWindow.GetPopupControlState();
timeout->mPopupState = nsContentUtils::GetPopupControlState();
}
}

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

@ -343,6 +343,8 @@ bool nsContentUtils::sDoNotTrackEnabled = false;
mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump");
PopupControlState nsContentUtils::sPopupControlState = openAbused;
// Subset of http://www.whatwg.org/specs/web-apps/current-work/#autofill-field-name
enum AutocompleteUnsupportedFieldName : uint8_t
{

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

@ -3253,6 +3253,26 @@ public:
static already_AddRefed<mozilla::dom::EventTarget>
TryGetTabChildGlobalAsEventTarget(nsISupports* aFrom);
static PopupControlState
PushPopupControlState(PopupControlState aState, bool aForce)
{
MOZ_ASSERT(NS_IsMainThread());
PopupControlState old = sPopupControlState;
if (aState < old || aForce) {
sPopupControlState = aState;
}
return old;
}
static void
PopPopupControlState(PopupControlState aState)
{
MOZ_ASSERT(NS_IsMainThread());
sPopupControlState = aState;
}
static PopupControlState GetPopupControlState() { return sPopupControlState; }
private:
static bool InitializeEventTable();
@ -3441,6 +3461,8 @@ private:
#endif
static bool sDoNotTrackEnabled;
static mozilla::LazyLogModule sDOMDumpLog;
static PopupControlState sPopupControlState;
};
/* static */ inline

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

@ -290,8 +290,6 @@ using mozilla::dom::cache::CacheStorage;
static LazyLogModule gDOMLeakPRLog("DOMLeak");
static int32_t gRefCnt = 0;
static int32_t gOpenPopupSpamCount = 0;
static PopupControlState gPopupControlState = openAbused;
static bool gMouseDown = false;
static bool gDragServiceDisabled = false;
static FILE *gDumpFile = nullptr;

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

@ -1479,8 +1479,7 @@ nsGlobalWindowInner::PopPopupControlState(PopupControlState aState) const
PopupControlState
nsGlobalWindowInner::GetPopupControlState() const
{
MOZ_ASSERT(NS_IsMainThread());
return gPopupControlState;
return nsContentUtils::GetPopupControlState();
}
nsresult

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

@ -43,6 +43,7 @@
return GetCurrentInnerWindowInternal()->method args; \
PR_END_MACRO
static int32_t gOpenPopupSpamCount = 0;
nsGlobalWindowOuter::OuterWindowByIdTable *nsGlobalWindowOuter::sOuterWindowsById = nullptr;
@ -1425,46 +1426,23 @@ nsGlobalWindowOuter::SetInitialPrincipalToSubject()
}
}
PopupControlState
PushPopupControlState(PopupControlState aState, bool aForce)
{
MOZ_ASSERT(NS_IsMainThread());
PopupControlState oldState = gPopupControlState;
if (aState < gPopupControlState || aForce) {
gPopupControlState = aState;
}
return oldState;
}
PopupControlState
nsGlobalWindowOuter::PushPopupControlState(PopupControlState aState,
bool aForce) const
{
return ::PushPopupControlState(aState, aForce);
}
void
PopPopupControlState(PopupControlState aState)
{
MOZ_ASSERT(NS_IsMainThread());
gPopupControlState = aState;
return nsContentUtils::PushPopupControlState(aState, aForce);
}
void
nsGlobalWindowOuter::PopPopupControlState(PopupControlState aState) const
{
::PopPopupControlState(aState);
nsContentUtils::PopPopupControlState(aState);
}
PopupControlState
nsGlobalWindowOuter::GetPopupControlState() const
{
MOZ_ASSERT(NS_IsMainThread());
return gPopupControlState;
return nsContentUtils::GetPopupControlState();
}
#define WINDOWSTATEHOLDER_IID \
@ -5078,7 +5056,7 @@ nsGlobalWindowOuter::FocusOuter(ErrorResult& aError)
// (bugs 355482 and 369306).
bool canFocus = CanSetProperty("dom.disable_window_flip") ||
(opener == callerOuter &&
RevisePopupAbuseLevel(gPopupControlState) < openBlocked);
RevisePopupAbuseLevel(GetPopupControlState()) < openBlocked);
nsCOMPtr<mozIDOMWindowProxy> activeDOMWindow;
fm->GetActiveWindow(getter_AddRefs(activeDOMWindow));
@ -7483,7 +7461,7 @@ nsGlobalWindowOuter::OpenInternal(const nsAString& aUrl, const nsAString& aName,
if (NS_FAILED(rv))
return rv;
PopupControlState abuseLevel = gPopupControlState;
PopupControlState abuseLevel = GetPopupControlState();
if (checkForPopup) {
abuseLevel = RevisePopupAbuseLevel(abuseLevel);
if (abuseLevel >= openBlocked) {
@ -8265,3 +8243,13 @@ nsGlobalWindowOuter::Create(bool aIsChrome)
window->InitWasOffline();
return window.forget();
}
nsAutoPopupStatePusherInternal::nsAutoPopupStatePusherInternal(PopupControlState aState, bool aForce)
: mOldState(nsContentUtils::PushPopupControlState(aState, aForce))
{
}
nsAutoPopupStatePusherInternal::~nsAutoPopupStatePusherInternal()
{
nsContentUtils::PopPopupControlState(mOldState);
}

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

@ -1039,12 +1039,6 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowOuter, NS_PIDOMWINDOWOUTER_IID)
#include "nsPIDOMWindowInlines.h"
#ifdef MOZILLA_INTERNAL_API
PopupControlState
PushPopupControlState(PopupControlState aState, bool aForce);
void
PopPopupControlState(PopupControlState aState);
#define NS_AUTO_POPUP_STATE_PUSHER nsAutoPopupStatePusherInternal
#else
#define NS_AUTO_POPUP_STATE_PUSHER nsAutoPopupStatePusherExternal
@ -1060,15 +1054,8 @@ class NS_AUTO_POPUP_STATE_PUSHER
{
public:
#ifdef MOZILLA_INTERNAL_API
explicit NS_AUTO_POPUP_STATE_PUSHER(PopupControlState aState, bool aForce = false)
: mOldState(::PushPopupControlState(aState, aForce))
{
}
~NS_AUTO_POPUP_STATE_PUSHER()
{
PopPopupControlState(mOldState);
}
explicit NS_AUTO_POPUP_STATE_PUSHER(PopupControlState aState, bool aForce = false);
~NS_AUTO_POPUP_STATE_PUSHER();
#else
NS_AUTO_POPUP_STATE_PUSHER(nsPIDOMWindowOuter *aWindow, PopupControlState aState)
: mWindow(aWindow), mOldState(openAbused)