Title: [250573] trunk/Source/WebCore
Revision
250573
Author
you...@apple.com
Date
2019-10-01 12:21:07 -0700 (Tue, 01 Oct 2019)

Log Message

RTCDataChannel should not prevent entering page cache except if in open state
https://bugs.webkit.org/show_bug.cgi?id=202395

Reviewed by Chris Dumez.

Only prevent entering page cache in open state.
Enqueue message through the document event queue to handle suspension properly.

We cannot yet write page cache tests as a data channel requires a peer connection which
currently forbids entering page cache.

* Modules/mediastream/RTCDataChannel.cpp:
(WebCore::RTCDataChannel::RTCDataChannel):
(WebCore::RTCDataChannel::didReceiveStringData):
(WebCore::RTCDataChannel::didReceiveRawData):
(WebCore::RTCDataChannel::didDetectError):
(WebCore::RTCDataChannel::bufferedAmountIsDecreasing):
(WebCore::RTCDataChannel::scheduleDispatchEvent):
(WebCore::RTCDataChannel::scheduledEventTimerFired): Deleted.
* Modules/mediastream/RTCDataChannel.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (250572 => 250573)


--- trunk/Source/WebCore/ChangeLog	2019-10-01 19:06:30 UTC (rev 250572)
+++ trunk/Source/WebCore/ChangeLog	2019-10-01 19:21:07 UTC (rev 250573)
@@ -1,3 +1,26 @@
+2019-10-01  youenn fablet  <you...@apple.com>
+
+        RTCDataChannel should not prevent entering page cache except if in open state
+        https://bugs.webkit.org/show_bug.cgi?id=202395
+
+        Reviewed by Chris Dumez.
+
+        Only prevent entering page cache in open state.
+        Enqueue message through the document event queue to handle suspension properly.
+
+        We cannot yet write page cache tests as a data channel requires a peer connection which
+        currently forbids entering page cache.
+
+        * Modules/mediastream/RTCDataChannel.cpp:
+        (WebCore::RTCDataChannel::RTCDataChannel):
+        (WebCore::RTCDataChannel::didReceiveStringData):
+        (WebCore::RTCDataChannel::didReceiveRawData):
+        (WebCore::RTCDataChannel::didDetectError):
+        (WebCore::RTCDataChannel::bufferedAmountIsDecreasing):
+        (WebCore::RTCDataChannel::scheduleDispatchEvent):
+        (WebCore::RTCDataChannel::scheduledEventTimerFired): Deleted.
+        * Modules/mediastream/RTCDataChannel.h:
+
 2019-10-01  Rob Buis  <rb...@igalia.com>
 
         [Mac] Layout Test imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location.any.html fails

Modified: trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp (250572 => 250573)


--- trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp	2019-10-01 19:06:30 UTC (rev 250572)
+++ trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.cpp	2019-10-01 19:21:07 UTC (rev 250573)
@@ -81,7 +81,6 @@
 RTCDataChannel::RTCDataChannel(Document& document, std::unique_ptr<RTCDataChannelHandler>&& handler, String&& label, RTCDataChannelInit&& options)
     : ActiveDOMObject(document)
     , m_handler(WTFMove(handler))
-    , m_scheduledEventTimer(*this, &RTCDataChannel::scheduledEventTimerFired)
     , m_label(WTFMove(label))
     , m_options(WTFMove(options))
     , m_messageQueue(createMessageQueue(document, *this))
@@ -194,17 +193,11 @@
 
 void RTCDataChannel::didReceiveStringData(const String& text)
 {
-    if (m_stopped)
-        return;
-
     scheduleDispatchEvent(MessageEvent::create(text));
 }
 
 void RTCDataChannel::didReceiveRawData(const char* data, size_t dataLength)
 {
-    if (m_stopped)
-        return;
-
     switch (m_binaryType) {
     case BinaryType::Blob:
         scheduleDispatchEvent(MessageEvent::create(Blob::create(SharedBuffer::create(data, dataLength), emptyString()), { }));
@@ -218,17 +211,11 @@
 
 void RTCDataChannel::didDetectError()
 {
-    if (m_stopped)
-        return;
-
     scheduleDispatchEvent(Event::create(eventNames().errorEvent, Event::CanBubble::No, Event::IsCancelable::No));
 }
 
 void RTCDataChannel::bufferedAmountIsDecreasing(size_t amount)
 {
-    if (m_stopped)
-        return;
-
     if (amount <= m_bufferedAmountLowThreshold)
         scheduleDispatchEvent(Event::create(eventNames().bufferedamountlowEvent, Event::CanBubble::No, Event::IsCancelable::No));
 }
@@ -240,22 +227,11 @@
 
 void RTCDataChannel::scheduleDispatchEvent(Ref<Event>&& event)
 {
-    m_scheduledEvents.append(WTFMove(event));
-
-    if (!m_scheduledEventTimer.isActive())
-        m_scheduledEventTimer.startOneShot(0_s);
-}
-
-void RTCDataChannel::scheduledEventTimerFired()
-{
     if (m_stopped)
         return;
 
-    Vector<Ref<Event>> events;
-    events.swap(m_scheduledEvents);
-
-    for (auto& event : events)
-        dispatchEvent(event);
+    event->setTarget(this);
+    scriptExecutionContext()->eventQueue().enqueueEvent(WTFMove(event));
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h (250572 => 250573)


--- trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h	2019-10-01 19:06:30 UTC (rev 250572)
+++ trunk/Source/WebCore/Modules/mediastream/RTCDataChannel.h	2019-10-01 19:21:07 UTC (rev 250573)
@@ -84,7 +84,6 @@
     static NetworkSendQueue createMessageQueue(Document&, RTCDataChannel&);
 
     void scheduleDispatchEvent(Ref<Event>&&);
-    void scheduledEventTimerFired();
 
     EventTargetInterface eventTargetInterface() const final { return RTCDataChannelEventTargetInterfaceType; }
     ScriptExecutionContext* scriptExecutionContext() const final { return m_scriptExecutionContext; }
@@ -95,7 +94,7 @@
     // ActiveDOMObject API
     void stop() final;
     const char* activeDOMObjectName() const final { return "RTCDataChannel"; }
-    bool canSuspendForDocumentSuspension() const final { return m_readyState == RTCDataChannelState::Closed; }
+    bool canSuspendForDocumentSuspension() const final { return m_readyState != RTCDataChannelState::Open; }
 
     // RTCDataChannelHandlerClient API
     void didChangeReadyState(RTCDataChannelState) final;
@@ -113,9 +112,6 @@
     enum class BinaryType { Blob, ArrayBuffer };
     BinaryType m_binaryType { BinaryType::ArrayBuffer };
 
-    Timer m_scheduledEventTimer;
-    Vector<Ref<Event>> m_scheduledEvents;
-
     String m_label;
     RTCDataChannelInit m_options;
     size_t m_bufferedAmountLowThreshold { 0 };
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to