Title: [250464] trunk
Revision
250464
Author
[email protected]
Date
2019-09-27 15:42:20 -0700 (Fri, 27 Sep 2019)

Log Message

Pages using WebGLRenderingContext fail to enter the back/forward cache
https://bugs.webkit.org/show_bug.cgi?id=202318
<rdar://problem/55783612>

Reviewed by Tim Horton.

Source/WebCore:

Allow pages with a WebGLRenderingContext to enter the back/forward cache by updating the
implementation to use SuspendableTimers to fire JS events. This guarantees that no events
will be fired (and thus no JS will run) while in the page cache.

This was preventing some of the pages on weather.com and facebook.com from entering the
back/forward cache.

Test: fast/canvas/webgl/canvas-webgl-page-cache.html

* dom/DocumentEventQueue.cpp:
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase):
(WebCore::WebGLRenderingContextBase::canSuspendForDocumentSuspension const):
(WebCore::WebGLRenderingContextBase::suspend):
(WebCore::WebGLRenderingContextBase::resume):
(WebCore::WebGLRenderingContextBase::dispatchContextLostEvent):
(WebCore::WebGLRenderingContextBase::maybeRestoreContext):
(WebCore::WebGLRenderingContextBase::dispatchContextChangedNotification):
(WebCore::WebGLRenderingContextBase::dispatchContextChangedEvent):
* html/canvas/WebGLRenderingContextBase.h:
* page/DOMTimer.cpp:
(WebCore::DOMTimer::DOMTimer):
* page/DOMTimer.h:
* page/SuspendableTimer.cpp:
(WebCore::SuspendableTimerBase::SuspendableTimerBase):
(WebCore::SuspendableTimerBase::hasPendingActivity const):
(WebCore::SuspendableTimerBase::stop):
(WebCore::SuspendableTimerBase::suspend):
(WebCore::SuspendableTimerBase::resume):
(WebCore::SuspendableTimerBase::canSuspendForDocumentSuspension const):
(WebCore::SuspendableTimerBase::didStop):
(WebCore::SuspendableTimerBase::cancel):
(WebCore::SuspendableTimerBase::startRepeating):
(WebCore::SuspendableTimerBase::startOneShot):
(WebCore::SuspendableTimerBase::repeatInterval const):
(WebCore::SuspendableTimerBase::augmentFireInterval):
(WebCore::SuspendableTimerBase::augmentRepeatInterval):
(WebCore::SuspendableTimer::activeDOMObjectName const):
* page/SuspendableTimer.h:

Source/WebKitLegacy/win:

* WebView.cpp:
(WindowCloseTimer::WindowCloseTimer):
(WindowCloseTimer::contextDestroyed):
* WebView.h:

LayoutTests:

Add layout test coverage.

* fast/canvas/webgl/canvas-webgl-page-cache-expected.txt: Added.
* fast/canvas/webgl/canvas-webgl-page-cache.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (250463 => 250464)


--- trunk/LayoutTests/ChangeLog	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/LayoutTests/ChangeLog	2019-09-27 22:42:20 UTC (rev 250464)
@@ -1,3 +1,16 @@
+2019-09-27  Chris Dumez  <[email protected]>
+
+        Pages using WebGLRenderingContext fail to enter the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=202318
+        <rdar://problem/55783612>
+
+        Reviewed by Tim Horton.
+
+        Add layout test coverage.
+
+        * fast/canvas/webgl/canvas-webgl-page-cache-expected.txt: Added.
+        * fast/canvas/webgl/canvas-webgl-page-cache.html: Added.
+
 2019-09-27  Andres Gonzalez  <[email protected]>
 
         Support accessibility for <figure> element on iOS.

Added: trunk/LayoutTests/fast/canvas/webgl/canvas-webgl-page-cache-expected.txt (0 => 250464)


--- trunk/LayoutTests/fast/canvas/webgl/canvas-webgl-page-cache-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/canvas-webgl-page-cache-expected.txt	2019-09-27 22:42:20 UTC (rev 250464)
@@ -0,0 +1,14 @@
+Tests that a page with a WebGLRenderingContext is able to enter the back/forward cache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Canvas did not crash on resize.
+pageshow - not from page cache
+pagehide - entering page cache
+pageshow - from page cache
+PASS Page entered page cache
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/webgl/canvas-webgl-page-cache.html (0 => 250464)


--- trunk/LayoutTests/fast/canvas/webgl/canvas-webgl-page-cache.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/canvas-webgl-page-cache.html	2019-09-27 22:42:20 UTC (rev 250464)
@@ -0,0 +1,50 @@
+<!-- webkit-test-runner [ enablePageCache=true ] -->
+<html>
+<head>
+<style>
+#example {
+  width: 100%;
+  height: 100%;
+}
+</style>
+<script src=""
+<script src="" </script>
+<script>
+description('Tests that a page with a WebGLRenderingContext is able to enter the back/forward cache.');
+jsTestIsAsync = true;
+
+window.addEventListener("pageshow", function(event) {
+  debug("pageshow - " + (event.persisted ? "" : "not ") + "from page cache");
+  if (event.persisted) {
+      testPassed("Page entered page cache");
+      finishJSTest();
+  }
+});
+
+window.addEventListener("pagehide", function(event) {
+    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering page cache");
+    if (!event.persisted) {
+        testFailed("Page failed to enter page cache");
+        finishJSTest();
+    }
+});
+
+function start()
+{
+    canvas = document.getElementById('example');
+    gl = WebGLTestUtils.create3DContext(canvas);
+
+    setTimeout(() => {
+        window.location = "../../history/resources/page-cache-helper.html";
+    }, 0);
+}
+
+testPassed("Canvas did not crash on resize.");
+</script>
+</head>
+
+<body _onload_="start()">
+    <canvas id="example"></canvas>
+</body>
+</html>
+

Modified: trunk/LayoutTests/http/tests/security/navigate-when-restoring-cached-page.html (250463 => 250464)


--- trunk/LayoutTests/http/tests/security/navigate-when-restoring-cached-page.html	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/LayoutTests/http/tests/security/navigate-when-restoring-cached-page.html	2019-09-27 22:42:20 UTC (rev 250464)
@@ -60,10 +60,11 @@
             return;
           
           clearInterval(interval_id);
+
+          // Prevent entering PageCache.
+          peerConnection = new w.RTCPeerConnection();
+          peerConnection.addEventListener('onicecandidate', (e) => { });
           
-          canvas = w.document.body.appendChild(document.createElement('canvas'));
-          context = canvas.getContext('webgl');
-          
           child_frame = w.document.body.appendChild(document.createElement('iframe'));
           child_frame.contentWindow._onunload_ = () => {
             child_frame.contentWindow._onunload_ = null;

Modified: trunk/Source/WebCore/ChangeLog (250463 => 250464)


--- trunk/Source/WebCore/ChangeLog	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/ChangeLog	2019-09-27 22:42:20 UTC (rev 250464)
@@ -1,3 +1,51 @@
+2019-09-27  Chris Dumez  <[email protected]>
+
+        Pages using WebGLRenderingContext fail to enter the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=202318
+        <rdar://problem/55783612>
+
+        Reviewed by Tim Horton.
+
+        Allow pages with a WebGLRenderingContext to enter the back/forward cache by updating the
+        implementation to use SuspendableTimers to fire JS events. This guarantees that no events
+        will be fired (and thus no JS will run) while in the page cache.
+
+        This was preventing some of the pages on weather.com and facebook.com from entering the
+        back/forward cache.
+
+        Test: fast/canvas/webgl/canvas-webgl-page-cache.html
+
+        * dom/DocumentEventQueue.cpp:
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase):
+        (WebCore::WebGLRenderingContextBase::canSuspendForDocumentSuspension const):
+        (WebCore::WebGLRenderingContextBase::suspend):
+        (WebCore::WebGLRenderingContextBase::resume):
+        (WebCore::WebGLRenderingContextBase::dispatchContextLostEvent):
+        (WebCore::WebGLRenderingContextBase::maybeRestoreContext):
+        (WebCore::WebGLRenderingContextBase::dispatchContextChangedNotification):
+        (WebCore::WebGLRenderingContextBase::dispatchContextChangedEvent):
+        * html/canvas/WebGLRenderingContextBase.h:
+        * page/DOMTimer.cpp:
+        (WebCore::DOMTimer::DOMTimer):
+        * page/DOMTimer.h:
+        * page/SuspendableTimer.cpp:
+        (WebCore::SuspendableTimerBase::SuspendableTimerBase):
+        (WebCore::SuspendableTimerBase::hasPendingActivity const):
+        (WebCore::SuspendableTimerBase::stop):
+        (WebCore::SuspendableTimerBase::suspend):
+        (WebCore::SuspendableTimerBase::resume):
+        (WebCore::SuspendableTimerBase::canSuspendForDocumentSuspension const):
+        (WebCore::SuspendableTimerBase::didStop):
+        (WebCore::SuspendableTimerBase::cancel):
+        (WebCore::SuspendableTimerBase::startRepeating):
+        (WebCore::SuspendableTimerBase::startOneShot):
+        (WebCore::SuspendableTimerBase::repeatInterval const):
+        (WebCore::SuspendableTimerBase::augmentFireInterval):
+        (WebCore::SuspendableTimerBase::augmentRepeatInterval):
+        (WebCore::SuspendableTimer::activeDOMObjectName const):
+        * page/SuspendableTimer.h:
+
 2019-09-27  Adrian Perez de Castro  <[email protected]>
 
         [GTK][WPE] Fixes for non-unified builds after r249714

Modified: trunk/Source/WebCore/dom/DocumentEventQueue.cpp (250463 => 250464)


--- trunk/Source/WebCore/dom/DocumentEventQueue.cpp	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/dom/DocumentEventQueue.cpp	2019-09-27 22:42:20 UTC (rev 250464)
@@ -37,10 +37,10 @@
 
 namespace WebCore {
     
-class DocumentEventQueue::Timer final : public SuspendableTimer {
+class DocumentEventQueue::Timer final : public SuspendableTimerBase {
 public:
     Timer(DocumentEventQueue& eventQueue)
-        : SuspendableTimer(eventQueue.m_document)
+        : SuspendableTimerBase(&eventQueue.m_document)
         , m_eventQueue(eventQueue)
     {
     }

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (250463 => 250464)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2019-09-27 22:42:20 UTC (rev 250464)
@@ -632,13 +632,18 @@
 
 WebGLRenderingContextBase::WebGLRenderingContextBase(CanvasBase& canvas, WebGLContextAttributes attributes)
     : GPUBasedCanvasRenderingContext(canvas)
-    , m_dispatchContextLostEventTimer(*this, &WebGLRenderingContextBase::dispatchContextLostEvent)
-    , m_restoreTimer(*this, &WebGLRenderingContextBase::maybeRestoreContext)
+    , m_dispatchContextLostEventTimer(canvas.scriptExecutionContext(), *this, &WebGLRenderingContextBase::dispatchContextLostEvent)
+    , m_dispatchContextChangedEventTimer(canvas.scriptExecutionContext(), *this, &WebGLRenderingContextBase::dispatchContextChangedEvent)
+    , m_restoreTimer(canvas.scriptExecutionContext(), *this, &WebGLRenderingContextBase::maybeRestoreContext)
     , m_attributes(attributes)
     , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
     , m_isPendingPolicyResolution(true)
     , m_checkForContextLossHandlingTimer(*this, &WebGLRenderingContextBase::checkForContextLossHandling)
 {
+    m_dispatchContextLostEventTimer.suspendIfNeeded();
+    m_dispatchContextChangedEventTimer.suspendIfNeeded();
+    m_restoreTimer.suspendIfNeeded();
+
     registerWithWebGLStateTracker();
     m_checkForContextLossHandlingTimer.startOneShot(checkContextLossHandlingDelay);
 }
@@ -646,13 +651,18 @@
 WebGLRenderingContextBase::WebGLRenderingContextBase(CanvasBase& canvas, Ref<GraphicsContext3D>&& context, WebGLContextAttributes attributes)
     : GPUBasedCanvasRenderingContext(canvas)
     , m_context(WTFMove(context))
-    , m_dispatchContextLostEventTimer(*this, &WebGLRenderingContextBase::dispatchContextLostEvent)
-    , m_restoreTimer(*this, &WebGLRenderingContextBase::maybeRestoreContext)
+    , m_dispatchContextLostEventTimer(canvas.scriptExecutionContext(), *this, &WebGLRenderingContextBase::dispatchContextLostEvent)
+    , m_dispatchContextChangedEventTimer(canvas.scriptExecutionContext(), *this, &WebGLRenderingContextBase::dispatchContextChangedEvent)
+    , m_restoreTimer(canvas.scriptExecutionContext(), *this, &WebGLRenderingContextBase::maybeRestoreContext)
     , m_generatedImageCache(4)
     , m_attributes(attributes)
     , m_numGLErrorsToConsoleAllowed(maxGLErrorsAllowedToConsole)
     , m_checkForContextLossHandlingTimer(*this, &WebGLRenderingContextBase::checkForContextLossHandling)
 {
+    m_dispatchContextLostEventTimer.suspendIfNeeded();
+    m_dispatchContextChangedEventTimer.suspendIfNeeded();
+    m_restoreTimer.suspendIfNeeded();
+
     m_contextGroup = WebGLContextGroup::create();
     m_contextGroup->addContext(*this);
     
@@ -5197,10 +5207,19 @@
 
 bool WebGLRenderingContextBase::canSuspendForDocumentSuspension() const
 {
-    // FIXME: We should try and do better here.
-    return false;
+    return true;
 }
 
+void WebGLRenderingContextBase::suspend(ReasonForSuspension)
+{
+    m_isSuspended = true;
+}
+
+void WebGLRenderingContextBase::resume()
+{
+    m_isSuspended = false;
+}
+
 bool WebGLRenderingContextBase::getBooleanParameter(GC3Denum pname)
 {
     GC3Dboolean value = 0;
@@ -6151,6 +6170,7 @@
 
 void WebGLRenderingContextBase::dispatchContextLostEvent()
 {
+    RELEASE_ASSERT(!m_isSuspended);
     auto* canvas = htmlCanvas();
     if (!canvas)
         return;
@@ -6164,6 +6184,7 @@
 
 void WebGLRenderingContextBase::maybeRestoreContext()
 {
+    RELEASE_ASSERT(!m_isSuspended);
     ASSERT(m_contextLost);
     if (!m_contextLost)
         return;
@@ -6545,6 +6566,13 @@
 
 void WebGLRenderingContextBase::dispatchContextChangedNotification()
 {
+    if (!m_dispatchContextChangedEventTimer.isActive())
+        m_dispatchContextChangedEventTimer.startOneShot(0_s);
+}
+
+void WebGLRenderingContextBase::dispatchContextChangedEvent()
+{
+    RELEASE_ASSERT(!m_isSuspended);
     auto* canvas = htmlCanvas();
     if (!canvas)
         return;

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (250463 => 250464)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2019-09-27 22:42:20 UTC (rev 250464)
@@ -32,6 +32,7 @@
 #include "GPUBasedCanvasRenderingContext.h"
 #include "GraphicsContext3D.h"
 #include "ImageBuffer.h"
+#include "SuspendableTimer.h"
 #include "Timer.h"
 #include "WebGLAny.h"
 #include "WebGLBuffer.h"
@@ -391,6 +392,8 @@
     void stop() override;
     const char* activeDOMObjectName() const override;
     bool canSuspendForDocumentSuspension() const override;
+    void suspend(ReasonForSuspension) override;
+    void resume() override;
 
     void addSharedObject(WebGLSharedObject&);
     void addContextObject(WebGLContextObject&);
@@ -451,9 +454,10 @@
     // likely that there's no _javascript_ on the stack, but that might be dependent
     // on how exactly the platform discovers that the context was lost. For better
     // portability we always defer the dispatch of the event.
-    Timer m_dispatchContextLostEventTimer;
+    SuspendableTimer m_dispatchContextLostEventTimer;
+    SuspendableTimer m_dispatchContextChangedEventTimer;
     bool m_restoreAllowed { false };
-    Timer m_restoreTimer;
+    SuspendableTimer m_restoreTimer;
 
     bool m_needsUpdate;
     bool m_markedCanvasDirty;
@@ -806,10 +810,6 @@
     bool validateSimulatedVertexAttrib0(GC3Duint numVertex);
     void restoreStatesAfterVertexAttrib0Simulation();
 
-    void dispatchContextLostEvent();
-    // Helper for restoration after context lost.
-    void maybeRestoreContext();
-
     // Wrapper for GraphicsContext3D::synthesizeGLError that sends a message to the _javascript_ console.
     enum ConsoleDisplayPreference { DisplayInConsole, DontDisplayInConsole };
     void synthesizeGLError(GC3Denum, const char* functionName, const char* description, ConsoleDisplayPreference = DisplayInConsole);
@@ -842,6 +842,11 @@
     template <typename T> unsigned getMaxIndex(const RefPtr<JSC::ArrayBuffer> elementArrayBuffer, GC3Dintptr uoffset, GC3Dsizei n);
 
 private:
+    void dispatchContextLostEvent();
+    void dispatchContextChangedEvent();
+    // Helper for restoration after context lost.
+    void maybeRestoreContext();
+
     bool validateArrayBufferType(const char* functionName, GC3Denum type, Optional<JSC::TypedArrayType>);
     void registerWithWebGLStateTracker();
     void checkForContextLossHandling();
@@ -850,6 +855,7 @@
 
     WebGLStateTracker::Token m_trackerToken;
     Timer m_checkForContextLossHandlingTimer;
+    bool m_isSuspended { false };
 };
 
 template <typename T>

Modified: trunk/Source/WebCore/page/DOMTimer.cpp (250463 => 250464)


--- trunk/Source/WebCore/page/DOMTimer.cpp	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/page/DOMTimer.cpp	2019-09-27 22:42:20 UTC (rev 250464)
@@ -161,7 +161,7 @@
 bool NestedTimersMap::isTrackingNestedTimers = false;
 
 DOMTimer::DOMTimer(ScriptExecutionContext& context, std::unique_ptr<ScheduledAction> action, Seconds interval, bool singleShot)
-    : SuspendableTimer(context)
+    : SuspendableTimerBase(&context)
     , m_nestingLevel(context.timerNestingLevel())
     , m_action(WTFMove(action))
     , m_originalInterval(interval)

Modified: trunk/Source/WebCore/page/DOMTimer.h (250463 => 250464)


--- trunk/Source/WebCore/page/DOMTimer.h	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/page/DOMTimer.h	2019-09-27 22:42:20 UTC (rev 250464)
@@ -40,7 +40,7 @@
 class HTMLPlugInElement;
 class ScheduledAction;
 
-class DOMTimer final : public RefCounted<DOMTimer>, public SuspendableTimer {
+class DOMTimer final : public RefCounted<DOMTimer>, public SuspendableTimerBase {
     WTF_MAKE_NONCOPYABLE(DOMTimer);
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -72,7 +72,7 @@
     bool isDOMTimersThrottlingEnabled(Document&) const;
     void updateThrottlingStateIfNecessary(const DOMTimerFireState&);
 
-    // SuspendableTimer
+    // SuspendableTimerBase
     void fired() override;
     void didStop() override;
     WEBCORE_EXPORT Optional<MonotonicTime> alignedFireTime(MonotonicTime) const override;

Modified: trunk/Source/WebCore/page/SuspendableTimer.cpp (250463 => 250464)


--- trunk/Source/WebCore/page/SuspendableTimer.cpp	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/page/SuspendableTimer.cpp	2019-09-27 22:42:20 UTC (rev 250464)
@@ -31,19 +31,19 @@
 
 namespace WebCore {
 
-SuspendableTimer::SuspendableTimer(ScriptExecutionContext& context)
-    : ActiveDOMObject(&context)
+SuspendableTimerBase::SuspendableTimerBase(ScriptExecutionContext* context)
+    : ActiveDOMObject(context)
 {
 }
 
-SuspendableTimer::~SuspendableTimer() = default;
+SuspendableTimerBase::~SuspendableTimerBase() = default;
 
-bool SuspendableTimer::hasPendingActivity() const
+bool SuspendableTimerBase::hasPendingActivity() const
 {
     return isActive();
 }
 
-void SuspendableTimer::stop()
+void SuspendableTimerBase::stop()
 {
     if (!m_suspended)
         TimerBase::stop();
@@ -56,7 +56,7 @@
     didStop();
 }
 
-void SuspendableTimer::suspend(ReasonForSuspension)
+void SuspendableTimerBase::suspend(ReasonForSuspension)
 {
     ASSERT(!m_suspended);
     m_suspended = true;
@@ -69,7 +69,7 @@
     }
 }
 
-void SuspendableTimer::resume()
+void SuspendableTimerBase::resume()
 {
     ASSERT(m_suspended);
     m_suspended = false;
@@ -78,16 +78,16 @@
         start(m_savedNextFireInterval, m_savedRepeatInterval);
 }
 
-bool SuspendableTimer::canSuspendForDocumentSuspension() const
+bool SuspendableTimerBase::canSuspendForDocumentSuspension() const
 {
     return true;
 }
 
-void SuspendableTimer::didStop()
+void SuspendableTimerBase::didStop()
 {
 }
 
-void SuspendableTimer::cancel()
+void SuspendableTimerBase::cancel()
 {
     if (!m_suspended)
         TimerBase::stop();
@@ -95,7 +95,7 @@
         m_suspended = false;
 }
 
-void SuspendableTimer::startRepeating(Seconds repeatInterval)
+void SuspendableTimerBase::startRepeating(Seconds repeatInterval)
 {
     if (!m_suspended)
         TimerBase::startRepeating(repeatInterval);
@@ -106,7 +106,7 @@
     }
 }
 
-void SuspendableTimer::startOneShot(Seconds interval)
+void SuspendableTimerBase::startOneShot(Seconds interval)
 {
     if (!m_suspended)
         TimerBase::startOneShot(interval);
@@ -117,7 +117,7 @@
     }
 }
 
-Seconds SuspendableTimer::repeatInterval() const
+Seconds SuspendableTimerBase::repeatInterval() const
 {
     if (!m_suspended)
         return TimerBase::repeatInterval();
@@ -126,7 +126,7 @@
     return 0_s;
 }
 
-void SuspendableTimer::augmentFireInterval(Seconds delta)
+void SuspendableTimerBase::augmentFireInterval(Seconds delta)
 {
     if (!m_suspended)
         TimerBase::augmentFireInterval(delta);
@@ -139,7 +139,7 @@
     }
 }
 
-void SuspendableTimer::augmentRepeatInterval(Seconds delta)
+void SuspendableTimerBase::augmentRepeatInterval(Seconds delta)
 {
     if (!m_suspended)
         TimerBase::augmentRepeatInterval(delta);
@@ -153,4 +153,9 @@
     }
 }
 
+const char* SuspendableTimer::activeDOMObjectName() const
+{
+    return "SuspendableTimer";
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/SuspendableTimer.h (250463 => 250464)


--- trunk/Source/WebCore/page/SuspendableTimer.h	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebCore/page/SuspendableTimer.h	2019-09-27 22:42:20 UTC (rev 250464)
@@ -29,20 +29,21 @@
 #include "ActiveDOMObject.h"
 #include "Timer.h"
 
+#include <wtf/Function.h>
 #include <wtf/Seconds.h>
 
 namespace WebCore {
 
-class SuspendableTimer : private TimerBase, public ActiveDOMObject {
+class SuspendableTimerBase : private TimerBase, public ActiveDOMObject {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit SuspendableTimer(ScriptExecutionContext&);
-    virtual ~SuspendableTimer();
+    explicit SuspendableTimerBase(ScriptExecutionContext*);
+    virtual ~SuspendableTimerBase();
 
     // A hook for derived classes to perform cleanup.
     virtual void didStop();
 
-    // Part of TimerBase interface used by SuspendableTimer clients, modified to work when suspended.
+    // Part of TimerBase interface used by SuspendableTimerBase clients, modified to work when suspended.
     bool isActive() const { return TimerBase::isActive() || (m_suspended && m_savedIsActive); }
     bool isSuspended() const { return m_suspended; }
 
@@ -77,4 +78,31 @@
     bool m_savedIsActive { false };
 };
 
+class SuspendableTimer final : public SuspendableTimerBase {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    template <typename TimerFiredClass, typename TimerFiredBaseClass>
+    SuspendableTimer(ScriptExecutionContext* context, TimerFiredClass& object, void (TimerFiredBaseClass::*function)())
+        : SuspendableTimerBase(context)
+        , m_function(std::bind(function, &object))
+    {
+    }
+
+    SuspendableTimer(ScriptExecutionContext* context, WTF::Function<void ()>&& function)
+        : SuspendableTimerBase(context)
+        , m_function(WTFMove(function))
+    {
+    }
+
+private:
+    void fired() final
+    {
+        m_function();
+    }
+
+    const char* activeDOMObjectName() const final;
+
+    WTF::Function<void ()> m_function;
+};
+
 } // namespace WebCore

Modified: trunk/Source/WebKitLegacy/win/ChangeLog (250463 => 250464)


--- trunk/Source/WebKitLegacy/win/ChangeLog	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebKitLegacy/win/ChangeLog	2019-09-27 22:42:20 UTC (rev 250464)
@@ -1,3 +1,16 @@
+2019-09-27  Chris Dumez  <[email protected]>
+
+        Pages using WebGLRenderingContext fail to enter the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=202318
+        <rdar://problem/55783612>
+
+        Reviewed by Tim Horton.
+
+        * WebView.cpp:
+        (WindowCloseTimer::WindowCloseTimer):
+        (WindowCloseTimer::contextDestroyed):
+        * WebView.h:
+
 2019-09-25  Fujii Hironori  <[email protected]>
 
         Unreviewed build fix for Windows ports.

Modified: trunk/Source/WebKitLegacy/win/WebView.cpp (250463 => 250464)


--- trunk/Source/WebKitLegacy/win/WebView.cpp	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebKitLegacy/win/WebView.cpp	2019-09-27 22:42:20 UTC (rev 250464)
@@ -1455,7 +1455,7 @@
     ::GetWindowRect(m_viewWindow, rect);
 }
 
-class WindowCloseTimer final : public WebCore::SuspendableTimer {
+class WindowCloseTimer final : public WebCore::SuspendableTimerBase {
 public:
     static WindowCloseTimer* create(WebView*);
 
@@ -1466,7 +1466,7 @@
     void contextDestroyed() override;
     const char* activeDOMObjectName() const override { return "WindowCloseTimer"; }
 
-    // SuspendableTimer API.
+    // SuspendableTimerBase API.
     void fired() override;
 
     WebView* m_webView;
@@ -1491,7 +1491,7 @@
 }
 
 WindowCloseTimer::WindowCloseTimer(ScriptExecutionContext& context, WebView* webView)
-    : SuspendableTimer(context)
+    : SuspendableTimerBase(&context)
     , m_webView(webView)
 {
     ASSERT_ARG(webView, webView);
@@ -1499,7 +1499,7 @@
 
 void WindowCloseTimer::contextDestroyed()
 {
-    SuspendableTimer::contextDestroyed();
+    SuspendableTimerBase::contextDestroyed();
     delete this;
 }
 

Modified: trunk/Source/WebKitLegacy/win/WebView.h (250463 => 250464)


--- trunk/Source/WebKitLegacy/win/WebView.h	2019-09-27 22:15:49 UTC (rev 250463)
+++ trunk/Source/WebKitLegacy/win/WebView.h	2019-09-27 22:42:20 UTC (rev 250464)
@@ -680,7 +680,7 @@
 
     static bool s_allowSiteSpecificHacks;
 
-    WebCore::SuspendableTimer* m_closeWindowTimer { nullptr };
+    WebCore::SuspendableTimerBase* m_closeWindowTimer { nullptr };
     std::unique_ptr<TRACKMOUSEEVENT> m_mouseOutTracker;
 
     HWND m_topLevelParent { nullptr };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to