Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 module content.mojom; | |
| 6 | |
| 7 import "url/mojo/origin.mojom"; | |
| 8 import "url/mojo/url.mojom"; | |
| 9 | |
| 10 enum WebSocketMessageType { | |
| 11 CONTINUATION, | |
| 12 TEXT, | |
| 13 BINARY, | |
| 14 LAST = BINARY | |
| 15 }; | |
| 16 | |
| 17 // TODO(darin): Move to a more general location. | |
| 18 struct HttpHeader { | |
| 19 string name; | |
| 20 string value; | |
| 21 }; | |
| 22 | |
| 23 // TODO(darin): Remove redundancy b/w |headers| and |headers_text|. | |
| 24 | |
| 25 struct WebSocketHandshakeRequest { | |
| 26 url.mojom.Url url; | |
| 27 array<HttpHeader> headers; | |
| 28 string headers_text; | |
| 29 }; | |
| 30 | |
| 31 struct WebSocketHandshakeResponse { | |
| 32 url.mojom.Url url; | |
| 33 int32 status_code; | |
| 34 string status_text; | |
| 35 array<HttpHeader> headers; | |
| 36 string headers_text; | |
| 37 }; | |
| 38 | |
| 39 interface WebSocketClient { | |
| 40 OnFailChannel(string reason); | |
| 41 | |
| 42 // Notify the renderer that the browser has started an opening handshake. | |
| 43 // This message is for showing the request in the inspector and | |
| 44 // can be omitted if the inspector is not active. | |
| 45 OnStartOpeningHandshake(WebSocketHandshakeRequest request); | |
| 46 | |
| 47 // Notify the renderer that the browser has finished an opening handshake. | |
| 48 // This message precedes AddChannelResponse. | |
| 49 // This message is for showing the response in the inspector and | |
| 50 // can be omitted if the inspector is not active. | |
| 51 OnFinishOpeningHandshake(WebSocketHandshakeResponse response); | |
| 52 | |
| 53 // Response to an AddChannelRequest. |selected_protocol| is the sub-protocol | |
| 54 // the server selected, or empty if no sub-protocol was selected. | |
| 55 // |extensions| is the list of extensions negotiated for the connection. | |
| 56 OnAddChannelResponse(string selected_protocol, string extensions); | |
| 57 | |
| 58 // Send a non-control frame to the channel. | |
| 59 // - If the sender is the renderer, it will be sent to the remote server. | |
|
Adam Rice
2016/07/08 04:03:11
If I understand correctly, the sender will always
| |
| 60 // - If the sender is the browser, it comes from the remote server. | |
| 61 // | |
| 62 // - |fin| indicates that this frame is the last in the current message. | |
| 63 // - |type| is the type of the message. On the first frame of a message, it | |
| 64 // must be set to either WEB_SOCKET_MESSAGE_TYPE_TEXT or | |
| 65 // WEB_SOCKET_MESSAGE_TYPE_BINARY. On subsequent frames, it must be set to | |
| 66 // WEB_SOCKET_MESSAGE_TYPE_CONTINUATION, and the type is the same as that of | |
| 67 // the first message. If |type| is WEB_SOCKET_MESSAGE_TYPE_TEXT, then the | |
| 68 // concatenation of the |data| from every frame in the message must be valid | |
| 69 // UTF-8. If |fin| is not set, |data| must be non-empty. | |
| 70 OnDataFrame(bool fin, WebSocketMessageType type, array<uint8> data); | |
| 71 | |
| 72 // Add |quota| tokens of send quota for the channel. |quota| must be a positiv e | |
|
Ben Goodger (Google)
2016/07/07 20:49:19
is this a rietveld issue or are these lines > 80co
| |
| 73 // integer. Both the browser and the renderer set send quota for the other | |
| 74 // side, and check that quota has not been exceeded when receiving messages. | |
| 75 // Both sides start a new channel with a quota of 0, and must wait for a | |
| 76 // FlowControl message before calling SendFrame. The total available quota on | |
| 77 // one side must never exceed 0x7FFFFFFFFFFFFFFF tokens. | |
| 78 OnFlowControl(int64 quota); | |
| 79 | |
| 80 // Drop the channel. | |
| 81 // | |
| 82 // When sent by the renderer, this will cause a Close message will be sent and | |
| 83 // the TCP/IP connection will be closed. | |
| 84 // | |
| 85 // When sent by the browser, this indicates that a Close has been received, th e | |
| 86 // connection was closed, or a network or protocol error occurred. | |
| 87 // | |
| 88 // - |code| is one of the reason codes specified in RFC6455. | |
| 89 // - |reason|, if non-empty, is a UTF-8 encoded string which may be useful for | |
| 90 // debugging but is not necessarily human-readable, as supplied by the serve r | |
| 91 // in the Close message. | |
| 92 // - If |was_clean| is false, then the WebSocket connection was not closed | |
| 93 // cleanly. | |
| 94 OnDropChannel(bool was_clean, uint16 code, string reason); | |
| 95 | |
| 96 // Notify the renderer that a closing handshake has been initiated by the | |
| 97 // server, so that it can set the Javascript readyState to CLOSING. | |
| 98 OnClosingHandshake(); | |
| 99 }; | |
| 100 | |
| 101 interface WebSocket { | |
| 102 // Must be called prior to any of the other methods. | |
| 103 Initialize(WebSocketClient client); | |
| 104 | |
| 105 // Open new WebSocket connection to |socket_url|. |requested_protocols| is a | |
| 106 // list of tokens identifying sub-protocols the renderer would like to use, | |
| 107 // as described in RFC6455 "Subprotocols Using the WebSocket Protocol". | |
| 108 AddChannelRequest(url.mojom.Url url, | |
| 109 array<string> requested_protocols, | |
| 110 url.mojom.Origin origin, | |
| 111 string user_agent_override); | |
| 112 | |
| 113 // Send a non-control frame to the channel. | |
| 114 // - If the sender is the renderer, it will be sent to the remote server. | |
| 115 // - If the sender is the browser, it comes from the remote server. | |
| 116 // | |
| 117 // - |fin| indicates that this frame is the last in the current message. | |
| 118 // - |type| is the type of the message. On the first frame of a message, it | |
| 119 // must be set to either WEB_SOCKET_MESSAGE_TYPE_TEXT or | |
| 120 // WEB_SOCKET_MESSAGE_TYPE_BINARY. On subsequent frames, it must be set to | |
| 121 // WEB_SOCKET_MESSAGE_TYPE_CONTINUATION, and the type is the same as that of | |
| 122 // the first message. If |type| is WEB_SOCKET_MESSAGE_TYPE_TEXT, then the | |
| 123 // concatenation of the |data| from every frame in the message must be valid | |
| 124 // UTF-8. If |fin| is not set, |data| must be non-empty. | |
| 125 SendFrame(bool fin, WebSocketMessageType type, array<uint8> data); | |
| 126 | |
| 127 // Add |quota| tokens of send quota for the channel. |quota| must be a positiv e | |
| 128 // integer. Both the browser and the renderer set send quota for the other | |
| 129 // side, and check that quota has not been exceeded when receiving messages. | |
| 130 // Both sides start a new channel with a quota of 0, and must wait for a | |
| 131 // FlowControl message before calling SendFrame. The total available quota on | |
| 132 // one side must never exceed 0x7FFFFFFFFFFFFFFF tokens. | |
| 133 SendFlowControl(int64 quota); | |
| 134 | |
| 135 // Close the channel gracefully. | |
| 136 // | |
| 137 // When sent by the renderer, this will cause a Close message will be sent and | |
| 138 // the TCP/IP connection will be closed. | |
| 139 // | |
| 140 // - |code| is one of the reason codes specified in RFC6455. | |
| 141 // - |reason|, if non-empty, is a UTF-8 encoded string which may be useful for | |
| 142 // debugging but is not necessarily human-readable, as supplied by the serve r | |
| 143 // in the Close message. | |
| 144 StartClosingHandshake(uint16 code, string reason); | |
| 145 }; | |
| OLD | NEW |