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

Side by Side Diff: third_party/WebKit/Source/core/loader/resource/MultipartImageResourceParser.cpp

Issue 2776203002: Migrate WTF::Vector::remove() to ::erase() (Closed)
Patch Set: rebase, repatch VectorTest Created 3 years, 8 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
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/loader/resource/MultipartImageResourceParser.h" 5 #include "core/loader/resource/MultipartImageResourceParser.h"
6 6
7 #include "platform/network/HTTPParsers.h" 7 #include "platform/network/HTTPParsers.h"
8 #include "wtf/NotFound.h" 8 #include "wtf/NotFound.h"
9 #include "wtf/text/WTFString.h" 9 #include "wtf/text/WTFString.h"
10 10
(...skipping 24 matching lines...) Expand all
35 if (m_isParsingTop) { 35 if (m_isParsingTop) {
36 // Eat leading \r\n 36 // Eat leading \r\n
37 size_t pos = skippableLength(m_data, 0); 37 size_t pos = skippableLength(m_data, 0);
38 // +2 for "--" 38 // +2 for "--"
39 if (m_data.size() < m_boundary.size() + 2 + pos) { 39 if (m_data.size() < m_boundary.size() + 2 + pos) {
40 // We don't have enough data yet to make a boundary token. Just wait 40 // We don't have enough data yet to make a boundary token. Just wait
41 // until the next chunk of data arrives. 41 // until the next chunk of data arrives.
42 return; 42 return;
43 } 43 }
44 if (pos) 44 if (pos)
45 m_data.remove(0, pos); 45 m_data.erase(0, pos);
46 46
47 // Some servers don't send a boundary token before the first chunk of 47 // Some servers don't send a boundary token before the first chunk of
48 // data. We handle this case anyway (Gecko does too). 48 // data. We handle this case anyway (Gecko does too).
49 if (0 != memcmp(m_data.data(), m_boundary.data(), m_boundary.size())) { 49 if (0 != memcmp(m_data.data(), m_boundary.data(), m_boundary.size())) {
50 m_data.push_front("\n", 1); 50 m_data.push_front("\n", 1);
51 m_data.prependVector(m_boundary); 51 m_data.prependVector(m_boundary);
52 } 52 }
53 m_isParsingTop = false; 53 m_isParsingTop = false;
54 } 54 }
55 55
(...skipping 28 matching lines...) Expand all
84 size_t boundaryEndPosition = boundaryPosition + m_boundary.size(); 84 size_t boundaryEndPosition = boundaryPosition + m_boundary.size();
85 if (boundaryEndPosition < m_data.size() && 85 if (boundaryEndPosition < m_data.size() &&
86 '-' == m_data[boundaryEndPosition]) { 86 '-' == m_data[boundaryEndPosition]) {
87 // This was the last boundary so we can stop processing. 87 // This was the last boundary so we can stop processing.
88 m_sawLastBoundary = true; 88 m_sawLastBoundary = true;
89 m_data.clear(); 89 m_data.clear();
90 return; 90 return;
91 } 91 }
92 92
93 // We can now throw out data up through the boundary 93 // We can now throw out data up through the boundary
94 m_data.remove(0, boundaryEndPosition); 94 m_data.erase(0, boundaryEndPosition);
95 95
96 // Ok, back to parsing headers 96 // Ok, back to parsing headers
97 if (!parseHeaders()) { 97 if (!parseHeaders()) {
98 m_isParsingHeaders = true; 98 m_isParsingHeaders = true;
99 break; 99 break;
100 } 100 }
101 if (isCancelled()) 101 if (isCancelled())
102 return; 102 return;
103 } 103 }
104 104
105 // At this point, we should send over any data we have, but keep enough data 105 // At this point, we should send over any data we have, but keep enough data
106 // buffered to handle a boundary that may have been truncated. "+2" for CRLF, 106 // buffered to handle a boundary that may have been truncated. "+2" for CRLF,
107 // as we may ignore the last CRLF. 107 // as we may ignore the last CRLF.
108 if (!m_isParsingHeaders && m_data.size() > m_boundary.size() + 2) { 108 if (!m_isParsingHeaders && m_data.size() > m_boundary.size() + 2) {
109 size_t sendLength = m_data.size() - m_boundary.size() - 2; 109 size_t sendLength = m_data.size() - m_boundary.size() - 2;
110 m_client->multipartDataReceived(m_data.data(), sendLength); 110 m_client->multipartDataReceived(m_data.data(), sendLength);
111 m_data.remove(0, sendLength); 111 m_data.erase(0, sendLength);
112 } 112 }
113 } 113 }
114 114
115 void MultipartImageResourceParser::finish() { 115 void MultipartImageResourceParser::finish() {
116 DCHECK(!isCancelled()); 116 DCHECK(!isCancelled());
117 if (m_sawLastBoundary) 117 if (m_sawLastBoundary)
118 return; 118 return;
119 // If we have any pending data and we're not in a header, go ahead and send 119 // If we have any pending data and we're not in a header, go ahead and send
120 // it to the client. 120 // it to the client.
121 if (!m_isParsingHeaders && !m_data.isEmpty()) 121 if (!m_isParsingHeaders && !m_data.isEmpty())
(...skipping 20 matching lines...) Expand all
142 // See netwerk/streamconv/converters/nsMultiMixedConv.cpp. 142 // See netwerk/streamconv/converters/nsMultiMixedConv.cpp.
143 ResourceResponse response; 143 ResourceResponse response;
144 response.setURL(m_originalResponse.url()); 144 response.setURL(m_originalResponse.url());
145 for (const auto& header : m_originalResponse.httpHeaderFields()) 145 for (const auto& header : m_originalResponse.httpHeaderFields())
146 response.addHTTPHeaderField(header.key, header.value); 146 response.addHTTPHeaderField(header.key, header.value);
147 147
148 size_t end = 0; 148 size_t end = 0;
149 if (!parseMultipartHeadersFromBody(m_data.data() + pos, m_data.size() - pos, 149 if (!parseMultipartHeadersFromBody(m_data.data() + pos, m_data.size() - pos,
150 &response, &end)) 150 &response, &end))
151 return false; 151 return false;
152 m_data.remove(0, end + pos); 152 m_data.erase(0, end + pos);
153 // Send the response! 153 // Send the response!
154 m_client->onePartInMultipartReceived(response); 154 m_client->onePartInMultipartReceived(response);
155 return true; 155 return true;
156 } 156 }
157 157
158 // Boundaries are supposed to be preceeded with --, but it looks like gecko 158 // Boundaries are supposed to be preceeded with --, but it looks like gecko
159 // doesn't require the dashes to exist. See nsMultiMixedConv::FindToken. 159 // doesn't require the dashes to exist. See nsMultiMixedConv::FindToken.
160 size_t MultipartImageResourceParser::findBoundary(const Vector<char>& data, 160 size_t MultipartImageResourceParser::findBoundary(const Vector<char>& data,
161 Vector<char>* boundary) { 161 Vector<char>* boundary) {
162 auto it = std::search(data.data(), data.data() + data.size(), 162 auto it = std::search(data.data(), data.data() + data.size(),
(...skipping 15 matching lines...) Expand all
178 } 178 }
179 } 179 }
180 return boundaryPosition; 180 return boundaryPosition;
181 } 181 }
182 182
183 DEFINE_TRACE(MultipartImageResourceParser) { 183 DEFINE_TRACE(MultipartImageResourceParser) {
184 visitor->trace(m_client); 184 visitor->trace(m_client);
185 } 185 }
186 186
187 } // namespace blink 187 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698