c3c277ac88c34dc609acacfeed6ae5978328f142
[WebKit.git] / Source / WebKit / WebProcess / GPU / media / RemoteMediaPlayerManager.h
1 /*
2  * Copyright (C) 2019 Apple Inc. All rights reserved.
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(GPU_PROCESS)
29
30 #include "MediaPlayerPrivateRemoteIdentifier.h"
31 #include "MessageReceiver.h"
32 #include "RemoteMediaPlayerState.h"
33 #include "SharedMemory.h"
34 #include "WebProcessSupplement.h"
35 #include <WebCore/MediaPlayer.h>
36 #include <wtf/HashMap.h>
37
38 namespace WebCore {
39 class MediaPlayerPrivateInterface;
40 class Settings;
41 }
42
43 namespace WebKit {
44
45 class MediaPlayerPrivateRemote;
46 class WebProcess;
47
48 class RemoteMediaPlayerManager : public WebProcessSupplement, public IPC::MessageReceiver {
49     WTF_MAKE_FAST_ALLOCATED;
50 public:
51     explicit RemoteMediaPlayerManager(WebProcess&);
52     ~RemoteMediaPlayerManager();
53
54     static const char* supplementName();
55
56     void updatePreferences(const WebCore::Settings&);
57
58     IPC::Connection& gpuProcessConnection() const;
59
60     void didReceiveMessageFromWebProcess(IPC::Connection& connection, IPC::Decoder& decoder) { didReceiveMessage(connection, decoder); }
61
62     void deleteRemoteMediaPlayer(MediaPlayerPrivateRemoteIdentifier);
63
64 private:
65     std::unique_ptr<WebCore::MediaPlayerPrivateInterface> createRemoteMediaPlayer(WebCore::MediaPlayer*, WebCore::MediaPlayerEnums::MediaEngineIdentifier);
66
67     // WebProcessSupplement
68     void initialize(const WebProcessCreationParameters&) final;
69
70     // IPC::MessageReceiver
71     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
72
73     // Messages::RemoteMediaPlayerManager
74     void networkStateChanged(MediaPlayerPrivateRemoteIdentifier, RemoteMediaPlayerState&&);
75     void readyStateChanged(MediaPlayerPrivateRemoteIdentifier, RemoteMediaPlayerState&&);
76     void volumeChanged(WebKit::MediaPlayerPrivateRemoteIdentifier, double);
77     void muteChanged(WebKit::MediaPlayerPrivateRemoteIdentifier, bool);
78     void timeChanged(WebKit::MediaPlayerPrivateRemoteIdentifier, RemoteMediaPlayerState&&);
79     void durationChanged(WebKit::MediaPlayerPrivateRemoteIdentifier, RemoteMediaPlayerState&&);
80     void rateChanged(WebKit::MediaPlayerPrivateRemoteIdentifier, double);
81     void playbackStateChanged(WebKit::MediaPlayerPrivateRemoteIdentifier, bool);
82     void engineFailedToLoad(WebKit::MediaPlayerPrivateRemoteIdentifier, long);
83     void updateCachedState(WebKit::MediaPlayerPrivateRemoteIdentifier, RemoteMediaPlayerState&&);
84     void characteristicChanged(WebKit::MediaPlayerPrivateRemoteIdentifier, bool hasAudio, bool hasVideo, WebCore::MediaPlayerEnums::MovieLoadType);
85
86     friend class MediaPlayerRemoteFactory;
87     void getSupportedTypes(WebCore::MediaPlayerEnums::MediaEngineIdentifier, HashSet<String, ASCIICaseInsensitiveHash>&);
88     WebCore::MediaPlayer::SupportsType supportsTypeAndCodecs(WebCore::MediaPlayerEnums::MediaEngineIdentifier, const WebCore::MediaEngineSupportParameters&);
89     bool supportsKeySystem(WebCore::MediaPlayerEnums::MediaEngineIdentifier, const String& keySystem, const String& mimeType);
90     HashSet<RefPtr<WebCore::SecurityOrigin>> originsInMediaCache(WebCore::MediaPlayerEnums::MediaEngineIdentifier, const String&);
91     void clearMediaCache(WebCore::MediaPlayerEnums::MediaEngineIdentifier, const String&, WallTime modifiedSince);
92     void clearMediaCacheForOrigins(WebCore::MediaPlayerEnums::MediaEngineIdentifier, const String&, const HashSet<RefPtr<WebCore::SecurityOrigin>>&);
93
94     HashMap<MediaPlayerPrivateRemoteIdentifier, WeakPtr<MediaPlayerPrivateRemote>> m_players;
95     WebProcess& m_process;
96 };
97
98 } // namespace WebKit
99
100 #endif