#pragma once
#if ENABLE(VIDEO_TRACK)
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
#include "Timer.h"
#include "WebVTTParser.h"
#include <memory>
namespace WebCore {
class CachedTextTrack;
class Document;
class TextTrackLoader;
class ScriptExecutionContext;
class TextTrackLoaderClient {
public:
virtual ~TextTrackLoaderClient() { }
virtual void newCuesAvailable(TextTrackLoader*) = 0;
virtual void cueLoadingCompleted(TextTrackLoader*, bool loadingFailed) = 0;
virtual void newRegionsAvailable(TextTrackLoader*) = 0;
};
class TextTrackLoader : public CachedResourceClient, private WebVTTParserClient {
WTF_MAKE_NONCOPYABLE(TextTrackLoader);
WTF_MAKE_FAST_ALLOCATED;
public:
TextTrackLoader(TextTrackLoaderClient&, ScriptExecutionContext*);
virtual ~TextTrackLoader();
bool load(const URL&, const String& crossOriginMode, bool isInitiatingElementInUserAgentShadowTree);
void cancelLoad();
void getNewCues(Vector<RefPtr<TextTrackCue>>& outputCues);
void getNewRegions(Vector<RefPtr<VTTRegion>>& outputRegions);
private:
void notifyFinished(CachedResource&) override;
void deprecatedDidReceiveCachedResource(CachedResource&) override;
void newCuesParsed() override;
void newRegionsParsed() override;
void fileFailedToParse() override;
void processNewCueData(CachedResource&);
void cueLoadTimerFired();
void corsPolicyPreventedLoad();
enum State { Idle, Loading, Finished, Failed };
TextTrackLoaderClient& m_client;
std::unique_ptr<WebVTTParser> m_cueParser;
CachedResourceHandle<CachedTextTrack> m_resource;
ScriptExecutionContext* m_scriptExecutionContext;
Timer m_cueLoadTimer;
State m_state;
unsigned m_parseOffset;
bool m_newCuesAvailable;
};
}
#endif // ENABLE(VIDEO_TRACK)