Chromium Code Reviews| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 | 117 |
| 118 void ImageResource::addObserver(ImageResourceObserver* observer) | 118 void ImageResource::addObserver(ImageResourceObserver* observer) |
| 119 { | 119 { |
| 120 willAddClientOrObserver(); | 120 willAddClientOrObserver(); |
| 121 | 121 |
| 122 m_observers.add(observer); | 122 m_observers.add(observer); |
| 123 | 123 |
| 124 if (isCacheValidator()) | 124 if (isCacheValidator()) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 if (m_data && !m_image && !errorOccurred()) { | 127 DCHECK(!m_data || m_image); |
| 128 createImage(); | |
| 129 m_image->setData(m_data, true); | |
| 130 } | |
| 131 | 128 |
| 132 if (m_image && !m_image->isNull()) { | 129 if (m_image && !m_image->isNull()) { |
| 133 observer->imageChanged(this); | 130 observer->imageChanged(this); |
| 134 } | 131 } |
| 135 | 132 |
| 136 if (isLoaded()) { | 133 if (isLoaded()) { |
| 137 observer->imageNotifyFinished(this); | 134 observer->imageNotifyFinished(this); |
| 138 if (m_observers.contains(observer)) { | 135 if (m_observers.contains(observer)) { |
| 139 m_finishedObservers.add(observer); | 136 m_finishedObservers.add(observer); |
| 140 m_observers.remove(observer); | 137 m_observers.remove(observer); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 } | 180 } |
| 184 | 181 |
| 185 bool ImageResource::isSafeToUnlock() const | 182 bool ImageResource::isSafeToUnlock() const |
| 186 { | 183 { |
| 187 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. | 184 // Note that |m_image| holds a reference to |m_data| in addition to the one held by the Resource parent class. |
| 188 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); | 185 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); |
| 189 } | 186 } |
| 190 | 187 |
| 191 void ImageResource::destroyDecodedDataForFailedRevalidation() | 188 void ImageResource::destroyDecodedDataForFailedRevalidation() |
| 192 { | 189 { |
| 193 m_image = nullptr; | 190 m_image->destroyDecodedData(); |
|
haraken
2016/06/23 01:26:40
Honestly speaking, I don't fully understand change
hajimehoshi
2016/06/23 09:23:12
Before this CL, m_data is a primary data and m_ima
| |
| 194 setDecodedSize(0); | |
| 195 } | 191 } |
| 196 | 192 |
| 197 void ImageResource::destroyDecodedDataIfPossible() | 193 void ImageResource::destroyDecodedDataIfPossible() |
| 198 { | 194 { |
| 199 if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOn eRef() && m_image->isBitmapImage()))) { | 195 if (!m_image) |
| 200 m_image = nullptr; | 196 return; |
| 201 setDecodedSize(0); | 197 if ((!hasClientsOrObservers() && !isLoading() && m_image->hasOneRef() && m_i mage->isBitmapImage()) || !errorOccurred()) |
| 202 } else if (m_image && !errorOccurred()) { | |
| 203 m_image->destroyDecodedData(); | 198 m_image->destroyDecodedData(); |
| 204 } | |
| 205 } | 199 } |
| 206 | 200 |
| 207 void ImageResource::doResetAnimation() | 201 void ImageResource::doResetAnimation() |
| 208 { | 202 { |
| 209 if (m_image) | 203 if (m_image) |
| 210 m_image->resetAnimation(); | 204 m_image->resetAnimation(); |
| 211 } | 205 } |
| 212 | 206 |
| 213 void ImageResource::allClientsAndObserversRemoved() | 207 void ImageResource::allClientsAndObserversRemoved() |
| 214 { | 208 { |
| 215 if (m_image && !errorOccurred()) { | 209 if (m_image && !errorOccurred()) { |
| 216 // If possible, delay the resetting until back at the event loop. | 210 // If possible, delay the resetting until back at the event loop. |
| 217 // Doing so after a conservative GC prevents resetAnimation() from | 211 // Doing so after a conservative GC prevents resetAnimation() from |
| 218 // upsetting ongoing animation updates (crbug.com/613709) | 212 // upsetting ongoing animation updates (crbug.com/613709) |
| 219 if (!ThreadHeap::willObjectBeLazilySwept(this)) | 213 if (!ThreadHeap::willObjectBeLazilySwept(this)) |
| 220 Platform::current()->currentThread()->getWebTaskRunner()->postTask(B LINK_FROM_HERE, bind(&ImageResource::doResetAnimation, WeakPersistentThisPointer <ImageResource>(this))); | 214 Platform::current()->currentThread()->getWebTaskRunner()->postTask(B LINK_FROM_HERE, bind(&ImageResource::doResetAnimation, WeakPersistentThisPointer <ImageResource>(this))); |
| 221 else | 215 else |
| 222 m_image->resetAnimation(); | 216 m_image->resetAnimation(); |
| 223 } | 217 } |
| 224 if (m_multipartParser) | 218 if (m_multipartParser) |
| 225 m_multipartParser->cancel(); | 219 m_multipartParser->cancel(); |
| 226 Resource::allClientsAndObserversRemoved(); | 220 Resource::allClientsAndObserversRemoved(); |
| 227 } | 221 } |
| 228 | 222 |
| 223 PassRefPtr<SharedBuffer> ImageResource::resourceBuffer() const | |
| 224 { | |
| 225 RefPtr<SharedBuffer> data = Resource::resourceBuffer(); | |
| 226 if (data) | |
| 227 return data; | |
| 228 if (m_image) | |
| 229 return m_image->data(); | |
| 230 return nullptr; | |
| 231 } | |
| 232 | |
| 229 void ImageResource::appendData(const char* data, size_t length) | 233 void ImageResource::appendData(const char* data, size_t length) |
| 230 { | 234 { |
| 231 if (m_multipartParser) { | 235 if (m_multipartParser) { |
| 232 m_multipartParser->appendData(data, length); | 236 m_multipartParser->appendData(data, length); |
| 233 } else { | 237 } else { |
| 234 Resource::appendData(data, length); | 238 Resource::appendData(data, length); |
| 235 updateImage(false); | 239 updateImage(false); |
| 236 } | 240 } |
| 237 } | 241 } |
| 238 | 242 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 } | 352 } |
| 349 | 353 |
| 350 inline void ImageResource::clearImage() | 354 inline void ImageResource::clearImage() |
| 351 { | 355 { |
| 352 if (!m_image) | 356 if (!m_image) |
| 353 return; | 357 return; |
| 354 | 358 |
| 355 // If our Image has an observer, it's always us so we need to clear the back pointer | 359 // If our Image has an observer, it's always us so we need to clear the back pointer |
| 356 // before dropping our reference. | 360 // before dropping our reference. |
| 357 m_image->clearImageObserver(); | 361 m_image->clearImageObserver(); |
| 358 m_image.clear(); | |
| 359 } | 362 } |
| 360 | 363 |
| 361 void ImageResource::updateImage(bool allDataReceived) | 364 void ImageResource::updateImage(bool allDataReceived) |
| 362 { | 365 { |
| 363 TRACE_EVENT0("blink", "ImageResource::updateImage"); | 366 TRACE_EVENT0("blink", "ImageResource::updateImage"); |
| 364 | 367 |
| 365 if (m_data) | 368 if (m_data) |
| 366 createImage(); | 369 createImage(); |
| 367 | 370 |
| 368 bool sizeAvailable = false; | 371 bool sizeAvailable = false; |
| 369 | 372 |
| 370 // Have the image update its data from its internal buffer. | 373 // Have the image update its data from its internal buffer. |
| 371 // It will not do anything now, but will delay decoding until | 374 // It will not do anything now, but will delay decoding until |
| 372 // queried for info (like size or specific image frames). | 375 // queried for info (like size or specific image frames). |
| 373 if (m_image) | 376 if (m_image && m_data) |
| 374 sizeAvailable = m_image->setData(m_data, allDataReceived); | 377 sizeAvailable = m_image->setData(m_data, allDataReceived); |
| 375 | 378 |
| 376 // Go ahead and tell our observers to try to draw if we have either | 379 // Go ahead and tell our observers to try to draw if we have either |
| 377 // received all the data or the size is known. Each chunk from the | 380 // received all the data or the size is known. Each chunk from the |
| 378 // network causes observers to repaint, which will force that chunk | 381 // network causes observers to repaint, which will force that chunk |
| 379 // to decode. | 382 // to decode. |
| 380 if (sizeAvailable || allDataReceived) { | 383 if (sizeAvailable || allDataReceived) { |
| 381 if (!m_image || m_image->isNull()) { | 384 if (!m_image || m_image->isNull()) { |
| 382 if (!errorOccurred()) | 385 if (!errorOccurred()) |
| 383 setStatus(DecodeError); | 386 setStatus(DecodeError); |
| 384 clear(); | 387 clear(); |
| 385 if (memoryCache()->contains(this)) | 388 if (memoryCache()->contains(this)) |
| 386 memoryCache()->remove(this); | 389 memoryCache()->remove(this); |
| 387 } | 390 } |
| 388 | 391 |
| 389 // It would be nice to only redraw the decoded band of the image, but wi th the current design | 392 // It would be nice to only redraw the decoded band of the image, but wi th the current design |
| 390 // (decoding delayed until painting) that seems hard. | 393 // (decoding delayed until painting) that seems hard. |
| 391 notifyObservers(); | 394 notifyObservers(); |
| 392 } | 395 } |
| 396 | |
| 397 if (allDataReceived) | |
| 398 m_data.clear(); | |
| 393 } | 399 } |
| 394 | 400 |
| 395 void ImageResource::updateImageAndClearBuffer() | 401 void ImageResource::updateImageAndClearBuffer() |
| 396 { | 402 { |
| 397 clearImage(); | 403 clearImage(); |
| 398 updateImage(true); | 404 updateImage(true); |
| 399 m_data.clear(); | |
| 400 } | 405 } |
| 401 | 406 |
| 402 void ImageResource::finish(double loadFinishTime) | 407 void ImageResource::finish(double loadFinishTime) |
| 403 { | 408 { |
| 404 if (m_multipartParser) { | 409 if (m_multipartParser) { |
| 405 m_multipartParser->finish(); | 410 m_multipartParser->finish(); |
| 406 if (m_data) | 411 if (m_data) |
| 407 updateImageAndClearBuffer(); | 412 updateImageAndClearBuffer(); |
| 408 } else { | 413 } else { |
| 409 updateImage(true); | 414 updateImage(true); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 if (response().wasFetchedViaServiceWorker()) | 569 if (response().wasFetchedViaServiceWorker()) |
| 565 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; | 570 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; |
| 566 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 571 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 567 return false; | 572 return false; |
| 568 if (passesAccessControlCheck(securityOrigin)) | 573 if (passesAccessControlCheck(securityOrigin)) |
| 569 return true; | 574 return true; |
| 570 return !securityOrigin->taintsCanvas(response().url()); | 575 return !securityOrigin->taintsCanvas(response().url()); |
| 571 } | 576 } |
| 572 | 577 |
| 573 } // namespace blink | 578 } // namespace blink |
| OLD | NEW |