[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 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 CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | d24a847 | 2013-10-21 09:05:10 | [diff] [blame] | 12 | #include "content/common/content_export.h" |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 13 | #include "content/common/websocket.h" |
| 14 | |
| 15 | class GURL; |
| 16 | |
[email protected] | 7824cf8 | 2014-03-13 10:22:57 | [diff] [blame] | 17 | namespace url { |
| 18 | class Origin; |
| 19 | } // namespace url |
| 20 | |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 21 | namespace net { |
| 22 | class WebSocketChannel; |
| 23 | class URLRequestContext; |
| 24 | } // namespace net |
| 25 | |
| 26 | namespace IPC { |
| 27 | class Message; |
| 28 | } // namespace IPC |
| 29 | |
| 30 | namespace content { |
| 31 | |
| 32 | class WebSocketDispatcherHost; |
| 33 | |
[email protected] | f485985e | 2013-10-24 13:47:44 | [diff] [blame] | 34 | // Host of net::WebSocketChannel. The lifetime of an instance of this class is |
| 35 | // completely controlled by the WebSocketDispatcherHost object. |
[email protected] | d24a847 | 2013-10-21 09:05:10 | [diff] [blame] | 36 | class CONTENT_EXPORT WebSocketHost { |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 37 | public: |
| 38 | WebSocketHost(int routing_id, |
| 39 | WebSocketDispatcherHost* dispatcher, |
| 40 | net::URLRequestContext* url_request_context); |
[email protected] | d24a847 | 2013-10-21 09:05:10 | [diff] [blame] | 41 | virtual ~WebSocketHost(); |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 42 | |
[email protected] | e778f32 | 2014-07-28 10:00:53 | [diff] [blame] | 43 | // The renderer process is going away. |
| 44 | // This function is virtual for testing. |
| 45 | virtual void GoAway(); |
| 46 | |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 47 | // General message dispatch. WebSocketDispatcherHost::OnMessageReceived |
| 48 | // delegates to this method after looking up the |routing_id|. |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 49 | virtual bool OnMessageReceived(const IPC::Message& message); |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 50 | |
[email protected] | e778f32 | 2014-07-28 10:00:53 | [diff] [blame] | 51 | int routing_id() const { return routing_id_; } |
| 52 | |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 53 | private: |
| 54 | // Handlers for each message type, dispatched by OnMessageReceived(), as |
| 55 | // defined in content/common/websocket_messages.h |
| 56 | |
| 57 | void OnAddChannelRequest(const GURL& socket_url, |
| 58 | const std::vector<std::string>& requested_protocols, |
[email protected] | a6244952 | 2014-06-05 11:11:15 | [diff] [blame] | 59 | const url::Origin& origin, |
| 60 | int render_frame_id); |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 61 | |
| 62 | void OnSendFrame(bool fin, |
| 63 | WebSocketMessageType type, |
| 64 | const std::vector<char>& data); |
| 65 | |
| 66 | void OnFlowControl(int64 quota); |
| 67 | |
[email protected] | d756944 | 2013-11-05 05:59:39 | [diff] [blame] | 68 | void OnDropChannel(bool was_clean, uint16 code, const std::string& reason); |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 69 | |
| 70 | // The channel we use to send events to the network. |
| 71 | scoped_ptr<net::WebSocketChannel> channel_; |
| 72 | |
[email protected] | a6244952 | 2014-06-05 11:11:15 | [diff] [blame] | 73 | // The WebSocketHostDispatcher that created this object. |
| 74 | WebSocketDispatcherHost* const dispatcher_; |
| 75 | |
| 76 | // The URL request context for the channel. |
| 77 | net::URLRequestContext* const url_request_context_; |
| 78 | |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 79 | // The ID used to route messages. |
[email protected] | a6244952 | 2014-06-05 11:11:15 | [diff] [blame] | 80 | const int routing_id_; |
[email protected] | dab33eb | 2013-10-08 02:27:51 | [diff] [blame] | 81 | |
| 82 | DISALLOW_COPY_AND_ASSIGN(WebSocketHost); |
| 83 | }; |
| 84 | |
| 85 | } // namespace content |
| 86 | |
| 87 | #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |