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/bind.h" | 10 #include "base/bind.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/serialized_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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // destroyed first. | 271 // destroyed first. |
271 stream_.reset(); | 272 stream_.reset(); |
272 // The timer may have a callback pointing back to us, so stop it just in case | 273 // The timer may have a callback pointing back to us, so stop it just in case |
273 // someone decides to run the event loop from their destructor. | 274 // someone decides to run the event loop from their destructor. |
274 timer_.Stop(); | 275 timer_.Stop(); |
275 } | 276 } |
276 | 277 |
277 void WebSocketChannel::SendAddChannelRequest( | 278 void WebSocketChannel::SendAddChannelRequest( |
278 const GURL& socket_url, | 279 const GURL& socket_url, |
279 const std::vector<std::string>& requested_subprotocols, | 280 const std::vector<std::string>& requested_subprotocols, |
280 const GURL& origin) { | 281 const SerializedOrigin& origin) { |
281 // Delegate to the tested version. | 282 // Delegate to the tested version. |
282 SendAddChannelRequestWithSuppliedCreator( | 283 SendAddChannelRequestWithSuppliedCreator( |
283 socket_url, | 284 socket_url, |
284 requested_subprotocols, | 285 requested_subprotocols, |
285 origin, | 286 origin, |
286 base::Bind(&WebSocketStream::CreateAndConnectStream)); | 287 base::Bind(&WebSocketStream::CreateAndConnectStream)); |
287 } | 288 } |
288 | 289 |
289 bool WebSocketChannel::InClosingState() const { | 290 bool WebSocketChannel::InClosingState() const { |
290 // The state RECV_CLOSED is not supported here, because it is only used in one | 291 // 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... |
397 return; | 398 return; |
398 } | 399 } |
399 AllowUnused(SendClose( | 400 AllowUnused(SendClose( |
400 code, StreamingUtf8Validator::Validate(reason) ? reason : std::string())); | 401 code, StreamingUtf8Validator::Validate(reason) ? reason : std::string())); |
401 // |this| may have been deleted. | 402 // |this| may have been deleted. |
402 } | 403 } |
403 | 404 |
404 void WebSocketChannel::SendAddChannelRequestForTesting( | 405 void WebSocketChannel::SendAddChannelRequestForTesting( |
405 const GURL& socket_url, | 406 const GURL& socket_url, |
406 const std::vector<std::string>& requested_subprotocols, | 407 const std::vector<std::string>& requested_subprotocols, |
407 const GURL& origin, | 408 const SerializedOrigin& origin, |
408 const WebSocketStreamCreator& creator) { | 409 const WebSocketStreamCreator& creator) { |
409 SendAddChannelRequestWithSuppliedCreator( | 410 SendAddChannelRequestWithSuppliedCreator( |
410 socket_url, requested_subprotocols, origin, creator); | 411 socket_url, requested_subprotocols, origin, creator); |
411 } | 412 } |
412 | 413 |
413 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( | 414 void WebSocketChannel::SetClosingHandshakeTimeoutForTesting( |
414 base::TimeDelta delay) { | 415 base::TimeDelta delay) { |
415 timeout_ = delay; | 416 timeout_ = delay; |
416 } | 417 } |
417 | 418 |
418 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( | 419 void WebSocketChannel::SendAddChannelRequestWithSuppliedCreator( |
419 const GURL& socket_url, | 420 const GURL& socket_url, |
420 const std::vector<std::string>& requested_subprotocols, | 421 const std::vector<std::string>& requested_subprotocols, |
421 const GURL& origin, | 422 const SerializedOrigin& origin, |
422 const WebSocketStreamCreator& creator) { | 423 const WebSocketStreamCreator& creator) { |
423 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); | 424 DCHECK_EQ(FRESHLY_CONSTRUCTED, state_); |
424 if (!socket_url.SchemeIsWSOrWSS()) { | 425 if (!socket_url.SchemeIsWSOrWSS()) { |
425 // TODO(ricea): Kill the renderer (this error should have been caught by | 426 // TODO(ricea): Kill the renderer (this error should have been caught by |
426 // Javascript). | 427 // Javascript). |
427 AllowUnused(event_interface_->OnAddChannelResponse(true, "", "")); | 428 AllowUnused(event_interface_->OnAddChannelResponse(true, "", "")); |
428 // |this| is deleted here. | 429 // |this| is deleted here. |
429 return; | 430 return; |
430 } | 431 } |
431 socket_url_ = socket_url; | 432 socket_url_ = socket_url; |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 955 |
955 void WebSocketChannel::CloseTimeout() { | 956 void WebSocketChannel::CloseTimeout() { |
956 stream_->Close(); | 957 stream_->Close(); |
957 DCHECK_NE(CLOSED, state_); | 958 DCHECK_NE(CLOSED, state_); |
958 state_ = CLOSED; | 959 state_ = CLOSED; |
959 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); | 960 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); |
960 // |this| has been deleted. | 961 // |this| has been deleted. |
961 } | 962 } |
962 | 963 |
963 } // namespace net | 964 } // namespace net |
OLD | NEW |