| 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 <memory> | 26 #include <memory> |
| 27 #include "core/CoreExport.h" | 27 #include "core/CoreExport.h" |
| 28 #include "core/dom/TaskRunnerHelper.h" |
| 28 #include "core/loader/resource/ImageResource.h" | 29 #include "core/loader/resource/ImageResource.h" |
| 29 #include "core/loader/resource/ImageResourceContent.h" | 30 #include "core/loader/resource/ImageResourceContent.h" |
| 30 #include "core/loader/resource/ImageResourceObserver.h" | 31 #include "core/loader/resource/ImageResourceObserver.h" |
| 31 #include "platform/heap/Handle.h" | 32 #include "platform/heap/Handle.h" |
| 32 #include "platform/wtf/HashSet.h" | 33 #include "platform/wtf/HashSet.h" |
| 33 #include "platform/wtf/WeakPtr.h" | 34 #include "platform/wtf/WeakPtr.h" |
| 34 #include "platform/wtf/text/AtomicString.h" | 35 #include "platform/wtf/text/AtomicString.h" |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 class IncrementLoadEventDelayCount; | 39 class IncrementLoadEventDelayCount; |
| 39 class Element; | 40 class Element; |
| 40 class ImageLoader; | 41 class ImageLoader; |
| 41 class LayoutImageResource; | 42 class LayoutImageResource; |
| 42 | 43 |
| 43 template <typename T> | |
| 44 class EventSender; | |
| 45 using ImageEventSender = EventSender<ImageLoader>; | |
| 46 | |
| 47 class CORE_EXPORT ImageLoader : public GarbageCollectedFinalized<ImageLoader>, | 44 class CORE_EXPORT ImageLoader : public GarbageCollectedFinalized<ImageLoader>, |
| 48 public ImageResourceObserver { | 45 public ImageResourceObserver { |
| 49 USING_PRE_FINALIZER(ImageLoader, Dispose); | 46 USING_PRE_FINALIZER(ImageLoader, Dispose); |
| 50 | 47 |
| 51 public: | 48 public: |
| 52 explicit ImageLoader(Element*); | 49 explicit ImageLoader(Element*); |
| 53 ~ImageLoader() override; | 50 ~ImageLoader() override; |
| 54 | 51 |
| 55 DECLARE_TRACE(); | 52 DECLARE_TRACE(); |
| 56 | 53 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 ImageResource* ImageResourceForImageDocument() const { | 86 ImageResource* ImageResourceForImageDocument() const { |
| 90 return image_resource_for_image_document_; | 87 return image_resource_for_image_document_; |
| 91 } | 88 } |
| 92 // Cancels pending load events, and doesn't dispatch new ones. | 89 // Cancels pending load events, and doesn't dispatch new ones. |
| 93 void SetImage(ImageResourceContent*); | 90 void SetImage(ImageResourceContent*); |
| 94 | 91 |
| 95 bool IsLoadingImageDocument() { return loading_image_document_; } | 92 bool IsLoadingImageDocument() { return loading_image_document_; } |
| 96 void SetLoadingImageDocument() { loading_image_document_ = true; } | 93 void SetLoadingImageDocument() { loading_image_document_ = true; } |
| 97 | 94 |
| 98 bool HasPendingActivity() const { | 95 bool HasPendingActivity() const { |
| 99 return (image_ && !image_complete_) || has_pending_load_event_ || | 96 return (image_ && !image_complete_) || pending_load_event_.IsActive() || |
| 100 has_pending_error_event_ || pending_task_; | 97 pending_error_event_.IsActive() || pending_task_; |
| 101 } | 98 } |
| 102 | 99 |
| 103 bool HasPendingError() const { return has_pending_error_event_; } | 100 bool HasPendingError() const { return pending_error_event_.IsActive(); } |
| 104 | 101 |
| 105 bool HadError() const { return !failed_load_url_.IsEmpty(); } | 102 bool HadError() const { return !failed_load_url_.IsEmpty(); } |
| 106 | 103 |
| 107 void DispatchPendingEvent(ImageEventSender*); | |
| 108 | |
| 109 static void DispatchPendingLoadEvents(); | |
| 110 static void DispatchPendingErrorEvents(); | |
| 111 | |
| 112 bool GetImageAnimationPolicy(ImageAnimationPolicy&) final; | 104 bool GetImageAnimationPolicy(ImageAnimationPolicy&) final; |
| 113 | 105 |
| 114 protected: | 106 protected: |
| 115 void ImageChanged(ImageResourceContent*, const IntRect*) override; | 107 void ImageChanged(ImageResourceContent*, const IntRect*) override; |
| 116 void ImageNotifyFinished(ImageResourceContent*) override; | 108 void ImageNotifyFinished(ImageResourceContent*) override; |
| 117 | 109 |
| 118 private: | 110 private: |
| 119 class Task; | 111 class Task; |
| 120 | 112 |
| 121 // Called from the task or from updateFromElement to initiate the load. | 113 // Called from the task or from updateFromElement to initiate the load. |
| 122 void DoUpdateFromElement(BypassMainWorldBehavior, | 114 void DoUpdateFromElement(BypassMainWorldBehavior, |
| 123 UpdateFromElementBehavior, | 115 UpdateFromElementBehavior, |
| 124 const KURL&, | 116 const KURL&, |
| 125 ReferrerPolicy = kReferrerPolicyDefault); | 117 ReferrerPolicy = kReferrerPolicyDefault); |
| 126 | 118 |
| 127 virtual void DispatchLoadEvent() = 0; | 119 virtual void DispatchLoadEvent() = 0; |
| 128 virtual void NoImageResourceToLoad() {} | 120 virtual void NoImageResourceToLoad() {} |
| 129 | 121 |
| 130 void UpdatedHasPendingEvent(); | 122 void UpdatedHasPendingEvent(); |
| 131 | 123 |
| 132 void DispatchPendingLoadEvent(); | 124 void DispatchPendingLoadEvent(std::unique_ptr<IncrementLoadEventDelayCount>); |
| 133 void DispatchPendingErrorEvent(); | 125 void DispatchPendingErrorEvent(std::unique_ptr<IncrementLoadEventDelayCount>); |
| 134 | 126 |
| 135 LayoutImageResource* GetLayoutImageResource(); | 127 LayoutImageResource* GetLayoutImageResource(); |
| 136 void UpdateLayoutObject(); | 128 void UpdateLayoutObject(); |
| 137 | 129 |
| 138 void SetImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); | 130 void SetImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); |
| 139 void ClearFailedLoadURL(); | 131 void ClearFailedLoadURL(); |
| 140 void DispatchErrorEvent(); | 132 void DispatchErrorEvent(); |
| 141 void CrossSiteOrCSPViolationOccurred(AtomicString); | 133 void CrossSiteOrCSPViolationOccurred(AtomicString); |
| 142 void EnqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy); | 134 void EnqueueImageLoadingMicroTask(UpdateFromElementBehavior, ReferrerPolicy); |
| 143 | 135 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // and we delay Document load event from (1) to (3): | 172 // and we delay Document load event from (1) to (3): |
| 181 // - |ResourceFetcher::loaders_| delays Document load event from (1) to (2). | 173 // - |ResourceFetcher::loaders_| delays Document load event from (1) to (2). |
| 182 // - |delay_until_image_notify_finished_| delays Document load event from | 174 // - |delay_until_image_notify_finished_| delays Document load event from |
| 183 // the first ImageChanged() (at some time between (1) and (2)) until (3). | 175 // the first ImageChanged() (at some time between (1) and (2)) until (3). |
| 184 // Ideally, we might want to delay Document load event from (1) to (3), | 176 // Ideally, we might want to delay Document load event from (1) to (3), |
| 185 // but currently we piggyback on ImageChanged() because adding a callback | 177 // but currently we piggyback on ImageChanged() because adding a callback |
| 186 // hook at (1) might complicate the code. | 178 // hook at (1) might complicate the code. |
| 187 std::unique_ptr<IncrementLoadEventDelayCount> | 179 std::unique_ptr<IncrementLoadEventDelayCount> |
| 188 delay_until_image_notify_finished_; | 180 delay_until_image_notify_finished_; |
| 189 | 181 |
| 190 bool has_pending_load_event_ : 1; | 182 TaskHandle pending_load_event_; |
| 191 bool has_pending_error_event_ : 1; | 183 TaskHandle pending_error_event_; |
| 184 |
| 192 bool image_complete_ : 1; | 185 bool image_complete_ : 1; |
| 193 bool loading_image_document_ : 1; | 186 bool loading_image_document_ : 1; |
| 194 bool element_is_protected_ : 1; | 187 bool element_is_protected_ : 1; |
| 195 bool suppress_error_events_ : 1; | 188 bool suppress_error_events_ : 1; |
| 196 }; | 189 }; |
| 197 | 190 |
| 198 } // namespace blink | 191 } // namespace blink |
| 199 | 192 |
| 200 #endif | 193 #endif |
| OLD | NEW |