OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * Copyright (C) 2004, 2009 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2009 Apple Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 template<typename T> class EventSender; | 57 template<typename T> class EventSender; |
58 typedef EventSender<ImageLoader> ImageEventSender; | 58 typedef EventSender<ImageLoader> ImageEventSender; |
59 | 59 |
60 class ImageLoader : public NoBaseWillBeGarbageCollectedFinalized<ImageLoader>, p
ublic ImageResourceClient { | 60 class ImageLoader : public NoBaseWillBeGarbageCollectedFinalized<ImageLoader>, p
ublic ImageResourceClient { |
61 public: | 61 public: |
62 explicit ImageLoader(Element*); | 62 explicit ImageLoader(Element*); |
63 virtual ~ImageLoader(); | 63 virtual ~ImageLoader(); |
64 void trace(Visitor*); | 64 void trace(Visitor*); |
65 | 65 |
66 enum LoadType { | |
67 LoadNormally, | |
68 ForceLoadImmediately | |
69 }; | |
70 | |
71 enum UpdateFromElementBehavior { | 66 enum UpdateFromElementBehavior { |
72 // This should be the update behavior when the element is attached to a
document, or when DOM mutations trigger a new load. | 67 // This should be the update behavior when the element is attached to a
document, or when DOM mutations trigger a new load. |
73 // Starts loading if a load hasn't already been started. | 68 // Starts loading if a load hasn't already been started. |
74 UpdateNormal, | 69 UpdateNormal, |
75 // This should be the update behavior when the resource was changed (via
'src', 'srcset' or 'sizes'). | 70 // This should be the update behavior when the resource was changed (via
'src', 'srcset' or 'sizes'). |
76 // Starts a new load even if a previous load of the same resource have f
ailed, to match Firefox's behavior. | 71 // Starts a new load even if a previous load of the same resource have f
ailed, to match Firefox's behavior. |
77 // FIXME - Verify that this is the right behavior according to the spec. | 72 // FIXME - Verify that this is the right behavior according to the spec. |
78 UpdateIgnorePreviousError, | 73 UpdateIgnorePreviousError, |
79 // This forces the image to update its intrinsic size, even if the image
source has not changed. | 74 // This forces the image to update its intrinsic size, even if the image
source has not changed. |
80 UpdateSizeChanged | 75 UpdateSizeChanged |
81 }; | 76 }; |
82 | 77 |
83 enum BypassMainWorldBehavior { | 78 enum BypassMainWorldBehavior { |
84 BypassMainWorldCSP, | 79 BypassMainWorldCSP, |
85 DoNotBypassMainWorldCSP | 80 DoNotBypassMainWorldCSP |
86 }; | 81 }; |
87 | 82 |
88 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, LoadType =
LoadNormally); | 83 void updateFromElement(UpdateFromElementBehavior = UpdateNormal); |
89 | 84 |
90 void elementDidMoveToNewDocument(); | 85 void elementDidMoveToNewDocument(); |
91 | 86 |
92 Element* element() const { return m_element; } | 87 Element* element() const { return m_element; } |
93 bool imageComplete() const | 88 bool imageComplete() const |
94 { | 89 { |
95 return m_imageComplete && !m_pendingTask; | 90 return m_imageComplete && !m_pendingTask; |
96 } | 91 } |
97 | 92 |
98 ImageResource* image() const { return m_image.get(); } | 93 ImageResource* image() const { return m_image.get(); } |
99 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. | 94 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. |
100 | 95 |
101 void setLoadingImageDocument() { m_loadingImageDocument = true; } | 96 void setLoadingImageDocument() { m_loadingImageDocument = true; } |
102 | 97 |
103 bool hasPendingActivity() const | 98 bool hasPendingActivity() const |
104 { | 99 { |
105 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; | 100 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; |
106 } | 101 } |
107 | 102 |
108 void dispatchPendingEvent(ImageEventSender*); | 103 void dispatchPendingEvent(ImageEventSender*); |
109 | 104 |
110 static void dispatchPendingLoadEvents(); | 105 static void dispatchPendingLoadEvents(); |
111 static void dispatchPendingErrorEvents(); | 106 static void dispatchPendingErrorEvents(); |
112 | 107 |
113 void addClient(ImageLoaderClient*); | 108 void addClient(ImageLoaderClient*); |
114 void removeClient(ImageLoaderClient*); | 109 void removeClient(ImageLoaderClient*); |
115 | |
116 protected: | 110 protected: |
117 virtual void notifyFinished(Resource*) override; | 111 virtual void notifyFinished(Resource*) override; |
118 | 112 |
119 private: | 113 private: |
120 class Task; | 114 class Task; |
121 | 115 |
122 // Called from the task or from updateFromElement to initiate the load. | 116 // Called from the task or from updateFromElement to initiate the load. |
123 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior)
; | 117 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior)
; |
124 | 118 |
125 virtual void dispatchLoadEvent() = 0; | 119 virtual void dispatchLoadEvent() = 0; |
126 virtual String sourceURI(const AtomicString&) const = 0; | 120 virtual String sourceURI(const AtomicString&) const = 0; |
| 121 virtual void noImageResourceToLoad() { }; |
127 | 122 |
128 void updatedHasPendingEvent(); | 123 void updatedHasPendingEvent(); |
129 | 124 |
130 void dispatchPendingLoadEvent(); | 125 void dispatchPendingLoadEvent(); |
131 void dispatchPendingErrorEvent(); | 126 void dispatchPendingErrorEvent(); |
132 | 127 |
133 RenderImageResource* renderImageResource(); | 128 RenderImageResource* renderImageResource(); |
134 void updateRenderer(); | 129 void updateRenderer(); |
135 | 130 |
136 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | 131 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); |
137 void sourceImageChanged(); | 132 void sourceImageChanged(); |
138 void clearFailedLoadURL(); | 133 void clearFailedLoadURL(); |
139 void crossSiteOrCSPViolationOccured(AtomicString); | 134 void crossSiteOrCSPViolationOccured(AtomicString); |
140 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior); | 135 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior); |
141 static ResourcePtr<ImageResource> createImageResourceForImageDocument(Docume
nt&, FetchRequest&); | 136 static ResourcePtr<ImageResource> createImageResourceForImageDocument(Docume
nt&, FetchRequest&); |
142 | 137 |
143 void timerFired(Timer<ImageLoader>*); | 138 void timerFired(Timer<ImageLoader>*); |
144 | 139 |
145 KURL imageSourceToKURL(AtomicString) const; | 140 KURL imageSourceToKURL(AtomicString) const; |
146 | 141 |
147 // Used to determine whether to immediately initiate the load | 142 // Used to determine whether to immediately initiate the load |
148 // or to schedule a microtask. | 143 // or to schedule a microtask. |
149 bool shouldLoadImmediately(const KURL&, LoadType) const; | 144 bool shouldLoadImmediately(const KURL&) const; |
150 | 145 |
151 void willRemoveClient(ImageLoaderClient&); | 146 void willRemoveClient(ImageLoaderClient&); |
152 | 147 |
153 RawPtrWillBeMember<Element> m_element; | 148 RawPtrWillBeMember<Element> m_element; |
154 ResourcePtr<ImageResource> m_image; | 149 ResourcePtr<ImageResource> m_image; |
155 // FIXME: Oilpan: We might be able to remove this Persistent hack when | 150 // FIXME: Oilpan: We might be able to remove this Persistent hack when |
156 // ImageResourceClient is traceable. | 151 // ImageResourceClient is traceable. |
157 GC_PLUGIN_IGNORE("http://crbug.com/383741") | 152 GC_PLUGIN_IGNORE("http://crbug.com/383741") |
158 RefPtrWillBePersistent<Element> m_keepAlive; | 153 RefPtrWillBePersistent<Element> m_keepAlive; |
159 #if ENABLE(OILPAN) | 154 #if ENABLE(OILPAN) |
(...skipping 26 matching lines...) Expand all Loading... |
186 bool m_imageComplete : 1; | 181 bool m_imageComplete : 1; |
187 bool m_loadingImageDocument : 1; | 182 bool m_loadingImageDocument : 1; |
188 bool m_elementIsProtected : 1; | 183 bool m_elementIsProtected : 1; |
189 bool m_suppressErrorEvents : 1; | 184 bool m_suppressErrorEvents : 1; |
190 unsigned m_highPriorityClientCount; | 185 unsigned m_highPriorityClientCount; |
191 }; | 186 }; |
192 | 187 |
193 } | 188 } |
194 | 189 |
195 #endif | 190 #endif |
OLD | NEW |