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

Side by Side Diff: net/websockets/websocket_frame.h

Issue 14850012: Add missing status codes to WebSocketError enum. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove other mux status codes. Created 7 years, 7 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
« no previous file with comments | « net/websockets/websocket_errors_unittest.cc ('k') | net/websockets/websocket_frame.cc » ('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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ 6 #define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/net_export.h" 13 #include "net/base/net_export.h"
14 14
15 namespace net { 15 namespace net {
16 16
17 class IOBufferWithSize; 17 class IOBufferWithSize;
18 18
19 // Represents a WebSocket frame header. 19 // Represents a WebSocket frame header.
20 // 20 //
21 // Members of this class correspond to each element in WebSocket frame header 21 // Members of this class correspond to each element in WebSocket frame header
22 // (see http://tools.ietf.org/html/rfc6455#section-5.2). 22 // (see http://tools.ietf.org/html/rfc6455#section-5.2).
23 struct NET_EXPORT WebSocketFrameHeader { 23 struct NET_EXPORT WebSocketFrameHeader {
24 typedef int OpCode; 24 typedef int OpCode;
25 static const OpCode kOpCodeContinuation; 25 static const OpCode kOpCodeContinuation;
26 static const OpCode kOpCodeText; 26 static const OpCode kOpCodeText;
27 static const OpCode kOpCodeBinary; 27 static const OpCode kOpCodeBinary;
28 static const OpCode kOpCodeDataUnused;
28 static const OpCode kOpCodeClose; 29 static const OpCode kOpCodeClose;
29 static const OpCode kOpCodePing; 30 static const OpCode kOpCodePing;
30 static const OpCode kOpCodePong; 31 static const OpCode kOpCodePong;
32 static const OpCode kOpCodeControlUnused;
33
34 // Efficiently determine whether a given opcode is one of the data opcodes
35 // known to this implementation.
36 static bool IsKnownDataOpCode(OpCode opCode) {
37 return (opCode & ~3) == 0 && opCode != 3;
38 }
39
40 // Efficiently determine whether a given opcode is one of the control opcodes
41 // known to this implementation.
42 static bool IsKnownControlOpCode(OpCode opCode) {
43 return (opCode & ~3) == 8 && opCode != 0x0B;
44 }
31 45
32 // These values must be a compile-time constant. "enum hack" is used here 46 // These values must be a compile-time constant. "enum hack" is used here
33 // to make MSVC happy. 47 // to make MSVC happy.
34 enum { 48 enum {
35 kBaseHeaderSize = 2, 49 kBaseHeaderSize = 2,
36 kMaximumExtendedLengthSize = 8, 50 kMaximumExtendedLengthSize = 8,
37 kMaskingKeyLength = 4 51 kMaskingKeyLength = 4
38 }; 52 };
39 53
54 // Constructor to avoid a lot of repetitive initialisation.
55 explicit WebSocketFrameHeader(OpCode opCode)
56 : final(false),
57 reserved1(false),
58 reserved2(false),
59 reserved3(false),
60 opcode(opCode),
61 masked(false),
62 payload_length(0) {}
63
64 // Backwards-compatible constructor to avoid breaking Chromedriver.
65 // The above constructor should be used in preference, as there is no good
66 // default value for "opcode".
67 // TODO(ricea): Remove this once Chromedriver have stopped using it.
68 WebSocketFrameHeader()
69 : final(false),
70 reserved1(false),
71 reserved2(false),
72 reserved3(false),
73 opcode(kOpCodeDataUnused),
74 masked(false),
75 payload_length(0) {}
76
77 // Create a clone of this object on the heap.
78 scoped_ptr<WebSocketFrameHeader> Clone();
79
40 // Members below correspond to each item in WebSocket frame header. 80 // Members below correspond to each item in WebSocket frame header.
41 // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details. 81 // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details.
42 bool final; 82 bool final;
43 bool reserved1; 83 bool reserved1;
44 bool reserved2; 84 bool reserved2;
45 bool reserved3; 85 bool reserved3;
46 OpCode opcode; 86 OpCode opcode;
47 bool masked; 87 bool masked;
48 uint64 payload_length; 88 uint64 payload_length;
89
90 private:
91 DISALLOW_COPY_AND_ASSIGN(WebSocketFrameHeader);
49 }; 92 };
50 93
51 // Contains payload data of part of a WebSocket frame. 94 // Contains payload data of part of a WebSocket frame.
52 // 95 //
53 // Payload of a WebSocket frame may be divided into multiple chunks. 96 // Payload of a WebSocket frame may be divided into multiple chunks.
54 // You need to look at |final_chunk| member variable to detect the end of a 97 // You need to look at |final_chunk| member variable to detect the end of a
55 // series of chunk objects of a WebSocket frame. 98 // series of chunk objects of a WebSocket frame.
56 // 99 //
57 // Frame dissection is necessary to handle WebSocket frame stream containing 100 // Frame dissection is necessary to handle WebSocket frame stream containing
58 // abritrarily large frames in the browser process. Because the server may send 101 // abritrarily large frames in the browser process. Because the server may send
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // used for unmasking a WebSocket frame. 174 // used for unmasking a WebSocket frame.
132 NET_EXPORT void MaskWebSocketFramePayload( 175 NET_EXPORT void MaskWebSocketFramePayload(
133 const WebSocketMaskingKey& masking_key, 176 const WebSocketMaskingKey& masking_key,
134 uint64 frame_offset, 177 uint64 frame_offset,
135 char* data, 178 char* data,
136 int data_size); 179 int data_size);
137 180
138 } // namespace net 181 } // namespace net
139 182
140 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_ 183 #endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
OLDNEW
« no previous file with comments | « net/websockets/websocket_errors_unittest.cc ('k') | net/websockets/websocket_frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698