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 #include "content/child/websocket_bridge.h" | 5 #include "content/child/websocket_bridge.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 23 matching lines...) Expand all Loading... |
34 using blink::WebString; | 34 using blink::WebString; |
35 using blink::WebURL; | 35 using blink::WebURL; |
36 using blink::WebVector; | 36 using blink::WebVector; |
37 | 37 |
38 namespace content { | 38 namespace content { |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 const unsigned short kAbnormalShutdownOpCode = 1006; | 42 const unsigned short kAbnormalShutdownOpCode = 1006; |
43 | 43 |
| 44 WebSocketBinaryType BlinkBinaryTypeToContentWebSocketBinaryType( |
| 45 WebSocketHandle::BinaryType binary_type) { |
| 46 static_assert( |
| 47 static_cast<WebSocketBinaryType>(WebSocketHandle::BinaryTypeBlob) == |
| 48 WebSocketBinaryType::BLOB, |
| 49 "enum types must match"); |
| 50 static_assert(static_cast<WebSocketBinaryType>( |
| 51 WebSocketHandle::BinaryTypeArrayBuffer) == |
| 52 WebSocketBinaryType::ARRAY_BUFFER, |
| 53 "enum types must match"); |
| 54 DCHECK(binary_type == WebSocketHandle::BinaryTypeBlob || |
| 55 binary_type == WebSocketHandle::BinaryTypeArrayBuffer); |
| 56 return static_cast<WebSocketBinaryType>(binary_type); |
| 57 } |
| 58 |
44 } // namespace | 59 } // namespace |
45 | 60 |
46 WebSocketBridge::WebSocketBridge() | 61 WebSocketBridge::WebSocketBridge() |
47 : channel_id_(kInvalidChannelId), | 62 : channel_id_(kInvalidChannelId), |
48 render_frame_id_(MSG_ROUTING_NONE), | 63 render_frame_id_(MSG_ROUTING_NONE), |
49 client_(NULL) {} | 64 client_(NULL) {} |
50 | 65 |
51 WebSocketBridge::~WebSocketBridge() { | 66 WebSocketBridge::~WebSocketBridge() { |
52 if (channel_id_ != kInvalidChannelId) { | 67 if (channel_id_ != kInvalidChannelId) { |
53 // The connection is abruptly disconnected by the renderer without | 68 // The connection is abruptly disconnected by the renderer without |
(...skipping 10 matching lines...) Expand all Loading... |
64 bool WebSocketBridge::OnMessageReceived(const IPC::Message& msg) { | 79 bool WebSocketBridge::OnMessageReceived(const IPC::Message& msg) { |
65 bool handled = true; | 80 bool handled = true; |
66 IPC_BEGIN_MESSAGE_MAP(WebSocketBridge, msg) | 81 IPC_BEGIN_MESSAGE_MAP(WebSocketBridge, msg) |
67 IPC_MESSAGE_HANDLER(WebSocketMsg_AddChannelResponse, DidConnect) | 82 IPC_MESSAGE_HANDLER(WebSocketMsg_AddChannelResponse, DidConnect) |
68 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyStartOpeningHandshake, | 83 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyStartOpeningHandshake, |
69 DidStartOpeningHandshake) | 84 DidStartOpeningHandshake) |
70 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyFinishOpeningHandshake, | 85 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyFinishOpeningHandshake, |
71 DidFinishOpeningHandshake) | 86 DidFinishOpeningHandshake) |
72 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyFailure, DidFail) | 87 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyFailure, DidFail) |
73 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, DidReceiveData) | 88 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, DidReceiveData) |
| 89 IPC_MESSAGE_HANDLER(WebSocketMsg_BlobReceived, DidReceiveBlob) |
74 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, DidReceiveFlowControl) | 90 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, DidReceiveFlowControl) |
75 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, DidClose) | 91 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, DidClose) |
76 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyClosing, | 92 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyClosing, |
77 DidStartClosingHandshake) | 93 DidStartClosingHandshake) |
78 IPC_MESSAGE_UNHANDLED(handled = false) | 94 IPC_MESSAGE_UNHANDLED(handled = false) |
79 IPC_END_MESSAGE_MAP() | 95 IPC_END_MESSAGE_MAP() |
80 return handled; | 96 return handled; |
81 } | 97 } |
82 | 98 |
83 void WebSocketBridge::DidConnect(const std::string& selected_protocol, | 99 void WebSocketBridge::DidConnect(const std::string& selected_protocol, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 break; | 177 break; |
162 case WEB_SOCKET_MESSAGE_TYPE_BINARY: | 178 case WEB_SOCKET_MESSAGE_TYPE_BINARY: |
163 type_to_pass = WebSocketHandle::MessageTypeBinary; | 179 type_to_pass = WebSocketHandle::MessageTypeBinary; |
164 break; | 180 break; |
165 } | 181 } |
166 const char* data_to_pass = data.empty() ? NULL : &data[0]; | 182 const char* data_to_pass = data.empty() ? NULL : &data[0]; |
167 client_->didReceiveData(this, fin, type_to_pass, data_to_pass, data.size()); | 183 client_->didReceiveData(this, fin, type_to_pass, data_to_pass, data.size()); |
168 // |this| can be deleted here. | 184 // |this| can be deleted here. |
169 } | 185 } |
170 | 186 |
| 187 void WebSocketBridge::DidReceiveBlob(const std::string& uuid, uint64_t size) { |
| 188 DVLOG(1) << "WebSocketBridge::DidReceiveBlob(" << uuid << "," << size << ")"; |
| 189 |
| 190 client_->didReceiveBlob(this, WebString::fromLatin1(uuid), size); |
| 191 } |
| 192 |
171 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) { | 193 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) { |
172 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")"; | 194 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")"; |
173 if (!client_) | 195 if (!client_) |
174 return; | 196 return; |
175 | 197 |
176 client_->didReceiveFlowControl(this, quota); | 198 client_->didReceiveFlowControl(this, quota); |
177 // |this| can be deleted here. | 199 // |this| can be deleted here. |
178 } | 200 } |
179 | 201 |
180 void WebSocketBridge::DidClose(bool was_clean, | 202 void WebSocketBridge::DidClose(bool was_clean, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 return; | 294 return; |
273 | 295 |
274 std::string reason_to_pass = reason.utf8(); | 296 std::string reason_to_pass = reason.utf8(); |
275 DVLOG(1) << "Bridge #" << channel_id_ << " Close(" | 297 DVLOG(1) << "Bridge #" << channel_id_ << " Close(" |
276 << code << ", " << reason_to_pass << ")"; | 298 << code << ", " << reason_to_pass << ")"; |
277 // This method is for closing handshake and hence |was_clean| shall be true. | 299 // This method is for closing handshake and hence |was_clean| shall be true. |
278 ChildThreadImpl::current()->Send( | 300 ChildThreadImpl::current()->Send( |
279 new WebSocketMsg_DropChannel(channel_id_, true, code, reason_to_pass)); | 301 new WebSocketMsg_DropChannel(channel_id_, true, code, reason_to_pass)); |
280 } | 302 } |
281 | 303 |
| 304 void WebSocketBridge::changeBinaryType(BinaryType new_binary_type) { |
| 305 if (channel_id_ == kInvalidChannelId) |
| 306 return; |
| 307 |
| 308 DVLOG(1) << "Bridge #" << channel_id_ << " ChangeBinaryType(" |
| 309 << new_binary_type << ")"; |
| 310 ChildThreadImpl::current()->Send(new WebSocketHostMsg_BinaryTypeChanged( |
| 311 channel_id_, |
| 312 BlinkBinaryTypeToContentWebSocketBinaryType(new_binary_type))); |
| 313 } |
| 314 |
| 315 void WebSocketBridge::confirmBlob() { |
| 316 if (channel_id_ == kInvalidChannelId) |
| 317 return; |
| 318 |
| 319 DVLOG(1) << "Bridge #" << channel_id_ << " ConfirmBlob()"; |
| 320 ChildThreadImpl::current()->Send( |
| 321 new WebSocketHostMsg_BlobConfirmed(channel_id_)); |
| 322 } |
| 323 |
282 void WebSocketBridge::Disconnect() { | 324 void WebSocketBridge::Disconnect() { |
283 if (channel_id_ == kInvalidChannelId) | 325 if (channel_id_ == kInvalidChannelId) |
284 return; | 326 return; |
285 WebSocketDispatcher* dispatcher = | 327 WebSocketDispatcher* dispatcher = |
286 ChildThreadImpl::current()->websocket_dispatcher(); | 328 ChildThreadImpl::current()->websocket_dispatcher(); |
287 dispatcher->RemoveBridge(channel_id_); | 329 dispatcher->RemoveBridge(channel_id_); |
288 | 330 |
289 channel_id_ = kInvalidChannelId; | 331 channel_id_ = kInvalidChannelId; |
290 client_ = NULL; | 332 client_ = NULL; |
291 } | 333 } |
292 | 334 |
293 } // namespace content | 335 } // namespace content |
OLD | NEW |