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 #ifndef NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" // for WARN_UNUSED_RESULT
13 #include "net/base/net_export.h"
17 // Interface for events sent from the network layer to the content layer. These
18 // events will generally be sent as-is to the renderer process.
19 class NET_EXPORT WebSocketEventInterface {
21 typedef int WebSocketMessageType;
23 // Any event can cause the Channel to be deleted. The Channel needs to avoid
24 // doing further processing in this case. It does not need to do cleanup, as
25 // cleanup will already have been done as a result of the deletion.
31 virtual ~WebSocketEventInterface() {}
32 // Called in response to an AddChannelRequest. This generally means that a
33 // response has been received from the remote server, but the response might
34 // have been generated internally. If |fail| is true, the channel cannot be
35 // used and should be deleted, returning CHANNEL_DELETED.
36 virtual ChannelState OnAddChannelResponse(
38 const std::string& selected_subprotocol) WARN_UNUSED_RESULT = 0;
40 // Called when a data frame has been received from the remote host and needs
41 // to be forwarded to the renderer process.
42 virtual ChannelState OnDataFrame(
44 WebSocketMessageType type,
45 const std::vector<char>& data) WARN_UNUSED_RESULT = 0;
47 // Called to provide more send quota for this channel to the renderer
48 // process. Currently the quota units are always bytes of message body
49 // data. In future it might depend on the type of multiplexing in use.
50 virtual ChannelState OnFlowControl(int64 quota) WARN_UNUSED_RESULT = 0;
52 // Called when the remote server has Started the WebSocket Closing
53 // Handshake. The client should not attempt to send any more messages after
54 // receiving this message. It will be followed by OnDropChannel() when the
55 // closing handshake is complete.
56 virtual ChannelState OnClosingHandshake() WARN_UNUSED_RESULT = 0;
58 // Called when the channel has been dropped, either due to a network close, a
59 // network error, or a protocol error. This may or may not be preceeded by a
60 // call to OnClosingHandshake().
62 // Warning: Both the |code| and |reason| are passed through to Javascript, so
63 // callers must take care not to provide details that could be useful to
64 // attackers attempting to use WebSockets to probe networks.
66 // The channel should not be used again after OnDropChannel() has been
69 // This method returns a ChannelState for consistency, but all implementations
70 // must delete the Channel and return CHANNEL_DELETED.
71 virtual ChannelState OnDropChannel(uint16 code, const std::string& reason)
72 WARN_UNUSED_RESULT = 0;
75 WebSocketEventInterface() {}
78 DISALLOW_COPY_AND_ASSIGN(WebSocketEventInterface);
83 #endif // NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_