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. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #if ENABLE(VIDEO) |
29 | |
30 | #include "PolicyChecker.h" |
31 | #include <wtf/CompletionHandler.h> |
32 | #include <wtf/Noncopyable.h> |
33 | #include <wtf/RefCounted.h> |
34 | #include <wtf/ThreadSafeRefCounted.h> |
35 | |
36 | namespace WebCore { |
37 | |
38 | class PlatformMediaResource; |
39 | class ResourceError; |
40 | class ResourceRequest; |
41 | class ResourceResponse; |
42 | |
43 | class PlatformMediaResourceClient { |
44 | public: |
45 | virtual ~PlatformMediaResourceClient() = default; |
46 | |
47 | virtual void responseReceived(PlatformMediaResource&, const ResourceResponse&, CompletionHandler<void(ShouldContinue)>&& completionHandler) { completionHandler(ShouldContinue::Yes); } |
48 | virtual void redirectReceived(PlatformMediaResource&, ResourceRequest&& request, const ResourceResponse&, CompletionHandler<void(ResourceRequest&&)>&& completionHandler) { completionHandler(WTFMove(request)); } |
49 | virtual bool shouldCacheResponse(PlatformMediaResource&, const ResourceResponse&) { return true; } |
50 | virtual void dataSent(PlatformMediaResource&, unsigned long long, unsigned long long) { } |
51 | virtual void dataReceived(PlatformMediaResource&, const char*, int) { } |
52 | virtual void accessControlCheckFailed(PlatformMediaResource&, const ResourceError&) { } |
53 | virtual void loadFailed(PlatformMediaResource&, const ResourceError&) { } |
54 | virtual void loadFinished(PlatformMediaResource&) { } |
55 | }; |
56 | |
57 | class PlatformMediaResourceLoader : public ThreadSafeRefCounted<PlatformMediaResourceLoader> { |
58 | WTF_MAKE_NONCOPYABLE(PlatformMediaResourceLoader); WTF_MAKE_FAST_ALLOCATED; |
59 | public: |
60 | enum LoadOption { |
61 | BufferData = 1 << 0, |
62 | DisallowCaching = 1 << 1, |
63 | }; |
64 | typedef unsigned LoadOptions; |
65 | |
66 | virtual ~PlatformMediaResourceLoader() = default; |
67 | |
68 | virtual RefPtr<PlatformMediaResource> requestResource(ResourceRequest&&, LoadOptions) = 0; |
69 | |
70 | protected: |
71 | PlatformMediaResourceLoader() = default; |
72 | }; |
73 | |
74 | class PlatformMediaResource : public ThreadSafeRefCounted<PlatformMediaResource> { |
75 | WTF_MAKE_NONCOPYABLE(PlatformMediaResource); WTF_MAKE_FAST_ALLOCATED; |
76 | public: |
77 | PlatformMediaResource() = default; |
78 | virtual ~PlatformMediaResource() = default; |
79 | virtual void stop() { } |
80 | virtual bool didPassAccessControlCheck() const { return false; } |
81 | |
82 | void setClient(std::unique_ptr<PlatformMediaResourceClient>&& client) { m_client = WTFMove(client); } |
83 | PlatformMediaResourceClient* client() { return m_client.get(); } |
84 | |
85 | protected: |
86 | std::unique_ptr<PlatformMediaResourceClient> m_client; |
87 | }; |
88 | |
89 | } // namespace WebCore |
90 | |
91 | #endif |
92 | |