| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 enum BypassMainWorldBehavior { BypassMainWorldCSP, DoNotBypassMainWorldCSP }; | 75 enum BypassMainWorldBehavior { BypassMainWorldCSP, DoNotBypassMainWorldCSP }; |
| 75 | 76 |
| 76 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, | 77 void updateFromElement(UpdateFromElementBehavior = UpdateNormal, |
| 77 ReferrerPolicy = ReferrerPolicyDefault); | 78 ReferrerPolicy = ReferrerPolicyDefault); |
| 78 | 79 |
| 79 void elementDidMoveToNewDocument(); | 80 void elementDidMoveToNewDocument(); |
| 80 | 81 |
| 81 Element* element() const { return m_element; } | 82 Element* element() const { return m_element; } |
| 82 bool imageComplete() const { return m_imageComplete && !m_pendingTask; } | 83 bool imageComplete() const { return m_imageComplete && !m_pendingTask; } |
| 83 | 84 |
| 84 ImageResource* image() const { return m_image.get(); } | 85 ImageResourceContent* image() const { return m_image.get(); } |
| 86 ImageResource* imageResourceForImageDocument() const { |
| 87 return m_imageResourceForImageDocument; |
| 88 } |
| 85 // Cancels pending load events, and doesn't dispatch new ones. | 89 // Cancels pending load events, and doesn't dispatch new ones. |
| 86 void setImage(ImageResource*); | 90 void setImage(ImageResourceContent*); |
| 87 | 91 |
| 88 bool isLoadingImageDocument() { return m_loadingImageDocument; } | 92 bool isLoadingImageDocument() { return m_loadingImageDocument; } |
| 89 void setLoadingImageDocument() { m_loadingImageDocument = true; } | 93 void setLoadingImageDocument() { m_loadingImageDocument = true; } |
| 90 | 94 |
| 91 bool hasPendingActivity() const { | 95 bool hasPendingActivity() const { |
| 92 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; | 96 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; |
| 93 } | 97 } |
| 94 | 98 |
| 95 bool hasPendingError() const { return m_hasPendingErrorEvent; } | 99 bool hasPendingError() const { return m_hasPendingErrorEvent; } |
| 96 | 100 |
| 97 bool hadError() const { return !m_failedLoadURL.isEmpty(); } | 101 bool hadError() const { return !m_failedLoadURL.isEmpty(); } |
| 98 | 102 |
| 99 void dispatchPendingEvent(ImageEventSender*); | 103 void dispatchPendingEvent(ImageEventSender*); |
| 100 | 104 |
| 101 static void dispatchPendingLoadEvents(); | 105 static void dispatchPendingLoadEvents(); |
| 102 static void dispatchPendingErrorEvents(); | 106 static void dispatchPendingErrorEvents(); |
| 103 | 107 |
| 104 bool getImageAnimationPolicy(ImageAnimationPolicy&) final; | 108 bool getImageAnimationPolicy(ImageAnimationPolicy&) final; |
| 105 | 109 |
| 106 protected: | 110 protected: |
| 107 void imageNotifyFinished(ImageResource*) override; | 111 void imageNotifyFinished(ImageResourceContent*) override; |
| 108 | 112 |
| 109 private: | 113 private: |
| 110 class Task; | 114 class Task; |
| 111 | 115 |
| 112 // Called from the task or from updateFromElement to initiate the load. | 116 // Called from the task or from updateFromElement to initiate the load. |
| 113 void doUpdateFromElement(BypassMainWorldBehavior, | 117 void doUpdateFromElement(BypassMainWorldBehavior, |
| 114 UpdateFromElementBehavior, | 118 UpdateFromElementBehavior, |
| 115 const KURL&, | 119 const KURL&, |
| 116 ReferrerPolicy = ReferrerPolicyDefault); | 120 ReferrerPolicy = ReferrerPolicyDefault); |
| 117 | 121 |
| 118 virtual void dispatchLoadEvent() = 0; | 122 virtual void dispatchLoadEvent() = 0; |
| 119 virtual void noImageResourceToLoad() {} | 123 virtual void noImageResourceToLoad() {} |
| 120 | 124 |
| 121 void updatedHasPendingEvent(); | 125 void updatedHasPendingEvent(); |
| 122 | 126 |
| 123 void dispatchPendingLoadEvent(); | 127 void dispatchPendingLoadEvent(); |
| 124 void dispatchPendingErrorEvent(); | 128 void dispatchPendingErrorEvent(); |
| 125 | 129 |
| 126 LayoutImageResource* layoutImageResource(); | 130 LayoutImageResource* layoutImageResource(); |
| 127 void updateLayoutObject(); | 131 void updateLayoutObject(); |
| 128 | 132 |
| 129 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | 133 void setImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); |
| 130 void clearFailedLoadURL(); | 134 void clearFailedLoadURL(); |
| 131 void dispatchErrorEvent(); | 135 void dispatchErrorEvent(); |
| 132 void crossSiteOrCSPViolationOccurred(AtomicString); | 136 void crossSiteOrCSPViolationOccurred(AtomicString); |
| 133 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy); | 137 void enqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy); |
| 134 | 138 |
| 135 void timerFired(TimerBase*); | 139 void timerFired(TimerBase*); |
| 136 | 140 |
| 137 KURL imageSourceToKURL(AtomicString) const; | 141 KURL imageSourceToKURL(AtomicString) const; |
| 138 | 142 |
| 139 // Used to determine whether to immediately initiate the load or to schedule a | 143 // Used to determine whether to immediately initiate the load or to schedule a |
| 140 // microtask. | 144 // microtask. |
| 141 bool shouldLoadImmediately(const KURL&) const; | 145 bool shouldLoadImmediately(const KURL&) const; |
| 142 | 146 |
| 143 // For Oilpan, we must run dispose() as a prefinalizer and call | 147 // For Oilpan, we must run dispose() as a prefinalizer and call |
| 144 // m_image->removeClient(this) (and more.) Otherwise, the ImageResource can | 148 // m_image->removeClient(this) (and more.) Otherwise, the ImageResource can |
| 145 // invoke didAddClient() for the ImageLoader that is about to die in the | 149 // invoke didAddClient() for the ImageLoader that is about to die in the |
| 146 // current lazy sweeping, and the didAddClient() can access on-heap objects | 150 // current lazy sweeping, and the didAddClient() can access on-heap objects |
| 147 // that have already been finalized in the current lazy sweeping. | 151 // that have already been finalized in the current lazy sweeping. |
| 148 void dispose(); | 152 void dispose(); |
| 149 | 153 |
| 150 Member<Element> m_element; | 154 Member<Element> m_element; |
| 151 Member<ImageResource> m_image; | 155 Member<ImageResourceContent> m_image; |
| 156 Member<ImageResource> m_imageResourceForImageDocument; |
| 152 // FIXME: Oilpan: We might be able to remove this Persistent hack when | 157 // FIXME: Oilpan: We might be able to remove this Persistent hack when |
| 153 // ImageResourceClient is traceable. | 158 // ImageResourceClient is traceable. |
| 154 GC_PLUGIN_IGNORE("http://crbug.com/383741") | 159 GC_PLUGIN_IGNORE("http://crbug.com/383741") |
| 155 Persistent<Element> m_keepAlive; | 160 Persistent<Element> m_keepAlive; |
| 156 | 161 |
| 157 Timer<ImageLoader> m_derefElementTimer; | 162 Timer<ImageLoader> m_derefElementTimer; |
| 158 AtomicString m_failedLoadURL; | 163 AtomicString m_failedLoadURL; |
| 159 WeakPtr<Task> m_pendingTask; // owned by Microtask | 164 WeakPtr<Task> m_pendingTask; // owned by Microtask |
| 160 std::unique_ptr<IncrementLoadEventDelayCount> m_loadDelayCounter; | 165 std::unique_ptr<IncrementLoadEventDelayCount> m_loadDelayCounter; |
| 161 bool m_hasPendingLoadEvent : 1; | 166 bool m_hasPendingLoadEvent : 1; |
| 162 bool m_hasPendingErrorEvent : 1; | 167 bool m_hasPendingErrorEvent : 1; |
| 163 bool m_imageComplete : 1; | 168 bool m_imageComplete : 1; |
| 164 bool m_loadingImageDocument : 1; | 169 bool m_loadingImageDocument : 1; |
| 165 bool m_elementIsProtected : 1; | 170 bool m_elementIsProtected : 1; |
| 166 bool m_suppressErrorEvents : 1; | 171 bool m_suppressErrorEvents : 1; |
| 167 }; | 172 }; |
| 168 | 173 |
| 169 } // namespace blink | 174 } // namespace blink |
| 170 | 175 |
| 171 #endif | 176 #endif |
| OLD | NEW |