[WebSocket] Send (request|response)_headers_text to the inspector.
[chromium-blink-merge.git] / content / common / websocket_messages.h
blob20fef1e94a720b56c8c62474d773aa57a136013e
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.
5 // Multiply-included message file, hence no include guard.
7 // This file defines the IPCs for the browser-side implementation of
8 // WebSockets. For the legacy renderer-side implementation, see
9 // socket_stream_messages.h.
10 // TODO(ricea): Fix this comment when the legacy implementation has been
11 // removed.
13 // This IPC interface is based on the WebSocket multiplexing draft spec,
14 // http://tools.ietf.org/html/draft-ietf-hybi-websocket-multiplexing-09
16 #include <string>
17 #include <vector>
19 #include "base/basictypes.h"
20 #include "content/common/content_export.h"
21 #include "content/common/websocket.h"
22 #include "ipc/ipc_message_macros.h"
23 #include "url/gurl.h"
25 #undef IPC_MESSAGE_EXPORT
26 #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
27 #define IPC_MESSAGE_START WebSocketMsgStart
29 IPC_ENUM_TRAITS_MAX_VALUE(content::WebSocketMessageType,
30 content::WEB_SOCKET_MESSAGE_TYPE_LAST)
32 IPC_STRUCT_TRAITS_BEGIN(content::WebSocketHandshakeRequest)
33 IPC_STRUCT_TRAITS_MEMBER(url)
34 IPC_STRUCT_TRAITS_MEMBER(headers)
35 IPC_STRUCT_TRAITS_MEMBER(headers_text)
36 IPC_STRUCT_TRAITS_MEMBER(request_time)
37 IPC_STRUCT_TRAITS_END()
39 IPC_STRUCT_TRAITS_BEGIN(content::WebSocketHandshakeResponse)
40 IPC_STRUCT_TRAITS_MEMBER(url)
41 IPC_STRUCT_TRAITS_MEMBER(status_code)
42 IPC_STRUCT_TRAITS_MEMBER(status_text)
43 IPC_STRUCT_TRAITS_MEMBER(headers)
44 IPC_STRUCT_TRAITS_MEMBER(headers_text)
45 IPC_STRUCT_TRAITS_MEMBER(response_time)
46 IPC_STRUCT_TRAITS_END()
48 // WebSocket messages sent from the renderer to the browser.
50 // Open new virtual WebSocket connection to |socket_url|. |channel_id| is an
51 // identifier chosen by the renderer for the new channel. It cannot correspond
52 // to an existing open channel, and must be between 1 and
53 // 0x7FFFFFFF. |requested_protocols| is a list of tokens identifying
54 // sub-protocols the renderer would like to use, as described in RFC6455
55 // "Subprotocols Using the WebSocket Protocol".
57 // The browser process will not send |channel_id| as-is to the remote server; it
58 // will try to use a short id on the wire. This saves the renderer from
59 // having to try to choose the ids cleverly.
60 IPC_MESSAGE_ROUTED3(WebSocketHostMsg_AddChannelRequest,
61 GURL /* socket_url */,
62 std::vector<std::string> /* requested_protocols */,
63 GURL /* origin */)
65 // WebSocket messages sent from the browser to the renderer.
67 // Respond to an AddChannelRequest for channel |channel_id|. |channel_id| is
68 // scoped to the renderer process; while it is unique per-renderer, the browser
69 // may have multiple renderers using the same id. If |fail| is true, the channel
70 // could not be established (the cause of the failure is not provided to the
71 // renderer in order to limit its ability to abuse WebSockets to perform network
72 // probing, etc.). If |fail| is set then the |channel_id| is available for
73 // re-use. |selected_protocol| is the sub-protocol the server selected,
74 // or empty if no sub-protocol was selected. |extensions| is the list of
75 // extensions negotiated for the connection.
76 IPC_MESSAGE_ROUTED3(WebSocketMsg_AddChannelResponse,
77 bool /* fail */,
78 std::string /* selected_protocol */,
79 std::string /* extensions */)
81 // Notify the renderer that the browser has started an opening handshake.
82 // This message is for showing the request in the inspector and
83 // can be omitted if the inspector is not active.
84 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyStartOpeningHandshake,
85 content::WebSocketHandshakeRequest /* request */)
87 // Notify the renderer that the browser has finished an opening handshake.
88 // This message precedes AddChannelResponse.
89 // This message is for showing the response in the inspector and
90 // can be omitted if the inspector is not active.
91 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyFinishOpeningHandshake,
92 content::WebSocketHandshakeResponse /* response */)
94 // Notify the renderer that the browser is required to fail the connection
95 // (see RFC6455 7.1.7 for details).
96 // When the renderer process receives this messages it does the following:
97 // 1. Fire an error event.
98 // 2. Show |message| to the inspector.
99 // 3. Close the channel immediately uncleanly, as if it received
100 // DropChannel(was_clean = false, code = 1006, reason = "").
101 // |message| will be shown in the inspector and won't be passed to the script.
102 // TODO(yhirano): Find the way to pass |message| directly to the inspector
103 // process.
104 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyFailure,
105 std::string /* message */)
107 // WebSocket messages that can be sent in either direction.
109 // Send a non-control frame on |channel_id|. If the sender is the renderer, it
110 // will be sent to the remote server. If the sender is the browser, it comes
111 // from the remote server. |fin| indicates that this frame is the last in the
112 // current message. |type| is the type of the message. On the first frame of a
113 // message, it must be set to either WEB_SOCKET_MESSAGE_TYPE_TEXT or
114 // WEB_SOCKET_MESSAGE_TYPE_BINARY. On subsequent frames, it must be set to
115 // WEB_SOCKET_MESSAGE_TYPE_CONTINUATION, and the type is the same as that of the
116 // first message. If |type| is WEB_SOCKET_MESSAGE_TYPE_TEXT, then the
117 // concatenation of the |data| from every frame in the message must be valid
118 // UTF-8. If |fin| is not set, |data| must be non-empty.
119 IPC_MESSAGE_ROUTED3(WebSocketMsg_SendFrame,
120 bool /* fin */,
121 content::WebSocketMessageType /* type */,
122 std::vector<char> /* data */)
124 // Add |quota| tokens of send quota for channel |channel_id|. |quota| must be a
125 // positive integer. Both the browser and the renderer set send quota for the
126 // other side, and check that quota has not been exceeded when receiving
127 // messages. Both sides start a new channel with a quota of 0, and must wait for
128 // a FlowControl message before calling SendFrame. The total available quota on
129 // one side must never exceed 0x7FFFFFFFFFFFFFFF tokens.
130 IPC_MESSAGE_ROUTED1(WebSocketMsg_FlowControl,
131 int64 /* quota */)
133 // Drop the channel.
134 // When sent by the renderer, this will cause a DropChannel message to be sent
135 // if the multiplex extension is in use, otherwise a Close message will be sent
136 // and the TCP/IP connection will be closed.
137 // When sent by the browser, this indicates that a Close or DropChannel has been
138 // received, the connection was closed, or a network or protocol error
139 // occurred. On receiving DropChannel, the renderer process may consider the
140 // |channel_id| available for reuse by a new AddChannelRequest.
141 // |code| is one of the reason codes specified in RFC6455 or
142 // draft-ietf-hybi-websocket-multiplexing-09. |reason|, if non-empty, is a
143 // UTF-8 encoded string which may be useful for debugging but is not necessarily
144 // human-readable, as supplied by the server in the Close or DropChannel
145 // message.
146 // If |was_clean| is false on a message from the browser, then the WebSocket
147 // connection was not closed cleanly. If |was_clean| is false on a message from
148 // the renderer, then the connection should be closed immediately without a
149 // closing handshake and the renderer cannot accept any new messages on this
150 // connection.
151 IPC_MESSAGE_ROUTED3(WebSocketMsg_DropChannel,
152 bool /* was_clean */,
153 unsigned short /* code */,
154 std::string /* reason */)
156 // Notify the renderer that a closing handshake has been initiated by the
157 // server, so that it can set the Javascript readyState to CLOSING.
158 IPC_MESSAGE_ROUTED0(WebSocketMsg_NotifyClosing)