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 struct WebSocketHandshakeRequestInfo
;
18 struct WebSocketHandshakeResponseInfo
;
20 // Interface for events sent from the network layer to the content layer. These
21 // events will generally be sent as-is to the renderer process.
22 class NET_EXPORT WebSocketEventInterface
{
24 typedef int WebSocketMessageType
;
26 // Any event can cause the Channel to be deleted. The Channel needs to avoid
27 // doing further processing in this case. It does not need to do cleanup, as
28 // cleanup will already have been done as a result of the deletion.
34 virtual ~WebSocketEventInterface() {}
36 // Called in response to an AddChannelRequest. This generally means that a
37 // response has been received from the remote server, but the response might
38 // have been generated internally. If |fail| is true, the channel cannot be
39 // used and should be deleted, returning CHANNEL_DELETED.
40 virtual ChannelState
OnAddChannelResponse(
42 const std::string
& selected_subprotocol
,
43 const std::string
& extensions
) WARN_UNUSED_RESULT
= 0;
45 // Called when a data frame has been received from the remote host and needs
46 // to be forwarded to the renderer process.
47 virtual ChannelState
OnDataFrame(
49 WebSocketMessageType type
,
50 const std::vector
<char>& data
) WARN_UNUSED_RESULT
= 0;
52 // Called to provide more send quota for this channel to the renderer
53 // process. Currently the quota units are always bytes of message body
54 // data. In future it might depend on the type of multiplexing in use.
55 virtual ChannelState
OnFlowControl(int64 quota
) WARN_UNUSED_RESULT
= 0;
57 // Called when the remote server has Started the WebSocket Closing
58 // Handshake. The client should not attempt to send any more messages after
59 // receiving this message. It will be followed by OnDropChannel() when the
60 // closing handshake is complete.
61 virtual ChannelState
OnClosingHandshake() WARN_UNUSED_RESULT
= 0;
63 // Called when the channel has been dropped, either due to a network close, a
64 // network error, or a protocol error. This may or may not be preceeded by a
65 // call to OnClosingHandshake().
67 // Warning: Both the |code| and |reason| are passed through to Javascript, so
68 // callers must take care not to provide details that could be useful to
69 // attackers attempting to use WebSockets to probe networks.
71 // |was_clean| should be true if the closing handshake completed successfully.
73 // The channel should not be used again after OnDropChannel() has been
76 // This method returns a ChannelState for consistency, but all implementations
77 // must delete the Channel and return CHANNEL_DELETED.
78 virtual ChannelState
OnDropChannel(bool was_clean
,
80 const std::string
& reason
)
81 WARN_UNUSED_RESULT
= 0;
83 // Called when the browser fails the channel, as specified in the spec.
85 // The channel should not be used again after OnFailChannel() has been
88 // This method returns a ChannelState for consistency, but all implementations
89 // must delete the Channel and return CHANNEL_DELETED.
90 virtual ChannelState
OnFailChannel(const std::string
& message
)
91 WARN_UNUSED_RESULT
= 0;
93 // Called when the browser starts the WebSocket Opening Handshake.
94 virtual ChannelState
OnStartOpeningHandshake(
95 scoped_ptr
<WebSocketHandshakeRequestInfo
> request
) WARN_UNUSED_RESULT
= 0;
97 // Called when the browser finishes the WebSocket Opening Handshake.
98 virtual ChannelState
OnFinishOpeningHandshake(
99 scoped_ptr
<WebSocketHandshakeResponseInfo
> response
)
100 WARN_UNUSED_RESULT
= 0;
103 WebSocketEventInterface() {}
106 DISALLOW_COPY_AND_ASSIGN(WebSocketEventInterface
);
111 #endif // NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_