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"
20 struct WebSocketHandshakeRequestInfo
;
21 struct WebSocketHandshakeResponseInfo
;
23 // Interface for events sent from the network layer to the content layer. These
24 // events will generally be sent as-is to the renderer process.
25 class NET_EXPORT WebSocketEventInterface
{
27 typedef int WebSocketMessageType
;
29 // Any event can cause the Channel to be deleted. The Channel needs to avoid
30 // doing further processing in this case. It does not need to do cleanup, as
31 // cleanup will already have been done as a result of the deletion.
37 virtual ~WebSocketEventInterface() {}
39 // Called in response to an AddChannelRequest. This means that a response has
40 // been received from the remote server.
41 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;
102 // Callbacks to be used in response to a call to OnSSLCertificateError. Very
103 // similar to content::SSLErrorHandler::Delegate (which we can't use directly
104 // due to layering constraints).
105 class NET_EXPORT SSLErrorCallbacks
{
107 virtual ~SSLErrorCallbacks() {}
109 // Cancels the SSL response in response to the error.
110 virtual void CancelSSLRequest(int error
, const SSLInfo
* ssl_info
) = 0;
112 // Continue with the SSL connection despite the error.
113 virtual void ContinueSSLRequest() = 0;
116 // Called on SSL Certificate Error during the SSL handshake. Should result in
117 // a call to either ssl_error_callbacks->ContinueSSLRequest() or
118 // ssl_error_callbacks->CancelSSLRequest(). Normally the implementation of
119 // this method will delegate to content::SSLManager::OnSSLCertificateError to
120 // make the actual decision. The callbacks must not be called after the
121 // WebSocketChannel has been destroyed.
122 virtual ChannelState
OnSSLCertificateError(
123 scoped_ptr
<SSLErrorCallbacks
> ssl_error_callbacks
,
125 const SSLInfo
& ssl_info
,
126 bool fatal
) WARN_UNUSED_RESULT
= 0;
129 WebSocketEventInterface() {}
132 DISALLOW_COPY_AND_ASSIGN(WebSocketEventInterface
);
137 #endif // NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_