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

Unified Diff: net/websockets/websocket_frame.h

Issue 9956013: Add WebSocketFrameParser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase for try runs. Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: net/websockets/websocket_frame.h
diff --git a/net/websockets/websocket_frame.h b/net/websockets/websocket_frame.h
new file mode 100644
index 0000000000000000000000000000000000000000..c32b6455d08d0a08dcb2771707f0b31132ccb66b
--- /dev/null
+++ b/net/websockets/websocket_frame.h
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
+#define NET_WEBSOCKETS_WEBSOCKET_FRAME_H_
+#pragma once
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "net/base/net_export.h"
+
+namespace net {
+
+// Represents a WebSocket frame header which may be shared by multiple
+// WebSocketPartialFrames.
+//
+// Members of this class correspond to each element in WebSocket frame header
+// (see http://tools.ietf.org/html/rfc6455#section-5.2).
+struct NET_EXPORT_PRIVATE WebSocketFrameHeader
+ : public base::RefCounted<WebSocketFrameHeader> {
mmenke 2012/05/02 16:15:41 May be worth considering not refcounting this, jus
Yuta Kitamura 2012/05/08 08:21:58 After some consideration, I decided to not refcoun
+ typedef int OpCode;
+ static const OpCode kOpCodeContinuation;
+ static const OpCode kOpCodeText;
+ static const OpCode kOpCodeBinary;
+ static const OpCode kOpCodeClose;
+ static const OpCode kOpCodePing;
+ static const OpCode kOpCodePong;
+
+ // These values must be a compile-time constant. "enum hack" is used here
+ // to make MSVC happy.
+ enum {
+ kBaseHeaderSize = 2,
+ kMaximumExtendedLengthSize = 8,
+ kMaskingKeyLength = 4
+ };
+
+ // Members below correspond to each item in WebSocket frame header.
+ // See <http://tools.ietf.org/html/rfc6455#section-5.2> for details.
+ bool final;
+ bool reserved1;
+ bool reserved2;
+ bool reserved3;
+ OpCode opcode;
+ bool masked;
+ uint64 payload_length;
+};
+
+// Contains payload data of a WebSocket frame.
+//
+// Payload of a WebSocket frame may be divided into multiple
+// WebSocketPartialFrame objects. You need to look at |final_part| member
+// variable to detect the end of a series of partial frame objects.
+//
+// Frame dissection is necessary to handle WebSocket frame stream containing
+// abritrarily large frames in the browser process. Because the server may send
+// a huge frame that doesn't fit in the memory, we cannot store the entire
+// payload data in the memory.
+//
+// Users of this struct should treat WebSocket frames as a data stream; it's
+// important to keep the frame data flowing, especially in the browser process.
+// Users should not let the data stuck somewhere in the pipeline.
+struct NET_EXPORT_PRIVATE WebSocketPartialFrame {
Yuta Kitamura 2012/05/08 08:21:58 I'm going to rename this class to "WebSocketFrameC
+ WebSocketPartialFrame();
+ ~WebSocketPartialFrame();
+
+ // |header| may be shared among multiple WebSocketPartialFrames.
+ scoped_refptr<const WebSocketFrameHeader> header;
+
+ // Indicates this part is the last of partial frames.
+ bool final_part;
+
+ // |data| is always unmasked even if the frame is masked.
+ std::vector<char> data;
+};
+
+} // namespace net
+
+#endif // NET_WEBSOCKETS_WEBSOCKET_FRAME_H_

Powered by Google App Engine
This is Rietveld 408576698