1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/dom/TimeoutManager.h"
10 #include "nsGlobalWindowInner.h"
11 #include "GeckoProfiler.h"
13 namespace mozilla::dom
{
17 mFiringId(TimeoutManager::InvalidFiringId
),
21 mPopupState(PopupBlocker::openAllowed
),
22 mReason(Reason::eTimeoutOrInterval
),
29 NS_IMPL_CYCLE_COLLECTION_CLASS(Timeout
)
31 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Timeout
)
32 NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow
)
33 NS_IMPL_CYCLE_COLLECTION_UNLINK(mScriptHandler
)
34 if (tmp
->isInList()) {
37 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
39 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Timeout
)
40 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow
)
41 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptHandler
)
42 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
44 void Timeout::SetWhenOrTimeRemaining(const TimeStamp
& aBaseTime
,
45 const TimeDuration
& aDelay
) {
46 MOZ_DIAGNOSTIC_ASSERT(mWindow
);
47 mSubmitTime
= aBaseTime
;
49 mSubmitTime
= aBaseTime
;
50 if (profiler_is_active()) {
51 mCause
= profiler_capture_backtrace();
54 // If we are frozen simply set mTimeRemaining to be the "time remaining" in
55 // the timeout (i.e., the interval itself). This will be used to create a
56 // new mWhen time when the window is thawed. The end effect is that time does
57 // not appear to pass for frozen windows.
58 if (mWindow
->IsFrozen()) {
60 mTimeRemaining
= aDelay
;
64 // Since we are not frozen we must set a precise mWhen target wakeup
65 // time. Even if we are suspended we want to use this target time so
66 // that it appears time passes while suspended.
67 mWhen
= aBaseTime
+ aDelay
;
68 mTimeRemaining
= TimeDuration(0);
71 const TimeStamp
& Timeout::When() const {
72 MOZ_DIAGNOSTIC_ASSERT(!mWhen
.IsNull());
73 // Note, mWindow->IsFrozen() can be true here. The Freeze() method calls
74 // When() to calculate the delay to populate mTimeRemaining.
78 const TimeStamp
& Timeout::SubmitTime() const { return mSubmitTime
; }
80 const TimeDuration
& Timeout::TimeRemaining() const {
81 MOZ_DIAGNOSTIC_ASSERT(mWhen
.IsNull());
82 // Note, mWindow->IsFrozen() can be false here. The Thaw() method calls
83 // TimeRemaining() to calculate the new When() value.
84 return mTimeRemaining
;
87 } // namespace mozilla::dom