| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 // Multiply-included message file, hence no include guard. | |
| 6 | |
| 7 // This file defines the IPCs for the browser-side implementation of | |
| 8 // WebSockets. | |
| 9 // | |
| 10 // This IPC interface was originally desined based on the WebSocket | |
| 11 // multiplexing draft spec, | |
| 12 // http://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-09. So, | |
| 13 // some of them are given names correspond to the concepts defined in the spec. | |
| 14 // | |
| 15 // A WebSocketBridge object in the renderer and the corresponding WebSocketHost | |
| 16 // object in the browser are associated using an identifier named channel ID. | |
| 17 // The channel id is chosen by the renderer for a new channel. While the | |
| 18 // channel id is unique per-renderer, the browser may have multiple renderers | |
| 19 // using the same channel id. | |
| 20 // | |
| 21 // There're WebSocketDispatcherHost objects for each renderer. Each of | |
| 22 // WebSocketDispatcherHost holds a channel id to WebSocketHost map. | |
| 23 // | |
| 24 // Received messages are routed to the corresponding object by | |
| 25 // WebSocketDispatcher in the renderer and WebSocketDispatcherHost in the | |
| 26 // browser using the channel ID. | |
| 27 // | |
| 28 // The channel ID value is stored in the routing ID member which is available | |
| 29 // when we use the IPC_MESSAGE_ROUTED macro though it's unintended use. | |
| 30 | |
| 31 #include <stdint.h> | |
| 32 | |
| 33 #include <string> | |
| 34 #include <vector> | |
| 35 | |
| 36 #include "content/common/content_export.h" | |
| 37 #include "content/common/websocket.h" | |
| 38 #include "ipc/ipc_message_macros.h" | |
| 39 #include "url/gurl.h" | |
| 40 #include "url/origin.h" | |
| 41 | |
| 42 #undef IPC_MESSAGE_EXPORT | |
| 43 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT | |
| 44 #define IPC_MESSAGE_START WebSocketMsgStart | |
| 45 | |
| 46 IPC_ENUM_TRAITS_MAX_VALUE(content::WebSocketMessageType, | |
| 47 content::WEB_SOCKET_MESSAGE_TYPE_LAST) | |
| 48 | |
| 49 IPC_STRUCT_TRAITS_BEGIN(content::WebSocketHandshakeRequest) | |
| 50 IPC_STRUCT_TRAITS_MEMBER(url) | |
| 51 IPC_STRUCT_TRAITS_MEMBER(headers) | |
| 52 IPC_STRUCT_TRAITS_MEMBER(headers_text) | |
| 53 IPC_STRUCT_TRAITS_MEMBER(request_time) | |
| 54 IPC_STRUCT_TRAITS_END() | |
| 55 | |
| 56 IPC_STRUCT_TRAITS_BEGIN(content::WebSocketHandshakeResponse) | |
| 57 IPC_STRUCT_TRAITS_MEMBER(url) | |
| 58 IPC_STRUCT_TRAITS_MEMBER(status_code) | |
| 59 IPC_STRUCT_TRAITS_MEMBER(status_text) | |
| 60 IPC_STRUCT_TRAITS_MEMBER(headers) | |
| 61 IPC_STRUCT_TRAITS_MEMBER(headers_text) | |
| 62 IPC_STRUCT_TRAITS_MEMBER(response_time) | |
| 63 IPC_STRUCT_TRAITS_END() | |
| 64 | |
| 65 // WebSocket messages sent from the renderer to the browser. | |
| 66 | |
| 67 // Open new WebSocket connection to |socket_url|. |requested_protocols| is a | |
| 68 // list of tokens identifying sub-protocols the renderer would like to use, as | |
| 69 // described in RFC6455 "Subprotocols Using the WebSocket Protocol". | |
| 70 IPC_MESSAGE_ROUTED4(WebSocketHostMsg_AddChannelRequest, | |
| 71 GURL /* socket_url */, | |
| 72 std::vector<std::string> /* requested_protocols */, | |
| 73 url::Origin /* origin */, | |
| 74 int /* render_frame_id */) | |
| 75 | |
| 76 // Send a complete binary WebSocket message consisting of the Blob identified by | |
| 77 // |uuid|. The message will be split into frames as necessary. |expected_size| | |
| 78 // must match the browser's idea of the size of the Blob to prevent flow control | |
| 79 // from becoming desynchronised. If it does not match the connection will be | |
| 80 // terminated with a WebSocketMsg_NotifyFailure message. On success, the browser | |
| 81 // will have consumed |expected_size| bytes of flow control send quota and the | |
| 82 // renderer needs to subtract that from its running total of flow control send | |
| 83 // quota. See the design doc at | |
| 84 // https://docs.google.com/document/d/1CDiXB9pBumhFVVfmIn1CRI6v6byxyqWu2urEE9xp7
14/edit | |
| 85 // SendFrame or SendBlob IPCs must not be sent by the renderer until the | |
| 86 // BlobSendComplete message has been received from the browser. The renderer | |
| 87 // should retain a reference to the Blob until either a BlobSendComplete or | |
| 88 // NotifyFailure IPC is received. | |
| 89 IPC_MESSAGE_ROUTED2(WebSocketHostMsg_SendBlob, | |
| 90 std::string /* uuid */, | |
| 91 uint64_t /* expected_size */) | |
| 92 | |
| 93 // WebSocket messages sent from the browser to the renderer. | |
| 94 | |
| 95 // Respond to an AddChannelRequest. |selected_protocol| is the sub-protocol the | |
| 96 // server selected, or empty if no sub-protocol was selected. |extensions| is | |
| 97 // the list of extensions negotiated for the connection. | |
| 98 IPC_MESSAGE_ROUTED2(WebSocketMsg_AddChannelResponse, | |
| 99 std::string /* selected_protocol */, | |
| 100 std::string /* extensions */) | |
| 101 | |
| 102 // Notify the renderer that the browser has started an opening handshake. | |
| 103 // This message is for showing the request in the inspector and | |
| 104 // can be omitted if the inspector is not active. | |
| 105 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyStartOpeningHandshake, | |
| 106 content::WebSocketHandshakeRequest /* request */) | |
| 107 | |
| 108 // Notify the renderer that the browser has finished an opening handshake. | |
| 109 // This message precedes AddChannelResponse. | |
| 110 // This message is for showing the response in the inspector and | |
| 111 // can be omitted if the inspector is not active. | |
| 112 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyFinishOpeningHandshake, | |
| 113 content::WebSocketHandshakeResponse /* response */) | |
| 114 | |
| 115 // Notify the renderer that either: | |
| 116 // - the connection open request (WebSocketHostMsg_AddChannelRequest) failed. | |
| 117 // - the browser is required to fail the connection | |
| 118 // (see RFC6455 7.1.7 for details). | |
| 119 // | |
| 120 // When the renderer process receives this messages it does the following: | |
| 121 // 1. Fire an error event. | |
| 122 // 2. Show |message| to the inspector. | |
| 123 // 3. Close the channel immediately uncleanly, as if it received | |
| 124 // DropChannel(was_clean = false, code = 1006, reason = ""). | |
| 125 // |message| will be shown in the inspector and won't be passed to the script. | |
| 126 // TODO(yhirano): Find the way to pass |message| directly to the inspector | |
| 127 // process. | |
| 128 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyFailure, | |
| 129 std::string /* message */) | |
| 130 | |
| 131 // Indicates tbat the current Blob has finished sending. The renderer can | |
| 132 // release its reference on the Blob, and may now use SendFrame or SendBlob to | |
| 133 // send more messages. | |
| 134 IPC_MESSAGE_ROUTED0(WebSocketMsg_BlobSendComplete) | |
| 135 | |
| 136 // WebSocket messages that can be sent in either direction. | |
| 137 | |
| 138 // Send a non-control frame to the channel. | |
| 139 // - If the sender is the renderer, it will be sent to the remote server. | |
| 140 // - If the sender is the browser, it comes from the remote server. | |
| 141 // | |
| 142 // - |fin| indicates that this frame is the last in the current message. | |
| 143 // - |type| is the type of the message. On the first frame of a message, it | |
| 144 // must be set to either WEB_SOCKET_MESSAGE_TYPE_TEXT or | |
| 145 // WEB_SOCKET_MESSAGE_TYPE_BINARY. On subsequent frames, it must be set to | |
| 146 // WEB_SOCKET_MESSAGE_TYPE_CONTINUATION, and the type is the same as that of | |
| 147 // the first message. If |type| is WEB_SOCKET_MESSAGE_TYPE_TEXT, then the | |
| 148 // concatenation of the |data| from every frame in the message must be valid | |
| 149 // UTF-8. If |fin| is not set, |data| must be non-empty. | |
| 150 IPC_MESSAGE_ROUTED3(WebSocketMsg_SendFrame, | |
| 151 bool /* fin */, | |
| 152 content::WebSocketMessageType /* type */, | |
| 153 std::vector<char> /* data */) | |
| 154 | |
| 155 // Add |quota| tokens of send quota for the channel. |quota| must be a positive | |
| 156 // integer. Both the browser and the renderer set send quota for the other | |
| 157 // side, and check that quota has not been exceeded when receiving messages. | |
| 158 // Both sides start a new channel with a quota of 0, and must wait for a | |
| 159 // FlowControl message before calling SendFrame. The total available quota on | |
| 160 // one side must never exceed 0x7FFFFFFFFFFFFFFF tokens. | |
| 161 // | |
| 162 // During "blob sending mode", ie. between the renderer sending a | |
| 163 // WebSocketHostMsg_SendBlob IPC and receiving a WebSocketMsg_BlobSendComplete | |
| 164 // IPC, quota is used up in the browser process to send the blob, but | |
| 165 // FlowControl IPCs for that quota are still sent to the renderer. The render | |
| 166 // process needs to take into account that quota equal to the size of the Blob | |
| 167 // has already been used when calculating how much send quota it has left after | |
| 168 // receiving BlobSendComplete. | |
| 169 IPC_MESSAGE_ROUTED1(WebSocketMsg_FlowControl, int64_t /* quota */) | |
| 170 | |
| 171 // Drop the channel. | |
| 172 // | |
| 173 // When sent by the renderer, this will cause a Close message will be sent and | |
| 174 // the TCP/IP connection will be closed. | |
| 175 // | |
| 176 // When sent by the browser, this indicates that a Close has been received, the | |
| 177 // connection was closed, or a network or protocol error occurred. | |
| 178 // | |
| 179 // - |code| is one of the reason codes specified in RFC6455. | |
| 180 // - |reason|, if non-empty, is a UTF-8 encoded string which may be useful for | |
| 181 // debugging but is not necessarily human-readable, as supplied by the server | |
| 182 // in the Close message. | |
| 183 // - If |was_clean| is false on a message from the browser, then the WebSocket | |
| 184 // connection was not closed cleanly. If |was_clean| is false on a message | |
| 185 // from the renderer, then the connection should be closed immediately without | |
| 186 // a closing handshake and the renderer cannot accept any new messages on this | |
| 187 // connection. | |
| 188 IPC_MESSAGE_ROUTED3(WebSocketMsg_DropChannel, | |
| 189 bool /* was_clean */, | |
| 190 unsigned short /* code */, | |
| 191 std::string /* reason */) | |
| 192 | |
| 193 // Notify the renderer that a closing handshake has been initiated by the | |
| 194 // server, so that it can set the Javascript readyState to CLOSING. | |
| 195 IPC_MESSAGE_ROUTED0(WebSocketMsg_NotifyClosing) | |
| OLD | NEW |