Improve behavior of media elements in page cache.
<https://webkit.org/b/147020>
<rdar://problem/21712311>
Reviewed by Chris Dumez.
Source/WebCore:
Make improvements for media elements when transitioning in/out of page cache:
- Events that were scheduled when going into cache will now be delivered
when the page is restored from cache.
- Data buffering is turned off while in the cache. This reduces the memory
cost of cached pages with media elements on iOS (where mediaserverd would
keep upcoming video frames in memory for cached pages.)
Test: media/restore-from-page-cache.html (amended)
* dom/GenericEventQueue.h:
* dom/GenericEventQueue.cpp:
(WebCore::GenericEventQueue::enqueueEvent):
(WebCore::GenericEventQueue::suspend):
(WebCore::GenericEventQueue::resume):
Add a simple suspend/resume mechanism to GenericEventQueue that can
be used to support page caching.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::stop):
(WebCore::HTMLMediaElement::suspend):
(WebCore::HTMLMediaElement::resume):
(WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
Adapt to event queueing changes and add calls to setShouldBufferData().
* html/HTMLSourceElement.h:
* html/HTMLSourceElement.cpp:
(WebCore::HTMLSourceElement::HTMLSourceElement):
(WebCore::HTMLSourceElement::create):
(WebCore::HTMLSourceElement::activeDOMObjectName):
(WebCore::HTMLSourceElement::canSuspendForPageCache):
(WebCore::HTMLSourceElement::suspend):
(WebCore::HTMLSourceElement::resume):
(WebCore::HTMLSourceElement::stop):
Turn HTMLSourceElement into an ActiveDOMObject so it gets all the
appropriate page cache notifications directly. Suspend the delayed
error event delivery timer when cached.
LayoutTests:
Add some coverage for suspend/resume of queued events on cached media elements.
* media/restore-from-page-cache-expected.txt:
* media/restore-from-page-cache.html:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@187031 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/GenericEventQueue.cpp b/Source/WebCore/dom/GenericEventQueue.cpp
index 10c034c..fa397d2 100644
--- a/Source/WebCore/dom/GenericEventQueue.cpp
+++ b/Source/WebCore/dom/GenericEventQueue.cpp
@@ -45,20 +45,22 @@
{
}
-bool GenericEventQueue::enqueueEvent(PassRefPtr<Event> event)
+void GenericEventQueue::enqueueEvent(PassRefPtr<Event> event)
{
if (m_isClosed)
- return false;
+ return;
if (event->target() == &m_owner)
event->setTarget(0);
m_pendingEvents.append(event);
+
+ if (m_isSuspended)
+ return;
+
pendingQueues().append(m_weakPtrFactory.createWeakPtr());
if (!sharedTimer().isActive())
sharedTimer().startOneShot(0);
-
- return true;
}
Timer& GenericEventQueue::sharedTimer()
@@ -120,4 +122,26 @@
return !m_pendingEvents.isEmpty();
}
+void GenericEventQueue::suspend()
+{
+ ASSERT(!m_isSuspended);
+ m_isSuspended = true;
+ m_weakPtrFactory.revokeAll();
+}
+
+void GenericEventQueue::resume()
+{
+ ASSERT(m_isSuspended);
+ m_isSuspended = false;
+
+ if (m_pendingEvents.isEmpty())
+ return;
+
+ for (unsigned i = 0; i < m_pendingEvents.size(); ++i)
+ pendingQueues().append(m_weakPtrFactory.createWeakPtr());
+
+ if (!sharedTimer().isActive())
+ sharedTimer().startOneShot(0);
+}
+
}