| 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_request_headers.h" | 16 #include "net/http/http_request_headers.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebURLError.h" | 18 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 19 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 19 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 20 #include "third_party/WebKit/public/web/WebKit.h" | 20 #include "third_party/WebKit/public/web/WebKit.h" |
| 21 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" | 21 #include "third_party/WebKit/public/web/WebURLLoaderOptions.h" |
| 22 | 22 |
| 23 using WebKit::WebFrame; | 23 using blink::WebFrame; |
| 24 using WebKit::WebString; | 24 using blink::WebString; |
| 25 using WebKit::WebURLError; | 25 using blink::WebURLError; |
| 26 using WebKit::WebURLLoader; | 26 using blink::WebURLLoader; |
| 27 using WebKit::WebURLLoaderOptions; | 27 using blink::WebURLLoaderOptions; |
| 28 using WebKit::WebURLRequest; | 28 using blink::WebURLRequest; |
| 29 using WebKit::WebURLResponse; | 29 using blink::WebURLResponse; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 static const int kHttpOK = 200; | 33 static const int kHttpOK = 200; |
| 34 static const int kHttpPartialContent = 206; | 34 static const int kHttpPartialContent = 206; |
| 35 | 35 |
| 36 // Define the number of bytes in a megabyte. | 36 // Define the number of bytes in a megabyte. |
| 37 static const int kMegabyte = 1024 * 1024; | 37 static const int kMegabyte = 1024 * 1024; |
| 38 | 38 |
| 39 // Minimum capacity of the buffer in forward or backward direction. | 39 // Minimum capacity of the buffer in forward or backward direction. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 WebURLRequest request(url_); | 162 WebURLRequest request(url_); |
| 163 request.setTargetType(WebURLRequest::TargetIsMedia); | 163 request.setTargetType(WebURLRequest::TargetIsMedia); |
| 164 | 164 |
| 165 if (IsRangeRequest()) { | 165 if (IsRangeRequest()) { |
| 166 request.setHTTPHeaderField( | 166 request.setHTTPHeaderField( |
| 167 WebString::fromUTF8(net::HttpRequestHeaders::kRange), | 167 WebString::fromUTF8(net::HttpRequestHeaders::kRange), |
| 168 WebString::fromUTF8(GenerateHeaders(first_byte_position_, | 168 WebString::fromUTF8(GenerateHeaders(first_byte_position_, |
| 169 last_byte_position_))); | 169 last_byte_position_))); |
| 170 } | 170 } |
| 171 | 171 |
| 172 frame->setReferrerForRequest(request, WebKit::WebURL()); | 172 frame->setReferrerForRequest(request, blink::WebURL()); |
| 173 | 173 |
| 174 // Disable compression, compression for audio/video doesn't make sense... | 174 // Disable compression, compression for audio/video doesn't make sense... |
| 175 request.setHTTPHeaderField( | 175 request.setHTTPHeaderField( |
| 176 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), | 176 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), |
| 177 WebString::fromUTF8("identity;q=1, *;q=0")); | 177 WebString::fromUTF8("identity;q=1, *;q=0")); |
| 178 | 178 |
| 179 // Check for our test WebURLLoader. | 179 // Check for our test WebURLLoader. |
| 180 scoped_ptr<WebURLLoader> loader; | 180 scoped_ptr<WebURLLoader> loader; |
| 181 if (test_loader_) { | 181 if (test_loader_) { |
| 182 loader = test_loader_.Pass(); | 182 loader = test_loader_.Pass(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 315 |
| 316 int64 BufferedResourceLoader::instance_size() { | 316 int64 BufferedResourceLoader::instance_size() { |
| 317 return instance_size_; | 317 return instance_size_; |
| 318 } | 318 } |
| 319 | 319 |
| 320 bool BufferedResourceLoader::range_supported() { | 320 bool BufferedResourceLoader::range_supported() { |
| 321 return range_supported_; | 321 return range_supported_; |
| 322 } | 322 } |
| 323 | 323 |
| 324 ///////////////////////////////////////////////////////////////////////////// | 324 ///////////////////////////////////////////////////////////////////////////// |
| 325 // WebKit::WebURLLoaderClient implementation. | 325 // blink::WebURLLoaderClient implementation. |
| 326 void BufferedResourceLoader::willSendRequest( | 326 void BufferedResourceLoader::willSendRequest( |
| 327 WebURLLoader* loader, | 327 WebURLLoader* loader, |
| 328 WebURLRequest& newRequest, | 328 WebURLRequest& newRequest, |
| 329 const WebURLResponse& redirectResponse) { | 329 const WebURLResponse& redirectResponse) { |
| 330 | 330 |
| 331 // The load may have been stopped and |start_cb| is destroyed. | 331 // The load may have been stopped and |start_cb| is destroyed. |
| 332 // In this case we shouldn't do anything. | 332 // In this case we shouldn't do anything. |
| 333 if (start_cb_.is_null()) { | 333 if (start_cb_.is_null()) { |
| 334 // Set the url in the request to an invalid value (empty url). | 334 // Set the url in the request to an invalid value (empty url). |
| 335 newRequest.setURL(WebKit::WebURL()); | 335 newRequest.setURL(blink::WebURL()); |
| 336 return; | 336 return; |
| 337 } | 337 } |
| 338 | 338 |
| 339 // Only allow |single_origin_| if we haven't seen a different origin yet. | 339 // Only allow |single_origin_| if we haven't seen a different origin yet. |
| 340 if (single_origin_) | 340 if (single_origin_) |
| 341 single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); | 341 single_origin_ = url_.GetOrigin() == GURL(newRequest.url()).GetOrigin(); |
| 342 | 342 |
| 343 url_ = newRequest.url(); | 343 url_ = newRequest.url(); |
| 344 } | 344 } |
| 345 | 345 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 DCHECK(success); | 460 DCHECK(success); |
| 461 offset_ += first_offset_ + excess; | 461 offset_ += first_offset_ + excess; |
| 462 } | 462 } |
| 463 | 463 |
| 464 // Notify latest progress and buffered offset. | 464 // Notify latest progress and buffered offset. |
| 465 progress_cb_.Run(offset_ + buffer_.forward_bytes() - 1); | 465 progress_cb_.Run(offset_ + buffer_.forward_bytes() - 1); |
| 466 Log(); | 466 Log(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 void BufferedResourceLoader::didDownloadData( | 469 void BufferedResourceLoader::didDownloadData( |
| 470 WebKit::WebURLLoader* loader, | 470 blink::WebURLLoader* loader, |
| 471 int dataLength, | 471 int dataLength, |
| 472 int encoded_data_length) { | 472 int encoded_data_length) { |
| 473 NOTIMPLEMENTED(); | 473 NOTIMPLEMENTED(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void BufferedResourceLoader::didReceiveCachedMetadata( | 476 void BufferedResourceLoader::didReceiveCachedMetadata( |
| 477 WebURLLoader* loader, | 477 WebURLLoader* loader, |
| 478 const char* data, | 478 const char* data, |
| 479 int data_length) { | 479 int data_length) { |
| 480 NOTIMPLEMENTED(); | 480 NOTIMPLEMENTED(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 | 795 |
| 796 void BufferedResourceLoader::Log() { | 796 void BufferedResourceLoader::Log() { |
| 797 media_log_->AddEvent( | 797 media_log_->AddEvent( |
| 798 media_log_->CreateBufferedExtentsChangedEvent( | 798 media_log_->CreateBufferedExtentsChangedEvent( |
| 799 offset_ - buffer_.backward_bytes(), | 799 offset_ - buffer_.backward_bytes(), |
| 800 offset_, | 800 offset_, |
| 801 offset_ + buffer_.forward_bytes())); | 801 offset_ + buffer_.forward_bytes())); |
| 802 } | 802 } |
| 803 | 803 |
| 804 } // namespace content | 804 } // namespace content |
| OLD | NEW |