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" |
| 18 #include "net/http/http_util.h" |
17 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
18 #include "third_party/WebKit/public/platform/WebURLError.h" | 20 #include "third_party/WebKit/public/platform/WebURLError.h" |
19 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 21 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
20 #include "third_party/WebKit/public/web/WebKit.h" | 22 #include "third_party/WebKit/public/web/WebKit.h" |
21 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | 23 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" |
22 | 24 |
23 using blink::WebFrame; | 25 using blink::WebFrame; |
24 using blink::WebString; | 26 using blink::WebString; |
25 using blink::WebURLError; | 27 using blink::WebURLError; |
26 using blink::WebURLLoader; | 28 using blink::WebURLLoader; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 offset_ = first_byte_position_; | 160 offset_ = first_byte_position_; |
159 } | 161 } |
160 | 162 |
161 // Prepare the request. | 163 // Prepare the request. |
162 WebURLRequest request(url_); | 164 WebURLRequest request(url_); |
163 request.setTargetType(WebURLRequest::TargetIsMedia); | 165 request.setTargetType(WebURLRequest::TargetIsMedia); |
164 | 166 |
165 if (IsRangeRequest()) { | 167 if (IsRangeRequest()) { |
166 request.setHTTPHeaderField( | 168 request.setHTTPHeaderField( |
167 WebString::fromUTF8(net::HttpRequestHeaders::kRange), | 169 WebString::fromUTF8(net::HttpRequestHeaders::kRange), |
168 WebString::fromUTF8(GenerateHeaders(first_byte_position_, | 170 WebString::fromUTF8( |
169 last_byte_position_))); | 171 net::HttpUtil::PrintRange(net::HttpByteRange::Bounded( |
| 172 first_byte_position_, last_byte_position_)))); |
170 } | 173 } |
171 | 174 |
172 frame->setReferrerForRequest(request, blink::WebURL()); | 175 frame->setReferrerForRequest(request, blink::WebURL()); |
173 | 176 |
174 // Disable compression, compression for audio/video doesn't make sense... | 177 // Disable compression, compression for audio/video doesn't make sense... |
175 request.setHTTPHeaderField( | 178 request.setHTTPHeaderField( |
176 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), | 179 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), |
177 WebString::fromUTF8("identity;q=1, *;q=0")); | 180 WebString::fromUTF8("identity;q=1, *;q=0")); |
178 | 181 |
179 // Check for our test WebURLLoader. | 182 // Check for our test WebURLLoader. |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 if (first_byte_position_ != kPositionNotSpecified && | 746 if (first_byte_position_ != kPositionNotSpecified && |
744 first_byte_position_ != first_byte_position) { | 747 first_byte_position_ != first_byte_position) { |
745 return false; | 748 return false; |
746 } | 749 } |
747 | 750 |
748 // TODO(hclam): I should also check |last_byte_position|, but since | 751 // 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. | 752 // we will never make such a request that it is ok to leave it unimplemented. |
750 return true; | 753 return true; |
751 } | 754 } |
752 | 755 |
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) { | 756 void BufferedResourceLoader::DoneRead(Status status, int bytes_read) { |
775 if (saved_forward_capacity_) { | 757 if (saved_forward_capacity_) { |
776 buffer_.set_forward_capacity(saved_forward_capacity_); | 758 buffer_.set_forward_capacity(saved_forward_capacity_); |
777 saved_forward_capacity_ = 0; | 759 saved_forward_capacity_ = 0; |
778 } | 760 } |
779 read_position_ = 0; | 761 read_position_ = 0; |
780 read_size_ = 0; | 762 read_size_ = 0; |
781 read_buffer_ = NULL; | 763 read_buffer_ = NULL; |
782 first_offset_ = 0; | 764 first_offset_ = 0; |
783 last_offset_ = 0; | 765 last_offset_ = 0; |
(...skipping 13 matching lines...) Expand all Loading... |
797 | 779 |
798 void BufferedResourceLoader::Log() { | 780 void BufferedResourceLoader::Log() { |
799 media_log_->AddEvent( | 781 media_log_->AddEvent( |
800 media_log_->CreateBufferedExtentsChangedEvent( | 782 media_log_->CreateBufferedExtentsChangedEvent( |
801 offset_ - buffer_.backward_bytes(), | 783 offset_ - buffer_.backward_bytes(), |
802 offset_, | 784 offset_, |
803 offset_ + buffer_.forward_bytes())); | 785 offset_ + buffer_.forward_bytes())); |
804 } | 786 } |
805 | 787 |
806 } // namespace content | 788 } // namespace content |
OLD | NEW |