Pages with Web Workers cannot enter the back / forward cache
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2019 21:00:33 +0000 (21:00 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Sep 2019 21:00:33 +0000 (21:00 +0000)
commit986e7f6f1681849b0b48cc00e3a18ff1733da182
treebd464d4e5d9e18117a0b43a7b64144fb7a808583
parent313b6e4c8c8a5b48e15c3ea62c35f4b9bbf805cf
Pages with Web Workers cannot enter the back / forward cache
https://bugs.webkit.org/show_bug.cgi?id=202296
<rdar://problem/55764073>

Reviewed by Jer Noble.

Source/WebCore:

Allow pages that use Web Workers to enter the back / forward cache.
This involves adding an EventQueue for all event firing on Woker
objects and suspending this EventQueue while in the page cache.

This was preventing some of the pages on weather.com to enter the
back / forward cache.

Test: fast/workers/worker-page-cache.html

* Modules/encryptedmedia/MediaKeySession.h:
* Modules/encryptedmedia/legacy/WebKitMediaKeySession.h:
* Modules/mediasource/MediaSource.h:
* Modules/mediasource/SourceBuffer.h:
* Modules/mediasource/SourceBufferList.h:
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::AudioContext):
* Modules/webaudio/AudioContext.h:
* animation/DeclarativeAnimation.h:

* dom/GenericEventQueue.cpp:
(WebCore::TaskQueueConstructor::construct):
(WebCore::TaskQueueConstructor<Timer>::construct):
(WebCore::GenericEventQueueBase<T>::GenericEventQueueBase):
(WebCore::GenericEventQueueBase<T>::enqueueEvent):
(WebCore::GenericEventQueueBase<T>::dispatchOneEvent):
(WebCore::GenericEventQueueBase<T>::close):
(WebCore::GenericEventQueueBase<T>::cancelAllEvents):
(WebCore::GenericEventQueueBase<T>::hasPendingEvents const):
(WebCore::GenericEventQueueBase<T>::hasPendingEventsOfType const):
(WebCore::GenericEventQueueBase<T>::suspend):
(WebCore::GenericEventQueueBase<T>::resume):
* dom/GenericEventQueue.h:
(WebCore::GenericEventQueueBase::isSuspended const):
(WebCore::MainThreadGenericEventQueue::MainThreadGenericEventQueue):
(WebCore::GenericEventQueue::GenericEventQueue):
Rename GenericEventQueue to MainThreadGenericEventQueue since its implementation relies
on a global shared Timer to fire events. Introduce a new GenericEventQueue which can
actually be used from any thread. This is useful for MessagePort, which is used both
on the main thread and on worker threads.

* dom/MessagePort.cpp:
(WebCore::MessagePort::MessagePort):
(WebCore::MessagePort::close):
(WebCore::MessagePort::suspend):
(WebCore::MessagePort::resume):
(WebCore::MessagePort::dispatchMessages):
* dom/MessagePort.h:
Use an GenericEventQueue in MessagePort for consistency with Worker.
MessagePort is an ActiveDOMobject which returns true in canSuspend(),
we therefore need to make sure it suspends event firing while
suspended.

* html/HTMLMediaElement.h:
* html/track/TrackListBase.h:
* workers/Worker.cpp:
(WebCore::Worker::Worker):
(WebCore::Worker::terminate):
(WebCore::Worker::canSuspendForDocumentSuspension const):
(WebCore::Worker::suspend):
(WebCore::Worker::resume):
(WebCore::Worker::stop):
(WebCore::Worker::hasPendingActivity const):
(WebCore::Worker::notifyFinished):
(WebCore::Worker::enqueueEvent):
(WebCore::Worker::dispatchEvent):
* workers/Worker.h:
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::postMessageToWorkerObject):
(WebCore::WorkerMessagingProxy::postExceptionToWorkerObject):

LayoutTests:

Add layout test coverage.

* fast/workers/worker-page-cache-expected.txt: Added.
* fast/workers/worker-page-cache.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250527 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/workers/worker-page-cache-expected.txt [new file with mode: 0644]
LayoutTests/fast/workers/worker-page-cache.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/MediaKeySession.h
Source/WebCore/Modules/encryptedmedia/legacy/WebKitMediaKeySession.h
Source/WebCore/Modules/mediasource/MediaSource.h
Source/WebCore/Modules/mediasource/SourceBuffer.h
Source/WebCore/Modules/mediasource/SourceBufferList.h
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h
Source/WebCore/animation/DeclarativeAnimation.h
Source/WebCore/dom/GenericEventQueue.cpp
Source/WebCore/dom/GenericEventQueue.h
Source/WebCore/dom/MessagePort.cpp
Source/WebCore/dom/MessagePort.h
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/track/TrackListBase.h
Source/WebCore/workers/Worker.cpp
Source/WebCore/workers/Worker.h
Source/WebCore/workers/WorkerMessagingProxy.cpp