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 GMPChild_h_
7 #define GMPChild_h_
8 
9 #include "mozilla/gmp/PGMPChild.h"
10 #include "GMPTimerChild.h"
11 #include "GMPStorageChild.h"
12 #include "GMPLoader.h"
13 #include "gmp-async-shutdown.h"
14 #include "gmp-entrypoints.h"
15 #include "prlink.h"
16 
17 namespace mozilla {
18 namespace gmp {
19 
20 class GMPContentChild;
21 
22 class GMPChild : public PGMPChild
23                , public GMPAsyncShutdownHost
24 {
25 public:
26   GMPChild();
27   virtual ~GMPChild();
28 
29   bool Init(const nsAString& aPluginPath,
30             const nsAString& aVoucherPath,
31             base::ProcessId aParentPid,
32             MessageLoop* aIOLoop,
33             IPC::Channel* aChannel);
34   MessageLoop* GMPMessageLoop();
35 
36   // Main thread only.
37   GMPTimerChild* GetGMPTimers();
38   GMPStorageChild* GetGMPStorage();
39 
40   // GMPAsyncShutdownHost
41   void ShutdownComplete() override;
42 
43 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
44   bool SetMacSandboxInfo(MacSandboxPluginType aPluginType);
45 #endif
46 
47 private:
48   friend class GMPContentChild;
49 
50   bool PreLoadPluginVoucher();
51   void PreLoadSandboxVoucher();
52 
53   bool GetUTF8LibPath(nsACString& aOutLibPath);
54 
55   bool RecvSetNodeId(const nsCString& aNodeId) override;
56   bool AnswerStartPlugin(const nsString& aAdapter) override;
57   bool RecvPreloadLibs(const nsCString& aLibs) override;
58 
59   PCrashReporterChild* AllocPCrashReporterChild(const NativeThreadId& aThread) override;
60   bool DeallocPCrashReporterChild(PCrashReporterChild*) override;
61 
62   PGMPTimerChild* AllocPGMPTimerChild() override;
63   bool DeallocPGMPTimerChild(PGMPTimerChild* aActor) override;
64 
65   PGMPStorageChild* AllocPGMPStorageChild() override;
66   bool DeallocPGMPStorageChild(PGMPStorageChild* aActor) override;
67 
68   PGMPContentChild* AllocPGMPContentChild(Transport* aTransport,
69                                           ProcessId aOtherPid) override;
70   void GMPContentChildActorDestroy(GMPContentChild* aGMPContentChild);
71 
72   bool RecvCrashPluginNow() override;
73   bool RecvBeginAsyncShutdown() override;
74   bool RecvCloseActive() override;
75 
76   void ActorDestroy(ActorDestroyReason aWhy) override;
77   void ProcessingError(Result aCode, const char* aReason) override;
78 
79   GMPErr GetAPI(const char* aAPIName, void* aHostAPI, void** aPluginAPI, uint32_t aDecryptorId = 0);
80 
81   nsTArray<UniquePtr<GMPContentChild>> mGMPContentChildren;
82 
83   GMPAsyncShutdown* mAsyncShutdown;
84   RefPtr<GMPTimerChild> mTimerChild;
85   RefPtr<GMPStorageChild> mStorage;
86 
87   MessageLoop* mGMPMessageLoop;
88   nsString mPluginPath;
89   nsString mSandboxVoucherPath;
90   nsCString mNodeId;
91   GMPLoader* mGMPLoader;
92   nsTArray<uint8_t> mPluginVoucher;
93   nsTArray<uint8_t> mSandboxVoucher;
94 };
95 
96 } // namespace gmp
97 } // namespace mozilla
98 
99 #endif // GMPChild_h_
100