MediaParent.h (2808B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et ft=cpp : */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_MediaParent_h 8 #define mozilla_MediaParent_h 9 10 #include "MediaChild.h" 11 #include "mozilla/media/PMediaParent.h" 12 13 namespace mozilla::media { 14 15 // media::Parent implements the chrome-process side of ipc for media::Child APIs 16 // A same-process version may also be created to service non-e10s calls. 17 18 class OriginKeyStore; 19 20 class NonE10s { 21 typedef mozilla::ipc::IProtocol::ActorDestroyReason ActorDestroyReason; 22 23 public: 24 virtual ~NonE10s() = default; 25 26 protected: 27 virtual mozilla::ipc::IPCResult RecvGetPrincipalKey( 28 const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const bool& aPersist, 29 PMediaParent::GetPrincipalKeyResolver&& aResolve) = 0; 30 virtual mozilla::ipc::IPCResult RecvSanitizeOriginKeys( 31 const uint64_t& aSinceWhen, const bool& aOnlyPrivateBrowsing) = 0; 32 virtual void ActorDestroy(ActorDestroyReason aWhy) = 0; 33 }; 34 35 /** 36 * Dummy class to avoid a templated class being passed to the refcounting macro 37 * (see Bug 1334421 for what happens then) 38 */ 39 class RefCountedParent { 40 public: 41 NS_INLINE_DECL_THREADSAFE_REFCOUNTING_WITH_DELETE_ON_MAIN_THREAD( 42 RefCountedParent) 43 44 protected: 45 virtual ~RefCountedParent() = default; 46 }; 47 48 // Super = PMediaParent or NonE10s 49 50 template <class Super> 51 class Parent : public RefCountedParent, public Super { 52 typedef mozilla::ipc::IProtocol::ActorDestroyReason ActorDestroyReason; 53 54 public: 55 virtual mozilla::ipc::IPCResult RecvGetPrincipalKey( 56 const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const bool& aPersist, 57 PMediaParent::GetPrincipalKeyResolver&& aResolve) override; 58 virtual mozilla::ipc::IPCResult RecvSanitizeOriginKeys( 59 const uint64_t& aSinceWhen, const bool& aOnlyPrivateBrowsing) override; 60 virtual void ActorDestroy(ActorDestroyReason aWhy) override; 61 62 Parent(); 63 64 private: 65 virtual ~Parent(); 66 67 RefPtr<OriginKeyStore> mOriginKeyStore; 68 bool mDestroyed; 69 }; 70 71 template <class Parent> 72 mozilla::ipc::IPCResult IPCResult(Parent* aSelf, bool aSuccess); 73 74 template <> 75 inline mozilla::ipc::IPCResult IPCResult(Parent<PMediaParent>* aSelf, 76 bool aSuccess) { 77 return aSuccess ? IPC_OK() : IPC_FAIL_NO_REASON(aSelf); 78 } 79 80 template <> 81 inline mozilla::ipc::IPCResult IPCResult(Parent<NonE10s>* aSelf, 82 bool aSuccess) { 83 return IPC_OK(); 84 } 85 86 PMediaParent* AllocPMediaParent(); 87 bool DeallocPMediaParent(PMediaParent* aActor); 88 89 } // namespace mozilla::media 90 91 #endif // mozilla_MediaParent_h