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 "mojo/services/network/network_context.h" | 8 #include "mojo/services/network/network_context.h" |
9 #include "net/websockets/websocket_channel.h" | 9 #include "net/websockets/websocket_channel.h" |
10 #include "net/websockets/websocket_errors.h" | 10 #include "net/websockets/websocket_errors.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 WebSocketClientPtr client_; | 91 WebSocketClientPtr client_; |
92 | 92 |
93 DISALLOW_COPY_AND_ASSIGN(WebSocketEventHandler); | 93 DISALLOW_COPY_AND_ASSIGN(WebSocketEventHandler); |
94 }; | 94 }; |
95 | 95 |
96 ChannelState WebSocketEventHandler::OnAddChannelResponse( | 96 ChannelState WebSocketEventHandler::OnAddChannelResponse( |
97 bool fail, | 97 bool fail, |
98 const std::string& selected_protocol, | 98 const std::string& selected_protocol, |
99 const std::string& extensions) { | 99 const std::string& extensions) { |
100 client_->DidConnect(fail, selected_protocol, extensions); | 100 client_->DidConnect(fail, selected_protocol, extensions); |
| 101 if (fail) |
| 102 return WebSocketEventInterface::CHANNEL_DELETED; |
101 return WebSocketEventInterface::CHANNEL_ALIVE; | 103 return WebSocketEventInterface::CHANNEL_ALIVE; |
102 } | 104 } |
103 | 105 |
104 ChannelState WebSocketEventHandler::OnDataFrame( | 106 ChannelState WebSocketEventHandler::OnDataFrame( |
105 bool fin, | 107 bool fin, |
106 net::WebSocketFrameHeader::OpCode type, | 108 net::WebSocketFrameHeader::OpCode type, |
107 const std::vector<char>& data) { | 109 const std::vector<char>& data) { |
108 // TODO(mpcomplete): reuse the data pipe for subsequent frames. | 110 // TODO(mpcomplete): reuse the data pipe for subsequent frames. |
109 uint32_t num_bytes = static_cast<uint32_t>(data.size()); | 111 uint32_t num_bytes = static_cast<uint32_t>(data.size()); |
110 MojoCreateDataPipeOptions options; | 112 MojoCreateDataPipeOptions options; |
(...skipping 14 matching lines...) Expand all Loading... |
125 ChannelState WebSocketEventHandler::OnClosingHandshake() { | 127 ChannelState WebSocketEventHandler::OnClosingHandshake() { |
126 return WebSocketEventInterface::CHANNEL_ALIVE; | 128 return WebSocketEventInterface::CHANNEL_ALIVE; |
127 } | 129 } |
128 | 130 |
129 ChannelState WebSocketEventHandler::OnFlowControl(int64 quota) { | 131 ChannelState WebSocketEventHandler::OnFlowControl(int64 quota) { |
130 client_->DidReceiveFlowControl(quota); | 132 client_->DidReceiveFlowControl(quota); |
131 return WebSocketEventInterface::CHANNEL_ALIVE; | 133 return WebSocketEventInterface::CHANNEL_ALIVE; |
132 } | 134 } |
133 | 135 |
134 ChannelState WebSocketEventHandler::OnDropChannel(bool was_clean, | 136 ChannelState WebSocketEventHandler::OnDropChannel(bool was_clean, |
135 uint16 code, | 137 uint16 code, |
136 const std::string& reason) { | 138 const std::string& reason) { |
137 return WebSocketEventInterface::CHANNEL_ALIVE; | 139 client_->DidClose(was_clean, code, reason); |
| 140 return WebSocketEventInterface::CHANNEL_DELETED; |
138 } | 141 } |
139 | 142 |
140 ChannelState WebSocketEventHandler::OnFailChannel(const std::string& message) { | 143 ChannelState WebSocketEventHandler::OnFailChannel(const std::string& message) { |
141 return WebSocketEventInterface::CHANNEL_ALIVE; | 144 client_->DidFail(message); |
| 145 return WebSocketEventInterface::CHANNEL_DELETED; |
142 } | 146 } |
143 | 147 |
144 ChannelState WebSocketEventHandler::OnStartOpeningHandshake( | 148 ChannelState WebSocketEventHandler::OnStartOpeningHandshake( |
145 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) { | 149 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) { |
146 return WebSocketEventInterface::CHANNEL_ALIVE; | 150 return WebSocketEventInterface::CHANNEL_ALIVE; |
147 } | 151 } |
148 | 152 |
149 ChannelState WebSocketEventHandler::OnFinishOpeningHandshake( | 153 ChannelState WebSocketEventHandler::OnFinishOpeningHandshake( |
150 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) { | 154 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) { |
151 return WebSocketEventInterface::CHANNEL_ALIVE; | 155 return WebSocketEventInterface::CHANNEL_ALIVE; |
152 } | 156 } |
153 | 157 |
154 ChannelState WebSocketEventHandler::OnSSLCertificateError( | 158 ChannelState WebSocketEventHandler::OnSSLCertificateError( |
155 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks, | 159 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks, |
156 const GURL& url, | 160 const GURL& url, |
157 const net::SSLInfo& ssl_info, | 161 const net::SSLInfo& ssl_info, |
158 bool fatal) { | 162 bool fatal) { |
159 // The above method is always asynchronous. | 163 client_->DidFail("SSL Error"); |
160 return WebSocketEventInterface::CHANNEL_ALIVE; | 164 return WebSocketEventInterface::CHANNEL_DELETED; |
161 } | 165 } |
162 | 166 |
163 } // namespace mojo | 167 } // namespace mojo |
164 | 168 |
165 WebSocketImpl::WebSocketImpl(NetworkContext* context) : context_(context) { | 169 WebSocketImpl::WebSocketImpl(NetworkContext* context) : context_(context) { |
166 } | 170 } |
167 | 171 |
168 WebSocketImpl::~WebSocketImpl() { | 172 WebSocketImpl::~WebSocketImpl() { |
169 } | 173 } |
170 | 174 |
(...skipping 21 matching lines...) Expand all Loading... |
192 ReadDataRaw(data_pipe.get(), &data[0], &num_bytes, MOJO_READ_DATA_FLAG_NONE); | 196 ReadDataRaw(data_pipe.get(), &data[0], &num_bytes, MOJO_READ_DATA_FLAG_NONE); |
193 channel_->SendFrame( | 197 channel_->SendFrame( |
194 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), data); | 198 fin, ConvertTo<net::WebSocketFrameHeader::OpCode>(type), data); |
195 } | 199 } |
196 | 200 |
197 void WebSocketImpl::FlowControl(int64_t quota) { | 201 void WebSocketImpl::FlowControl(int64_t quota) { |
198 DCHECK(channel_); | 202 DCHECK(channel_); |
199 channel_->SendFlowControl(quota); | 203 channel_->SendFlowControl(quota); |
200 } | 204 } |
201 | 205 |
202 void WebSocketImpl::Close(int16_t code, const String& reason) { | 206 void WebSocketImpl::Close(uint16_t code, const String& reason) { |
203 DCHECK(channel_); | 207 DCHECK(channel_); |
204 channel_->StartClosingHandshake(code, reason); | 208 channel_->StartClosingHandshake(code, reason); |
205 } | 209 } |
206 | 210 |
207 | |
208 } // namespace mojo | 211 } // namespace mojo |
OLD | NEW |