Title: [270937] trunk
Revision
270937
Author
[email protected]
Date
2020-12-17 10:26:06 -0800 (Thu, 17 Dec 2020)

Log Message

Web Inspector: REGRESSION(r266467): viewing a WebSocket created before Web Inspector was opened doesn't show any message frames
https://bugs.webkit.org/show_bug.cgi?id=219510

Reviewed by Youenn Fablet.

Source/WebCore:

Updated test: http/tests/websocket/tests/hybi/inspector/before-load.html

Restored functionality prior to r266467 so that the `progressIdentifier` (previously `channelIdentifier`) is
available from `WebSocketChannel`.

* Modules/websockets/ThreadableWebSocketChannel.h:
* Modules/websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::WebSocketChannel):
(WebCore::WebSocketChannel::connect):
(WebCore::WebSocketChannel::fail):
(WebCore::WebSocketChannel::disconnect):
(WebCore::WebSocketChannel::didOpenSocketStream):
(WebCore::WebSocketChannel::didCloseSocketStream):
(WebCore::WebSocketChannel::didFailSocketStream):
(WebCore::WebSocketChannel::processBuffer):
(WebCore::WebSocketChannel::processFrame):
(WebCore::WebSocketChannel::sendFrame):
* Modules/websockets/WebSocketChannel.h:
- Reinstate a separate progress identifier for inspection
* Modules/websockets/WebSocketChannelInspector.cpp:
(WebCore::progressIdentifier const):
* Modules/websockets/WebSocketChannelInspector.h:
- Support getting the progress identifier.
* Modules/websockets/WorkerThreadableWebSocketChannel.h:
* inspector/agents/InspectorNetworkAgent.cpp:
(WebCore::InspectorNetworkAgent::enable):
(WebCore::InspectorNetworkAgent::webSocketForRequestId):

Source/WebKit:

Restored functionality prior to r266467 so that the `progressIdentifier` (previously `channelIdentifier`) is
available from `WebSocketChannel`.

* WebProcess/Network/WebSocketChannel.h:

LayoutTests:

Updated test to check that sent and received frames are correctly associated with WebSockets that were open
before the Web Inspector was opened.

* http/tests/websocket/tests/hybi/inspector/before-load-expected.txt:
* http/tests/websocket/tests/hybi/inspector/before-load.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (270936 => 270937)


--- trunk/LayoutTests/ChangeLog	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/LayoutTests/ChangeLog	2020-12-17 18:26:06 UTC (rev 270937)
@@ -1,3 +1,16 @@
+2020-12-17  Patrick Angle  <[email protected]>
+
+        Web Inspector: REGRESSION(r266467): viewing a WebSocket created before Web Inspector was opened doesn't show any message frames
+        https://bugs.webkit.org/show_bug.cgi?id=219510
+
+        Reviewed by Youenn Fablet.
+
+        Updated test to check that sent and received frames are correctly associated with WebSockets that were open
+        before the Web Inspector was opened.
+
+        * http/tests/websocket/tests/hybi/inspector/before-load-expected.txt:
+        * http/tests/websocket/tests/hybi/inspector/before-load.html:
+
 2020-12-17  Truitt Savell  <[email protected]>
 
         Rebase fast/css/text-overflow-input.html

Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load-expected.txt (270936 => 270937)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load-expected.txt	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load-expected.txt	2020-12-17 18:26:06 UTC (rev 270937)
@@ -9,4 +9,8 @@
 PASS: Resource should have request headers.
 PASS: Resource should have response headers.
 Resource readyState should be Symbol(open).
+PASS: Frame data should be 'Hello World!'
+PASS: Frame outgoing should be 'true'
+PASS: Frame data should be 'Hello World!'
+PASS: Frame outgoing should be 'false'
 

Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load.html (270936 => 270937)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load.html	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/before-load.html	2020-12-17 18:26:06 UTC (rev 270937)
@@ -8,8 +8,8 @@
     testRunner.waitUntilDone();
 
     const url = ""
-    let webSocket = new WebSocket(url);
-    webSocket.addEventListener("open", (event) => {
+    window.testWebSocket = new WebSocket(url);
+    window.testWebSocket.addEventListener("open", (event) => {
         // Only run the tests once the websocket has connected.
         runTest();
     });
@@ -60,7 +60,34 @@
             InspectorTest.expectThat(!isEmptyObject(webSocketResource.responseHeaders), "Resource should have response headers.");
             InspectorTest.log(`Resource readyState should be ${String(webSocketResource.readyState)}.`);
 
-            resolve();
+            let expectedFrames = [
+                {
+                    data: "Hello World!",
+                    isOutgoing: true,
+                },
+                {
+                    data: "Hello World!",
+                    isOutgoing: false,
+                },
+            ];
+
+            let handleFrameAdded = (event) => {
+                let frame = event.data;
+                let expectedFrame = expectedFrames[webSocketResource.frames.length - 1];
+                if (!expectedFrame)
+                    return;
+
+                InspectorTest.expectEqual(frame.data, expectedFrame.data, `Frame data should be '${expectedFrame.data}'`);
+                InspectorTest.expectEqual(frame.isOutgoing, expectedFrame.isOutgoing, `Frame outgoing should be '${expectedFrame.isOutgoing}'`);
+
+                if (webSocketResource.frames.length == expectedFrames.length) {
+                    webSocketResource.removeEventListener(WI.WebSocketResource.Event.FrameAdded, handleFrameAdded);
+                    resolve();
+                }
+            };
+            webSocketResource.addEventListener(WI.WebSocketResource.Event.FrameAdded, handleFrameAdded);
+
+            InspectorTest.evaluateInPage("window.testWebSocket.send(\"Hello World!\")");
         }
     });
 

Modified: trunk/Source/WebCore/ChangeLog (270936 => 270937)


--- trunk/Source/WebCore/ChangeLog	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/ChangeLog	2020-12-17 18:26:06 UTC (rev 270937)
@@ -1,3 +1,38 @@
+2020-12-17  Patrick Angle  <[email protected]>
+
+        Web Inspector: REGRESSION(r266467): viewing a WebSocket created before Web Inspector was opened doesn't show any message frames
+        https://bugs.webkit.org/show_bug.cgi?id=219510
+
+        Reviewed by Youenn Fablet.
+
+        Updated test: http/tests/websocket/tests/hybi/inspector/before-load.html
+
+        Restored functionality prior to r266467 so that the `progressIdentifier` (previously `channelIdentifier`) is
+        available from `WebSocketChannel`.
+
+        * Modules/websockets/ThreadableWebSocketChannel.h:
+        * Modules/websockets/WebSocketChannel.cpp:
+        (WebCore::WebSocketChannel::WebSocketChannel):
+        (WebCore::WebSocketChannel::connect):
+        (WebCore::WebSocketChannel::fail):
+        (WebCore::WebSocketChannel::disconnect):
+        (WebCore::WebSocketChannel::didOpenSocketStream):
+        (WebCore::WebSocketChannel::didCloseSocketStream):
+        (WebCore::WebSocketChannel::didFailSocketStream):
+        (WebCore::WebSocketChannel::processBuffer):
+        (WebCore::WebSocketChannel::processFrame):
+        (WebCore::WebSocketChannel::sendFrame):
+        * Modules/websockets/WebSocketChannel.h:
+        - Reinstate a separate progress identifier for inspection
+        * Modules/websockets/WebSocketChannelInspector.cpp:
+        (WebCore::progressIdentifier const):
+        * Modules/websockets/WebSocketChannelInspector.h:
+        - Support getting the progress identifier.
+        * Modules/websockets/WorkerThreadableWebSocketChannel.h:
+        * inspector/agents/InspectorNetworkAgent.cpp:
+        (WebCore::InspectorNetworkAgent::enable):
+        (WebCore::InspectorNetworkAgent::webSocketForRequestId):
+
 2020-12-17  Rob Buis  <[email protected]>
 
         Make FontCascade::CodePath an enum class

Modified: trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.h (270936 => 270937)


--- trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.h	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.h	2020-12-17 18:26:06 UTC (rev 270937)
@@ -80,6 +80,7 @@
     virtual void suspend() = 0;
     virtual void resume() = 0;
 
+    virtual unsigned long progressIdentifier() const = 0;
     virtual bool hasCreatedHandshake() const = 0;
     virtual bool isConnected() const = 0;
     using CookieGetter = Function<String(const URL&)>;

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp (270936 => 270937)


--- trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp	2020-12-17 18:26:06 UTC (rev 270937)
@@ -71,9 +71,9 @@
     , m_socketProvider(provider)
 {
     if (Page* page = document.page())
-        m_identifier = page->progress().createUniqueIdentifier();
+        m_progressIdentifier = page->progress().createUniqueIdentifier();
 
-    LOG(Network, "WebSocketChannel %p ctor, identifier %u", this, m_identifier);
+    LOG(Network, "WebSocketChannel %p ctor, progress identifier %u", this, m_progressIdentifier);
 }
 
 WebSocketChannel::~WebSocketChannel()
@@ -100,8 +100,8 @@
     m_handshake = makeUnique<WebSocketHandshake>(validatedURL->url, protocol, userAgent, clientOrigin, m_allowCookies);
     m_handshake->reset();
     m_handshake->addExtensionProcessor(m_deflateFramer.createExtensionProcessor());
-    if (m_identifier)
-        InspectorInstrumentation::didCreateWebSocket(m_document.get(), m_identifier, validatedURL->url);
+    if (m_progressIdentifier)
+        InspectorInstrumentation::didCreateWebSocket(m_document.get(), m_progressIdentifier, validatedURL->url);
 
     auto* frame = m_document->frame();
     auto* page = m_document->page();
@@ -205,7 +205,7 @@
     RELEASE_LOG(Network, "WebSocketChannel %p fail() reason='%s'", this, reason.utf8().data());
     ASSERT(!m_suspended);
     if (m_document) {
-        InspectorInstrumentation::didReceiveWebSocketFrameError(m_document.get(), m_identifier, reason);
+        InspectorInstrumentation::didReceiveWebSocketFrameError(m_document.get(), m_progressIdentifier, reason);
 
         String consoleMessage;
         if (m_handshake)
@@ -235,8 +235,8 @@
 void WebSocketChannel::disconnect()
 {
     LOG(Network, "WebSocketChannel %p disconnect()", this);
-    if (m_identifier && m_document)
-        InspectorInstrumentation::didCloseWebSocket(m_document.get(), m_identifier);
+    if (m_progressIdentifier && m_document)
+        InspectorInstrumentation::didCloseWebSocket(m_document.get(), m_progressIdentifier);
     m_client = nullptr;
     m_document = nullptr;
     if (m_handle)
@@ -261,13 +261,13 @@
     ASSERT(&handle == m_handle);
     if (!m_document)
         return;
-    if (m_identifier && UNLIKELY(InspectorInstrumentation::hasFrontends())) {
+    if (m_progressIdentifier && UNLIKELY(InspectorInstrumentation::hasFrontends())) {
         auto cookieRequestHeaderFieldValue = [document = m_document] (const URL& url) -> String {
             if (!document || !document->page())
                 return { };
             return document->page()->cookieJar().cookieRequestHeaderFieldValue(*document, url);
         };
-        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_document.get(), m_identifier, m_handshake->clientHandshakeRequest(WTFMove(cookieRequestHeaderFieldValue)));
+        InspectorInstrumentation::willSendWebSocketHandshakeRequest(m_document.get(), m_progressIdentifier, m_handshake->clientHandshakeRequest(WTFMove(cookieRequestHeaderFieldValue)));
     }
     auto handshakeMessage = m_handshake->clientHandshakeMessage();
     Optional<CookieRequestHeaderFieldProxy> cookieRequestHeaderFieldProxy;
@@ -285,8 +285,8 @@
 void WebSocketChannel::didCloseSocketStream(SocketStreamHandle& handle)
 {
     LOG(Network, "WebSocketChannel %p didCloseSocketStream()", this);
-    if (m_identifier && m_document)
-        InspectorInstrumentation::didCloseWebSocket(m_document.get(), m_identifier);
+    if (m_progressIdentifier && m_document)
+        InspectorInstrumentation::didCloseWebSocket(m_document.get(), m_progressIdentifier);
     ASSERT_UNUSED(handle, &handle == m_handle || !m_handle);
     m_closed = true;
     if (m_closingTimer.isActive())
@@ -360,7 +360,7 @@
             message = makeString("WebSocket network error: error code ", error.errorCode());
         else
             message = "WebSocket network error: " + error.localizedDescription();
-        InspectorInstrumentation::didReceiveWebSocketFrameError(m_document.get(), m_identifier, message);
+        InspectorInstrumentation::didReceiveWebSocketFrameError(m_document.get(), m_progressIdentifier, message);
         m_document->addConsoleMessage(MessageSource::Network, MessageLevel::Error, message);
         LOG_ERROR("%s", message.utf8().data());
     }
@@ -446,8 +446,8 @@
         if (headerLength <= 0)
             return false;
         if (m_handshake->mode() == WebSocketHandshake::Connected) {
-            if (m_identifier)
-                InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_document.get(), m_identifier, m_handshake->serverHandshakeResponse());
+            if (m_progressIdentifier)
+                InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(m_document.get(), m_progressIdentifier, m_handshake->serverHandshakeResponse());
             String serverSetCookie = m_handshake->serverSetCookie();
             if (!serverSetCookie.isEmpty()) {
                 if (m_document && m_document->page() && m_document->page()->cookieJar().cookiesEnabled(*m_document))
@@ -581,7 +581,7 @@
         return false;
     }
 
-    InspectorInstrumentation::didReceiveWebSocketFrame(m_document.get(), m_identifier, frame);
+    InspectorInstrumentation::didReceiveWebSocketFrame(m_document.get(), m_progressIdentifier, frame);
 
     switch (frame.opCode) {
     case WebSocketFrame::OpCodeContinuation:
@@ -819,7 +819,7 @@
     ASSERT(!m_suspended);
 
     WebSocketFrame frame(opCode, true, false, true, data, dataLength);
-    InspectorInstrumentation::didSendWebSocketFrame(m_document.get(), m_identifier, frame);
+    InspectorInstrumentation::didSendWebSocketFrame(m_document.get(), m_progressIdentifier, frame);
 
     auto deflateResult = m_deflateFramer.deflate(frame);
     if (!deflateResult->succeeded()) {

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannel.h (270936 => 270937)


--- trunk/Source/WebCore/Modules/websockets/WebSocketChannel.h	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannel.h	2020-12-17 18:26:06 UTC (rev 270937)
@@ -114,6 +114,7 @@
     void didFinishLoading() override;
     void didFail(ExceptionCode errorCode) override;
 
+    unsigned long progressIdentifier() const final { return m_progressIdentifier; }
     bool hasCreatedHandshake() const final { return !!m_handshake; }
     bool isConnected() const final { return m_handshake->mode() == WebSocketHandshake::Mode::Connected; }
     ResourceRequest clientHandshakeRequest(const CookieGetter&) const final;
@@ -208,7 +209,7 @@
     bool m_shouldDiscardReceivedData { false };
     unsigned m_unhandledBufferedAmount { 0 };
 
-    unsigned m_identifier { 0 }; // m_identifier == 0 means that we could not obtain a valid identifier.
+    unsigned m_progressIdentifier { 0 }; // m_progressIdentifier == 0 means that we could not obtain a progress identifier.
 
     // Private members only for hybi-10 protocol.
     bool m_hasContinuousFrame { false };

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannelInspector.cpp (270936 => 270937)


--- trunk/Source/WebCore/Modules/websockets/WebSocketChannelInspector.cpp	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannelInspector.cpp	2020-12-17 18:26:06 UTC (rev 270937)
@@ -95,4 +95,9 @@
     InspectorInstrumentation::didReceiveWebSocketFrameError(document, m_progressIdentifier, errorMessage);
 }
 
+unsigned long WebSocketChannelInspector::progressIdentifier() const
+{
+    return m_progressIdentifier;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannelInspector.h (270936 => 270937)


--- trunk/Source/WebCore/Modules/websockets/WebSocketChannelInspector.h	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannelInspector.h	2020-12-17 18:26:06 UTC (rev 270937)
@@ -45,6 +45,8 @@
     void didReceiveWebSocketFrame(Document*, const WebSocketFrame&);
     void didSendWebSocketFrame(Document*, const WebSocketFrame&);
     void didReceiveWebSocketFrameError(Document*, const String& errorMessage);
+    
+    unsigned long progressIdentifier() const;
 
 private:
     unsigned long m_progressIdentifier { 0 };

Modified: trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h (270936 => 270937)


--- trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.h	2020-12-17 18:26:06 UTC (rev 270937)
@@ -159,8 +159,10 @@
     WEBCORE_EXPORT WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient&, const String& taskMode, SocketProvider&);
 
     class WorkerGlobalScopeDidInitializeTask;
-
+    
+    unsigned long progressIdentifier() const final { return 0; }
     // FIXME: <https://webkit.org/b/168475> Web Inspector: Correctly display iframe's and worker's WebSockets
+    // Dummy implementation of inspector related APIs.
     bool hasCreatedHandshake() const final { return false; }
     bool isConnected() const final { return false; }
     ResourceRequest clientHandshakeRequest(const CookieGetter&) const final { return m_handshakeRequest; }

Modified: trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp (270936 => 270937)


--- trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp	2020-12-17 18:26:06 UTC (rev 270937)
@@ -837,7 +837,7 @@
             auto& document = downcast<Document>(*webSocket->scriptExecutionContext());
             auto channel = webSocket->channel();
 
-            auto identifier = channel->identifier().toUInt64();
+            auto identifier = channel->progressIdentifier();
             didCreateWebSocket(identifier, webSocket->url());
 
             auto cookieRequestHeaderFieldValue = [document = makeWeakPtr(document)](const URL& url) -> String {
@@ -1014,7 +1014,7 @@
     LockHolder lock(WebSocket::allActiveWebSocketsMutex());
 
     for (auto* webSocket : activeWebSockets(lock)) {
-        if (IdentifiersFactory::requestId(webSocket->channel()->identifier().toUInt64()) == requestId)
+        if (IdentifiersFactory::requestId(webSocket->channel()->progressIdentifier()) == requestId)
             return webSocket;
     }
 

Modified: trunk/Source/WebKit/ChangeLog (270936 => 270937)


--- trunk/Source/WebKit/ChangeLog	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebKit/ChangeLog	2020-12-17 18:26:06 UTC (rev 270937)
@@ -1,3 +1,15 @@
+2020-12-17  Patrick Angle  <[email protected]>
+
+        Web Inspector: REGRESSION(r266467): viewing a WebSocket created before Web Inspector was opened doesn't show any message frames
+        https://bugs.webkit.org/show_bug.cgi?id=219510
+
+        Reviewed by Youenn Fablet.
+
+        Restored functionality prior to r266467 so that the `progressIdentifier` (previously `channelIdentifier`) is
+        available from `WebSocketChannel`.
+
+        * WebProcess/Network/WebSocketChannel.h:
+
 2020-12-17  Rob Buis  <[email protected]>
 
         Make FontCascade::CodePath an enum class

Modified: trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h (270936 => 270937)


--- trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h	2020-12-17 18:21:36 UTC (rev 270936)
+++ trunk/Source/WebKit/WebProcess/Network/WebSocketChannel.h	2020-12-17 18:26:06 UTC (rev 270937)
@@ -97,6 +97,7 @@
     template<typename T> void sendMessage(T&&, size_t byteLength);
     void enqueueTask(Function<void()>&&);
 
+    unsigned long progressIdentifier() const final { return m_inspector.progressIdentifier(); }
     bool hasCreatedHandshake() const final { return !m_url.isNull(); }
     bool isConnected() const final { return !m_handshakeResponse.isNull(); }
     WebCore::ResourceRequest clientHandshakeRequest(const CookieGetter&) const final { return m_handshakeRequest; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to