#ifndef ImageLoader_h
#define ImageLoader_h
#include "core/fetch/ImageResource.h"
#include "core/fetch/ImageResourceClient.h"
#include "core/fetch/ResourcePtr.h"
#include "heap/Handle.h"
#include "wtf/HashSet.h"
#include "wtf/text/AtomicString.h"
namespace WebCore {
class ImageLoaderClient : public WillBeGarbageCollectedMixin {
public:
virtual void notifyImageSourceChanged() = 0;
virtual bool requestsHighLiveResourceCachePriority() { return false; }
virtual void trace(Visitor*) = 0;
protected:
ImageLoaderClient() { }
};
class Element;
class ImageLoader;
class RenderImageResource;
template<typename T> class EventSender;
typedef EventSender<ImageLoader> ImageEventSender;
class ImageLoader : public ImageResourceClient {
public:
explicit ImageLoader(Element*);
virtual ~ImageLoader();
void updateFromElement();
void updateFromElementIgnoringPreviousError();
void elementDidMoveToNewDocument();
Element* element() const { return m_element; }
bool imageComplete() const { return m_imageComplete; }
ImageResource* image() const { return m_image.get(); }
void setImage(ImageResource*);
void setLoadManually(bool loadManually) { m_loadManually = loadManually; }
bool hasPendingActivity() const { return m_hasPendingLoadEvent || m_hasPendingErrorEvent; }
void dispatchPendingEvent(ImageEventSender*);
static void dispatchPendingLoadEvents();
static void dispatchPendingErrorEvents();
void addClient(ImageLoaderClient*);
void removeClient(ImageLoaderClient*);
protected:
virtual void notifyFinished(Resource*) OVERRIDE;
private:
virtual void dispatchLoadEvent() = 0;
virtual String sourceURI(const AtomicString&) const = 0;
void updatedHasPendingEvent();
void dispatchPendingLoadEvent();
void dispatchPendingErrorEvent();
RenderImageResource* renderImageResource();
void updateRenderer();
void setImageWithoutConsideringPendingLoadEvent(ImageResource*);
void sourceImageChanged();
void clearFailedLoadURL();
void timerFired(Timer<ImageLoader>*);
typedef WillBePersistentHeapHashSet<RawPtrWillBeWeakMember<ImageLoaderClient> > ImageLoaderClientSet;
Element* m_element;
ResourcePtr<ImageResource> m_image;
ImageLoaderClientSet m_clients;
Timer<ImageLoader> m_derefElementTimer;
AtomicString m_failedLoadURL;
bool m_hasPendingLoadEvent : 1;
bool m_hasPendingErrorEvent : 1;
bool m_imageComplete : 1;
bool m_loadManually : 1;
bool m_elementIsProtected : 1;
unsigned m_highPriorityClientCount;
};
}
#endif