| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | |
| 4 * Copyright (C) 2004, 2009 Apple Inc. All rights reserved. | |
| 5 * | |
| 6 * This library is free software; you can redistribute it and/or | |
| 7 * modify it under the terms of the GNU Library General Public | |
| 8 * License as published by the Free Software Foundation; either | |
| 9 * version 2 of the License, or (at your option) any later version. | |
| 10 * | |
| 11 * This library is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 * Library General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU Library General Public License | |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 19 * Boston, MA 02110-1301, USA. | |
| 20 * | |
| 21 */ | |
| 22 | |
| 23 #ifndef SKY_ENGINE_CORE_LOADER_IMAGELOADER_H_ | |
| 24 #define SKY_ENGINE_CORE_LOADER_IMAGELOADER_H_ | |
| 25 | |
| 26 #include "sky/engine/core/fetch/ImageResource.h" | |
| 27 #include "sky/engine/core/fetch/ImageResourceClient.h" | |
| 28 #include "sky/engine/core/fetch/ResourcePtr.h" | |
| 29 #include "sky/engine/platform/heap/Handle.h" | |
| 30 #include "sky/engine/wtf/HashSet.h" | |
| 31 #include "sky/engine/wtf/WeakPtr.h" | |
| 32 #include "sky/engine/wtf/text/AtomicString.h" | |
| 33 | |
| 34 namespace blink { | |
| 35 | |
| 36 class IncrementLoadEventDelayCount; | |
| 37 class FetchRequest; | |
| 38 class Document; | |
| 39 | |
| 40 class ImageLoaderClient { | |
| 41 public: | |
| 42 virtual void notifyImageSourceChanged() = 0; | |
| 43 | |
| 44 // Determines whether the observed ImageResource should have higher priority
in the decoded resources cache. | |
| 45 virtual bool requestsHighLiveResourceCachePriority() { return false; } | |
| 46 | |
| 47 protected: | |
| 48 ImageLoaderClient() { } | |
| 49 }; | |
| 50 | |
| 51 class Element; | |
| 52 class ImageLoader; | |
| 53 | |
| 54 template<typename T> class EventSender; | |
| 55 typedef EventSender<ImageLoader> ImageEventSender; | |
| 56 | |
| 57 class ImageLoader : public ImageResourceClient { | |
| 58 public: | |
| 59 explicit ImageLoader(Element*); | |
| 60 virtual ~ImageLoader(); | |
| 61 | |
| 62 enum LoadType { | |
| 63 LoadNormally, | |
| 64 ForceLoadImmediately | |
| 65 }; | |
| 66 | |
| 67 enum UpdateFromElementBehavior { | |
| 68 // This should be the update behavior when the element is attached to a
document, or when DOM mutations trigger a new load. | |
| 69 // Starts loading if a load hasn't already been started. | |
| 70 UpdateNormal, | |
| 71 // This should be the update behavior when the resource was changed (via
'src', 'srcset' or 'sizes'). | |
| 72 // Starts a new load even if a previous load of the same resource have f
ailed, to match Firefox's behavior. | |
| 73 // FIXME - Verify that this is the right behavior according to the spec. | |
| 74 UpdateIgnorePreviousError, | |
| 75 // This forces the image to update its intrinsic size, even if the image
source has not changed. | |
| 76 UpdateSizeChanged | |
| 77 }; | |
| 78 | |
| 79 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, LoadType =
LoadNormally); | |
| 80 | |
| 81 void elementDidMoveToNewDocument(); | |
| 82 | |
| 83 Element* element() const { return m_element; } | |
| 84 bool imageComplete() const | |
| 85 { | |
| 86 return m_imageComplete && !m_pendingTask; | |
| 87 } | |
| 88 | |
| 89 ImageResource* image() const { return m_image.get(); } | |
| 90 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. | |
| 91 | |
| 92 bool hasPendingActivity() const | |
| 93 { | |
| 94 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; | |
| 95 } | |
| 96 | |
| 97 void dispatchPendingEvent(ImageEventSender*); | |
| 98 | |
| 99 static void dispatchPendingLoadEvents(); | |
| 100 static void dispatchPendingErrorEvents(); | |
| 101 | |
| 102 void addClient(ImageLoaderClient*); | |
| 103 void removeClient(ImageLoaderClient*); | |
| 104 | |
| 105 protected: | |
| 106 virtual void notifyFinished(Resource*) override; | |
| 107 | |
| 108 private: | |
| 109 class Task; | |
| 110 | |
| 111 // Called from the task or from updateFromElement to initiate the load. | |
| 112 void doUpdateFromElement(UpdateFromElementBehavior); | |
| 113 | |
| 114 virtual void dispatchLoadEvent() = 0; | |
| 115 virtual String sourceURI(const AtomicString&) const = 0; | |
| 116 | |
| 117 void updatedHasPendingEvent(); | |
| 118 | |
| 119 void dispatchPendingLoadEvent(); | |
| 120 void dispatchPendingErrorEvent(); | |
| 121 | |
| 122 void updateRenderer(); | |
| 123 | |
| 124 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | |
| 125 void sourceImageChanged(); | |
| 126 void clearFailedLoadURL(); | |
| 127 void crossSiteOrCSPViolationOccured(AtomicString); | |
| 128 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior); | |
| 129 | |
| 130 void timerFired(Timer<ImageLoader>*); | |
| 131 | |
| 132 KURL imageSourceToKURL(AtomicString) const; | |
| 133 | |
| 134 // Used to determine whether to immediately initiate the load | |
| 135 // or to schedule a microtask. | |
| 136 bool shouldLoadImmediately(const KURL&, LoadType) const; | |
| 137 | |
| 138 void willRemoveClient(ImageLoaderClient&); | |
| 139 | |
| 140 RawPtr<Element> m_element; | |
| 141 ResourcePtr<ImageResource> m_image; | |
| 142 RefPtr<Element> m_keepAlive; | |
| 143 HashSet<ImageLoaderClient*> m_clients; | |
| 144 Timer<ImageLoader> m_derefElementTimer; | |
| 145 AtomicString m_failedLoadURL; | |
| 146 WeakPtr<Task> m_pendingTask; // owned by Microtask | |
| 147 OwnPtr<IncrementLoadEventDelayCount> m_loadDelayCounter; | |
| 148 bool m_hasPendingLoadEvent : 1; | |
| 149 bool m_hasPendingErrorEvent : 1; | |
| 150 bool m_imageComplete : 1; | |
| 151 bool m_elementIsProtected : 1; | |
| 152 unsigned m_highPriorityClientCount; | |
| 153 }; | |
| 154 | |
| 155 } | |
| 156 | |
| 157 #endif // SKY_ENGINE_CORE_LOADER_IMAGELOADER_H_ | |
| OLD | NEW |