summaryrefslogtreecommitdiffstats
path: root/dom/base/Timeout.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/Timeout.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/Timeout.cpp')
-rw-r--r--dom/base/Timeout.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/dom/base/Timeout.cpp b/dom/base/Timeout.cpp
new file mode 100644
index 0000000000..1619231007
--- /dev/null
+++ b/dom/base/Timeout.cpp
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 "mozilla/dom/TimeoutManager.h"
+#include "nsGlobalWindowInner.h"
+#include "GeckoProfiler.h"
+
+namespace mozilla::dom {
+
+Timeout::Timeout()
+ : mTimeoutId(0),
+ mFiringId(TimeoutManager::InvalidFiringId),
+#ifdef DEBUG
+ mFiringIndex(-1),
+#endif
+ mPopupState(PopupBlocker::openAllowed),
+ mReason(Reason::eTimeoutOrInterval),
+ mNestingLevel(0),
+ mCleared(false),
+ mRunning(false),
+ mIsInterval(false) {
+}
+
+NS_IMPL_CYCLE_COLLECTION_CLASS(Timeout)
+
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Timeout)
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
+ NS_IMPL_CYCLE_COLLECTION_UNLINK(mScriptHandler)
+ if (tmp->isInList()) {
+ tmp->remove();
+ }
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Timeout)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScriptHandler)
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
+
+void Timeout::SetWhenOrTimeRemaining(const TimeStamp& aBaseTime,
+ const TimeDuration& aDelay) {
+ MOZ_DIAGNOSTIC_ASSERT(mWindow);
+ mSubmitTime = aBaseTime;
+
+ mSubmitTime = aBaseTime;
+ if (profiler_is_active()) {
+ mCause = profiler_capture_backtrace();
+ }
+
+ // If we are frozen simply set mTimeRemaining to be the "time remaining" in
+ // the timeout (i.e., the interval itself). This will be used to create a
+ // new mWhen time when the window is thawed. The end effect is that time does
+ // not appear to pass for frozen windows.
+ if (mWindow->IsFrozen()) {
+ mWhen = TimeStamp();
+ mTimeRemaining = aDelay;
+ return;
+ }
+
+ // Since we are not frozen we must set a precise mWhen target wakeup
+ // time. Even if we are suspended we want to use this target time so
+ // that it appears time passes while suspended.
+ mWhen = aBaseTime + aDelay;
+ mTimeRemaining = TimeDuration(0);
+}
+
+const TimeStamp& Timeout::When() const {
+ MOZ_DIAGNOSTIC_ASSERT(!mWhen.IsNull());
+ // Note, mWindow->IsFrozen() can be true here. The Freeze() method calls
+ // When() to calculate the delay to populate mTimeRemaining.
+ return mWhen;
+}
+
+const TimeStamp& Timeout::SubmitTime() const { return mSubmitTime; }
+
+const TimeDuration& Timeout::TimeRemaining() const {
+ MOZ_DIAGNOSTIC_ASSERT(mWhen.IsNull());
+ // Note, mWindow->IsFrozen() can be false here. The Thaw() method calls
+ // TimeRemaining() to calculate the new When() value.
+ return mTimeRemaining;
+}
+
+} // namespace mozilla::dom