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/ResourceClientWalker.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 namespace { |
| 45 |
| 46 using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResource
Observer, ImageResourceObserver>; |
| 47 |
| 48 } // namespace |
| 49 |
44 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request
, ResourceFetcher* fetcher) | 50 PassRefPtrWillBeRawPtr<ImageResource> ImageResource::fetch(FetchRequest& request
, ResourceFetcher* fetcher) |
45 { | 51 { |
46 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) | 52 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont
extUnspecified) |
47 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); | 53 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques
tContextImage); |
48 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 54 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
49 KURL requestURL = request.resourceRequest().url(); | 55 KURL requestURL = request.resourceRequest().url(); |
50 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) | 56 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag
e, request.resourceRequest(), requestURL, request.options(), request.forPreload(
), request.getOriginRestriction())) |
51 fetcher->context().sendImagePing(requestURL); | 57 fetcher->context().sendImagePing(requestURL); |
52 return nullptr; | 58 return nullptr; |
53 } | 59 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 112 } |
107 | 113 |
108 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions&
options) | 114 void ImageResource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions&
options) |
109 { | 115 { |
110 if (!fetcher || fetcher->autoLoadImages()) | 116 if (!fetcher || fetcher->autoLoadImages()) |
111 Resource::load(fetcher, options); | 117 Resource::load(fetcher, options); |
112 else | 118 else |
113 setLoading(false); | 119 setLoading(false); |
114 } | 120 } |
115 | 121 |
116 void ImageResource::didAddClient(ResourceClient* c) | 122 void ImageResource::addObserver(ImageResourceObserver* observer) |
117 { | 123 { |
| 124 willAddClientOrObserver(); |
| 125 |
| 126 m_observers.add(observer); |
| 127 |
| 128 if (!m_revalidatingRequest.isNull()) |
| 129 return; |
| 130 |
118 if (m_data && !m_image && !errorOccurred()) { | 131 if (m_data && !m_image && !errorOccurred()) { |
119 createImage(); | 132 createImage(); |
120 m_image->setData(m_data, true); | 133 m_image->setData(m_data, true); |
121 } | 134 } |
122 | 135 |
123 ASSERT(ImageResourceClient::isExpectedType(c)); | |
124 if (m_image && !m_image->isNull()) | 136 if (m_image && !m_image->isNull()) |
125 static_cast<ImageResourceClient*>(c)->imageChanged(this); | 137 observer->imageChanged(this); |
126 | |
127 Resource::didAddClient(c); | |
128 } | 138 } |
129 | 139 |
130 void ImageResource::didRemoveClient(ResourceClient* c) | 140 void ImageResource::removeObserver(ImageResourceObserver* observer) |
131 { | 141 { |
132 ASSERT(c); | 142 ASSERT(observer); |
133 ASSERT(ImageResourceClient::isExpectedType(c)); | 143 ASSERT(m_observers.contains(observer)); |
| 144 m_observers.remove(observer); |
| 145 didRemoveClientOrObserver(); |
| 146 } |
134 | 147 |
135 Resource::didRemoveClient(c); | 148 ResourcePriority ImageResource::priorityFromObservers() |
| 149 { |
| 150 ResourcePriority priority; |
| 151 ImageResourceObserverWalker w(m_observers); |
| 152 while (const auto* observer = w.next()) { |
| 153 ResourcePriority nextPriority = observer->computeResourcePriority(); |
| 154 if (nextPriority.visibility == ResourcePriority::NotVisible) |
| 155 continue; |
| 156 priority.visibility = ResourcePriority::Visible; |
| 157 priority.intraPriorityValue += nextPriority.intraPriorityValue; |
| 158 } |
| 159 return priority; |
136 } | 160 } |
137 | 161 |
138 bool ImageResource::isSafeToUnlock() const | 162 bool ImageResource::isSafeToUnlock() const |
139 { | 163 { |
140 // Note that |m_image| holds a reference to |m_data| in addition to the one
held by the Resource parent class. | 164 // Note that |m_image| holds a reference to |m_data| in addition to the one
held by the Resource parent class. |
141 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); | 165 return !m_image || (m_image->hasOneRef() && m_data->refCount() == 2); |
142 } | 166 } |
143 | 167 |
144 void ImageResource::destroyDecodedDataForFailedRevalidation() | 168 void ImageResource::destroyDecodedDataForFailedRevalidation() |
145 { | 169 { |
146 m_image = nullptr; | 170 m_image = nullptr; |
147 setDecodedSize(0); | 171 setDecodedSize(0); |
148 } | 172 } |
149 | 173 |
150 void ImageResource::destroyDecodedDataIfPossible() | 174 void ImageResource::destroyDecodedDataIfPossible() |
151 { | 175 { |
152 if (!hasClients() && !isLoading() && (!m_image || (m_image->hasOneRef() && m
_image->isBitmapImage()))) { | 176 if (!hasClientsOrObservers() && !isLoading() && (!m_image || (m_image->hasOn
eRef() && m_image->isBitmapImage()))) { |
153 m_image = nullptr; | 177 m_image = nullptr; |
154 setDecodedSize(0); | 178 setDecodedSize(0); |
155 } else if (m_image && !errorOccurred()) { | 179 } else if (m_image && !errorOccurred()) { |
156 m_image->destroyDecodedData(true); | 180 m_image->destroyDecodedData(true); |
157 } | 181 } |
158 } | 182 } |
159 | 183 |
160 void ImageResource::allClientsRemoved() | 184 void ImageResource::allClientsAndObserversRemoved() |
161 { | 185 { |
162 if (m_image && !errorOccurred()) | 186 if (m_image && !errorOccurred()) |
163 m_image->resetAnimation(); | 187 m_image->resetAnimation(); |
164 if (m_multipartParser) | 188 if (m_multipartParser) |
165 m_multipartParser->cancel(); | 189 m_multipartParser->cancel(); |
166 Resource::allClientsRemoved(); | 190 Resource::allClientsAndObserversRemoved(); |
167 } | 191 } |
168 | 192 |
169 void ImageResource::appendData(const char* data, size_t length) | 193 void ImageResource::appendData(const char* data, size_t length) |
170 { | 194 { |
171 if (m_multipartParser) { | 195 if (m_multipartParser) { |
172 m_multipartParser->appendData(data, length); | 196 m_multipartParser->appendData(data, length); |
173 } else { | 197 } else { |
174 Resource::appendData(data, length); | 198 Resource::appendData(data, length); |
175 updateImage(false); | 199 updateImage(false); |
176 } | 200 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 278 } |
255 | 279 |
256 void ImageResource::computeIntrinsicDimensions(FloatSize& intrinsicSize, FloatSi
ze& intrinsicRatio) | 280 void ImageResource::computeIntrinsicDimensions(FloatSize& intrinsicSize, FloatSi
ze& intrinsicRatio) |
257 { | 281 { |
258 if (m_image) | 282 if (m_image) |
259 m_image->computeIntrinsicDimensions(intrinsicSize, intrinsicRatio); | 283 m_image->computeIntrinsicDimensions(intrinsicSize, intrinsicRatio); |
260 } | 284 } |
261 | 285 |
262 void ImageResource::notifyObservers(const IntRect* changeRect) | 286 void ImageResource::notifyObservers(const IntRect* changeRect) |
263 { | 287 { |
264 ResourceClientWalker<ImageResourceClient> w(m_clients); | 288 ImageResourceObserverWalker w(m_observers); |
265 while (ImageResourceClient* c = w.next()) | 289 while (auto* observer = w.next()) { |
266 c->imageChanged(this, changeRect); | 290 observer->imageChanged(this, changeRect); |
267 | 291 } |
268 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
269 while (ImageResourceClient* c = w2.next()) | |
270 c->imageChanged(this, changeRect); | |
271 } | 292 } |
272 | 293 |
273 void ImageResource::clear() | 294 void ImageResource::clear() |
274 { | 295 { |
275 prune(); | 296 prune(); |
276 clearImage(); | 297 clearImage(); |
277 setEncodedSize(0); | 298 setEncodedSize(0); |
278 } | 299 } |
279 | 300 |
280 void ImageResource::setCustomAcceptHeader() | 301 void ImageResource::setCustomAcceptHeader() |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // to update MemoryCache. | 422 // to update MemoryCache. |
402 if (decodedSize() != 0) | 423 if (decodedSize() != 0) |
403 Resource::didAccessDecodedData(); | 424 Resource::didAccessDecodedData(); |
404 } | 425 } |
405 | 426 |
406 bool ImageResource::shouldPauseAnimation(const blink::Image* image) | 427 bool ImageResource::shouldPauseAnimation(const blink::Image* image) |
407 { | 428 { |
408 if (!image || image != m_image) | 429 if (!image || image != m_image) |
409 return false; | 430 return false; |
410 | 431 |
411 ResourceClientWalker<ImageResourceClient> w(m_clients); | 432 ImageResourceObserverWalker w(m_observers); |
412 while (ImageResourceClient* c = w.next()) { | 433 while (auto* observer = w.next()) { |
413 if (c->willRenderImage(this)) | 434 if (observer->willRenderImage()) |
414 return false; | 435 return false; |
415 } | 436 } |
416 | |
417 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
418 while (ImageResourceClient* c = w2.next()) { | |
419 if (c->willRenderImage(this)) | |
420 return false; | |
421 } | |
422 | |
423 return true; | 437 return true; |
424 } | 438 } |
425 | 439 |
426 void ImageResource::animationAdvanced(const blink::Image* image) | 440 void ImageResource::animationAdvanced(const blink::Image* image) |
427 { | 441 { |
428 if (!image || image != m_image) | 442 if (!image || image != m_image) |
429 return; | 443 return; |
430 notifyObservers(); | 444 notifyObservers(); |
431 } | 445 } |
432 | 446 |
433 void ImageResource::updateImageAnimationPolicy() | 447 void ImageResource::updateImageAnimationPolicy() |
434 { | 448 { |
435 if (!m_image) | 449 if (!m_image) |
436 return; | 450 return; |
437 | 451 |
438 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; | 452 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; |
439 ResourceClientWalker<ImageResourceClient> w(m_clients); | 453 ImageResourceObserverWalker w(m_observers); |
440 while (ImageResourceClient* c = w.next()) { | 454 while (auto* observer = w.next()) { |
441 if (c->getImageAnimationPolicy(this, newPolicy)) | 455 if (observer->getImageAnimationPolicy(newPolicy)) |
442 break; | 456 break; |
443 } | 457 } |
444 | 458 |
445 ResourceClientWalker<ImageResourceClient> w2(m_finishedClients); | |
446 while (ImageResourceClient* c = w2.next()) { | |
447 if (c->getImageAnimationPolicy(this, newPolicy)) | |
448 break; | |
449 } | |
450 | |
451 if (m_image->animationPolicy() != newPolicy) { | 459 if (m_image->animationPolicy() != newPolicy) { |
452 m_image->resetAnimation(); | 460 m_image->resetAnimation(); |
453 m_image->setAnimationPolicy(newPolicy); | 461 m_image->setAnimationPolicy(newPolicy); |
454 } | 462 } |
455 } | 463 } |
456 | 464 |
457 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 465 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
458 { | 466 { |
459 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) | 467 if (!m_response.httpHeaderField("chrome-proxy").contains("q=low")) |
460 return; | 468 return; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 if (response().wasFetchedViaServiceWorker()) | 505 if (response().wasFetchedViaServiceWorker()) |
498 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; | 506 return response().serviceWorkerResponseType() != WebServiceWorkerRespons
eTypeOpaque; |
499 if (!image()->currentFrameHasSingleSecurityOrigin()) | 507 if (!image()->currentFrameHasSingleSecurityOrigin()) |
500 return false; | 508 return false; |
501 if (passesAccessControlCheck(securityOrigin)) | 509 if (passesAccessControlCheck(securityOrigin)) |
502 return true; | 510 return true; |
503 return !securityOrigin->taintsCanvas(response().url()); | 511 return !securityOrigin->taintsCanvas(response().url()); |
504 } | 512 } |
505 | 513 |
506 } // namespace blink | 514 } // namespace blink |
OLD | NEW |