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..54c216e3ba7bf1012611e3e988cb766082f89c40 |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/fetch/MultipartParser.h |
@@ -0,0 +1,87 @@ |
+// 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 final : public GarbageCollectedFinalized<MultipartParser> { |
+ 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: |
+ class Buffer { |
yhirano
2016/09/20 09:49:53
This class is used in a two ways:
1. It is a matc
e_hakkinen
2016/09/20 21:59:29
Done.
|
+ public: |
+ Buffer(); |
+ Buffer(const char* first, const char* last); |
+ Buffer(const char* data, size_t, size_t capacity); |
+ |
+ bool appendIfExpected(char value); |
+ bool appendIfExpected(const char* first, const char* last); |
+ void clear(); |
+ |
+ bool empty() const { return size() == 0u; } |
+ const char* data() const { return m_data; } |
+ size_t size() const { return m_size; } |
+ |
+ private: |
+ size_t m_capacity = 0u; |
+ const char* m_data = nullptr; |
+ size_t m_size = 0u; |
+ }; |
+ |
+ Buffer closeDelimiterSuffixBuffer(size_t = 0u) const; |
yhirano
2016/09/20 09:49:53
The parameter is never specified.
e_hakkinen
2016/09/20 21:59:29
Done.
|
+ Buffer delimiterBuffer(size_t = 0u) const; |
+ Buffer delimiterSuffixBuffer(size_t = 0u) const; |
yhirano
2016/09/20 09:49:53
The parameter is never specified.
e_hakkinen
2016/09/20 21:59:29
Done.
|
+ |
+ bool parseDataAndDelimiter(const char** bytesPointer, const char* bytesEnd, Buffer* data); |
yhirano
2016/09/20 09:49:53
These three functions are named in the same manner
e_hakkinen
2016/09/20 21:59:29
They return true only when they have parsed what t
|
+ bool parseHeaderFields(const char** bytesPointer, const char* bytesEnd, WebURLResponse*); |
+ bool parseTransportPadding(const char** bytesPointer, const char* bytesEnd) const; |
+ |
+ Buffer m_bufferedBytes; |
+ Vector<char> m_bufferedHeaderBytes; |
+ Member<Client> m_client; |
+ Vector<char> m_delimiter; |
+ |
+ enum State { |
+ ParsingPreamble, |
+ ParsingDelimiterSuffix, |
+ ParsingPartHeaderFields, |
+ ParsingPartOctets, |
+ ParsingDelimiterOrCloseDelimiterSuffix, |
+ ParsingCloseDelimiterSuffix, |
+ ParsingEpilogue, |
+ Cancelled, |
+ Failed, |
+ Finished |
+ } m_state; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // MultipartParser_h |