#ifndef TextTrackLoader_h
#define TextTrackLoader_h
#include "core/fetch/RawResource.h"
#include "core/fetch/ResourceOwner.h"
#include "core/html/track/vtt/VTTParser.h"
#include "platform/Timer.h"
#include "wtf/OwnPtr.h"
namespace WebCore {
class Document;
class TextTrackLoader;
class TextTrackLoaderClient : public ResourceOwner<RawResource> {
public:
virtual ~TextTrackLoaderClient() { }
virtual void newCuesAvailable(TextTrackLoader*) = 0;
virtual void cueLoadingCompleted(TextTrackLoader*, bool loadingFailed) = 0;
virtual void newRegionsAvailable(TextTrackLoader*) = 0;
};
class TextTrackLoader FINAL : public ResourceOwner<RawResource>, private VTTParserClient {
WTF_MAKE_NONCOPYABLE(TextTrackLoader);
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<TextTrackLoader> create(TextTrackLoaderClient& client, Document& document)
{
return adoptPtr(new TextTrackLoader(client, document));
}
virtual ~TextTrackLoader();
bool load(const KURL&, const AtomicString& crossOriginMode);
void cancelLoad();
enum State { Idle, Loading, Finished, Failed };
State loadState() { return m_state; }
void getNewCues(Vector<RefPtr<VTTCue> >& outputCues);
void getNewRegions(Vector<RefPtr<VTTRegion> >& outputRegions);
private:
virtual void dataReceived(Resource*, const char* data, int length) OVERRIDE;
virtual void notifyFinished(Resource*) OVERRIDE;
virtual void newCuesParsed() OVERRIDE;
virtual void newRegionsParsed() OVERRIDE;
virtual void fileFailedToParse() OVERRIDE;
TextTrackLoader(TextTrackLoaderClient&, Document&);
void cueLoadTimerFired(Timer<TextTrackLoader>*);
void corsPolicyPreventedLoad(SecurityOrigin*, const KURL&);
TextTrackLoaderClient& m_client;
OwnPtr<VTTParser> m_cueParser;
Document& m_document;
Timer<TextTrackLoader> m_cueLoadTimer;
State m_state;
bool m_newCuesAvailable;
};
}
#endif