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 * |
(...skipping 10 matching lines...) Expand all Loading... |
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/fetch/ImageResource.h" | 26 #include "core/fetch/ImageResource.h" |
27 #include "core/fetch/ImageResourceClient.h" | 27 #include "core/fetch/ImageResourceClient.h" |
28 #include "core/fetch/ResourcePtr.h" | 28 #include "core/fetch/ResourcePtr.h" |
29 #include "platform/heap/Handle.h" | 29 #include "platform/heap/Handle.h" |
30 #include "wtf/HashSet.h" | 30 #include "wtf/HashSet.h" |
| 31 #include "wtf/WeakPtr.h" |
31 #include "wtf/text/AtomicString.h" | 32 #include "wtf/text/AtomicString.h" |
32 | 33 |
33 namespace WebCore { | 34 namespace WebCore { |
34 | 35 |
| 36 class IncrementLoadEventDelayCount; |
| 37 |
35 class ImageLoaderClient : public WillBeGarbageCollectedMixin { | 38 class ImageLoaderClient : public WillBeGarbageCollectedMixin { |
36 public: | 39 public: |
37 virtual void notifyImageSourceChanged() = 0; | 40 virtual void notifyImageSourceChanged() = 0; |
38 | 41 |
39 // Determines whether the observed ImageResource should have higher priority
in the decoded resources cache. | 42 // Determines whether the observed ImageResource should have higher priority
in the decoded resources cache. |
40 virtual bool requestsHighLiveResourceCachePriority() { return false; } | 43 virtual bool requestsHighLiveResourceCachePriority() { return false; } |
41 | 44 |
42 virtual void trace(Visitor*) { } | 45 virtual void trace(Visitor*) { } |
43 | 46 |
44 protected: | 47 protected: |
(...skipping 16 matching lines...) Expand all Loading... |
61 // loading if a load hasn't already been started. | 64 // loading if a load hasn't already been started. |
62 void updateFromElement(); | 65 void updateFromElement(); |
63 | 66 |
64 // This function should be called whenever the 'src' attribute is set, even
if its value | 67 // This function should be called whenever the 'src' attribute is set, even
if its value |
65 // doesn't change; starts new load unconditionally (matches Firefox and Oper
a behavior). | 68 // doesn't change; starts new load unconditionally (matches Firefox and Oper
a behavior). |
66 void updateFromElementIgnoringPreviousError(); | 69 void updateFromElementIgnoringPreviousError(); |
67 | 70 |
68 void elementDidMoveToNewDocument(); | 71 void elementDidMoveToNewDocument(); |
69 | 72 |
70 Element* element() const { return m_element; } | 73 Element* element() const { return m_element; } |
71 bool imageComplete() const { return m_imageComplete; } | 74 bool imageComplete() const |
| 75 { |
| 76 return m_imageComplete && !m_pendingTask; |
| 77 } |
72 | 78 |
73 ImageResource* image() const { return m_image.get(); } | 79 ImageResource* image() const { return m_image.get(); } |
74 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. | 80 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. |
75 | 81 |
76 void setLoadManually(bool loadManually) { m_loadManually = loadManually; } | 82 void setLoadManually(bool loadManually) { m_loadManually = loadManually; } |
77 | 83 |
78 bool hasPendingActivity() const { return m_hasPendingLoadEvent || m_hasPendi
ngErrorEvent; } | 84 bool hasPendingActivity() const |
| 85 { |
| 86 return m_hasPendingLoadEvent || m_hasPendingErrorEvent || m_pendingTask; |
| 87 } |
79 | 88 |
80 void dispatchPendingEvent(ImageEventSender*); | 89 void dispatchPendingEvent(ImageEventSender*); |
81 | 90 |
82 static void dispatchPendingLoadEvents(); | 91 static void dispatchPendingLoadEvents(); |
83 static void dispatchPendingErrorEvents(); | 92 static void dispatchPendingErrorEvents(); |
84 | 93 |
85 void addClient(ImageLoaderClient*); | 94 void addClient(ImageLoaderClient*); |
86 void removeClient(ImageLoaderClient*); | 95 void removeClient(ImageLoaderClient*); |
87 | 96 |
88 protected: | 97 protected: |
89 virtual void notifyFinished(Resource*) OVERRIDE; | 98 virtual void notifyFinished(Resource*) OVERRIDE; |
90 | 99 |
91 private: | 100 private: |
| 101 class Task; |
| 102 |
| 103 // Called from the task or from updateFromElement to initiate the load. |
| 104 void doUpdateFromElement(bool bypassMainWorldCSP = false); |
| 105 |
92 virtual void dispatchLoadEvent() = 0; | 106 virtual void dispatchLoadEvent() = 0; |
93 virtual String sourceURI(const AtomicString&) const = 0; | 107 virtual String sourceURI(const AtomicString&) const = 0; |
94 | 108 |
95 void updatedHasPendingEvent(); | 109 void updatedHasPendingEvent(); |
96 | 110 |
97 void dispatchPendingLoadEvent(); | 111 void dispatchPendingLoadEvent(); |
98 void dispatchPendingErrorEvent(); | 112 void dispatchPendingErrorEvent(); |
99 | 113 |
100 RenderImageResource* renderImageResource(); | 114 RenderImageResource* renderImageResource(); |
101 void updateRenderer(); | 115 void updateRenderer(); |
102 | 116 |
103 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | 117 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); |
104 void sourceImageChanged(); | 118 void sourceImageChanged(); |
105 void clearFailedLoadURL(); | 119 void clearFailedLoadURL(); |
106 | 120 |
107 void timerFired(Timer<ImageLoader>*); | 121 void timerFired(Timer<ImageLoader>*); |
108 | 122 |
| 123 KURL imageURL() const; |
| 124 |
| 125 // Used to determine whether to immediately initiate the load |
| 126 // or to schedule a microtask. |
| 127 bool shouldLoadImmediately(const KURL&) const; |
| 128 |
109 typedef WillBePersistentHeapHashSet<RawPtrWillBeWeakMember<ImageLoaderClient
> > ImageLoaderClientSet; | 129 typedef WillBePersistentHeapHashSet<RawPtrWillBeWeakMember<ImageLoaderClient
> > ImageLoaderClientSet; |
110 | 130 |
111 Element* m_element; | 131 Element* m_element; |
112 ResourcePtr<ImageResource> m_image; | 132 ResourcePtr<ImageResource> m_image; |
113 ImageLoaderClientSet m_clients; | 133 ImageLoaderClientSet m_clients; |
114 Timer<ImageLoader> m_derefElementTimer; | 134 Timer<ImageLoader> m_derefElementTimer; |
115 AtomicString m_failedLoadURL; | 135 AtomicString m_failedLoadURL; |
| 136 WeakPtr<Task> m_pendingTask; // owned by Microtask |
| 137 OwnPtr<IncrementLoadEventDelayCount> m_delayLoad; |
116 bool m_hasPendingLoadEvent : 1; | 138 bool m_hasPendingLoadEvent : 1; |
117 bool m_hasPendingErrorEvent : 1; | 139 bool m_hasPendingErrorEvent : 1; |
118 bool m_imageComplete : 1; | 140 bool m_imageComplete : 1; |
119 bool m_loadManually : 1; | 141 bool m_loadManually : 1; |
120 bool m_elementIsProtected : 1; | 142 bool m_elementIsProtected : 1; |
121 unsigned m_highPriorityClientCount; | 143 unsigned m_highPriorityClientCount; |
122 }; | 144 }; |
123 | 145 |
124 } | 146 } |
125 | 147 |
126 #endif | 148 #endif |
OLD | NEW |