| 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 26 matching lines...) Expand all Loading... |
| 37 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
| 38 #include "public/platform/WebCachePolicy.h" | 38 #include "public/platform/WebCachePolicy.h" |
| 39 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
| 40 #include "wtf/HashCountedSet.h" | 40 #include "wtf/HashCountedSet.h" |
| 41 #include "wtf/StdLibExtras.h" | 41 #include "wtf/StdLibExtras.h" |
| 42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 43 #include <memory> | 43 #include <memory> |
| 44 #include <v8.h> | 44 #include <v8.h> |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 namespace { |
| 48 // The amount of time to wait before informing the clients that the image has |
| 49 // been updated (in seconds). This effectively throttles invalidations that |
| 50 // result from new data arriving for this image. |
| 51 constexpr double kFlushDelaySeconds = 1.; |
| 52 } // namespace |
| 47 | 53 |
| 48 ImageResource* ImageResource::fetch(FetchRequest& request, | 54 ImageResource* ImageResource::fetch(FetchRequest& request, |
| 49 ResourceFetcher* fetcher) { | 55 ResourceFetcher* fetcher) { |
| 50 if (request.resourceRequest().requestContext() == | 56 if (request.resourceRequest().requestContext() == |
| 51 WebURLRequest::RequestContextUnspecified) | 57 WebURLRequest::RequestContextUnspecified) |
| 52 request.mutableResourceRequest().setRequestContext( | 58 request.mutableResourceRequest().setRequestContext( |
| 53 WebURLRequest::RequestContextImage); | 59 WebURLRequest::RequestContextImage); |
| 54 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 60 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
| 55 KURL requestURL = request.resourceRequest().url(); | 61 KURL requestURL = request.resourceRequest().url(); |
| 56 if (requestURL.isValid() && | 62 if (requestURL.isValid() && |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 135 } |
| 130 | 136 |
| 131 void ImageResource::addObserver(ImageResourceObserver* observer) { | 137 void ImageResource::addObserver(ImageResourceObserver* observer) { |
| 132 willAddClientOrObserver(MarkAsReferenced); | 138 willAddClientOrObserver(MarkAsReferenced); |
| 133 | 139 |
| 134 m_observers.add(observer); | 140 m_observers.add(observer); |
| 135 | 141 |
| 136 if (isCacheValidator()) | 142 if (isCacheValidator()) |
| 137 return; | 143 return; |
| 138 | 144 |
| 139 // When the response is not multipart, if |data()| exists, |m_image| must be | 145 // When the response is not multipart, if |data()| exists and image is loaded, |
| 140 // created. This is assured that |updateImage()| is called when |appendData()| | 146 // |m_image| must be created. This is assured that |updateImage()| is called |
| 141 // is called. | 147 // when the image finishes loading. However, while loading |appendData()| can |
| 148 // throttle |updateImage()| calls. |
| 142 // | 149 // |
| 143 // On the other hand, when the response is multipart, |updateImage()| is not | 150 // On the other hand, when the response is multipart, |updateImage()| is not |
| 144 // called in |appendData()|, which means |m_image| might not be created even | 151 // called in |appendData()|, which means |m_image| might not be created even |
| 145 // when |data()| exists. This is intentional since creating a |m_image| on | 152 // when |data()| exists. This is intentional since creating a |m_image| on |
| 146 // receiving data might destroy an existing image in a previous part. | 153 // receiving data might destroy an existing image in a previous part. |
| 147 DCHECK((m_multipartParser && isLoading()) || !data() || m_image); | 154 DCHECK((m_multipartParser && isLoading()) || !data() || m_image || |
| 155 !isLoaded()); |
| 148 | 156 |
| 149 if (m_image && !m_image->isNull()) { | 157 if (m_image && !m_image->isNull()) { |
| 150 observer->imageChanged(this); | 158 observer->imageChanged(this); |
| 151 } | 159 } |
| 152 | 160 |
| 153 if (isLoaded()) { | 161 if (isLoaded()) { |
| 154 markObserverFinished(observer); | 162 markObserverFinished(observer); |
| 155 observer->imageNotifyFinished(this); | 163 observer->imageNotifyFinished(this); |
| 156 } | 164 } |
| 157 } | 165 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 return m_image->data(); | 243 return m_image->data(); |
| 236 return nullptr; | 244 return nullptr; |
| 237 } | 245 } |
| 238 | 246 |
| 239 void ImageResource::appendData(const char* data, size_t length) { | 247 void ImageResource::appendData(const char* data, size_t length) { |
| 240 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(length); | 248 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(length); |
| 241 if (m_multipartParser) { | 249 if (m_multipartParser) { |
| 242 m_multipartParser->appendData(data, length); | 250 m_multipartParser->appendData(data, length); |
| 243 } else { | 251 } else { |
| 244 Resource::appendData(data, length); | 252 Resource::appendData(data, length); |
| 245 updateImage(false); | 253 |
| 254 // If we have an animated image, then update as soon as we have more data. |
| 255 if (m_image && m_image->maybeAnimated()) { |
| 256 updateImage(false); |
| 257 return; |
| 258 } |
| 259 |
| 260 // For other images, only update at |kFlushDelaySeconds| intervals. This |
| 261 // throttles how frequently we update |m_image| and how frequently we |
| 262 // inform the clients which causes an invalidation of this image. In other |
| 263 // words, we only invalidate this image every |kFlushDelaySeconds| seconds |
| 264 // while loading. |
| 265 double now = WTF::currentTime(); |
| 266 if (!m_lastFlushTime) { |
| 267 m_lastFlushTime = now; |
| 268 } else if (m_lastFlushTime + kFlushDelaySeconds <= now) { |
| 269 updateImage(false); |
| 270 m_lastFlushTime = now; |
| 271 } |
| 246 } | 272 } |
| 247 } | 273 } |
| 248 | 274 |
| 249 std::pair<blink::Image*, float> ImageResource::brokenImage( | 275 std::pair<blink::Image*, float> ImageResource::brokenImage( |
| 250 float deviceScaleFactor) { | 276 float deviceScaleFactor) { |
| 251 if (deviceScaleFactor >= 2) { | 277 if (deviceScaleFactor >= 2) { |
| 252 DEFINE_STATIC_REF(blink::Image, brokenImageHiRes, | 278 DEFINE_STATIC_REF(blink::Image, brokenImageHiRes, |
| 253 (blink::Image::loadPlatformResource("missingImage@2x"))); | 279 (blink::Image::loadPlatformResource("missingImage@2x"))); |
| 254 return std::make_pair(brokenImageHiRes, 2); | 280 return std::make_pair(brokenImageHiRes, 2); |
| 255 } | 281 } |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 return response().serviceWorkerResponseType() != | 612 return response().serviceWorkerResponseType() != |
| 587 WebServiceWorkerResponseTypeOpaque; | 613 WebServiceWorkerResponseTypeOpaque; |
| 588 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 614 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
| 589 return false; | 615 return false; |
| 590 if (passesAccessControlCheck(securityOrigin)) | 616 if (passesAccessControlCheck(securityOrigin)) |
| 591 return true; | 617 return true; |
| 592 return !securityOrigin->taintsCanvas(response().url()); | 618 return !securityOrigin->taintsCanvas(response().url()); |
| 593 } | 619 } |
| 594 | 620 |
| 595 } // namespace blink | 621 } // namespace blink |
| OLD | NEW |