Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: net/websockets/websocket_channel.cc

Issue 145873006: ui/base/resource: Roll our own version of ReadBigEndian() function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: base/big_endian Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 11 #include "base/bind.h"
11 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
14 #include "base/numerics/safe_conversions.h" 15 #include "base/numerics/safe_conversions.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "net/base/big_endian.h"
19 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
20 #include "net/base/net_log.h" 20 #include "net/base/net_log.h"
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"
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 scoped_refptr<IOBuffer> body; 827 scoped_refptr<IOBuffer> body;
828 size_t size = 0; 828 size_t size = 0;
829 if (code == kWebSocketErrorNoStatusReceived) { 829 if (code == kWebSocketErrorNoStatusReceived) {
830 // Special case: translate kWebSocketErrorNoStatusReceived into a Close 830 // Special case: translate kWebSocketErrorNoStatusReceived into a Close
831 // frame with no payload. 831 // frame with no payload.
832 body = new IOBuffer(0); 832 body = new IOBuffer(0);
833 } else { 833 } else {
834 const size_t payload_length = kWebSocketCloseCodeLength + reason.length(); 834 const size_t payload_length = kWebSocketCloseCodeLength + reason.length();
835 body = new IOBuffer(payload_length); 835 body = new IOBuffer(payload_length);
836 size = payload_length; 836 size = payload_length;
837 WriteBigEndian(body->data(), code); 837 base::WriteBigEndian(body->data(), code);
838 COMPILE_ASSERT(sizeof(code) == kWebSocketCloseCodeLength, 838 COMPILE_ASSERT(sizeof(code) == kWebSocketCloseCodeLength,
839 they_should_both_be_two); 839 they_should_both_be_two);
840 std::copy( 840 std::copy(
841 reason.begin(), reason.end(), body->data() + kWebSocketCloseCodeLength); 841 reason.begin(), reason.end(), body->data() + kWebSocketCloseCodeLength);
842 } 842 }
843 // This use of base::Unretained() is safe because we stop the timer in the 843 // This use of base::Unretained() is safe because we stop the timer in the
844 // destructor. 844 // destructor.
845 timer_.Start( 845 timer_.Start(
846 FROM_HERE, 846 FROM_HERE,
847 timeout_, 847 timeout_,
(...skipping 22 matching lines...) Expand all
870 << static_cast<int>(buffer->data()[0]) << ")"; 870 << static_cast<int>(buffer->data()[0]) << ")";
871 parsed_ok = false; 871 parsed_ok = false;
872 *code = kWebSocketErrorProtocolError; 872 *code = kWebSocketErrorProtocolError;
873 *message = 873 *message =
874 "Received a broken close frame containing an invalid size body."; 874 "Received a broken close frame containing an invalid size body.";
875 } 875 }
876 return parsed_ok; 876 return parsed_ok;
877 } 877 }
878 const char* data = buffer->data(); 878 const char* data = buffer->data();
879 uint16 unchecked_code = 0; 879 uint16 unchecked_code = 0;
880 ReadBigEndian(data, &unchecked_code); 880 base::ReadBigEndian(data, &unchecked_code);
881 COMPILE_ASSERT(sizeof(unchecked_code) == kWebSocketCloseCodeLength, 881 COMPILE_ASSERT(sizeof(unchecked_code) == kWebSocketCloseCodeLength,
882 they_should_both_be_two_bytes); 882 they_should_both_be_two_bytes);
883 switch (unchecked_code) { 883 switch (unchecked_code) {
884 case kWebSocketErrorNoStatusReceived: 884 case kWebSocketErrorNoStatusReceived:
885 case kWebSocketErrorAbnormalClosure: 885 case kWebSocketErrorAbnormalClosure:
886 case kWebSocketErrorTlsHandshake: 886 case kWebSocketErrorTlsHandshake:
887 *code = kWebSocketErrorProtocolError; 887 *code = kWebSocketErrorProtocolError;
888 *message = 888 *message =
889 "Received a broken close frame containing a reserved status code."; 889 "Received a broken close frame containing a reserved status code.";
890 parsed_ok = false; 890 parsed_ok = false;
(...skipping 28 matching lines...) Expand all
919 919
920 void WebSocketChannel::CloseTimeout() { 920 void WebSocketChannel::CloseTimeout() {
921 stream_->Close(); 921 stream_->Close();
922 DCHECK_NE(CLOSED, state_); 922 DCHECK_NE(CLOSED, state_);
923 state_ = CLOSED; 923 state_ = CLOSED;
924 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, "")); 924 AllowUnused(DoDropChannel(false, kWebSocketErrorAbnormalClosure, ""));
925 // |this| has been deleted. 925 // |this| has been deleted.
926 } 926 }
927 927
928 } // namespace net 928 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698