| 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/browser/renderer_host/websocket_host.h" | 5 #include "content/browser/renderer_host/websocket_host.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "content/browser/renderer_host/websocket_dispatcher_host.h" | 10 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // Convert a content::WebSocketMessageType to a | 33 // Convert a content::WebSocketMessageType to a |
| 34 // net::WebSocketFrameHeader::OpCode | 34 // net::WebSocketFrameHeader::OpCode |
| 35 net::WebSocketFrameHeader::OpCode MessageTypeToOpCode( | 35 net::WebSocketFrameHeader::OpCode MessageTypeToOpCode( |
| 36 WebSocketMessageType type) { | 36 WebSocketMessageType type) { |
| 37 DCHECK(type == WEB_SOCKET_MESSAGE_TYPE_CONTINUATION || | 37 DCHECK(type == WEB_SOCKET_MESSAGE_TYPE_CONTINUATION || |
| 38 type == WEB_SOCKET_MESSAGE_TYPE_TEXT || | 38 type == WEB_SOCKET_MESSAGE_TYPE_TEXT || |
| 39 type == WEB_SOCKET_MESSAGE_TYPE_BINARY); | 39 type == WEB_SOCKET_MESSAGE_TYPE_BINARY); |
| 40 typedef net::WebSocketFrameHeader::OpCode OpCode; | 40 typedef net::WebSocketFrameHeader::OpCode OpCode; |
| 41 // These compile asserts verify that the same underlying values are used for | 41 // These compile asserts verify that the same underlying values are used for |
| 42 // both types, so we can simply cast between them. | 42 // both types, so we can simply cast between them. |
| 43 COMPILE_ASSERT(static_cast<OpCode>(WEB_SOCKET_MESSAGE_TYPE_CONTINUATION) == | 43 static_assert(static_cast<OpCode>(WEB_SOCKET_MESSAGE_TYPE_CONTINUATION) == |
| 44 net::WebSocketFrameHeader::kOpCodeContinuation, | 44 net::WebSocketFrameHeader::kOpCodeContinuation, |
| 45 enum_values_must_match_for_opcode_continuation); | 45 "enum values must match for opcode continuation"); |
| 46 COMPILE_ASSERT(static_cast<OpCode>(WEB_SOCKET_MESSAGE_TYPE_TEXT) == | 46 static_assert(static_cast<OpCode>(WEB_SOCKET_MESSAGE_TYPE_TEXT) == |
| 47 net::WebSocketFrameHeader::kOpCodeText, | 47 net::WebSocketFrameHeader::kOpCodeText, |
| 48 enum_values_must_match_for_opcode_text); | 48 "enum values must match for opcode text"); |
| 49 COMPILE_ASSERT(static_cast<OpCode>(WEB_SOCKET_MESSAGE_TYPE_BINARY) == | 49 static_assert(static_cast<OpCode>(WEB_SOCKET_MESSAGE_TYPE_BINARY) == |
| 50 net::WebSocketFrameHeader::kOpCodeBinary, | 50 net::WebSocketFrameHeader::kOpCodeBinary, |
| 51 enum_values_must_match_for_opcode_binary); | 51 "enum values must match for opcode binary"); |
| 52 return static_cast<OpCode>(type); | 52 return static_cast<OpCode>(type); |
| 53 } | 53 } |
| 54 | 54 |
| 55 WebSocketMessageType OpCodeToMessageType( | 55 WebSocketMessageType OpCodeToMessageType( |
| 56 net::WebSocketFrameHeader::OpCode opCode) { | 56 net::WebSocketFrameHeader::OpCode opCode) { |
| 57 DCHECK(opCode == net::WebSocketFrameHeader::kOpCodeContinuation || | 57 DCHECK(opCode == net::WebSocketFrameHeader::kOpCodeContinuation || |
| 58 opCode == net::WebSocketFrameHeader::kOpCodeText || | 58 opCode == net::WebSocketFrameHeader::kOpCodeText || |
| 59 opCode == net::WebSocketFrameHeader::kOpCodeBinary); | 59 opCode == net::WebSocketFrameHeader::kOpCodeBinary); |
| 60 // This cast is guaranteed valid by the COMPILE_ASSERT() statements above. | 60 // This cast is guaranteed valid by the static_assert() statements above. |
| 61 return static_cast<WebSocketMessageType>(opCode); | 61 return static_cast<WebSocketMessageType>(opCode); |
| 62 } | 62 } |
| 63 | 63 |
| 64 ChannelState StateCast(WebSocketDispatcherHost::WebSocketHostState host_state) { | 64 ChannelState StateCast(WebSocketDispatcherHost::WebSocketHostState host_state) { |
| 65 const WebSocketDispatcherHost::WebSocketHostState WEBSOCKET_HOST_ALIVE = | 65 const WebSocketDispatcherHost::WebSocketHostState WEBSOCKET_HOST_ALIVE = |
| 66 WebSocketDispatcherHost::WEBSOCKET_HOST_ALIVE; | 66 WebSocketDispatcherHost::WEBSOCKET_HOST_ALIVE; |
| 67 const WebSocketDispatcherHost::WebSocketHostState WEBSOCKET_HOST_DELETED = | 67 const WebSocketDispatcherHost::WebSocketHostState WEBSOCKET_HOST_DELETED = |
| 68 WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED; | 68 WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED; |
| 69 | 69 |
| 70 DCHECK(host_state == WEBSOCKET_HOST_ALIVE || | 70 DCHECK(host_state == WEBSOCKET_HOST_ALIVE || |
| 71 host_state == WEBSOCKET_HOST_DELETED); | 71 host_state == WEBSOCKET_HOST_DELETED); |
| 72 // These compile asserts verify that we can get away with using static_cast<> | 72 // These compile asserts verify that we can get away with using static_cast<> |
| 73 // for the conversion. | 73 // for the conversion. |
| 74 COMPILE_ASSERT(static_cast<ChannelState>(WEBSOCKET_HOST_ALIVE) == | 74 static_assert(static_cast<ChannelState>(WEBSOCKET_HOST_ALIVE) == |
| 75 net::WebSocketEventInterface::CHANNEL_ALIVE, | 75 net::WebSocketEventInterface::CHANNEL_ALIVE, |
| 76 enum_values_must_match_for_state_alive); | 76 "enum values must match for state_alive"); |
| 77 COMPILE_ASSERT(static_cast<ChannelState>(WEBSOCKET_HOST_DELETED) == | 77 static_assert(static_cast<ChannelState>(WEBSOCKET_HOST_DELETED) == |
| 78 net::WebSocketEventInterface::CHANNEL_DELETED, | 78 net::WebSocketEventInterface::CHANNEL_DELETED, |
| 79 enum_values_must_match_for_state_deleted); | 79 "enum values must match for state_deleted"); |
| 80 return static_cast<ChannelState>(host_state); | 80 return static_cast<ChannelState>(host_state); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Implementation of net::WebSocketEventInterface. Receives events from our | 83 // Implementation of net::WebSocketEventInterface. Receives events from our |
| 84 // WebSocketChannel object. Each event is translated to an IPC and sent to the | 84 // WebSocketChannel object. Each event is translated to an IPC and sent to the |
| 85 // renderer or child process via WebSocketDispatcherHost. | 85 // renderer or child process via WebSocketDispatcherHost. |
| 86 class WebSocketEventHandler : public net::WebSocketEventInterface { | 86 class WebSocketEventHandler : public net::WebSocketEventInterface { |
| 87 public: | 87 public: |
| 88 WebSocketEventHandler(WebSocketDispatcherHost* dispatcher, | 88 WebSocketEventHandler(WebSocketDispatcherHost* dispatcher, |
| 89 int routing_id, | 89 int routing_id, |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 DVLOG(3) << "WebSocketHost::OnDropChannel" | 383 DVLOG(3) << "WebSocketHost::OnDropChannel" |
| 384 << " routing_id=" << routing_id_ << " was_clean=" << was_clean | 384 << " routing_id=" << routing_id_ << " was_clean=" << was_clean |
| 385 << " code=" << code << " reason=\"" << reason << "\""; | 385 << " code=" << code << " reason=\"" << reason << "\""; |
| 386 | 386 |
| 387 DCHECK(channel_); | 387 DCHECK(channel_); |
| 388 // TODO(yhirano): Handle |was_clean| appropriately. | 388 // TODO(yhirano): Handle |was_clean| appropriately. |
| 389 channel_->StartClosingHandshake(code, reason); | 389 channel_->StartClosingHandshake(code, reason); |
| 390 } | 390 } |
| 391 | 391 |
| 392 } // namespace content | 392 } // namespace content |
| OLD | NEW |