MediaDrmProvisioningHelper.h (1997B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "mozilla/PRemoteCDMChild.h" 8 #include "mozilla/dom/PromiseNativeHandler.h" 9 #include "nsISerialEventTarget.h" 10 11 namespace mozilla { 12 13 /** 14 * MediaDrm may require us to provision during EME playback, which consists of 15 * sending a POST request to the given URL with a given sequence of request 16 * bytes, granted by AMediaDrm_getProvisionRequest. When we receive the 17 * response, we need to call AMediaDrm_provideProvisionResponse. This class runs 18 * in the content process to perform this network request on behalf of the 19 * decrypting process. 20 */ 21 class MediaDrmProvisioningHelper final : public dom::PromiseNativeHandler { 22 public: 23 NS_DECL_THREADSAFE_ISUPPORTS 24 25 explicit MediaDrmProvisioningHelper( 26 const RemoteCDMProvisionRequestIPDL& aRequest, 27 PRemoteCDMChild::ProvisionResolver&& aResolver); 28 29 void Provision(); 30 31 MOZ_CAN_RUN_SCRIPT 32 void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue, 33 ErrorResult& aRv) override; 34 35 MOZ_CAN_RUN_SCRIPT 36 void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue, 37 ErrorResult& aRv) override; 38 39 private: 40 ~MediaDrmProvisioningHelper() override; 41 42 template <class T> 43 void MaybeResolve(T&& aResult) { 44 if (!mResolver) { 45 return; 46 } 47 48 (void)mEventTarget->Dispatch(NS_NewRunnableFunction( 49 __func__, [result = std::move(aResult), 50 resolver = std::move(mResolver)]() { resolver(result); })); 51 mResolver = nullptr; 52 } 53 54 const nsCOMPtr<nsISerialEventTarget> mEventTarget; 55 nsString mServerUrl; 56 nsString mRequestData; 57 PRemoteCDMChild::ProvisionResolver mResolver; 58 }; 59 60 } // namespace mozilla