зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1198381 - Move/rename nsTimeout to Timeout, r=smaug
MozReview-Commit-ID: 1WrH2ZbOuzj --HG-- extra : rebase_source : a010060badf2ffbfeadb1d7f8cc29376c214bcc6
This commit is contained in:
Родитель
b05b4b2b0d
Коммит
979adce9e5
|
@ -0,0 +1,90 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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 "Timeout.h"
|
||||
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsIScriptTimeoutHandler.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
Timeout::Timeout()
|
||||
: mCleared(false),
|
||||
mRunning(false),
|
||||
mIsInterval(false),
|
||||
mPublicId(0),
|
||||
mInterval(0),
|
||||
mFiringDepth(0),
|
||||
mNestingLevel(0),
|
||||
mPopupState(openAllowed)
|
||||
{
|
||||
MOZ_COUNT_CTOR(Timeout);
|
||||
}
|
||||
|
||||
Timeout::~Timeout()
|
||||
{
|
||||
if (mTimer) {
|
||||
mTimer->Cancel();
|
||||
mTimer = nullptr;
|
||||
}
|
||||
|
||||
MOZ_COUNT_DTOR(Timeout);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(Timeout)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Timeout)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrincipal)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mScriptHandler)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Timeout)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrincipal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptHandler)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(Timeout, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(Timeout, Release)
|
||||
|
||||
nsresult
|
||||
Timeout::InitTimer(uint32_t aDelay)
|
||||
{
|
||||
return mTimer->InitWithNameableFuncCallback(
|
||||
nsGlobalWindow::TimerCallback, this, aDelay,
|
||||
nsITimer::TYPE_ONE_SHOT, Timeout::TimerNameCallback);
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
Timeout::TimerNameCallback(nsITimer* aTimer, void* aClosure, char* aBuf,
|
||||
size_t aLen)
|
||||
{
|
||||
RefPtr<Timeout> timeout = (Timeout*)aClosure;
|
||||
|
||||
const char* filename;
|
||||
uint32_t lineNum, column;
|
||||
timeout->mScriptHandler->GetLocation(&filename, &lineNum, &column);
|
||||
snprintf(aBuf, aLen, "[content] %s:%u:%u", filename, lineNum, column);
|
||||
}
|
||||
|
||||
|
||||
// Return true if this timeout has a refcount of 1. This is used to check
|
||||
// that dummy_timeout doesn't leak from nsGlobalWindow::RunTimeout.
|
||||
#ifdef DEBUG
|
||||
bool
|
||||
Timeout::HasRefCntOne() const
|
||||
{
|
||||
return mRefCnt.get() == 1;
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,97 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_timeout_h
|
||||
#define mozilla_dom_timeout_h
|
||||
|
||||
#include "mozilla/LinkedList.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
class nsGlobalWindow;
|
||||
class nsIPrincipal;
|
||||
class nsIScriptTimeoutHandler;
|
||||
class nsITimer;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/*
|
||||
* Timeout struct that holds information about each script
|
||||
* timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which
|
||||
* abstracts the language specific cruft.
|
||||
*/
|
||||
class Timeout final
|
||||
: public LinkedListElement<Timeout>
|
||||
{
|
||||
public:
|
||||
Timeout();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(Timeout)
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Timeout)
|
||||
|
||||
nsresult InitTimer(uint32_t aDelay);
|
||||
|
||||
static void TimerNameCallback(nsITimer* aTimer, void* aClosure, char* aBuf,
|
||||
size_t aLen);
|
||||
|
||||
#ifdef DEBUG
|
||||
bool HasRefCntOne() const;
|
||||
#endif // DEBUG
|
||||
|
||||
// Window for which this timeout fires
|
||||
RefPtr<nsGlobalWindow> mWindow;
|
||||
|
||||
// The actual timer object
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
|
||||
// True if the timeout was cleared
|
||||
bool mCleared;
|
||||
|
||||
// True if this is one of the timeouts that are currently running
|
||||
bool mRunning;
|
||||
|
||||
// True if this is a repeating/interval timer
|
||||
bool mIsInterval;
|
||||
|
||||
// Returned as value of setTimeout()
|
||||
uint32_t mPublicId;
|
||||
|
||||
// Interval in milliseconds
|
||||
uint32_t mInterval;
|
||||
|
||||
// mWhen and mTimeRemaining can't be in a union, sadly, because they
|
||||
// have constructors.
|
||||
// Nominal time to run this timeout. Use only when timeouts are not
|
||||
// suspended.
|
||||
TimeStamp mWhen;
|
||||
// Remaining time to wait. Used only when timeouts are suspended.
|
||||
TimeDuration mTimeRemaining;
|
||||
|
||||
// Principal with which to execute
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
|
||||
// stack depth at which timeout is firing
|
||||
uint32_t mFiringDepth;
|
||||
|
||||
uint32_t mNestingLevel;
|
||||
|
||||
// The popup state at timeout creation time if not created from
|
||||
// another timeout
|
||||
PopupControlState mPopupState;
|
||||
|
||||
// The language-specific information about the callback.
|
||||
nsCOMPtr<nsIScriptTimeoutHandler> mScriptHandler;
|
||||
|
||||
private:
|
||||
~Timeout();
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_timeout_h
|
|
@ -204,6 +204,7 @@ EXPORTS.mozilla.dom += [
|
|||
'StyleSheetList.h',
|
||||
'SubtleCrypto.h',
|
||||
'Text.h',
|
||||
'Timeout.h',
|
||||
'TreeWalker.h',
|
||||
'WebKitCSSMatrix.h',
|
||||
'WebSocket.h',
|
||||
|
@ -342,6 +343,7 @@ UNIFIED_SOURCES += [
|
|||
'Text.cpp',
|
||||
'TextInputProcessor.cpp',
|
||||
'ThirdPartyUtil.cpp',
|
||||
'Timeout.cpp',
|
||||
'TreeWalker.cpp',
|
||||
'WebKitCSSMatrix.cpp',
|
||||
'WebSocket.cpp',
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "mozilla/dom/Performance.h"
|
||||
#include "mozilla/dom/StorageEvent.h"
|
||||
#include "mozilla/dom/StorageEventBinding.h"
|
||||
#include "mozilla/dom/Timeout.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#if defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GONK)
|
||||
#include "mozilla/dom/WindowOrientationObserver.h"
|
||||
|
@ -502,71 +503,6 @@ private:
|
|||
|
||||
NS_IMPL_ISUPPORTS(nsGlobalWindowObserver, nsIObserver, nsIInterfaceRequestor)
|
||||
|
||||
nsTimeout::nsTimeout()
|
||||
: mCleared(false),
|
||||
mRunning(false),
|
||||
mIsInterval(false),
|
||||
mPublicId(0),
|
||||
mInterval(0),
|
||||
mFiringDepth(0),
|
||||
mNestingLevel(0),
|
||||
mPopupState(openAllowed)
|
||||
{
|
||||
#ifdef DEBUG_jst
|
||||
{
|
||||
extern int gTimeoutCnt;
|
||||
|
||||
++gTimeoutCnt;
|
||||
}
|
||||
#endif
|
||||
|
||||
MOZ_COUNT_CTOR(nsTimeout);
|
||||
}
|
||||
|
||||
nsTimeout::~nsTimeout()
|
||||
{
|
||||
#ifdef DEBUG_jst
|
||||
{
|
||||
extern int gTimeoutCnt;
|
||||
|
||||
--gTimeoutCnt;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (mTimer) {
|
||||
mTimer->Cancel();
|
||||
mTimer = nullptr;
|
||||
}
|
||||
|
||||
MOZ_COUNT_DTOR(nsTimeout);
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsTimeout)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsTimeout)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsTimeout)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptHandler)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsTimeout, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsTimeout, Release)
|
||||
|
||||
nsresult
|
||||
nsTimeout::InitTimer(uint32_t aDelay)
|
||||
{
|
||||
return mTimer->InitWithNameableFuncCallback(
|
||||
nsGlobalWindow::TimerCallback, this, aDelay,
|
||||
nsITimer::TYPE_ONE_SHOT, nsGlobalWindow::TimerNameCallback);
|
||||
}
|
||||
|
||||
// Return true if this timeout has a refcount of 1. This is used to check
|
||||
// that dummy_timeout doesn't leak from nsGlobalWindow::RunTimeout.
|
||||
bool
|
||||
nsTimeout::HasRefCntOne()
|
||||
{
|
||||
return mRefCnt.get() == 1;
|
||||
}
|
||||
|
||||
static already_AddRefed<nsIVariant>
|
||||
CreateVoidVariant()
|
||||
{
|
||||
|
@ -1895,10 +1831,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListenerManager)
|
||||
|
||||
for (nsTimeout* timeout = tmp->mTimeouts.getFirst();
|
||||
for (Timeout* timeout = tmp->mTimeouts.getFirst();
|
||||
timeout;
|
||||
timeout = timeout->getNext()) {
|
||||
cb.NoteNativeChild(timeout, NS_CYCLE_COLLECTION_PARTICIPANT(nsTimeout));
|
||||
cb.NoteNativeChild(timeout, NS_CYCLE_COLLECTION_PARTICIPANT(Timeout));
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocation)
|
||||
|
@ -2058,7 +1994,7 @@ nsGlobalWindow::IsBlackForCC(bool aTracingNeeded)
|
|||
void
|
||||
nsGlobalWindow::UnmarkGrayTimers()
|
||||
{
|
||||
for (nsTimeout* timeout = mTimeouts.getFirst();
|
||||
for (Timeout* timeout = mTimeouts.getFirst();
|
||||
timeout;
|
||||
timeout = timeout->getNext()) {
|
||||
if (timeout->mScriptHandler) {
|
||||
|
@ -12123,9 +12059,9 @@ nsGlobalWindow::SetInterval(JSContext* aCx, const nsAString& aHandler,
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
|
||||
int32_t interval,
|
||||
bool aIsInterval, int32_t *aReturn)
|
||||
nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler* aHandler,
|
||||
int32_t interval, bool aIsInterval,
|
||||
int32_t* aReturn)
|
||||
{
|
||||
MOZ_ASSERT(IsInnerWindow());
|
||||
|
||||
|
@ -12147,7 +12083,7 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
|
|||
interval = maxTimeoutMs;
|
||||
}
|
||||
|
||||
RefPtr<nsTimeout> timeout = new nsTimeout();
|
||||
RefPtr<Timeout> timeout = new Timeout();
|
||||
timeout->mIsInterval = aIsInterval;
|
||||
timeout->mInterval = interval;
|
||||
timeout->mScriptHandler = aHandler;
|
||||
|
@ -12176,7 +12112,7 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
|
|||
return rv;
|
||||
}
|
||||
|
||||
RefPtr<nsTimeout> copy = timeout;
|
||||
RefPtr<Timeout> copy = timeout;
|
||||
|
||||
rv = timeout->InitTimer(realInterval);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -12227,7 +12163,6 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
|
|||
*aReturn = timeout->mPublicId;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
int32_t
|
||||
|
@ -12284,13 +12219,13 @@ nsGlobalWindow::SetTimeoutOrInterval(JSContext* aCx, const nsAString& aHandler,
|
|||
}
|
||||
|
||||
bool
|
||||
nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
|
||||
nsGlobalWindow::RunTimeoutHandler(Timeout* aTimeout,
|
||||
nsIScriptContext* aScx)
|
||||
{
|
||||
// Hold on to the timeout in case mExpr or mFunObj releases its
|
||||
// doc.
|
||||
RefPtr<nsTimeout> timeout = aTimeout;
|
||||
nsTimeout* last_running_timeout = mRunningTimeout;
|
||||
RefPtr<Timeout> timeout = aTimeout;
|
||||
Timeout* last_running_timeout = mRunningTimeout;
|
||||
mRunningTimeout = timeout;
|
||||
timeout->mRunning = true;
|
||||
|
||||
|
@ -12324,6 +12259,7 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
|
|||
bool abortIntervalHandler = false;
|
||||
nsCOMPtr<nsIScriptTimeoutHandler> handler(timeout->mScriptHandler);
|
||||
RefPtr<Function> callback = handler->GetCallback();
|
||||
|
||||
if (!callback) {
|
||||
// Evaluate the timeout expression.
|
||||
const nsAString& script = handler->GetHandlerText();
|
||||
|
@ -12396,7 +12332,7 @@ nsGlobalWindow::RunTimeoutHandler(nsTimeout* aTimeout,
|
|||
}
|
||||
|
||||
bool
|
||||
nsGlobalWindow::RescheduleTimeout(nsTimeout* aTimeout, const TimeStamp& now,
|
||||
nsGlobalWindow::RescheduleTimeout(Timeout* aTimeout, const TimeStamp& now,
|
||||
bool aRunningPendingTimeouts)
|
||||
{
|
||||
if (!aTimeout->mIsInterval) {
|
||||
|
@ -12475,7 +12411,7 @@ nsGlobalWindow::RescheduleTimeout(nsTimeout* aTimeout, const TimeStamp& now,
|
|||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
|
||||
nsGlobalWindow::RunTimeout(Timeout* aTimeout)
|
||||
{
|
||||
// If a modal dialog is open for this window, return early. Pending
|
||||
// timeouts will run when the modal dialog is dismissed.
|
||||
|
@ -12486,8 +12422,9 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
|
|||
NS_ASSERTION(IsInnerWindow(), "Timeout running on outer window!");
|
||||
NS_ASSERTION(!IsFrozen(), "Timeout running on a window in the bfcache!");
|
||||
|
||||
nsTimeout *nextTimeout;
|
||||
nsTimeout *last_expired_timeout, *last_insertion_point;
|
||||
Timeout* nextTimeout;
|
||||
Timeout* last_expired_timeout;
|
||||
Timeout* last_insertion_point;
|
||||
uint32_t firingDepth = mTimeoutFiringDepth + 1;
|
||||
|
||||
// Make sure that the window and the script context don't go away as
|
||||
|
@ -12518,7 +12455,7 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
|
|||
// whose mWhen is greater than deadline, since once that happens we know
|
||||
// nothing past that point is expired.
|
||||
last_expired_timeout = nullptr;
|
||||
for (nsTimeout *timeout = mTimeouts.getFirst();
|
||||
for (Timeout* timeout = mTimeouts.getFirst();
|
||||
timeout && timeout->mWhen <= deadline;
|
||||
timeout = timeout->getNext()) {
|
||||
if (timeout->mFiringDepth == 0) {
|
||||
|
@ -12548,18 +12485,18 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
|
|||
// timeouts that will be processed in a future call to
|
||||
// win_run_timeout(). This dummy timeout serves as the head of the
|
||||
// list for any timeouts inserted as a result of running a timeout.
|
||||
RefPtr<nsTimeout> dummy_timeout = new nsTimeout();
|
||||
RefPtr<Timeout> dummy_timeout = new Timeout();
|
||||
dummy_timeout->mFiringDepth = firingDepth;
|
||||
dummy_timeout->mWhen = now;
|
||||
last_expired_timeout->setNext(dummy_timeout);
|
||||
RefPtr<nsTimeout> timeoutExtraRef(dummy_timeout);
|
||||
RefPtr<Timeout> timeoutExtraRef(dummy_timeout);
|
||||
|
||||
last_insertion_point = mTimeoutInsertionPoint;
|
||||
// If we ever start setting mTimeoutInsertionPoint to a non-dummy timeout,
|
||||
// the logic in ResetTimersForNonBackgroundWindow will need to change.
|
||||
mTimeoutInsertionPoint = dummy_timeout;
|
||||
|
||||
for (nsTimeout *timeout = mTimeouts.getFirst();
|
||||
for (Timeout* timeout = mTimeouts.getFirst();
|
||||
timeout != dummy_timeout && !IsFrozen();
|
||||
timeout = nextTimeout) {
|
||||
nextTimeout = timeout->getNext();
|
||||
|
@ -12636,15 +12573,15 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout)
|
|||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::ClearTimeoutOrInterval(int32_t aTimerID)
|
||||
nsGlobalWindow::ClearTimeoutOrInterval(int32_t aTimerId)
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(IsInnerWindow());
|
||||
|
||||
uint32_t public_id = (uint32_t)aTimerID;
|
||||
nsTimeout *timeout;
|
||||
uint32_t timerId = (uint32_t)aTimerId;
|
||||
Timeout* timeout;
|
||||
|
||||
for (timeout = mTimeouts.getFirst(); timeout; timeout = timeout->getNext()) {
|
||||
if (timeout->mPublicId == public_id) {
|
||||
if (timeout->mPublicId == timerId) {
|
||||
if (timeout->mRunning) {
|
||||
/* We're running from inside the timeout. Mark this
|
||||
timeout for deferred deletion by the code in
|
||||
|
@ -12685,7 +12622,7 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
|
|||
// anything with mTimeoutInsertionPoint or anything before it, so should
|
||||
// start at the timer after mTimeoutInsertionPoint, if there is one.
|
||||
// Otherwise, start at the beginning of the list.
|
||||
for (nsTimeout *timeout = mTimeoutInsertionPoint ?
|
||||
for (Timeout* timeout = mTimeoutInsertionPoint ?
|
||||
mTimeoutInsertionPoint->getNext() : mTimeouts.getFirst();
|
||||
timeout; ) {
|
||||
// It's important that this check be <= so that we guarantee that
|
||||
|
@ -12729,7 +12666,7 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
|
|||
|
||||
// Get the pointer to the next timeout now, before we move the
|
||||
// current timeout in the list.
|
||||
nsTimeout* nextTimeout = timeout->getNext();
|
||||
Timeout* nextTimeout = timeout->getNext();
|
||||
|
||||
// It is safe to remove and re-insert because mWhen is now
|
||||
// strictly smaller than it used to be, so we know we'll insert
|
||||
|
@ -12763,7 +12700,8 @@ nsresult nsGlobalWindow::ResetTimersForNonBackgroundWindow()
|
|||
void
|
||||
nsGlobalWindow::ClearAllTimeouts()
|
||||
{
|
||||
nsTimeout *timeout, *nextTimeout;
|
||||
Timeout* timeout;
|
||||
Timeout* nextTimeout;
|
||||
|
||||
for (timeout = mTimeouts.getFirst(); timeout; timeout = nextTimeout) {
|
||||
/* If RunTimeout() is higher up on the stack for this
|
||||
|
@ -12798,7 +12736,7 @@ nsGlobalWindow::ClearAllTimeouts()
|
|||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::InsertTimeoutIntoList(nsTimeout *aTimeout)
|
||||
nsGlobalWindow::InsertTimeoutIntoList(Timeout* aTimeout)
|
||||
{
|
||||
NS_ASSERTION(IsInnerWindow(),
|
||||
"InsertTimeoutIntoList() called on outer window!");
|
||||
|
@ -12806,7 +12744,7 @@ nsGlobalWindow::InsertTimeoutIntoList(nsTimeout *aTimeout)
|
|||
// Start at mLastTimeout and go backwards. Don't go further than
|
||||
// mTimeoutInsertionPoint, though. This optimizes for the common case of
|
||||
// insertion at the end.
|
||||
nsTimeout* prevSibling;
|
||||
Timeout* prevSibling;
|
||||
for (prevSibling = mTimeouts.getLast();
|
||||
prevSibling && prevSibling != mTimeoutInsertionPoint &&
|
||||
// This condition needs to match the one in SetTimeoutOrInterval that
|
||||
|
@ -12836,24 +12774,11 @@ nsGlobalWindow::InsertTimeoutIntoList(nsTimeout *aTimeout)
|
|||
void
|
||||
nsGlobalWindow::TimerCallback(nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
RefPtr<nsTimeout> timeout = (nsTimeout *)aClosure;
|
||||
RefPtr<Timeout> timeout = (Timeout*)aClosure;
|
||||
|
||||
timeout->mWindow->RunTimeout(timeout);
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
nsGlobalWindow::TimerNameCallback(nsITimer* aTimer, void* aClosure, char* aBuf,
|
||||
size_t aLen)
|
||||
{
|
||||
RefPtr<nsTimeout> timeout = (nsTimeout*)aClosure;
|
||||
|
||||
const char* filename;
|
||||
uint32_t lineNum, column;
|
||||
timeout->mScriptHandler->GetLocation(&filename, &lineNum, &column);
|
||||
snprintf(aBuf, aLen, "[content] %s:%u:%u", filename, lineNum, column);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// nsGlobalWindow: Helper Functions
|
||||
//*****************************************************************************
|
||||
|
@ -13080,7 +13005,7 @@ nsGlobalWindow::SuspendTimeouts(uint32_t aIncrease,
|
|||
}
|
||||
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
for (nsTimeout *t = mTimeouts.getFirst(); t; t = t->getNext()) {
|
||||
for (Timeout* t = mTimeouts.getFirst(); t; t = t->getNext()) {
|
||||
// Set mTimeRemaining to be the time remaining for this timer.
|
||||
if (t->mWhen > now)
|
||||
t->mTimeRemaining = t->mWhen - now;
|
||||
|
@ -13174,7 +13099,7 @@ nsGlobalWindow::ResumeTimeouts(bool aThawChildren, bool aThawWorkers)
|
|||
bool _seenDummyTimeout = false;
|
||||
#endif
|
||||
|
||||
for (nsTimeout *t = mTimeouts.getFirst(); t; t = t->getNext()) {
|
||||
for (Timeout* t = mTimeouts.getFirst(); t; t = t->getNext()) {
|
||||
// There's a chance we're being called with RunTimeout on the stack in which
|
||||
// case we have a dummy timeout in the list that *must not* be resumed. It
|
||||
// can be identified by a null mWindow.
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "nsSize.h"
|
||||
#include "nsCheapSets.h"
|
||||
#include "mozilla/dom/ImageBitmapSource.h"
|
||||
#include "mozilla/dom/Timeout.h"
|
||||
|
||||
#define DEFAULT_HOME_PAGE "www.mozilla.org"
|
||||
#define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
|
||||
|
@ -121,6 +122,7 @@ struct RequestInit;
|
|||
class RequestOrUSVString;
|
||||
class Selection;
|
||||
class SpeechSynthesis;
|
||||
class Timeout;
|
||||
class U2F;
|
||||
class VRDisplay;
|
||||
class VREventObserver;
|
||||
|
@ -148,69 +150,6 @@ NS_CreateJSTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
|
|||
|
||||
extern const js::Class OuterWindowProxyClass;
|
||||
|
||||
/*
|
||||
* Timeout struct that holds information about each script
|
||||
* timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which
|
||||
* abstracts the language specific cruft.
|
||||
*/
|
||||
struct nsTimeout final
|
||||
: mozilla::LinkedListElement<nsTimeout>
|
||||
{
|
||||
private:
|
||||
~nsTimeout();
|
||||
|
||||
public:
|
||||
nsTimeout();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsTimeout)
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsTimeout)
|
||||
|
||||
nsresult InitTimer(uint32_t aDelay);
|
||||
|
||||
bool HasRefCntOne();
|
||||
|
||||
// Window for which this timeout fires
|
||||
RefPtr<nsGlobalWindow> mWindow;
|
||||
|
||||
// The actual timer object
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
|
||||
// True if the timeout was cleared
|
||||
bool mCleared;
|
||||
|
||||
// True if this is one of the timeouts that are currently running
|
||||
bool mRunning;
|
||||
|
||||
// True if this is a repeating/interval timer
|
||||
bool mIsInterval;
|
||||
|
||||
// Returned as value of setTimeout()
|
||||
uint32_t mPublicId;
|
||||
|
||||
// Interval in milliseconds
|
||||
uint32_t mInterval;
|
||||
|
||||
// mWhen and mTimeRemaining can't be in a union, sadly, because they
|
||||
// have constructors.
|
||||
// Nominal time to run this timeout. Use only when timeouts are not
|
||||
// suspended.
|
||||
mozilla::TimeStamp mWhen;
|
||||
// Remaining time to wait. Used only when timeouts are suspended.
|
||||
mozilla::TimeDuration mTimeRemaining;
|
||||
|
||||
// stack depth at which timeout is firing
|
||||
uint32_t mFiringDepth;
|
||||
|
||||
uint32_t mNestingLevel;
|
||||
|
||||
// The popup state at timeout creation time if not created from
|
||||
// another timeout
|
||||
PopupControlState mPopupState;
|
||||
|
||||
// The language-specific information about the callback.
|
||||
nsCOMPtr<nsIScriptTimeoutHandler> mScriptHandler;
|
||||
};
|
||||
|
||||
struct IdleObserverHolder
|
||||
{
|
||||
nsCOMPtr<nsIIdleObserver> mIdleObserver;
|
||||
|
@ -1501,9 +1440,9 @@ public:
|
|||
// Timeout Functions
|
||||
// Language agnostic timeout function (all args passed).
|
||||
// |interval| is in milliseconds.
|
||||
nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
|
||||
int32_t interval,
|
||||
bool aIsInterval, int32_t* aReturn);
|
||||
nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler* aHandler,
|
||||
int32_t interval, bool aIsInterval,
|
||||
int32_t* aReturn);
|
||||
int32_t SetTimeoutOrInterval(JSContext* aCx,
|
||||
mozilla::dom::Function& aFunction,
|
||||
int32_t aTimeout,
|
||||
|
@ -1512,27 +1451,25 @@ public:
|
|||
int32_t SetTimeoutOrInterval(JSContext* aCx, const nsAString& aHandler,
|
||||
int32_t aTimeout, bool aIsInterval,
|
||||
mozilla::ErrorResult& aError);
|
||||
void ClearTimeoutOrInterval(int32_t aTimerID);
|
||||
void ClearTimeoutOrInterval(int32_t aTimerId);
|
||||
|
||||
// JS specific timeout functions (JS args grabbed from context).
|
||||
nsresult ResetTimersForNonBackgroundWindow();
|
||||
|
||||
// The timeout implementation functions.
|
||||
void RunTimeout(nsTimeout *aTimeout);
|
||||
void RunTimeout(mozilla::dom::Timeout* aTimeout);
|
||||
void RunTimeout() { RunTimeout(nullptr); }
|
||||
// Return true if |aTimeout| was cleared while its handler ran.
|
||||
bool RunTimeoutHandler(nsTimeout* aTimeout, nsIScriptContext* aScx);
|
||||
bool RunTimeoutHandler(mozilla::dom::Timeout* aTimeout, nsIScriptContext* aScx);
|
||||
// Return true if |aTimeout| needs to be reinserted into the timeout list.
|
||||
bool RescheduleTimeout(nsTimeout* aTimeout, const TimeStamp& now,
|
||||
bool RescheduleTimeout(mozilla::dom::Timeout* aTimeout, const TimeStamp& now,
|
||||
bool aRunningPendingTimeouts);
|
||||
|
||||
void ClearAllTimeouts();
|
||||
// Insert aTimeout into the list, before all timeouts that would
|
||||
// fire after it, but no earlier than mTimeoutInsertionPoint, if any.
|
||||
void InsertTimeoutIntoList(nsTimeout *aTimeout);
|
||||
void InsertTimeoutIntoList(mozilla::dom::Timeout* aTimeout);
|
||||
static void TimerCallback(nsITimer *aTimer, void *aClosure);
|
||||
static void TimerNameCallback(nsITimer* aTimer, void* aClosure, char* aBuf,
|
||||
size_t aLen);
|
||||
|
||||
// Helper Functions
|
||||
already_AddRefed<nsIDocShellTreeOwner> GetTreeOwner();
|
||||
|
@ -1884,11 +1821,11 @@ protected:
|
|||
// non-null. In that case, the dummy timeout pointed to by
|
||||
// mTimeoutInsertionPoint may have a later mWhen than some of the timeouts
|
||||
// that come after it.
|
||||
mozilla::LinkedList<nsTimeout> mTimeouts;
|
||||
mozilla::LinkedList<mozilla::dom::Timeout> mTimeouts;
|
||||
// If mTimeoutInsertionPoint is non-null, insertions should happen after it.
|
||||
// This is a dummy timeout at the moment; if that ever changes, the logic in
|
||||
// ResetTimersForNonBackgroundWindow needs to change.
|
||||
nsTimeout* mTimeoutInsertionPoint;
|
||||
mozilla::dom::Timeout* mTimeoutInsertionPoint;
|
||||
uint32_t mTimeoutPublicIdCounter;
|
||||
uint32_t mTimeoutFiringDepth;
|
||||
RefPtr<mozilla::dom::Location> mLocation;
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "nsTArray.h"
|
||||
#include "js/TypeDecls.h"
|
||||
#include "mozilla/Function.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -31,7 +33,7 @@ public:
|
|||
|
||||
// Get the Function to call. If this returns nullptr, GetHandlerText() will
|
||||
// be called to get the string.
|
||||
virtual mozilla::dom::Function *GetCallback() = 0;
|
||||
virtual mozilla::dom::Function* GetCallback() = 0;
|
||||
|
||||
// Get the handler text of not a compiled object.
|
||||
virtual const nsAString& GetHandlerText() = 0;
|
||||
|
|
|
@ -4,21 +4,24 @@
|
|||
* 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 <algorithm>
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Function.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/dom/FunctionBinding.h"
|
||||
#include "nsAXPCNativeCallContext.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIScriptTimeoutHandler.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsError.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsIContentSecurityPolicy.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Likely.h"
|
||||
#include <algorithm>
|
||||
#include "mozilla/dom/FunctionBinding.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIScriptTimeoutHandler.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "WorkerPrivate.h"
|
||||
#include "nsAXPCNativeCallContext.h"
|
||||
|
||||
static const char kSetIntervalStr[] = "setInterval";
|
||||
static const char kSetTimeoutStr[] = "setTimeout";
|
||||
|
@ -37,11 +40,11 @@ public:
|
|||
|
||||
nsJSScriptTimeoutHandler();
|
||||
// This will call SwapElements on aArguments with an empty array.
|
||||
nsJSScriptTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
|
||||
nsJSScriptTimeoutHandler(JSContext* aCx, nsGlobalWindow* aWindow,
|
||||
Function& aFunction,
|
||||
nsTArray<JS::Heap<JS::Value>>&& aArguments,
|
||||
ErrorResult& aError);
|
||||
nsJSScriptTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
|
||||
nsJSScriptTimeoutHandler(JSContext* aCx, nsGlobalWindow* aWindow,
|
||||
const nsAString& aExpression, bool* aAllowEval,
|
||||
ErrorResult& aError);
|
||||
nsJSScriptTimeoutHandler(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
||||
|
@ -51,10 +54,12 @@ public:
|
|||
const nsAString& aExpression);
|
||||
|
||||
virtual const nsAString& GetHandlerText() override;
|
||||
|
||||
virtual Function* GetCallback() override
|
||||
{
|
||||
return mFunction;
|
||||
}
|
||||
|
||||
virtual void GetLocation(const char** aFileName, uint32_t* aLineNo,
|
||||
uint32_t* aColumn) override
|
||||
{
|
||||
|
|
|
@ -36,7 +36,6 @@ class nsPIDOMWindowInner;
|
|||
class nsPIDOMWindowOuter;
|
||||
class nsPIWindowRoot;
|
||||
class nsXBLPrototypeHandler;
|
||||
struct nsTimeout;
|
||||
|
||||
typedef uint32_t SuspendTypes;
|
||||
|
||||
|
@ -46,6 +45,7 @@ class AudioContext;
|
|||
class Element;
|
||||
class Performance;
|
||||
class ServiceWorkerRegistration;
|
||||
class Timeout;
|
||||
class CustomElementRegistry;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -627,7 +627,7 @@ protected:
|
|||
uint32_t mModalStateDepth;
|
||||
|
||||
// These variables are only used on inner windows.
|
||||
nsTimeout *mRunningTimeout;
|
||||
mozilla::dom::Timeout *mRunningTimeout;
|
||||
|
||||
uint32_t mMutationBits;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче