| 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 <stdint.h> |
| 8 |
| 7 #include <utility> | 9 #include <utility> |
| 8 | 10 |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 11 #include "mojo/message_pump/handle_watcher.h" | 14 #include "mojo/message_pump/handle_watcher.h" |
| 12 #include "mojo/services/network/network_context.h" | 15 #include "mojo/services/network/network_context.h" |
| 13 #include "mojo/services/network/public/cpp/web_socket_read_queue.h" | 16 #include "mojo/services/network/public/cpp/web_socket_read_queue.h" |
| 14 #include "mojo/services/network/public/cpp/web_socket_write_queue.h" | 17 #include "mojo/services/network/public/cpp/web_socket_write_queue.h" |
| 15 #include "net/websockets/websocket_channel.h" | 18 #include "net/websockets/websocket_channel.h" |
| 16 #include "net/websockets/websocket_errors.h" | 19 #include "net/websockets/websocket_errors.h" |
| 17 #include "net/websockets/websocket_event_interface.h" | 20 #include "net/websockets/websocket_event_interface.h" |
| 18 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode | 21 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode |
| 19 #include "net/websockets/websocket_handshake_request_info.h" | 22 #include "net/websockets/websocket_handshake_request_info.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 ~WebSocketEventHandler() override {} | 72 ~WebSocketEventHandler() override {} |
| 70 | 73 |
| 71 private: | 74 private: |
| 72 // net::WebSocketEventInterface methods: | 75 // net::WebSocketEventInterface methods: |
| 73 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, | 76 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, |
| 74 const std::string& extensions) override; | 77 const std::string& extensions) override; |
| 75 ChannelState OnDataFrame(bool fin, | 78 ChannelState OnDataFrame(bool fin, |
| 76 WebSocketMessageType type, | 79 WebSocketMessageType type, |
| 77 const std::vector<char>& data) override; | 80 const std::vector<char>& data) override; |
| 78 ChannelState OnClosingHandshake() override; | 81 ChannelState OnClosingHandshake() override; |
| 79 ChannelState OnFlowControl(int64 quota) override; | 82 ChannelState OnFlowControl(int64_t quota) override; |
| 80 ChannelState OnDropChannel(bool was_clean, | 83 ChannelState OnDropChannel(bool was_clean, |
| 81 uint16 code, | 84 uint16_t code, |
| 82 const std::string& reason) override; | 85 const std::string& reason) override; |
| 83 ChannelState OnFailChannel(const std::string& message) override; | 86 ChannelState OnFailChannel(const std::string& message) override; |
| 84 ChannelState OnStartOpeningHandshake( | 87 ChannelState OnStartOpeningHandshake( |
| 85 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) override; | 88 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) override; |
| 86 ChannelState OnFinishOpeningHandshake( | 89 ChannelState OnFinishOpeningHandshake( |
| 87 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) override; | 90 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) override; |
| 88 ChannelState OnSSLCertificateError( | 91 ChannelState OnSSLCertificateError( |
| 89 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks, | 92 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks, |
| 90 const GURL& url, | 93 const GURL& url, |
| 91 const net::SSLInfo& ssl_info, | 94 const net::SSLInfo& ssl_info, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 base::Bind(&WebSocketEventHandler::DidWriteToReceiveStream, | 127 base::Bind(&WebSocketEventHandler::DidWriteToReceiveStream, |
| 125 base::Unretained(this), | 128 base::Unretained(this), |
| 126 fin, type, size)); | 129 fin, type, size)); |
| 127 return WebSocketEventInterface::CHANNEL_ALIVE; | 130 return WebSocketEventInterface::CHANNEL_ALIVE; |
| 128 } | 131 } |
| 129 | 132 |
| 130 ChannelState WebSocketEventHandler::OnClosingHandshake() { | 133 ChannelState WebSocketEventHandler::OnClosingHandshake() { |
| 131 return WebSocketEventInterface::CHANNEL_ALIVE; | 134 return WebSocketEventInterface::CHANNEL_ALIVE; |
| 132 } | 135 } |
| 133 | 136 |
| 134 ChannelState WebSocketEventHandler::OnFlowControl(int64 quota) { | 137 ChannelState WebSocketEventHandler::OnFlowControl(int64_t quota) { |
| 135 client_->DidReceiveFlowControl(quota); | 138 client_->DidReceiveFlowControl(quota); |
| 136 return WebSocketEventInterface::CHANNEL_ALIVE; | 139 return WebSocketEventInterface::CHANNEL_ALIVE; |
| 137 } | 140 } |
| 138 | 141 |
| 139 ChannelState WebSocketEventHandler::OnDropChannel(bool was_clean, | 142 ChannelState WebSocketEventHandler::OnDropChannel(bool was_clean, |
| 140 uint16 code, | 143 uint16_t code, |
| 141 const std::string& reason) { | 144 const std::string& reason) { |
| 142 client_->DidClose(was_clean, code, reason); | 145 client_->DidClose(was_clean, code, reason); |
| 143 return WebSocketEventInterface::CHANNEL_DELETED; | 146 return WebSocketEventInterface::CHANNEL_DELETED; |
| 144 } | 147 } |
| 145 | 148 |
| 146 ChannelState WebSocketEventHandler::OnFailChannel(const std::string& message) { | 149 ChannelState WebSocketEventHandler::OnFailChannel(const std::string& message) { |
| 147 client_->DidFail(message); | 150 client_->DidFail(message); |
| 148 return WebSocketEventInterface::CHANNEL_DELETED; | 151 return WebSocketEventInterface::CHANNEL_DELETED; |
| 149 } | 152 } |
| 150 | 153 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 uint32_t num_bytes, | 233 uint32_t num_bytes, |
| 231 const char* data) { | 234 const char* data) { |
| 232 std::vector<char> buffer(num_bytes); | 235 std::vector<char> buffer(num_bytes); |
| 233 memcpy(&buffer[0], data, num_bytes); | 236 memcpy(&buffer[0], data, num_bytes); |
| 234 DCHECK(channel_); | 237 DCHECK(channel_); |
| 235 channel_->SendFrame( | 238 channel_->SendFrame( |
| 236 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer); | 239 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer); |
| 237 } | 240 } |
| 238 | 241 |
| 239 } // namespace mojo | 242 } // namespace mojo |
| OLD | NEW |