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