OLD | NEW |
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_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/net_util.h" | 10 #include "net/base/net_util.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // The byte range response can have quoted boundary strings. This is legal | 309 // The byte range response can have quoted boundary strings. This is legal |
310 // as per MIME specifications. Individual data fragements however don't | 310 // as per MIME specifications. Individual data fragements however don't |
311 // contain quoted boundary strings. | 311 // contain quoted boundary strings. |
312 TrimString(*multipart_boundary, "\"", multipart_boundary); | 312 TrimString(*multipart_boundary, "\"", multipart_boundary); |
313 return true; | 313 return true; |
314 } | 314 } |
315 | 315 |
316 bool MultipartResponseDelegate::ReadContentRanges( | 316 bool MultipartResponseDelegate::ReadContentRanges( |
317 const WebURLResponse& response, | 317 const WebURLResponse& response, |
318 int* content_range_lower_bound, | 318 int* content_range_lower_bound, |
319 int* content_range_upper_bound) { | 319 int* content_range_upper_bound, |
| 320 int* content_range_instance_size) { |
320 | 321 |
321 std::string content_range = response.httpHeaderField("Content-Range").utf8(); | 322 std::string content_range = response.httpHeaderField("Content-Range").utf8(); |
322 if (content_range.empty()) { | 323 if (content_range.empty()) { |
323 content_range = response.httpHeaderField("Range").utf8(); | 324 content_range = response.httpHeaderField("Range").utf8(); |
324 } | 325 } |
325 | 326 |
326 if (content_range.empty()) { | 327 if (content_range.empty()) { |
327 DLOG(WARNING) << "Failed to read content range from response."; | 328 DLOG(WARNING) << "Failed to read content range from response."; |
328 return false; | 329 return false; |
329 } | 330 } |
330 | 331 |
331 size_t byte_range_lower_bound_start_offset = content_range.find(" "); | 332 size_t byte_range_lower_bound_start_offset = content_range.find(" "); |
332 if (byte_range_lower_bound_start_offset == std::string::npos) { | 333 if (byte_range_lower_bound_start_offset == std::string::npos) { |
333 return false; | 334 return false; |
334 } | 335 } |
335 | 336 |
336 // Skip over the initial space. | 337 // Skip over the initial space. |
337 byte_range_lower_bound_start_offset++; | 338 byte_range_lower_bound_start_offset++; |
338 | 339 |
| 340 // Find the lower bound. |
339 size_t byte_range_lower_bound_end_offset = | 341 size_t byte_range_lower_bound_end_offset = |
340 content_range.find("-", byte_range_lower_bound_start_offset); | 342 content_range.find("-", byte_range_lower_bound_start_offset); |
341 if (byte_range_lower_bound_end_offset == std::string::npos) { | 343 if (byte_range_lower_bound_end_offset == std::string::npos) { |
342 return false; | 344 return false; |
343 } | 345 } |
344 | 346 |
| 347 size_t byte_range_lower_bound_characters = |
| 348 byte_range_lower_bound_end_offset - byte_range_lower_bound_start_offset; |
| 349 std::string byte_range_lower_bound = |
| 350 content_range.substr(byte_range_lower_bound_start_offset, |
| 351 byte_range_lower_bound_characters); |
| 352 |
| 353 // Find the upper bound. |
345 size_t byte_range_upper_bound_start_offset = | 354 size_t byte_range_upper_bound_start_offset = |
346 byte_range_lower_bound_end_offset + 1; | 355 byte_range_lower_bound_end_offset + 1; |
347 | 356 |
348 size_t byte_range_upper_bound_end_offset = | 357 size_t byte_range_upper_bound_end_offset = |
349 content_range.find("/", byte_range_upper_bound_start_offset); | 358 content_range.find("/", byte_range_upper_bound_start_offset); |
350 if (byte_range_upper_bound_end_offset == std::string::npos) { | 359 if (byte_range_upper_bound_end_offset == std::string::npos) { |
351 return false; | 360 return false; |
352 } | 361 } |
353 | 362 |
354 if (!base::StringToInt( | 363 size_t byte_range_upper_bound_characters = |
355 content_range.begin() + byte_range_lower_bound_start_offset, | 364 byte_range_upper_bound_end_offset - byte_range_upper_bound_start_offset; |
356 content_range.begin() + byte_range_lower_bound_end_offset, | 365 std::string byte_range_upper_bound = |
357 content_range_lower_bound)) | 366 content_range.substr(byte_range_upper_bound_start_offset, |
| 367 byte_range_upper_bound_characters); |
| 368 |
| 369 // Find the instance size. |
| 370 size_t byte_range_instance_size_start_offset = |
| 371 byte_range_upper_bound_end_offset + 1; |
| 372 |
| 373 size_t byte_range_instance_size_end_offset = |
| 374 content_range.length(); |
| 375 |
| 376 size_t byte_range_instance_size_characters = |
| 377 byte_range_instance_size_end_offset - |
| 378 byte_range_instance_size_start_offset; |
| 379 std::string byte_range_instance_size = |
| 380 content_range.substr(byte_range_instance_size_start_offset, |
| 381 byte_range_instance_size_characters); |
| 382 |
| 383 if (!base::StringToInt(byte_range_lower_bound, content_range_lower_bound)) |
358 return false; | 384 return false; |
359 | 385 if (!base::StringToInt(byte_range_upper_bound, content_range_upper_bound)) |
360 if (!base::StringToInt( | 386 return false; |
361 content_range.begin() + byte_range_upper_bound_start_offset, | 387 if (!base::StringToInt(byte_range_instance_size, content_range_instance_size)) |
362 content_range.begin() + byte_range_upper_bound_end_offset, | |
363 content_range_upper_bound)) | |
364 return false; | 388 return false; |
365 return true; | 389 return true; |
366 } | 390 } |
367 | 391 |
368 } // namespace webkit_glue | 392 } // namespace webkit_glue |
OLD | NEW |