This source file includes following definitions.
- m_newCuesAvailable
- cueLoadTimerFired
- cancelLoad
- dataReceived
- corsPolicyPreventedLoad
- notifyFinished
- load
- newCuesParsed
- newRegionsParsed
- fileFailedToParse
- getNewCues
- getNewRegions
#include "config.h"
#include "core/loader/TextTrackLoader.h"
#include "FetchInitiatorTypeNames.h"
#include "core/dom/Document.h"
#include "core/fetch/CrossOriginAccessControl.h"
#include "core/fetch/FetchRequest.h"
#include "core/fetch/ResourceFetcher.h"
#include "platform/Logging.h"
#include "platform/SharedBuffer.h"
#include "platform/weborigin/SecurityOrigin.h"
namespace WebCore {
TextTrackLoader::TextTrackLoader(TextTrackLoaderClient& client, Document& document)
: m_client(client)
, m_document(document)
, m_cueLoadTimer(this, &TextTrackLoader::cueLoadTimerFired)
, m_state(Idle)
, m_newCuesAvailable(false)
{
}
TextTrackLoader::~TextTrackLoader()
{
}
void TextTrackLoader::cueLoadTimerFired(Timer<TextTrackLoader>* timer)
{
ASSERT_UNUSED(timer, timer == &m_cueLoadTimer);
if (m_newCuesAvailable) {
m_newCuesAvailable = false;
m_client.newCuesAvailable(this);
}
if (m_state >= Finished)
m_client.cueLoadingCompleted(this, m_state == Failed);
}
void TextTrackLoader::cancelLoad()
{
clearResource();
}
void TextTrackLoader::dataReceived(Resource* resource, const char* data, int length)
{
ASSERT(this->resource() == resource);
if (m_state == Failed)
return;
if (!m_cueParser)
m_cueParser = VTTParser::create(this, m_document);
m_cueParser->parseBytes(data, length);
}
void TextTrackLoader::corsPolicyPreventedLoad(SecurityOrigin* securityOrigin, const KURL& url)
{
String consoleMessage("Text track from origin '" + SecurityOrigin::create(url)->toString() + "' has been blocked from loading: Not at same origin as the document, and parent of track element does not have a 'crossorigin' attribute. Origin '" + securityOrigin->toString() + "' is therefore not allowed access.");
m_document.addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, consoleMessage);
m_state = Failed;
}
void TextTrackLoader::notifyFinished(Resource* resource)
{
ASSERT(this->resource() == resource);
if (m_state != Failed)
m_state = resource->errorOccurred() ? Failed : Finished;
if (m_state == Finished && m_cueParser)
m_cueParser->flush();
if (!m_cueLoadTimer.isActive())
m_cueLoadTimer.startOneShot(0, FROM_HERE);
cancelLoad();
}
bool TextTrackLoader::load(const KURL& url, const AtomicString& crossOriginMode)
{
cancelLoad();
FetchRequest cueRequest(ResourceRequest(m_document.completeURL(url)), FetchInitiatorTypeNames::texttrack);
if (!crossOriginMode.isNull()) {
cueRequest.setCrossOriginAccessControl(m_document.securityOrigin(), crossOriginMode);
} else if (!m_document.securityOrigin()->canRequest(url)) {
corsPolicyPreventedLoad(m_document.securityOrigin(), url);
return false;
}
ResourceFetcher* fetcher = m_document.fetcher();
setResource(fetcher->fetchRawResource(cueRequest));
return resource();
}
void TextTrackLoader::newCuesParsed()
{
if (m_cueLoadTimer.isActive())
return;
m_newCuesAvailable = true;
m_cueLoadTimer.startOneShot(0, FROM_HERE);
}
void TextTrackLoader::newRegionsParsed()
{
m_client.newRegionsAvailable(this);
}
void TextTrackLoader::fileFailedToParse()
{
WTF_LOG(Media, "TextTrackLoader::fileFailedToParse");
m_state = Failed;
if (!m_cueLoadTimer.isActive())
m_cueLoadTimer.startOneShot(0, FROM_HERE);
cancelLoad();
}
void TextTrackLoader::getNewCues(Vector<RefPtr<VTTCue> >& outputCues)
{
ASSERT(m_cueParser);
if (m_cueParser)
m_cueParser->getNewCues(outputCues);
}
void TextTrackLoader::getNewRegions(Vector<RefPtr<VTTRegion> >& outputRegions)
{
ASSERT(m_cueParser);
if (m_cueParser)
m_cueParser->getNewRegions(outputRegions);
}
}