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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 void ImageResource::markClientsAndObserversFinished() | 108 void ImageResource::markClientsAndObserversFinished() |
| 109 { | 109 { |
| 110 HashCountedSet<ImageResourceObserver*> observers; | 110 HashCountedSet<ImageResourceObserver*> observers; |
| 111 m_observers.swap(observers); | 111 m_observers.swap(observers); |
| 112 for (const auto& it : observers) | 112 for (const auto& it : observers) |
| 113 m_finishedObservers.add(it.key, it.value); | 113 m_finishedObservers.add(it.key, it.value); |
| 114 | 114 |
| 115 Resource::markClientsAndObserversFinished(); | 115 Resource::markClientsAndObserversFinished(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void ImageResource::ensureImage() | |
| 119 { | |
| 120 if (m_data && !m_image && !errorOccurred()) { | |
| 121 createImage(); | |
| 122 m_image->setData(m_data, true); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 void ImageResource::didAddClient(ResourceClient* client) | |
| 127 { | |
| 128 ensureImage(); | |
| 129 Resource::didAddClient(client); | |
| 130 } | |
| 131 | |
| 132 void ImageResource::addObserver(ImageResourceObserver* observer) | 118 void ImageResource::addObserver(ImageResourceObserver* observer) |
| 133 { | 119 { |
| 134 willAddClientOrObserver(); | 120 willAddClientOrObserver(); |
| 135 | 121 |
| 136 m_observers.add(observer); | 122 m_observers.add(observer); |
| 137 | 123 |
| 138 if (isCacheValidator()) | 124 if (isCacheValidator()) |
| 139 return; | 125 return; |
| 140 | 126 |
| 141 ensureImage(); | 127 DCHECK(!m_data || m_image); |
| 142 | 128 |
| 143 if (m_image && !m_image->isNull()) { | 129 if (m_image && !m_image->isNull()) { |
| 144 observer->imageChanged(this); | 130 observer->imageChanged(this); |
| 145 } | 131 } |
| 146 | 132 |
| 147 if (isLoaded()) { | 133 if (isLoaded()) { |
| 148 observer->imageNotifyFinished(this); | 134 observer->imageNotifyFinished(this); |
| 149 if (m_observers.contains(observer)) { | 135 if (m_observers.contains(observer)) { |
| 150 m_finishedObservers.add(observer); | 136 m_finishedObservers.add(observer); |
| 151 m_observers.remove(observer); | 137 m_observers.remove(observer); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 } | 186 } |
| 201 | 187 |
| 202 void ImageResource::destroyDecodedDataForFailedRevalidation() | 188 void ImageResource::destroyDecodedDataForFailedRevalidation() |
| 203 { | 189 { |
| 204 clearImage(); | 190 clearImage(); |
| 205 setDecodedSize(0); | 191 setDecodedSize(0); |
| 206 } | 192 } |
| 207 | 193 |
| 208 void ImageResource::destroyDecodedDataIfPossible() | 194 void ImageResource::destroyDecodedDataIfPossible() |
| 209 { | 195 { |
| 210 if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOn eRef() && m_image->isBitmapImage()))) { | 196 if (!m_image) |
| 211 clearImage(); | 197 return; |
| 212 setDecodedSize(0); | 198 if ((!hasClientsOrObservers() && !isLoading() && m_image->hasOneRef() && m_i mage->isBitmapImage()) || !errorOccurred()) |
| 213 } else if (m_image && !errorOccurred()) { | |
| 214 m_image->destroyDecodedData(); | 199 m_image->destroyDecodedData(); |
| 215 } | |
| 216 } | 200 } |
| 217 | 201 |
| 218 void ImageResource::doResetAnimation() | 202 void ImageResource::doResetAnimation() |
| 219 { | 203 { |
| 220 if (m_image) | 204 if (m_image) |
| 221 m_image->resetAnimation(); | 205 m_image->resetAnimation(); |
| 222 } | 206 } |
| 223 | 207 |
| 224 void ImageResource::allClientsAndObserversRemoved() | 208 void ImageResource::allClientsAndObserversRemoved() |
| 225 { | 209 { |
| 226 if (m_image && !errorOccurred()) { | 210 if (m_image && !errorOccurred()) { |
| 227 // If possible, delay the resetting until back at the event loop. | 211 // If possible, delay the resetting until back at the event loop. |
| 228 // Doing so after a conservative GC prevents resetAnimation() from | 212 // Doing so after a conservative GC prevents resetAnimation() from |
| 229 // upsetting ongoing animation updates (crbug.com/613709) | 213 // upsetting ongoing animation updates (crbug.com/613709) |
| 230 if (!ThreadHeap::willObjectBeLazilySwept(this)) | 214 if (!ThreadHeap::willObjectBeLazilySwept(this)) |
| 231 Platform::current()->currentThread()->getWebTaskRunner()->postTask(B LINK_FROM_HERE, WTF::bind(&ImageResource::doResetAnimation, wrapWeakPersistent(t his))); | 215 Platform::current()->currentThread()->getWebTaskRunner()->postTask(B LINK_FROM_HERE, WTF::bind(&ImageResource::doResetAnimation, wrapWeakPersistent(t his))); |
| 232 else | 216 else |
| 233 m_image->resetAnimation(); | 217 m_image->resetAnimation(); |
| 234 } | 218 } |
| 235 if (m_multipartParser) | 219 if (m_multipartParser) |
| 236 m_multipartParser->cancel(); | 220 m_multipartParser->cancel(); |
| 237 Resource::allClientsAndObserversRemoved(); | 221 Resource::allClientsAndObserversRemoved(); |
| 238 } | 222 } |
| 239 | 223 |
| 224 PassRefPtr<SharedBuffer> ImageResource::resourceBuffer() const | |
| 225 { | |
| 226 if (m_data) | |
| 227 return m_data.get(); | |
| 228 if (m_image) | |
| 229 return m_image->data(); | |
| 230 return nullptr; | |
| 231 } | |
| 232 | |
| 240 void ImageResource::appendData(const char* data, size_t length) | 233 void ImageResource::appendData(const char* data, size_t length) |
| 241 { | 234 { |
| 242 if (m_multipartParser) { | 235 if (m_multipartParser) { |
| 243 m_multipartParser->appendData(data, length); | 236 m_multipartParser->appendData(data, length); |
| 244 } else { | 237 } else { |
| 245 Resource::appendData(data, length); | 238 Resource::appendData(data, length); |
| 246 updateImage(false); | 239 updateImage(false); |
| 247 } | 240 } |
| 248 } | 241 } |
| 249 | 242 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 TRACE_EVENT0("blink", "ImageResource::updateImage"); | 367 TRACE_EVENT0("blink", "ImageResource::updateImage"); |
| 375 | 368 |
| 376 if (m_data) | 369 if (m_data) |
| 377 createImage(); | 370 createImage(); |
| 378 | 371 |
| 379 bool sizeAvailable = false; | 372 bool sizeAvailable = false; |
| 380 | 373 |
| 381 // Have the image update its data from its internal buffer. | 374 // Have the image update its data from its internal buffer. |
| 382 // It will not do anything now, but will delay decoding until | 375 // It will not do anything now, but will delay decoding until |
| 383 // queried for info (like size or specific image frames). | 376 // queried for info (like size or specific image frames). |
| 384 if (m_image) | 377 if (m_data) { |
| 378 DCHECK(m_image); | |
| 385 sizeAvailable = m_image->setData(m_data, allDataReceived); | 379 sizeAvailable = m_image->setData(m_data, allDataReceived); |
| 380 } | |
| 386 | 381 |
| 387 // Go ahead and tell our observers to try to draw if we have either | 382 // Go ahead and tell our observers to try to draw if we have either |
| 388 // received all the data or the size is known. Each chunk from the | 383 // received all the data or the size is known. Each chunk from the |
| 389 // network causes observers to repaint, which will force that chunk | 384 // network causes observers to repaint, which will force that chunk |
| 390 // to decode. | 385 // to decode. |
| 391 if (sizeAvailable || allDataReceived) { | 386 if (sizeAvailable || allDataReceived) { |
| 392 if (!m_image || m_image->isNull()) { | 387 if (!m_image || m_image->isNull()) { |
| 393 if (!errorOccurred()) | 388 if (!errorOccurred()) |
| 394 setStatus(DecodeError); | 389 setStatus(DecodeError); |
| 395 clear(); | 390 clear(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 411 } | 406 } |
| 412 | 407 |
| 413 void ImageResource::finish(double loadFinishTime) | 408 void ImageResource::finish(double loadFinishTime) |
| 414 { | 409 { |
| 415 if (m_multipartParser) { | 410 if (m_multipartParser) { |
| 416 m_multipartParser->finish(); | 411 m_multipartParser->finish(); |
| 417 if (m_data) | 412 if (m_data) |
| 418 updateImageAndClearBuffer(); | 413 updateImageAndClearBuffer(); |
| 419 } else { | 414 } else { |
| 420 updateImage(true); | 415 updateImage(true); |
| 416 // As encoded image data can be created from m_image, we don't have to | |
| 417 // keep m_data. Let's clear this. As for the lifetimes of m_image and | |
| 418 // m_data, see this document: | |
| 419 // https://docs.google.com/document/d/1v0yTAZ6wkqX2U_M6BNIGUJpM1s0TIw1Vs qpxoL7aciY/edit?usp=sharing | |
| 420 m_data.clear(); | |
| 421 } | 421 } |
| 422 Resource::finish(loadFinishTime); | 422 Resource::finish(loadFinishTime); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void ImageResource::error(const ResourceError& error) | 425 void ImageResource::error(const ResourceError& error) |
| 426 { | 426 { |
| 427 if (m_multipartParser) | 427 if (m_multipartParser) |
| 428 m_multipartParser->cancel(); | 428 m_multipartParser->cancel(); |
| 429 clear(); | 429 clear(); |
| 430 Resource::error(error); | 430 Resource::error(error); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 } | 521 } |
| 522 | 522 |
| 523 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 523 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
| 524 { | 524 { |
| 525 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) | 525 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) |
| 526 return; | 526 return; |
| 527 m_resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); | 527 m_resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); |
| 528 m_resourceRequest.setLoFiState(WebURLRequest::LoFiOff); | 528 m_resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
| 529 if (isLoading()) | 529 if (isLoading()) |
| 530 m_loader->cancel(); | 530 m_loader->cancel(); |
| 531 else | |
| 532 updateImageAndClearBuffer(); | |
|
haraken
2016/07/13 08:07:42
Why can we remove this? Now you're not calling m_d
| |
| 533 setStatus(NotStarted); | 531 setStatus(NotStarted); |
| 534 fetcher->startLoad(this); | 532 fetcher->startLoad(this); |
| 535 } | 533 } |
| 536 | 534 |
| 537 void ImageResource::changedInRect(const blink::Image* image, const IntRect& rect ) | 535 void ImageResource::changedInRect(const blink::Image* image, const IntRect& rect ) |
| 538 { | 536 { |
| 539 if (!image || image != m_image) | 537 if (!image || image != m_image) |
| 540 return; | 538 return; |
| 541 notifyObservers(&rect); | 539 notifyObservers(&rect); |
| 542 } | 540 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 if (response().wasFetchedViaServiceWorker()) | 573 if (response().wasFetchedViaServiceWorker()) |
| 576 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; | 574 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; |
| 577 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 575 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 578 return false; | 576 return false; |
| 579 if (passesAccessControlCheck(securityOrigin)) | 577 if (passesAccessControlCheck(securityOrigin)) |
| 580 return true; | 578 return true; |
| 581 return !securityOrigin->taintsCanvas(response().url()); | 579 return !securityOrigin->taintsCanvas(response().url()); |
| 582 } | 580 } |
| 583 | 581 |
| 584 } // namespace blink | 582 } // namespace blink |
| OLD | NEW |