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/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" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 *out_forward_capacity = std::min(*out_forward_capacity, kMaxBufferCapacity); | 99 *out_forward_capacity = std::min(*out_forward_capacity, kMaxBufferCapacity); |
100 *out_backward_capacity = std::min(*out_backward_capacity, kMaxBufferCapacity); | 100 *out_backward_capacity = std::min(*out_backward_capacity, kMaxBufferCapacity); |
101 | 101 |
102 if (backward_playback) | 102 if (backward_playback) |
103 std::swap(*out_forward_capacity, *out_backward_capacity); | 103 std::swap(*out_forward_capacity, *out_backward_capacity); |
104 } | 104 } |
105 | 105 |
106 BufferedResourceLoader::BufferedResourceLoader( | 106 BufferedResourceLoader::BufferedResourceLoader( |
107 const GURL& url, | 107 const GURL& url, |
| 108 CORSMode cors_mode, |
108 int64 first_byte_position, | 109 int64 first_byte_position, |
109 int64 last_byte_position, | 110 int64 last_byte_position, |
110 DeferStrategy strategy, | 111 DeferStrategy strategy, |
111 int bitrate, | 112 int bitrate, |
112 float playback_rate, | 113 float playback_rate, |
113 media::MediaLog* media_log) | 114 media::MediaLog* media_log) |
114 : buffer_(kMinBufferCapacity, kMinBufferCapacity), | 115 : buffer_(kMinBufferCapacity, kMinBufferCapacity), |
115 loader_failed_(false), | 116 loader_failed_(false), |
116 defer_strategy_(strategy), | 117 defer_strategy_(strategy), |
117 might_be_reused_from_cache_in_future_(true), | 118 might_be_reused_from_cache_in_future_(true), |
118 range_supported_(false), | 119 range_supported_(false), |
119 saved_forward_capacity_(0), | 120 saved_forward_capacity_(0), |
120 url_(url), | 121 url_(url), |
| 122 cors_mode_(cors_mode), |
121 first_byte_position_(first_byte_position), | 123 first_byte_position_(first_byte_position), |
122 last_byte_position_(last_byte_position), | 124 last_byte_position_(last_byte_position), |
123 single_origin_(true), | 125 single_origin_(true), |
124 offset_(0), | 126 offset_(0), |
125 content_length_(kPositionNotSpecified), | 127 content_length_(kPositionNotSpecified), |
126 instance_size_(kPositionNotSpecified), | 128 instance_size_(kPositionNotSpecified), |
127 read_position_(0), | 129 read_position_(0), |
128 read_size_(0), | 130 read_size_(0), |
129 read_buffer_(NULL), | 131 read_buffer_(NULL), |
130 first_offset_(0), | 132 first_offset_(0), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 request.setHTTPHeaderField( | 179 request.setHTTPHeaderField( |
178 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), | 180 WebString::fromUTF8(net::HttpRequestHeaders::kAcceptEncoding), |
179 WebString::fromUTF8("identity;q=1, *;q=0")); | 181 WebString::fromUTF8("identity;q=1, *;q=0")); |
180 | 182 |
181 // Check for our test WebURLLoader. | 183 // Check for our test WebURLLoader. |
182 scoped_ptr<WebURLLoader> loader; | 184 scoped_ptr<WebURLLoader> loader; |
183 if (test_loader_.get()) { | 185 if (test_loader_.get()) { |
184 loader = test_loader_.Pass(); | 186 loader = test_loader_.Pass(); |
185 } else { | 187 } else { |
186 WebURLLoaderOptions options; | 188 WebURLLoaderOptions options; |
187 options.allowCredentials = true; | 189 if (cors_mode_ == kUnspecified) { |
188 options.crossOriginRequestPolicy = | 190 options.crossOriginRequestPolicy = |
189 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | 191 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; |
| 192 } else { |
| 193 options.crossOriginRequestPolicy = |
| 194 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; |
| 195 if (cors_mode_ == kUseCredentials) |
| 196 options.allowCredentials = true; |
| 197 } |
190 loader.reset(frame->createAssociatedURLLoader(options)); | 198 loader.reset(frame->createAssociatedURLLoader(options)); |
191 } | 199 } |
192 | 200 |
193 // Start the resource loading. | 201 // Start the resource loading. |
194 loader->loadAsynchronously(request, this); | 202 loader->loadAsynchronously(request, this); |
195 active_loader_.reset(new ActiveLoader(loader.Pass())); | 203 active_loader_.reset(new ActiveLoader(loader.Pass())); |
196 } | 204 } |
197 | 205 |
198 void BufferedResourceLoader::Stop() { | 206 void BufferedResourceLoader::Stop() { |
199 // Reset callbacks. | 207 // Reset callbacks. |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 } | 527 } |
520 | 528 |
521 // There must not be any outstanding read request. | 529 // There must not be any outstanding read request. |
522 DCHECK(!HasPendingRead()); | 530 DCHECK(!HasPendingRead()); |
523 } | 531 } |
524 | 532 |
525 void BufferedResourceLoader::didFail( | 533 void BufferedResourceLoader::didFail( |
526 WebURLLoader* loader, | 534 WebURLLoader* loader, |
527 const WebURLError& error) { | 535 const WebURLError& error) { |
528 DVLOG(1) << "didFail: reason=" << error.reason | 536 DVLOG(1) << "didFail: reason=" << error.reason |
529 << " isCancellation=" << error.isCancellation; | 537 << ", isCancellation=" << error.isCancellation |
| 538 << ", domain=" << error.domain.utf8().data() |
| 539 << ", localizedDescription=" |
| 540 << error.localizedDescription.utf8().data(); |
530 DCHECK(active_loader_.get()); | 541 DCHECK(active_loader_.get()); |
531 | 542 |
532 // We don't need to continue loading after failure. | 543 // We don't need to continue loading after failure. |
533 // | 544 // |
534 // Keep it alive until we exit this method so that |error| remains valid. | 545 // Keep it alive until we exit this method so that |error| remains valid. |
535 scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass(); | 546 scoped_ptr<ActiveLoader> active_loader = active_loader_.Pass(); |
536 loader_failed_ = true; | 547 loader_failed_ = true; |
537 NotifyNetworkEvent(); | 548 NotifyNetworkEvent(); |
538 | 549 |
539 // Don't leave start callbacks hanging around. | 550 // Don't leave start callbacks hanging around. |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 | 847 |
837 void BufferedResourceLoader::Log() { | 848 void BufferedResourceLoader::Log() { |
838 media_log_->AddEvent( | 849 media_log_->AddEvent( |
839 media_log_->CreateBufferedExtentsChangedEvent( | 850 media_log_->CreateBufferedExtentsChangedEvent( |
840 offset_ - buffer_.backward_bytes(), | 851 offset_ - buffer_.backward_bytes(), |
841 offset_, | 852 offset_, |
842 offset_ + buffer_.forward_bytes())); | 853 offset_ + buffer_.forward_bytes())); |
843 } | 854 } |
844 | 855 |
845 } // namespace webkit_media | 856 } // namespace webkit_media |
OLD | NEW |