1 | /* |
2 | * Copyright (C) 2014 Igalia S.L |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(VIDEO) |
29 | |
30 | #include "CachedRawResourceClient.h" |
31 | #include "CachedResourceHandle.h" |
32 | #include "ContextDestructionObserver.h" |
33 | #include "PlatformMediaResourceLoader.h" |
34 | #include "ResourceResponse.h" |
35 | #include <wtf/HashSet.h> |
36 | #include <wtf/Ref.h> |
37 | #include <wtf/WeakPtr.h> |
38 | #include <wtf/text/WTFString.h> |
39 | |
40 | namespace WebCore { |
41 | |
42 | class CachedRawResource; |
43 | class Document; |
44 | class HTMLMediaElement; |
45 | class MediaResource; |
46 | |
47 | class MediaResourceLoader final : public PlatformMediaResourceLoader, public CanMakeWeakPtr<MediaResourceLoader>, public ContextDestructionObserver { |
48 | public: |
49 | WEBCORE_EXPORT MediaResourceLoader(Document&, HTMLMediaElement&, const String& crossOriginMode); |
50 | WEBCORE_EXPORT virtual ~MediaResourceLoader(); |
51 | |
52 | RefPtr<PlatformMediaResource> requestResource(ResourceRequest&&, LoadOptions) final; |
53 | void removeResource(MediaResource&); |
54 | |
55 | Document* document() { return m_document.get(); } |
56 | const String& crossOriginMode() const { return m_crossOriginMode; } |
57 | |
58 | Vector<ResourceResponse> responsesForTesting() const { return m_responsesForTesting; } |
59 | void addResponseForTesting(const ResourceResponse&); |
60 | |
61 | private: |
62 | void contextDestroyed() override; |
63 | |
64 | WeakPtr<Document> m_document; |
65 | WeakPtr<HTMLMediaElement> m_mediaElement; |
66 | String m_crossOriginMode; |
67 | HashSet<MediaResource*> m_resources; |
68 | Vector<ResourceResponse> m_responsesForTesting; |
69 | }; |
70 | |
71 | class MediaResource : public PlatformMediaResource, CachedRawResourceClient { |
72 | public: |
73 | static Ref<MediaResource> create(MediaResourceLoader&, CachedResourceHandle<CachedRawResource>); |
74 | virtual ~MediaResource(); |
75 | |
76 | // PlatformMediaResource |
77 | void stop() override; |
78 | bool didPassAccessControlCheck() const override { return m_didPassAccessControlCheck; } |
79 | |
80 | // CachedRawResourceClient |
81 | void responseReceived(CachedResource&, const ResourceResponse&, CompletionHandler<void()>&&) override; |
82 | void redirectReceived(CachedResource&, ResourceRequest&&, const ResourceResponse&, CompletionHandler<void(ResourceRequest&&)>&&) override; |
83 | bool shouldCacheResponse(CachedResource&, const ResourceResponse&) override; |
84 | void dataSent(CachedResource&, unsigned long long, unsigned long long) override; |
85 | void dataReceived(CachedResource&, const char*, int) override; |
86 | void notifyFinished(CachedResource&) override; |
87 | |
88 | private: |
89 | MediaResource(MediaResourceLoader&, CachedResourceHandle<CachedRawResource>); |
90 | Ref<MediaResourceLoader> m_loader; |
91 | bool m_didPassAccessControlCheck { false }; |
92 | CachedResourceHandle<CachedRawResource> m_resource; |
93 | }; |
94 | |
95 | } // namespace WebCore |
96 | |
97 | #endif // ENABLE(VIDEO) |
98 | |