| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 6 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 void ImageResource::addObserver(ImageResourceObserver* observer) { | 131 void ImageResource::addObserver(ImageResourceObserver* observer) { |
| 132 willAddClientOrObserver(MarkAsReferenced); | 132 willAddClientOrObserver(MarkAsReferenced); |
| 133 | 133 |
| 134 m_observers.add(observer); | 134 m_observers.add(observer); |
| 135 | 135 |
| 136 if (isCacheValidator()) | 136 if (isCacheValidator()) |
| 137 return; | 137 return; |
| 138 | 138 |
| 139 // When the response is not multipart, if |data()| exists, |m_image| must be | 139 // When the response is not multipart, if |data()| exists, |m_image| must be |
| 140 // created. This is assured that |updateImage()| is called when | 140 // created. This is assured that |updateImage()| is called when |appendData()| |
| 141 // |appendData()| is called. | 141 // is called. |
| 142 // | 142 // |
| 143 // On the other hand, when the response is multipart, |updateImage()| is | 143 // On the other hand, when the response is multipart, |updateImage()| is not |
| 144 // not called in |appendData()|, which means |m_image| might not be created | 144 // called in |appendData()|, which means |m_image| might not be created even |
| 145 // even when |data()| exists. This is intentional since creating a |m_image| | 145 // when |data()| exists. This is intentional since creating a |m_image| on |
| 146 // on receiving data might destroy an existing image in a previous part. | 146 // receiving data might destroy an existing image in a previous part. |
| 147 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); | 147 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); |
| 148 | 148 |
| 149 if (m_image && !m_image->isNull()) { | 149 if (m_image && !m_image->isNull()) { |
| 150 observer->imageChanged(this); | 150 observer->imageChanged(this); |
| 151 } | 151 } |
| 152 | 152 |
| 153 if (isLoaded()) { | 153 if (isLoaded()) { |
| 154 markObserverFinished(observer); | 154 markObserverFinished(observer); |
| 155 observer->imageNotifyFinished(this); | 155 observer->imageNotifyFinished(this); |
| 156 } | 156 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 void ImageResource::doResetAnimation() { | 208 void ImageResource::doResetAnimation() { |
| 209 if (m_image) | 209 if (m_image) |
| 210 m_image->resetAnimation(); | 210 m_image->resetAnimation(); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void ImageResource::allClientsAndObserversRemoved() { | 213 void ImageResource::allClientsAndObserversRemoved() { |
| 214 if (m_image) { | 214 if (m_image) { |
| 215 CHECK(!errorOccurred()); | 215 CHECK(!errorOccurred()); |
| 216 // If possible, delay the resetting until back at the event loop. | 216 // If possible, delay the resetting until back at the event loop. Doing so |
| 217 // Doing so after a conservative GC prevents resetAnimation() from | 217 // after a conservative GC prevents resetAnimation() from upsetting ongoing |
| 218 // upsetting ongoing animation updates (crbug.com/613709) | 218 // animation updates (crbug.com/613709) |
| 219 if (!ThreadHeap::willObjectBeLazilySwept(this)) | 219 if (!ThreadHeap::willObjectBeLazilySwept(this)) |
| 220 Platform::current()->currentThread()->getWebTaskRunner()->postTask( | 220 Platform::current()->currentThread()->getWebTaskRunner()->postTask( |
| 221 BLINK_FROM_HERE, WTF::bind(&ImageResource::doResetAnimation, | 221 BLINK_FROM_HERE, WTF::bind(&ImageResource::doResetAnimation, |
| 222 wrapWeakPersistent(this))); | 222 wrapWeakPersistent(this))); |
| 223 else | 223 else |
| 224 m_image->resetAnimation(); | 224 m_image->resetAnimation(); |
| 225 } | 225 } |
| 226 if (m_multipartParser) | 226 if (m_multipartParser) |
| 227 m_multipartParser->cancel(); | 227 m_multipartParser->cancel(); |
| 228 Resource::allClientsAndObserversRemoved(); | 228 Resource::allClientsAndObserversRemoved(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 258 (blink::Image::loadPlatformResource("missingImage"))); | 258 (blink::Image::loadPlatformResource("missingImage"))); |
| 259 return std::make_pair(brokenImageLoRes, 1); | 259 return std::make_pair(brokenImageLoRes, 1); |
| 260 } | 260 } |
| 261 | 261 |
| 262 bool ImageResource::willPaintBrokenImage() const { | 262 bool ImageResource::willPaintBrokenImage() const { |
| 263 return errorOccurred(); | 263 return errorOccurred(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 blink::Image* ImageResource::getImage() { | 266 blink::Image* ImageResource::getImage() { |
| 267 if (errorOccurred()) { | 267 if (errorOccurred()) { |
| 268 // Returning the 1x broken image is non-ideal, but we cannot reliably access
the appropriate | 268 // Returning the 1x broken image is non-ideal, but we cannot reliably access |
| 269 // deviceScaleFactor from here. It is critical that callers use ImageResourc
e::brokenImage() | 269 // the appropriate deviceScaleFactor from here. It is critical that callers |
| 270 // when they need the real, deviceScaleFactor-appropriate broken image icon. | 270 // use ImageResource::brokenImage() when they need the real, |
| 271 // deviceScaleFactor-appropriate broken image icon. |
| 271 return brokenImage(1).first; | 272 return brokenImage(1).first; |
| 272 } | 273 } |
| 273 | 274 |
| 274 if (m_image) | 275 if (m_image) |
| 275 return m_image.get(); | 276 return m_image.get(); |
| 276 | 277 |
| 277 return blink::Image::nullImage(); | 278 return blink::Image::nullImage(); |
| 278 } | 279 } |
| 279 | 280 |
| 280 bool ImageResource::usesImageContainerSize() const { | 281 bool ImageResource::usesImageContainerSize() const { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 m_image = BitmapImage::create(this); | 352 m_image = BitmapImage::create(this); |
| 352 } | 353 } |
| 353 } | 354 } |
| 354 | 355 |
| 355 inline void ImageResource::clearImage() { | 356 inline void ImageResource::clearImage() { |
| 356 if (!m_image) | 357 if (!m_image) |
| 357 return; | 358 return; |
| 358 int64_t length = m_image->data() ? m_image->data()->size() : 0; | 359 int64_t length = m_image->data() ? m_image->data()->size() : 0; |
| 359 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); | 360 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-length); |
| 360 | 361 |
| 361 // If our Image has an observer, it's always us so we need to clear the back p
ointer | 362 // If our Image has an observer, it's always us so we need to clear the back |
| 362 // before dropping our reference. | 363 // pointer before dropping our reference. |
| 363 m_image->clearImageObserver(); | 364 m_image->clearImageObserver(); |
| 364 m_image.clear(); | 365 m_image.clear(); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void ImageResource::updateImage(bool allDataReceived) { | 368 void ImageResource::updateImage(bool allDataReceived) { |
| 368 TRACE_EVENT0("blink", "ImageResource::updateImage"); | 369 TRACE_EVENT0("blink", "ImageResource::updateImage"); |
| 369 | 370 |
| 370 if (data()) | 371 if (data()) |
| 371 createImage(); | 372 createImage(); |
| 372 | 373 |
| 373 Image::SizeAvailability sizeAvailable = Image::SizeUnavailable; | 374 Image::SizeAvailability sizeAvailable = Image::SizeUnavailable; |
| 374 | 375 |
| 375 // Have the image update its data from its internal buffer. | 376 // Have the image update its data from its internal buffer. It will not do |
| 376 // It will not do anything now, but will delay decoding until | 377 // anything now, but will delay decoding until queried for info (like size or |
| 377 // queried for info (like size or specific image frames). | 378 // specific image frames). |
| 378 if (data()) { | 379 if (data()) { |
| 379 DCHECK(m_image); | 380 DCHECK(m_image); |
| 380 sizeAvailable = m_image->setData(data(), allDataReceived); | 381 sizeAvailable = m_image->setData(data(), allDataReceived); |
| 381 } | 382 } |
| 382 | 383 |
| 383 // Go ahead and tell our observers to try to draw if we have either | 384 // Go ahead and tell our observers to try to draw if we have either received |
| 384 // received all the data or the size is known. Each chunk from the | 385 // all the data or the size is known. Each chunk from the network causes |
| 385 // network causes observers to repaint, which will force that chunk | 386 // observers to repaint, which will force that chunk to decode. |
| 386 // to decode. | |
| 387 if (sizeAvailable == Image::SizeUnavailable && !allDataReceived) | 387 if (sizeAvailable == Image::SizeUnavailable && !allDataReceived) |
| 388 return; | 388 return; |
| 389 if (!m_image || m_image->isNull()) { | 389 if (!m_image || m_image->isNull()) { |
| 390 size_t size = encodedSize(); | 390 size_t size = encodedSize(); |
| 391 clear(); | 391 clear(); |
| 392 if (!errorOccurred()) | 392 if (!errorOccurred()) |
| 393 setStatus(DecodeError); | 393 setStatus(DecodeError); |
| 394 if (!allDataReceived && loader()) | 394 if (!allDataReceived && loader()) |
| 395 loader()->didFinishLoading(nullptr, monotonicallyIncreasingTime(), size); | 395 loader()->didFinishLoading(nullptr, monotonicallyIncreasingTime(), size); |
| 396 memoryCache()->remove(this); | 396 memoryCache()->remove(this); |
| 397 } | 397 } |
| 398 | 398 |
| 399 // It would be nice to only redraw the decoded band of the image, but with the
current design | 399 // It would be nice to only redraw the decoded band of the image, but with the |
| 400 // (decoding delayed until painting) that seems hard. | 400 // current design (decoding delayed until painting) that seems hard. |
| 401 notifyObservers(); | 401 notifyObservers(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 void ImageResource::updateImageAndClearBuffer() { | 404 void ImageResource::updateImageAndClearBuffer() { |
| 405 clearImage(); | 405 clearImage(); |
| 406 updateImage(true); | 406 updateImage(true); |
| 407 clearData(); | 407 clearData(); |
| 408 } | 408 } |
| 409 | 409 |
| 410 void ImageResource::finish(double loadFinishTime) { | 410 void ImageResource::finish(double loadFinishTime) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 size_t newSize) { | 467 size_t newSize) { |
| 468 if (!image || image != m_image) | 468 if (!image || image != m_image) |
| 469 return; | 469 return; |
| 470 | 470 |
| 471 setDecodedSize(newSize); | 471 setDecodedSize(newSize); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void ImageResource::didDraw(const blink::Image* image) { | 474 void ImageResource::didDraw(const blink::Image* image) { |
| 475 if (!image || image != m_image) | 475 if (!image || image != m_image) |
| 476 return; | 476 return; |
| 477 // decodedSize() == 0 indicates that the image is decoded into DiscardableMemo
ry, | 477 // decodedSize() == 0 indicates that the image is decoded into |
| 478 // not in MemoryCache. So we don't need to call Resource::didAccessDecodedData
() | 478 // DiscardableMemory, not in MemoryCache. So we don't need to call |
| 479 // to update MemoryCache. | 479 // Resource::didAccessDecodedData() to update MemoryCache. |
| 480 if (decodedSize() != 0) | 480 if (decodedSize() != 0) |
| 481 Resource::didAccessDecodedData(); | 481 Resource::didAccessDecodedData(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 bool ImageResource::shouldPauseAnimation(const blink::Image* image) { | 484 bool ImageResource::shouldPauseAnimation(const blink::Image* image) { |
| 485 if (!image || image != m_image) | 485 if (!image || image != m_image) |
| 486 return false; | 486 return false; |
| 487 | 487 |
| 488 for (auto* observer : m_finishedObservers.asVector()) { | 488 for (auto* observer : m_finishedObservers.asVector()) { |
| 489 if (m_finishedObservers.contains(observer) && observer->willRenderImage()) | 489 if (m_finishedObservers.contains(observer) && observer->willRenderImage()) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 return response().serviceWorkerResponseType() != | 586 return response().serviceWorkerResponseType() != |
| 587 WebServiceWorkerResponseTypeOpaque; | 587 WebServiceWorkerResponseTypeOpaque; |
| 588 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 588 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 589 return false; | 589 return false; |
| 590 if (passesAccessControlCheck(securityOrigin)) | 590 if (passesAccessControlCheck(securityOrigin)) |
| 591 return true; | 591 return true; |
| 592 return !securityOrigin->taintsCanvas(response().url()); | 592 return !securityOrigin->taintsCanvas(response().url()); |
| 593 } | 593 } |
| 594 | 594 |
| 595 } // namespace blink | 595 } // namespace blink |
| OLD | NEW |