summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/DOMTimer.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/page/DOMTimer.h')
-rw-r--r--Source/WebCore/page/DOMTimer.h92
1 files changed, 55 insertions, 37 deletions
diff --git a/Source/WebCore/page/DOMTimer.h b/Source/WebCore/page/DOMTimer.h
index a47dd5f7c..39a0461da 100644
--- a/Source/WebCore/page/DOMTimer.h
+++ b/Source/WebCore/page/DOMTimer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2014 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -24,53 +24,71 @@
*
*/
-#ifndef DOMTimer_h
-#define DOMTimer_h
+#pragma once
#include "SuspendableTimer.h"
-#include <wtf/OwnPtr.h>
-#include <wtf/PassOwnPtr.h>
+#include "UserGestureIndicator.h"
+#include <memory>
+#include <wtf/RefCounted.h>
namespace WebCore {
- class ScheduledAction;
+class DOMTimerFireState;
+class Document;
+class HTMLPlugInElement;
+class ScheduledAction;
- class DOMTimer final : public SuspendableTimer {
- public:
- virtual ~DOMTimer();
- // Creates a new timer owned by specified ScriptExecutionContext, starts it
- // and returns its Id.
- static int install(ScriptExecutionContext*, PassOwnPtr<ScheduledAction>, int timeout, bool singleShot);
- static void removeById(ScriptExecutionContext*, int timeoutId);
+class DOMTimer final : public RefCounted<DOMTimer>, public SuspendableTimer {
+ WTF_MAKE_NONCOPYABLE(DOMTimer);
+ WTF_MAKE_FAST_ALLOCATED;
+public:
+ virtual ~DOMTimer();
- // Adjust to a change in the ScriptExecutionContext's minimum timer interval.
- // This allows the minimum allowable interval time to be changed in response
- // to events like moving a tab to the background.
- void adjustMinimumTimerInterval(double oldMinimumTimerInterval);
+ static std::chrono::milliseconds defaultMinimumInterval() { return 4ms; }
+ static std::chrono::milliseconds defaultAlignmentInterval() { return 0ms; }
+ static std::chrono::milliseconds hiddenPageAlignmentInterval() { return 1000ms; }
- private:
- DOMTimer(ScriptExecutionContext*, PassOwnPtr<ScheduledAction>, int interval, bool singleShot);
- virtual void fired() override;
+ // Creates a new timer owned by specified ScriptExecutionContext, starts it
+ // and returns its Id.
+ static int install(ScriptExecutionContext&, std::unique_ptr<ScheduledAction>, std::chrono::milliseconds timeout, bool singleShot);
+ static void removeById(ScriptExecutionContext&, int timeoutId);
- // ActiveDOMObject
- virtual void contextDestroyed() override;
+ // Notify that the interval may need updating (e.g. because the minimum interval
+ // setting for the context has changed).
+ void updateTimerIntervalIfNecessary();
- // SuspendableTimer
- virtual void didStop() override;
+ static void scriptDidInteractWithPlugin(HTMLPlugInElement&);
- double intervalClampedToMinimum(int timeout, double minimumTimerInterval) const;
+private:
+ DOMTimer(ScriptExecutionContext&, std::unique_ptr<ScheduledAction>, std::chrono::milliseconds interval, bool singleShot);
+ friend class Internals;
- // Retuns timer fire time rounded to the next multiple of timer alignment interval.
- virtual double alignedFireTime(double) const override;
+ std::chrono::milliseconds intervalClampedToMinimum() const;
- int m_timeoutId;
- int m_nestingLevel;
- OwnPtr<ScheduledAction> m_action;
- int m_originalInterval;
- bool m_shouldForwardUserGesture;
- };
+ bool isDOMTimersThrottlingEnabled(Document&) const;
+ void updateThrottlingStateIfNecessary(const DOMTimerFireState&);
-} // namespace WebCore
+ // SuspendableTimer
+ void fired() override;
+ void didStop() override;
+ std::optional<std::chrono::milliseconds> alignedFireTime(std::chrono::milliseconds) const override;
+
+ // ActiveDOMObject API.
+ const char* activeDOMObjectName() const override;
-#endif // DOMTimer_h
+ enum TimerThrottleState {
+ Undetermined,
+ ShouldThrottle,
+ ShouldNotThrottle
+ };
+
+ int m_timeoutId;
+ int m_nestingLevel;
+ std::unique_ptr<ScheduledAction> m_action;
+ std::chrono::milliseconds m_originalInterval;
+ TimerThrottleState m_throttleState;
+ std::chrono::milliseconds m_currentTimerInterval;
+ RefPtr<UserGestureToken> m_userGestureTokenToForward;
+};
+} // namespace WebCore