| 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 "components/html_viewer/web_socket_handle_impl.h" | 5 #include "components/html_viewer/web_socket_handle_impl.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "components/html_viewer/blink_basic_type_converters.h" | 12 #include "components/html_viewer/blink_basic_type_converters.h" |
| 13 #include "mojo/services/network/public/cpp/web_socket_read_queue.h" | 13 #include "mojo/services/network/public/cpp/web_socket_read_queue.h" |
| 14 #include "mojo/services/network/public/cpp/web_socket_write_queue.h" | 14 #include "mojo/services/network/public/cpp/web_socket_write_queue.h" |
| 15 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 15 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 16 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" | 16 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 17 #include "third_party/WebKit/public/platform/WebSocketHandleClient.h" | 17 #include "third_party/WebKit/public/platform/WebSocketHandleClient.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
| 20 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 21 | 21 |
| 22 using blink::WebSerializedOrigin; | 22 using blink::WebSecurityOrigin; |
| 23 using blink::WebSocketHandle; | 23 using blink::WebSocketHandle; |
| 24 using blink::WebSocketHandleClient; | 24 using blink::WebSocketHandleClient; |
| 25 using blink::WebString; | 25 using blink::WebString; |
| 26 using blink::WebURL; | 26 using blink::WebURL; |
| 27 using blink::WebVector; | 27 using blink::WebVector; |
| 28 | 28 |
| 29 using mojo::ConvertTo; | 29 using mojo::ConvertTo; |
| 30 using mojo::String; | 30 using mojo::String; |
| 31 using mojo::WebSocket; | 31 using mojo::WebSocket; |
| 32 using mojo::WebSocketReadQueue; | 32 using mojo::WebSocketReadQueue; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 WebSocketHandleImpl::~WebSocketHandleImpl() { | 155 WebSocketHandleImpl::~WebSocketHandleImpl() { |
| 156 if (!did_close_) { | 156 if (!did_close_) { |
| 157 // The connection is abruptly disconnected by the renderer without | 157 // The connection is abruptly disconnected by the renderer without |
| 158 // closing handshake. | 158 // closing handshake. |
| 159 web_socket_->Close(WebSocket::kAbnormalCloseCode, String()); | 159 web_socket_->Close(WebSocket::kAbnormalCloseCode, String()); |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 | 162 |
| 163 void WebSocketHandleImpl::connect(const WebURL& url, | 163 void WebSocketHandleImpl::connect(const WebURL& url, |
| 164 const WebVector<WebString>& protocols, | 164 const WebVector<WebString>& protocols, |
| 165 const WebSerializedOrigin& origin, | 165 const WebSecurityOrigin& origin, |
| 166 WebSocketHandleClient* client) { | 166 WebSocketHandleClient* client) { |
| 167 // TODO(mpcomplete): Is this the right ownership model? Or should mojo own | 167 // TODO(mpcomplete): Is this the right ownership model? Or should mojo own |
| 168 // |client_|? | 168 // |client_|? |
| 169 mojo::WebSocketClientPtr client_ptr; | 169 mojo::WebSocketClientPtr client_ptr; |
| 170 mojo::MessagePipe pipe; | 170 mojo::MessagePipe pipe; |
| 171 client_ptr.Bind( | 171 client_ptr.Bind( |
| 172 mojo::InterfacePtrInfo<mojo::WebSocketClient>(pipe.handle0.Pass(), 0u)); | 172 mojo::InterfacePtrInfo<mojo::WebSocketClient>(pipe.handle0.Pass(), 0u)); |
| 173 mojo::InterfaceRequest<mojo::WebSocketClient> request; | 173 mojo::InterfaceRequest<mojo::WebSocketClient> request; |
| 174 request.Bind(pipe.handle1.Pass()); | 174 request.Bind(pipe.handle1.Pass()); |
| 175 client_.reset(new WebSocketClientImpl(this, client, request.Pass())); | 175 client_.reset(new WebSocketClientImpl(this, client, request.Pass())); |
| 176 | 176 |
| 177 mojo::DataPipe data_pipe; | 177 mojo::DataPipe data_pipe; |
| 178 send_stream_ = data_pipe.producer_handle.Pass(); | 178 send_stream_ = data_pipe.producer_handle.Pass(); |
| 179 write_queue_.reset(new mojo::WebSocketWriteQueue(send_stream_.get())); | 179 write_queue_.reset(new mojo::WebSocketWriteQueue(send_stream_.get())); |
| 180 web_socket_->Connect(url.string().utf8(), | 180 web_socket_->Connect(url.string().utf8(), |
| 181 mojo::Array<String>::From(protocols), | 181 mojo::Array<String>::From(protocols), |
| 182 origin.string().utf8(), data_pipe.consumer_handle.Pass(), | 182 origin.toString().utf8(), |
| 183 client_ptr.Pass()); | 183 data_pipe.consumer_handle.Pass(), client_ptr.Pass()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void WebSocketHandleImpl::send(bool fin, | 186 void WebSocketHandleImpl::send(bool fin, |
| 187 WebSocketHandle::MessageType type, | 187 WebSocketHandle::MessageType type, |
| 188 const char* data, | 188 const char* data, |
| 189 size_t size) { | 189 size_t size) { |
| 190 if (!client_) | 190 if (!client_) |
| 191 return; | 191 return; |
| 192 | 192 |
| 193 uint32_t size32 = static_cast<uint32_t>(size); | 193 uint32_t size32 = static_cast<uint32_t>(size); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 216 const char* data) { | 216 const char* data) { |
| 217 web_socket_->Send(fin, ConvertTo<WebSocket::MessageType>(type), num_bytes); | 217 web_socket_->Send(fin, ConvertTo<WebSocket::MessageType>(type), num_bytes); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void WebSocketHandleImpl::Disconnect() { | 220 void WebSocketHandleImpl::Disconnect() { |
| 221 did_close_ = true; | 221 did_close_ = true; |
| 222 client_.reset(); | 222 client_.reset(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 } // namespace html_viewer | 225 } // namespace html_viewer |
| OLD | NEW |