| 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 11 matching lines...) Expand all Loading... |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "config.h" | 24 #include "config.h" |
| 25 #include "core/fetch/ImageResource.h" | 25 #include "core/fetch/ImageResource.h" |
| 26 | 26 |
| 27 #include "core/fetch/ImageResourceClient.h" | 27 #include "core/fetch/ImageResourceClient.h" |
| 28 #include "core/fetch/MemoryCache.h" | 28 #include "core/fetch/MemoryCache.h" |
| 29 #include "core/fetch/ResourceClient.h" | 29 #include "core/fetch/ResourceClient.h" |
| 30 #include "core/fetch/ResourceClientWalker.h" | 30 #include "core/fetch/ResourceClientWalker.h" |
| 31 #include "core/fetch/ResourceFetcher.h" | 31 #include "core/fetch/ResourceFetcher.h" |
| 32 #include "core/fetch/ResourceLoader.h" |
| 32 #include "core/html/HTMLImageElement.h" | 33 #include "core/html/HTMLImageElement.h" |
| 33 #include "core/layout/LayoutObject.h" | 34 #include "core/layout/LayoutObject.h" |
| 34 #include "core/svg/graphics/SVGImage.h" | 35 #include "core/svg/graphics/SVGImage.h" |
| 35 #include "core/svg/graphics/SVGImageForContainer.h" | 36 #include "core/svg/graphics/SVGImageForContainer.h" |
| 36 #include "platform/Logging.h" | 37 #include "platform/Logging.h" |
| 37 #include "platform/RuntimeEnabledFeatures.h" | 38 #include "platform/RuntimeEnabledFeatures.h" |
| 38 #include "platform/SharedBuffer.h" | 39 #include "platform/SharedBuffer.h" |
| 39 #include "platform/TraceEvent.h" | 40 #include "platform/TraceEvent.h" |
| 40 #include "platform/graphics/BitmapImage.h" | 41 #include "platform/graphics/BitmapImage.h" |
| 41 #include "wtf/CurrentTime.h" | 42 #include "wtf/CurrentTime.h" |
| 42 #include "wtf/StdLibExtras.h" | 43 #include "wtf/StdLibExtras.h" |
| 43 | 44 |
| 44 namespace blink { | 45 namespace blink { |
| 45 | 46 |
| 46 ImageResource::ImageResource(const ResourceRequest& resourceRequest) | 47 ImageResource::ImageResource(const ResourceRequest& resourceRequest) |
| 47 : Resource(resourceRequest, Image) | 48 : Resource(resourceRequest, Image) |
| 48 , m_devicePixelRatioHeaderValue(1.0) | 49 , m_devicePixelRatioHeaderValue(1.0) |
| 49 , m_image(nullptr) | 50 , m_image(nullptr) |
| 50 , m_loadingMultipartContent(false) | |
| 51 , m_hasDevicePixelRatioHeaderValue(false) | 51 , m_hasDevicePixelRatioHeaderValue(false) |
| 52 { | 52 { |
| 53 WTF_LOG(Timers, "new ImageResource(ResourceRequest) %p", this); | 53 WTF_LOG(Timers, "new ImageResource(ResourceRequest) %p", this); |
| 54 setStatus(Unknown); | 54 setStatus(Unknown); |
| 55 setCustomAcceptHeader(); | 55 setCustomAcceptHeader(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 ImageResource::ImageResource(blink::Image* image) | 58 ImageResource::ImageResource(blink::Image* image) |
| 59 : Resource(ResourceRequest(""), Image) | 59 : Resource(ResourceRequest(""), Image) |
| 60 , m_devicePixelRatioHeaderValue(1.0) | 60 , m_devicePixelRatioHeaderValue(1.0) |
| 61 , m_image(image) | 61 , m_image(image) |
| 62 , m_loadingMultipartContent(false) | |
| 63 , m_hasDevicePixelRatioHeaderValue(false) | 62 , m_hasDevicePixelRatioHeaderValue(false) |
| 64 { | 63 { |
| 65 WTF_LOG(Timers, "new ImageResource(Image) %p", this); | 64 WTF_LOG(Timers, "new ImageResource(Image) %p", this); |
| 66 setStatus(Cached); | 65 setStatus(Cached); |
| 67 setLoading(false); | 66 setLoading(false); |
| 68 setCustomAcceptHeader(); | 67 setCustomAcceptHeader(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 ImageResource::ImageResource(const ResourceRequest& resourceRequest, blink::Imag
e* image) | 70 ImageResource::ImageResource(const ResourceRequest& resourceRequest, blink::Imag
e* image) |
| 72 : Resource(resourceRequest, Image) | 71 : Resource(resourceRequest, Image) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // If our Image has an observer, it's always us so we need to clear the back
pointer | 310 // If our Image has an observer, it's always us so we need to clear the back
pointer |
| 312 // before dropping our reference. | 311 // before dropping our reference. |
| 313 if (m_image) | 312 if (m_image) |
| 314 m_image->setImageObserver(nullptr); | 313 m_image->setImageObserver(nullptr); |
| 315 m_image.clear(); | 314 m_image.clear(); |
| 316 } | 315 } |
| 317 | 316 |
| 318 void ImageResource::appendData(const char* data, unsigned length) | 317 void ImageResource::appendData(const char* data, unsigned length) |
| 319 { | 318 { |
| 320 Resource::appendData(data, length); | 319 Resource::appendData(data, length); |
| 321 if (!m_loadingMultipartContent) | 320 if (!loadingMultipartContent()) |
| 322 updateImage(false); | 321 updateImage(false); |
| 323 } | 322 } |
| 324 | 323 |
| 325 void ImageResource::updateImage(bool allDataReceived) | 324 void ImageResource::updateImage(bool allDataReceived) |
| 326 { | 325 { |
| 327 TRACE_EVENT0("blink", "ImageResource::updateImage"); | 326 TRACE_EVENT0("blink", "ImageResource::updateImage"); |
| 328 | 327 |
| 329 if (m_data) | 328 if (m_data) |
| 330 createImage(); | 329 createImage(); |
| 331 | 330 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 350 } | 349 } |
| 351 | 350 |
| 352 // It would be nice to only redraw the decoded band of the image, but wi
th the current design | 351 // It would be nice to only redraw the decoded band of the image, but wi
th the current design |
| 353 // (decoding delayed until painting) that seems hard. | 352 // (decoding delayed until painting) that seems hard. |
| 354 notifyObservers(); | 353 notifyObservers(); |
| 355 } | 354 } |
| 356 } | 355 } |
| 357 | 356 |
| 358 void ImageResource::finishOnePart() | 357 void ImageResource::finishOnePart() |
| 359 { | 358 { |
| 360 if (m_loadingMultipartContent) | 359 if (loadingMultipartContent()) |
| 361 clear(); | 360 clear(); |
| 362 updateImage(true); | 361 updateImage(true); |
| 363 if (m_loadingMultipartContent) | 362 if (loadingMultipartContent()) |
| 364 m_data.clear(); | 363 m_data.clear(); |
| 365 Resource::finishOnePart(); | 364 Resource::finishOnePart(); |
| 366 } | 365 } |
| 367 | 366 |
| 368 void ImageResource::error(Resource::Status status) | 367 void ImageResource::error(Resource::Status status) |
| 369 { | 368 { |
| 370 clear(); | 369 clear(); |
| 371 Resource::error(status); | 370 Resource::error(status); |
| 372 notifyObservers(); | 371 notifyObservers(); |
| 373 } | 372 } |
| 374 | 373 |
| 375 void ImageResource::responseReceived(const ResourceResponse& response, PassOwnPt
r<WebDataConsumerHandle> handle) | 374 void ImageResource::responseReceived(const ResourceResponse& response, PassOwnPt
r<WebDataConsumerHandle> handle) |
| 376 { | 375 { |
| 377 if (m_loadingMultipartContent && m_data) | 376 if (loadingMultipartContent() && m_data) |
| 378 finishOnePart(); | 377 finishOnePart(); |
| 379 else if (response.isMultipart()) | |
| 380 m_loadingMultipartContent = true; | |
| 381 if (RuntimeEnabledFeatures::clientHintsEnabled()) { | 378 if (RuntimeEnabledFeatures::clientHintsEnabled()) { |
| 382 m_devicePixelRatioHeaderValue = response.httpHeaderField("content-dpr").
toFloat(&m_hasDevicePixelRatioHeaderValue); | 379 m_devicePixelRatioHeaderValue = response.httpHeaderField("content-dpr").
toFloat(&m_hasDevicePixelRatioHeaderValue); |
| 383 if (!m_hasDevicePixelRatioHeaderValue || m_devicePixelRatioHeaderValue <
= 0.0) { | 380 if (!m_hasDevicePixelRatioHeaderValue || m_devicePixelRatioHeaderValue <
= 0.0) { |
| 384 m_devicePixelRatioHeaderValue = 1.0; | 381 m_devicePixelRatioHeaderValue = 1.0; |
| 385 m_hasDevicePixelRatioHeaderValue = false; | 382 m_hasDevicePixelRatioHeaderValue = false; |
| 386 } | 383 } |
| 387 } | 384 } |
| 388 Resource::responseReceived(response, handle); | 385 Resource::responseReceived(response, handle); |
| 389 } | 386 } |
| 390 | 387 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 Node* node = layoutObject->node(); | 506 Node* node = layoutObject->node(); |
| 510 if (node && isHTMLImageElement(node)) { | 507 if (node && isHTMLImageElement(node)) { |
| 511 const AtomicString& urlString = toHTMLImageElement(node)->imageSourceURL
(); | 508 const AtomicString& urlString = toHTMLImageElement(node)->imageSourceURL
(); |
| 512 KURL url = node->document().completeURL(urlString); | 509 KURL url = node->document().completeURL(urlString); |
| 513 imageForContainer->setURL(url); | 510 imageForContainer->setURL(url); |
| 514 } | 511 } |
| 515 | 512 |
| 516 return imageForContainer.get(); | 513 return imageForContainer.get(); |
| 517 } | 514 } |
| 518 | 515 |
| 516 bool ImageResource::loadingMultipartContent() const |
| 517 { |
| 518 return m_loader && m_loader->loadingMultipartContent(); |
| 519 } |
| 520 |
| 519 } // namespace blink | 521 } // namespace blink |
| OLD | NEW |