Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/gmp/GMPService.h
Line
Count
Source (jump to first uncovered line)
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/Atomics.h"
14
#include "mozilla/Attributes.h"
15
#include "mozilla/Monitor.h"
16
#include "nsString.h"
17
#include "nsCOMPtr.h"
18
#include "nsIThread.h"
19
#include "nsThreadUtils.h"
20
#include "nsIDocument.h"
21
#include "nsIWeakReference.h"
22
#include "mozilla/AbstractThread.h"
23
#include "nsClassHashtable.h"
24
#include "nsISupportsImpl.h"
25
#include "mozilla/MozPromise.h"
26
#include "GMPContentParent.h"
27
#include "GMPCrashHelper.h"
28
#include "ChromiumCDMParent.h"
29
#include "MediaResult.h"
30
31
template <class> struct already_AddRefed;
32
33
namespace mozilla {
34
35
class GMPCrashHelper;
36
37
extern LogModule* GetGMPLog();
38
39
namespace gmp {
40
41
struct NodeId
42
{
43
  NodeId(const nsAString& aOrigin,
44
         const nsAString& aTopLevelOrigin,
45
         const nsAString& aGMPName)
46
    : mOrigin(aOrigin)
47
    , mTopLevelOrigin(aTopLevelOrigin)
48
    , mGMPName(aGMPName)
49
0
  {
50
0
  }
51
  nsString mOrigin;
52
  nsString mTopLevelOrigin;
53
  nsString mGMPName;
54
};
55
56
typedef MozPromise<RefPtr<GMPContentParent::CloseBlocker>,
57
                   MediaResult,
58
                   /* IsExclusive = */ true>
59
  GetGMPContentParentPromise;
60
typedef MozPromise<RefPtr<ChromiumCDMParent>,
61
                   MediaResult,
62
                   /* IsExclusive = */ true>
63
  GetCDMParentPromise;
64
65
class GeckoMediaPluginService : public mozIGeckoMediaPluginService
66
                              , public nsIObserver
67
{
68
public:
69
  static already_AddRefed<GeckoMediaPluginService> GetGeckoMediaPluginService();
70
71
  virtual nsresult Init();
72
73
  NS_DECL_THREADSAFE_ISUPPORTS
74
75
  RefPtr<GetCDMParentPromise> GetCDM(const NodeId& aNodeId,
76
                                     nsTArray<nsCString> aTags,
77
                                     GMPCrashHelper* aHelper);
78
79
  // mozIGeckoMediaPluginService
80
  NS_IMETHOD GetThread(nsIThread** aThread) override;
81
  NS_IMETHOD GetDecryptingGMPVideoDecoder(GMPCrashHelper* aHelper,
82
                                          nsTArray<nsCString>* aTags,
83
                                          const nsACString& aNodeId,
84
                                          UniquePtr<GetGMPVideoDecoderCallback>&& aCallback,
85
                                          uint32_t aDecryptorId)
86
    override;
87
  NS_IMETHOD GetGMPVideoEncoder(GMPCrashHelper* aHelper,
88
                                nsTArray<nsCString>* aTags,
89
                                const nsACString& aNodeId,
90
                                UniquePtr<GetGMPVideoEncoderCallback>&& aCallback)
91
    override;
92
93
  // Helper for backwards compatibility with WebRTC/tests.
94
  NS_IMETHOD
95
  GetGMPVideoDecoder(GMPCrashHelper* aHelper,
96
                     nsTArray<nsCString>* aTags,
97
                     const nsACString& aNodeId,
98
                     UniquePtr<GetGMPVideoDecoderCallback>&& aCallback) override
99
0
  {
100
0
    return GetDecryptingGMPVideoDecoder(aHelper, aTags, aNodeId, std::move(aCallback), 0);
101
0
  }
102
103
  NS_IMETHOD RunPluginCrashCallbacks(uint32_t aPluginId,
104
                                     const nsACString& aPluginName) override;
105
106
  RefPtr<AbstractThread> GetAbstractGMPThread();
107
108
  void ConnectCrashHelper(uint32_t aPluginId, GMPCrashHelper* aHelper);
109
  void DisconnectCrashHelper(GMPCrashHelper* aHelper);
110
111
0
  bool XPCOMWillShutdownReceived() const { return mXPCOMWillShutdown; }
112
113
protected:
114
  GeckoMediaPluginService();
115
  virtual ~GeckoMediaPluginService();
116
117
  virtual void InitializePlugins(AbstractThread* aAbstractGMPThread) = 0;
118
119
  virtual RefPtr<GetGMPContentParentPromise> GetContentParent(
120
    GMPCrashHelper* aHelper,
121
    const nsACString& aNodeIdString,
122
    const nsCString& aAPI,
123
    const nsTArray<nsCString>& aTags) = 0;
124
125
  virtual RefPtr<GetGMPContentParentPromise> GetContentParent(
126
    GMPCrashHelper* aHelper,
127
    const NodeId& aNodeId,
128
    const nsCString& aAPI,
129
    const nsTArray<nsCString>& aTags) = 0;
130
131
  nsresult GMPDispatch(nsIRunnable* event, uint32_t flags = NS_DISPATCH_NORMAL);
132
  nsresult GMPDispatch(already_AddRefed<nsIRunnable> event, uint32_t flags = NS_DISPATCH_NORMAL);
133
  void ShutdownGMPThread();
134
135
  Mutex mMutex; // Protects mGMPThread, mAbstractGMPThread, mPluginCrashHelpers,
136
                // mGMPThreadShutdown and some members in derived classes.
137
  nsCOMPtr<nsIThread> mGMPThread;
138
  RefPtr<AbstractThread> mAbstractGMPThread;
139
  bool mGMPThreadShutdown;
140
  bool mShuttingDownOnGMPThread;
141
  Atomic<bool> mXPCOMWillShutdown;
142
143
  nsClassHashtable<nsUint32HashKey, nsTArray<RefPtr<GMPCrashHelper>>> mPluginCrashHelpers;
144
};
145
146
} // namespace gmp
147
} // namespace mozilla
148
149
#endif // GMPService_h_