WebCoreAVCFResourceLoader.cpp [plain text]
#include "config.h"
#include "WebCoreAVCFResourceLoader.h"
#if ENABLE(VIDEO) && USE(AVFOUNDATION) && HAVE(AVFOUNDATION_LOADER_DELEGATE)
#include "CachedRawResource.h"
#include "CachedResourceLoader.h"
#include "CachedResourceRequest.h"
#include "MediaPlayerPrivateAVFoundationCF.h"
#include "NotImplemented.h"
#include "ResourceLoaderOptions.h"
#include "SharedBuffer.h"
#include <AVFoundationCF/AVCFAssetResourceLoader.h>
#include <AVFoundationCF/AVFoundationCF.h>
#include <wtf/SoftLinking.h>
#include <wtf/text/CString.h>
#include "AVFoundationCFSoftLinking.h"
namespace WebCore {
Ref<WebCoreAVCFResourceLoader> WebCoreAVCFResourceLoader::create(MediaPlayerPrivateAVFoundationCF* parent, AVCFAssetResourceLoadingRequestRef avRequest)
{
ASSERT(avRequest);
ASSERT(parent);
return adoptRef(*new WebCoreAVCFResourceLoader(parent, avRequest));
}
WebCoreAVCFResourceLoader::WebCoreAVCFResourceLoader(MediaPlayerPrivateAVFoundationCF* parent, AVCFAssetResourceLoadingRequestRef avRequest)
: m_parent(parent)
, m_avRequest(avRequest)
{
}
WebCoreAVCFResourceLoader::~WebCoreAVCFResourceLoader()
{
stopLoading();
}
void WebCoreAVCFResourceLoader::startLoading()
{
if (m_resource || !m_parent)
return;
RetainPtr<CFURLRequestRef> urlRequest = AVCFAssetResourceLoadingRequestGetURLRequest(m_avRequest.get());
ResourceRequest resourceRequest(urlRequest.get());
resourceRequest.setPriority(ResourceLoadPriority::Low);
CachedResourceRequest request(WTFMove(resourceRequest), ResourceLoaderOptions(SendCallbacks, DoNotSniffContent, BufferData, DoNotAllowStoredCredentials, ClientCredentialPolicy::CannotAskClientForCredentials, FetchOptions::Credentials::Omit, DoSecurityCheck, FetchOptions::Mode::NoCors, DoNotIncludeCertificateInfo, ContentSecurityPolicyImposition::DoPolicyCheck, DefersLoadingPolicy::AllowDefersLoading, CachingPolicy::DisallowCaching));
CachedResourceLoader* loader = m_parent->player()->cachedResourceLoader();
m_resource = loader ? loader->requestRawResource(WTFMove(request)) : 0;
if (m_resource)
m_resource->addClient(*this);
else {
LOG_ERROR("Failed to start load for media at url %s", URL(CFURLRequestGetURL(urlRequest.get())).string().ascii().data());
RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, kCFURLErrorUnknown, nullptr));
AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), error.get());
}
}
void WebCoreAVCFResourceLoader::stopLoading()
{
if (!m_resource)
return;
m_resource->removeClient(*this);
m_resource = 0;
if (m_parent)
m_parent->didStopLoadingRequest(m_avRequest.get());
}
void WebCoreAVCFResourceLoader::invalidate()
{
if (!m_parent)
return;
m_parent = nullptr;
callOnMainThread([protectedThis = makeRef(*this)] () mutable {
protectedThis->stopLoading();
});
}
void WebCoreAVCFResourceLoader::responseReceived(CachedResource& resource, const ResourceResponse& response)
{
ASSERT_UNUSED(resource, &resource == m_resource);
int status = response.httpStatusCode();
if (status && (status < 200 || status > 299)) {
RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, status, nullptr));
AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), error.get());
return;
}
notImplemented();
}
void WebCoreAVCFResourceLoader::dataReceived(CachedResource& resource, const char*, int)
{
fulfillRequestWithResource(resource);
}
void WebCoreAVCFResourceLoader::notifyFinished(CachedResource& resource)
{
if (resource.loadFailedOrCanceled()) {
notImplemented();
RetainPtr<CFErrorRef> error = adoptCF(CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, kCFURLErrorUnknown, nullptr));
AVCFAssetResourceLoadingRequestFinishLoadingWithError(m_avRequest.get(), error.get());
} else {
fulfillRequestWithResource(resource);
notImplemented();
}
stopLoading();
}
void WebCoreAVCFResourceLoader::fulfillRequestWithResource(CachedResource& resource)
{
ASSERT_UNUSED(resource, &resource == m_resource);
notImplemented();
}
}
#endif // ENABLE(VIDEO) && USE(AVFOUNDATION)