| 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 CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 class WebSocketChannel; | 27 class WebSocketChannel; |
| 28 class URLRequestContext; | 28 class URLRequestContext; |
| 29 } // namespace net | 29 } // namespace net |
| 30 | 30 |
| 31 namespace IPC { | 31 namespace IPC { |
| 32 class Message; | 32 class Message; |
| 33 } // namespace IPC | 33 } // namespace IPC |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 class WebSocketBlobSender; |
| 37 class WebSocketDispatcherHost; | 38 class WebSocketDispatcherHost; |
| 38 | 39 |
| 39 // Host of net::WebSocketChannel. The lifetime of an instance of this class is | 40 // Host of net::WebSocketChannel. The lifetime of an instance of this class is |
| 40 // completely controlled by the WebSocketDispatcherHost object. | 41 // completely controlled by the WebSocketDispatcherHost object. |
| 41 class CONTENT_EXPORT WebSocketHost { | 42 class CONTENT_EXPORT WebSocketHost { |
| 42 public: | 43 public: |
| 43 WebSocketHost(int routing_id, | 44 WebSocketHost(int routing_id, |
| 44 WebSocketDispatcherHost* dispatcher, | 45 WebSocketDispatcherHost* dispatcher, |
| 45 net::URLRequestContext* url_request_context, | 46 net::URLRequestContext* url_request_context, |
| 46 base::TimeDelta delay); | 47 base::TimeDelta delay); |
| 47 virtual ~WebSocketHost(); | 48 virtual ~WebSocketHost(); |
| 48 | 49 |
| 49 // The renderer process is going away. | 50 // The renderer process is going away. |
| 50 // This function is virtual for testing. | 51 // This function is virtual for testing. |
| 51 virtual void GoAway(); | 52 virtual void GoAway(); |
| 52 | 53 |
| 53 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived | 54 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived |
| 54 // delegates to this method after looking up the |routing_id|. | 55 // delegates to this method after looking up the |routing_id|. |
| 55 virtual bool OnMessageReceived(const IPC::Message& message); | 56 virtual bool OnMessageReceived(const IPC::Message& message); |
| 56 | 57 |
| 57 int routing_id() const { return routing_id_; } | 58 int routing_id() const { return routing_id_; } |
| 58 | 59 |
| 59 bool handshake_succeeded() const { return handshake_succeeded_; } | 60 bool handshake_succeeded() const { return handshake_succeeded_; } |
| 60 void OnHandshakeSucceeded() { handshake_succeeded_ = true; } | 61 void OnHandshakeSucceeded() { handshake_succeeded_ = true; } |
| 61 | 62 |
| 62 private: | 63 private: |
| 64 class WebSocketEventHandler; |
| 65 |
| 63 // Handlers for each message type, dispatched by OnMessageReceived(), as | 66 // Handlers for each message type, dispatched by OnMessageReceived(), as |
| 64 // defined in content/common/websocket_messages.h | 67 // defined in content/common/websocket_messages.h |
| 65 | 68 |
| 66 void OnAddChannelRequest(const GURL& socket_url, | 69 void OnAddChannelRequest(const GURL& socket_url, |
| 67 const std::vector<std::string>& requested_protocols, | 70 const std::vector<std::string>& requested_protocols, |
| 68 const url::Origin& origin, | 71 const url::Origin& origin, |
| 69 int render_frame_id); | 72 int render_frame_id); |
| 70 | 73 |
| 71 void AddChannel(const GURL& socket_url, | 74 void AddChannel(const GURL& socket_url, |
| 72 const std::vector<std::string>& requested_protocols, | 75 const std::vector<std::string>& requested_protocols, |
| 73 const url::Origin& origin, | 76 const url::Origin& origin, |
| 74 int render_frame_id); | 77 int render_frame_id); |
| 75 | 78 |
| 79 void OnSendBlob(const std::string& uuid, uint64_t expected_size); |
| 80 |
| 76 void OnSendFrame(bool fin, | 81 void OnSendFrame(bool fin, |
| 77 WebSocketMessageType type, | 82 WebSocketMessageType type, |
| 78 const std::vector<char>& data); | 83 const std::vector<char>& data); |
| 79 | 84 |
| 80 void OnFlowControl(int64_t quota); | 85 void OnFlowControl(int64_t quota); |
| 81 | 86 |
| 82 void OnDropChannel(bool was_clean, uint16_t code, const std::string& reason); | 87 void OnDropChannel(bool was_clean, uint16_t code, const std::string& reason); |
| 83 | 88 |
| 89 void BlobSendComplete(int result); |
| 90 |
| 91 // non-NULL if and only if this object is currently in "blob sending mode". |
| 92 scoped_ptr<WebSocketBlobSender> blob_sender_; |
| 93 |
| 84 // The channel we use to send events to the network. | 94 // The channel we use to send events to the network. |
| 85 scoped_ptr<net::WebSocketChannel> channel_; | 95 scoped_ptr<net::WebSocketChannel> channel_; |
| 86 | 96 |
| 87 // The WebSocketHostDispatcher that created this object. | 97 // The WebSocketHostDispatcher that created this object. |
| 88 WebSocketDispatcherHost* const dispatcher_; | 98 WebSocketDispatcherHost* const dispatcher_; |
| 89 | 99 |
| 90 // The URL request context for the channel. | 100 // The URL request context for the channel. |
| 91 net::URLRequestContext* const url_request_context_; | 101 net::URLRequestContext* const url_request_context_; |
| 92 | 102 |
| 93 // The ID used to route messages. | 103 // The ID used to route messages. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 bool handshake_succeeded_; | 116 bool handshake_succeeded_; |
| 107 | 117 |
| 108 base::WeakPtrFactory<WebSocketHost> weak_ptr_factory_; | 118 base::WeakPtrFactory<WebSocketHost> weak_ptr_factory_; |
| 109 | 119 |
| 110 DISALLOW_COPY_AND_ASSIGN(WebSocketHost); | 120 DISALLOW_COPY_AND_ASSIGN(WebSocketHost); |
| 111 }; | 121 }; |
| 112 | 122 |
| 113 } // namespace content | 123 } // namespace content |
| 114 | 124 |
| 115 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ | 125 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ |
| OLD | NEW |