OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/fetch/FormDataBytesConsumer.h" | 5 #include "modules/fetch/FormDataBytesConsumer.h" |
6 | 6 |
7 #include "core/dom/DOMArrayBuffer.h" | 7 #include "core/dom/DOMArrayBuffer.h" |
8 #include "core/dom/DOMArrayBufferView.h" | 8 #include "core/dom/DOMArrayBufferView.h" |
9 #include "modules/fetch/BlobBytesConsumer.h" | 9 #include "modules/fetch/BlobBytesConsumer.h" |
10 #include "platform/blob/BlobData.h" | 10 #include "platform/blob/BlobData.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 for (const auto& element : formData->elements()) { | 22 for (const auto& element : formData->elements()) { |
23 if (element.m_type != FormDataElement::data) | 23 if (element.m_type != FormDataElement::data) |
24 return false; | 24 return false; |
25 } | 25 } |
26 return true; | 26 return true; |
27 } | 27 } |
28 | 28 |
29 class SimpleFormDataBytesConsumer : public BytesConsumer { | 29 class SimpleFormDataBytesConsumer : public BytesConsumer { |
30 public: | 30 public: |
31 explicit SimpleFormDataBytesConsumer(PassRefPtr<EncodedFormData> formData) | 31 explicit SimpleFormDataBytesConsumer(PassRefPtr<EncodedFormData> formData) |
32 : m_formData(formData) {} | 32 : m_formData(std::move(formData)) {} |
33 | 33 |
34 // BytesConsumer implementation | 34 // BytesConsumer implementation |
35 Result beginRead(const char** buffer, size_t* available) override { | 35 Result beginRead(const char** buffer, size_t* available) override { |
36 *buffer = nullptr; | 36 *buffer = nullptr; |
37 *available = 0; | 37 *available = 0; |
38 if (m_formData) { | 38 if (m_formData) { |
39 m_formData->flatten(m_flattenFormData); | 39 m_formData->flatten(m_flattenFormData); |
40 m_formData = nullptr; | 40 m_formData = nullptr; |
41 DCHECK_EQ(m_flattenFormDataOffset, 0u); | 41 DCHECK_EQ(m_flattenFormDataOffset, 0u); |
42 } | 42 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 Vector<char> m_flattenFormData; | 98 Vector<char> m_flattenFormData; |
99 size_t m_flattenFormDataOffset = 0; | 99 size_t m_flattenFormDataOffset = 0; |
100 PublicState m_state = PublicState::ReadableOrWaiting; | 100 PublicState m_state = PublicState::ReadableOrWaiting; |
101 }; | 101 }; |
102 | 102 |
103 class ComplexFormDataBytesConsumer final : public BytesConsumer { | 103 class ComplexFormDataBytesConsumer final : public BytesConsumer { |
104 public: | 104 public: |
105 ComplexFormDataBytesConsumer(ExecutionContext* executionContext, | 105 ComplexFormDataBytesConsumer(ExecutionContext* executionContext, |
106 PassRefPtr<EncodedFormData> formData, | 106 PassRefPtr<EncodedFormData> formData, |
107 BytesConsumer* consumer) | 107 BytesConsumer* consumer) |
108 : m_formData(formData) { | 108 : m_formData(std::move(formData)) { |
109 if (consumer) { | 109 if (consumer) { |
110 // For testing. | 110 // For testing. |
111 m_blobBytesConsumer = consumer; | 111 m_blobBytesConsumer = consumer; |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 std::unique_ptr<BlobData> blobData = BlobData::create(); | 115 std::unique_ptr<BlobData> blobData = BlobData::create(); |
116 for (const auto& element : m_formData->elements()) { | 116 for (const auto& element : m_formData->elements()) { |
117 switch (element.m_type) { | 117 switch (element.m_type) { |
118 case FormDataElement::data: | 118 case FormDataElement::data: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 BytesConsumer* consumer) | 220 BytesConsumer* consumer) |
221 : m_impl(isSimple(formData.get()) | 221 : m_impl(isSimple(formData.get()) |
222 ? static_cast<BytesConsumer*>( | 222 ? static_cast<BytesConsumer*>( |
223 new SimpleFormDataBytesConsumer(std::move(formData))) | 223 new SimpleFormDataBytesConsumer(std::move(formData))) |
224 : static_cast<BytesConsumer*>( | 224 : static_cast<BytesConsumer*>( |
225 new ComplexFormDataBytesConsumer(executionContext, | 225 new ComplexFormDataBytesConsumer(executionContext, |
226 std::move(formData), | 226 std::move(formData), |
227 consumer))) {} | 227 consumer))) {} |
228 | 228 |
229 } // namespace blink | 229 } // namespace blink |
OLD | NEW |