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..fd36846cbb65045947363f31ad1a10b4569005d4 |
--- /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> { |
yhirano
2016/09/21 09:02:58
Can you write some explanation of this class, plea
e_hakkinen
2016/09/22 22:27:16
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: |
+ class Matcher { |
+ public: |
+ Matcher(); |
+ Matcher(const char* data, size_t, size_t capacity); |
+ |
+ bool appendIfExpected(char value); |
yhirano
2016/09/21 09:02:58
Is |match| a better name?
e_hakkinen
2016/09/22 22:27:16
Done.
|
+ bool appendIfExpected(const char* first, const char* last); |
+ bool isComplete() const { return m_size == m_capacity; } |
+ |
+ void clear(); |
+ bool empty() const { return size() == 0u; } |
+ const char* data() const { return m_data; } |
+ size_t size() const { return m_size; } |
yhirano
2016/09/21 09:02:58
Having a more specific name would be better. Maybe
e_hakkinen
2016/09/22 22:27:16
Done.
|
+ |
+ private: |
+ size_t m_capacity = 0u; |
yhirano
2016/09/21 09:02:58
This variable suits with the name "m_size" IMO.
e_hakkinen
2016/09/22 22:27:16
Done. After these changes the class does not look
|
+ const char* m_data = nullptr; |
+ size_t m_size = 0u; |
+ }; |
+ |
+ Matcher closeDelimiterSuffixMatcher() const; |
+ Matcher delimiterMatcher(size_t = 0u) const; |
yhirano
2016/09/21 09:02:58
Is giving the parameter name such as |numAlreadyMa
e_hakkinen
2016/09/22 22:27:16
Done.
|
+ Matcher delimiterSuffixMatcher() const; |
+ |
+ void parseDataAndDelimiter(const char** bytesPointer, const char* bytesEnd); |
+ void parseDelimiter(const char** bytesPointer, const char* bytesEnd); |
+ bool parseHeaderFields(const char** bytesPointer, const char* bytesEnd, WebURLResponse*); |
+ void parseTransportPadding(const char** bytesPointer, const char* bytesEnd) const; |
+ |
+ Matcher m_bufferedBytes; |
yhirano
2016/09/21 09:02:58
m_matcher would be a better name.
e_hakkinen
2016/09/22 22:27:16
Done.
|
+ Vector<char> m_bufferedHeaderBytes; |
+ Member<Client> m_client; |
+ Vector<char> m_delimiter; |
+ |
+ enum State { |
+ ParsingPreamble, |
+ ParsingDelimiterSuffix, |
+ ParsingPartHeaderFields, |
+ ParsingPartOctets, |
+ ParsingDelimiterOrCloseDelimiterSuffix, |
+ ParsingCloseDelimiterSuffix, |
+ ParsingEpilogue, |
+ Cancelled, |
+ Finished |
+ } m_state; |
+}; |
+ |
+} // namespace blink |
+ |
+#endif // MultipartParser_h |