| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/media/buffered_resource_loader.h" | 5 #include "content/renderer/media/buffered_resource_loader.h" |
| 6 | 6 |
| 7 #include "base/bits.h" | 7 #include "base/bits.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "content/renderer/media/cache_util.h" | 14 #include "content/renderer/media/cache_util.h" |
| 15 #include "media/base/media_log.h" | 15 #include "media/base/media_log.h" |
| 16 #include "net/http/http_byte_range.h" |
| 16 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebURLError.h" | 19 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 19 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 20 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 20 #include "third_party/WebKit/public/web/WebKit.h" | 21 #include "third_party/WebKit/public/web/WebKit.h" |
| 21 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | 22 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" |
| 22 | 23 |
| 23 using blink::WebFrame; | 24 using blink::WebFrame; |
| 24 using blink::WebString; | 25 using blink::WebString; |
| 25 using blink::WebURLError; | 26 using blink::WebURLError; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 offset_ = first_byte_position_; | 159 offset_ = first_byte_position_; |
| 159 } | 160 } |
| 160 | 161 |
| 161 // Prepare the request. | 162 // Prepare the request. |
| 162 WebURLRequest request(url_); | 163 WebURLRequest request(url_); |
| 163 request.setTargetType(WebURLRequest::TargetIsMedia); | 164 request.setTargetType(WebURLRequest::TargetIsMedia); |
| 164 | 165 |
| 165 if (IsRangeRequest()) { | 166 if (IsRangeRequest()) { |
| 166 request.setHTTPHeaderField( | 167 request.setHTTPHeaderField( |
| 167 WebString::fromUTF8(net::HttpRequestHeaders::kRange), | 168 WebString::fromUTF8(net::HttpRequestHeaders::kRange), |
| 168 WebString::fromUTF8(GenerateHeaders(first_byte_position_, | 169 WebString::fromUTF8(net::HttpByteRange::Bounded( |
| 169 last_byte_position_))); | 170 first_byte_position_, last_byte_position_).PrintHeader())); |
| 170 } | 171 } |
| 171 | 172 |
| 172 frame->setReferrerForRequest(request, blink::WebURL()); | 173 frame->setReferrerForRequest(request, blink::WebURL()); |
| 173 | 174 |
| 174 // Disable compression, compression for audio/video doesn't make sense... | 175 // Disable compression, compression for audio/video doesn't make sense... |
| 175 request.setHTTPHeaderField( | 176 request.setHTTPHeaderField( |
| 176 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), | 177 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), |
| 177 WebString::fromUTF8("identity;q=1, *;q=0")); | 178 WebString::fromUTF8("identity;q=1, *;q=0")); |
| 178 | 179 |
| 179 // Check for our test WebURLLoader. | 180 // Check for our test WebURLLoader. |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 if (first_byte_position_ != kPositionNotSpecified && | 744 if (first_byte_position_ != kPositionNotSpecified && |
| 744 first_byte_position_ != first_byte_position) { | 745 first_byte_position_ != first_byte_position) { |
| 745 return false; | 746 return false; |
| 746 } | 747 } |
| 747 | 748 |
| 748 // TODO(hclam): I should also check |last_byte_position|, but since | 749 // TODO(hclam): I should also check |last_byte_position|, but since |
| 749 // we will never make such a request that it is ok to leave it unimplemented. | 750 // we will never make such a request that it is ok to leave it unimplemented. |
| 750 return true; | 751 return true; |
| 751 } | 752 } |
| 752 | 753 |
| 753 std::string BufferedResourceLoader::GenerateHeaders( | |
| 754 int64 first_byte_position, | |
| 755 int64 last_byte_position) { | |
| 756 // Construct the value for the range header. | |
| 757 std::string header; | |
| 758 if (first_byte_position > kPositionNotSpecified && | |
| 759 last_byte_position > kPositionNotSpecified) { | |
| 760 if (first_byte_position <= last_byte_position) { | |
| 761 header = base::StringPrintf("bytes=%" PRId64 "-%" PRId64, | |
| 762 first_byte_position, | |
| 763 last_byte_position); | |
| 764 } | |
| 765 } else if (first_byte_position > kPositionNotSpecified) { | |
| 766 header = base::StringPrintf("bytes=%" PRId64 "-", | |
| 767 first_byte_position); | |
| 768 } else if (last_byte_position > kPositionNotSpecified) { | |
| 769 NOTIMPLEMENTED() << "Suffix range not implemented"; | |
| 770 } | |
| 771 return header; | |
| 772 } | |
| 773 | |
| 774 void BufferedResourceLoader::DoneRead(Status status, int bytes_read) { | 754 void BufferedResourceLoader::DoneRead(Status status, int bytes_read) { |
| 775 if (saved_forward_capacity_) { | 755 if (saved_forward_capacity_) { |
| 776 buffer_.set_forward_capacity(saved_forward_capacity_); | 756 buffer_.set_forward_capacity(saved_forward_capacity_); |
| 777 saved_forward_capacity_ = 0; | 757 saved_forward_capacity_ = 0; |
| 778 } | 758 } |
| 779 read_position_ = 0; | 759 read_position_ = 0; |
| 780 read_size_ = 0; | 760 read_size_ = 0; |
| 781 read_buffer_ = NULL; | 761 read_buffer_ = NULL; |
| 782 first_offset_ = 0; | 762 first_offset_ = 0; |
| 783 last_offset_ = 0; | 763 last_offset_ = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 797 | 777 |
| 798 void BufferedResourceLoader::Log() { | 778 void BufferedResourceLoader::Log() { |
| 799 media_log_->AddEvent( | 779 media_log_->AddEvent( |
| 800 media_log_->CreateBufferedExtentsChangedEvent( | 780 media_log_->CreateBufferedExtentsChangedEvent( |
| 801 offset_ - buffer_.backward_bytes(), | 781 offset_ - buffer_.backward_bytes(), |
| 802 offset_, | 782 offset_, |
| 803 offset_ + buffer_.forward_bytes())); | 783 offset_ + buffer_.forward_bytes())); |
| 804 } | 784 } |
| 805 | 785 |
| 806 } // namespace content | 786 } // namespace content |
| OLD | NEW |