OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ |
| 6 #define NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "net/base/net_export.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 // 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 class NET_EXPORT WebSocketEventInterface { |
| 19 public: |
| 20 typedef int WebSocketMessageType; |
| 21 virtual ~WebSocketEventInterface() {} |
| 22 // Called in response to an AddChannelRequest. This generally means that a |
| 23 // 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 |
| 25 // used and it is valid to delete the WebSocketChannel from within this |
| 26 // callback. |
| 27 virtual void OnAddChannelResponse( |
| 28 bool fail, |
| 29 const std::string& selected_subprotocol) = 0; |
| 30 |
| 31 // 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 |
| 33 // WebSocketChannel object from within this callback. |
| 34 virtual void OnDataFrame(bool fin, |
| 35 WebSocketMessageType type, |
| 36 const std::vector<char>& data) = 0; |
| 37 |
| 38 // Called to provide more send quota for this channel to the renderer |
| 39 // 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 |
| 41 // not safe to delete the WebSocketChannel from within this callback. |
| 42 virtual void OnFlowControl(int64 quota) = 0; |
| 43 |
| 44 // Called when the remote server has Started the WebSocket Closing |
| 45 // Handshake. The client should not attempt to send any more messages after |
| 46 // receiving this message. It will be followed by OnDropChannel() when the |
| 47 // closing handshake is complete. It is not safe to delete the |
| 48 // WebSocketChannel from within this callback. |
| 49 virtual void OnClosingHandshake() = 0; |
| 50 |
| 51 // 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 |
| 53 // call to OnClosingHandshake(). |
| 54 // |
| 55 // 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 |
| 57 // attackers attempting to use WebSockets to probe networks. |
| 58 // |
| 59 // The channel should not be used again after OnDropChannel() has been |
| 60 // called. |
| 61 // |
| 62 // It is not safe to delete the WebSocketChannel from within this |
| 63 // callback. It is recommended to delete the channel after returning to the |
| 64 // event loop. |
| 65 virtual void OnDropChannel(uint16 code, const std::string& reason) = 0; |
| 66 |
| 67 protected: |
| 68 WebSocketEventInterface() {} |
| 69 |
| 70 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(WebSocketEventInterface); |
| 72 }; |
| 73 |
| 74 } // namespace net |
| 75 |
| 76 #endif // NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_ |
OLD | NEW |