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 | 135 |
144 void DispatchPendingLoadEvent(); | 136 void DispatchPendingLoadEvent(std::unique_ptr<IncrementLoadEventDelayCount>); |
145 void DispatchPendingErrorEvent(); | 137 void DispatchPendingErrorEvent(std::unique_ptr<IncrementLoadEventDelayCount>); |
146 | 138 |
147 LayoutImageResource* GetLayoutImageResource(); | 139 LayoutImageResource* GetLayoutImageResource(); |
148 void UpdateLayoutObject(); | 140 void UpdateLayoutObject(); |
149 | 141 |
150 // Note: SetImage.*() are not a simple setter. | 142 // Note: SetImage.*() are not a simple setter. |
151 // Check the implementation to see what they do. | 143 // Check the implementation to see what they do. |
152 // TODO(hiroshige): Cleanup these methods. | 144 // TODO(hiroshige): Cleanup these methods. |
153 void SetImageForImageDocument(ImageResource*); | 145 void SetImageForImageDocument(ImageResource*); |
154 void SetImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); | 146 void SetImageWithoutConsideringPendingLoadEvent(ImageResourceContent*); |
155 void UpdateImageState(ImageResourceContent*); | 147 void UpdateImageState(ImageResourceContent*); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // and we delay Document load event from (1) to (3): | 183 // and we delay Document load event from (1) to (3): |
192 // - |ResourceFetcher::loaders_| delays Document load event from (1) to (2). | 184 // - |ResourceFetcher::loaders_| delays Document load event from (1) to (2). |
193 // - |delay_until_image_notify_finished_| delays Document load event from | 185 // - |delay_until_image_notify_finished_| delays Document load event from |
194 // the first ImageChanged() (at some time between (1) and (2)) until (3). | 186 // the first ImageChanged() (at some time between (1) and (2)) until (3). |
195 // Ideally, we might want to delay Document load event from (1) to (3), | 187 // Ideally, we might want to delay Document load event from (1) to (3), |
196 // but currently we piggyback on ImageChanged() because adding a callback | 188 // but currently we piggyback on ImageChanged() because adding a callback |
197 // hook at (1) might complicate the code. | 189 // hook at (1) might complicate the code. |
198 std::unique_ptr<IncrementLoadEventDelayCount> | 190 std::unique_ptr<IncrementLoadEventDelayCount> |
199 delay_until_image_notify_finished_; | 191 delay_until_image_notify_finished_; |
200 | 192 |
201 // Indicates whether there is a pending task for the load/error event on | 193 TaskHandle pending_load_event_; |
202 // EventSender. Will be replaced when EventSender is removed crbug/624697. | 194 TaskHandle pending_error_event_; |
203 bool has_pending_load_event_ : 1; | |
204 bool has_pending_error_event_ : 1; | |
205 | 195 |
206 bool image_complete_ : 1; | 196 bool image_complete_ : 1; |
207 bool loading_image_document_ : 1; | 197 bool loading_image_document_ : 1; |
208 bool suppress_error_events_ : 1; | 198 bool suppress_error_events_ : 1; |
209 }; | 199 }; |
210 | 200 |
211 } // namespace blink | 201 } // namespace blink |
212 | 202 |
213 #endif | 203 #endif |
OLD | NEW |