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 |
11 version 2 of the License, or (at your option) any later version. | 11 version 2 of the License, or (at your option) any later version. |
12 | 12 |
13 This library is distributed in the hope that it will be useful, | 13 This library is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16 Library General Public License for more details. | 16 Library General Public License for more details. |
17 | 17 |
18 You should have received a copy of the GNU Library General Public License | 18 You should have received a copy of the GNU Library General Public License |
19 along with this library; see the file COPYING.LIB. If not, write to | 19 along with this library; see the file COPYING.LIB. If not, write to |
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
22 */ | 22 */ |
23 | 23 |
24 #include "core/fetch/ImageResource.h" | 24 #include "core/fetch/ImageResource.h" |
25 | 25 |
26 #include "core/fetch/ImageResourceClient.h" | 26 #include "core/fetch/ImageResourceObserver.h" |
27 #include "core/fetch/MemoryCache.h" | 27 #include "core/fetch/MemoryCache.h" |
28 #include "core/fetch/ResourceClient.h" | 28 #include "core/fetch/ResourceClient.h" |
29 #include "core/fetch/ResourceClientWalker.h" | 29 #include "core/fetch/ResourceClientOrObserverWalker.h" |
30 #include "core/fetch/ResourceFetcher.h" | 30 #include "core/fetch/ResourceFetcher.h" |
31 #include "core/fetch/ResourceLoader.h" | 31 #include "core/fetch/ResourceLoader.h" |
32 #include "core/svg/graphics/SVGImage.h" | 32 #include "core/svg/graphics/SVGImage.h" |
33 #include "platform/Logging.h" | 33 #include "platform/Logging.h" |
34 #include "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
35 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
36 #include "platform/TraceEvent.h" | 36 #include "platform/TraceEvent.h" |
37 #include "platform/graphics/BitmapImage.h" | 37 #include "platform/graphics/BitmapImage.h" |
38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
39 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
40 #include "wtf/StdLibExtras.h" | 40 #include "wtf/StdLibExtras.h" |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
| 44 using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResource
Observer, ImageResourceObserver>; |
| 45 |
44 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request
, ResourceFetcher* fetcher) | 46 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request
, ResourceFetcher* fetcher) |
45 { | 47 { |
46 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) | 48 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) |
47 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); | 49 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); |
48 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 50 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
49 KURL requestURL = request.resourceRequest().url(); | 51 KURL requestURL = request.resourceRequest().url(); |
50 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) | 52 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) |
51 fetcher->context().sendImagePing(requestURL); | 53 fetcher->context().sendImagePing(requestURL); |
52 return nullptr; | 54 return nullptr; |
53 } | 55 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 94 } |
93 | 95 |
94 DEFINE_TRACE(ImageResource) | 96 DEFINE_TRACE(ImageResource) |
95 { | 97 { |
96 visitor->trace(m_multipartParser); | 98 visitor->trace(m_multipartParser); |
97 Resource::trace(visitor); | 99 Resource::trace(visitor); |
98 ImageObserver::trace(visitor); | 100 ImageObserver::trace(visitor); |
99 MultipartImageResourceParser::Client::trace(visitor); | 101 MultipartImageResourceParser::Client::trace(visitor); |
100 } | 102 } |
101 | 103 |
102 void ImageResource::didAddClient(ResourceClient* c) | 104 void ImageResource::addObserver(ImageResourceObserver* observer) |
103 { | 105 { |
| 106 willAddClientOrObserver(); |
| 107 |
| 108 m_observers.add(observer); |
| 109 |
| 110 if (!m_revalidatingRequest.isNull()) |
| 111 return; |
| 112 |
104 if (m_data && !m_image && !errorOccurred()) { | 113 if (m_data && !m_image && !errorOccurred()) { |
105 createImage(); | 114 createImage(); |
106 m_image->setData(m_data, true); | 115 m_image->setData(m_data, true); |
107 } | 116 } |
108 | 117 |
109 ASSERT(ImageResourceClient::isExpectedType(c)); | |
110 if (m_image && !m_image->isNull()) | 118 if (m_image && !m_image->isNull()) |
111 static_cast<ImageResourceClient*>(c)->imageChanged(this); | 119 observer->imageChanged(this); |
112 | |
113 Resource::didAddClient(c); | |
114 } | 120 } |
115 | 121 |
116 void ImageResource::didRemoveClient(ResourceClient* c) | 122 void ImageResource::removeObserver(ImageResourceObserver* observer) |
117 { | 123 { |
118 ASSERT(c); | 124 ASSERT(observer); |
119 ASSERT(ImageResourceClient::isExpectedType(c)); | 125 ASSERT(m_observers.contains(observer)); |
| 126 m_observers.remove(observer); |
| 127 didRemoveClientOrObserver(); |
| 128 } |
120 | 129 |
121 Resource::didRemoveClient(c); | 130 ResourcePriority ImageResource::priorityFromObservers() |
| 131 { |
| 132 ResourcePriority priority; |
| 133 ImageResourceObserverWalker w(m_observers); |
| 134 while (const auto* observer = w.next()) { |
| 135 ResourcePriority nextPriority = observer->computeResourcePriority(); |
| 136 if (nextPriority.visibility == ResourcePriority::NotVisible) |
| 137 continue; |
| 138 priority.visibility = ResourcePriority::Visible; |
| 139 priority.intraPriorityValue += nextPriority.intraPriorityValue; |
| 140 } |
| 141 return priority; |
122 } | 142 } |
123 | 143 |
124 bool ImageResource::isSafeToUnlock() const | 144 bool ImageResource::isSafeToUnlock() const |
125 { | 145 { |
126 // Note that |m_image| holds a reference to |m_data| in addition to the one
held by the Resource parent class. | 146 // Note that |m_image| holds a reference to |m_data| in addition to the one
held by the Resource parent class. |
127 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); | 147 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); |
128 } | 148 } |
129 | 149 |
130 void ImageResource::destroyDecodedDataForFailedRevalidation() | 150 void ImageResource::destroyDecodedDataForFailedRevalidation() |
131 { | 151 { |
132 m_image = nullptr; | 152 m_image = nullptr; |
133 setDecodedSize(0); | 153 setDecodedSize(0); |
134 } | 154 } |
135 | 155 |
136 void ImageResource::destroyDecodedDataIfPossible() | 156 void ImageResource::destroyDecodedDataIfPossible() |
137 { | 157 { |
138 if (!hasClients() && !isLoading() && (!m_image || (m_image->hasOneRef() && m
_image->isBitmapImage()))) { | 158 if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOn
eRef() && m_image->isBitmapImage()))) { |
139 m_image = nullptr; | 159 m_image = nullptr; |
140 setDecodedSize(0); | 160 setDecodedSize(0); |
141 } else if (m_image && !errorOccurred()) { | 161 } else if (m_image && !errorOccurred()) { |
142 m_image->destroyDecodedData(true); | 162 m_image->destroyDecodedData(true); |
143 } | 163 } |
144 } | 164 } |
145 | 165 |
146 void ImageResource::allClientsRemoved() | 166 void ImageResource::allClientsAndObserversRemoved() |
147 { | 167 { |
148 if (m_image && !errorOccurred()) | 168 if (m_image && !errorOccurred()) |
149 m_image->resetAnimation(); | 169 m_image->resetAnimation(); |
150 if (m_multipartParser) | 170 if (m_multipartParser) |
151 m_multipartParser->cancel(); | 171 m_multipartParser->cancel(); |
152 Resource::allClientsRemoved(); | 172 Resource::allClientsAndObserversRemoved(); |
153 } | 173 } |
154 | 174 |
155 void ImageResource::appendData(const char* data, size_t length) | 175 void ImageResource::appendData(const char* data, size_t length) |
156 { | 176 { |
157 if (m_multipartParser) { | 177 if (m_multipartParser) { |
158 m_multipartParser->appendData(data, length); | 178 m_multipartParser->appendData(data, length); |
159 } else { | 179 } else { |
160 Resource::appendData(data, length); | 180 Resource::appendData(data, length); |
161 updateImage(false); | 181 updateImage(false); |
162 } | 182 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed
. | 254 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed
. |
235 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU
nit(), | 255 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU
nit(), |
236 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit()))
; | 256 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit()))
; |
237 size.scale(multiplier); | 257 size.scale(multiplier); |
238 size.clampToMinimumSize(minimumSize); | 258 size.clampToMinimumSize(minimumSize); |
239 return size; | 259 return size; |
240 } | 260 } |
241 | 261 |
242 void ImageResource::notifyObservers(const IntRect* changeRect) | 262 void ImageResource::notifyObservers(const IntRect* changeRect) |
243 { | 263 { |
244 ResourceClientWalker<ImageResourceClient> w(m_clients); | 264 ImageResourceObserverWalker w(m_observers); |
245 while (ImageResourceClient* c = w.next()) | 265 while (auto* observer = w.next()) { |
246 c->imageChanged(this, changeRect); | 266 observer->imageChanged(this, changeRect); |
247 | 267 } |
248 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
249 while (ImageResourceClient* c = w2.next()) | |
250 c->imageChanged(this, changeRect); | |
251 } | 268 } |
252 | 269 |
253 void ImageResource::clear() | 270 void ImageResource::clear() |
254 { | 271 { |
255 prune(); | 272 prune(); |
256 clearImage(); | 273 clearImage(); |
257 setEncodedSize(0); | 274 setEncodedSize(0); |
258 } | 275 } |
259 | 276 |
260 void ImageResource::setCustomAcceptHeader() | 277 void ImageResource::setCustomAcceptHeader() |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // to update MemoryCache. | 398 // to update MemoryCache. |
382 if (decodedSize() != 0) | 399 if (decodedSize() != 0) |
383 Resource::didAccessDecodedData(); | 400 Resource::didAccessDecodedData(); |
384 } | 401 } |
385 | 402 |
386 bool ImageResource::shouldPauseAnimation(const blink::Image* image) | 403 bool ImageResource::shouldPauseAnimation(const blink::Image* image) |
387 { | 404 { |
388 if (!image || image != m_image) | 405 if (!image || image != m_image) |
389 return false; | 406 return false; |
390 | 407 |
391 ResourceClientWalker<ImageResourceClient> w(m_clients); | 408 ImageResourceObserverWalker w(m_observers); |
392 while (ImageResourceClient* c = w.next()) { | 409 while (auto* observer = w.next()) { |
393 if (c->willRenderImage(this)) | 410 if (observer->willRenderImage()) |
394 return false; | 411 return false; |
395 } | 412 } |
396 | |
397 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
398 while (ImageResourceClient* c = w2.next()) { | |
399 if (c->willRenderImage(this)) | |
400 return false; | |
401 } | |
402 | |
403 return true; | 413 return true; |
404 } | 414 } |
405 | 415 |
406 void ImageResource::animationAdvanced(const blink::Image* image) | 416 void ImageResource::animationAdvanced(const blink::Image* image) |
407 { | 417 { |
408 if (!image || image != m_image) | 418 if (!image || image != m_image) |
409 return; | 419 return; |
410 notifyObservers(); | 420 notifyObservers(); |
411 } | 421 } |
412 | 422 |
413 void ImageResource::updateImageAnimationPolicy() | 423 void ImageResource::updateImageAnimationPolicy() |
414 { | 424 { |
415 if (!m_image) | 425 if (!m_image) |
416 return; | 426 return; |
417 | 427 |
418 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; | 428 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; |
419 ResourceClientWalker<ImageResourceClient> w(m_clients); | 429 ImageResourceObserverWalker w(m_observers); |
420 while (ImageResourceClient* c = w.next()) { | 430 while (auto* observer = w.next()) { |
421 if (c->getImageAnimationPolicy(this, newPolicy)) | 431 if (observer->getImageAnimationPolicy(newPolicy)) |
422 break; | 432 break; |
423 } | 433 } |
424 | 434 |
425 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
426 while (ImageResourceClient* c = w2.next()) { | |
427 if (c->getImageAnimationPolicy(this, newPolicy)) | |
428 break; | |
429 } | |
430 | |
431 if (m_image->animationPolicy() != newPolicy) { | 435 if (m_image->animationPolicy() != newPolicy) { |
432 m_image->resetAnimation(); | 436 m_image->resetAnimation(); |
433 m_image->setAnimationPolicy(newPolicy); | 437 m_image->setAnimationPolicy(newPolicy); |
434 } | 438 } |
435 } | 439 } |
436 | 440 |
437 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 441 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
438 { | 442 { |
439 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) | 443 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) |
440 return; | 444 return; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 if (response().wasFetchedViaServiceWorker()) | 491 if (response().wasFetchedViaServiceWorker()) |
488 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; | 492 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; |
489 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 493 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
490 return false; | 494 return false; |
491 if (passesAccessControlCheck(securityOrigin)) | 495 if (passesAccessControlCheck(securityOrigin)) |
492 return true; | 496 return true; |
493 return !securityOrigin->taintsCanvas(response().url()); | 497 return !securityOrigin->taintsCanvas(response().url()); |
494 } | 498 } |
495 | 499 |
496 } // namespace blink | 500 } // namespace blink |
OLD | NEW |