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

Side by Side Diff: runtime/bin/websocket_impl.dart

Issue 10829459: Deprecate Math object in corelib in favor of dart:math library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 4 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
« no previous file with comments | « runtime/bin/stream_util.dart ('k') | runtime/lib/math_patch.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 final String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; 5 final String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
6 6
7 class _WebSocketMessageType { 7 class _WebSocketMessageType {
8 static final int NONE = 0; 8 static final int NONE = 0;
9 static final int BINARY = 1; 9 static final int BINARY = 1;
10 static final int TEXT = 2; 10 static final int TEXT = 2;
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 720 }
721 721
722 // Connection upgrade successful. 722 // Connection upgrade successful.
723 DetachedSocket detached = _conn.detachSocket(); 723 DetachedSocket detached = _conn.detachSocket();
724 _socketConnected(detached.socket); 724 _socketConnected(detached.socket);
725 if (_onOpen != null) _onOpen(); 725 if (_onOpen != null) _onOpen();
726 _startProcessing(detached.unparsedData); 726 _startProcessing(detached.unparsedData);
727 } 727 }
728 728
729 void _generateNonceAndHash() { 729 void _generateNonceAndHash() {
730 Random random = new Random();
730 assert(_nonce == null); 731 assert(_nonce == null);
731 void intToBigEndianBytes(int value, List<int> bytes, int offset) { 732 void intToBigEndianBytes(int value, List<int> bytes, int offset) {
732 bytes[offset] = (value >> 24) & 0xFF; 733 bytes[offset] = (value >> 24) & 0xFF;
733 bytes[offset + 1] = (value >> 16) & 0xFF; 734 bytes[offset + 1] = (value >> 16) & 0xFF;
734 bytes[offset + 2] = (value >> 8) & 0xFF; 735 bytes[offset + 2] = (value >> 8) & 0xFF;
735 bytes[offset + 3] = value & 0xFF; 736 bytes[offset + 3] = value & 0xFF;
736 } 737 }
737 738
738 // Generate 16 random bytes. Use the last four bytes for the hash code. 739 // Generate 16 random bytes. Use the last four bytes for the hash code.
739 List<int> nonce = new List<int>(16); 740 List<int> nonce = new List<int>(16);
740 for (int i = 0; i < 4; i++) { 741 for (int i = 0; i < 4; i++) {
741 int r = (Math.random() * 0x100000000).toInt(); 742 int r = random.nextInt(0x100000000);
742 intToBigEndianBytes(r, nonce, i * 4); 743 intToBigEndianBytes(r, nonce, i * 4);
743 } 744 }
744 _nonce = _Base64._encode(nonce); 745 _nonce = _Base64._encode(nonce);
745 _hash = (Math.random() * 0x100000000).toInt(); 746 _hash = random.nextInt(0x100000000);
746 } 747 }
747 748
748 bool _isWebSocketUpgrade(HttpClientResponse response) { 749 bool _isWebSocketUpgrade(HttpClientResponse response) {
749 if (response.headers[HttpHeaders.CONNECTION] == null) { 750 if (response.headers[HttpHeaders.CONNECTION] == null) {
750 return false; 751 return false;
751 } 752 }
752 bool isUpgrade = false; 753 bool isUpgrade = false;
753 response.headers[HttpHeaders.CONNECTION].forEach((String value) { 754 response.headers[HttpHeaders.CONNECTION].forEach((String value) {
754 if (value.toLowerCase() == "upgrade") isUpgrade = true; 755 if (value.toLowerCase() == "upgrade") isUpgrade = true;
755 }); 756 });
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 882
882 class _WebSocketCloseEvent implements CloseEvent { 883 class _WebSocketCloseEvent implements CloseEvent {
883 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); 884 _WebSocketCloseEvent(this._wasClean, this._code, this._reason);
884 bool get wasClean() => _wasClean; 885 bool get wasClean() => _wasClean;
885 int get code() => _code; 886 int get code() => _code;
886 String get reason() => _reason; 887 String get reason() => _reason;
887 bool _wasClean; 888 bool _wasClean;
888 int _code; 889 int _code;
889 String _reason; 890 String _reason;
890 } 891 }
OLDNEW
« no previous file with comments | « runtime/bin/stream_util.dart ('k') | runtime/lib/math_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698