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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 template<typename T> class EventSender; | 52 template<typename T> class EventSender; |
53 typedef EventSender<ImageLoader> ImageEventSender; | 53 typedef EventSender<ImageLoader> ImageEventSender; |
54 | 54 |
55 class ImageLoader : public ImageResourceClient { | 55 class ImageLoader : public ImageResourceClient { |
56 public: | 56 public: |
57 explicit ImageLoader(Element*); | 57 explicit ImageLoader(Element*); |
58 virtual ~ImageLoader(); | 58 virtual ~ImageLoader(); |
59 | 59 |
60 // This function should be called when the element is attached to a document
; starts | 60 // This function should be called when the element is attached to a document
; starts |
61 // loading if a load hasn't already been started. | 61 // loading if a load hasn't already been started. |
62 void updateFromElement(); | 62 void updateFromElement(bool calledFromTask = false, bool bypassMainWorldCSP
= false); |
63 | 63 |
64 // This function should be called whenever the 'src' attribute is set, even
if its value | 64 // 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). | 65 // doesn't change; starts new load unconditionally (matches Firefox and Oper
a behavior). |
66 void updateFromElementIgnoringPreviousError(); | 66 void updateFromElementIgnoringPreviousError(); |
67 | 67 |
68 void elementDidMoveToNewDocument(); | 68 void elementDidMoveToNewDocument(); |
69 | 69 |
70 Element* element() const { return m_element; } | 70 Element* element() const { return m_element; } |
71 bool imageComplete() const { return m_imageComplete; } | 71 bool imageComplete() const { return m_imageComplete && !m_pendingTask; } |
72 | 72 |
73 ImageResource* image() const { return m_image.get(); } | 73 ImageResource* image() const { return m_image.get(); } |
74 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. | 74 void setImage(ImageResource*); // Cancels pending load events, and doesn't d
ispatch new ones. |
75 | 75 |
76 void setLoadManually(bool loadManually) { m_loadManually = loadManually; } | 76 void setLoadManually(bool loadManually) { m_loadManually = loadManually; } |
77 | 77 |
78 bool hasPendingActivity() const { return m_hasPendingLoadEvent || m_hasPendi
ngErrorEvent; } | 78 bool hasPendingActivity() const { return m_hasPendingLoadEvent || m_hasPendi
ngErrorEvent || m_pendingTask; } |
79 | 79 |
80 void dispatchPendingEvent(ImageEventSender*); | 80 void dispatchPendingEvent(ImageEventSender*); |
81 | 81 |
82 static void dispatchPendingLoadEvents(); | 82 static void dispatchPendingLoadEvents(); |
83 static void dispatchPendingErrorEvents(); | 83 static void dispatchPendingErrorEvents(); |
84 | 84 |
85 void addClient(ImageLoaderClient*); | 85 void addClient(ImageLoaderClient*); |
86 void removeClient(ImageLoaderClient*); | 86 void removeClient(ImageLoaderClient*); |
87 | 87 |
88 protected: | 88 protected: |
89 virtual void notifyFinished(Resource*) OVERRIDE; | 89 virtual void notifyFinished(Resource*) OVERRIDE; |
90 | 90 |
91 private: | 91 private: |
| 92 class Task; |
| 93 |
92 virtual void dispatchLoadEvent() = 0; | 94 virtual void dispatchLoadEvent() = 0; |
93 virtual String sourceURI(const AtomicString&) const = 0; | 95 virtual String sourceURI(const AtomicString&) const = 0; |
94 | 96 |
95 void updatedHasPendingEvent(); | 97 void updatedHasPendingEvent(); |
96 | 98 |
97 void dispatchPendingLoadEvent(); | 99 void dispatchPendingLoadEvent(); |
98 void dispatchPendingErrorEvent(); | 100 void dispatchPendingErrorEvent(); |
99 | 101 |
100 RenderImageResource* renderImageResource(); | 102 RenderImageResource* renderImageResource(); |
101 void updateRenderer(); | 103 void updateRenderer(); |
102 | 104 |
103 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); | 105 void setImageWithoutConsideringPendingLoadEvent(ImageResource*); |
104 void sourceImageChanged(); | 106 void sourceImageChanged(); |
105 void clearFailedLoadURL(); | 107 void clearFailedLoadURL(); |
106 | 108 |
107 void timerFired(Timer<ImageLoader>*); | 109 void timerFired(Timer<ImageLoader>*); |
108 | 110 |
| 111 // Used to determine whether to immediately initiate the load |
| 112 // or to schedule a microtask. |
| 113 bool shouldLoadImmediately(const KURL&) const; |
| 114 |
109 typedef WillBePersistentHeapHashSet<RawPtrWillBeWeakMember<ImageLoaderClient
> > ImageLoaderClientSet; | 115 typedef WillBePersistentHeapHashSet<RawPtrWillBeWeakMember<ImageLoaderClient
> > ImageLoaderClientSet; |
110 | 116 |
111 Element* m_element; | 117 Element* m_element; |
112 ResourcePtr<ImageResource> m_image; | 118 ResourcePtr<ImageResource> m_image; |
113 ImageLoaderClientSet m_clients; | 119 ImageLoaderClientSet m_clients; |
114 Timer<ImageLoader> m_derefElementTimer; | 120 Timer<ImageLoader> m_derefElementTimer; |
115 AtomicString m_failedLoadURL; | 121 AtomicString m_failedLoadURL; |
| 122 Task* m_pendingTask; // owned by Microtask |
116 bool m_hasPendingLoadEvent : 1; | 123 bool m_hasPendingLoadEvent : 1; |
117 bool m_hasPendingErrorEvent : 1; | 124 bool m_hasPendingErrorEvent : 1; |
118 bool m_imageComplete : 1; | 125 bool m_imageComplete : 1; |
119 bool m_loadManually : 1; | 126 bool m_loadManually : 1; |
120 bool m_elementIsProtected : 1; | 127 bool m_elementIsProtected : 1; |
121 unsigned m_highPriorityClientCount; | 128 unsigned m_highPriorityClientCount; |
122 }; | 129 }; |
123 | 130 |
124 } | 131 } |
125 | 132 |
126 #endif | 133 #endif |
OLD | NEW |