| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ |
| 6 #define NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" // for WARN_UNUSED_RESULT |
| 12 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 // Interface for events sent from the network layer to the content layer. These | 17 // Interface for events sent from the network layer to the content layer. These |
| 17 // events will generally be sent as-is to the renderer process. | 18 // events will generally be sent as-is to the renderer process. |
| 18 class NET_EXPORT WebSocketEventInterface { | 19 class NET_EXPORT WebSocketEventInterface { |
| 19 public: | 20 public: |
| 20 typedef int WebSocketMessageType; | 21 typedef int WebSocketMessageType; |
| 22 |
| 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. |
| 26 enum ChannelState { |
| 27 CHANNEL_ALIVE, |
| 28 CHANNEL_DELETED |
| 29 }; |
| 30 |
| 21 virtual ~WebSocketEventInterface() {} | 31 virtual ~WebSocketEventInterface() {} |
| 22 // Called in response to an AddChannelRequest. This generally means that a | 32 // Called in response to an AddChannelRequest. This generally means that a |
| 23 // response has been received from the remote server, but the response might | 33 // response has been received from the remote server, but the response might |
| 24 // have been generated internally. If |fail| is true, the channel cannot be | 34 // have been generated internally. If |fail| is true, the channel cannot be |
| 25 // used and it is valid to delete the WebSocketChannel from within this | 35 // used and should be deleted, returning CHANNEL_DELETED. |
| 26 // callback. | 36 virtual ChannelState OnAddChannelResponse( |
| 27 virtual void OnAddChannelResponse( | |
| 28 bool fail, | 37 bool fail, |
| 29 const std::string& selected_subprotocol) = 0; | 38 const std::string& selected_subprotocol) WARN_UNUSED_RESULT = 0; |
| 30 | 39 |
| 31 // Called when a data frame has been received from the remote host and needs | 40 // Called when a data frame has been received from the remote host and needs |
| 32 // to be forwarded to the renderer process. It is not safe to delete the | 41 // to be forwarded to the renderer process. |
| 33 // WebSocketChannel object from within this callback. | 42 virtual ChannelState OnDataFrame( |
| 34 virtual void OnDataFrame(bool fin, | 43 bool fin, |
| 35 WebSocketMessageType type, | 44 WebSocketMessageType type, |
| 36 const std::vector<char>& data) = 0; | 45 const std::vector<char>& data) WARN_UNUSED_RESULT = 0; |
| 37 | 46 |
| 38 // Called to provide more send quota for this channel to the renderer | 47 // Called to provide more send quota for this channel to the renderer |
| 39 // process. Currently the quota units are always bytes of message body | 48 // process. Currently the quota units are always bytes of message body |
| 40 // data. In future it might depend on the type of multiplexing in use. It is | 49 // data. In future it might depend on the type of multiplexing in use. |
| 41 // not safe to delete the WebSocketChannel from within this callback. | 50 virtual ChannelState OnFlowControl(int64 quota) WARN_UNUSED_RESULT = 0; |
| 42 virtual void OnFlowControl(int64 quota) = 0; | |
| 43 | 51 |
| 44 // Called when the remote server has Started the WebSocket Closing | 52 // Called when the remote server has Started the WebSocket Closing |
| 45 // Handshake. The client should not attempt to send any more messages after | 53 // Handshake. The client should not attempt to send any more messages after |
| 46 // receiving this message. It will be followed by OnDropChannel() when the | 54 // receiving this message. It will be followed by OnDropChannel() when the |
| 47 // closing handshake is complete. It is not safe to delete the | 55 // closing handshake is complete. |
| 48 // WebSocketChannel from within this callback. | 56 virtual ChannelState OnClosingHandshake() WARN_UNUSED_RESULT = 0; |
| 49 virtual void OnClosingHandshake() = 0; | |
| 50 | 57 |
| 51 // Called when the channel has been dropped, either due to a network close, a | 58 // Called when the channel has been dropped, either due to a network close, a |
| 52 // network error, or a protocol error. This may or may not be preceeded by a | 59 // network error, or a protocol error. This may or may not be preceeded by a |
| 53 // call to OnClosingHandshake(). | 60 // call to OnClosingHandshake(). |
| 54 // | 61 // |
| 55 // Warning: Both the |code| and |reason| are passed through to Javascript, so | 62 // Warning: Both the |code| and |reason| are passed through to Javascript, so |
| 56 // callers must take care not to provide details that could be useful to | 63 // callers must take care not to provide details that could be useful to |
| 57 // attackers attempting to use WebSockets to probe networks. | 64 // attackers attempting to use WebSockets to probe networks. |
| 58 // | 65 // |
| 59 // The channel should not be used again after OnDropChannel() has been | 66 // The channel should not be used again after OnDropChannel() has been |
| 60 // called. | 67 // called. |
| 61 // | 68 // |
| 62 // It is not safe to delete the WebSocketChannel from within this | 69 // This method returns a ChannelState for consistency, but all implementations |
| 63 // callback. It is recommended to delete the channel after returning to the | 70 // must delete the Channel and return CHANNEL_DELETED. |
| 64 // event loop. | 71 virtual ChannelState OnDropChannel(uint16 code, const std::string& reason) |
| 65 virtual void OnDropChannel(uint16 code, const std::string& reason) = 0; | 72 WARN_UNUSED_RESULT = 0; |
| 66 | 73 |
| 67 protected: | 74 protected: |
| 68 WebSocketEventInterface() {} | 75 WebSocketEventInterface() {} |
| 69 | 76 |
| 70 private: | 77 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(WebSocketEventInterface); | 78 DISALLOW_COPY_AND_ASSIGN(WebSocketEventInterface); |
| 72 }; | 79 }; |
| 73 | 80 |
| 74 } // namespace net | 81 } // namespace net |
| 75 | 82 |
| 76 #endif // NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ | 83 #endif // NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ |
| OLD | NEW |