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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 class IncrementLoadEventDelayCount; | 37 class IncrementLoadEventDelayCount; |
38 class FetchRequest; | 38 class FetchRequest; |
39 class Document; | 39 class Document; |
40 class Element; | 40 class Element; |
41 class ImageLoader; | 41 class ImageLoader; |
42 class LayoutImageResource; | 42 class LayoutImageResource; |
43 | 43 |
44 template<typename T> class EventSender; | |
45 using ImageEventSender = EventSender<ImageLoader>; | |
46 | |
47 class CORE_EXPORT ImageLoader : public NoBaseWillBeGarbageCollectedFinalized<Ima
geLoader>, public ResourceClient, public ImageResourceObserver { | 44 class CORE_EXPORT ImageLoader : public NoBaseWillBeGarbageCollectedFinalized<Ima
geLoader>, public ResourceClient, public ImageResourceObserver { |
48 WILL_BE_USING_PRE_FINALIZER(ImageLoader, dispose); | 45 WILL_BE_USING_PRE_FINALIZER(ImageLoader, dispose); |
49 USING_FAST_MALLOC_WILL_BE_REMOVED(ImageLoader); | 46 USING_FAST_MALLOC_WILL_BE_REMOVED(ImageLoader); |
50 public: | 47 public: |
51 explicit ImageLoader(Element*); | 48 explicit ImageLoader(Element*); |
52 ~ImageLoader() override; | 49 ~ImageLoader() override; |
53 | 50 |
54 DECLARE_TRACE(); | 51 DECLARE_TRACE(); |
55 | 52 |
56 enum UpdateFromElementBehavior { | 53 enum UpdateFromElementBehavior { |
(...skipping 15 matching lines...) Expand all Loading... |
72 DoNotBypassMainWorldCSP | 69 DoNotBypassMainWorldCSP |
73 }; | 70 }; |
74 | 71 |
75 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, ReferrerPol
icy = ReferrerPolicyDefault); | 72 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, ReferrerPol
icy = ReferrerPolicyDefault); |
76 | 73 |
77 void elementDidMoveToNewDocument(); | 74 void elementDidMoveToNewDocument(); |
78 | 75 |
79 Element* element() const { return m_element; } | 76 Element* element() const { return m_element; } |
80 bool imageComplete() const | 77 bool imageComplete() const |
81 { | 78 { |
82 return m_imageComplete && !m_pendingTask; | 79 return m_imageComplete && !m_pendingMicrotask; |
83 } | 80 } |
84 | 81 |
85 ImageResource* image() const { return m_image.get(); } | 82 ImageResource* image() const { return m_image.get(); } |
86 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. | 83 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. |
87 | 84 |
88 void setLoadingImageDocument() { m_loadingImageDocument = true; } | 85 void setLoadingImageDocument() { m_loadingImageDocument = true; } |
89 | 86 |
90 bool hasPendingActivity() const | 87 bool hasPendingActivity() const |
91 { | 88 { |
92 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; | 89 return m_hasPendingLoadEvent || hasPendingError() || m_pendingMicrotask; |
93 } | 90 } |
94 | 91 |
95 bool hasPendingError() const | 92 bool hasPendingError() const |
96 { | 93 { |
97 return m_hasPendingErrorEvent; | 94 return m_loadDelayCounterForError; |
98 } | 95 } |
99 | 96 |
100 void dispatchPendingEvent(ImageEventSender*); | 97 bool getImageAnimationPolicy(ImageAnimationPolicy&) final; |
101 | 98 |
102 static void dispatchPendingLoadEvents(); | |
103 static void dispatchPendingErrorEvents(); | |
104 | |
105 bool getImageAnimationPolicy(ImageAnimationPolicy&) final; | |
106 protected: | 99 protected: |
107 void notifyFinished(Resource*) override; | 100 virtual void finishInternal(ImageResource*) { } |
108 | 101 |
109 private: | 102 private: |
110 class Task; | 103 class Task; |
111 | 104 |
| 105 void notifyFinished(Resource*) final; |
| 106 |
112 // Called from the task or from updateFromElement to initiate the load. | 107 // Called from the task or from updateFromElement to initiate the load. |
113 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior,
ReferrerPolicy = ReferrerPolicyDefault); | 108 void doUpdateFromElement(BypassMainWorldBehavior, UpdateFromElementBehavior,
ReferrerPolicy = ReferrerPolicyDefault); |
114 | 109 |
115 virtual void dispatchLoadEvent() = 0; | |
116 virtual void noImageResourceToLoad() { } | 110 virtual void noImageResourceToLoad() { } |
117 | 111 |
118 void updatedHasPendingEvent(); | 112 void updatedHasPendingEvent(); |
119 | 113 |
120 void dispatchPendingLoadEvent(); | 114 void scheduleFinish(); |
121 void dispatchPendingErrorEvent(); | 115 void cancelPendingFinish(); |
| 116 void finish(); |
| 117 |
| 118 virtual void dispatchLoadEvent() = 0; |
| 119 |
| 120 void scheduleErrorEvent(); |
| 121 void cancelPendingErrorEvent(); |
| 122 void dispatchErrorEvent(); |
| 123 void dispatchErrorEventWithoutUpdatedHasPendingEvent(); |
122 | 124 |
123 LayoutImageResource* layoutImageResource(); | 125 LayoutImageResource* layoutImageResource(); |
124 void updateLayoutObject(); | 126 void updateLayoutObject(); |
125 | 127 |
126 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | 128 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); |
127 void clearFailedLoadURL(); | 129 void clearFailedLoadURL(); |
128 void dispatchErrorEvent(); | |
129 void crossSiteOrCSPViolationOccurred(AtomicString); | 130 void crossSiteOrCSPViolationOccurred(AtomicString); |
130 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy)
; | 131 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy)
; |
131 | 132 |
132 void timerFired(Timer<ImageLoader>*); | 133 void timerFired(Timer<ImageLoader>*); |
133 | 134 |
134 KURL imageSourceToKURL(AtomicString) const; | 135 KURL imageSourceToKURL(AtomicString) const; |
135 | 136 |
136 // Used to determine whether to immediately initiate the load | 137 // Used to determine whether to immediately initiate the load |
137 // or to schedule a microtask. | 138 // or to schedule a microtask. |
138 bool shouldLoadImmediately(const KURL&) const; | 139 bool shouldLoadImmediately(const KURL&) const; |
139 | 140 |
140 // For Oilpan, we must run dispose() as a prefinalizer and call | 141 // For Oilpan, we must run dispose() as a prefinalizer and call |
141 // m_image->removeClient(this) (and more.) Otherwise, the ImageResource can
invoke | 142 // m_image->removeClient(this) (and more.) Otherwise, the ImageResource can
invoke |
142 // didAddClient() for the ImageLoader that is about to die in the current | 143 // didAddClient() for the ImageLoader that is about to die in the current |
143 // lazy sweeping, and the didAddClient() can access on-heap objects that | 144 // lazy sweeping, and the didAddClient() can access on-heap objects that |
144 // have already been finalized in the current lazy sweeping. | 145 // have already been finalized in the current lazy sweeping. |
145 void dispose(); | 146 void dispose(); |
146 | 147 |
147 RawPtrWillBeMember<Element> m_element; | 148 RawPtrWillBeMember<Element> m_element; |
148 RefPtrWillBeMember<ImageResource> m_image; | 149 RefPtrWillBeMember<ImageResource> m_image; |
149 // 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 |
150 // ImageResourceClient is traceable. | 151 // ImageResourceClient is traceable. |
151 GC_PLUGIN_IGNORE("http://crbug.com/383741") | 152 GC_PLUGIN_IGNORE("http://crbug.com/383741") |
152 RefPtrWillBePersistent<Element> m_keepAlive; | 153 RefPtrWillBePersistent<Element> m_keepAlive; |
153 | 154 |
154 Timer<ImageLoader> m_derefElementTimer; | 155 Timer<ImageLoader> m_derefElementTimer; |
155 AtomicString m_failedLoadURL; | 156 AtomicString m_failedLoadURL; |
156 WeakPtr<Task> m_pendingTask; // owned by Microtask | 157 |
157 OwnPtr<IncrementLoadEventDelayCount> m_loadDelayCounter; | 158 WeakPtr<Task> m_pendingMicrotask; // owned by Microtask |
| 159 OwnPtr<CancellableTaskFactory> m_finishTask; |
| 160 OwnPtr<CancellableTaskFactory> m_dispatchErrorEventTask; |
| 161 |
| 162 OwnPtr<IncrementLoadEventDelayCount> m_loadDelayCounterForMicrotask; |
| 163 OwnPtr<IncrementLoadEventDelayCount> m_loadDelayCounterForFinish; |
| 164 OwnPtr<IncrementLoadEventDelayCount> m_loadDelayCounterForError; |
| 165 |
158 bool m_hasPendingLoadEvent : 1; | 166 bool m_hasPendingLoadEvent : 1; |
159 bool m_hasPendingErrorEvent : 1; | |
160 bool m_imageComplete : 1; | 167 bool m_imageComplete : 1; |
161 bool m_loadingImageDocument : 1; | 168 bool m_loadingImageDocument : 1; |
162 bool m_elementIsProtected : 1; | 169 bool m_elementIsProtected : 1; |
163 bool m_suppressErrorEvents : 1; | 170 bool m_suppressErrorEvents : 1; |
164 }; | 171 }; |
165 | 172 |
166 } // namespace blink | 173 } // namespace blink |
167 | 174 |
168 #endif | 175 #endif |
OLD | NEW |