summaryrefslogtreecommitdiff
path: root/Source/WebCore/loader/TextTrackLoader.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/loader/TextTrackLoader.cpp
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/loader/TextTrackLoader.cpp')
-rw-r--r--Source/WebCore/loader/TextTrackLoader.cpp122
1 files changed, 51 insertions, 71 deletions
diff --git a/Source/WebCore/loader/TextTrackLoader.cpp b/Source/WebCore/loader/TextTrackLoader.cpp
index 35d788cfb..866096875 100644
--- a/Source/WebCore/loader/TextTrackLoader.cpp
+++ b/Source/WebCore/loader/TextTrackLoader.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,10 +11,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -35,10 +36,8 @@
#include "CrossOriginAccessControl.h"
#include "Document.h"
#include "Logging.h"
-#include "ResourceBuffer.h"
-#include "ScriptCallStack.h"
-#include "SecurityOrigin.h"
-#include "TextTrackCue.h"
+#include "SharedBuffer.h"
+#include "VTTCue.h"
#include "WebVTTParser.h"
namespace WebCore {
@@ -46,7 +45,7 @@ namespace WebCore {
TextTrackLoader::TextTrackLoader(TextTrackLoaderClient& client, ScriptExecutionContext* context)
: m_client(client)
, m_scriptExecutionContext(context)
- , m_cueLoadTimer(this, &TextTrackLoader::cueLoadTimerFired)
+ , m_cueLoadTimer(*this, &TextTrackLoader::cueLoadTimerFired)
, m_state(Idle)
, m_parseOffset(0)
, m_newCuesAvailable(false)
@@ -56,13 +55,11 @@ TextTrackLoader::TextTrackLoader(TextTrackLoaderClient& client, ScriptExecutionC
TextTrackLoader::~TextTrackLoader()
{
if (m_resource)
- m_resource->removeClient(this);
+ m_resource->removeClient(*this);
}
-void TextTrackLoader::cueLoadTimerFired(Timer<TextTrackLoader>* timer)
+void TextTrackLoader::cueLoadTimerFired()
{
- ASSERT_UNUSED(timer, timer == &m_cueLoadTimer);
-
if (m_newCuesAvailable) {
m_newCuesAvailable = false;
m_client.newCuesAvailable(this);
@@ -75,24 +72,24 @@ void TextTrackLoader::cueLoadTimerFired(Timer<TextTrackLoader>* timer)
void TextTrackLoader::cancelLoad()
{
if (m_resource) {
- m_resource->removeClient(this);
+ m_resource->removeClient(*this);
m_resource = nullptr;
}
}
-void TextTrackLoader::processNewCueData(CachedResource* resource)
+void TextTrackLoader::processNewCueData(CachedResource& resource)
{
- ASSERT(m_resource == resource);
-
- if (m_state == Failed || !resource->resourceBuffer())
+ ASSERT_UNUSED(resource, m_resource == &resource);
+
+ if (m_state == Failed || !m_resource->resourceBuffer())
return;
-
- ResourceBuffer* buffer = resource->resourceBuffer();
+
+ auto* buffer = m_resource->resourceBuffer();
if (m_parseOffset == buffer->size())
return;
if (!m_cueParser)
- m_cueParser = WebVTTParser::create(this, m_scriptExecutionContext);
+ m_cueParser = std::make_unique<WebVTTParser>(static_cast<WebVTTParserClient*>(this), m_scriptExecutionContext);
const char* data;
unsigned length;
@@ -104,77 +101,67 @@ void TextTrackLoader::processNewCueData(CachedResource* resource)
}
// FIXME: This is a very unusual pattern, no other CachedResourceClient does this. Refactor to use notifyFinished() instead.
-void TextTrackLoader::deprecatedDidReceiveCachedResource(CachedResource* resource)
+void TextTrackLoader::deprecatedDidReceiveCachedResource(CachedResource& resource)
{
- ASSERT(m_resource == resource);
-
- if (!resource->resourceBuffer())
+ ASSERT_UNUSED(resource, m_resource == &resource);
+
+ if (!m_resource->resourceBuffer())
return;
-
- processNewCueData(resource);
+
+ processNewCueData(*m_resource);
}
void TextTrackLoader::corsPolicyPreventedLoad()
{
- DEFINE_STATIC_LOCAL(String, consoleMessage, (ASCIILiteral("Cross-origin text track load denied by Cross-Origin Resource Sharing policy.")));
- Document* document = toDocument(m_scriptExecutionContext);
- document->addConsoleMessage(SecurityMessageSource, ErrorMessageLevel, consoleMessage);
+ static NeverDestroyed<String> consoleMessage(ASCIILiteral("Cross-origin text track load denied by Cross-Origin Resource Sharing policy."));
+ Document* document = downcast<Document>(m_scriptExecutionContext);
+ document->addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage);
m_state = Failed;
}
-void TextTrackLoader::notifyFinished(CachedResource* resource)
+void TextTrackLoader::notifyFinished(CachedResource& resource)
{
- ASSERT(m_resource == resource);
-
- Document* document = toDocument(m_scriptExecutionContext);
- if (!m_crossOriginMode.isNull()
- && !document->securityOrigin()->canRequest(resource->response().url())
- && !resource->passesAccessControlCheck(document->securityOrigin())) {
+ ASSERT_UNUSED(resource, m_resource == &resource);
+ if (m_resource->resourceError().isAccessControl())
corsPolicyPreventedLoad();
- }
if (m_state != Failed) {
- processNewCueData(resource);
+ processNewCueData(*m_resource);
if (m_cueParser)
m_cueParser->fileFinished();
if (m_state != Failed)
- m_state = resource->errorOccurred() ? Failed : Finished;
+ m_state = m_resource->errorOccurred() ? Failed : Finished;
}
+ if (m_state == Finished && m_cueParser)
+ m_cueParser->flush();
+
if (!m_cueLoadTimer.isActive())
m_cueLoadTimer.startOneShot(0);
-
+
cancelLoad();
}
-bool TextTrackLoader::load(const URL& url, const String& crossOriginMode)
+bool TextTrackLoader::load(const URL& url, const String& crossOriginMode, bool isInitiatingElementInUserAgentShadowTree)
{
cancelLoad();
- ASSERT(m_scriptExecutionContext->isDocument());
- Document* document = toDocument(m_scriptExecutionContext);
- CachedResourceRequest cueRequest(ResourceRequest(document->completeURL(url)));
-
- if (!crossOriginMode.isNull()) {
- m_crossOriginMode = crossOriginMode;
- StoredCredentials allowCredentials = equalIgnoringCase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials;
- updateRequestForAccessControl(cueRequest.mutableResourceRequest(), document->securityOrigin(), allowCredentials);
- } else {
- // Cross-origin resources that are not suitably CORS-enabled may not load.
- if (!document->securityOrigin()->canRequest(url)) {
- corsPolicyPreventedLoad();
- return false;
- }
- }
+ ASSERT(is<Document>(m_scriptExecutionContext));
+ Document* document = downcast<Document>(m_scriptExecutionContext);
- CachedResourceLoader* cachedResourceLoader = document->cachedResourceLoader();
- m_resource = cachedResourceLoader->requestTextTrack(cueRequest);
+ ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
+ options.contentSecurityPolicyImposition = isInitiatingElementInUserAgentShadowTree ? ContentSecurityPolicyImposition::SkipPolicyCheck : ContentSecurityPolicyImposition::DoPolicyCheck;
+
+ CachedResourceRequest cueRequest(ResourceRequest(document->completeURL(url)), options);
+ cueRequest.setAsPotentiallyCrossOrigin(crossOriginMode, *document);
+
+ m_resource = document->cachedResourceLoader().requestTextTrack(WTFMove(cueRequest));
if (!m_resource)
return false;
- m_resource->addClient(this);
-
+ m_resource->addClient(*this);
+
return true;
}
@@ -187,12 +174,10 @@ void TextTrackLoader::newCuesParsed()
m_cueLoadTimer.startOneShot(0);
}
-#if ENABLE(WEBVTT_REGIONS)
void TextTrackLoader::newRegionsParsed()
{
m_client.newRegionsAvailable(this);
}
-#endif
void TextTrackLoader::fileFailedToParse()
{
@@ -212,24 +197,19 @@ void TextTrackLoader::getNewCues(Vector<RefPtr<TextTrackCue>>& outputCues)
if (m_cueParser) {
Vector<RefPtr<WebVTTCueData>> newCues;
m_cueParser->getNewCues(newCues);
- for (size_t i = 0; i < newCues.size(); ++i) {
- RefPtr<WebVTTCueData> data = newCues[i];
- RefPtr<TextTrackCue> cue = TextTrackCue::create(*m_scriptExecutionContext, data->startTime(), data->endTime(), data->content());
- cue->setId(data->id());
- cue->setCueSettings(data->settings());
- outputCues.append(cue);
- }
+
+ for (auto& cueData : newCues)
+ outputCues.append(VTTCue::create(*m_scriptExecutionContext, *cueData));
}
}
-#if ENABLE(WEBVTT_REGIONS)
-void TextTrackLoader::getNewRegions(Vector<RefPtr<TextTrackRegion>>& outputRegions)
+void TextTrackLoader::getNewRegions(Vector<RefPtr<VTTRegion>>& outputRegions)
{
ASSERT(m_cueParser);
if (m_cueParser)
m_cueParser->getNewRegions(outputRegions);
}
-#endif
+
}
#endif