Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: content/common/websocket_messages.h

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

Powered by Google App Engine
This is Rietveld 408576698