| 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 "core/loader/resource/ImageResource.h" | 7 #include "core/loader/resource/ImageResource.h" |
| 8 #include "core/loader/resource/ImageResourceInfo.h" | 8 #include "core/loader/resource/ImageResourceInfo.h" |
| 9 #include "core/loader/resource/ImageResourceObserver.h" | 9 #include "core/loader/resource/ImageResourceObserver.h" |
| 10 #include "core/svg/graphics/SVGImage.h" | 10 #include "core/svg/graphics/SVGImage.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 bool isAccessAllowed( | 47 bool isAccessAllowed( |
| 48 SecurityOrigin*, | 48 SecurityOrigin*, |
| 49 DoesCurrentFrameHaveSingleSecurityOrigin) const override { | 49 DoesCurrentFrameHaveSingleSecurityOrigin) const override { |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 bool hasCacheControlNoStoreHeader() const override { return false; } | 52 bool hasCacheControlNoStoreHeader() const override { return false; } |
| 53 const ResourceError& resourceError() const override { return m_error; } | 53 const ResourceError& resourceError() const override { return m_error; } |
| 54 | 54 |
| 55 void decodeError(bool allDataReceived) override {} | |
| 56 void setDecodedSize(size_t) override {} | 55 void setDecodedSize(size_t) override {} |
| 57 void setIsPlaceholder(bool) override {} | 56 void setIsPlaceholder(bool) override {} |
| 58 void willAddClientOrObserver() override {} | 57 void willAddClientOrObserver() override {} |
| 59 void didRemoveClientOrObserver() override {} | 58 void didRemoveClientOrObserver() override {} |
| 60 void emulateLoadStartedForInspector( | 59 void emulateLoadStartedForInspector( |
| 61 ResourceFetcher*, | 60 ResourceFetcher*, |
| 62 const KURL&, | 61 const KURL&, |
| 63 const AtomicString& initiatorName) override {} | 62 const AtomicString& initiatorName) override {} |
| 64 | 63 |
| 65 const KURL m_url; | 64 const KURL m_url; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 return true; | 321 return true; |
| 323 | 322 |
| 324 // Don't treat a complete and broken image as a placeholder if the response | 323 // Don't treat a complete and broken image as a placeholder if the response |
| 325 // code is something other than a 4xx or 5xx error. This is done to prevent | 324 // code is something other than a 4xx or 5xx error. This is done to prevent |
| 326 // reissuing the request in cases like "204 No Content" responses to tracking | 325 // reissuing the request in cases like "204 No Content" responses to tracking |
| 327 // requests triggered by <img> tags, and <img> tags used to preload non-image | 326 // requests triggered by <img> tags, and <img> tags used to preload non-image |
| 328 // resources. | 327 // resources. |
| 329 return response.httpStatusCode() < 400 || response.httpStatusCode() >= 600; | 328 return response.httpStatusCode() < 400 || response.httpStatusCode() >= 600; |
| 330 } | 329 } |
| 331 | 330 |
| 332 void ImageResourceContent::updateImage(PassRefPtr<SharedBuffer> data, | 331 ImageResourceContent::UpdateImageResult ImageResourceContent::updateImage( |
| 333 UpdateImageOption updateImageOption, | 332 PassRefPtr<SharedBuffer> data, |
| 334 bool allDataReceived) { | 333 UpdateImageOption updateImageOption, |
| 334 bool allDataReceived) { |
| 335 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); | 335 TRACE_EVENT0("blink", "ImageResourceContent::updateImage"); |
| 336 | 336 |
| 337 #if DCHECK_IS_ON() |
| 338 DCHECK(!m_isUpdateImageBeingCalled); |
| 339 AutoReset<bool> scope(&m_isUpdateImageBeingCalled, true); |
| 340 #endif |
| 341 |
| 337 // Clears the existing image, if instructed by |updateImageOption|. | 342 // Clears the existing image, if instructed by |updateImageOption|. |
| 338 switch (updateImageOption) { | 343 switch (updateImageOption) { |
| 339 case ClearAndUpdateImage: | 344 case ClearAndUpdateImage: |
| 340 case ClearImageAndNotifyObservers: | 345 case ClearImageAndNotifyObservers: |
| 341 clearImage(); | 346 clearImage(); |
| 342 break; | 347 break; |
| 343 case UpdateImage: | 348 case UpdateImage: |
| 344 break; | 349 break; |
| 345 } | 350 } |
| 346 | 351 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 359 if (!m_image) | 364 if (!m_image) |
| 360 m_image = createImage(); | 365 m_image = createImage(); |
| 361 DCHECK(m_image); | 366 DCHECK(m_image); |
| 362 m_sizeAvailable = m_image->setData(std::move(data), allDataReceived); | 367 m_sizeAvailable = m_image->setData(std::move(data), allDataReceived); |
| 363 } | 368 } |
| 364 | 369 |
| 365 // Go ahead and tell our observers to try to draw if we have either | 370 // Go ahead and tell our observers to try to draw if we have either |
| 366 // received all the data or the size is known. Each chunk from the network | 371 // received all the data or the size is known. Each chunk from the network |
| 367 // causes observers to repaint, which will force that chunk to decode. | 372 // causes observers to repaint, which will force that chunk to decode. |
| 368 if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived) | 373 if (m_sizeAvailable == Image::SizeUnavailable && !allDataReceived) |
| 369 return; | 374 return UpdateImageResult::NoDecodeError; |
| 370 | 375 |
| 371 if (m_info->isPlaceholder() && allDataReceived) { | 376 if (m_info->isPlaceholder() && allDataReceived) { |
| 372 if (shouldShowFullImageInsteadOfPlaceholder(response(), | 377 if (shouldShowFullImageInsteadOfPlaceholder(response(), |
| 373 m_image.get())) { | 378 m_image.get())) { |
| 374 m_info->setIsPlaceholder(false); | 379 m_info->setIsPlaceholder(false); |
| 375 } else if (m_image && !m_image->isNull()) { | 380 } else if (m_image && !m_image->isNull()) { |
| 376 IntSize dimensions = m_image->size(); | 381 IntSize dimensions = m_image->size(); |
| 377 clearImage(); | 382 clearImage(); |
| 378 m_image = PlaceholderImage::create(this, dimensions); | 383 m_image = PlaceholderImage::create(this, dimensions); |
| 379 } | 384 } |
| 380 } | 385 } |
| 381 | 386 |
| 382 if (!m_image || m_image->isNull()) { | 387 if (!m_image || m_image->isNull()) { |
| 383 clearImage(); | 388 clearImage(); |
| 384 m_info->decodeError(allDataReceived); | 389 return UpdateImageResult::ShouldDecodeError; |
| 385 } | 390 } |
| 386 break; | 391 break; |
| 387 } | 392 } |
| 388 | 393 |
| 389 // Notifies the observers. | 394 // Notifies the observers. |
| 390 // It would be nice to only redraw the decoded band of the image, but with the | 395 // It would be nice to only redraw the decoded band of the image, but with the |
| 391 // current design (decoding delayed until painting) that seems hard. | 396 // current design (decoding delayed until painting) that seems hard. |
| 392 notifyObservers(allDataReceived ? ShouldNotifyFinish : DoNotNotifyFinish); | 397 notifyObservers(allDataReceived ? ShouldNotifyFinish : DoNotNotifyFinish); |
| 398 return UpdateImageResult::NoDecodeError; |
| 393 } | 399 } |
| 394 | 400 |
| 395 void ImageResourceContent::decodedSizeChangedTo(const blink::Image* image, | 401 void ImageResourceContent::decodedSizeChangedTo(const blink::Image* image, |
| 396 size_t newSize) { | 402 size_t newSize) { |
| 397 if (!image || image != m_image) | 403 if (!image || image != m_image) |
| 398 return; | 404 return; |
| 399 | 405 |
| 400 m_info->setDecodedSize(newSize); | 406 m_info->setDecodedSize(newSize); |
| 401 } | 407 } |
| 402 | 408 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 511 |
| 506 const ResourceResponse& ImageResourceContent::response() const { | 512 const ResourceResponse& ImageResourceContent::response() const { |
| 507 return m_info->response(); | 513 return m_info->response(); |
| 508 } | 514 } |
| 509 | 515 |
| 510 const ResourceError& ImageResourceContent::resourceError() const { | 516 const ResourceError& ImageResourceContent::resourceError() const { |
| 511 return m_info->resourceError(); | 517 return m_info->resourceError(); |
| 512 } | 518 } |
| 513 | 519 |
| 514 } // namespace blink | 520 } // namespace blink |
| OLD | NEW |