| 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 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 * | 20 * |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #ifndef ImageLoader_h | 23 #ifndef ImageLoader_h |
| 24 #define ImageLoader_h | 24 #define ImageLoader_h |
| 25 | 25 |
| 26 #include "core/CoreExport.h" | 26 #include "core/CoreExport.h" |
| 27 #include "core/fetch/ImageResource.h" | 27 #include "core/fetch/ImageResource.h" |
| 28 #include "core/fetch/ImageResourceContent.h" |
| 28 #include "core/fetch/ImageResourceObserver.h" | 29 #include "core/fetch/ImageResourceObserver.h" |
| 29 #include "platform/heap/Handle.h" | 30 #include "platform/heap/Handle.h" |
| 30 #include "wtf/HashSet.h" | 31 #include "wtf/HashSet.h" |
| 31 #include "wtf/WeakPtr.h" | 32 #include "wtf/WeakPtr.h" |
| 32 #include "wtf/text/AtomicString.h" | 33 #include "wtf/text/AtomicString.h" |
| 33 #include <memory> | 34 #include <memory> |
| 34 | 35 |
| 35 namespace blink { | 36 namespace blink { |
| 36 | 37 |
| 37 class IncrementLoadEventDelayCount; | 38 class IncrementLoadEventDelayCount; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 enum BypassMainWorldBehavior { BypassMainWorldCSP, DoNotBypassMainWorldCSP }; | 76 enum BypassMainWorldBehavior { BypassMainWorldCSP, DoNotBypassMainWorldCSP }; |
| 76 | 77 |
| 77 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, | 78 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, |
| 78 ReferrerPolicy = ReferrerPolicyDefault); | 79 ReferrerPolicy = ReferrerPolicyDefault); |
| 79 | 80 |
| 80 void elementDidMoveToNewDocument(); | 81 void elementDidMoveToNewDocument(); |
| 81 | 82 |
| 82 Element* element() const { return m_element; } | 83 Element* element() const { return m_element; } |
| 83 bool imageComplete() const { return m_imageComplete && !m_pendingTask; } | 84 bool imageComplete() const { return m_imageComplete && !m_pendingTask; } |
| 84 | 85 |
| 85 ImageResource* image() const { return m_image.get(); } | 86 ImageResourceContent* image() const { return m_image.get(); } |
| 87 ImageResource* imageResourceForImageDocument() const { |
| 88 return m_imageResourceForImageDocument; |
| 89 } |
| 86 // Cancels pending load events, and doesn't dispatch new ones. | 90 // Cancels pending load events, and doesn't dispatch new ones. |
| 87 void setImage(ImageResource*); | 91 void setImage(ImageResourceContent*); |
| 88 | 92 |
| 89 bool isLoadingImageDocument() { return m_loadingImageDocument; } | 93 bool isLoadingImageDocument() { return m_loadingImageDocument; } |
| 90 void setLoadingImageDocument() { m_loadingImageDocument = true; } | 94 void setLoadingImageDocument() { m_loadingImageDocument = true; } |
| 91 | 95 |
| 92 bool hasPendingActivity() const { | 96 bool hasPendingActivity() const { |
| 93 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; | 97 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool hasPendingError() const { return m_hasPendingErrorEvent; } | 100 bool hasPendingError() const { return m_hasPendingErrorEvent; } |
| 97 | 101 |
| 98 bool hadError() const { return !m_failedLoadURL.isEmpty(); } | 102 bool hadError() const { return !m_failedLoadURL.isEmpty(); } |
| 99 | 103 |
| 100 void dispatchPendingEvent(ImageEventSender*); | 104 void dispatchPendingEvent(ImageEventSender*); |
| 101 | 105 |
| 102 static void dispatchPendingLoadEvents(); | 106 static void dispatchPendingLoadEvents(); |
| 103 static void dispatchPendingErrorEvents(); | 107 static void dispatchPendingErrorEvents(); |
| 104 | 108 |
| 105 bool getImageAnimationPolicy(ImageAnimationPolicy&) final; | 109 bool getImageAnimationPolicy(ImageAnimationPolicy&) final; |
| 106 | 110 |
| 107 protected: | 111 protected: |
| 108 void imageNotifyFinished(ImageResource*) override; | 112 void imageNotifyFinished(ImageResourceContent*) override; |
| 109 | 113 |
| 110 private: | 114 private: |
| 111 class Task; | 115 class Task; |
| 112 | 116 |
| 113 // Called from the task or from updateFromElement to initiate the load. | 117 // Called from the task or from updateFromElement to initiate the load. |
| 114 void doUpdateFromElement(BypassMainWorldBehavior, | 118 void doUpdateFromElement(BypassMainWorldBehavior, |
| 115 UpdateFromElementBehavior, | 119 UpdateFromElementBehavior, |
| 116 const KURL&, | 120 const KURL&, |
| 117 ReferrerPolicy = ReferrerPolicyDefault); | 121 ReferrerPolicy = ReferrerPolicyDefault); |
| 118 | 122 |
| 119 virtual void dispatchLoadEvent() = 0; | 123 virtual void dispatchLoadEvent() = 0; |
| 120 virtual void noImageResourceToLoad() {} | 124 virtual void noImageResourceToLoad() {} |
| 121 | 125 |
| 122 void updatedHasPendingEvent(); | 126 void updatedHasPendingEvent(); |
| 123 | 127 |
| 124 void dispatchPendingLoadEvent(); | 128 void dispatchPendingLoadEvent(); |
| 125 void dispatchPendingErrorEvent(); | 129 void dispatchPendingErrorEvent(); |
| 126 | 130 |
| 127 LayoutImageResource* layoutImageResource(); | 131 LayoutImageResource* layoutImageResource(); |
| 128 void updateLayoutObject(); | 132 void updateLayoutObject(); |
| 129 | 133 |
| 130 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | 134 void setImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); |
| 131 void clearFailedLoadURL(); | 135 void clearFailedLoadURL(); |
| 132 void dispatchErrorEvent(); | 136 void dispatchErrorEvent(); |
| 133 void crossSiteOrCSPViolationOccurred(AtomicString); | 137 void crossSiteOrCSPViolationOccurred(AtomicString); |
| 134 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy); | 138 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy); |
| 135 | 139 |
| 136 void timerFired(TimerBase*); | 140 void timerFired(TimerBase*); |
| 137 | 141 |
| 138 KURL imageSourceToKURL(AtomicString) const; | 142 KURL imageSourceToKURL(AtomicString) const; |
| 139 | 143 |
| 140 // Used to determine whether to immediately initiate the load or to schedule a | 144 // Used to determine whether to immediately initiate the load or to schedule a |
| 141 // microtask. | 145 // microtask. |
| 142 bool shouldLoadImmediately(const KURL&) const; | 146 bool shouldLoadImmediately(const KURL&) const; |
| 143 | 147 |
| 144 // For Oilpan, we must run dispose() as a prefinalizer and call | 148 // For Oilpan, we must run dispose() as a prefinalizer and call |
| 145 // m_image->removeClient(this) (and more.) Otherwise, the ImageResource can | 149 // m_image->removeClient(this) (and more.) Otherwise, the ImageResource can |
| 146 // invoke didAddClient() for the ImageLoader that is about to die in the | 150 // invoke didAddClient() for the ImageLoader that is about to die in the |
| 147 // current lazy sweeping, and the didAddClient() can access on-heap objects | 151 // current lazy sweeping, and the didAddClient() can access on-heap objects |
| 148 // that have already been finalized in the current lazy sweeping. | 152 // that have already been finalized in the current lazy sweeping. |
| 149 void dispose(); | 153 void dispose(); |
| 150 | 154 |
| 151 Member<Element> m_element; | 155 Member<Element> m_element; |
| 152 Member<ImageResource> m_image; | 156 Member<ImageResourceContent> m_image; |
| 157 Member<ImageResource> m_imageResourceForImageDocument; |
| 153 // FIXME: Oilpan: We might be able to remove this Persistent hack when | 158 // FIXME: Oilpan: We might be able to remove this Persistent hack when |
| 154 // ImageResourceClient is traceable. | 159 // ImageResourceClient is traceable. |
| 155 GC_PLUGIN_IGNORE("http://crbug.com/383741") | 160 GC_PLUGIN_IGNORE("http://crbug.com/383741") |
| 156 Persistent<Element> m_keepAlive; | 161 Persistent<Element> m_keepAlive; |
| 157 | 162 |
| 158 Timer<ImageLoader> m_derefElementTimer; | 163 Timer<ImageLoader> m_derefElementTimer; |
| 159 AtomicString m_failedLoadURL; | 164 AtomicString m_failedLoadURL; |
| 160 WeakPtr<Task> m_pendingTask; // owned by Microtask | 165 WeakPtr<Task> m_pendingTask; // owned by Microtask |
| 161 std::unique_ptr<IncrementLoadEventDelayCount> m_loadDelayCounter; | 166 std::unique_ptr<IncrementLoadEventDelayCount> m_loadDelayCounter; |
| 162 bool m_hasPendingLoadEvent : 1; | 167 bool m_hasPendingLoadEvent : 1; |
| 163 bool m_hasPendingErrorEvent : 1; | 168 bool m_hasPendingErrorEvent : 1; |
| 164 bool m_imageComplete : 1; | 169 bool m_imageComplete : 1; |
| 165 bool m_loadingImageDocument : 1; | 170 bool m_loadingImageDocument : 1; |
| 166 bool m_elementIsProtected : 1; | 171 bool m_elementIsProtected : 1; |
| 167 bool m_suppressErrorEvents : 1; | 172 bool m_suppressErrorEvents : 1; |
| 168 }; | 173 }; |
| 169 | 174 |
| 170 } // namespace blink | 175 } // namespace blink |
| 171 | 176 |
| 172 #endif | 177 #endif |
| OLD | NEW |