| 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 active_loader_ = nullptr; |
| 167 url_data_->Fail(); | 168 url_data_->Fail(); |
| 169 return; // "this" may be deleted now. |
| 168 } | 170 } |
| 169 } | 171 } |
| 170 } | 172 } |
| 171 | 173 |
| 172 void ResourceMultiBufferDataProvider::didSendData( | 174 void ResourceMultiBufferDataProvider::didSendData( |
| 173 WebURLLoader* loader, | 175 WebURLLoader* loader, |
| 174 unsigned long long bytes_sent, | 176 unsigned long long bytes_sent, |
| 175 unsigned long long total_bytes_to_be_sent) { | 177 unsigned long long total_bytes_to_be_sent) { |
| 176 NOTIMPLEMENTED(); | 178 NOTIMPLEMENTED(); |
| 177 } | 179 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // to return. | 273 // to return. |
| 272 destination_url_data->set_length(content_length); | 274 destination_url_data->set_length(content_length); |
| 273 } else if (response.httpStatusCode() == kHttpRangeNotSatisfiable) { | 275 } else if (response.httpStatusCode() == kHttpRangeNotSatisfiable) { |
| 274 // Really, we should never request a range that doesn't exist, but | 276 // Really, we should never request a range that doesn't exist, but |
| 275 // if we do, let's handle it in a sane way. | 277 // if we do, let's handle it in a sane way. |
| 276 // Unsatisfiable range | 278 // Unsatisfiable range |
| 277 fifo_.push_back(DataBuffer::CreateEOSBuffer()); | 279 fifo_.push_back(DataBuffer::CreateEOSBuffer()); |
| 278 destination_url_data->multibuffer()->OnDataProviderEvent(this); | 280 destination_url_data->multibuffer()->OnDataProviderEvent(this); |
| 279 return; | 281 return; |
| 280 } else { | 282 } else { |
| 283 active_loader_ = nullptr; |
| 281 destination_url_data->Fail(); | 284 destination_url_data->Fail(); |
| 282 return; | 285 return; // "this" may be deleted now. |
| 283 } | 286 } |
| 284 } else { | 287 } else { |
| 285 destination_url_data->set_range_supported(); | 288 destination_url_data->set_range_supported(); |
| 286 if (content_length != kPositionNotSpecified) { | 289 if (content_length != kPositionNotSpecified) { |
| 287 destination_url_data->set_length(content_length + byte_pos()); | 290 destination_url_data->set_length(content_length + byte_pos()); |
| 288 } | 291 } |
| 289 } | 292 } |
| 290 | 293 |
| 291 if (url_index) { | 294 if (url_index) { |
| 292 destination_url_data = url_index->TryInsert(destination_url_data); | 295 destination_url_data = url_index->TryInsert(destination_url_data); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 305 url_data_->multibuffer()->RemoveProvider(this)); | 308 url_data_->multibuffer()->RemoveProvider(this)); |
| 306 url_data_ = destination_url_data.get(); | 309 url_data_ = destination_url_data.get(); |
| 307 // Give the ownership to our new owner. | 310 // Give the ownership to our new owner. |
| 308 url_data_->multibuffer()->AddProvider(std::move(self)); | 311 url_data_->multibuffer()->AddProvider(std::move(self)); |
| 309 | 312 |
| 310 // Call callback to let upstream users know about the transfer. | 313 // Call callback to let upstream users know about the transfer. |
| 311 // This will merge the data from the two multibuffers and | 314 // This will merge the data from the two multibuffers and |
| 312 // cause clients to start using the new UrlData. | 315 // cause clients to start using the new UrlData. |
| 313 old_url_data->RedirectTo(destination_url_data); | 316 old_url_data->RedirectTo(destination_url_data); |
| 314 } | 317 } |
| 318 |
| 319 // This test is vital for security! |
| 320 const GURL& original_url = response.wasFetchedViaServiceWorker() |
| 321 ? response.originalURLViaServiceWorker() |
| 322 : response.url(); |
| 323 if (!url_data_->ValidateDataOrigin(original_url.GetOrigin())) { |
| 324 active_loader_ = nullptr; |
| 325 url_data_->Fail(); |
| 326 return; // "this" may be deleted now. |
| 327 } |
| 315 } | 328 } |
| 316 | 329 |
| 317 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader, | 330 void ResourceMultiBufferDataProvider::didReceiveData(WebURLLoader* loader, |
| 318 const char* data, | 331 const char* data, |
| 319 int data_length, | 332 int data_length, |
| 320 int encoded_data_length) { | 333 int encoded_data_length) { |
| 321 DVLOG(1) << "didReceiveData: " << data_length << " bytes"; | 334 DVLOG(1) << "didReceiveData: " << data_length << " bytes"; |
| 322 DCHECK(!Available()); | 335 DCHECK(!Available()); |
| 323 DCHECK(active_loader_); | 336 DCHECK(active_loader_); |
| 324 DCHECK_GT(data_length, 0); | 337 DCHECK_GT(data_length, 0); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 size < url_data_->length()) { | 394 size < url_data_->length()) { |
| 382 if (retries_ < kMaxRetries) { | 395 if (retries_ < kMaxRetries) { |
| 383 DVLOG(1) << " Partial data received.... @ pos = " << size; | 396 DVLOG(1) << " Partial data received.... @ pos = " << size; |
| 384 retries_++; | 397 retries_++; |
| 385 base::MessageLoop::current()->PostDelayedTask( | 398 base::MessageLoop::current()->PostDelayedTask( |
| 386 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, | 399 FROM_HERE, base::Bind(&ResourceMultiBufferDataProvider::Start, |
| 387 weak_factory_.GetWeakPtr()), | 400 weak_factory_.GetWeakPtr()), |
| 388 base::TimeDelta::FromMilliseconds(kLoaderPartialRetryDelayMs)); | 401 base::TimeDelta::FromMilliseconds(kLoaderPartialRetryDelayMs)); |
| 389 return; | 402 return; |
| 390 } else { | 403 } else { |
| 391 std::unique_ptr<ActiveLoader> active_loader = std::move(active_loader_); | 404 active_loader_ = nullptr; |
| 392 url_data_->Fail(); | 405 url_data_->Fail(); |
| 393 return; | 406 return; // "this" may be deleted now. |
| 394 } | 407 } |
| 395 } | 408 } |
| 396 | 409 |
| 397 url_data_->set_length(size); | 410 url_data_->set_length(size); |
| 398 fifo_.push_back(DataBuffer::CreateEOSBuffer()); | 411 fifo_.push_back(DataBuffer::CreateEOSBuffer()); |
| 399 | 412 |
| 400 DCHECK(Available()); | 413 DCHECK(Available()); |
| 401 url_data_->multibuffer()->OnDataProviderEvent(this); | 414 url_data_->multibuffer()->OnDataProviderEvent(this); |
| 402 | 415 |
| 403 // Beware, this object might be deleted here. | 416 // Beware, this object might be deleted here. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 } | 511 } |
| 499 | 512 |
| 500 if (byte_pos() != first_byte_position) { | 513 if (byte_pos() != first_byte_position) { |
| 501 return false; | 514 return false; |
| 502 } | 515 } |
| 503 | 516 |
| 504 return true; | 517 return true; |
| 505 } | 518 } |
| 506 | 519 |
| 507 } // namespace media | 520 } // namespace media |
| OLD | NEW |