| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/loader/resource/ImageResourceContent.h" | 5 #include "core/loader/resource/ImageResourceContent.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "core/loader/resource/ImageResource.h" | 9 #include "core/loader/resource/ImageResource.h" |
| 10 #include "core/loader/resource/ImageResourceInfo.h" | 10 #include "core/loader/resource/ImageResourceInfo.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 observers_.Contains(observer) && | 306 observers_.Contains(observer) && |
| 307 !info_->SchedulingReloadOrShouldReloadBrokenPlaceholder()) { | 307 !info_->SchedulingReloadOrShouldReloadBrokenPlaceholder()) { |
| 308 MarkObserverFinished(observer); | 308 MarkObserverFinished(observer); |
| 309 observer->ImageNotifyFinished(this); | 309 observer->ImageNotifyFinished(this); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| 316 PassRefPtr<Image> ImageResourceContent::CreateImage() { | 316 PassRefPtr<Image> ImageResourceContent::CreateImage(bool is_multipart) { |
| 317 if (info_->GetResponse().MimeType() == "image/svg+xml") | 317 if (info_->GetResponse().MimeType() == "image/svg+xml") |
| 318 return SVGImage::Create(this); | 318 return SVGImage::Create(this, is_multipart); |
| 319 return BitmapImage::Create(this); | 319 return BitmapImage::Create(this, is_multipart); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void ImageResourceContent::ClearImage() { | 322 void ImageResourceContent::ClearImage() { |
| 323 if (!image_) | 323 if (!image_) |
| 324 return; | 324 return; |
| 325 int64_t length = image_->Data() ? image_->Data()->size() : 0; | 325 int64_t length = image_->Data() ? image_->Data()->size() : 0; |
| 326 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); | 326 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); |
| 327 | 327 |
| 328 // If our Image has an observer, it's always us so we need to clear the back | 328 // If our Image has an observer, it's always us so we need to clear the back |
| 329 // pointer before dropping our reference. | 329 // pointer before dropping our reference. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 CHECK_EQ(size_available_, Image::kSizeAvailableAndLoadingAsynchronously); | 412 CHECK_EQ(size_available_, Image::kSizeAvailableAndLoadingAsynchronously); |
| 413 size_available_ = Image::kSizeAvailable; | 413 size_available_ = Image::kSizeAvailable; |
| 414 UpdateToLoadedContentStatus(ResourceStatus::kCached); | 414 UpdateToLoadedContentStatus(ResourceStatus::kCached); |
| 415 NotifyObservers(kShouldNotifyFinish); | 415 NotifyObservers(kShouldNotifyFinish); |
| 416 } | 416 } |
| 417 | 417 |
| 418 ImageResourceContent::UpdateImageResult ImageResourceContent::UpdateImage( | 418 ImageResourceContent::UpdateImageResult ImageResourceContent::UpdateImage( |
| 419 PassRefPtr<SharedBuffer> data, | 419 PassRefPtr<SharedBuffer> data, |
| 420 ResourceStatus status, | 420 ResourceStatus status, |
| 421 UpdateImageOption update_image_option, | 421 UpdateImageOption update_image_option, |
| 422 bool all_data_received) { | 422 bool all_data_received, |
| 423 bool is_multipart) { |
| 423 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); | 424 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); |
| 424 | 425 |
| 425 #if DCHECK_IS_ON() | 426 #if DCHECK_IS_ON() |
| 426 DCHECK(!is_update_image_being_called_); | 427 DCHECK(!is_update_image_being_called_); |
| 427 AutoReset<bool> scope(&is_update_image_being_called_, true); | 428 AutoReset<bool> scope(&is_update_image_being_called_, true); |
| 428 #endif | 429 #endif |
| 429 | 430 |
| 430 CHECK_NE(GetContentStatus(), ResourceStatus::kNotStarted); | 431 CHECK_NE(GetContentStatus(), ResourceStatus::kNotStarted); |
| 431 | 432 |
| 432 // Clears the existing image, if instructed by |updateImageOption|. | 433 // Clears the existing image, if instructed by |updateImageOption|. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 445 DCHECK(!data); | 446 DCHECK(!data); |
| 446 break; | 447 break; |
| 447 | 448 |
| 448 case kUpdateImage: | 449 case kUpdateImage: |
| 449 case kClearAndUpdateImage: | 450 case kClearAndUpdateImage: |
| 450 // Have the image update its data from its internal buffer. It will not do | 451 // Have the image update its data from its internal buffer. It will not do |
| 451 // anything now, but will delay decoding until queried for info (like size | 452 // anything now, but will delay decoding until queried for info (like size |
| 452 // or specific image frames). | 453 // or specific image frames). |
| 453 if (data) { | 454 if (data) { |
| 454 if (!image_) | 455 if (!image_) |
| 455 image_ = CreateImage(); | 456 image_ = CreateImage(is_multipart); |
| 456 DCHECK(image_); | 457 DCHECK(image_); |
| 457 size_available_ = image_->SetData(std::move(data), all_data_received); | 458 size_available_ = image_->SetData(std::move(data), all_data_received); |
| 458 DCHECK(all_data_received || | 459 DCHECK(all_data_received || |
| 459 size_available_ != | 460 size_available_ != |
| 460 Image::kSizeAvailableAndLoadingAsynchronously); | 461 Image::kSizeAvailableAndLoadingAsynchronously); |
| 461 } | 462 } |
| 462 | 463 |
| 463 // Go ahead and tell our observers to try to draw if we have either | 464 // Go ahead and tell our observers to try to draw if we have either |
| 464 // received all the data or the size is known. Each chunk from the network | 465 // received all the data or the size is known. Each chunk from the network |
| 465 // causes observers to repaint, which will force that chunk to decode. | 466 // causes observers to repaint, which will force that chunk to decode. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 622 |
| 622 const ResourceResponse& ImageResourceContent::GetResponse() const { | 623 const ResourceResponse& ImageResourceContent::GetResponse() const { |
| 623 return info_->GetResponse(); | 624 return info_->GetResponse(); |
| 624 } | 625 } |
| 625 | 626 |
| 626 const ResourceError& ImageResourceContent::GetResourceError() const { | 627 const ResourceError& ImageResourceContent::GetResourceError() const { |
| 627 return info_->GetResourceError(); | 628 return info_->GetResourceError(); |
| 628 } | 629 } |
| 629 | 630 |
| 630 } // namespace blink | 631 } // namespace blink |
| OLD | NEW |