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 |
66 enum UpdateFromElementBehavior { | 71 enum UpdateFromElementBehavior { |
67 // This should be the update behavior when the element is attached to a
document, or when DOM mutations trigger a new load. | 72 // This should be the update behavior when the element is attached to a
document, or when DOM mutations trigger a new load. |
68 // Starts loading if a load hasn't already been started. | 73 // Starts loading if a load hasn't already been started. |
69 UpdateNormal, | 74 UpdateNormal, |
70 // This should be the update behavior when the resource was changed (via
'src', 'srcset' or 'sizes'). | 75 // This should be the update behavior when the resource was changed (via
'src', 'srcset' or 'sizes'). |
71 // Starts a new load even if a previous load of the same resource have f
ailed, to match Firefox's behavior. | 76 // Starts a new load even if a previous load of the same resource have f
ailed, to match Firefox's behavior. |
72 // FIXME - Verify that this is the right behavior according to the spec. | 77 // FIXME - Verify that this is the right behavior according to the spec. |
73 UpdateIgnorePreviousError, | 78 UpdateIgnorePreviousError, |
74 // This forces the image to update its intrinsic size, even if the image
source has not changed. | 79 // This forces the image to update its intrinsic size, even if the image
source has not changed. |
75 UpdateSizeChanged | 80 UpdateSizeChanged |
76 }; | 81 }; |
77 | 82 |
78 enum BypassMainWorldBehavior { | 83 enum BypassMainWorldBehavior { |
79 BypassMainWorldCSP, | 84 BypassMainWorldCSP, |
80 DoNotBypassMainWorldCSP | 85 DoNotBypassMainWorldCSP |
81 }; | 86 }; |
82 | 87 |
83 void updateFromElement(UpdateFromElementBehavior = UpdateNormal); | 88 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, LoadType =
LoadNormally); |
84 | 89 |
85 void elementDidMoveToNewDocument(); | 90 void elementDidMoveToNewDocument(); |
86 | 91 |
87 Element* element() const { return m_element; } | 92 Element* element() const { return m_element; } |
88 bool imageComplete() const | 93 bool imageComplete() const |
89 { | 94 { |
90 return m_imageComplete && !m_pendingTask; | 95 return m_imageComplete && !m_pendingTask; |
91 } | 96 } |
92 | 97 |
93 ImageResource* image() const { return m_image.get(); } | 98 ImageResource* image() const { return m_image.get(); } |
94 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. | 99 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. |
95 | 100 |
96 void setLoadingImageDocument() { m_loadingImageDocument = true; } | 101 void setLoadingImageDocument() { m_loadingImageDocument = true; } |
97 | 102 |
98 bool hasPendingActivity() const | 103 bool hasPendingActivity() const |
99 { | 104 { |
100 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; | 105 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; |
101 } | 106 } |
102 | 107 |
103 void dispatchPendingEvent(ImageEventSender*); | 108 void dispatchPendingEvent(ImageEventSender*); |
104 | 109 |
105 static void dispatchPendingLoadEvents(); | 110 static void dispatchPendingLoadEvents(); |
106 static void dispatchPendingErrorEvents(); | 111 static void dispatchPendingErrorEvents(); |
107 | 112 |
108 void addClient(ImageLoaderClient*); | 113 void addClient(ImageLoaderClient*); |
109 void removeClient(ImageLoaderClient*); | 114 void removeClient(ImageLoaderClient*); |
| 115 |
110 protected: | 116 protected: |
111 virtual void notifyFinished(Resource*) override; | 117 virtual void notifyFinished(Resource*) override; |
112 | 118 |
113 private: | 119 private: |
114 class Task; | 120 class Task; |
115 | 121 |
116 // Called from the task or from updateFromElement to initiate the load. | 122 // Called from the task or from updateFromElement to initiate the load. |
117 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior)
; | 123 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior)
; |
118 | 124 |
119 virtual void dispatchLoadEvent() = 0; | 125 virtual void dispatchLoadEvent() = 0; |
120 virtual String sourceURI(const AtomicString&) const = 0; | 126 virtual String sourceURI(const AtomicString&) const = 0; |
121 virtual void noImageResourceToLoad() { }; | |
122 | 127 |
123 void updatedHasPendingEvent(); | 128 void updatedHasPendingEvent(); |
124 | 129 |
125 void dispatchPendingLoadEvent(); | 130 void dispatchPendingLoadEvent(); |
126 void dispatchPendingErrorEvent(); | 131 void dispatchPendingErrorEvent(); |
127 | 132 |
128 RenderImageResource* renderImageResource(); | 133 RenderImageResource* renderImageResource(); |
129 void updateRenderer(); | 134 void updateRenderer(); |
130 | 135 |
131 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | 136 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); |
132 void sourceImageChanged(); | 137 void sourceImageChanged(); |
133 void clearFailedLoadURL(); | 138 void clearFailedLoadURL(); |
134 void crossSiteOrCSPViolationOccured(AtomicString); | 139 void crossSiteOrCSPViolationOccured(AtomicString); |
135 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior); | 140 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior); |
136 static ResourcePtr<ImageResource> createImageResourceForImageDocument(Docume
nt&, FetchRequest&); | 141 static ResourcePtr<ImageResource> createImageResourceForImageDocument(Docume
nt&, FetchRequest&); |
137 | 142 |
138 void timerFired(Timer<ImageLoader>*); | 143 void timerFired(Timer<ImageLoader>*); |
139 | 144 |
140 KURL imageSourceToKURL(AtomicString) const; | 145 KURL imageSourceToKURL(AtomicString) const; |
141 | 146 |
142 // Used to determine whether to immediately initiate the load | 147 // Used to determine whether to immediately initiate the load |
143 // or to schedule a microtask. | 148 // or to schedule a microtask. |
144 bool shouldLoadImmediately(const KURL&) const; | 149 bool shouldLoadImmediately(const KURL&, LoadType) const; |
145 | 150 |
146 void willRemoveClient(ImageLoaderClient&); | 151 void willRemoveClient(ImageLoaderClient&); |
147 | 152 |
148 RawPtrWillBeMember<Element> m_element; | 153 RawPtrWillBeMember<Element> m_element; |
149 ResourcePtr<ImageResource> m_image; | 154 ResourcePtr<ImageResource> m_image; |
150 // FIXME: Oilpan: We might be able to remove this Persistent hack when | 155 // FIXME: Oilpan: We might be able to remove this Persistent hack when |
151 // ImageResourceClient is traceable. | 156 // ImageResourceClient is traceable. |
152 GC_PLUGIN_IGNORE("http://crbug.com/383741") | 157 GC_PLUGIN_IGNORE("http://crbug.com/383741") |
153 RefPtrWillBePersistent<Element> m_keepAlive; | 158 RefPtrWillBePersistent<Element> m_keepAlive; |
154 #if ENABLE(OILPAN) | 159 #if ENABLE(OILPAN) |
(...skipping 26 matching lines...) Expand all Loading... |
181 bool m_imageComplete : 1; | 186 bool m_imageComplete : 1; |
182 bool m_loadingImageDocument : 1; | 187 bool m_loadingImageDocument : 1; |
183 bool m_elementIsProtected : 1; | 188 bool m_elementIsProtected : 1; |
184 bool m_suppressErrorEvents : 1; | 189 bool m_suppressErrorEvents : 1; |
185 unsigned m_highPriorityClientCount; | 190 unsigned m_highPriorityClientCount; |
186 }; | 191 }; |
187 | 192 |
188 } | 193 } |
189 | 194 |
190 #endif | 195 #endif |
OLD | NEW |