OLD | NEW |
| (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 /* ***** BEGIN LICENSE BLOCK ***** | |
6 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
7 * | |
8 * The contents of this file are subject to the Mozilla Public License Version | |
9 * 1.1 (the "License"); you may not use this file except in compliance with | |
10 * the License. You may obtain a copy of the License at | |
11 * http://www.mozilla.org/MPL/ | |
12 * | |
13 * Software distributed under the License is distributed on an "AS IS" basis, | |
14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
15 * for the specific language governing rights and limitations under the | |
16 * License. | |
17 * | |
18 * The Original Code is mozilla.org code. | |
19 * | |
20 * The Initial Developer of the Original Code is | |
21 * Netscape Communications Corporation. | |
22 * Portions created by the Initial Developer are Copyright (C) 1998 | |
23 * the Initial Developer. All Rights Reserved. | |
24 * | |
25 * Contributor(s): | |
26 * | |
27 * Alternatively, the contents of this file may be used under the terms of | |
28 * either the GNU General Public License Version 2 or later (the "GPL"), or | |
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
30 * in which case the provisions of the GPL or the LGPL are applicable instead | |
31 * of those above. If you wish to allow use of your version of this file only | |
32 * under the terms of either the GPL or the LGPL, and not to allow others to | |
33 * use your version of this file under the terms of the MPL, indicate your | |
34 * decision by deleting the provisions above and replace them with the notice | |
35 * and other provisions required by the GPL or the LGPL. If you do not delete | |
36 * the provisions above, a recipient may use your version of this file under | |
37 * the terms of any one of the MPL, the GPL or the LGPL. | |
38 * | |
39 * ***** END LICENSE BLOCK ***** */ | |
40 | |
41 #ifndef MultipartImageResourceParser_h | |
42 #define MultipartImageResourceParser_h | |
43 | |
44 #include "core/CoreExport.h" | |
45 #include "platform/heap/Handle.h" | |
46 #include "platform/network/ResourceResponse.h" | |
47 #include "wtf/Vector.h" | |
48 | |
49 namespace blink { | |
50 | |
51 // A parser parsing mlutipart/x-mixed-replace resource. | |
52 class CORE_EXPORT MultipartImageResourceParser final | |
53 : public GarbageCollectedFinalized<MultipartImageResourceParser> { | |
54 WTF_MAKE_NONCOPYABLE(MultipartImageResourceParser); | |
55 | |
56 public: | |
57 class CORE_EXPORT Client : public GarbageCollectedMixin { | |
58 public: | |
59 virtual ~Client() = default; | |
60 virtual void onePartInMultipartReceived(const ResourceResponse&) = 0; | |
61 virtual void multipartDataReceived(const char* bytes, size_t) = 0; | |
62 DEFINE_INLINE_VIRTUAL_TRACE() {} | |
63 }; | |
64 | |
65 MultipartImageResourceParser(const ResourceResponse&, | |
66 const Vector<char>& boundary, | |
67 Client*); | |
68 void appendData(const char* bytes, size_t); | |
69 void finish(); | |
70 void cancel() { m_isCancelled = true; } | |
71 | |
72 DECLARE_TRACE(); | |
73 | |
74 static size_t skippableLengthForTest(const Vector<char>& data, size_t size) { | |
75 return skippableLength(data, size); | |
76 } | |
77 static size_t findBoundaryForTest(const Vector<char>& data, | |
78 Vector<char>* boundary) { | |
79 return findBoundary(data, boundary); | |
80 } | |
81 | |
82 private: | |
83 bool parseHeaders(); | |
84 bool isCancelled() const { return m_isCancelled; } | |
85 static size_t skippableLength(const Vector<char>&, size_t); | |
86 // This function updates |*boundary|. | |
87 static size_t findBoundary(const Vector<char>& data, Vector<char>* boundary); | |
88 | |
89 const ResourceResponse m_originalResponse; | |
90 Vector<char> m_boundary; | |
91 Member<Client> m_client; | |
92 | |
93 Vector<char> m_data; | |
94 bool m_isParsingTop = true; | |
95 bool m_isParsingHeaders = false; | |
96 bool m_sawLastBoundary = false; | |
97 bool m_isCancelled = false; | |
98 }; | |
99 | |
100 } // namespace blink | |
101 | |
102 #endif // MultipartImageResourceParser_h | |
OLD | NEW |