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