Make MediaResourceLoader behave more like a CachedResourceLoader.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Feb 2016 22:34:36 +0000 (22:34 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Feb 2016 22:34:36 +0000 (22:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154117

Reviewed by Alex Christensen.

MediaResourceLoader currently can only handle a single request at a time. Split the class
into two, MediaResourceLoader and MediaResource, effectively wrapping CachedResourceLoader
and CachedRawResource respectively. With this devision, the same loader can be used to issue
multiple simultaneous resource requests.

This necessecitates splitting PlatformMediaResource into two classes as well.  To simplify
the HTMLMediaElement, MediaPlayer, and MediaPlayerClient APIs, do not require a client
object when creating the loader; instead, the client is required to create the resource.
This also matches the CachedRawResource API.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): Remove the client parameter.
* html/HTMLMediaElement.h:
* loader/MediaResourceLoader.cpp:
(WebCore::MediaResourceLoader::MediaResourceLoader):
(WebCore::MediaResourceLoader::~MediaResourceLoader):
(WebCore::MediaResourceLoader::requestResource): Renamed from start().
(WebCore::MediaResourceLoader::removeResource): Remove resource from live resource list.
(WebCore::MediaResource::create): Utility factory.
(WebCore::MediaResource::MediaResource):
(WebCore::MediaResource::~MediaResource):
(WebCore::MediaResource::stop): Moved from MediaResourceLoader.
(WebCore::MediaResource::setDefersLoading): Ditto.
(WebCore::MediaResource::responseReceived): Ditto.
(WebCore::MediaResource::redirectReceived): Ditto.
(WebCore::MediaResource::dataSent): Ditto.
(WebCore::MediaResource::dataReceived): Ditto.
(WebCore::MediaResource::notifyFinished): Ditto.
(WebCore::MediaResource::getOrCreateReadBuffer): Ditto.
* loader/MediaResourceLoader.h:
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::createResourceLoader):
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaPlayerCreateResourceLoader):
* platform/graphics/PlatformMediaResourceLoader.h:
(WebCore::PlatformMediaResourceClient::~PlatformMediaResourceClient): Renamed from PlatformMediaResourceLoaderClient.
(WebCore::PlatformMediaResourceClient::responseReceived): Client methods now take a reference to the resource.
(WebCore::PlatformMediaResourceClient::redirectReceived): Ditto.
(WebCore::PlatformMediaResourceClient::dataSent): Ditto.
(WebCore::PlatformMediaResourceClient::dataReceived): Ditto.
(WebCore::PlatformMediaResourceClient::accessControlCheckFailed): Ditto.
(WebCore::PlatformMediaResourceClient::loadFailed): Ditto.
(WebCore::PlatformMediaResourceClient::loadFinished): Ditto.
(WebCore::PlatformMediaResourceClient::getOrCreateReadBuffer): Ditto.
(WebCore::PlatformMediaResourceLoader::PlatformMediaResourceLoader): Ditto.
(WebCore::PlatformMediaResource::PlatformMediaResource):
(WebCore::PlatformMediaResource::~PlatformMediaResource):
(WebCore::PlatformMediaResource::setClient):
* platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
(webKitWebSrcStart):
(webKitWebSrcNeedData):
(webKitWebSrcEnoughData):
(CachedResourceStreamingClient::getOrCreateReadBuffer):
(CachedResourceStreamingClient::responseReceived):
(CachedResourceStreamingClient::dataReceived):
(CachedResourceStreamingClient::accessControlCheckFailed):
(CachedResourceStreamingClient::loadFailed):
(CachedResourceStreamingClient::loadFinished):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@196442 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/loader/MediaResourceLoader.cpp
Source/WebCore/loader/MediaResourceLoader.h
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/PlatformMediaResourceLoader.h
Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp

index 7d6acf4..618eaf2 100644 (file)
@@ -1,3 +1,69 @@
+2016-02-11  Jer Noble  <jer.noble@apple.com>
+
+        Make MediaResourceLoader behave more like a CachedResourceLoader.
+        https://bugs.webkit.org/show_bug.cgi?id=154117
+
+        Reviewed by Alex Christensen.
+
+        MediaResourceLoader currently can only handle a single request at a time. Split the class
+        into two, MediaResourceLoader and MediaResource, effectively wrapping CachedResourceLoader
+        and CachedRawResource respectively. With this devision, the same loader can be used to issue
+        multiple simultaneous resource requests.
+
+        This necessecitates splitting PlatformMediaResource into two classes as well.  To simplify
+        the HTMLMediaElement, MediaPlayer, and MediaPlayerClient APIs, do not require a client
+        object when creating the loader; instead, the client is required to create the resource.
+        This also matches the CachedRawResource API.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaPlayerCreateResourceLoader): Remove the client parameter.
+        * html/HTMLMediaElement.h:
+        * loader/MediaResourceLoader.cpp:
+        (WebCore::MediaResourceLoader::MediaResourceLoader):
+        (WebCore::MediaResourceLoader::~MediaResourceLoader):
+        (WebCore::MediaResourceLoader::requestResource): Renamed from start().
+        (WebCore::MediaResourceLoader::removeResource): Remove resource from live resource list.
+        (WebCore::MediaResource::create): Utility factory.
+        (WebCore::MediaResource::MediaResource):
+        (WebCore::MediaResource::~MediaResource):
+        (WebCore::MediaResource::stop): Moved from MediaResourceLoader.
+        (WebCore::MediaResource::setDefersLoading): Ditto.
+        (WebCore::MediaResource::responseReceived): Ditto.
+        (WebCore::MediaResource::redirectReceived): Ditto.
+        (WebCore::MediaResource::dataSent): Ditto.
+        (WebCore::MediaResource::dataReceived): Ditto.
+        (WebCore::MediaResource::notifyFinished): Ditto.
+        (WebCore::MediaResource::getOrCreateReadBuffer): Ditto.
+        * loader/MediaResourceLoader.h:
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::createResourceLoader):
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayerClient::mediaPlayerCreateResourceLoader):
+        * platform/graphics/PlatformMediaResourceLoader.h:
+        (WebCore::PlatformMediaResourceClient::~PlatformMediaResourceClient): Renamed from PlatformMediaResourceLoaderClient.
+        (WebCore::PlatformMediaResourceClient::responseReceived): Client methods now take a reference to the resource.
+        (WebCore::PlatformMediaResourceClient::redirectReceived): Ditto.
+        (WebCore::PlatformMediaResourceClient::dataSent): Ditto. 
+        (WebCore::PlatformMediaResourceClient::dataReceived): Ditto.
+        (WebCore::PlatformMediaResourceClient::accessControlCheckFailed): Ditto.
+        (WebCore::PlatformMediaResourceClient::loadFailed): Ditto.
+        (WebCore::PlatformMediaResourceClient::loadFinished): Ditto.
+        (WebCore::PlatformMediaResourceClient::getOrCreateReadBuffer): Ditto.
+        (WebCore::PlatformMediaResourceLoader::PlatformMediaResourceLoader): Ditto.
+        (WebCore::PlatformMediaResource::PlatformMediaResource): 
+        (WebCore::PlatformMediaResource::~PlatformMediaResource): 
+        (WebCore::PlatformMediaResource::setClient):
+        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
+        (webKitWebSrcStart):
+        (webKitWebSrcNeedData):
+        (webKitWebSrcEnoughData):
+        (CachedResourceStreamingClient::getOrCreateReadBuffer):
+        (CachedResourceStreamingClient::responseReceived):
+        (CachedResourceStreamingClient::dataReceived):
+        (CachedResourceStreamingClient::accessControlCheckFailed):
+        (CachedResourceStreamingClient::loadFailed):
+        (CachedResourceStreamingClient::loadFinished):
+
 2016-02-11  Zalan Bujtas  <zalan@apple.com>
 
         Subpixel rendering: Make focusring painting subpixel aware.
index 54309e8..4c755b8 100644 (file)
@@ -6092,9 +6092,9 @@ CachedResourceLoader* HTMLMediaElement::mediaPlayerCachedResourceLoader()
     return &document().cachedResourceLoader();
 }
 
-RefPtr<PlatformMediaResourceLoader> HTMLMediaElement::mediaPlayerCreateResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
+RefPtr<PlatformMediaResourceLoader> HTMLMediaElement::mediaPlayerCreateResourceLoader()
 {
-    return adoptRef(*new MediaResourceLoader(document(), fastGetAttribute(HTMLNames::crossoriginAttr), WTFMove(client)));
+    return adoptRef(*new MediaResourceLoader(document(), fastGetAttribute(HTMLNames::crossoriginAttr)));
 }
 
 bool HTMLMediaElement::mediaPlayerShouldWaitForResponseToAuthenticationChallenge(const AuthenticationChallenge& challenge)
index c11d35a..d61df75 100644 (file)
@@ -595,7 +595,7 @@ private:
     virtual bool mediaPlayerIsPaused() const override;
     virtual bool mediaPlayerIsLooping() const override;
     virtual CachedResourceLoader* mediaPlayerCachedResourceLoader() override;
-    virtual RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient>) override;
+    virtual RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader() override;
 
 #if PLATFORM(WIN) && USE(AVFOUNDATION)
     virtual GraphicsDeviceAdapter* mediaPlayerGraphicsDeviceAdapter(const MediaPlayer*) const override;
index 5db1eb5..66e91a8 100644 (file)
 
 namespace WebCore {
 
-MediaResourceLoader::MediaResourceLoader(Document& document, const String& crossOriginMode, std::unique_ptr<PlatformMediaResourceLoaderClient> client)
-    : PlatformMediaResourceLoader(WTFMove(client))
-    , m_document(document)
+MediaResourceLoader::MediaResourceLoader(Document& document, const String& crossOriginMode)
+    : m_document(document)
     , m_crossOriginMode(crossOriginMode)
-    , m_didPassAccessControlCheck(false)
 {
 }
 
 MediaResourceLoader::~MediaResourceLoader()
 {
-    stop();
+    ASSERT(m_resources.isEmpty());
 }
 
-bool MediaResourceLoader::start(const ResourceRequest& request, LoadOptions options)
+RefPtr<PlatformMediaResource> MediaResourceLoader::requestResource(const ResourceRequest& request, LoadOptions options)
 {
-    if (m_resource)
-        return false;
-
     DataBufferingPolicy bufferingPolicy = options & LoadOption::BufferData ? WebCore::BufferData : WebCore::DoNotBufferData;
     RequestOriginPolicy corsPolicy = !m_crossOriginMode.isNull() ? PotentiallyCrossOriginEnabled : UseDefaultOriginRestrictionsForType;
     StoredCredentials allowCredentials = m_crossOriginMode.isNull() || equalLettersIgnoringASCIICase(m_crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials;
@@ -66,17 +61,42 @@ bool MediaResourceLoader::start(const ResourceRequest& request, LoadOptions opti
     if (!m_crossOriginMode.isNull())
         updateRequestForAccessControl(cacheRequest.mutableResourceRequest(), m_document.securityOrigin(), allowCredentials);
 
-    m_didPassAccessControlCheck = false;
+    CachedResourceHandle<CachedRawResource> resource = m_document.cachedResourceLoader().requestRawResource(cacheRequest);
+    if (!resource)
+        return nullptr;
 
-    m_resource = m_document.cachedResourceLoader().requestRawResource(cacheRequest);
-    if (!m_resource)
-        return false;
+    Ref<MediaResource> mediaResource = MediaResource::create(*this, resource);
+    m_resources.add(mediaResource.ptr());
+
+    return WTFMove(mediaResource);
+}
+
+void MediaResourceLoader::removeResource(MediaResource& mediaResource)
+{
+    ASSERT(m_resources.contains(&mediaResource));
+    m_resources.remove(&mediaResource);
+}
+
+Ref<MediaResource> MediaResource::create(MediaResourceLoader& loader, CachedResourceHandle<CachedRawResource> resource)
+{
+    return adoptRef(*new MediaResource(loader, resource));
+}
+
+MediaResource::MediaResource(MediaResourceLoader& loader, CachedResourceHandle<CachedRawResource> resource)
+    : m_loader(loader)
+    , m_resource(resource)
+{
+    ASSERT(resource);
+    resource->addClient(this);
+}
 
-    m_resource->addClient(this);
-    return true;
+MediaResource::~MediaResource()
+{
+    stop();
+    m_loader->removeResource(*this);
 }
 
-void MediaResourceLoader::stop()
+void MediaResource::stop()
 {
     if (!m_resource)
         return;
@@ -85,55 +105,78 @@ void MediaResourceLoader::stop()
     m_resource = nullptr;
 }
 
-void MediaResourceLoader::setDefersLoading(bool defersLoading)
+void MediaResource::setDefersLoading(bool defersLoading)
 {
     if (m_resource)
         m_resource->setDefersLoading(defersLoading);
 }
 
-void MediaResourceLoader::responseReceived(CachedResource* resource, const ResourceResponse& response)
+void MediaResource::responseReceived(CachedResource* resource, const ResourceResponse& response)
 {
     ASSERT_UNUSED(resource, resource == m_resource);
 
-    RefPtr<MediaResourceLoader> protect(this);
-    if (!m_crossOriginMode.isNull() && !resource->passesSameOriginPolicyCheck(*m_document.securityOrigin())) {
+    RefPtr<MediaResource> protect(this);
+    if (!m_loader->crossOriginMode().isNull() && !resource->passesSameOriginPolicyCheck(*m_loader->document().securityOrigin())) {
         static NeverDestroyed<const String> consoleMessage("Cross-origin media resource load denied by Cross-Origin Resource Sharing policy.");
-        m_document.addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage.get());
+        m_loader->document().addConsoleMessage(MessageSource::Security, MessageLevel::Error, consoleMessage.get());
         m_didPassAccessControlCheck = false;
-        m_client->accessControlCheckFailed(ResourceError(errorDomainWebKitInternal, 0, response.url(), consoleMessage.get()));
+        if (m_client)
+            m_client->accessControlCheckFailed(*this, ResourceError(errorDomainWebKitInternal, 0, response.url(), consoleMessage.get()));
         stop();
         return;
     }
 
-    m_didPassAccessControlCheck = !m_crossOriginMode.isNull();
-    m_client->responseReceived(response);
+    m_didPassAccessControlCheck = !m_loader->crossOriginMode().isNull();
+    if (m_client)
+        m_client->responseReceived(*this, response);
+}
+
+void MediaResource::redirectReceived(CachedResource* resource, ResourceRequest& request, const ResourceResponse& response)
+{
+    ASSERT_UNUSED(resource, resource == m_resource);
+
+    RefPtr<MediaResource> protect(this);
+    if (m_client)
+        m_client->redirectReceived(*this, request, response);
 }
 
-void MediaResourceLoader::dataReceived(CachedResource* resource, const char* data, int dataLength)
+void MediaResource::dataSent(CachedResource* resource, unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
 {
     ASSERT_UNUSED(resource, resource == m_resource);
 
-    RefPtr<MediaResourceLoader> protect(this);
-    m_client->dataReceived(data, dataLength);
+    RefPtr<MediaResource> protect(this);
+    if (m_client)
+        m_client->dataSent(*this, bytesSent, totalBytesToBeSent);
 }
 
-void MediaResourceLoader::notifyFinished(CachedResource* resource)
+void MediaResource::dataReceived(CachedResource* resource, const char* data, int dataLength)
+{
+    ASSERT_UNUSED(resource, resource == m_resource);
+
+    RefPtr<MediaResource> protect(this);
+    if (m_client)
+        m_client->dataReceived(*this, data, dataLength);
+}
+
+void MediaResource::notifyFinished(CachedResource* resource)
 {
     ASSERT(resource == m_resource);
 
-    RefPtr<MediaResourceLoader> protect(this);
-    if (resource->loadFailedOrCanceled())
-        m_client->loadFailed(resource->resourceError());
-    else
-        m_client->loadFinished();
+    RefPtr<MediaResource> protect(this);
+    if (m_client) {
+        if (resource->loadFailedOrCanceled())
+            m_client->loadFailed(*this, resource->resourceError());
+        else
+            m_client->loadFinished(*this);
+    }
     stop();
 }
 
 #if USE(SOUP)
-char* MediaResourceLoader::getOrCreateReadBuffer(CachedResource* resource, size_t requestedSize, size_t& actualSize)
+char* MediaResource::getOrCreateReadBuffer(CachedResource* resource, size_t requestedSize, size_t& actualSize)
 {
     ASSERT_UNUSED(resource, resource == m_resource);
-    return m_client->getOrCreateReadBuffer(requestedSize, actualSize);
+    return m_client ? m_client->getOrCreateReadBuffer(*this, requestedSize, actualSize) : nullptr;
 }
 #endif
 
index 31b4db8..872e3f2 100644 (file)
 #include "CachedRawResourceClient.h"
 #include "CachedResourceHandle.h"
 #include "PlatformMediaResourceLoader.h"
+#include <wtf/HashSet.h>
+#include <wtf/Ref.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
 class CachedRawResource;
 class Document;
+class MediaResource;
 
-class MediaResourceLoader final : public PlatformMediaResourceLoader, CachedRawResourceClient {
+class MediaResourceLoader final : public PlatformMediaResourceLoader {
 public:
-    MediaResourceLoader(Document&, const String& crossOriginMode, std::unique_ptr<PlatformMediaResourceLoaderClient>);
-    virtual ~MediaResourceLoader();
+    WEBCORE_EXPORT MediaResourceLoader(Document&, const String& crossOriginMode);
+    WEBCORE_EXPORT virtual ~MediaResourceLoader();
 
-    virtual bool start(const ResourceRequest&, LoadOptions) override;
-    virtual void stop() override;
-    virtual void setDefersLoading(bool) override;
-    virtual bool didPassAccessControlCheck() const override { return m_didPassAccessControlCheck; }
+    RefPtr<PlatformMediaResource> requestResource(const ResourceRequest&, LoadOptions) override;
+    void removeResource(MediaResource&);
+
+    Document& document() { return m_document; }
+    const String& crossOriginMode() const { return m_crossOriginMode; }
+
+private:
+    Document& m_document;
+    String m_crossOriginMode;
+    HashSet<MediaResource*> m_resources;
+};
+
+class MediaResource : public PlatformMediaResource, CachedRawResourceClient {
+public:
+    static Ref<MediaResource> create(MediaResourceLoader&, CachedResourceHandle<CachedRawResource>);
+    virtual ~MediaResource();
+
+    // PlatformMediaResource
+    void stop() override;
+    void setDefersLoading(bool) override;
+    bool didPassAccessControlCheck() const override { return m_didPassAccessControlCheck; }
 
     // CachedResourceClient
-    virtual void responseReceived(CachedResource*, const ResourceResponse&) override;
-    virtual void dataReceived(CachedResource*, const char*, int) override;
-    virtual void notifyFinished(CachedResource*) override;
+    void responseReceived(CachedResource*, const ResourceResponse&) override;
+    void redirectReceived(CachedResource*, ResourceRequest&, const ResourceResponse&) override;
+    void dataSent(CachedResource*, unsigned long long, unsigned long long) override;
+    void dataReceived(CachedResource*, const char*, int) override;
+    void notifyFinished(CachedResource*) override;
 #if USE(SOUP)
-    virtual char* getOrCreateReadBuffer(CachedResource*, size_t /*requestedSize*/, size_t& /*actualSize*/) override;
+    char* getOrCreateReadBuffer(CachedResource*, size_t /*requestedSize*/, size_t& /*actualSize*/) override;
 #endif
 
 private:
-    Document& m_document;
-    String m_crossOriginMode;
-    bool m_didPassAccessControlCheck;
+    MediaResource(MediaResourceLoader&, CachedResourceHandle<CachedRawResource>);
+    Ref<MediaResourceLoader> m_loader;
+    bool m_didPassAccessControlCheck { false };
     CachedResourceHandle<CachedRawResource> m_resource;
 };
 
index 5f16f44..99b9d5c 100644 (file)
@@ -1237,9 +1237,9 @@ CachedResourceLoader* MediaPlayer::cachedResourceLoader()
     return m_client.mediaPlayerCachedResourceLoader();
 }
 
-PassRefPtr<PlatformMediaResourceLoader> MediaPlayer::createResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
+PassRefPtr<PlatformMediaResourceLoader> MediaPlayer::createResourceLoader()
 {
-    return m_client.mediaPlayerCreateResourceLoader(WTFMove(client));
+    return m_client.mediaPlayerCreateResourceLoader();
 }
 
 #if ENABLE(VIDEO_TRACK)
index 73216c9..2faaa19 100644 (file)
@@ -238,7 +238,7 @@ public:
     virtual bool mediaPlayerIsPaused() const { return true; }
     virtual bool mediaPlayerIsLooping() const { return false; }
     virtual CachedResourceLoader* mediaPlayerCachedResourceLoader() { return 0; }
-    virtual RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient>) { return nullptr; }
+    virtual RefPtr<PlatformMediaResourceLoader> mediaPlayerCreateResourceLoader() { return nullptr; }
     virtual bool doesHaveAttribute(const AtomicString&, AtomicString* = 0) const { return false; }
 
 #if ENABLE(VIDEO_TRACK)
@@ -546,7 +546,7 @@ public:
     long platformErrorCode() const;
 
     CachedResourceLoader* cachedResourceLoader();
-    PassRefPtr<PlatformMediaResourceLoader> createResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient>);
+    PassRefPtr<PlatformMediaResourceLoader> createResourceLoader();
 
 #if ENABLE(VIDEO_TRACK)
     void addAudioTrack(PassRefPtr<AudioTrackPrivate>);
index 58fec4e..c082043 100644 (file)
 
 namespace WebCore {
 
+class PlatformMediaResource;
 class ResourceError;
 class ResourceRequest;
 class ResourceResponse;
 
-class PlatformMediaResourceLoaderClient {
+class PlatformMediaResourceClient {
 public:
-    virtual ~PlatformMediaResourceLoaderClient() { }
+    virtual ~PlatformMediaResourceClient() { }
 
-    virtual void responseReceived(const ResourceResponse&) { }
-    virtual void dataReceived(const char*, int) { }
-    virtual void accessControlCheckFailed(const ResourceError&) { }
-    virtual void loadFailed(const ResourceError&) { }
-    virtual void loadFinished() { }
+    virtual void responseReceived(PlatformMediaResource&, const ResourceResponse&) { }
+    virtual void redirectReceived(PlatformMediaResource&, ResourceRequest&, const ResourceResponse&) { }
+    virtual void dataSent(PlatformMediaResource&, unsigned long long, unsigned long long) { }
+    virtual void dataReceived(PlatformMediaResource&, const char*, int) { }
+    virtual void accessControlCheckFailed(PlatformMediaResource&, const ResourceError&) { }
+    virtual void loadFailed(PlatformMediaResource&, const ResourceError&) { }
+    virtual void loadFinished(PlatformMediaResource&) { }
 #if USE(SOUP)
-    virtual char* getOrCreateReadBuffer(size_t /*requestedSize*/, size_t& /*actualSize*/) { return nullptr; };
+    virtual char* getOrCreateReadBuffer(PlatformMediaResource&, size_t /*requestedSize*/, size_t& /*actualSize*/) { return nullptr; };
 #endif
 };
 
@@ -61,18 +64,25 @@ public:
 
     virtual ~PlatformMediaResourceLoader() { }
 
-    virtual bool start(const ResourceRequest&, LoadOptions) = 0;
+    virtual RefPtr<PlatformMediaResource> requestResource(const ResourceRequest&, LoadOptions) = 0;
+
+protected:
+    PlatformMediaResourceLoader() { }
+};
+
+class PlatformMediaResource : public RefCounted<PlatformMediaResource> {
+    WTF_MAKE_NONCOPYABLE(PlatformMediaResource); WTF_MAKE_FAST_ALLOCATED;
+public:
+    PlatformMediaResource() { }
+    virtual ~PlatformMediaResource() { }
     virtual void stop() { }
     virtual void setDefersLoading(bool) { }
     virtual bool didPassAccessControlCheck() const { return false; }
 
-protected:
-    explicit PlatformMediaResourceLoader(std::unique_ptr<PlatformMediaResourceLoaderClient> client)
-        : m_client(WTFMove(client))
-    {
-    }
+    void setClient(std::unique_ptr<PlatformMediaResourceClient>&& client) { m_client = WTFMove(client); }
 
-    std::unique_ptr<PlatformMediaResourceLoaderClient> m_client;
+protected:
+    std::unique_ptr<PlatformMediaResourceClient> m_client;
 };
 
 } // namespace WebCore
index da316b7..cfb38b7 100644 (file)
@@ -62,22 +62,22 @@ class StreamingClient {
         GstElement* m_src;
 };
 
-class CachedResourceStreamingClient final : public PlatformMediaResourceLoaderClient, public StreamingClient {
+class CachedResourceStreamingClient final : public PlatformMediaResourceClient, public StreamingClient {
     WTF_MAKE_NONCOPYABLE(CachedResourceStreamingClient);
     public:
         CachedResourceStreamingClient(WebKitWebSrc*);
         virtual ~CachedResourceStreamingClient();
 
     private:
-        // PlatformMediaResourceLoaderClient virtual methods.
+        // PlatformMediaResourceClient virtual methods.
 #if USE(SOUP)
-        virtual char* getOrCreateReadBuffer(size_t requestedSize, size_t& actualSize) override;
+        virtual char* getOrCreateReadBuffer(PlatformMediaResource&, size_t requestedSize, size_t& actualSize) override;
 #endif
-        virtual void responseReceived(const ResourceResponse&) override;
-        virtual void dataReceived(const char*, int) override;
-        virtual void accessControlCheckFailed(const ResourceError&) override;
-        virtual void loadFailed(const ResourceError&) override;
-        virtual void loadFinished() override;
+        virtual void responseReceived(PlatformMediaResource&, const ResourceResponse&) override;
+        virtual void dataReceived(PlatformMediaResource&, const char*, int) override;
+        virtual void accessControlCheckFailed(PlatformMediaResource&, const ResourceError&) override;
+        virtual void loadFailed(PlatformMediaResource&, const ResourceError&) override;
+        virtual void loadFinished(PlatformMediaResource&) override;
 };
 
 class ResourceHandleStreamingClient : public ResourceHandleClient, public StreamingClient {
@@ -126,6 +126,7 @@ struct _WebKitWebSrcPrivate {
     WebCore::MediaPlayer* player;
 
     RefPtr<PlatformMediaResourceLoader> loader;
+    RefPtr<PlatformMediaResource> resource;
     ResourceHandleStreamingClient* client;
 
     bool didPassAccessControlCheck;
@@ -577,13 +578,17 @@ static void webKitWebSrcStart(WebKitWebSrc* src)
 
     bool loadFailed = true;
     if (priv->player && !priv->loader)
-        priv->loader = priv->player->createResourceLoader(std::make_unique<CachedResourceStreamingClient>(src));
+        priv->loader = priv->player->createResourceLoader();
 
     if (priv->loader) {
         PlatformMediaResourceLoader::LoadOptions loadOptions = 0;
         if (request.url().protocolIs("blob"))
             loadOptions |= PlatformMediaResourceLoader::LoadOption::BufferData;
-        loadFailed = !priv->loader->start(request, loadOptions);
+        priv->resource = priv->loader->requestResource(request, loadOptions);
+        loadFailed = !priv->resource;
+
+        if (priv->resource)
+            priv->resource->setClient(std::make_unique<CachedResourceStreamingClient>(src));
     } else {
         priv->client = new ResourceHandleStreamingClient(src, request);
         loadFailed = priv->client->loadFailed();
@@ -596,6 +601,7 @@ static void webKitWebSrcStart(WebKitWebSrc* src)
             priv->client = nullptr;
         }
         priv->loader = nullptr;
+        priv->resource = nullptr;
         locker.unlock();
         webKitWebSrcStop(src);
         return;
@@ -783,8 +789,8 @@ static void webKitWebSrcNeedData(WebKitWebSrc* src)
 
     if (priv->client)
         priv->client->setDefersLoading(false);
-    if (priv->loader)
-        priv->loader->setDefersLoading(false);
+    if (priv->resource)
+        priv->resource->setDefersLoading(false);
 }
 
 static void webKitWebSrcEnoughData(WebKitWebSrc* src)
@@ -802,8 +808,8 @@ static void webKitWebSrcEnoughData(WebKitWebSrc* src)
 
     if (priv->client)
         priv->client->setDefersLoading(true);
-    if (priv->loader)
-        priv->loader->setDefersLoading(true);
+    if (priv->resource)
+        priv->resource->setDefersLoading(true);
 }
 
 static void webKitWebSrcSeek(WebKitWebSrc* src)
@@ -1002,25 +1008,25 @@ CachedResourceStreamingClient::~CachedResourceStreamingClient()
 }
 
 #if USE(SOUP)
-char* CachedResourceStreamingClient::getOrCreateReadBuffer(size_t requestedSize, size_t& actualSize)
+char* CachedResourceStreamingClient::getOrCreateReadBuffer(PlatformMediaResource&, size_t requestedSize, size_t& actualSize)
 {
     return createReadBuffer(requestedSize, actualSize);
 }
 #endif
 
-void CachedResourceStreamingClient::responseReceived(const ResourceResponse& response)
+void CachedResourceStreamingClient::responseReceived(PlatformMediaResource&, const ResourceResponse& response)
 {
     WebKitWebSrcPrivate* priv = WEBKIT_WEB_SRC(m_src)->priv;
-    priv->didPassAccessControlCheck = priv->loader->didPassAccessControlCheck();
+    priv->didPassAccessControlCheck = priv->resource->didPassAccessControlCheck();
     handleResponseReceived(response);
 }
 
-void CachedResourceStreamingClient::dataReceived(const char* data, int length)
+void CachedResourceStreamingClient::dataReceived(PlatformMediaResource&, const char* data, int length)
 {
     handleDataReceived(data, length);
 }
 
-void CachedResourceStreamingClient::accessControlCheckFailed(const ResourceError& error)
+void CachedResourceStreamingClient::accessControlCheckFailed(PlatformMediaResource&, const ResourceError& error)
 {
     WebKitWebSrc* src = WEBKIT_WEB_SRC(m_src);
     GST_ELEMENT_ERROR(src, RESOURCE, READ, ("%s", error.localizedDescription().utf8().data()), (nullptr));
@@ -1028,7 +1034,7 @@ void CachedResourceStreamingClient::accessControlCheckFailed(const ResourceError
     webKitWebSrcStop(src);
 }
 
-void CachedResourceStreamingClient::loadFailed(const ResourceError& error)
+void CachedResourceStreamingClient::loadFailed(PlatformMediaResource&, const ResourceError& error)
 {
     WebKitWebSrc* src = WEBKIT_WEB_SRC(m_src);
 
@@ -1040,7 +1046,7 @@ void CachedResourceStreamingClient::loadFailed(const ResourceError& error)
     gst_app_src_end_of_stream(src->priv->appsrc);
 }
 
-void CachedResourceStreamingClient::loadFinished()
+void CachedResourceStreamingClient::loadFinished(PlatformMediaResource&)
 {
     handleNotifyFinished();
 }