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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 } | 186 } |
190 | 187 |
191 void ImageResource::destroyDecodedDataForFailedRevalidation() | 188 void ImageResource::destroyDecodedDataForFailedRevalidation() |
192 { | 189 { |
193 clearImage(); | 190 clearImage(); |
194 setDecodedSize(0); | 191 setDecodedSize(0); |
195 } | 192 } |
196 | 193 |
197 void ImageResource::destroyDecodedDataIfPossible() | 194 void ImageResource::destroyDecodedDataIfPossible() |
198 { | 195 { |
199 if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOn eRef() && m_image->isBitmapImage()))) { | 196 if (!m_image) |
200 clearImage(); | 197 return; |
201 setDecodedSize(0); | 198 if ((!hasClientsOrObservers() && !isLoading() && m_image->hasOneRef() && m_i mage->isBitmapImage()) || !errorOccurred()) |
202 } else if (m_image && !errorOccurred()) { | |
203 m_image->destroyDecodedData(); | 199 m_image->destroyDecodedData(); |
204 } | |
205 } | 200 } |
206 | 201 |
207 void ImageResource::doResetAnimation() | 202 void ImageResource::doResetAnimation() |
208 { | 203 { |
209 if (m_image) | 204 if (m_image) |
210 m_image->resetAnimation(); | 205 m_image->resetAnimation(); |
211 } | 206 } |
212 | 207 |
213 void ImageResource::allClientsAndObserversRemoved() | 208 void ImageResource::allClientsAndObserversRemoved() |
214 { | 209 { |
215 if (m_image && !errorOccurred()) { | 210 if (m_image && !errorOccurred()) { |
216 // If possible, delay the resetting until back at the event loop. | 211 // If possible, delay the resetting until back at the event loop. |
217 // Doing so after a conservative GC prevents resetAnimation() from | 212 // Doing so after a conservative GC prevents resetAnimation() from |
218 // upsetting ongoing animation updates (crbug.com/613709) | 213 // upsetting ongoing animation updates (crbug.com/613709) |
219 if (!ThreadHeap::willObjectBeLazilySwept(this)) | 214 if (!ThreadHeap::willObjectBeLazilySwept(this)) |
220 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))); |
221 else | 216 else |
222 m_image->resetAnimation(); | 217 m_image->resetAnimation(); |
223 } | 218 } |
224 if (m_multipartParser) | 219 if (m_multipartParser) |
225 m_multipartParser->cancel(); | 220 m_multipartParser->cancel(); |
226 Resource::allClientsAndObserversRemoved(); | 221 Resource::allClientsAndObserversRemoved(); |
227 } | 222 } |
228 | 223 |
224 PassRefPtr<SharedBuffer> ImageResource::resourceBuffer() const | |
225 { | |
226 RefPtr<SharedBuffer> data = Resource::resourceBuffer(); | |
227 if (data) | |
228 return data.release(); | |
229 if (m_image) | |
230 return m_image->data(); | |
231 return nullptr; | |
232 } | |
233 | |
229 void ImageResource::appendData(const char* data, size_t length) | 234 void ImageResource::appendData(const char* data, size_t length) |
230 { | 235 { |
231 if (m_multipartParser) { | 236 if (m_multipartParser) { |
232 m_multipartParser->appendData(data, length); | 237 m_multipartParser->appendData(data, length); |
233 } else { | 238 } else { |
234 Resource::appendData(data, length); | 239 Resource::appendData(data, length); |
235 updateImage(false); | 240 updateImage(false); |
236 } | 241 } |
237 } | 242 } |
238 | 243 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 TRACE_EVENT0("blink", "ImageResource::updateImage"); | 368 TRACE_EVENT0("blink", "ImageResource::updateImage"); |
364 | 369 |
365 if (m_data) | 370 if (m_data) |
366 createImage(); | 371 createImage(); |
367 | 372 |
368 bool sizeAvailable = false; | 373 bool sizeAvailable = false; |
369 | 374 |
370 // Have the image update its data from its internal buffer. | 375 // Have the image update its data from its internal buffer. |
371 // It will not do anything now, but will delay decoding until | 376 // It will not do anything now, but will delay decoding until |
372 // queried for info (like size or specific image frames). | 377 // queried for info (like size or specific image frames). |
373 if (m_image) | 378 if (m_data) { |
379 DCHECK(m_image); | |
374 sizeAvailable = m_image->setData(m_data, allDataReceived); | 380 sizeAvailable = m_image->setData(m_data, allDataReceived); |
381 } | |
375 | 382 |
376 // Go ahead and tell our observers to try to draw if we have either | 383 // 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 | 384 // received all the data or the size is known. Each chunk from the |
378 // network causes observers to repaint, which will force that chunk | 385 // network causes observers to repaint, which will force that chunk |
379 // to decode. | 386 // to decode. |
380 if (sizeAvailable || allDataReceived) { | 387 if (sizeAvailable || allDataReceived) { |
381 if (!m_image || m_image->isNull()) { | 388 if (!m_image || m_image->isNull()) { |
382 if (!errorOccurred()) | 389 if (!errorOccurred()) |
383 setStatus(DecodeError); | 390 setStatus(DecodeError); |
384 clear(); | 391 clear(); |
385 if (memoryCache()->contains(this)) | 392 if (memoryCache()->contains(this)) |
386 memoryCache()->remove(this); | 393 memoryCache()->remove(this); |
387 } | 394 } |
388 | 395 |
389 // It would be nice to only redraw the decoded band of the image, but wi th the current design | 396 // 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. | 397 // (decoding delayed until painting) that seems hard. |
391 notifyObservers(); | 398 notifyObservers(); |
392 } | 399 } |
400 | |
401 if (allDataReceived) | |
402 m_data.clear(); | |
393 } | 403 } |
394 | 404 |
395 void ImageResource::updateImageAndClearBuffer() | 405 void ImageResource::updateImageAndClearBuffer() |
396 { | 406 { |
397 clearImage(); | 407 clearImage(); |
398 updateImage(true); | 408 updateImage(true); |
399 m_data.clear(); | |
400 } | 409 } |
401 | 410 |
402 void ImageResource::finish(double loadFinishTime) | 411 void ImageResource::finish(double loadFinishTime) |
403 { | 412 { |
404 if (m_multipartParser) { | 413 if (m_multipartParser) { |
405 m_multipartParser->finish(); | 414 m_multipartParser->finish(); |
406 if (m_data) | 415 if (m_data) |
407 updateImageAndClearBuffer(); | 416 updateImageAndClearBuffer(); |
408 } else { | 417 } else { |
409 updateImage(true); | 418 updateImage(true); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
511 | 520 |
512 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 521 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
513 { | 522 { |
514 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) | 523 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) |
515 return; | 524 return; |
516 m_resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); | 525 m_resourceRequest.setCachePolicy(WebCachePolicy::BypassingCache); |
517 m_resourceRequest.setLoFiState(WebURLRequest::LoFiOff); | 526 m_resourceRequest.setLoFiState(WebURLRequest::LoFiOff); |
518 if (isLoading()) | 527 if (isLoading()) |
519 m_loader->cancel(); | 528 m_loader->cancel(); |
520 else | 529 else |
521 updateImageAndClearBuffer(); | 530 updateImage(true); |
hiroshige
2016/07/08 08:28:41
FYI [1] will change this line. Because [1] is to b
hiroshige
2016/07/08 08:29:26
Sorry I forgot the link:
[1] https://codereview.ch
| |
522 setStatus(NotStarted); | 531 setStatus(NotStarted); |
523 fetcher->startLoad(this); | 532 fetcher->startLoad(this); |
524 } | 533 } |
525 | 534 |
526 void ImageResource::changedInRect(const blink::Image* image, const IntRect& rect ) | 535 void ImageResource::changedInRect(const blink::Image* image, const IntRect& rect ) |
527 { | 536 { |
528 if (!image || image != m_image) | 537 if (!image || image != m_image) |
529 return; | 538 return; |
530 notifyObservers(&rect); | 539 notifyObservers(&rect); |
531 } | 540 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 if (response().wasFetchedViaServiceWorker()) | 573 if (response().wasFetchedViaServiceWorker()) |
565 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; | 574 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; |
566 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 575 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
567 return false; | 576 return false; |
568 if (passesAccessControlCheck(securityOrigin)) | 577 if (passesAccessControlCheck(securityOrigin)) |
569 return true; | 578 return true; |
570 return !securityOrigin->taintsCanvas(response().url()); | 579 return !securityOrigin->taintsCanvas(response().url()); |
571 } | 580 } |
572 | 581 |
573 } // namespace blink | 582 } // namespace blink |
OLD | NEW |