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 CrossOriginAttribute cross_origin_attribute, |
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 cross_origin_attribute_(cross_origin_attribute), |
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 (cross_origin_attribute_ == kUnspecified) { |
188 options.crossOriginRequestPolicy = | 190 options.crossOriginRequestPolicy = |
189 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; | 191 WebURLLoaderOptions::CrossOriginRequestPolicyAllow; |
| 192 } else { |
| 193 options.crossOriginRequestPolicy = |
| 194 WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; |
| 195 if (cross_origin_attribute_ == 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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 | 844 |
837 void BufferedResourceLoader::Log() { | 845 void BufferedResourceLoader::Log() { |
838 media_log_->AddEvent( | 846 media_log_->AddEvent( |
839 media_log_->CreateBufferedExtentsChangedEvent( | 847 media_log_->CreateBufferedExtentsChangedEvent( |
840 offset_ - buffer_.backward_bytes(), | 848 offset_ - buffer_.backward_bytes(), |
841 offset_, | 849 offset_, |
842 offset_ + buffer_.forward_bytes())); | 850 offset_ + buffer_.forward_bytes())); |
843 } | 851 } |
844 | 852 |
845 } // namespace webkit_media | 853 } // namespace webkit_media |
OLD | NEW |