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 "net/websockets/websocket_channel.h" | 5 #include "net/websockets/websocket_channel.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" // for size_t | 9 #include "base/basictypes.h" // for size_t |
10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/http/http_request_headers.h" | 21 #include "net/http/http_request_headers.h" |
22 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
23 #include "net/http/http_util.h" | 23 #include "net/http/http_util.h" |
24 #include "net/websockets/websocket_errors.h" | 24 #include "net/websockets/websocket_errors.h" |
25 #include "net/websockets/websocket_event_interface.h" | 25 #include "net/websockets/websocket_event_interface.h" |
26 #include "net/websockets/websocket_frame.h" | 26 #include "net/websockets/websocket_frame.h" |
27 #include "net/websockets/websocket_handshake_request_info.h" | 27 #include "net/websockets/websocket_handshake_request_info.h" |
28 #include "net/websockets/websocket_handshake_response_info.h" | 28 #include "net/websockets/websocket_handshake_response_info.h" |
29 #include "net/websockets/websocket_mux.h" | 29 #include "net/websockets/websocket_mux.h" |
30 #include "net/websockets/websocket_stream.h" | 30 #include "net/websockets/websocket_stream.h" |
| 31 #include "url/origin.h" |
31 | 32 |
32 namespace net { | 33 namespace net { |
33 | 34 |
34 namespace { | 35 namespace { |
35 | 36 |
36 using base::StreamingUtf8Validator; | 37 using base::StreamingUtf8Validator; |
37 | 38 |
38 const int kDefaultSendQuotaLowWaterMark = 1 << 16; | 39 const int kDefaultSendQuotaLowWaterMark = 1 << 16; |
39 const int kDefaultSendQuotaHighWaterMark = 1 << 17; | 40 const int kDefaultSendQuotaHighWaterMark = 1 << 17; |
40 const size_t kWebSocketCloseCodeLength = 2; | 41 const size_t kWebSocketCloseCodeLength = 2; |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // destroyed first. | 273 // destroyed first. |
273 stream_.reset(); | 274 stream_.reset(); |
274 // The timer may have a callback pointing back to us, so stop it just in case | 275 // The timer may have a callback pointing back to us, so stop it just in case |
275 // someone decides to run the event loop from their destructor. | 276 // someone decides to run the event loop from their destructor. |
276 timer_.Stop(); | 277 timer_.Stop(); |
277 } | 278 } |
278 | 279 |
279 void WebSocketChannel::SendAddChannelRequest( | 280 void WebSocketChannel::SendAddChannelRequest( |
280 const GURL& socket_url, | 281 const GURL& socket_url, |
281 const std::vector<std::string>& requested_subprotocols, | 282 const std::vector<std::string>& requested_subprotocols, |
282 const GURL& origin) { | 283 const url::Origin& origin) { |
283 // Delegate to the tested version. | 284 // Delegate to the tested version. |
284 SendAddChannelRequestWithSuppliedCreator( | 285 SendAddChannelRequestWithSuppliedCreator( |
285 socket_url, | 286 socket_url, |
286 requested_subprotocols, | 287 requested_subprotocols, |
287 origin, | 288 origin, |
288 base::Bind(&WebSocketStream::CreateAndConnectStream)); | 289 base::Bind(&WebSocketStream::CreateAndConnectStream)); |
289 } | 290 } |
290 | 291 |
291 bool WebSocketChannel::InClosingState() const { | 292 bool WebSocketChannel::InClosingState() const { |
292 // The state RECV_CLOSED is not supported here, because it is only used in one | 293 // The state RECV_CLOSED is not supported here, because it is only used in one |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return; | 400 return; |
400 } | 401 } |
401 AllowUnused(SendClose( | 402 AllowUnused(SendClose( |
402 code, StreamingUtf8Validator::Validate(reason) ? reason : std::string())); | 403 code, StreamingUtf8Validator::Validate(reason) ? reason : std::string())); |
403 // |this| may have been deleted. | 404 // |this| may have been deleted. |
404 } | 405 } |
405 | 406 |
406 void WebSocketChannel::SendAddChannelRequestForTesting( | 407 void WebSocketChannel::SendAddChannelRequestForTesting( |
407 const GURL& socket_url, | 408 const GURL& socket_url, |
408 const std::vector<std::string>& requested_subprotocols, | 409 const std::vector<std::string>& requested_subprotocols, |
409 const GURL& origin, | 410 const url::Origin& origin, |
410 const WebSocketStreamCreator& creator) { | 411 const WebSocketStreamCreator& creator) { |
411 SendAddChannelRequestWithSuppliedCreator( | 412 SendAddChannelRequestWithSuppliedCreator( |
412 socket_url, requested_subprotocols, origin, creator); | 413 socket_url, requested_subprotocols, origin, creator); |
413 } | 414 } |
414 | 415 |
415 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( | 416 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( |
416 base::TimeDelta delay) { | 417 base::TimeDelta delay) { |
417 timeout_ = delay; | 418 timeout_ = delay; |
418 } | 419 } |
419 | 420 |
420 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( | 421 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( |
421 const GURL& socket_url, | 422 const GURL& socket_url, |
422 const std::vector<std::string>& requested_subprotocols, | 423 const std::vector<std::string>& requested_subprotocols, |
423 const GURL& origin, | 424 const url::Origin& origin, |
424 const WebSocketStreamCreator& creator) { | 425 const WebSocketStreamCreator& creator) { |
425 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); | 426 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); |
426 if (!socket_url.SchemeIsWSOrWSS()) { | 427 if (!socket_url.SchemeIsWSOrWSS()) { |
427 // TODO(ricea): Kill the renderer (this error should have been caught by | 428 // TODO(ricea): Kill the renderer (this error should have been caught by |
428 // Javascript). | 429 // Javascript). |
429 AllowUnused(event_interface_->OnAddChannelResponse(true, "", "")); | 430 AllowUnused(event_interface_->OnAddChannelResponse(true, "", "")); |
430 // |this| is deleted here. | 431 // |this| is deleted here. |
431 return; | 432 return; |
432 } | 433 } |
433 socket_url_ = socket_url; | 434 socket_url_ = socket_url; |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 | 969 |
969 void WebSocketChannel::CloseTimeout() { | 970 void WebSocketChannel::CloseTimeout() { |
970 stream_->Close(); | 971 stream_->Close(); |
971 DCHECK_NE(CLOSED, state_); | 972 DCHECK_NE(CLOSED, state_); |
972 state_ = CLOSED; | 973 state_ = CLOSED; |
973 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); | 974 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); |
974 // |this| has been deleted. | 975 // |this| has been deleted. |
975 } | 976 } |
976 | 977 |
977 } // namespace net | 978 } // namespace net |
OLD | NEW |