Get foreground tab on Android
[chromium-blink-merge.git] / content / common / websocket_messages.h
blob233aacf1af17291f30146bd9165c33e6f3cd3fb1
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 // WebSocket messages sent from the renderer to the browser.
31 // Open new virtual WebSocket connection to |socket_url|. |channel_id| is an
32 // identifier chosen by the renderer for the new channel. It cannot correspond
33 // to an existing open channel, and must be between 1 and
34 // 0x7FFFFFFF. |requested_protocols| is a list of tokens identifying
35 // sub-protocols the renderer would like to use, as described in RFC6455
36 // "Subprotocols Using the WebSocket Protocol".
38 // The browser process will not send |channel_id| as-is to the remote server; it
39 // will try to use a short id on the wire. This saves the renderer from
40 // having to try to choose the ids cleverly.
41 IPC_MESSAGE_ROUTED3(WebSocketHostMsg_AddChannelRequest,
42 GURL /* socket_url */,
43 std::vector<std::string> /* requested_protocols */,
44 GURL /* origin */)
46 // WebSocket messages sent from the browser to the renderer.
48 // Respond to an AddChannelRequest for channel |channel_id|. |channel_id| is
49 // scoped to the renderer process; while it is unique per-renderer, the browser
50 // may have multiple renderers using the same id. If |fail| is true, the channel
51 // could not be established (the cause of the failure is not provided to the
52 // renderer in order to limit its ability to abuse WebSockets to perform network
53 // probing, etc.). If |fail| is set then the |channel_id| is available for
54 // re-use. |selected_protocol| is the sub-protocol the server selected,
55 // or empty if no sub-protocol was selected. |extensions| is the list of
56 // extensions negotiated for the connection.
57 IPC_MESSAGE_ROUTED3(WebSocketMsg_AddChannelResponse,
58 bool /* fail */,
59 std::string /* selected_protocol */,
60 std::string /* extensions */)
62 // Notify the renderer that the browser is required to fail the connection
63 // (see RFC6455 7.1.7 for details).
64 // When the renderer process receives this messages it does the following:
65 // 1. Fire an error event.
66 // 2. Show |message| to the inspector.
67 // 3. Close the channel immediately uncleanly, as if it received
68 // DropChannel(was_clean = false, code = 1006, reason = "").
69 // |message| will be shown in the inspector and won't be passed to the script.
70 // TODO(yhirano): Find the way to pass |message| directly to the inspector
71 // process.
72 IPC_MESSAGE_ROUTED1(WebSocketMsg_NotifyFailure,
73 std::string /* message */)
75 // WebSocket messages that can be sent in either direction.
77 IPC_ENUM_TRAITS(content::WebSocketMessageType)
79 // Send a non-control frame on |channel_id|. If the sender is the renderer, it
80 // will be sent to the remote server. If the sender is the browser, it comes
81 // from the remote server. |fin| indicates that this frame is the last in the
82 // current message. |type| is the type of the message. On the first frame of a
83 // message, it must be set to either WEB_SOCKET_MESSAGE_TYPE_TEXT or
84 // WEB_SOCKET_MESSAGE_TYPE_BINARY. On subsequent frames, it must be set to
85 // WEB_SOCKET_MESSAGE_TYPE_CONTINUATION, and the type is the same as that of the
86 // first message. If |type| is WEB_SOCKET_MESSAGE_TYPE_TEXT, then the
87 // concatenation of the |data| from every frame in the message must be valid
88 // UTF-8. If |fin| is not set, |data| must be non-empty.
89 IPC_MESSAGE_ROUTED3(WebSocketMsg_SendFrame,
90 bool /* fin */,
91 content::WebSocketMessageType /* type */,
92 std::vector<char> /* data */)
94 // Add |quota| tokens of send quota for channel |channel_id|. |quota| must be a
95 // positive integer. Both the browser and the renderer set send quota for the
96 // other side, and check that quota has not been exceeded when receiving
97 // messages. Both sides start a new channel with a quota of 0, and must wait for
98 // a FlowControl message before calling SendFrame. The total available quota on
99 // one side must never exceed 0x7FFFFFFFFFFFFFFF tokens.
100 IPC_MESSAGE_ROUTED1(WebSocketMsg_FlowControl,
101 int64 /* quota */)
103 // Drop the channel.
104 // When sent by the renderer, this will cause a DropChannel message to be sent
105 // if the multiplex extension is in use, otherwise a Close message will be sent
106 // and the TCP/IP connection will be closed.
107 // When sent by the browser, this indicates that a Close or DropChannel has been
108 // received, the connection was closed, or a network or protocol error
109 // occurred. On receiving DropChannel, the renderer process may consider the
110 // |channel_id| available for reuse by a new AddChannelRequest.
111 // |code| is one of the reason codes specified in RFC6455 or
112 // draft-ietf-hybi-websocket-multiplexing-09. |reason|, if non-empty, is a
113 // UTF-8 encoded string which may be useful for debugging but is not necessarily
114 // human-readable, as supplied by the server in the Close or DropChannel
115 // message.
116 // If |was_clean| is false on a message from the browser, then the WebSocket
117 // connection was not closed cleanly. If |was_clean| is false on a message from
118 // the renderer, then the connection should be closed immediately without a
119 // closing handshake and the renderer cannot accept any new messages on this
120 // connection.
121 IPC_MESSAGE_ROUTED3(WebSocketMsg_DropChannel,
122 bool /* was_clean */,
123 unsigned short /* code */,
124 std::string /* reason */)