Bug 1419597 - Part 11: Move gRefCnt/gSerialCounter into nsContentUtils, r=smaug

MozReview-Commit-ID: KkG6hQentSH
This commit is contained in:
Nika Layzell 2017-11-21 16:20:45 -05:00
Родитель 492842f10a
Коммит c89dc4dbb4
5 изменённых файлов: 41 добавлений и 16 удалений

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

@ -345,6 +345,9 @@ mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump");
PopupControlState nsContentUtils::sPopupControlState = openAbused;
int32_t nsContentUtils::sInnerOrOuterWindowCount = 0;
uint32_t nsContentUtils::sInnerOrOuterWindowSerialCounter = 0;
// Subset of http://www.whatwg.org/specs/web-apps/current-work/#autofill-field-name
enum AutocompleteUnsupportedFieldName : uint8_t
{
@ -11018,3 +11021,19 @@ nsContentUtils::TryGetTabChildGlobalAsEventTarget(nsISupports* aFrom)
nsCOMPtr<EventTarget> target = frameLoader->GetTabChildGlobalAsEventTarget();
return target.forget();
}
/* static */ uint32_t
nsContentUtils::InnerOrOuterWindowCreated()
{
MOZ_ASSERT(NS_IsMainThread());
++sInnerOrOuterWindowCount;
return ++sInnerOrOuterWindowSerialCounter;
}
/* static */ void
nsContentUtils::InnerOrOuterWindowDestroyed()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(sInnerOrOuterWindowCount > 0);
--sInnerOrOuterWindowCount;
}

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

@ -3273,6 +3273,13 @@ public:
static PopupControlState GetPopupControlState() { return sPopupControlState; }
// Get a serial number for a newly created inner or outer window.
static uint32_t InnerOrOuterWindowCreated();
// Record that an inner or outer window has been destroyed.
static void InnerOrOuterWindowDestroyed();
// Get the current number of inner or outer windows.
static int32_t GetCurrentInnerOrOuterWindowCount() { return sInnerOrOuterWindowCount; }
private:
static bool InitializeEventTable();
@ -3463,6 +3470,9 @@ private:
static mozilla::LazyLogModule sDOMDumpLog;
static PopupControlState sPopupControlState;
static int32_t sInnerOrOuterWindowCount;
static uint32_t sInnerOrOuterWindowSerialCounter;
};
/* static */ inline

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

@ -4,12 +4,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdint.h>
static const char kStorageEnabled[] = "dom.storage.enabled";
static int32_t gRefCnt = 0;
static bool gMouseDown = false;
static bool gDragServiceDisabled = false;
static uint32_t gSerialCounter = 0;
// Include the implementations for the inner and outer windows respectively.
#include "nsGlobalWindowOuter.cpp"

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

@ -958,7 +958,7 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow)
// to create the entropy collector, so we should
// try to get one until we succeed.
gRefCnt++;
mSerial = nsContentUtils::InnerOrOuterWindowCreated();
static bool sFirstTime = true;
if (sFirstTime) {
@ -980,15 +980,13 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow)
}
}
mSerial = ++gSerialCounter;
#ifdef DEBUG
if (!PR_GetEnv("MOZ_QUIET")) {
printf_stderr("++DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p]\n",
gRefCnt,
nsContentUtils::GetCurrentInnerOrOuterWindowCount(),
static_cast<void*>(ToCanonicalSupports(this)),
getpid(),
gSerialCounter,
mSerial,
static_cast<void*>(ToCanonicalSupports(aOuterWindow)));
}
#endif
@ -1054,7 +1052,7 @@ nsGlobalWindowInner::~nsGlobalWindowInner()
sInnerWindowsById->Remove(mWindowID);
}
--gRefCnt;
nsContentUtils::InnerOrOuterWindowDestroyed();
#ifdef DEBUG
if (!PR_GetEnv("MOZ_QUIET")) {
@ -1071,7 +1069,7 @@ nsGlobalWindowInner::~nsGlobalWindowInner()
nsGlobalWindowOuter* outer = nsGlobalWindowOuter::Cast(mOuterWindow);
printf_stderr("--DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p] [url = %s]\n",
gRefCnt,
nsContentUtils::GetCurrentInnerOrOuterWindowCount(),
static_cast<void*>(ToCanonicalSupports(this)),
getpid(),
mSerial,

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

@ -883,17 +883,15 @@ nsGlobalWindowOuter::nsGlobalWindowOuter()
// to create the entropy collector, so we should
// try to get one until we succeed.
gRefCnt++;
mSerial = ++gSerialCounter;
mSerial = nsContentUtils::InnerOrOuterWindowCreated();
#ifdef DEBUG
if (!PR_GetEnv("MOZ_QUIET")) {
printf_stderr("++DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p]\n",
gRefCnt,
nsContentUtils::GetCurrentInnerOrOuterWindowCount(),
static_cast<void*>(ToCanonicalSupports(this)),
getpid(),
gSerialCounter,
mSerial,
nullptr);
}
#endif
@ -945,7 +943,7 @@ nsGlobalWindowOuter::~nsGlobalWindowOuter()
sOuterWindowsById->Remove(mWindowID);
}
--gRefCnt;
nsContentUtils::InnerOrOuterWindowDestroyed();
#ifdef DEBUG
if (!PR_GetEnv("MOZ_QUIET")) {
@ -961,7 +959,7 @@ nsGlobalWindowOuter::~nsGlobalWindowOuter()
}
printf_stderr("--DOMWINDOW == %d (%p) [pid = %d] [serial = %d] [outer = %p] [url = %s]\n",
gRefCnt,
nsContentUtils::GetCurrentInnerOrOuterWindowCount(),
static_cast<void*>(ToCanonicalSupports(this)),
getpid(),
mSerial,