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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 return; | 285 return; |
286 | 286 |
287 // If a recoverable error condition existed, it would go here. | 287 // If a recoverable error condition existed, it would go here. |
288 | 288 |
289 default: | 289 default: |
290 DCHECK_LT(result, 0) | 290 DCHECK_LT(result, 0) |
291 << "WriteFrames() should only return OK or ERR_ codes"; | 291 << "WriteFrames() should only return OK or ERR_ codes"; |
292 stream_->Close(); | 292 stream_->Close(); |
293 if (state_ != CLOSED) { | 293 if (state_ != CLOSED) { |
294 state_ = CLOSED; | 294 state_ = CLOSED; |
295 event_interface_->OnDropChannel(kWebSocketErrorAbnormalClosure, | 295 // TODO(yhirano): Set |fail| appropriately. |
Adam Rice
2013/10/23 03:18:06
The OnDropChannel-calling code changes a bit in ht
yhirano
2013/10/23 05:42:23
OK, I will implement this in future CLs.
| |
296 bool fail = false; | |
297 event_interface_->OnDropChannel(fail, | |
298 kWebSocketErrorAbnormalClosure, | |
296 "Abnormal Closure"); | 299 "Abnormal Closure"); |
297 } | 300 } |
298 return; | 301 return; |
299 } | 302 } |
300 } | 303 } |
301 | 304 |
302 void WebSocketChannel::ReadFrames() { | 305 void WebSocketChannel::ReadFrames() { |
303 int result = OK; | 306 int result = OK; |
304 do { | 307 do { |
305 // This use of base::Unretained is safe because this object owns the | 308 // This use of base::Unretained is safe because this object owns the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 << "ReadFrames() should only return OK or ERR_ codes"; | 352 << "ReadFrames() should only return OK or ERR_ codes"; |
350 stream_->Close(); | 353 stream_->Close(); |
351 if (state_ != CLOSED) { | 354 if (state_ != CLOSED) { |
352 state_ = CLOSED; | 355 state_ = CLOSED; |
353 uint16 code = kWebSocketErrorAbnormalClosure; | 356 uint16 code = kWebSocketErrorAbnormalClosure; |
354 std::string reason = "Abnormal Closure"; | 357 std::string reason = "Abnormal Closure"; |
355 if (closing_code_ != 0) { | 358 if (closing_code_ != 0) { |
356 code = closing_code_; | 359 code = closing_code_; |
357 reason = closing_reason_; | 360 reason = closing_reason_; |
358 } | 361 } |
359 event_interface_->OnDropChannel(code, reason); | 362 // TODO(yhirano): Set |fail| appropriately. |
363 bool fail = false; | |
364 event_interface_->OnDropChannel(fail, code, reason); | |
360 } | 365 } |
361 return; | 366 return; |
362 } | 367 } |
363 } | 368 } |
364 | 369 |
365 void WebSocketChannel::ProcessFrame(scoped_ptr<WebSocketFrame> frame) { | 370 void WebSocketChannel::ProcessFrame(scoped_ptr<WebSocketFrame> frame) { |
366 if (frame->header.masked) { | 371 if (frame->header.masked) { |
367 // RFC6455 Section 5.1 "A client MUST close a connection if it detects a | 372 // RFC6455 Section 5.1 "A client MUST close a connection if it detects a |
368 // masked frame." | 373 // masked frame." |
369 FailChannel(SEND_REAL_ERROR, | 374 FailChannel(SEND_REAL_ERROR, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
547 } | 552 } |
548 SendClose(send_code, send_reason); // Sets state_ to SEND_CLOSED | 553 SendClose(send_code, send_reason); // Sets state_ to SEND_CLOSED |
549 } | 554 } |
550 // Careful study of RFC6455 section 7.1.7 and 7.1.1 indicates the browser | 555 // Careful study of RFC6455 section 7.1.7 and 7.1.1 indicates the browser |
551 // should close the connection itself without waiting for the closing | 556 // should close the connection itself without waiting for the closing |
552 // handshake. | 557 // handshake. |
553 stream_->Close(); | 558 stream_->Close(); |
554 state_ = CLOSED; | 559 state_ = CLOSED; |
555 | 560 |
556 if (old_state != CLOSED) { | 561 if (old_state != CLOSED) { |
557 event_interface_->OnDropChannel(code, reason); | 562 // TODO(yhirano): Set |fail| appropriately. |
563 bool fail = false; | |
564 event_interface_->OnDropChannel(fail, code, reason); | |
558 } | 565 } |
559 } | 566 } |
560 | 567 |
561 void WebSocketChannel::SendClose(uint16 code, const std::string& reason) { | 568 void WebSocketChannel::SendClose(uint16 code, const std::string& reason) { |
562 DCHECK(state_ == CONNECTED || state_ == RECV_CLOSED); | 569 DCHECK(state_ == CONNECTED || state_ == RECV_CLOSED); |
563 // TODO(ricea): Ensure reason.length() <= 123 | 570 // TODO(ricea): Ensure reason.length() <= 123 |
564 scoped_refptr<IOBuffer> body; | 571 scoped_refptr<IOBuffer> body; |
565 size_t size = 0; | 572 size_t size = 0; |
566 if (code == kWebSocketErrorNoStatusReceived) { | 573 if (code == kWebSocketErrorNoStatusReceived) { |
567 // Special case: translate kWebSocketErrorNoStatusReceived into a Close | 574 // Special case: translate kWebSocketErrorNoStatusReceived into a Close |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 } | 619 } |
613 std::string text(data + kWebSocketCloseCodeLength, data + size); | 620 std::string text(data + kWebSocketCloseCodeLength, data + size); |
614 // TODO(ricea): Is this check strict enough? In particular, check the | 621 // TODO(ricea): Is this check strict enough? In particular, check the |
615 // "Security Considerations" from RFC3629. | 622 // "Security Considerations" from RFC3629. |
616 if (IsStringUTF8(text)) { | 623 if (IsStringUTF8(text)) { |
617 reason->swap(text); | 624 reason->swap(text); |
618 } | 625 } |
619 } | 626 } |
620 | 627 |
621 } // namespace net | 628 } // namespace net |
OLD | NEW |