OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/media/buffered_resource_loader.h" | 5 #include "webkit/media/buffered_resource_loader.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "media/base/media_log.h" | 10 #include "media/base/media_log.h" |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 bool partial_response = false; | 370 bool partial_response = false; |
371 | 371 |
372 // We make a strong assumption that when we reach here we have either | 372 // We make a strong assumption that when we reach here we have either |
373 // received a response from HTTP/HTTPS protocol or the request was | 373 // received a response from HTTP/HTTPS protocol or the request was |
374 // successful (in particular range request). So we only verify the partial | 374 // successful (in particular range request). So we only verify the partial |
375 // response for HTTP and HTTPS protocol. | 375 // response for HTTP and HTTPS protocol. |
376 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { | 376 if (url_.SchemeIs(kHttpScheme) || url_.SchemeIs(kHttpsScheme)) { |
377 int error = net::OK; | 377 int error = net::OK; |
378 | 378 |
379 // Check to see whether the server supports byte ranges. | |
380 std::string accept_ranges = | |
381 response.httpHeaderField("Accept-Ranges").utf8(); | |
382 range_supported_ = (accept_ranges.find("bytes") != std::string::npos); | |
383 | |
384 partial_response = (response.httpStatusCode() == kHttpPartialContent); | 379 partial_response = (response.httpStatusCode() == kHttpPartialContent); |
| 380 bool ok_response = (response.httpStatusCode() == kHttpOK); |
385 | 381 |
386 if (range_requested_) { | 382 if (range_requested_) { |
| 383 // Check to see whether the server supports byte ranges. |
| 384 std::string accept_ranges = |
| 385 response.httpHeaderField("Accept-Ranges").utf8(); |
| 386 range_supported_ = (accept_ranges.find("bytes") != std::string::npos); |
| 387 |
387 // If we have verified the partial response and it is correct, we will | 388 // If we have verified the partial response and it is correct, we will |
388 // return net::OK. It's also possible for a server to support range | 389 // return net::OK. It's also possible for a server to support range |
389 // requests without advertising Accept-Ranges: bytes. | 390 // requests without advertising Accept-Ranges: bytes. |
390 if (partial_response && VerifyPartialResponse(response)) | 391 if (partial_response && VerifyPartialResponse(response)) { |
391 range_supported_ = true; | 392 range_supported_ = true; |
392 else | 393 } else if (ok_response && first_byte_position_ == 0 && |
| 394 last_byte_position_ == kPositionNotSpecified) { |
| 395 // We accept a 200 response for a Range:0- request and down-grade the |
| 396 // data source to streaming. |
| 397 range_supported_ = false; |
| 398 } else { |
393 error = net::ERR_INVALID_RESPONSE; | 399 error = net::ERR_INVALID_RESPONSE; |
| 400 } |
394 } else if (response.httpStatusCode() != kHttpOK) { | 401 } else if (response.httpStatusCode() != kHttpOK) { |
395 // We didn't request a range but server didn't reply with "200 OK". | 402 // We didn't request a range but server didn't reply with "200 OK". |
396 error = net::ERR_FAILED; | 403 error = net::ERR_FAILED; |
397 } | 404 } |
398 | 405 |
399 if (error != net::OK) { | 406 if (error != net::OK) { |
400 DoneStart(error); | 407 DoneStart(error); |
401 return; | 408 return; |
402 } | 409 } |
403 } else { | |
404 // For any protocol other than HTTP and HTTPS, assume range request is | |
405 // always fulfilled. | |
406 partial_response = range_requested_; | |
407 } | 410 } |
408 | 411 |
409 // Expected content length can be |kPositionNotSpecified|, in that case | 412 // Expected content length can be |kPositionNotSpecified|, in that case |
410 // |content_length_| is not specified and this is a streaming response. | 413 // |content_length_| is not specified and this is a streaming response. |
411 content_length_ = response.expectedContentLength(); | 414 content_length_ = response.expectedContentLength(); |
412 | 415 |
413 // If we have not requested a range, then the size of the instance is equal | 416 // If we have not requested a range or have not received a range, then the |
414 // to the content length. | 417 // size of the instance is equal to the content length. |
415 if (!partial_response) | 418 if (!range_requested_ || !partial_response) |
416 instance_size_ = content_length_; | 419 instance_size_ = content_length_; |
417 | 420 |
418 // Calls with a successful response. | 421 // Calls with a successful response. |
419 DoneStart(net::OK); | 422 DoneStart(net::OK); |
420 } | 423 } |
421 | 424 |
422 void BufferedResourceLoader::didReceiveData( | 425 void BufferedResourceLoader::didReceiveData( |
423 WebURLLoader* loader, | 426 WebURLLoader* loader, |
424 const char* data, | 427 const char* data, |
425 int data_length, | 428 int data_length, |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 if (buffer_.get()) { | 787 if (buffer_.get()) { |
785 media_log_->AddEvent( | 788 media_log_->AddEvent( |
786 media_log_->CreateBufferedExtentsChangedEvent( | 789 media_log_->CreateBufferedExtentsChangedEvent( |
787 offset_ - buffer_->backward_bytes(), | 790 offset_ - buffer_->backward_bytes(), |
788 offset_, | 791 offset_, |
789 offset_ + buffer_->forward_bytes())); | 792 offset_ + buffer_->forward_bytes())); |
790 } | 793 } |
791 } | 794 } |
792 | 795 |
793 } // namespace webkit_media | 796 } // namespace webkit_media |
OLD | NEW |