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 "media/blink/buffered_data_source.h" | 5 #include "media/blink/buffered_data_source.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 | 349 |
350 bool init_cb_is_null = false; | 350 bool init_cb_is_null = false; |
351 { | 351 { |
352 base::AutoLock auto_lock(lock_); | 352 base::AutoLock auto_lock(lock_); |
353 init_cb_is_null = init_cb_.is_null(); | 353 init_cb_is_null = init_cb_.is_null(); |
354 } | 354 } |
355 if (init_cb_is_null) { | 355 if (init_cb_is_null) { |
356 loader_->Stop(); | 356 loader_->Stop(); |
357 return; | 357 return; |
358 } | 358 } |
| 359 response_original_url_ = loader_->response_original_url(); |
359 | 360 |
360 // All responses must be successful. Resources that are assumed to be fully | 361 // All responses must be successful. Resources that are assumed to be fully |
361 // buffered must have a known content length. | 362 // buffered must have a known content length. |
362 bool success = status == BufferedResourceLoader::kOk && | 363 bool success = status == BufferedResourceLoader::kOk && |
363 (!assume_fully_buffered() || | 364 (!assume_fully_buffered() || |
364 loader_->instance_size() != kPositionNotSpecified); | 365 loader_->instance_size() != kPositionNotSpecified); |
365 | 366 |
366 if (success) { | 367 if (success) { |
367 total_bytes_ = loader_->instance_size(); | 368 total_bytes_ = loader_->instance_size(); |
368 streaming_ = | 369 streaming_ = |
(...skipping 27 matching lines...) Expand all Loading... |
396 loader_->range_supported()); | 397 loader_->range_supported()); |
397 } | 398 } |
398 | 399 |
399 base::ResetAndReturn(&init_cb_).Run(success); | 400 base::ResetAndReturn(&init_cb_).Run(success); |
400 } | 401 } |
401 | 402 |
402 void BufferedDataSource::PartialReadStartCallback( | 403 void BufferedDataSource::PartialReadStartCallback( |
403 BufferedResourceLoader::Status status) { | 404 BufferedResourceLoader::Status status) { |
404 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 405 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
405 DCHECK(loader_.get()); | 406 DCHECK(loader_.get()); |
406 | 407 if (status == BufferedResourceLoader::kOk && |
407 if (status == BufferedResourceLoader::kOk) { | 408 CheckPartialResponseURL(loader_->response_original_url())) { |
408 // Once the request has started successfully, we can proceed with | 409 // Once the request has started successfully, we can proceed with |
409 // reading from it. | 410 // reading from it. |
410 ReadInternal(); | 411 ReadInternal(); |
411 return; | 412 return; |
412 } | 413 } |
413 | 414 |
414 // Stop the resource loader since we have received an error. | 415 // Stop the resource loader since we have received an error. |
415 loader_->Stop(); | 416 loader_->Stop(); |
416 | 417 |
417 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 418 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
418 // http://crbug.com/113712 for details. | 419 // http://crbug.com/113712 for details. |
419 base::AutoLock auto_lock(lock_); | 420 base::AutoLock auto_lock(lock_); |
420 if (stop_signal_received_) | 421 if (stop_signal_received_) |
421 return; | 422 return; |
422 ReadOperation::Run(read_op_.Pass(), kReadError); | 423 ReadOperation::Run(read_op_.Pass(), kReadError); |
423 } | 424 } |
424 | 425 |
| 426 bool BufferedDataSource::CheckPartialResponseURL( |
| 427 const GURL& partial_response_original_url) const { |
| 428 // We check the redirected URL of partial responses in case malicious |
| 429 // attackers scan the bytes of other origin resources by mixing their |
| 430 // generated bytes and the target response. See http://crbug.com/489060#c32 |
| 431 // for details. |
| 432 // If the origin of the new response is different from the first response we |
| 433 // deny the redirected response. |
| 434 return response_original_url_.GetOrigin() == |
| 435 partial_response_original_url.GetOrigin(); |
| 436 } |
| 437 |
425 void BufferedDataSource::ReadCallback( | 438 void BufferedDataSource::ReadCallback( |
426 BufferedResourceLoader::Status status, | 439 BufferedResourceLoader::Status status, |
427 int bytes_read) { | 440 int bytes_read) { |
428 DCHECK(render_task_runner_->BelongsToCurrentThread()); | 441 DCHECK(render_task_runner_->BelongsToCurrentThread()); |
429 | 442 |
430 // TODO(scherkus): we shouldn't have to lock to signal host(), see | 443 // TODO(scherkus): we shouldn't have to lock to signal host(), see |
431 // http://crbug.com/113712 for details. | 444 // http://crbug.com/113712 for details. |
432 base::AutoLock auto_lock(lock_); | 445 base::AutoLock auto_lock(lock_); |
433 if (stop_signal_received_) | 446 if (stop_signal_received_) |
434 return; | 447 return; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 } | 564 } |
552 | 565 |
553 // If media is currently playing or the page indicated preload=auto or the | 566 // If media is currently playing or the page indicated preload=auto or the |
554 // the server does not support the byte range request or we do not want to go | 567 // the server does not support the byte range request or we do not want to go |
555 // too far ahead of the read head, use threshold strategy to enable/disable | 568 // too far ahead of the read head, use threshold strategy to enable/disable |
556 // deferring when the buffer is full/depleted. | 569 // deferring when the buffer is full/depleted. |
557 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); | 570 loader_->UpdateDeferStrategy(BufferedResourceLoader::kCapacityDefer); |
558 } | 571 } |
559 | 572 |
560 } // namespace media | 573 } // namespace media |
OLD | NEW |