diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-20 09:44:16 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-20 09:44:16 -0500 |
commit | 0cdd647abc53f7db3aa16f67bf0b2f8f3825db61 (patch) | |
tree | aa679e70fa83e4a1fce02ec1d783400fe3adba86 | |
parent | 9ecbf33313eee5c4e068e61451634cbfe4790694 (diff) | |
download | uxp-0cdd647abc53f7db3aa16f67bf0b2f8f3825db61.tar.gz |
Issue #26 - Revert 'Bug 1300654 - Remove MOZ_EME build option and make EME disabled by preferences'
34 files changed, 205 insertions, 25 deletions
diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index c2269c069f..dee6a3faaa 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -821,8 +821,10 @@ bin/libfreebl_32int64_3.so ; media +#ifdef MOZ_EME @RESPATH@/gmp-clearkey/0.1/@DLL_PREFIX@clearkey@DLL_SUFFIX@ @RESPATH@/gmp-clearkey/0.1/clearkey.info +#endif ; gfx #ifdef XP_WIN diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 290af152b2..9db9065142 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -97,8 +97,10 @@ #endif #include "mozilla/dom/ContentChild.h" +#ifdef MOZ_EME #include "mozilla/EMEUtils.h" #include "mozilla/DetailedPromise.h" +#endif namespace mozilla { namespace dom { @@ -214,7 +216,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow) +#ifdef MOZ_EME NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager) +#endif NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation) #ifdef MOZ_GAMEPAD NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest) @@ -288,10 +292,12 @@ Navigator::Invalidate() mServiceWorkerContainer = nullptr; +#ifdef MOZ_EME if (mMediaKeySystemAccessManager) { mMediaKeySystemAccessManager->Shutdown(); mMediaKeySystemAccessManager = nullptr; } +#endif #ifdef MOZ_GAMEPAD if (mGamepadServiceTest) { @@ -1894,6 +1900,7 @@ Navigator::GetUserAgent(nsPIDOMWindowInner* aWindow, nsIURI* aURI, return siteSpecificUA->GetUserAgentForURIAndWindow(aURI, aWindow, aUserAgent); } +#ifdef MOZ_EME static nsCString ToCString(const nsString& aString) { @@ -2019,6 +2026,7 @@ Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem, mMediaKeySystemAccessManager->Request(promise, aKeySystem, aConfigs); return promise.forget(); } +#endif Presentation* Navigator::GetPresentation(ErrorResult& aRv) diff --git a/dom/base/Navigator.h b/dom/base/Navigator.h index 4b4ae6759d..d47a80bc1c 100644 --- a/dom/base/Navigator.h +++ b/dom/base/Navigator.h @@ -18,7 +18,9 @@ #include "nsString.h" #include "nsTArray.h" #include "nsWeakPtr.h" +#ifdef MOZ_EME #include "mozilla/dom/MediaKeySystemAccessManager.h" +#endif class nsPluginArray; class nsMimeTypeArray; @@ -258,12 +260,14 @@ public: // any, else null. static already_AddRefed<nsPIDOMWindowInner> GetWindowFromGlobal(JSObject* aGlobal); +#ifdef MOZ_EME already_AddRefed<Promise> RequestMediaKeySystemAccess(const nsAString& aKeySystem, const Sequence<MediaKeySystemConfiguration>& aConfig, ErrorResult& aRv); private: RefPtr<MediaKeySystemAccessManager> mMediaKeySystemAccessManager; +#endif public: void NotifyVRDisplaysUpdated(); diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 8e6920a0e9..c6f58c57f5 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -4330,6 +4330,7 @@ nsDocument::SetScopeObject(nsIGlobalObject* aGlobal) } } +#ifdef MOZ_EME static void CheckIfContainsEMEContent(nsISupports* aSupports, void* aContainsEME) { @@ -4353,6 +4354,7 @@ nsDocument::ContainsEMEContent() static_cast<void*>(&containsEME)); return containsEME; } +#endif // MOZ_EME static void CheckIfContainsMSEContent(nsISupports* aSupports, void* aContainsMSE) @@ -8380,11 +8382,13 @@ nsDocument::CanSavePresentation(nsIRequest *aNewRequest) } #endif // MOZ_WEBRTC +#ifdef MOZ_EME // Don't save presentations for documents containing EME content, so that // CDMs reliably shutdown upon user navigation. if (ContainsEMEContent()) { return false; } +#endif // Don't save presentations for documents containing MSE content, to // reduce memory usage. diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index 17d936055c..2482d30570 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -1267,7 +1267,9 @@ public: js::ExpandoAndGeneration mExpandoAndGeneration; +#ifdef MOZ_EME bool ContainsEMEContent(); +#endif bool ContainsMSEContent(); diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index b0a430fe41..35ea2cd1a1 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -4977,10 +4977,12 @@ CanvasRenderingContext2D::DrawImage(const CanvasImageSource& aImage, return; } +#ifdef MOZ_EME if (video->ContainsRestrictedContent()) { aError.Throw(NS_ERROR_NOT_AVAILABLE); return; } +#endif uint16_t readyState; if (NS_SUCCEEDED(video->GetReadyState(&readyState)) && diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index e81cd20bcb..2dcc38fdfc 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -11,7 +11,9 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/MathAlgorithms.h" #include "mozilla/AsyncEventDispatcher.h" +#ifdef MOZ_EME #include "mozilla/dom/MediaEncryptedEvent.h" +#endif #include "base/basictypes.h" #include "nsIDOMHTMLMediaElement.h" @@ -820,7 +822,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLMediaElement, nsGenericHTM NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTextTrackManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioTrackList) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVideoTrackList) +#ifdef MOZ_EME NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeys) +#endif NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelectedVideoStreamTrack) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -845,7 +849,9 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement, nsGenericHTMLE NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextTrackManager) NS_IMPL_CYCLE_COLLECTION_UNLINK(mAudioTrackList) NS_IMPL_CYCLE_COLLECTION_UNLINK(mVideoTrackList) +#ifdef MOZ_EME NS_IMPL_CYCLE_COLLECTION_UNLINK(mMediaKeys) +#endif NS_IMPL_CYCLE_COLLECTION_UNLINK(mSelectedVideoStreamTrack) NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -1020,12 +1026,14 @@ void HTMLMediaElement::ShutdownDecoder() void HTMLMediaElement::AbortExistingLoads() { +#ifdef MOZ_EME // If there is no existing decoder then we don't have anything to // report. This prevents reporting the initial load from an // empty video element as a failed EME load. if (mDecoder) { ReportEMETelemetry(); } +#endif // Abort any already-running instance of the resource selection algorithm. mLoadWaitStatus = NOT_WAITING; @@ -1084,7 +1092,9 @@ void HTMLMediaElement::AbortExistingLoads() mDownloadSuspendedByCache = false; mMediaInfo = MediaInfo(); mIsEncrypted = false; +#ifdef MOZ_EME mPendingEncryptedInitData.mInitDatas.Clear(); +#endif mWaitingForKey = NOT_WAITING_FOR_KEY; mSourcePointer = nullptr; @@ -1758,6 +1768,18 @@ nsresult HTMLMediaElement::LoadResource() // Set the media element's CORS mode only when loading a resource mCORSMode = AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin)); + bool isBlob = false; + if (mMediaKeys && + Preferences::GetBool("media.eme.mse-only", true) && + // We only want mediaSource URLs, but they are BlobURL, so we have to + // check the schema and if they are not MediaStream or real Blob. + (NS_FAILED(mLoadingSrc->SchemeIs(BLOBURI_SCHEME, &isBlob)) || + !isBlob || + IsMediaStreamURI(mLoadingSrc) || + IsBlobURI(mLoadingSrc))) { + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; + } + HTMLMediaElement* other = LookupMediaElementURITable(mLoadingSrc); if (other && other->mDecoder) { // Clone it. @@ -2681,9 +2703,11 @@ HTMLMediaElement::CaptureStreamInternal(bool aFinishWhenEnded, if (!window) { return nullptr; } +#ifdef MOZ_EME if (ContainsRestrictedContent()) { return nullptr; } +#endif if (!mOutputStreams.IsEmpty() && aGraph != mOutputStreams[0].mStream->GetInputStream()->Graph()) { @@ -3638,6 +3662,7 @@ void HTMLMediaElement::HiddenVideoStop() mVideoDecodeSuspendTimer = nullptr; } +#ifdef MOZ_EME void HTMLMediaElement::ReportEMETelemetry() { @@ -3649,6 +3674,7 @@ HTMLMediaElement::ReportEMETelemetry() this, mLoadedDataFired ? "true" : "false")); } } +#endif void HTMLMediaElement::ReportTelemetry() @@ -3997,6 +4023,7 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder, ms.mFinishWhenEnded); } +#ifdef MOZ_EME if (mMediaKeys) { if (mMediaKeys->GetCDMProxy()) { mDecoder->SetCDMProxy(mMediaKeys->GetCDMProxy()); @@ -4006,6 +4033,7 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder, return NS_ERROR_FAILURE; } } +#endif MediaEventSource<void>* waitingForKeyProducer = mDecoder->WaitingForKeyEvent(); // Not every decoder will produce waitingForKey events, only add ones that can @@ -4468,7 +4496,11 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo, SetMediaInfo(*aInfo); - mIsEncrypted = aInfo->IsEncrypted() || mPendingEncryptedInitData.IsEncrypted(); + mIsEncrypted = aInfo->IsEncrypted() +#ifdef MOZ_EME + || mPendingEncryptedInitData.IsEncrypted() +#endif // MOZ_EME + ; mTags = aTags.forget(); mLoadedDataFired = false; ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA); @@ -4494,11 +4526,13 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo, return; } +#ifdef MOZ_EME // Dispatch a distinct 'encrypted' event for each initData we have. for (const auto& initData : mPendingEncryptedInitData.mInitDatas) { DispatchEncrypted(initData.mInitData, initData.mType); } mPendingEncryptedInitData.mInitDatas.Clear(); +#endif // MOZ_EME } mWatchManager.ManualNotify(&HTMLMediaElement::UpdateReadyStateInternal); @@ -5431,8 +5465,11 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement, bool aSuspendE UpdateAudioChannelPlayingState(); if (aPauseElement) { ReportTelemetry(); +#ifdef MOZ_EME ReportEMETelemetry(); +#endif +#ifdef MOZ_EME // For EME content, force destruction of the CDM client (and CDM // instance if this is the last client for that CDM instance) and // the CDM's decoder. This ensures the CDM gets reliable and prompt @@ -5445,13 +5482,16 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement, bool aSuspendE ShutdownDecoder(); } } +#endif if (mDecoder) { mDecoder->Pause(); mDecoder->Suspend(); } mEventDeliveryPaused = aSuspendEvents; } else { +#ifdef MOZ_EME MOZ_ASSERT(!mMediaKeys); +#endif if (mDecoder) { mDecoder->Resume(); if (!mPaused && !mDecoder->IsEnded()) { @@ -6269,7 +6309,7 @@ HTMLMediaElement::OnVisibilityChange(Visibility aNewVisibility) } } - +#ifdef MOZ_EME MediaKeys* HTMLMediaElement::GetMediaKeys() const { @@ -6479,6 +6519,7 @@ HTMLMediaElement::GetTopLevelPrincipal() principal = doc->NodePrincipal(); return principal.forget(); } +#endif // MOZ_EME void HTMLMediaElement::CannotDecryptWaitingForKey() diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index d40e9df463..fbc9d35d4e 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -20,7 +20,9 @@ #include "mozilla/dom/TextTrackManager.h" #include "mozilla/WeakPtr.h" #include "MediaDecoder.h" +#ifdef MOZ_EME #include "mozilla/dom/MediaKeys.h" +#endif #include "mozilla/StateWatching.h" #include "nsGkAtoms.h" #include "PrincipalChangeObserver.h" @@ -630,6 +632,7 @@ public: // XPCOM MozPreservesPitch() is OK +#ifdef MOZ_EME MediaKeys* GetMediaKeys() const; already_AddRefed<Promise> SetMediaKeys(MediaKeys* mediaKeys, @@ -651,6 +654,7 @@ public: already_AddRefed<nsIPrincipal> GetTopLevelPrincipal(); bool ContainsRestrictedContent(); +#endif // MOZ_EME void CannotDecryptWaitingForKey(); @@ -1198,8 +1202,9 @@ protected: */ void HiddenVideoStop(); +#ifdef MOZ_EME void ReportEMETelemetry(); - +#endif void ReportTelemetry(); // Check the permissions for audiochannel. @@ -1471,8 +1476,10 @@ protected: // Timer used to simulate video-suspend. nsCOMPtr<nsITimer> mVideoDecodeSuspendTimer; +#ifdef MOZ_EME // Encrypted Media Extension media keys. RefPtr<MediaKeys> mMediaKeys; +#endif // Stores the time at the start of the current 'played' range. double mCurrentPlayRangeStart; @@ -1627,8 +1634,10 @@ protected: // Listens for waitingForKey events from the owned decoder. MediaEventListener mWaitingForKeyListener; +#ifdef MOZ_EME // Init Data that needs to be sent in 'encrypted' events in MetadataLoaded(). EncryptionInfo mPendingEncryptedInitData; +#endif // True if the media's channel's download has been suspended. Watchable<bool> mDownloadSuspendedByCache; diff --git a/dom/media/AbstractMediaDecoder.h b/dom/media/AbstractMediaDecoder.h index a0f04ec988..6babcce171 100644 --- a/dom/media/AbstractMediaDecoder.h +++ b/dom/media/AbstractMediaDecoder.h @@ -31,7 +31,9 @@ class MediaResource; class ReentrantMonitor; class VideoFrameContainer; class MediaDecoderOwner; +#ifdef MOZ_EME class CDMProxy; +#endif typedef nsDataHashtable<nsCStringHashKey, nsCString> MetadataTags; diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp index ab39886ba7..dae5c8d382 100644 --- a/dom/media/MediaDecoder.cpp +++ b/dom/media/MediaDecoder.cpp @@ -382,7 +382,9 @@ MediaDecoder::MediaDecoder(MediaDecoderOwner* aOwner) , mLogicalPosition(0.0) , mDuration(std::numeric_limits<double>::quiet_NaN()) , mResourceCallback(new ResourceCallback()) +#ifdef MOZ_EME , mCDMProxyPromise(mCDMProxyPromiseHolder.Ensure(__func__)) +#endif , mIgnoreProgressData(false) , mInfiniteStream(false) , mOwner(aOwner) @@ -468,7 +470,9 @@ MediaDecoder::Shutdown() mResourceCallback->Disconnect(); +#ifdef MOZ_EME mCDMProxyPromiseHolder.RejectIfExists(true, __func__); +#endif DiscardOngoingSeekIfExists(); @@ -1569,6 +1573,7 @@ MediaDecoder::CanPlayThrough() return GetStatistics().CanPlayThrough(); } +#ifdef MOZ_EME RefPtr<MediaDecoder::CDMProxyPromise> MediaDecoder::RequestCDMProxy() const { @@ -1583,6 +1588,7 @@ MediaDecoder::SetCDMProxy(CDMProxy* aProxy) mCDMProxyPromiseHolder.ResolveIfExists(aProxy, __func__); } +#endif bool MediaDecoder::IsOpusEnabled() diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index 825bbbd2c0..47e286acae 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -7,8 +7,11 @@ #if !defined(MediaDecoder_h_) #define MediaDecoder_h_ -#include "mozilla/Atomics.h" +#ifdef MOZ_EME #include "mozilla/CDMProxy.h" +#endif + +#include "mozilla/Atomics.h" #include "mozilla/MozPromise.h" #include "mozilla/ReentrantMonitor.h" #include "mozilla/StateMirroring.h" @@ -428,6 +431,7 @@ private: MediaDecoderOwner* GetOwner() const override; +#ifdef MOZ_EME typedef MozPromise<RefPtr<CDMProxy>, bool /* aIgnored */, /* IsExclusive = */ true> CDMProxyPromise; // Resolved when a CDMProxy is available and the capabilities are known or @@ -435,6 +439,7 @@ private: RefPtr<CDMProxyPromise> RequestCDMProxy() const; void SetCDMProxy(CDMProxy* aProxy); +#endif void EnsureTelemetryReported(); @@ -591,8 +596,10 @@ private: RefPtr<ResourceCallback> mResourceCallback; +#ifdef MOZ_EME MozPromiseHolder<CDMProxyPromise> mCDMProxyPromiseHolder; RefPtr<CDMProxyPromise> mCDMProxyPromise; +#endif protected: // The promise resolving/rejection is queued as a "micro-task" which will be diff --git a/dom/media/MediaDecoderOwner.h b/dom/media/MediaDecoderOwner.h index f884686fb2..f993b43245 100644 --- a/dom/media/MediaDecoderOwner.h +++ b/dom/media/MediaDecoderOwner.h @@ -143,11 +143,13 @@ public: // reference to the decoder to prevent further calls into the decoder. virtual void NotifyXPCOMShutdown() = 0; +#ifdef MOZ_EME // Dispatches a "encrypted" event to the HTMLMediaElement, with the // provided init data. Actual dispatch may be delayed until HAVE_METADATA. // Main thread only. virtual void DispatchEncrypted(const nsTArray<uint8_t>& aInitData, const nsAString& aInitDataType) = 0; +#endif }; } // namespace mozilla diff --git a/dom/media/MediaDecoderReader.h b/dom/media/MediaDecoderReader.h index 8a69978264..819d514bc0 100644 --- a/dom/media/MediaDecoderReader.h +++ b/dom/media/MediaDecoderReader.h @@ -186,7 +186,9 @@ public: // when to call SetIdle(). virtual void SetIdle() {} +#ifdef MOZ_EME virtual void SetCDMProxy(CDMProxy* aProxy) {} +#endif // Tell the reader that the data decoded are not for direct playback, so it // can accept more files, in particular those which have more channels than diff --git a/dom/media/MediaDecoderReaderWrapper.h b/dom/media/MediaDecoderReaderWrapper.h index 92001ca333..1a8d3a68c7 100644 --- a/dom/media/MediaDecoderReaderWrapper.h +++ b/dom/media/MediaDecoderReaderWrapper.h @@ -113,7 +113,9 @@ public: return mReader->CanonicalBuffered(); } +#ifdef MOZ_EME void SetCDMProxy(CDMProxy* aProxy) { mReader->SetCDMProxy(aProxy); } +#endif void SetVideoBlankDecode(bool aIsBlankDecode); diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index f13e59b6cf..333c05cf6e 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -1289,7 +1289,12 @@ DecodeMetadataState::OnMetadataRead(MetadataHolder* aMetadata) // feeding in the CDM, which we need to decode the first frame (and // thus get the metadata). We could fix this if we could compute the start // time by demuxing without necessaring decoding. - bool waitingForCDM = Info().IsEncrypted() && !mMaster->mCDMProxy; + bool waitingForCDM = +#ifdef MOZ_EME + mMaster->Info().IsEncrypted() && !mMaster->mCDMProxy; +#else + false; +#endif mMaster->mNotifyMetadataBeforeFirstFrame = mMaster->mDuration.Ref().isSome() || waitingForCDM; @@ -1626,7 +1631,9 @@ ShutdownState::Enter() // dispose of the timer. master->mVideoDecodeSuspendTimer.Reset(); +#ifdef MOZ_EME master->mCDMProxyPromise.DisconnectIfExists(); +#endif if (master->IsPlaying()) { master->StopPlayback(); @@ -2180,10 +2187,12 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder) mMediaSink = CreateMediaSink(mAudioCaptured); +#ifdef MOZ_EME mCDMProxyPromise.Begin(aDecoder->RequestCDMProxy()->Then( OwnerThread(), __func__, this, &MediaDecoderStateMachine::OnCDMProxyReady, &MediaDecoderStateMachine::OnCDMProxyNotReady)); +#endif nsresult rv = mReader->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -3155,6 +3164,7 @@ void MediaDecoderStateMachine::OnMediaSinkAudioError(nsresult aResult) DecodeError(MediaResult(NS_ERROR_DOM_MEDIA_MEDIASINK_ERR, __func__)); } +#ifdef MOZ_EME void MediaDecoderStateMachine::OnCDMProxyReady(RefPtr<CDMProxy> aProxy) { @@ -3171,6 +3181,7 @@ MediaDecoderStateMachine::OnCDMProxyNotReady() MOZ_ASSERT(OnTaskQueue()); mCDMProxyPromise.Complete(); } +#endif void MediaDecoderStateMachine::SetAudioCaptured(bool aCaptured) diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index a61fe13d2a..dccb0e5c1d 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -765,10 +765,12 @@ private: // Playback will not start when audio is offloading. bool mAudioOffloading; +#ifdef MOZ_EME void OnCDMProxyReady(RefPtr<CDMProxy> aProxy); void OnCDMProxyNotReady(); RefPtr<CDMProxy> mCDMProxy; MozPromiseRequestHolder<MediaDecoder::CDMProxyPromise> mCDMProxyPromise; +#endif private: // The buffered range. Mirrored from the decoder thread. diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 2093803ad2..2fe66ad040 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -4,7 +4,6 @@ * 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/. */ -#include "mozilla/CDMProxy.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/Preferences.h" @@ -26,6 +25,10 @@ #include <algorithm> #include <queue> +#ifdef MOZ_EME +#include "mozilla/CDMProxy.h" +#endif + using namespace mozilla::media; using mozilla::layers::Image; @@ -346,8 +349,12 @@ MediaFormatReader::DecoderFactory::DoCreateDecoder(TrackType aTrack) if (!mOwner->mPlatform) { mOwner->mPlatform = new PDMFactory(); if (mOwner->IsEncrypted()) { +#ifdef MOZ_EME MOZ_ASSERT(mOwner->mCDMProxy); mOwner->mPlatform->SetCDMProxy(mOwner->mCDMProxy); +#else + return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, "EME not supported"); +#endif } } @@ -577,6 +584,7 @@ MediaFormatReader::InitInternal() return NS_OK; } +#ifdef MOZ_EME class DispatchKeyNeededEvent : public Runnable { public: DispatchKeyNeededEvent(AbstractMediaDecoder* aDecoder, @@ -614,11 +622,16 @@ MediaFormatReader::SetCDMProxy(CDMProxy* aProxy) }); OwnerThread()->Dispatch(r.forget()); } +#endif // MOZ_EME bool MediaFormatReader::IsWaitingOnCDMResource() { MOZ_ASSERT(OnTaskQueue()); +#ifdef MOZ_EME return IsEncrypted() && !mCDMProxy; +#else + return false; +#endif } RefPtr<MediaDecoderReader::MetadataPromise> @@ -725,11 +738,13 @@ MediaFormatReader::OnDemuxerInitDone(nsresult) UniquePtr<EncryptionInfo> crypto = mDemuxer->GetCrypto(); if (mDecoder && crypto && crypto->IsEncrypted()) { +#ifdef MOZ_EME // Try and dispatch 'encrypted'. Won't go if ready state still HAVE_NOTHING. for (uint32_t i = 0; i < crypto->mInitDatas.Length(); i++) { NS_DispatchToMainThread( new DispatchKeyNeededEvent(mDecoder, crypto->mInitDatas[i].mInitData, crypto->mInitDatas[i].mType)); } +#endif // MOZ_EME mInfo.mCrypto = *crypto; } diff --git a/dom/media/MediaFormatReader.h b/dom/media/MediaFormatReader.h index 4d05ca201c..bb016913ac 100644 --- a/dom/media/MediaFormatReader.h +++ b/dom/media/MediaFormatReader.h @@ -91,7 +91,9 @@ public: return mTrackDemuxersMayBlock; } +#ifdef MOZ_EME void SetCDMProxy(CDMProxy* aProxy) override; +#endif // Returns a string describing the state of the decoder data. // Used for debugging purposes. @@ -584,8 +586,9 @@ private: RefPtr<VideoFrameContainer> mVideoFrameContainer; layers::ImageContainer* GetImageContainer(); +#ifdef MOZ_EME RefPtr<CDMProxy> mCDMProxy; - +#endif RefPtr<GMPCrashHelper> mCrashHelper; void SetBlankDecode(TrackType aTrack, bool aIsBlankDecode); diff --git a/dom/media/fmp4/MP4Decoder.cpp b/dom/media/fmp4/MP4Decoder.cpp index fdd6f2c7e7..a26703b32d 100644 --- a/dom/media/fmp4/MP4Decoder.cpp +++ b/dom/media/fmp4/MP4Decoder.cpp @@ -10,7 +10,9 @@ #include "MP4Demuxer.h" #include "mozilla/Preferences.h" #include "nsCharSeparatedTokenizer.h" +#ifdef MOZ_EME #include "mozilla/CDMProxy.h" +#endif #include "mozilla/Logging.h" #include "mozilla/SharedThreadPool.h" #include "nsMimeTypes.h" diff --git a/dom/media/gmp/GMPParent.cpp b/dom/media/gmp/GMPParent.cpp index 75468ea9af..ff3c1d816c 100644 --- a/dom/media/gmp/GMPParent.cpp +++ b/dom/media/gmp/GMPParent.cpp @@ -41,8 +41,10 @@ using CrashReporter::GetIDFromMinidump; #include "WMFDecoderModule.h" #endif +#ifdef MOZ_EME #include "mozilla/dom/WidevineCDMManifestBinding.h" #include "widevine-adapter/WidevineAdapter.h" +#endif namespace mozilla { @@ -824,6 +826,7 @@ GMPParent::ReadGMPMetaData() return ReadGMPInfoFile(infoFile); } +#ifdef MOZ_EME // Maybe this is the Widevine adapted plugin? nsCOMPtr<nsIFile> manifestFile; rv = mDirectory->Clone(getter_AddRefs(manifestFile)); @@ -832,6 +835,9 @@ GMPParent::ReadGMPMetaData() } manifestFile->AppendRelativePath(NS_LITERAL_STRING("manifest.json")); return ReadChromiumManifestFile(manifestFile); +#else + return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); +#endif } RefPtr<GenericPromise> @@ -945,6 +951,7 @@ GMPParent::ParseChromiumManifest(nsString aJSON) LOGD("%s: for '%s'", __FUNCTION__, NS_LossyConvertUTF16toASCII(aJSON).get()); MOZ_ASSERT(NS_IsMainThread()); +#ifdef MOZ_EME mozilla::dom::WidevineCDMManifest m; if (!m.Init(aJSON)) { return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); @@ -979,6 +986,10 @@ GMPParent::ParseChromiumManifest(nsString aJSON) #endif return GenericPromise::CreateAndResolve(true, __func__); +#else + MOZ_ASSERT_UNREACHABLE("don't call me if EME isn't enabled"); + return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); +#endif } bool diff --git a/dom/media/gmp/moz.build b/dom/media/gmp/moz.build index 3b67fb5c91..f7b012733d 100644 --- a/dom/media/gmp/moz.build +++ b/dom/media/gmp/moz.build @@ -35,8 +35,6 @@ EXPORTS += [ 'GMPAudioDecoderProxy.h', 'GMPAudioHost.h', 'GMPCallbackBase.h', - 'GMPCDMCallbackProxy.h', - 'GMPCDMProxy.h', 'GMPChild.h', 'GMPContentChild.h', 'GMPContentParent.h', @@ -73,6 +71,12 @@ EXPORTS += [ 'GMPVideoPlaneImpl.h', ] +if CONFIG['MOZ_EME']: + EXPORTS += [ + 'GMPCDMCallbackProxy.h', + 'GMPCDMProxy.h', + ] + # We link GMPLoader into xul on B2G/Fennec as its code does not need to be # covered by a DRM vendor's voucher. if CONFIG['OS_TARGET'] == 'Android': @@ -87,8 +91,6 @@ UNIFIED_SOURCES += [ 'GMPAudioDecoderChild.cpp', 'GMPAudioDecoderParent.cpp', 'GMPAudioHost.cpp', - 'GMPCDMCallbackProxy.cpp', - 'GMPCDMProxy.cpp', 'GMPChild.cpp', 'GMPContentChild.cpp', 'GMPContentParent.cpp', @@ -120,6 +122,12 @@ UNIFIED_SOURCES += [ 'GMPVideoPlaneImpl.cpp', ] +if CONFIG['MOZ_EME']: + UNIFIED_SOURCES += [ + 'GMPCDMCallbackProxy.cpp', + 'GMPCDMProxy.cpp', + ] + DIRS += [ 'rlz', 'widevine-adapter', diff --git a/dom/media/gtest/MockMediaDecoderOwner.h b/dom/media/gtest/MockMediaDecoderOwner.h index 324f181416..81acc20a26 100644 --- a/dom/media/gtest/MockMediaDecoderOwner.h +++ b/dom/media/gtest/MockMediaDecoderOwner.h @@ -34,8 +34,10 @@ public: void DownloadProgressed() override {} void UpdateReadyState() override {} void FirstFrameLoaded() override {} +#ifdef MOZ_EME void DispatchEncrypted(const nsTArray<uint8_t>& aInitData, const nsAString& aInitDataType) override {} +#endif // MOZ_EME bool IsActive() const override { return true; } bool IsHidden() const override { return false; } void DownloadSuspended() override {} diff --git a/dom/media/gtest/moz.build b/dom/media/gtest/moz.build index fc92d5ef3b..8e9b3c880f 100644 --- a/dom/media/gtest/moz.build +++ b/dom/media/gtest/moz.build @@ -29,6 +29,11 @@ UNIFIED_SOURCES += [ 'TestWebMBuffered.cpp', ] +if CONFIG['MOZ_EME']: + UNIFIED_SOURCES += [ + 'TestEME.cpp', + ] + if CONFIG['MOZ_WEBM_ENCODER']: UNIFIED_SOURCES += [ 'TestVideoTrackEncoder.cpp', diff --git a/dom/media/mediasource/TrackBuffersManager.cpp b/dom/media/mediasource/TrackBuffersManager.cpp index 4265aed813..bb2f12b4f5 100644 --- a/dom/media/mediasource/TrackBuffersManager.cpp +++ b/dom/media/mediasource/TrackBuffersManager.cpp @@ -58,6 +58,7 @@ AppendStateToStr(SourceBufferAttributes::AppendState aState) static Atomic<uint32_t> sStreamSourceID(0u); +#ifdef MOZ_EME class DispatchKeyNeededEvent : public Runnable { public: DispatchKeyNeededEvent(AbstractMediaDecoder* aDecoder, @@ -83,6 +84,7 @@ private: nsTArray<uint8_t> mInitData; nsString mInitDataType; }; +#endif // MOZ_EME TrackBuffersManager::TrackBuffersManager(MediaSourceDecoder* aParentDecoder, const nsACString& aType) @@ -1097,12 +1099,14 @@ TrackBuffersManager::OnDemuxerInitDone(nsresult) UniquePtr<EncryptionInfo> crypto = mInputDemuxer->GetCrypto(); if (crypto && crypto->IsEncrypted()) { +#ifdef MOZ_EME // Try and dispatch 'encrypted'. Won't go if ready state still HAVE_NOTHING. for (uint32_t i = 0; i < crypto->mInitDatas.Length(); i++) { NS_DispatchToMainThread( new DispatchKeyNeededEvent(mParentDecoder, crypto->mInitDatas[i].mInitData, crypto->mInitDatas[i].mType)); } +#endif // MOZ_EME info.mCrypto = *crypto; // We clear our crypto init data array, so the MediaFormatReader will // not emit an encrypted event for the same init data again. diff --git a/dom/media/moz.build b/dom/media/moz.build index d1885793ba..fb8788e728 100644 --- a/dom/media/moz.build +++ b/dom/media/moz.build @@ -20,7 +20,6 @@ with Files('GetUserMedia*'): BUG_COMPONENT = component_av DIRS += [ - 'eme', 'encoder', 'flac', 'gmp', @@ -54,6 +53,9 @@ if CONFIG['MOZ_FMP4']: if CONFIG['MOZ_WEBRTC']: DIRS += ['bridge'] +if CONFIG['MOZ_EME']: + DIRS += ['eme'] + TEST_DIRS += [ 'gtest', ] diff --git a/dom/media/platforms/PDMFactory.cpp b/dom/media/platforms/PDMFactory.cpp index c1e58fdc2f..53a39d25c3 100644 --- a/dom/media/platforms/PDMFactory.cpp +++ b/dom/media/platforms/PDMFactory.cpp @@ -27,7 +27,6 @@ #endif #include "GMPDecoderModule.h" -#include "mozilla/CDMProxy.h" #include "mozilla/ClearOnShutdown.h" #include "mozilla/SharedThreadPool.h" #include "mozilla/StaticPtr.h" @@ -40,7 +39,11 @@ #include "H264Converter.h" #include "AgnosticDecoderModule.h" + +#ifdef MOZ_EME #include "EMEDecoderModule.h" +#include "mozilla/CDMProxy.h" +#endif #include "DecoderDoctorDiagnostics.h" @@ -459,11 +462,13 @@ PDMFactory::GetDecoder(const TrackInfo& aTrackInfo, return pdm.forget(); } +#ifdef MOZ_EME void PDMFactory::SetCDMProxy(CDMProxy* aProxy) { RefPtr<PDMFactory> m = new PDMFactory(); mEMEPDM = new EMEDecoderModule(aProxy, m); } +#endif } // namespace mozilla diff --git a/dom/media/platforms/PDMFactory.h b/dom/media/platforms/PDMFactory.h index 94be7e9283..f120ca2511 100644 --- a/dom/media/platforms/PDMFactory.h +++ b/dom/media/platforms/PDMFactory.h @@ -38,12 +38,14 @@ public: bool Supports(const TrackInfo& aTrackInfo, DecoderDoctorDiagnostics* aDiagnostics) const; +#ifdef MOZ_EME // Creates a PlatformDecoderModule that uses a CDMProxy to decrypt or // decrypt-and-decode EME encrypted content. If the CDM only decrypts and // does not decode, we create a PDM and use that to create MediaDataDecoders // that we use on on aTaskQueue to decode the decrypted stream. // This is called on the decode task queue. void SetCDMProxy(CDMProxy* aProxy); +#endif static constexpr int kYUV400 = 0; static constexpr int kYUV420 = 1; diff --git a/dom/media/platforms/moz.build b/dom/media/platforms/moz.build index 310820c912..c675e6969a 100644 --- a/dom/media/platforms/moz.build +++ b/dom/media/platforms/moz.build @@ -31,7 +31,6 @@ UNIFIED_SOURCES += [ ] DIRS += [ - 'agnostic/eme', 'agnostic/gmp', 'omx' ] @@ -39,6 +38,9 @@ DIRS += [ if CONFIG['MOZ_WMF']: DIRS += [ 'wmf' ]; +if CONFIG['MOZ_EME']: + DIRS += ['agnostic/eme'] + if CONFIG['MOZ_FFVPX'] or CONFIG['MOZ_FFMPEG']: # common code to either FFmpeg or FFVPX UNIFIED_SOURCES += [ diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index f61226a482..bd7ef20fc4 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -378,11 +378,12 @@ AudioContext::CreateMediaElementSource(HTMLMediaElement& aMediaElement, aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } - +#ifdef MOZ_EME if (aMediaElement.ContainsRestrictedContent()) { aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } +#endif if (CheckClosed(aRv)) { return nullptr; diff --git a/dom/webidl/HTMLMediaElement.webidl b/dom/webidl/HTMLMediaElement.webidl index 456579ec15..313686dacb 100644 --- a/dom/webidl/HTMLMediaElement.webidl +++ b/dom/webidl/HTMLMediaElement.webidl @@ -153,6 +153,7 @@ partial interface HTMLMediaElement { attribute EventHandler onmozinterruptend; }; +#ifdef MOZ_EME // Encrypted Media Extensions partial interface HTMLMediaElement { [Pref="media.eme.apiVisible"] @@ -168,6 +169,7 @@ partial interface HTMLMediaElement { [Pref="media.eme.apiVisible"] attribute EventHandler onwaitingforkey; }; +#endif // This is just for testing partial interface HTMLMediaElement { diff --git a/dom/webidl/Navigator.webidl b/dom/webidl/Navigator.webidl index 56461e4296..5452f3247a 100644 --- a/dom/webidl/Navigator.webidl +++ b/dom/webidl/Navigator.webidl @@ -348,12 +348,14 @@ partial interface Navigator { readonly attribute LegacyMozTCPSocket mozTCPSocket; }; +#ifdef MOZ_EME partial interface Navigator { [Pref="media.eme.apiVisible", NewObject] Promise<MediaKeySystemAccess> requestMediaKeySystemAccess(DOMString keySystem, sequence<MediaKeySystemConfiguration> supportedConfigurations); }; +#endif #ifdef NIGHTLY_BUILD partial interface Navigator { diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index f24c366e82..f5315dcd3c 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -9,6 +9,7 @@ GENERATED_WEBIDL_FILES = [ ] PREPROCESSED_WEBIDL_FILES = [ + 'HTMLMediaElement.webidl', 'Navigator.webidl', 'Node.webidl', 'Promise.webidl', @@ -210,7 +211,6 @@ WEBIDL_FILES = [ 'HTMLLIElement.webidl', 'HTMLLinkElement.webidl', 'HTMLMapElement.webidl', - 'HTMLMediaElement.webidl', 'HTMLMenuElement.webidl', 'HTMLMenuItemElement.webidl', 'HTMLMetaElement.webidl', @@ -286,15 +286,7 @@ WEBIDL_FILES = [ 'MediaDeviceInfo.webidl', 'MediaDevices.webidl', 'MediaElementAudioSourceNode.webidl', - 'MediaEncryptedEvent.webidl', 'MediaError.webidl', - 'MediaKeyError.webidl', - 'MediaKeyMessageEvent.webidl', - 'MediaKeys.webidl', - 'MediaKeySession.webidl', - 'MediaKeysRequestStatus.webidl', - 'MediaKeyStatusMap.webidl', - 'MediaKeySystemAccess.webidl', 'MediaList.webidl', 'MediaQueryList.webidl', 'MediaRecorder.webidl', @@ -564,7 +556,6 @@ WEBIDL_FILES = [ 'WebKitCSSMatrix.webidl', 'WebSocket.webidl', 'WheelEvent.webidl', - 'WidevineCDMManifest.webidl', 'WifiOptions.webidl', 'WindowOrWorkerGlobalScope.webidl', 'WindowRoot.webidl', @@ -778,6 +769,19 @@ if CONFIG['MOZ_BUILD_APP'] in ['mobile/android', 'xulrunner'] or CONFIG['MOZ_PHO 'External.webidl', ] +if CONFIG['MOZ_EME']: + WEBIDL_FILES += [ + 'MediaEncryptedEvent.webidl', + 'MediaKeyError.webidl', + 'MediaKeyMessageEvent.webidl', + 'MediaKeys.webidl', + 'MediaKeySession.webidl', + 'MediaKeysRequestStatus.webidl', + 'MediaKeyStatusMap.webidl', + 'MediaKeySystemAccess.webidl', + 'WidevineCDMManifest.webidl', + ] + if CONFIG['MOZ_B2G']: WEBIDL_FILES += [ 'MozApplicationEvent.webidl' diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index ed34f39cef..789c91f505 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -7242,9 +7242,11 @@ nsLayoutUtils::SurfaceFromElement(HTMLVideoElement* aElement, (aSurfaceFlags & SFE_PREFER_NO_PREMULTIPLY_ALPHA) == 0, "We can't support non-premultiplied alpha for video!"); +#ifdef MOZ_EME if (aElement->ContainsRestrictedContent()) { return result; } +#endif uint16_t readyState; if (NS_SUCCEEDED(aElement->GetReadyState(&readyState)) && diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 85a01e658d..502d268be9 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -447,6 +447,8 @@ def eme(value, fmp4): def eme_modules(value): return value +set_config('MOZ_EME', eme) +set_define('MOZ_EME', eme) set_config('MOZ_EME_MODULES', eme_modules) option(name='--enable-chrome-format', |