From 59e6c4722128261d99965c65db635ac9f14ec945 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Tue, 28 Oct 2014 13:21:12 +1300 Subject: [PATCH] Bug 1071482 - Make content encrypted via EME inaccessible from JS APIs. r=roc --- dom/html/HTMLMediaElement.cpp | 19 +++- dom/html/HTMLMediaElement.h | 1 + dom/media/test/eme.js | 6 +- dom/media/test/mochitest.ini | 4 + dom/media/test/test_eme_canvas_blocked.html | 67 ++++++++++++ .../test/test_eme_stream_capture_blocked.html | 102 ++++++++++++++++++ dom/media/webaudio/AudioContext.cpp | 6 ++ layout/base/nsLayoutUtils.cpp | 6 ++ 8 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 dom/media/test/test_eme_canvas_blocked.html create mode 100644 dom/media/test/test_eme_stream_capture_blocked.html diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 171861002c6..4f87760aa66 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -1792,7 +1792,11 @@ HTMLMediaElement::CaptureStreamInternal(bool aFinishWhenEnded) if (!window) { return nullptr; } - +#ifdef MOZ_EME + if (ContainsRestrictedContent()) { + return nullptr; + } +#endif OutputMediaStream* out = mOutputStreams.AppendElement(); #ifdef DEBUG // Estimate hints based on the type of the media element @@ -3997,10 +4001,21 @@ HTMLMediaElement::GetMediaKeys() const return mMediaKeys; } +bool +HTMLMediaElement::ContainsRestrictedContent() +{ + return GetMediaKeys() != nullptr; +} + already_AddRefed HTMLMediaElement::SetMediaKeys(mozilla::dom::MediaKeys* aMediaKeys, ErrorResult& aRv) { + if (MozAudioCaptured()) { + aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); + return nullptr; + } + nsCOMPtr global = do_QueryInterface(OwnerDoc()->GetInnerWindow()); if (!global) { @@ -4035,6 +4050,8 @@ HTMLMediaElement::SetMediaKeys(mozilla::dom::MediaKeys* aMediaKeys, if (mDecoder) { mDecoder->SetCDMProxy(mMediaKeys->GetCDMProxy()); } + // Update the same-origin status. + NotifyDecoderPrincipalChanged(); } promise->MaybeResolve(JS::UndefinedHandleValue); return promise.forget(); diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h index 82996463149..478f830a7ef 100644 --- a/dom/html/HTMLMediaElement.h +++ b/dom/html/HTMLMediaElement.h @@ -550,6 +550,7 @@ public: // in the URL bar of the browser window. already_AddRefed GetTopLevelPrincipal(); + bool ContainsRestrictedContent(); #endif // MOZ_EME bool MozAutoplayEnabled() const diff --git a/dom/media/test/eme.js b/dom/media/test/eme.js index ba8652f4170..8f8e7822e41 100644 --- a/dom/media/test/eme.js +++ b/dom/media/test/eme.js @@ -150,6 +150,10 @@ function SetupEME(test, token, params) { var v = document.createElement("video"); + var onSetKeysFail = (params && params.onSetKeysFail) + ? params.onSetKeysFail + : bail(token + " Failed to set MediaKeys on