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 "core/fetch/MultipartImageResourceParser.h" | 5 #include "core/fetch/MultipartImageResourceParser.h" |
6 | 6 |
7 #include "public/platform/Platform.h" | 7 #include "public/platform/Platform.h" |
8 #include "public/platform/WebURLResponse.h" | 8 #include "public/platform/WebURLResponse.h" |
9 #include "wtf/NotFound.h" | 9 #include "wtf/NotFound.h" |
10 #include "wtf/text/WTFString.h" | 10 #include "wtf/text/WTFString.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 // We can now throw out data up through the boundary | 101 // We can now throw out data up through the boundary |
102 int offset = pushOverLine(m_data, boundaryEndPosition); | 102 int offset = pushOverLine(m_data, boundaryEndPosition); |
103 m_data.remove(0, boundaryEndPosition + offset); | 103 m_data.remove(0, boundaryEndPosition + offset); |
104 | 104 |
105 // Ok, back to parsing headers | 105 // Ok, back to parsing headers |
106 if (!parseHeaders()) { | 106 if (!parseHeaders()) { |
107 m_isParsingHeaders = true; | 107 m_isParsingHeaders = true; |
108 break; | 108 break; |
109 } | 109 } |
| 110 if (isCancelled()) |
| 111 return; |
110 } | 112 } |
111 | 113 |
112 // At this point, we should send over any data we have, but keep enough data | 114 // At this point, we should send over any data we have, but keep enough data |
113 // buffered to handle a boundary that may have been truncated. | 115 // buffered to handle a boundary that may have been truncated. |
114 if (!m_isParsingHeaders && m_data.size() > m_boundary.size()) { | 116 if (!m_isParsingHeaders && m_data.size() > m_boundary.size()) { |
115 // If the last character is a new line character, go ahead and just send | 117 // If the last character is a new line character, go ahead and just send |
116 // everything we have buffered. This matches an optimization in Gecko. | 118 // everything we have buffered. This matches an optimization in Gecko. |
117 size_t sendLength = m_data.size() - m_boundary.size(); | 119 size_t sendLength = m_data.size() - m_boundary.size(); |
118 if (m_data.last() == '\n') | 120 if (m_data.last() == '\n') |
119 sendLength = m_data.size(); | 121 sendLength = m_data.size(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // does. See netwerk/streamconv/converters/nsMultiMixedConv.cpp. | 153 // does. See netwerk/streamconv/converters/nsMultiMixedConv.cpp. |
152 WebURLResponse response(m_originalResponse.url()); | 154 WebURLResponse response(m_originalResponse.url()); |
153 for (const auto& header : m_originalResponse.httpHeaderFields()) | 155 for (const auto& header : m_originalResponse.httpHeaderFields()) |
154 response.addHTTPHeaderField(header.key, header.value); | 156 response.addHTTPHeaderField(header.key, header.value); |
155 | 157 |
156 size_t end = 0; | 158 size_t end = 0; |
157 if (!Platform::current()->parseMultipartHeadersFromBody(m_data.data(), m_dat
a.size(), &response, &end)) | 159 if (!Platform::current()->parseMultipartHeadersFromBody(m_data.data(), m_dat
a.size(), &response, &end)) |
158 return false; | 160 return false; |
159 m_data.remove(0, end); | 161 m_data.remove(0, end); |
160 | 162 |
161 // To avoid recording every multipart load as a separate visit in | 163 bool isFirstPart = m_isFirstPart; |
162 // the history database, we want to keep track of whether the response | |
163 // is part of a multipart payload. We do want to record the first visit, | |
164 // so we only set isMultipartPayload to true after the first visit. | |
165 response.setIsMultipartPayload(!m_isFirstPart); | |
166 m_isFirstPart = false; | 164 m_isFirstPart = false; |
167 // Send the response! | 165 // Send the response! |
168 m_client->onePartInMultipartReceived(response.toResourceResponse()); | 166 m_client->onePartInMultipartReceived(response.toResourceResponse(), isFirstP
art); |
169 | 167 |
170 return true; | 168 return true; |
171 } | 169 } |
172 | 170 |
173 // Boundaries are supposed to be preceeded with --, but it looks like gecko | 171 // Boundaries are supposed to be preceeded with --, but it looks like gecko |
174 // doesn't require the dashes to exist. See nsMultiMixedConv::FindToken. | 172 // doesn't require the dashes to exist. See nsMultiMixedConv::FindToken. |
175 size_t MultipartImageResourceParser::findBoundary(const Vector<char>& data, Vect
or<char>* boundary) | 173 size_t MultipartImageResourceParser::findBoundary(const Vector<char>& data, Vect
or<char>* boundary) |
176 { | 174 { |
177 auto it = std::search(data.data(), data.data() + data.size(), boundary->data
(), boundary->data() + boundary->size()); | 175 auto it = std::search(data.data(), data.data() + data.size(), boundary->data
(), boundary->data() + boundary->size()); |
178 if (it == data.data() + data.size()) | 176 if (it == data.data() + data.size()) |
(...skipping 13 matching lines...) Expand all Loading... |
192 } | 190 } |
193 return boundaryPosition; | 191 return boundaryPosition; |
194 } | 192 } |
195 | 193 |
196 DEFINE_TRACE(MultipartImageResourceParser) | 194 DEFINE_TRACE(MultipartImageResourceParser) |
197 { | 195 { |
198 visitor->trace(m_client); | 196 visitor->trace(m_client); |
199 } | 197 } |
200 | 198 |
201 } // namespace blink | 199 } // namespace blink |
OLD | NEW |