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