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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // Normal loading via ResourceFetcher/ResourceLoader. | 102 // Normal loading via ResourceFetcher/ResourceLoader. |
106 // |image_resource_for_image_document_| is null. | 103 // |image_resource_for_image_document_| is null. |
107 bool IsLoadingImageDocument() { return loading_image_document_; } | 104 bool IsLoadingImageDocument() { return loading_image_document_; } |
108 void SetLoadingImageDocument() { loading_image_document_ = true; } | 105 void SetLoadingImageDocument() { loading_image_document_ = true; } |
109 ImageResource* ImageResourceForImageDocument() const { | 106 ImageResource* ImageResourceForImageDocument() const { |
110 return image_resource_for_image_document_; | 107 return image_resource_for_image_document_; |
111 } | 108 } |
112 | 109 |
113 bool HasPendingActivity() const { return HasPendingEvent() || pending_task_; } | 110 bool HasPendingActivity() const { return HasPendingEvent() || pending_task_; } |
114 | 111 |
115 bool HasPendingError() const { return has_pending_error_event_; } | 112 bool HasPendingError() const { return pending_error_event_.IsActive(); } |
116 | 113 |
117 bool HadError() const { return !failed_load_url_.IsEmpty(); } | 114 bool HadError() const { return !failed_load_url_.IsEmpty(); } |
118 | 115 |
119 void DispatchPendingEvent(ImageEventSender*); | |
120 | |
121 static void DispatchPendingLoadEvents(); | |
122 static void DispatchPendingErrorEvents(); | |
123 | |
124 bool GetImageAnimationPolicy(ImageAnimationPolicy&) final; | 116 bool GetImageAnimationPolicy(ImageAnimationPolicy&) final; |
125 | 117 |
126 protected: | 118 protected: |
127 void ImageChanged(ImageResourceContent*, const IntRect*) override; | 119 void ImageChanged(ImageResourceContent*, const IntRect*) override; |
128 void ImageNotifyFinished(ImageResourceContent*) override; | 120 void ImageNotifyFinished(ImageResourceContent*) override; |
129 | 121 |
130 private: | 122 private: |
131 class Task; | 123 class Task; |
132 | 124 |
133 // Called from the task or from updateFromElement to initiate the load. | 125 // Called from the task or from updateFromElement to initiate the load. |
134 void DoUpdateFromElement(BypassMainWorldBehavior, | 126 void DoUpdateFromElement(BypassMainWorldBehavior, |
135 UpdateFromElementBehavior, | 127 UpdateFromElementBehavior, |
136 const KURL&, | 128 const KURL&, |
137 ReferrerPolicy = kReferrerPolicyDefault); | 129 ReferrerPolicy = kReferrerPolicyDefault); |
138 | 130 |
139 virtual void DispatchLoadEvent() = 0; | 131 virtual void DispatchLoadEvent() = 0; |
140 virtual void NoImageResourceToLoad() {} | 132 virtual void NoImageResourceToLoad() {} |
141 | 133 |
142 bool HasPendingEvent() const; | 134 bool HasPendingEvent() const; |
143 void UpdatedHasPendingEvent(); | 135 void UpdatedHasPendingEvent(); |
144 | 136 |
145 void DispatchPendingLoadEvent(); | 137 void DispatchPendingLoadEvent(std::unique_ptr<IncrementLoadEventDelayCount>); |
146 void DispatchPendingErrorEvent(); | 138 void DispatchPendingErrorEvent(std::unique_ptr<IncrementLoadEventDelayCount>); |
147 | 139 |
148 LayoutImageResource* GetLayoutImageResource(); | 140 LayoutImageResource* GetLayoutImageResource(); |
149 void UpdateLayoutObject(); | 141 void UpdateLayoutObject(); |
150 | 142 |
151 // Note: SetImage.*() are not a simple setter. | 143 // Note: SetImage.*() are not a simple setter. |
152 // Check the implementation to see what they do. | 144 // Check the implementation to see what they do. |
153 // TODO(hiroshige): Cleanup these methods. | 145 // TODO(hiroshige): Cleanup these methods. |
154 void SetImageForImageDocument(ImageResource*); | 146 void SetImageForImageDocument(ImageResource*); |
155 void SetImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); | 147 void SetImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); |
156 void UpdateImageState(ImageResourceContent*); | 148 void UpdateImageState(ImageResourceContent*); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // and we delay Document load event from (1) to (3): | 191 // and we delay Document load event from (1) to (3): |
200 // - |ResourceFetcher::loaders_| delays Document load event from (1) to (2). | 192 // - |ResourceFetcher::loaders_| delays Document load event from (1) to (2). |
201 // - |delay_until_image_notify_finished_| delays Document load event from | 193 // - |delay_until_image_notify_finished_| delays Document load event from |
202 // the first ImageChanged() (at some time between (1) and (2)) until (3). | 194 // the first ImageChanged() (at some time between (1) and (2)) until (3). |
203 // Ideally, we might want to delay Document load event from (1) to (3), | 195 // Ideally, we might want to delay Document load event from (1) to (3), |
204 // but currently we piggyback on ImageChanged() because adding a callback | 196 // but currently we piggyback on ImageChanged() because adding a callback |
205 // hook at (1) might complicate the code. | 197 // hook at (1) might complicate the code. |
206 std::unique_ptr<IncrementLoadEventDelayCount> | 198 std::unique_ptr<IncrementLoadEventDelayCount> |
207 delay_until_image_notify_finished_; | 199 delay_until_image_notify_finished_; |
208 | 200 |
209 // Indicates whether there is a pending task for the load/error event on | 201 TaskHandle pending_load_event_; |
210 // EventSender. Will be replaced when EventSender is removed crbug/624697. | 202 TaskHandle pending_error_event_; |
211 bool has_pending_load_event_ : 1; | |
212 bool has_pending_error_event_ : 1; | |
213 | 203 |
214 bool image_complete_ : 1; | 204 bool image_complete_ : 1; |
215 bool loading_image_document_ : 1; | 205 bool loading_image_document_ : 1; |
216 bool element_is_protected_ : 1; | 206 bool element_is_protected_ : 1; |
217 bool suppress_error_events_ : 1; | 207 bool suppress_error_events_ : 1; |
218 }; | 208 }; |
219 | 209 |
220 } // namespace blink | 210 } // namespace blink |
221 | 211 |
222 #endif | 212 #endif |
OLD | NEW |