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/common/handle_watcher.h" |
10 #include "mojo/services/network/network_context.h" | 10 #include "mojo/services/network/network_context.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(WebSocketClientPtr client) |
66 : client_(client.Pass()) { | 66 : client_(client.Pass()) { |
67 } | 67 } |
68 virtual ~WebSocketEventHandler() {} | 68 ~WebSocketEventHandler() override {} |
69 | 69 |
70 private: | 70 private: |
71 // net::WebSocketEventInterface methods: | 71 // net::WebSocketEventInterface methods: |
72 virtual ChannelState OnAddChannelResponse( | 72 ChannelState OnAddChannelResponse(bool fail, |
73 bool fail, | 73 const std::string& selected_subprotocol, |
74 const std::string& selected_subprotocol, | 74 const std::string& extensions) override; |
75 const std::string& extensions) override; | 75 ChannelState OnDataFrame(bool fin, |
76 virtual ChannelState OnDataFrame(bool fin, | 76 WebSocketMessageType type, |
77 WebSocketMessageType type, | 77 const std::vector<char>& data) override; |
78 const std::vector<char>& data) override; | 78 ChannelState OnClosingHandshake() override; |
79 virtual ChannelState OnClosingHandshake() override; | 79 ChannelState OnFlowControl(int64 quota) override; |
80 virtual ChannelState OnFlowControl(int64 quota) override; | 80 ChannelState OnDropChannel(bool was_clean, |
81 virtual ChannelState OnDropChannel(bool was_clean, | 81 uint16 code, |
82 uint16 code, | 82 const std::string& reason) override; |
83 const std::string& reason) override; | 83 ChannelState OnFailChannel(const std::string& message) override; |
84 virtual ChannelState OnFailChannel(const std::string& message) override; | 84 ChannelState OnStartOpeningHandshake( |
85 virtual ChannelState OnStartOpeningHandshake( | |
86 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) override; | 85 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) override; |
87 virtual ChannelState OnFinishOpeningHandshake( | 86 ChannelState OnFinishOpeningHandshake( |
88 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) override; | 87 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) override; |
89 virtual ChannelState OnSSLCertificateError( | 88 ChannelState OnSSLCertificateError( |
90 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks, | 89 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks, |
91 const GURL& url, | 90 const GURL& url, |
92 const net::SSLInfo& ssl_info, | 91 const net::SSLInfo& ssl_info, |
93 bool fatal) override; | 92 bool fatal) override; |
94 | 93 |
95 // Called once we've written to |receive_stream_|. | 94 // Called once we've written to |receive_stream_|. |
96 void DidWriteToReceiveStream(bool fin, | 95 void DidWriteToReceiveStream(bool fin, |
97 net::WebSocketFrameHeader::OpCode type, | 96 net::WebSocketFrameHeader::OpCode type, |
98 uint32_t num_bytes, | 97 uint32_t num_bytes, |
99 const char* buffer); | 98 const char* buffer); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 uint32_t num_bytes, | 229 uint32_t num_bytes, |
231 const char* data) { | 230 const char* data) { |
232 std::vector<char> buffer(num_bytes); | 231 std::vector<char> buffer(num_bytes); |
233 memcpy(&buffer[0], data, num_bytes); | 232 memcpy(&buffer[0], data, num_bytes); |
234 DCHECK(channel_); | 233 DCHECK(channel_); |
235 channel_->SendFrame( | 234 channel_->SendFrame( |
236 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer); | 235 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), buffer); |
237 } | 236 } |
238 | 237 |
239 } // namespace mojo | 238 } // namespace mojo |
OLD | NEW |