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) { | |
321 | 320 |
322 std::string content_range = response.httpHeaderField("Content-Range").utf8(); | 321 std::string content_range = response.httpHeaderField("Content-Range").utf8(); |
323 if (content_range.empty()) { | 322 if (content_range.empty()) { |
324 content_range = response.httpHeaderField("Range").utf8(); | 323 content_range = response.httpHeaderField("Range").utf8(); |
325 } | 324 } |
326 | 325 |
327 if (content_range.empty()) { | 326 if (content_range.empty()) { |
328 DLOG(WARNING) << "Failed to read content range from response."; | 327 DLOG(WARNING) << "Failed to read content range from response."; |
329 return false; | 328 return false; |
330 } | 329 } |
331 | 330 |
332 size_t byte_range_lower_bound_start_offset = content_range.find(" "); | 331 size_t byte_range_lower_bound_start_offset = content_range.find(" "); |
333 if (byte_range_lower_bound_start_offset == std::string::npos) { | 332 if (byte_range_lower_bound_start_offset == std::string::npos) { |
334 return false; | 333 return false; |
335 } | 334 } |
336 | 335 |
337 // Skip over the initial space. | 336 // Skip over the initial space. |
338 byte_range_lower_bound_start_offset++; | 337 byte_range_lower_bound_start_offset++; |
339 | 338 |
340 // Find the lower bound. | |
341 size_t byte_range_lower_bound_end_offset = | 339 size_t byte_range_lower_bound_end_offset = |
342 content_range.find("-", byte_range_lower_bound_start_offset); | 340 content_range.find("-", byte_range_lower_bound_start_offset); |
343 if (byte_range_lower_bound_end_offset == std::string::npos) { | 341 if (byte_range_lower_bound_end_offset == std::string::npos) { |
344 return false; | 342 return false; |
345 } | 343 } |
346 | 344 |
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. | |
354 size_t byte_range_upper_bound_start_offset = | 345 size_t byte_range_upper_bound_start_offset = |
355 byte_range_lower_bound_end_offset + 1; | 346 byte_range_lower_bound_end_offset + 1; |
356 | 347 |
357 size_t byte_range_upper_bound_end_offset = | 348 size_t byte_range_upper_bound_end_offset = |
358 content_range.find("/", byte_range_upper_bound_start_offset); | 349 content_range.find("/", byte_range_upper_bound_start_offset); |
359 if (byte_range_upper_bound_end_offset == std::string::npos) { | 350 if (byte_range_upper_bound_end_offset == std::string::npos) { |
360 return false; | 351 return false; |
361 } | 352 } |
362 | 353 |
363 size_t byte_range_upper_bound_characters = | 354 if (!base::StringToInt( |
364 byte_range_upper_bound_end_offset - byte_range_upper_bound_start_offset; | 355 content_range.begin() + byte_range_lower_bound_start_offset, |
365 std::string byte_range_upper_bound = | 356 content_range.begin() + byte_range_lower_bound_end_offset, |
366 content_range.substr(byte_range_upper_bound_start_offset, | 357 content_range_lower_bound)) |
367 byte_range_upper_bound_characters); | 358 return false; |
368 | 359 |
369 // Find the instance size. | 360 if (!base::StringToInt( |
370 size_t byte_range_instance_size_start_offset = | 361 content_range.begin() + byte_range_upper_bound_start_offset, |
371 byte_range_upper_bound_end_offset + 1; | 362 content_range.begin() + byte_range_upper_bound_end_offset, |
372 | 363 content_range_upper_bound)) |
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)) | |
384 return false; | |
385 if (!base::StringToInt(byte_range_upper_bound, content_range_upper_bound)) | |
386 return false; | |
387 if (!base::StringToInt(byte_range_instance_size, content_range_instance_size)) | |
388 return false; | 364 return false; |
389 return true; | 365 return true; |
390 } | 366 } |
391 | 367 |
392 } // namespace webkit_glue | 368 } // namespace webkit_glue |
OLD | NEW |