OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "mojo/services/network/web_socket_impl.h" | 5 #include "mojo/services/network/web_socket_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "mojo/common/handle_watcher.h" | 9 #include "mojo/message_pump/handle_watcher.h" |
10 #include "mojo/services/network/network_context.h" | 10 #include "mojo/services/network/network_context.h" |
11 #include "mojo/services/network/web_socket_read_queue.h" | 11 #include "mojo/services/network/web_socket_read_queue.h" |
12 #include "mojo/services/network/web_socket_write_queue.h" | 12 #include "mojo/services/network/web_socket_write_queue.h" |
13 #include "net/websockets/websocket_channel.h" | 13 #include "net/websockets/websocket_channel.h" |
14 #include "net/websockets/websocket_errors.h" | 14 #include "net/websockets/websocket_errors.h" |
15 #include "net/websockets/websocket_event_interface.h" | 15 #include "net/websockets/websocket_event_interface.h" |
16 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode | 16 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode |
17 #include "net/websockets/websocket_handshake_request_info.h" | 17 #include "net/websockets/websocket_handshake_request_info.h" |
18 #include "net/websockets/websocket_handshake_response_info.h" | 18 #include "net/websockets/websocket_handshake_response_info.h" |
19 #include "url/origin.h" | 19 #include "url/origin.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 return static_cast<WebSocket::MessageType>(type); | 55 return static_cast<WebSocket::MessageType>(type); |
56 } | 56 } |
57 }; | 57 }; |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
61 typedef net::WebSocketEventInterface::ChannelState ChannelState; | 61 typedef net::WebSocketEventInterface::ChannelState ChannelState; |
62 | 62 |
63 struct WebSocketEventHandler : public net::WebSocketEventInterface { | 63 struct WebSocketEventHandler : public net::WebSocketEventInterface { |
64 public: | 64 public: |
65 WebSocketEventHandler(WebSocketClientPtr client) | 65 WebSocketEventHandler(InterfaceHandle<WebSocketClient> client) |
66 : client_(client.Pass()) { | 66 : client_(WebSocketClientPtr::Create(client.Pass())) { |
67 } | 67 } |
68 ~WebSocketEventHandler() override {} | 68 ~WebSocketEventHandler() override {} |
69 | 69 |
70 private: | 70 private: |
71 // net::WebSocketEventInterface methods: | 71 // net::WebSocketEventInterface methods: |
72 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, | 72 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, |
73 const std::string& extensions) override; | 73 const std::string& extensions) override; |
74 ChannelState OnDataFrame(bool fin, | 74 ChannelState OnDataFrame(bool fin, |
75 WebSocketMessageType type, | 75 WebSocketMessageType type, |
76 const std::vector<char>& data) override; | 76 const std::vector<char>& data) override; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 : binding_(this, request.Pass()), context_(context) { | 182 : binding_(this, request.Pass()), context_(context) { |
183 } | 183 } |
184 | 184 |
185 WebSocketImpl::~WebSocketImpl() { | 185 WebSocketImpl::~WebSocketImpl() { |
186 } | 186 } |
187 | 187 |
188 void WebSocketImpl::Connect(const String& url, | 188 void WebSocketImpl::Connect(const String& url, |
189 Array<String> protocols, | 189 Array<String> protocols, |
190 const String& origin, | 190 const String& origin, |
191 ScopedDataPipeConsumerHandle send_stream, | 191 ScopedDataPipeConsumerHandle send_stream, |
192 WebSocketClientPtr client) { | 192 InterfaceHandle<WebSocketClient> client) { |
193 DCHECK(!channel_); | 193 DCHECK(!channel_); |
194 send_stream_ = send_stream.Pass(); | 194 send_stream_ = send_stream.Pass(); |
195 read_queue_.reset(new WebSocketReadQueue(send_stream_.get())); | 195 read_queue_.reset(new WebSocketReadQueue(send_stream_.get())); |
196 scoped_ptr<net::WebSocketEventInterface> event_interface( | 196 scoped_ptr<net::WebSocketEventInterface> event_interface( |
197 new WebSocketEventHandler(client.Pass())); | 197 new WebSocketEventHandler(client.Pass())); |
198 channel_.reset(new net::WebSocketChannel(event_interface.Pass(), | 198 channel_.reset(new net::WebSocketChannel(event_interface.Pass(), |
199 context_->url_request_context())); | 199 context_->url_request_context())); |
200 channel_->SendAddChannelRequest(GURL(url.get()), | 200 channel_->SendAddChannelRequest(GURL(url.get()), |
201 protocols.To<std::vector<std::string> >(), | 201 protocols.To<std::vector<std::string> >(), |
202 url::Origin(origin.get())); | 202 url::Origin(origin.get())); |
(...skipping 24 matching lines...) Expand all Loading... |
227 uint32_t num_bytes, | 227 uint32_t num_bytes, |
228 const char* data) { | 228 const char* data) { |
229 std::vector<char> buffer(num_bytes); | 229 std::vector<char> buffer(num_bytes); |
230 memcpy(&buffer[0], data, num_bytes); | 230 memcpy(&buffer[0], data, num_bytes); |
231 DCHECK(channel_); | 231 DCHECK(channel_); |
232 channel_->SendFrame( | 232 channel_->SendFrame( |
233 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer); | 233 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer); |
234 } | 234 } |
235 | 235 |
236 } // namespace mojo | 236 } // namespace mojo |
OLD | NEW |