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