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_ROUTED5(WebSocketHostMsg_AddChannelRequest, | |
71 GURL /* socket_url */, | |
72 std::vector<std::string> /* requested_protocols */, | |
73 url::Origin /* origin */, | |
74 std::string /* user_agent_override */, | |
75 int /* render_frame_id */) | |
76 | |
77 // Send a complete binary WebSocket message consisting of the Blob identified by | |
78 // |uuid|. The message will be split into frames as necessary. |expected_size| | |
79 // must match the browser's idea of the size of the Blob to prevent flow control | |
80 // from becoming desynchronised. If it does not match the connection will be | |
81 // terminated with a WebSocketMsg_NotifyFailure message. On success, the browser | |
82 // will have consumed |expected_size| bytes of flow control send quota and the | |
83 // renderer needs to subtract that from its running total of flow control send | |
84 // quota. See the design doc at | |
85 // https://docs.google.com/document/d/1CDiXB9pBumhFVVfmIn1CRI6v6byxyqWu2urEE9xp7
14/edit | |
86 // SendFrame or SendBlob IPCs must not be sent by the renderer until the | |
87 // BlobSendComplete message has been received from the browser. The renderer | |
88 // should retain a reference to the Blob until either a BlobSendComplete or | |
89 // NotifyFailure IPC is received. | |
90 IPC_MESSAGE_ROUTED2(WebSocketHostMsg_SendBlob, | |
91 std::string /* uuid */, | |
92 uint64_t /* expected_size */) | |
93 | |
94 // WebSocket messages sent from the browser to the renderer. | |
95 | |
96 // Respond to an AddChannelRequest. |selected_protocol| is the sub-protocol the | |
97 // server selected, or empty if no sub-protocol was selected. |extensions| is | |
98 // the list of extensions negotiated for the connection. | |
99 IPC_MESSAGE_ROUTED2(WebSocketMsg_AddChannelResponse, | |
100 std::string /* selected_protocol */, | |
101 std::string /* extensions */) | |
102 | |
103 // Notify the renderer that the browser has started an opening handshake. | |
104 // This message is for showing the request in the inspector and | |
105 // can be omitted if the inspector is not active. | |
106 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyStartOpeningHandshake, | |
107 content::WebSocketHandshakeRequest /* request */) | |
108 | |
109 // Notify the renderer that the browser has finished an opening handshake. | |
110 // This message precedes AddChannelResponse. | |
111 // This message is for showing the response in the inspector and | |
112 // can be omitted if the inspector is not active. | |
113 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyFinishOpeningHandshake, | |
114 content::WebSocketHandshakeResponse /* response */) | |
115 | |
116 // Notify the renderer that either: | |
117 // - the connection open request (WebSocketHostMsg_AddChannelRequest) failed. | |
118 // - the browser is required to fail the connection | |
119 // (see RFC6455 7.1.7 for details). | |
120 // | |
121 // When the renderer process receives this messages it does the following: | |
122 // 1. Fire an error event. | |
123 // 2. Show |message| to the inspector. | |
124 // 3. Close the channel immediately uncleanly, as if it received | |
125 // DropChannel(was_clean = false, code = 1006, reason = ""). | |
126 // |message| will be shown in the inspector and won't be passed to the script. | |
127 // TODO(yhirano): Find the way to pass |message| directly to the inspector | |
128 // process. | |
129 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyFailure, | |
130 std::string /* message */) | |
131 | |
132 // Indicates tbat the current Blob has finished sending. The renderer can | |
133 // release its reference on the Blob, and may now use SendFrame or SendBlob to | |
134 // send more messages. | |
135 IPC_MESSAGE_ROUTED0(WebSocketMsg_BlobSendComplete) | |
136 | |
137 // WebSocket messages that can be sent in either direction. | |
138 | |
139 // Send a non-control frame to the channel. | |
140 // - If the sender is the renderer, it will be sent to the remote server. | |
141 // - If the sender is the browser, it comes from the remote server. | |
142 // | |
143 // - |fin| indicates that this frame is the last in the current message. | |
144 // - |type| is the type of the message. On the first frame of a message, it | |
145 // must be set to either WEB_SOCKET_MESSAGE_TYPE_TEXT or | |
146 // WEB_SOCKET_MESSAGE_TYPE_BINARY. On subsequent frames, it must be set to | |
147 // WEB_SOCKET_MESSAGE_TYPE_CONTINUATION, and the type is the same as that of | |
148 // the first message. If |type| is WEB_SOCKET_MESSAGE_TYPE_TEXT, then the | |
149 // concatenation of the |data| from every frame in the message must be valid | |
150 // UTF-8. If |fin| is not set, |data| must be non-empty. | |
151 IPC_MESSAGE_ROUTED3(WebSocketMsg_SendFrame, | |
152 bool /* fin */, | |
153 content::WebSocketMessageType /* type */, | |
154 std::vector<char> /* data */) | |
155 | |
156 // Add |quota| tokens of send quota for the channel. |quota| must be a positive | |
157 // integer. Both the browser and the renderer set send quota for the other | |
158 // side, and check that quota has not been exceeded when receiving messages. | |
159 // Both sides start a new channel with a quota of 0, and must wait for a | |
160 // FlowControl message before calling SendFrame. The total available quota on | |
161 // one side must never exceed 0x7FFFFFFFFFFFFFFF tokens. | |
162 // | |
163 // During "blob sending mode", ie. between the renderer sending a | |
164 // WebSocketHostMsg_SendBlob IPC and receiving a WebSocketMsg_BlobSendComplete | |
165 // IPC, quota is used up in the browser process to send the blob, but | |
166 // FlowControl IPCs for that quota are still sent to the renderer. The render | |
167 // process needs to take into account that quota equal to the size of the Blob | |
168 // has already been used when calculating how much send quota it has left after | |
169 // receiving BlobSendComplete. | |
170 IPC_MESSAGE_ROUTED1(WebSocketMsg_FlowControl, int64_t /* quota */) | |
171 | |
172 // Drop the channel. | |
173 // | |
174 // When sent by the renderer, this will cause a Close message will be sent and | |
175 // the TCP/IP connection will be closed. | |
176 // | |
177 // When sent by the browser, this indicates that a Close has been received, the | |
178 // connection was closed, or a network or protocol error occurred. | |
179 // | |
180 // - |code| is one of the reason codes specified in RFC6455. | |
181 // - |reason|, if non-empty, is a UTF-8 encoded string which may be useful for | |
182 // debugging but is not necessarily human-readable, as supplied by the server | |
183 // in the Close message. | |
184 // - If |was_clean| is false on a message from the browser, then the WebSocket | |
185 // connection was not closed cleanly. If |was_clean| is false on a message | |
186 // from the renderer, then the connection should be closed immediately without | |
187 // a closing handshake and the renderer cannot accept any new messages on this | |
188 // connection. | |
189 IPC_MESSAGE_ROUTED3(WebSocketMsg_DropChannel, | |
190 bool /* was_clean */, | |
191 unsigned short /* code */, | |
192 std::string /* reason */) | |
193 | |
194 // Notify the renderer that a closing handshake has been initiated by the | |
195 // server, so that it can set the Javascript readyState to CLOSING. | |
196 IPC_MESSAGE_ROUTED0(WebSocketMsg_NotifyClosing) | |
OLD | NEW |