Title: [256009] trunk
Revision
256009
Author
[email protected]
Date
2020-02-07 00:46:32 -0800 (Fri, 07 Feb 2020)

Log Message

Do not process newly gathered ICE candidates if document is suspended
https://bugs.webkit.org/show_bug.cgi?id=207326
<rdar://problem/57336453>

Reviewed by Alex Christensen.

Source/WebCore:

We should not register MDNS candidates for suspended documents.
For that reason, enqueue a task when receiving a new candidate.
If document is not suspended, it will be executed immediately.
Otherwise, we will wait until document gets unsuspended.

Add a mock endpoint that delays gathering of candidates until document is suspended.

Test: webrtc/peerconnection-new-candidate-page-cache.html

* Modules/mediastream/PeerConnectionBackend.cpp:
(WebCore::PeerConnectionBackend::newICECandidate):
* testing/MockLibWebRTCPeerConnection.cpp:
(WebCore::MockLibWebRTCPeerConnection::GetTransceivers const):
(WebCore::MockLibWebRTCPeerConnectionForIceCandidates::MockLibWebRTCPeerConnectionForIceCandidates):
(WebCore::MockLibWebRTCPeerConnectionForIceCandidates::gotLocalDescription):
(WebCore::MockLibWebRTCPeerConnectionForIceCandidates::sendCandidates):
(WebCore::MockLibWebRTCPeerConnectionFactory::CreatePeerConnection):

LayoutTests:

* fast/history/resources/page-cache-helper-100ms.html: Added.
* webrtc/peerconnection-new-candidate-page-cache-expected.txt: Added.
* webrtc/peerconnection-new-candidate-page-cache.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (256008 => 256009)


--- trunk/LayoutTests/ChangeLog	2020-02-07 05:19:16 UTC (rev 256008)
+++ trunk/LayoutTests/ChangeLog	2020-02-07 08:46:32 UTC (rev 256009)
@@ -1,3 +1,15 @@
+2020-02-07  youenn fablet  <[email protected]>
+
+        Do not process newly gathered ICE candidates if document is suspended
+        https://bugs.webkit.org/show_bug.cgi?id=207326
+        <rdar://problem/57336453>
+
+        Reviewed by Alex Christensen.
+
+        * fast/history/resources/page-cache-helper-100ms.html: Added.
+        * webrtc/peerconnection-new-candidate-page-cache-expected.txt: Added.
+        * webrtc/peerconnection-new-candidate-page-cache.html: Added.
+
 2020-02-06  Jiewen Tan  <[email protected]>
 
         [WebAuthn] authenticatorGetAssertion should be sent without pinAuth if UV = "discouraged"

Added: trunk/LayoutTests/fast/history/resources/page-cache-helper-100ms.html (0 => 256009)


--- trunk/LayoutTests/fast/history/resources/page-cache-helper-100ms.html	                        (rev 0)
+++ trunk/LayoutTests/fast/history/resources/page-cache-helper-100ms.html	2020-02-07 08:46:32 UTC (rev 256009)
@@ -0,0 +1,9 @@
+This page should go back. If a test outputs the contents of this
+page, then the test page failed to enter the page cache.
+<script>
+  window.addEventListener("load", function() {
+    setTimeout(function() {
+      history.back();
+    }, 100);
+  }, false);
+</script>

Added: trunk/LayoutTests/webrtc/peerconnection-new-candidate-page-cache-expected.txt (0 => 256009)


--- trunk/LayoutTests/webrtc/peerconnection-new-candidate-page-cache-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webrtc/peerconnection-new-candidate-page-cache-expected.txt	2020-02-07 08:46:32 UTC (rev 256009)
@@ -0,0 +1,3 @@
+
+PASS peerconnection-new-candidate-page-cache 
+

Added: trunk/LayoutTests/webrtc/peerconnection-new-candidate-page-cache.html (0 => 256009)


--- trunk/LayoutTests/webrtc/peerconnection-new-candidate-page-cache.html	                        (rev 0)
+++ trunk/LayoutTests/webrtc/peerconnection-new-candidate-page-cache.html	2020-02-07 08:46:32 UTC (rev 256009)
@@ -0,0 +1,52 @@
+<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script src=""
+<canvas id="canvas" width=320px height=240px></canvas>
+<script>
+t = async_test();
+
+if (window.testRunner)
+    testRunner.setWebRTCMDNSICECandidatesEnabled(true);
+if (window.internals) {
+    internals.useMockRTCPeerConnectionFactory("ICECandidatesWithDelay");
+    internals.setICECandidateFiltering(true);
+}
+
+window.addEventListener("pageshow", t.step_func(function(event) {
+    if (!event.persisted)
+        return;
+    t.hasPageShow = true;
+    if (t.hasMDNSCandidate)
+        t.done();
+}));
+
+window.addEventListener("pagehide", t.step_func((event) => {
+    if (!event.persisted)
+        assert_uneached("Page failed to enter page cache");
+
+}));
+t.pc = new RTCPeerConnection;
+t.hasMDNSCandidate = false;
+t.hasPageShow = false;
+_onload_ = async () => {
+     t.pc._onicecandidate_ = t.step_func((event) => {
+         if (!event.candidate || t.pasPageShow) {
+             t.done();
+             return;
+         }
+         if (event.candidate.candidate.includes('.local'))
+             t.hasMDNSCandidate = true;
+     });
+     const stream = canvas.captureStream();
+     t.pc.addTrack(stream.getVideoTracks()[0], stream);
+     const offer = await t.pc.createOffer();
+     window.location = "../fast/history/resources/page-cache-helper-100ms.html";
+
+     t.pc.setLocalDescription(offer); 
+     assert_false(t.hasMDNSCandidate);
+};
+</script>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (256008 => 256009)


--- trunk/Source/WebCore/ChangeLog	2020-02-07 05:19:16 UTC (rev 256008)
+++ trunk/Source/WebCore/ChangeLog	2020-02-07 08:46:32 UTC (rev 256009)
@@ -1,3 +1,29 @@
+2020-02-07  youenn fablet  <[email protected]>
+
+        Do not process newly gathered ICE candidates if document is suspended
+        https://bugs.webkit.org/show_bug.cgi?id=207326
+        <rdar://problem/57336453>
+
+        Reviewed by Alex Christensen.
+
+        We should not register MDNS candidates for suspended documents.
+        For that reason, enqueue a task when receiving a new candidate.
+        If document is not suspended, it will be executed immediately.
+        Otherwise, we will wait until document gets unsuspended.
+
+        Add a mock endpoint that delays gathering of candidates until document is suspended.
+
+        Test: webrtc/peerconnection-new-candidate-page-cache.html
+
+        * Modules/mediastream/PeerConnectionBackend.cpp:
+        (WebCore::PeerConnectionBackend::newICECandidate):
+        * testing/MockLibWebRTCPeerConnection.cpp:
+        (WebCore::MockLibWebRTCPeerConnection::GetTransceivers const):
+        (WebCore::MockLibWebRTCPeerConnectionForIceCandidates::MockLibWebRTCPeerConnectionForIceCandidates):
+        (WebCore::MockLibWebRTCPeerConnectionForIceCandidates::gotLocalDescription):
+        (WebCore::MockLibWebRTCPeerConnectionForIceCandidates::sendCandidates):
+        (WebCore::MockLibWebRTCPeerConnectionFactory::CreatePeerConnection):
+
 2020-02-06  Myles C. Maxfield  <[email protected]>
 
         REGRESSION(r254534): 1-3% regression on PLT

Modified: trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp (256008 => 256009)


--- trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp	2020-02-07 05:19:16 UTC (rev 256008)
+++ trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp	2020-02-07 08:46:32 UTC (rev 256009)
@@ -437,25 +437,28 @@
 
 void PeerConnectionBackend::newICECandidate(String&& sdp, String&& mid, unsigned short sdpMLineIndex, String&& serverURL)
 {
-    ALWAYS_LOG(LOGIDENTIFIER, "Gathered ice candidate:", sdp);
-    m_finishedGatheringCandidates = false;
+    m_peerConnection.doTask([logSiteIdentifier = LOGIDENTIFIER, this, sdp = WTFMove(sdp), mid = WTFMove(mid), sdpMLineIndex, serverURL = WTFMove(serverURL)]() mutable {
+        UNUSED_PARAM(logSiteIdentifier);
+        ALWAYS_LOG(logSiteIdentifier, "Gathered ice candidate:", sdp);
+        m_finishedGatheringCandidates = false;
 
-    if (!m_shouldFilterICECandidates) {
-        fireICECandidateEvent(RTCIceCandidate::create(WTFMove(sdp), WTFMove(mid), sdpMLineIndex), WTFMove(serverURL));
-        return;
-    }
-    if (sdp.find(" host ", 0) != notFound) {
-        // FIXME: We might need to clear all pending candidates when setting again local description.
-        m_pendingICECandidates.append(PendingICECandidate { String { sdp }, WTFMove(mid), sdpMLineIndex, WTFMove(serverURL) });
-        if (RuntimeEnabledFeatures::sharedFeatures().webRTCMDNSICECandidatesEnabled()) {
-            auto ipAddress = extractIPAddres(sdp);
-            // We restrict to IPv4 candidates for now.
-            if (ipAddress.contains('.'))
-                registerMDNSName(ipAddress);
+        if (!m_shouldFilterICECandidates) {
+            fireICECandidateEvent(RTCIceCandidate::create(WTFMove(sdp), WTFMove(mid), sdpMLineIndex), WTFMove(serverURL));
+            return;
         }
-        return;
-    }
-    fireICECandidateEvent(RTCIceCandidate::create(filterICECandidate(WTFMove(sdp)), WTFMove(mid), sdpMLineIndex), WTFMove(serverURL));
+        if (sdp.find(" host ", 0) != notFound) {
+            // FIXME: We might need to clear all pending candidates when setting again local description.
+            m_pendingICECandidates.append(PendingICECandidate { String { sdp }, WTFMove(mid), sdpMLineIndex, WTFMove(serverURL) });
+            if (RuntimeEnabledFeatures::sharedFeatures().webRTCMDNSICECandidatesEnabled()) {
+                auto ipAddress = extractIPAddres(sdp);
+                // We restrict to IPv4 candidates for now.
+                if (ipAddress.contains('.'))
+                    registerMDNSName(ipAddress);
+            }
+            return;
+        }
+        fireICECandidateEvent(RTCIceCandidate::create(filterICECandidate(WTFMove(sdp)), WTFMove(mid), sdpMLineIndex), WTFMove(serverURL));
+    });
 }
 
 void PeerConnectionBackend::doneGatheringCandidates()

Modified: trunk/Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp (256008 => 256009)


--- trunk/Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp	2020-02-07 05:19:16 UTC (rev 256008)
+++ trunk/Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp	2020-02-07 08:46:32 UTC (rev 256009)
@@ -86,30 +86,60 @@
 
 class MockLibWebRTCPeerConnectionForIceCandidates : public MockLibWebRTCPeerConnection {
 public:
-    explicit MockLibWebRTCPeerConnectionForIceCandidates(webrtc::PeerConnectionObserver& observer) : MockLibWebRTCPeerConnection(observer) { }
+    explicit MockLibWebRTCPeerConnectionForIceCandidates(webrtc::PeerConnectionObserver&, unsigned delayCount = 0);
     virtual ~MockLibWebRTCPeerConnectionForIceCandidates() = default;
 private:
     void gotLocalDescription() final;
+    void sendCandidates();
+
+    unsigned m_delayCount { 0 };
 };
 
+MockLibWebRTCPeerConnectionForIceCandidates::MockLibWebRTCPeerConnectionForIceCandidates(webrtc::PeerConnectionObserver& observer, unsigned delayCount)
+    : MockLibWebRTCPeerConnection(observer)
+    , m_delayCount(delayCount)
+{
+}
+
 void MockLibWebRTCPeerConnectionForIceCandidates::gotLocalDescription()
 {
+    AddRef();
+    sendCandidates();
+}
+
+void MockLibWebRTCPeerConnectionForIceCandidates::sendCandidates()
+{
+    if (m_delayCount > 0) {
+        m_delayCount--;
+        callOnMainThread([this] {
+            LibWebRTCProvider::callOnWebRTCNetworkThread([this] {
+                sendCandidates();
+            });
+        });
+        return;
+    }
+
     // Let's gather candidates
     LibWebRTCProvider::callOnWebRTCSignalingThread([this]() {
         MockLibWebRTCIceCandidate candidate("2013266431 1 udp 2013266432 192.168.0.100 38838 typ host generation 0", "1");
         m_observer.OnIceCandidate(&candidate);
     });
+
     LibWebRTCProvider::callOnWebRTCSignalingThread([this]() {
         MockLibWebRTCIceCandidate candidate("1019216383 1 tcp 1019216384 192.168.0.100 9 typ host tcptype passive generation 0", "1");
         m_observer.OnIceCandidate(&candidate);
     });
+
     LibWebRTCProvider::callOnWebRTCSignalingThread([this]() {
         MockLibWebRTCIceCandidate candidate("1677722111 1 tcp 1677722112 172.18.0.1 47989 typ srflx raddr 192.168.0.100 rport 47989 generation 0", "1");
         m_observer.OnIceCandidate(&candidate);
     });
+
     LibWebRTCProvider::callOnWebRTCSignalingThread([this]() {
         m_observer.OnIceGatheringChange(webrtc::PeerConnectionInterface::kIceGatheringComplete);
     });
+
+    Release();
 }
 
 class MockLibWebRTCPeerConnectionForIceConnectionState : public MockLibWebRTCPeerConnection {
@@ -190,6 +220,9 @@
     if (m_testCase == "ICECandidates")
         return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionForIceCandidates>(*dependencies.observer);
 
+    if (m_testCase == "ICECandidatesWithDelay")
+        return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionForIceCandidates>(*dependencies.observer, 1000);
+
     if (m_testCase == "ICEConnectionState")
         return new rtc::RefCountedObject<MockLibWebRTCPeerConnectionForIceConnectionState>(*dependencies.observer);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to