Changeset 256497 in webkit


Ignore:
Timestamp:
Feb 12, 2020 6:18:29 PM (4 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: encode binary web socket frames using base64
https://bugs.webkit.org/show_bug.cgi?id=207448

Previous representation of binary frames is lossy using fromUTF8WithLatin1Fallback,
this patch consistently encodes binary data using base64.

Patch by Pavel Feldman <pavel.feldman@gmail.com> on 2020-02-12
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

  • inspector/protocol/Network.json:

Source/WebCore:

  • inspector/agents/InspectorNetworkAgent.cpp:

(WebCore::Inspector::buildWebSocketMessage):
(WebCore::InspectorNetworkAgent::didReceiveWebSocketFrame):
(WebCore::InspectorNetworkAgent::didSendWebSocketFrame):

Source/WebInspectorUI:

  • UserInterface/Models/WebSocketResource.js:

(WI.WebSocketResource.prototype.addFrame):

LayoutTests:

  • http/tests/websocket/tests/hybi/inspector/binary-expected.txt:
  • http/tests/websocket/tests/hybi/inspector/binary.html:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r256493 r256497  
     12020-02-12  Pavel Feldman  <pavel.feldman@gmail.com>
     2
     3        Web Inspector: encode binary web socket frames using base64
     4        https://bugs.webkit.org/show_bug.cgi?id=207448
     5       
     6        Previous representation of binary frames is lossy using fromUTF8WithLatin1Fallback,
     7        this patch consistently encodes binary data using base64.
     8
     9        Reviewed by Timothy Hatcher.
     10
     11        * http/tests/websocket/tests/hybi/inspector/binary-expected.txt:
     12        * http/tests/websocket/tests/hybi/inspector/binary.html:
     13
    1142020-02-12  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/binary-expected.txt

    r215388 r256497  
    77PASS: Frame should not have data.
    88PASS: Frame should be binary.
     9PASS: Binary frames should be base64 encoded.
    910PASS: Frame should be outgoing.
    1011PASS: Frame should have walltime.
     
    3435PASS: Frame should not have data.
    3536PASS: Frame should be binary.
     37PASS: Binary frames should be base64 encoded.
    3638PASS: Frame should be outgoing.
    3739PASS: Frame should have walltime.
  • trunk/LayoutTests/http/tests/websocket/tests/hybi/inspector/binary.html

    r220119 r256497  
    5757
    5858                if (frameAddedCount === 1) {
     59                    InspectorTest.expectEqual(atob(frame.dataForTest), "Hello, world!", "Binary frames should be base64 encoded.");
    5960                    InspectorTest.expectThat(frame.isOutgoing, "Frame should be outgoing.");
    6061                    InspectorTest.expectThat(typeof frame.walltime === "number", "Frame should have walltime.");
  • trunk/Source/JavaScriptCore/ChangeLog

    r256477 r256497  
     12020-02-12  Pavel Feldman  <pavel.feldman@gmail.com>
     2
     3        Web Inspector: encode binary web socket frames using base64
     4        https://bugs.webkit.org/show_bug.cgi?id=207448
     5       
     6        Previous representation of binary frames is lossy using fromUTF8WithLatin1Fallback,
     7        this patch consistently encodes binary data using base64.
     8
     9        Reviewed by Timothy Hatcher.
     10
     11        * inspector/protocol/Network.json:
     12
    1132020-02-12  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/Source/JavaScriptCore/inspector/protocol/Network.json

    r252614 r256497  
    124124                { "name": "opcode", "type": "number", "description": "WebSocket frame opcode." },
    125125                { "name": "mask", "type": "boolean", "description": "WebSocket frame mask." },
    126                 { "name": "payloadData", "type": "string", "description": "WebSocket frame payload data." },
     126                { "name": "payloadData", "type": "string", "description": "WebSocket frame payload data, binary frames (opcode = 2) are base64-encoded." },
    127127                { "name": "payloadLength", "type": "number", "description": "WebSocket frame payload length in bytes." }
    128128            ]
  • trunk/Source/WebCore/ChangeLog

    r256496 r256497  
     12020-02-12  Pavel Feldman  <pavel.feldman@gmail.com>
     2
     3        Web Inspector: encode binary web socket frames using base64
     4        https://bugs.webkit.org/show_bug.cgi?id=207448
     5       
     6        Previous representation of binary frames is lossy using fromUTF8WithLatin1Fallback,
     7        this patch consistently encodes binary data using base64.
     8
     9        Reviewed by Timothy Hatcher.
     10
     11        * inspector/agents/InspectorNetworkAgent.cpp:
     12        (WebCore::Inspector::buildWebSocketMessage):
     13        (WebCore::InspectorNetworkAgent::didReceiveWebSocketFrame):
     14        (WebCore::InspectorNetworkAgent::didSendWebSocketFrame):
     15
    1162020-02-12  Pavel Feldman  <pavel.feldman@gmail.com>
    217
  • trunk/Source/WebCore/inspector/agents/InspectorNetworkAgent.cpp

    r254919 r256497  
    172172};
    173173
     174Ref<Inspector::Protocol::Network::WebSocketFrame> buildWebSocketMessage(const WebSocketFrame& frame)
     175{
     176    return Inspector::Protocol::Network::WebSocketFrame::create()
     177        .setOpcode(frame.opCode)
     178        .setMask(frame.masked)
     179        .setPayloadData(frame.opCode == 1 ? String::fromUTF8WithLatin1Fallback(frame.payload, frame.payloadLength) : base64Encode(frame.payload, frame.payloadLength))
     180        .setPayloadLength(frame.payloadLength)
     181        .release();
     182}
     183
    174184} // namespace
    175185
     
    771781void InspectorNetworkAgent::didReceiveWebSocketFrame(unsigned long identifier, const WebSocketFrame& frame)
    772782{
    773     auto frameObject = Inspector::Protocol::Network::WebSocketFrame::create()
    774         .setOpcode(frame.opCode)
    775         .setMask(frame.masked)
    776         .setPayloadData(String::fromUTF8WithLatin1Fallback(frame.payload, frame.payloadLength))
    777         .setPayloadLength(frame.payloadLength)
    778         .release();
    779     m_frontendDispatcher->webSocketFrameReceived(IdentifiersFactory::requestId(identifier), timestamp(), WTFMove(frameObject));
    780 }
    781 
     783    m_frontendDispatcher->webSocketFrameReceived(IdentifiersFactory::requestId(identifier), timestamp(), buildWebSocketMessage(frame));
     784}
    782785void InspectorNetworkAgent::didSendWebSocketFrame(unsigned long identifier, const WebSocketFrame& frame)
    783786{
    784     auto frameObject = Inspector::Protocol::Network::WebSocketFrame::create()
    785         .setOpcode(frame.opCode)
    786         .setMask(frame.masked)
    787         .setPayloadData(String::fromUTF8WithLatin1Fallback(frame.payload, frame.payloadLength))
    788         .setPayloadLength(frame.payloadLength)
    789         .release();
    790     m_frontendDispatcher->webSocketFrameSent(IdentifiersFactory::requestId(identifier), timestamp(), WTFMove(frameObject));
     787    m_frontendDispatcher->webSocketFrameSent(IdentifiersFactory::requestId(identifier), timestamp(), buildWebSocketMessage(frame));
    791788}
    792789
  • trunk/Source/WebInspectorUI/ChangeLog

    r256374 r256497  
     12020-02-12  Pavel Feldman  <pavel.feldman@gmail.com>
     2
     3        Web Inspector: encode binary web socket frames using base64
     4        https://bugs.webkit.org/show_bug.cgi?id=207448
     5       
     6        Previous representation of binary frames is lossy using fromUTF8WithLatin1Fallback,
     7        this patch consistently encodes binary data using base64.
     8
     9        Reviewed by Timothy Hatcher.
     10
     11        * UserInterface/Models/WebSocketResource.js:
     12        (WI.WebSocketResource.prototype.addFrame):
     13
    1142020-02-11  Nikita Vasilyev  <nvasilyev@apple.com>
    215
  • trunk/Source/WebInspectorUI/UserInterface/Models/WebSocketResource.js

    r248720 r256497  
    7676        let frame = {data: frameData, isOutgoing, opcode, walltime: this._walltimeForWebSocketTimestamp(timestamp)};
    7777        this._frames.push(frame);
     78        if (InspectorFrontendHost.isUnderTest())
     79            frame.dataForTest = data;
    7880
    7981        // COMPATIBILITY (iOS 10.3): `payloadLength` did not exist in 10.3 and earlier.
Note: See TracChangeset for help on using the changeset viewer.