Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "media/blink/resource_multibuffer_data_provider.h" | 5 #include "media/blink/resource_multibuffer_data_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 157 |
| 158 // This test is vital for security! | 158 // This test is vital for security! |
| 159 if (cors_mode_ == UrlData::CORS_UNSPECIFIED) { | 159 if (cors_mode_ == UrlData::CORS_UNSPECIFIED) { |
| 160 // We allow the redirect if the origin is the same. | 160 // We allow the redirect if the origin is the same. |
| 161 if (origin_ != redirects_to_.GetOrigin()) { | 161 if (origin_ != redirects_to_.GetOrigin()) { |
| 162 // We also allow the redirect if we don't have any data in the | 162 // We also allow the redirect if we don't have any data in the |
| 163 // cache, as that means that no dangerous data mixing can occur. | 163 // cache, as that means that no dangerous data mixing can occur. |
| 164 if (url_data_->multibuffer()->map().empty() && fifo_.empty()) | 164 if (url_data_->multibuffer()->map().empty() && fifo_.empty()) |
| 165 return; | 165 return; |
| 166 | 166 |
| 167 std::unique_ptr<ActiveLoader> active_loader = std::move(active_loader_); | |
|
DaleCurtis
2016/05/10 22:42:09
How come active_loader_ needs to out live Fail()?
hubbe
2016/05/11 00:06:38
Good question, I was lazily doing this the same as
| |
| 167 url_data_->Fail(); | 168 url_data_->Fail(); |
| 168 } | 169 } |
| 169 } | 170 } |
| 170 } | 171 } |
| 171 | 172 |
| 172 void ResourceMultiBufferDataProvider::didSendData( | 173 void ResourceMultiBufferDataProvider::didSendData( |
| 173 WebURLLoader* loader, | 174 WebURLLoader* loader, |
| 174 unsigned long long bytes_sent, | 175 unsigned long long bytes_sent, |
| 175 unsigned long long total_bytes_to_be_sent) { | 176 unsigned long long total_bytes_to_be_sent) { |
| 176 NOTIMPLEMENTED(); | 177 NOTIMPLEMENTED(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 // to return. | 272 // to return. |
| 272 destination_url_data->set_length(content_length); | 273 destination_url_data->set_length(content_length); |
| 273 } else if (response.httpStatusCode() == kHttpRangeNotSatisfiable) { | 274 } else if (response.httpStatusCode() == kHttpRangeNotSatisfiable) { |
| 274 // Really, we should never request a range that doesn't exist, but | 275 // Really, we should never request a range that doesn't exist, but |
| 275 // if we do, let's handle it in a sane way. | 276 // if we do, let's handle it in a sane way. |
| 276 // Unsatisfiable range | 277 // Unsatisfiable range |
| 277 fifo_.push_back(DataBuffer::CreateEOSBuffer()); | 278 fifo_.push_back(DataBuffer::CreateEOSBuffer()); |
| 278 destination_url_data->multibuffer()->OnDataProviderEvent(this); | 279 destination_url_data->multibuffer()->OnDataProviderEvent(this); |
| 279 return; | 280 return; |
| 280 } else { | 281 } else { |
| 282 std::unique_ptr<ActiveLoader> active_loader = std::move(active_loader_); | |
| 281 destination_url_data->Fail(); | 283 destination_url_data->Fail(); |
| 282 return; | 284 return; |
| 283 } | 285 } |
| 284 } else { | 286 } else { |
| 285 destination_url_data->set_range_supported(); | 287 destination_url_data->set_range_supported(); |
| 286 if (content_length != kPositionNotSpecified) { | 288 if (content_length != kPositionNotSpecified) { |
| 287 destination_url_data->set_length(content_length + byte_pos()); | 289 destination_url_data->set_length(content_length + byte_pos()); |
| 288 } | 290 } |
| 289 } | 291 } |
| 290 | 292 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 305 url_data_->multibuffer()->RemoveProvider(this)); | 307 url_data_->multibuffer()->RemoveProvider(this)); |
| 306 url_data_ = destination_url_data.get(); | 308 url_data_ = destination_url_data.get(); |
| 307 // Give the ownership to our new owner. | 309 // Give the ownership to our new owner. |
| 308 url_data_->multibuffer()->AddProvider(std::move(self)); | 310 url_data_->multibuffer()->AddProvider(std::move(self)); |
| 309 | 311 |
| 310 // Call callback to let upstream users know about the transfer. | 312 // Call callback to let upstream users know about the transfer. |
| 311 // This will merge the data from the two multibuffers and | 313 // This will merge the data from the two multibuffers and |
| 312 // cause clients to start using the new UrlData. | 314 // cause clients to start using the new UrlData. |
| 313 old_url_data->RedirectTo(destination_url_data); | 315 old_url_data->RedirectTo(destination_url_data); |
| 314 } | 316 } |
| 317 | |
| 318 // This test is vital for security! | |
| 319 const GURL& original_url = response.wasFetchedViaServiceWorker() | |
| 320 ? response.originalURLViaServiceWorker() | |
| 321 : response.url(); | |
| 322 if (!url_data_->ValidateDataOrigin(original_url.GetOrigin())) { | |
| 323 std::unique_ptr<ActiveLoader> active_loader = std::move(active_loader_); | |
| 324 url_data_->Fail(); | |
| 325 return; | |
| 326 } | |
| 315 } | 327 } |
| 316 | 328 |
| 317 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader, | 329 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader, |
| 318 const char* data, | 330 const char* data, |
| 319 int data_length, | 331 int data_length, |
| 320 int encoded_data_length) { | 332 int encoded_data_length) { |
| 321 DVLOG(1) << "didReceiveData: " << data_length << " bytes"; | 333 DVLOG(1) << "didReceiveData: " << data_length << " bytes"; |
| 322 DCHECK(!Available()); | 334 DCHECK(!Available()); |
| 323 DCHECK(active_loader_); | 335 DCHECK(active_loader_); |
| 324 DCHECK_GT(data_length, 0); | 336 DCHECK_GT(data_length, 0); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 } | 510 } |
| 499 | 511 |
| 500 if (byte_pos() != first_byte_position) { | 512 if (byte_pos() != first_byte_position) { |
| 501 return false; | 513 return false; |
| 502 } | 514 } |
| 503 | 515 |
| 504 return true; | 516 return true; |
| 505 } | 517 } |
| 506 | 518 |
| 507 } // namespace media | 519 } // namespace media |
| OLD | NEW |