Add very basic PageCache support for RTCPeerConnection
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Sep 2019 05:32:00 +0000 (05:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Sep 2019 05:32:00 +0000 (05:32 +0000)
commit4089a40425fc3c7b614268f7d26794963fa29694
treea56645710ace083b3a76e382b71d0b6e95cccda3
parentd38c99124cd621a5b9512d90d257b5ac2eec80f6
Add very basic PageCache support for RTCPeerConnection
https://bugs.webkit.org/show_bug.cgi?id=202244

Reviewed by Geoffrey Garen.

Source/WebCore:

RTCPeerConnection::canSuspendForDocumentSuspension() returns true if
RTCPeerConnection::hasPendingActivity() return false. Previously, hasPendingActivity()
would return true unless the JS has called close() on the RTCPeerConnection
object.

On weather.com, an ad would construct an RTCPeerConnection just to do some feature
checking and then let the variable go out of scope (without calling close()). Because
of the previous implementation of RTCPeerConnection::hasPendingActivity(), this wrapper
and its implementation object would stay alive forever AND prevent the page from
entering PageCache on navigation.

To improve this, the implementation of hadPendingActivity() has been updated so that
it keeps returning false if close() has been called, but will also return false if
there are no pending Promises to be resolved and no event listeners.

Test: fast/mediastream/RTCPeerConnection-page-cache.html

* Modules/mediastream/RTCPeerConnection.cpp:
WebCore::RTCPeerConnection::RTCPeerConnection:
Stop taking a pending activity in the constructor, this would be NOT keep the wrapper
alive since RTCPeerConnection::hasPendingActivity() was not checking
ActiveDOMObject::hasPendingActivity().

(WebCore::RTCPeerConnection::canSuspendForDocumentSuspension const):
(WebCore::RTCPeerConnection::hasPendingActivity const):

* Modules/mediastream/RTCPeerConnection.h:

* bindings/js/JSDOMPromiseDeferred.h:
(WebCore::DOMPromiseDeferredBase::whenSettled):

LayoutTests:

Add layout test coverage.

* fast/mediastream/RTCPeerConnection-page-cache-expected.txt: Added.
* fast/mediastream/RTCPeerConnection-page-cache.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250379 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/mediastream/RTCPeerConnection-page-cache-expected.txt [new file with mode: 0644]
LayoutTests/fast/mediastream/RTCPeerConnection-page-cache.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp
Source/WebCore/Modules/mediastream/RTCPeerConnection.h
Source/WebCore/bindings/js/JSDOMPromise.cpp
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp
Source/WebCore/bindings/js/JSDOMPromiseDeferred.h