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

Unified Diff: third_party/WebKit/Source/modules/fetch/MultipartParser.h

Issue 2292763002: [Fetch API] Implement Request.formData and Response.formData. (Closed)
Patch Set: Handle partial delimiter prefixes correctly and really test them Created 4 years, 3 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: third_party/WebKit/Source/modules/fetch/MultipartParser.h
diff --git a/third_party/WebKit/Source/modules/fetch/MultipartParser.h b/third_party/WebKit/Source/modules/fetch/MultipartParser.h
new file mode 100644
index 0000000000000000000000000000000000000000..43134ebafeb6d51172afdd3ed69b1c72a837372a
--- /dev/null
+++ b/third_party/WebKit/Source/modules/fetch/MultipartParser.h
@@ -0,0 +1,67 @@
+// Copyright 2016 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 MultipartParser_h
+#define MultipartParser_h
+
+#include "modules/ModulesExport.h"
+#include "platform/heap/Handle.h"
+#include "platform/network/ResourceResponse.h"
+#include "wtf/Vector.h"
+
+namespace blink {
+
+class MODULES_EXPORT MultipartParser : public GarbageCollectedFinalized<MultipartParser> {
yhirano 2016/09/07 06:00:16 final
e_hakkinen 2016/09/08 00:06:29 Done.
+ WTF_MAKE_NONCOPYABLE(MultipartParser);
+
+public:
+ class MODULES_EXPORT Client : public GarbageCollectedMixin {
+ public:
+ virtual ~Client() = default;
+ virtual void partHeaderFieldsInMultipartReceived(const ResourceResponse&) = 0;
+ virtual void partDataInMultipartReceived(const char* bytes, size_t) = 0;
+ virtual void partDataInMultipartFullyReceived() = 0;
+ DEFINE_INLINE_VIRTUAL_TRACE() {}
+ };
+
+ MultipartParser(Vector<char> boundary, Client*);
+ bool appendData(const char* bytes, size_t);
+ void cancel();
+ bool finish();
+
+ bool isCancelled() const { return m_state == Cancelled; }
+
+ DECLARE_TRACE();
+
+private:
+ size_t countNonDelimiterBytes(const char* bytes, size_t) const;
+ size_t countPossibleDelimiterBytes(const char* bytes, size_t) const;
+ size_t countTransportPaddingBytes(const char* bytes, size_t) const;
+ bool parseDelimiter(const char* bytes, size_t, size_t* index);
+ bool parseDelimiterSuffix(const char* bytes, size_t, size_t* index, const char* suffix);
+ size_t seenDelimiterSuffixLength() const;
+
+ Vector<char> m_delimiter;
+ Member<Client> m_client;
+ size_t m_seenDelimiterLength;
+ size_t m_seenDelimiterOffset;
+ Vector<char> m_seenHeaderBytes;
+
+ enum State {
+ ParsingPreamble,
+ ParsingDelimiterSuffix,
+ ParsingPartHeaderFields,
+ ParsingPartOctets,
+ ParsingDelimiterOrCloseDelimiterSuffix,
+ ParsingCloseDelimiterSuffix,
+ ParsingEpilogue,
+ Cancelled,
+ Failed,
+ Finished
+ } m_state;
+};
+
+} // namespace blink
+
+#endif // MultipartParser_h

Powered by Google App Engine
This is Rietveld 408576698