From f1df5dbbbd94039f4a4d952fdfd9353ea0fab373 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Mon, 1 May 2017 16:55:03 +1200 Subject: [PATCH] Bug 1361000 - Log a deprecation warning to the web console upon use of EME in an insecure context. r=bz Preliminary telemetry indicated 15% of users of EME are in an insecure context. We'd better log a warning to the web console to inform authors that their sites will stop working, rather than just breaking them! MozReview-Commit-ID: CZasdbcC1jS --HG-- extra : rebase_source : 008b9669d06a77bb133459df6479625ed47249a0 --- dom/base/Navigator.cpp | 18 ++++++++++++++++++ dom/locales/en-US/chrome/dom/dom.properties | 2 ++ 2 files changed, 20 insertions(+) diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 65a6e7550594..870afeaabeef 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -69,6 +69,7 @@ #include "nsStreamUtils.h" #include "WidgetUtils.h" #include "nsIPresentationService.h" +#include "nsIScriptError.h" #include "mozilla/dom/MediaDevices.h" #include "MediaManager.h" @@ -95,6 +96,7 @@ #include "mozilla/EMEUtils.h" #include "mozilla/DetailedPromise.h" +#include "mozilla/Unused.h" namespace mozilla { namespace dom { @@ -2024,6 +2026,22 @@ Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem, Telemetry::Accumulate(Telemetry::MEDIA_EME_SECURE_CONTEXT, mWindow->IsSecureContext()); + if (!mWindow->IsSecureContext()) { + nsIDocument* doc = mWindow->GetExtantDoc(); + nsString uri; + if (doc) { + Unused << doc->GetDocumentURI(uri); + } + const char16_t* params[] = { uri.get() }; + nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, + NS_LITERAL_CSTRING("Media"), + doc, + nsContentUtils::eDOM_PROPERTIES, + "MediaEMEInsecureContextDeprecatedWarning", + params, + ArrayLength(params)); + } + nsCOMPtr go = do_QueryInterface(mWindow); RefPtr promise = DetailedPromise::Create(go, aRv, diff --git a/dom/locales/en-US/chrome/dom/dom.properties b/dom/locales/en-US/chrome/dom/dom.properties index c33322723529..ec9b4a0dcbec 100644 --- a/dom/locales/en-US/chrome/dom/dom.properties +++ b/dom/locales/en-US/chrome/dom/dom.properties @@ -145,6 +145,8 @@ MediaRecorderMultiTracksNotSupported=MediaRecorder does not support recording mu MediaStreamAddTrackDifferentAudioChannel=MediaStreamTrack %S could not be added since it belongs to a different AudioChannel. # LOCALIZATION NOTE: Do not translate "MediaStream", "stop()" and "MediaStreamTrack" MediaStreamStopDeprecatedWarning=MediaStream.stop() is deprecated and will soon be removed. Use MediaStreamTrack.stop() instead. +# LOCALIZATION NOTE: %S is the URL of the web page which is not served on HTTPS and thus is not encrypted and considered insecure. +MediaEMEInsecureContextDeprecatedWarning=Using Encrypted Media Extensions at %S on an insecure (i.e. non-HTTPS) context is deprecated and will soon be removed. You should consider switching to a secure origin such as HTTPS. # LOCALIZATION NOTE: Do not translate "DOMException", "code" and "name" DOMExceptionCodeWarning=Use of DOMException’s code attribute is deprecated. Use name instead. # LOCALIZATION NOTE: Do not translate "__exposedProps__"