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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/MultipartParser.h

Issue 2292763002: [Fetch API] Implement Request.formData and Response.formData. (Closed)
Patch Set: Parse functions etc 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MultipartParser_h
6 #define MultipartParser_h
7
8 #include "modules/ModulesExport.h"
9 #include "platform/heap/Handle.h"
10 #include "platform/network/ResourceResponse.h"
11 #include "wtf/Vector.h"
12
13 namespace blink {
14
15 class MODULES_EXPORT MultipartParser final : public GarbageCollectedFinalized<Mu ltipartParser> {
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.
16 WTF_MAKE_NONCOPYABLE(MultipartParser);
17
18 public:
19 class MODULES_EXPORT Client : public GarbageCollectedMixin {
20 public:
21 virtual ~Client() = default;
22 virtual void partHeaderFieldsInMultipartReceived(const ResourceResponse& ) = 0;
23 virtual void partDataInMultipartReceived(const char* bytes, size_t) = 0;
24 virtual void partDataInMultipartFullyReceived() = 0;
25 DEFINE_INLINE_VIRTUAL_TRACE() {}
26 };
27
28 MultipartParser(Vector<char> boundary, Client*);
29 bool appendData(const char* bytes, size_t);
30 void cancel();
31 bool finish();
32
33 bool isCancelled() const { return m_state == Cancelled; }
34
35 DECLARE_TRACE();
36
37 private:
38 class Matcher {
39 public:
40 Matcher();
41 Matcher(const char* data, size_t, size_t capacity);
42
43 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.
44 bool appendIfExpected(const char* first, const char* last);
45 bool isComplete() const { return m_size == m_capacity; }
46
47 void clear();
48 bool empty() const { return size() == 0u; }
49 const char* data() const { return m_data; }
50 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.
51
52 private:
53 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
54 const char* m_data = nullptr;
55 size_t m_size = 0u;
56 };
57
58 Matcher closeDelimiterSuffixMatcher() const;
59 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.
60 Matcher delimiterSuffixMatcher() const;
61
62 void parseDataAndDelimiter(const char** bytesPointer, const char* bytesEnd);
63 void parseDelimiter(const char** bytesPointer, const char* bytesEnd);
64 bool parseHeaderFields(const char** bytesPointer, const char* bytesEnd, WebU RLResponse*);
65 void parseTransportPadding(const char** bytesPointer, const char* bytesEnd) const;
66
67 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.
68 Vector<char> m_bufferedHeaderBytes;
69 Member<Client> m_client;
70 Vector<char> m_delimiter;
71
72 enum State {
73 ParsingPreamble,
74 ParsingDelimiterSuffix,
75 ParsingPartHeaderFields,
76 ParsingPartOctets,
77 ParsingDelimiterOrCloseDelimiterSuffix,
78 ParsingCloseDelimiterSuffix,
79 ParsingEpilogue,
80 Cancelled,
81 Finished
82 } m_state;
83 };
84
85 } // namespace blink
86
87 #endif // MultipartParser_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698