From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/ipc/MFCDMChild.h | 146 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 dom/media/ipc/MFCDMChild.h (limited to 'dom/media/ipc/MFCDMChild.h') diff --git a/dom/media/ipc/MFCDMChild.h b/dom/media/ipc/MFCDMChild.h new file mode 100644 index 0000000000..e022e67862 --- /dev/null +++ b/dom/media/ipc/MFCDMChild.h @@ -0,0 +1,146 @@ +/* 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 DOM_MEDIA_IPC_MFCDMCHILD_H_ +#define DOM_MEDIA_IPC_MFCDMCHILD_H_ + +#include +#include "mozilla/Atomics.h" +#include "mozilla/MozPromise.h" +#include "mozilla/PMFCDMChild.h" + +namespace mozilla { + +class WMFCDMProxyCallback; + +/** + * MFCDMChild is a content process proxy to MFCDMParent and the actual CDM + * running in utility process. + */ +class MFCDMChild final : public PMFCDMChild { + public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MFCDMChild); + + explicit MFCDMChild(const nsAString& aKeySystem); + + using CapabilitiesPromise = MozPromise; + RefPtr GetCapabilities(); + + template + already_AddRefed InvokeAsync( + std::function&& aCall, const char* aCallerName, + MozPromiseHolder& aPromise); + + using InitPromise = MozPromise; + RefPtr Init(const nsAString& aOrigin, + const CopyableTArray& aInitDataTypes, + const KeySystemConfig::Requirement aPersistentState, + const KeySystemConfig::Requirement aDistinctiveID, + const bool aHWSecure, + WMFCDMProxyCallback* aProxyCallback); + + using SessionPromise = MozPromise; + RefPtr CreateSessionAndGenerateRequest( + uint32_t aPromiseId, const KeySystemConfig::SessionType aSessionType, + const nsAString& aInitDataType, const nsTArray& aInitData); + + RefPtr LoadSession( + uint32_t aPromiseId, const KeySystemConfig::SessionType aSessionType, + const nsAString& aSessionId); + + RefPtr UpdateSession(uint32_t aPromiseId, + const nsAString& aSessionId, + nsTArray& aResponse); + + RefPtr CloseSession(uint32_t aPromiseId, + const nsAString& aSessionId); + + RefPtr RemoveSession(uint32_t aPromiseId, + const nsAString& aSessionId); + + mozilla::ipc::IPCResult RecvOnSessionKeyMessage( + const MFCDMKeyMessage& aMessage); + mozilla::ipc::IPCResult RecvOnSessionKeyStatusesChanged( + const MFCDMKeyStatusChange& aKeyStatuses); + mozilla::ipc::IPCResult RecvOnSessionKeyExpiration( + const MFCDMKeyExpiration& aExpiration); + + uint64_t Id() const { return mId; } + + void IPDLActorDestroyed() { + AssertOnManagerThread(); + mIPDLSelfRef = nullptr; + if (!mShutdown) { + // Remote crashed! + mState = NS_ERROR_NOT_AVAILABLE; + } + } + void Shutdown(); + + nsISerialEventTarget* ManagerThread() { return mManagerThread; } + void AssertOnManagerThread() const { + MOZ_ASSERT(mManagerThread->IsOnCurrentThread()); + } + + private: + ~MFCDMChild(); + + using RemotePromise = GenericNonExclusivePromise; + RefPtr EnsureRemote(); + + void AssertSendable(); + + const nsString mKeySystem; + + const RefPtr mManagerThread; + RefPtr mIPDLSelfRef; + + RefPtr mRemotePromise; + MozPromiseHolder mRemotePromiseHolder; + MozPromiseRequestHolder mRemoteRequest; + // Before EnsureRemote(): NS_ERROR_NOT_INITIALIZED; After EnsureRemote(): + // NS_OK or some error code. + Atomic mState; + + MozPromiseHolder mCapabilitiesPromiseHolder; + + Atomic mShutdown; + + // This represents an unique Id to indentify the CDM in the remote process. + // 0(zero) means the CDM is not yet initialized. + // Modified on the manager thread, and read on other threads. + Atomic mId; + MozPromiseHolder mInitPromiseHolder; + using InitIPDLPromise = MozPromise; + MozPromiseRequestHolder mInitRequest; + + MozPromiseHolder mCreateSessionPromiseHolder; + MozPromiseRequestHolder + mCreateSessionRequest; + + MozPromiseHolder mLoadSessionPromiseHolder; + MozPromiseRequestHolder mLoadSessionRequest; + + MozPromiseHolder mUpdateSessionPromiseHolder; + MozPromiseRequestHolder mUpdateSessionRequest; + + MozPromiseHolder mCloseSessionPromiseHolder; + MozPromiseRequestHolder mCloseSessionRequest; + + MozPromiseHolder mRemoveSessionPromiseHolder; + MozPromiseRequestHolder mRemoveSessionRequest; + + std::unordered_map> + mPendingSessionPromises; + + std::unordered_map> + mPendingGenericPromises; + + RefPtr mProxyCallback; +}; + +} // namespace mozilla + +#endif // DOM_MEDIA_IPC_MFCDMCHILD_H_ -- cgit v1.2.3