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