Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef GMPService_h_
7 : #define GMPService_h_
8 :
9 : #include "nsString.h"
10 : #include "mozIGeckoMediaPluginService.h"
11 : #include "nsIObserver.h"
12 : #include "nsTArray.h"
13 : #include "mozilla/Attributes.h"
14 : #include "mozilla/Monitor.h"
15 : #include "nsString.h"
16 : #include "nsCOMPtr.h"
17 : #include "nsIThread.h"
18 : #include "nsThreadUtils.h"
19 : #include "nsIDocument.h"
20 : #include "nsIWeakReference.h"
21 : #include "mozilla/AbstractThread.h"
22 : #include "nsClassHashtable.h"
23 : #include "nsISupportsImpl.h"
24 : #include "mozilla/MozPromise.h"
25 : #include "GMPContentParent.h"
26 : #include "GMPCrashHelper.h"
27 : #include "ChromiumCDMParent.h"
28 :
29 : template <class> struct already_AddRefed;
30 :
31 : namespace mozilla {
32 :
33 : class GMPCrashHelper;
34 :
35 : extern LogModule* GetGMPLog();
36 :
37 : namespace gmp {
38 :
39 0 : struct NodeId
40 : {
41 0 : NodeId(const nsAString& aOrigin,
42 : const nsAString& aTopLevelOrigin,
43 : const nsAString& aGMPName)
44 0 : : mOrigin(aOrigin)
45 : , mTopLevelOrigin(aTopLevelOrigin)
46 0 : , mGMPName(aGMPName)
47 : {
48 0 : }
49 : nsString mOrigin;
50 : nsString mTopLevelOrigin;
51 : nsString mGMPName;
52 : };
53 :
54 : typedef MozPromise<RefPtr<GMPContentParent::CloseBlocker>,
55 : nsresult,
56 : /* IsExclusive = */ true>
57 : GetGMPContentParentPromise;
58 : typedef MozPromise<RefPtr<ChromiumCDMParent>,
59 : nsresult,
60 : /* IsExclusive = */ true>
61 : GetCDMParentPromise;
62 :
63 : class GeckoMediaPluginService : public mozIGeckoMediaPluginService
64 : , public nsIObserver
65 : {
66 : public:
67 : static already_AddRefed<GeckoMediaPluginService> GetGeckoMediaPluginService();
68 :
69 : virtual nsresult Init();
70 :
71 : NS_DECL_THREADSAFE_ISUPPORTS
72 :
73 : RefPtr<GetCDMParentPromise> GetCDM(const NodeId& aNodeId,
74 : nsTArray<nsCString> aTags,
75 : GMPCrashHelper* aHelper);
76 :
77 : // mozIGeckoMediaPluginService
78 : NS_IMETHOD GetThread(nsIThread** aThread) override;
79 : NS_IMETHOD GetDecryptingGMPVideoDecoder(GMPCrashHelper* aHelper,
80 : nsTArray<nsCString>* aTags,
81 : const nsACString& aNodeId,
82 : UniquePtr<GetGMPVideoDecoderCallback>&& aCallback,
83 : uint32_t aDecryptorId)
84 : override;
85 : NS_IMETHOD GetGMPVideoEncoder(GMPCrashHelper* aHelper,
86 : nsTArray<nsCString>* aTags,
87 : const nsACString& aNodeId,
88 : UniquePtr<GetGMPVideoEncoderCallback>&& aCallback)
89 : override;
90 : NS_IMETHOD GetGMPDecryptor(GMPCrashHelper* aHelper,
91 : nsTArray<nsCString>* aTags,
92 : const nsACString& aNodeId,
93 : UniquePtr<GetGMPDecryptorCallback>&& aCallback)
94 : override;
95 :
96 : // Helper for backwards compatibility with WebRTC/tests.
97 : NS_IMETHOD
98 0 : GetGMPVideoDecoder(GMPCrashHelper* aHelper,
99 : nsTArray<nsCString>* aTags,
100 : const nsACString& aNodeId,
101 : UniquePtr<GetGMPVideoDecoderCallback>&& aCallback) override
102 : {
103 0 : return GetDecryptingGMPVideoDecoder(aHelper, aTags, aNodeId, Move(aCallback), 0);
104 : }
105 :
106 : NS_IMETHOD RunPluginCrashCallbacks(uint32_t aPluginId,
107 : const nsACString& aPluginName) override;
108 :
109 : RefPtr<AbstractThread> GetAbstractGMPThread();
110 :
111 : void ConnectCrashHelper(uint32_t aPluginId, GMPCrashHelper* aHelper);
112 : void DisconnectCrashHelper(GMPCrashHelper* aHelper);
113 :
114 : protected:
115 : GeckoMediaPluginService();
116 : virtual ~GeckoMediaPluginService();
117 :
118 : virtual void InitializePlugins(AbstractThread* aAbstractGMPThread) = 0;
119 :
120 : virtual RefPtr<GetGMPContentParentPromise> GetContentParent(
121 : GMPCrashHelper* aHelper,
122 : const nsACString& aNodeIdString,
123 : const nsCString& aAPI,
124 : const nsTArray<nsCString>& aTags) = 0;
125 :
126 : virtual RefPtr<GetGMPContentParentPromise> GetContentParent(
127 : GMPCrashHelper* aHelper,
128 : const NodeId& aNodeId,
129 : const nsCString& aAPI,
130 : const nsTArray<nsCString>& aTags) = 0;
131 :
132 : nsresult GMPDispatch(nsIRunnable* event, uint32_t flags = NS_DISPATCH_NORMAL);
133 : nsresult GMPDispatch(already_AddRefed<nsIRunnable> event, uint32_t flags = NS_DISPATCH_NORMAL);
134 : void ShutdownGMPThread();
135 :
136 : Mutex mMutex; // Protects mGMPThread, mAbstractGMPThread, mPluginCrashHelpers,
137 : // mGMPThreadShutdown and some members in derived classes.
138 : nsCOMPtr<nsIThread> mGMPThread;
139 : RefPtr<AbstractThread> mAbstractGMPThread;
140 : bool mGMPThreadShutdown;
141 : bool mShuttingDownOnGMPThread;
142 :
143 : nsClassHashtable<nsUint32HashKey, nsTArray<RefPtr<GMPCrashHelper>>> mPluginCrashHelpers;
144 : };
145 :
146 : } // namespace gmp
147 : } // namespace mozilla
148 :
149 : #endif // GMPService_h_
|