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/ImageResourceObserver.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/ResourceClientOrObserverWalker.h" | |
30 #include "core/fetch/ResourceFetcher.h" | 29 #include "core/fetch/ResourceFetcher.h" |
31 #include "core/fetch/ResourceLoader.h" | 30 #include "core/fetch/ResourceLoader.h" |
32 #include "core/svg/graphics/SVGImage.h" | 31 #include "core/svg/graphics/SVGImage.h" |
33 #include "platform/Logging.h" | 32 #include "platform/Logging.h" |
34 #include "platform/RuntimeEnabledFeatures.h" | 33 #include "platform/RuntimeEnabledFeatures.h" |
35 #include "platform/SharedBuffer.h" | 34 #include "platform/SharedBuffer.h" |
36 #include "platform/TraceEvent.h" | 35 #include "platform/TraceEvent.h" |
37 #include "platform/graphics/BitmapImage.h" | 36 #include "platform/graphics/BitmapImage.h" |
38 #include "public/platform/Platform.h" | 37 #include "public/platform/Platform.h" |
39 #include "public/platform/WebCachePolicy.h" | 38 #include "public/platform/WebCachePolicy.h" |
40 #include "wtf/CurrentTime.h" | 39 #include "wtf/CurrentTime.h" |
40 #include "wtf/HashCountedSet.h" | |
41 #include "wtf/StdLibExtras.h" | 41 #include "wtf/StdLibExtras.h" |
42 #include "wtf/Vector.h" | |
42 #include <memory> | 43 #include <memory> |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 | 46 |
46 using ImageResourceObserverWalker = ResourceClientOrObserverWalker<ImageResource Observer, ImageResourceObserver>; | 47 namespace { |
48 | |
49 template <typename T> | |
50 Vector<T*> asVector(const HashCountedSet<T*>& set) | |
haraken
2016/08/12 10:45:20
I'd move this helper function to HashCountedSet.
yhirano
2016/08/16 08:57:24
Done.
| |
51 { | |
52 Vector<T*> vector; | |
53 copyToVector(set, vector); | |
54 return vector; | |
55 } | |
56 | |
57 } // namespace | |
47 | 58 |
48 ImageResource* ImageResource::fetch(FetchRequest& request, ResourceFetcher* fetc her) | 59 ImageResource* ImageResource::fetch(FetchRequest& request, ResourceFetcher* fetc her) |
49 { | 60 { |
50 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified) | 61 if (request.resourceRequest().requestContext() == WebURLRequest::RequestCont extUnspecified) |
51 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage); | 62 request.mutableResourceRequest().setRequestContext(WebURLRequest::Reques tContextImage); |
52 if (fetcher->context().pageDismissalEventBeingDispatched()) { | 63 if (fetcher->context().pageDismissalEventBeingDispatched()) { |
53 KURL requestURL = request.resourceRequest().url(); | 64 KURL requestURL = request.resourceRequest().url(); |
54 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.getOriginRestriction())) | 65 if (requestURL.isValid() && fetcher->context().canRequest(Resource::Imag e, request.resourceRequest(), requestURL, request.options(), request.forPreload( ), request.getOriginRestriction())) |
55 fetcher->context().sendImagePing(requestURL); | 66 fetcher->context().sendImagePing(requestURL); |
56 return nullptr; | 67 return nullptr; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 Resource::trace(visitor); | 101 Resource::trace(visitor); |
91 ImageObserver::trace(visitor); | 102 ImageObserver::trace(visitor); |
92 MultipartImageResourceParser::Client::trace(visitor); | 103 MultipartImageResourceParser::Client::trace(visitor); |
93 } | 104 } |
94 | 105 |
95 void ImageResource::checkNotify() | 106 void ImageResource::checkNotify() |
96 { | 107 { |
97 if (isLoading()) | 108 if (isLoading()) |
98 return; | 109 return; |
99 | 110 |
100 ImageResourceObserverWalker walker(m_observers); | 111 for (auto* observer : asVector(m_observers)) { |
101 while (auto* observer = walker.next()) { | 112 if (m_observers.contains(observer)) |
102 observer->imageNotifyFinished(this); | 113 observer->imageNotifyFinished(this); |
103 } | 114 } |
104 | 115 |
105 Resource::checkNotify(); | 116 Resource::checkNotify(); |
106 } | 117 } |
107 | 118 |
108 void ImageResource::markClientsAndObserversFinished() | 119 void ImageResource::markClientsAndObserversFinished() |
109 { | 120 { |
110 HashCountedSet<ImageResourceObserver*> observers; | 121 HashCountedSet<ImageResourceObserver*> observers; |
111 m_observers.swap(observers); | 122 m_observers.swap(observers); |
112 for (const auto& it : observers) | 123 for (const auto& it : observers) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 if (nextPriority.visibility == ResourcePriority::NotVisible) | 184 if (nextPriority.visibility == ResourcePriority::NotVisible) |
174 return; | 185 return; |
175 priority.visibility = ResourcePriority::Visible; | 186 priority.visibility = ResourcePriority::Visible; |
176 priority.intraPriorityValue += nextPriority.intraPriorityValue; | 187 priority.intraPriorityValue += nextPriority.intraPriorityValue; |
177 } | 188 } |
178 | 189 |
179 ResourcePriority ImageResource::priorityFromObservers() | 190 ResourcePriority ImageResource::priorityFromObservers() |
180 { | 191 { |
181 ResourcePriority priority; | 192 ResourcePriority priority; |
182 | 193 |
183 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 194 for (auto* observer : asVector(m_finishedObservers)) { |
184 while (const auto* observer = finishedWalker.next()) { | 195 if (m_finishedObservers.contains(observer)) |
185 priorityFromObserver(observer, priority); | 196 priorityFromObserver(observer, priority); |
186 } | 197 } |
187 | 198 for (auto* observer : asVector(m_observers)) { |
188 ImageResourceObserverWalker walker(m_observers); | 199 if (m_observers.contains(observer)) |
189 while (const auto* observer = walker.next()) { | 200 priorityFromObserver(observer, priority); |
190 priorityFromObserver(observer, priority); | |
191 } | 201 } |
192 | 202 |
193 return priority; | 203 return priority; |
194 } | 204 } |
195 | 205 |
196 bool ImageResource::isSafeToUnlock() const | 206 bool ImageResource::isSafeToUnlock() const |
197 { | 207 { |
198 // Note that |m_image| holds a reference to |data()| in addition to the one held by the Resource parent class. | 208 // Note that |m_image| holds a reference to |data()| in addition to the one held by the Resource parent class. |
199 return !m_image || (m_image->hasOneRef() && data()->refCount() == 2); | 209 return !m_image || (m_image->hasOneRef() && data()->refCount() == 2); |
200 } | 210 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed . | 337 // Don't let images that have a width/height >= 1 shrink below 1 when zoomed . |
328 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU nit(), | 338 LayoutSize minimumSize(size.width() > LayoutUnit() ? LayoutUnit(1) : LayoutU nit(), |
329 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit())) ; | 339 LayoutUnit(size.height() > LayoutUnit() ? LayoutUnit(1) : LayoutUnit())) ; |
330 size.scale(multiplier); | 340 size.scale(multiplier); |
331 size.clampToMinimumSize(minimumSize); | 341 size.clampToMinimumSize(minimumSize); |
332 return size; | 342 return size; |
333 } | 343 } |
334 | 344 |
335 void ImageResource::notifyObservers(const IntRect* changeRect) | 345 void ImageResource::notifyObservers(const IntRect* changeRect) |
336 { | 346 { |
337 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 347 for (auto* observer : asVector(m_finishedObservers)) { |
338 while (auto* observer = finishedWalker.next()) { | 348 if (m_finishedObservers.contains(observer)) |
339 observer->imageChanged(this, changeRect); | 349 observer->imageChanged(this, changeRect); |
340 } | 350 } |
341 | 351 for (auto* observer : asVector(m_observers)) { |
342 ImageResourceObserverWalker walker(m_observers); | 352 if (m_observers.contains(observer)) |
343 while (auto* observer = walker.next()) { | 353 observer->imageChanged(this, changeRect); |
344 observer->imageChanged(this, changeRect); | |
345 } | 354 } |
346 } | 355 } |
347 | 356 |
348 void ImageResource::clear() | 357 void ImageResource::clear() |
349 { | 358 { |
350 clearImage(); | 359 clearImage(); |
351 clearData(); | 360 clearData(); |
352 setEncodedSize(0); | 361 setEncodedSize(0); |
353 } | 362 } |
354 | 363 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 // to update MemoryCache. | 491 // to update MemoryCache. |
483 if (decodedSize() != 0) | 492 if (decodedSize() != 0) |
484 Resource::didAccessDecodedData(); | 493 Resource::didAccessDecodedData(); |
485 } | 494 } |
486 | 495 |
487 bool ImageResource::shouldPauseAnimation(const blink::Image* image) | 496 bool ImageResource::shouldPauseAnimation(const blink::Image* image) |
488 { | 497 { |
489 if (!image || image != m_image) | 498 if (!image || image != m_image) |
490 return false; | 499 return false; |
491 | 500 |
492 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 501 for (auto* observer : asVector(m_finishedObservers)) { |
493 while (auto* observer = finishedWalker.next()) { | 502 if (m_finishedObservers.contains(observer) && observer->willRenderImage( )) |
494 if (observer->willRenderImage()) | |
495 return false; | 503 return false; |
496 } | 504 } |
497 | 505 |
498 ImageResourceObserverWalker walker(m_observers); | 506 for (auto* observer : asVector(m_observers)) { |
499 while (auto* observer = walker.next()) { | 507 if (m_observers.contains(observer) && observer->willRenderImage()) |
500 if (observer->willRenderImage()) | |
501 return false; | 508 return false; |
502 } | 509 } |
503 | 510 |
504 return true; | 511 return true; |
505 } | 512 } |
506 | 513 |
507 void ImageResource::animationAdvanced(const blink::Image* image) | 514 void ImageResource::animationAdvanced(const blink::Image* image) |
508 { | 515 { |
509 if (!image || image != m_image) | 516 if (!image || image != m_image) |
510 return; | 517 return; |
511 notifyObservers(); | 518 notifyObservers(); |
512 } | 519 } |
513 | 520 |
514 void ImageResource::updateImageAnimationPolicy() | 521 void ImageResource::updateImageAnimationPolicy() |
515 { | 522 { |
516 if (!m_image) | 523 if (!m_image) |
517 return; | 524 return; |
518 | 525 |
519 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; | 526 ImageAnimationPolicy newPolicy = ImageAnimationPolicyAllowed; |
520 | 527 for (auto* observer : asVector(m_finishedObservers)) { |
521 ImageResourceObserverWalker finishedWalker(m_finishedObservers); | 528 if (m_finishedObservers.contains(observer) && observer->getImageAnimatio nPolicy(newPolicy)) |
522 while (auto* observer = finishedWalker.next()) { | 529 break; |
523 if (observer->getImageAnimationPolicy(newPolicy)) | 530 } |
531 for (auto* observer : asVector(m_observers)) { | |
532 if (m_observers.contains(observer) && observer->getImageAnimationPolicy( newPolicy)) | |
524 break; | 533 break; |
525 } | 534 } |
526 | 535 |
527 ImageResourceObserverWalker walker(m_observers); | |
528 while (auto* observer = walker.next()) { | |
529 if (observer->getImageAnimationPolicy(newPolicy)) | |
530 break; | |
531 } | |
532 | |
533 if (m_image->animationPolicy() != newPolicy) { | 536 if (m_image->animationPolicy() != newPolicy) { |
534 m_image->resetAnimation(); | 537 m_image->resetAnimation(); |
535 m_image->setAnimationPolicy(newPolicy); | 538 m_image->setAnimationPolicy(newPolicy); |
536 } | 539 } |
537 } | 540 } |
538 | 541 |
539 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) | 542 void ImageResource::reloadIfLoFi(ResourceFetcher* fetcher) |
540 { | 543 { |
541 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn) | 544 if (resourceRequest().loFiState() != WebURLRequest::LoFiOn) |
542 return; | 545 return; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 if (response().wasFetchedViaServiceWorker()) | 597 if (response().wasFetchedViaServiceWorker()) |
595 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; | 598 return response().serviceWorkerResponseType() != WebServiceWorkerRespons eTypeOpaque; |
596 if (!getImage()->currentFrameHasSingleSecurityOrigin()) | 599 if (!getImage()->currentFrameHasSingleSecurityOrigin()) |
597 return false; | 600 return false; |
598 if (passesAccessControlCheck(securityOrigin)) | 601 if (passesAccessControlCheck(securityOrigin)) |
599 return true; | 602 return true; |
600 return !securityOrigin->taintsCanvas(response().url()); | 603 return !securityOrigin->taintsCanvas(response().url()); |
601 } | 604 } |
602 | 605 |
603 } // namespace blink | 606 } // namespace blink |
OLD | NEW |