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

Side by Side Diff: webkit/glue/multipart_response_delegate.cc

Issue 295041: DevTools: report correct content length for resources (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "webkit/glue/multipart_response_delegate.h" 5 #include "webkit/glue/multipart_response_delegate.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "net/base/net_util.h" 9 #include "net/base/net_util.h"
10 #include "webkit/api/public/WebHTTPHeaderVisitor.h" 10 #include "webkit/api/public/WebHTTPHeaderVisitor.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 void MultipartResponseDelegate::OnReceivedData(const char* data, 76 void MultipartResponseDelegate::OnReceivedData(const char* data,
77 int data_len) { 77 int data_len) {
78 // stop_sending_ means that we've already received the final boundary token. 78 // stop_sending_ means that we've already received the final boundary token.
79 // The server should stop sending us data at this point, but if it does, we 79 // The server should stop sending us data at this point, but if it does, we
80 // just throw it away. 80 // just throw it away.
81 if (stop_sending_) 81 if (stop_sending_)
82 return; 82 return;
83 83
84 // TODO(tc): Figure out what to use for length_received. Maybe we can just
85 // pass the value on from our caller.
86 int length_received = -1;
87
88 data_.append(data, data_len); 84 data_.append(data, data_len);
89 if (first_received_data_) { 85 if (first_received_data_) {
90 // Some servers don't send a boundary token before the first chunk of 86 // Some servers don't send a boundary token before the first chunk of
91 // data. We handle this case anyway (Gecko does too). 87 // data. We handle this case anyway (Gecko does too).
92 first_received_data_ = false; 88 first_received_data_ = false;
93 89
94 // Eat leading \r\n 90 // Eat leading \r\n
95 int pos = PushOverLine(data_, 0); 91 int pos = PushOverLine(data_, 0);
96 if (pos) 92 if (pos)
97 data_ = data_.substr(pos); 93 data_ = data_.substr(pos);
(...skipping 27 matching lines...) Expand all
125 } 121 }
126 } 122 }
127 DCHECK(!processing_headers_); 123 DCHECK(!processing_headers_);
128 124
129 size_t boundary_pos; 125 size_t boundary_pos;
130 while ((boundary_pos = FindBoundary()) != std::string::npos) { 126 while ((boundary_pos = FindBoundary()) != std::string::npos) {
131 if (boundary_pos > 0) { 127 if (boundary_pos > 0) {
132 // Send the last data chunk. 128 // Send the last data chunk.
133 client_->didReceiveData(loader_, 129 client_->didReceiveData(loader_,
134 data_.data(), 130 data_.data(),
135 static_cast<int>(boundary_pos), 131 static_cast<int>(boundary_pos));
136 length_received);
137 } 132 }
138 size_t boundary_end_pos = boundary_pos + boundary_.length(); 133 size_t boundary_end_pos = boundary_pos + boundary_.length();
139 if (boundary_end_pos < data_.length() && '-' == data_[boundary_end_pos]) { 134 if (boundary_end_pos < data_.length() && '-' == data_[boundary_end_pos]) {
140 // This was the last boundary so we can stop processing. 135 // This was the last boundary so we can stop processing.
141 stop_sending_ = true; 136 stop_sending_ = true;
142 data_.clear(); 137 data_.clear();
143 return; 138 return;
144 } 139 }
145 140
146 // We can now throw out data up through the boundary 141 // We can now throw out data up through the boundary
147 int offset = PushOverLine(data_, boundary_end_pos); 142 int offset = PushOverLine(data_, boundary_end_pos);
148 data_ = data_.substr(boundary_end_pos + offset); 143 data_ = data_.substr(boundary_end_pos + offset);
149 144
150 // Ok, back to parsing headers 145 // Ok, back to parsing headers
151 if (!ParseHeaders()) { 146 if (!ParseHeaders()) {
152 processing_headers_ = true; 147 processing_headers_ = true;
153 break; 148 break;
154 } 149 }
155 } 150 }
156 } 151 }
157 152
158 void MultipartResponseDelegate::OnCompletedRequest() { 153 void MultipartResponseDelegate::OnCompletedRequest() {
159 // If we have any pending data and we're not in a header, go ahead and send 154 // If we have any pending data and we're not in a header, go ahead and send
160 // it to WebCore. 155 // it to WebCore.
161 if (!processing_headers_ && !data_.empty()) { 156 if (!processing_headers_ && !data_.empty()) {
162 // TODO(tc): Figure out what to use for length_received. Maybe we can just
163 // pass the value on from our caller.
164 int length_received = -1;
165 client_->didReceiveData(loader_, 157 client_->didReceiveData(loader_,
166 data_.data(), 158 data_.data(),
167 static_cast<int>(data_.length()), 159 static_cast<int>(data_.length()));
168 length_received);
169 } 160 }
170 } 161 }
171 162
172 int MultipartResponseDelegate::PushOverLine(const std::string& data, 163 int MultipartResponseDelegate::PushOverLine(const std::string& data,
173 size_t pos) { 164 size_t pos) {
174 int offset = 0; 165 int offset = 0;
175 if (pos < data.length() && (data[pos] == '\r' || data[pos] == '\n')) { 166 if (pos < data.length() && (data[pos] == '\r' || data[pos] == '\n')) {
176 ++offset; 167 ++offset;
177 if (pos + 1 < data.length() && data[pos + 1] == '\n') 168 if (pos + 1 < data.length() && data[pos + 1] == '\n')
178 ++offset; 169 ++offset;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 byte_range_upper_bound_characters); 321 byte_range_upper_bound_characters);
331 322
332 if (!StringToInt(byte_range_lower_bound, content_range_lower_bound)) 323 if (!StringToInt(byte_range_lower_bound, content_range_lower_bound))
333 return false; 324 return false;
334 if (!StringToInt(byte_range_upper_bound, content_range_upper_bound)) 325 if (!StringToInt(byte_range_upper_bound, content_range_upper_bound))
335 return false; 326 return false;
336 return true; 327 return true;
337 } 328 }
338 329
339 } // namespace webkit_glue 330 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/ftp_directory_listing_response_delegate.cc ('k') | webkit/glue/multipart_response_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698