| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #include "RuntimeEnabledFeatures.h" | 51 #include "RuntimeEnabledFeatures.h" |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 using std::max; | 54 using std::max; |
| 55 | 55 |
| 56 namespace WebCore { | 56 namespace WebCore { |
| 57 | 57 |
| 58 CachedImage::CachedImage(const ResourceRequest& resourceRequest) | 58 CachedImage::CachedImage(const ResourceRequest& resourceRequest) |
| 59 : CachedResource(resourceRequest, ImageResource) | 59 : CachedResource(resourceRequest, ImageResource) |
| 60 , m_image(0) | 60 , m_image(0) |
| 61 , m_loadingMultipartContent(false) |
| 61 { | 62 { |
| 62 setStatus(Unknown); | 63 setStatus(Unknown); |
| 63 setCustomAcceptHeader(); | 64 setCustomAcceptHeader(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 CachedImage::CachedImage(Image* image) | 67 CachedImage::CachedImage(Image* image) |
| 67 : CachedResource(ResourceRequest(), ImageResource) | 68 : CachedResource(ResourceRequest(), ImageResource) |
| 68 , m_image(image) | 69 , m_image(image) |
| 69 { | 70 { |
| 70 setStatus(Cached); | 71 setStatus(Cached); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 335 |
| 335 inline void CachedImage::clearImage() | 336 inline void CachedImage::clearImage() |
| 336 { | 337 { |
| 337 // If our Image has an observer, it's always us so we need to clear the back
pointer | 338 // If our Image has an observer, it's always us so we need to clear the back
pointer |
| 338 // before dropping our reference. | 339 // before dropping our reference. |
| 339 if (m_image) | 340 if (m_image) |
| 340 m_image->setImageObserver(0); | 341 m_image->setImageObserver(0); |
| 341 m_image.clear(); | 342 m_image.clear(); |
| 342 } | 343 } |
| 343 | 344 |
| 344 void CachedImage::data(PassRefPtr<ResourceBuffer> data, bool allDataReceived) | 345 void CachedImage::data(PassRefPtr<ResourceBuffer> data) |
| 345 { | 346 { |
| 346 m_data = data; | 347 CachedResource::data(data); |
| 348 if (!m_loadingMultipartContent) |
| 349 updateImage(false); |
| 350 } |
| 347 | 351 |
| 352 void CachedImage::updateImage(bool allDataReceived) |
| 353 { |
| 348 if (m_data) | 354 if (m_data) |
| 349 createImage(); | 355 createImage(); |
| 350 | 356 |
| 351 bool sizeAvailable = false; | 357 bool sizeAvailable = false; |
| 352 | 358 |
| 353 // Have the image update its data from its internal buffer. | 359 // Have the image update its data from its internal buffer. |
| 354 // It will not do anything now, but will delay decoding until | 360 // It will not do anything now, but will delay decoding until |
| 355 // queried for info (like size or specific image frames). | 361 // queried for info (like size or specific image frames). |
| 356 if (m_image) | 362 if (m_image) |
| 357 sizeAvailable = m_image->setData(m_data ? m_data->sharedBuffer() : 0, al
lDataReceived); | 363 sizeAvailable = m_image->setData(m_data ? m_data->sharedBuffer() : 0, al
lDataReceived); |
| 358 | 364 |
| 359 // Go ahead and tell our observers to try to draw if we have either | 365 // Go ahead and tell our observers to try to draw if we have either |
| 360 // received all the data or the size is known. Each chunk from the | 366 // received all the data or the size is known. Each chunk from the |
| 361 // network causes observers to repaint, which will force that chunk | 367 // network causes observers to repaint, which will force that chunk |
| 362 // to decode. | 368 // to decode. |
| 363 if (sizeAvailable || allDataReceived) { | 369 if (sizeAvailable || allDataReceived) { |
| 364 if (!m_image || m_image->isNull()) { | 370 if (!m_image || m_image->isNull()) { |
| 365 error(errorOccurred() ? status() : DecodeError); | 371 error(errorOccurred() ? status() : DecodeError); |
| 366 if (inCache()) | 372 if (inCache()) |
| 367 memoryCache()->remove(this); | 373 memoryCache()->remove(this); |
| 368 return; | 374 return; |
| 369 } | 375 } |
| 370 | 376 |
| 371 // It would be nice to only redraw the decoded band of the image, but wi
th the current design | 377 // It would be nice to only redraw the decoded band of the image, but wi
th the current design |
| 372 // (decoding delayed until painting) that seems hard. | 378 // (decoding delayed until painting) that seems hard. |
| 373 notifyObservers(); | 379 notifyObservers(); |
| 380 } |
| 381 } |
| 374 | 382 |
| 375 if (m_image) | 383 void CachedImage::finishOnePart() |
| 376 setEncodedSize(m_image->data() ? m_image->data()->size() : 0); | 384 { |
| 377 } | 385 updateImage(true); |
| 378 | 386 CachedResource::finishOnePart(); |
| 379 if (allDataReceived) { | |
| 380 setLoading(false); | |
| 381 checkNotify(); | |
| 382 } | |
| 383 } | 387 } |
| 384 | 388 |
| 385 void CachedImage::error(CachedResource::Status status) | 389 void CachedImage::error(CachedResource::Status status) |
| 386 { | 390 { |
| 387 clear(); | 391 clear(); |
| 388 CachedResource::error(status); | 392 CachedResource::error(status); |
| 389 notifyObservers(); | 393 notifyObservers(); |
| 390 } | 394 } |
| 391 | 395 |
| 392 void CachedImage::responseReceived(const ResourceResponse& response) | 396 void CachedImage::responseReceived(const ResourceResponse& response) |
| 393 { | 397 { |
| 394 if (!m_response.isNull()) | 398 if (!m_response.isNull()) |
| 395 clear(); | 399 clear(); |
| 400 if (response.isMultipart()) |
| 401 m_loadingMultipartContent = true; |
| 396 CachedResource::responseReceived(response); | 402 CachedResource::responseReceived(response); |
| 397 } | 403 } |
| 398 | 404 |
| 399 void CachedImage::destroyDecodedData() | 405 void CachedImage::destroyDecodedData() |
| 400 { | 406 { |
| 401 bool canDeleteImage = !m_image || (m_image->hasOneRef() && m_image->isBitmap
Image()); | 407 bool canDeleteImage = !m_image || (m_image->hasOneRef() && m_image->isBitmap
Image()); |
| 402 if (isSafeToMakePurgeable() && canDeleteImage && !isLoading()) { | 408 if (isSafeToMakePurgeable() && canDeleteImage && !isLoading()) { |
| 403 // Image refs the data buffer so we should not make it purgeable while t
he image is alive. | 409 // Image refs the data buffer so we should not make it purgeable while t
he image is alive. |
| 404 // Invoking addClient() will reconstruct the image object. | 410 // Invoking addClient() will reconstruct the image object. |
| 405 m_image = 0; | 411 m_image = 0; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 478 |
| 473 bool CachedImage::currentFrameKnownToBeOpaque(const RenderObject* renderer) | 479 bool CachedImage::currentFrameKnownToBeOpaque(const RenderObject* renderer) |
| 474 { | 480 { |
| 475 Image* image = imageForRenderer(renderer); | 481 Image* image = imageForRenderer(renderer); |
| 476 if (image->isBitmapImage()) | 482 if (image->isBitmapImage()) |
| 477 image->nativeImageForCurrentFrame(); // force decode | 483 image->nativeImageForCurrentFrame(); // force decode |
| 478 return image->currentFrameKnownToBeOpaque(); | 484 return image->currentFrameKnownToBeOpaque(); |
| 479 } | 485 } |
| 480 | 486 |
| 481 } // namespace WebCore | 487 } // namespace WebCore |
| OLD | NEW |