summaryrefslogtreecommitdiffstats
path: root/dom/media/gmp/GMPServiceChild.h
blob: 63b1325bb2e26218fda7e0779ed6e9c9d970d8e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GMPServiceChild_h_
#define GMPServiceChild_h_

#include "GMPService.h"
#include "base/process.h"
#include "mozilla/ipc/Transport.h"
#include "mozilla/gmp/PGMPServiceChild.h"
#include "nsRefPtrHashtable.h"
#include "mozilla/dom/ContentChild.h"

namespace mozilla {
namespace gmp {

class GMPContentParent;
class GMPServiceChild;

class GetServiceChildCallback
{
public:
  GetServiceChildCallback()
  {
    MOZ_COUNT_CTOR(GetServiceChildCallback);
  }
  virtual ~GetServiceChildCallback()
  {
    MOZ_COUNT_DTOR(GetServiceChildCallback);
  }
  virtual void Done(GMPServiceChild* aGMPServiceChild) = 0;
};

class GeckoMediaPluginServiceChild : public GeckoMediaPluginService
{
  friend class GMPServiceChild;

public:
  static already_AddRefed<GeckoMediaPluginServiceChild> GetSingleton();

  NS_IMETHOD HasPluginForAPI(const nsACString& aAPI,
                             nsTArray<nsCString>* aTags,
                             bool *aRetVal) override;
  NS_IMETHOD GetNodeId(const nsAString& aOrigin,
                       const nsAString& aTopLevelOrigin,
                       const nsAString& aGMPName,
                       bool aInPrivateBrowsingMode,
                       UniquePtr<GetNodeIdCallback>&& aCallback) override;

  NS_DECL_NSIOBSERVER

  void SetServiceChild(UniquePtr<GMPServiceChild>&& aServiceChild);

  void RemoveGMPContentParent(GMPContentParent* aGMPContentParent);

  static void UpdateGMPCapabilities(nsTArray<mozilla::dom::GMPCapabilityData>&& aCapabilities);

protected:
  void InitializePlugins(AbstractThread*) override
  {
    // Nothing to do here.
  }
  bool GetContentParentFrom(GMPCrashHelper* aHelper,
                            const nsACString& aNodeId,
                            const nsCString& aAPI,
                            const nsTArray<nsCString>& aTags,
                            UniquePtr<GetGMPContentParentCallback>&& aCallback)
    override;

private:
  friend class OpenPGMPServiceChild;

  void GetServiceChild(UniquePtr<GetServiceChildCallback>&& aCallback);

  UniquePtr<GMPServiceChild> mServiceChild;
  nsTArray<UniquePtr<GetServiceChildCallback>> mGetServiceChildCallbacks;
};

class GMPServiceChild : public PGMPServiceChild
{
public:
  explicit GMPServiceChild();
  virtual ~GMPServiceChild();

  PGMPContentParent* AllocPGMPContentParent(Transport* aTransport,
                                            ProcessId aOtherPid) override;

  void GetBridgedGMPContentParent(ProcessId aOtherPid,
                                  GMPContentParent** aGMPContentParent);
  void RemoveGMPContentParent(GMPContentParent* aGMPContentParent);

  void GetAlreadyBridgedTo(nsTArray<ProcessId>& aAlreadyBridgedTo);

  static PGMPServiceChild* Create(Transport* aTransport, ProcessId aOtherPid);

private:
  nsRefPtrHashtable<nsUint64HashKey, GMPContentParent> mContentParents;
};

} // namespace gmp
} // namespace mozilla

#endif // GMPServiceChild_h_