2014-11-18 09:13:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2015-09-01 05:31:48 +00:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2014-11-18 09:13:02 +00:00
|
|
|
#include "mozilla/dom/MediaKeySystemAccess.h"
|
|
|
|
#include "mozilla/dom/MediaKeySystemAccessBinding.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-05-10 01:02:28 +00:00
|
|
|
#include "MediaPrefs.h"
|
2014-11-18 09:13:02 +00:00
|
|
|
#include "nsContentTypeParser.h"
|
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
#include "MP4Decoder.h"
|
|
|
|
#endif
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "mozilla/WindowsVersion.h"
|
2016-04-12 04:12:22 +00:00
|
|
|
#include "WMFDecoderModule.h"
|
2014-11-18 09:13:02 +00:00
|
|
|
#endif
|
2015-08-31 04:08:03 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsCocoaFeatures.h"
|
|
|
|
#endif
|
2014-11-18 09:13:02 +00:00
|
|
|
#include "nsContentCID.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "mozIGeckoMediaPluginService.h"
|
|
|
|
#include "VideoUtils.h"
|
2015-02-13 19:52:42 +00:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIObserverService.h"
|
2015-02-20 01:37:55 +00:00
|
|
|
#include "mozilla/EMEUtils.h"
|
2015-04-30 09:52:14 +00:00
|
|
|
#include "GMPUtils.h"
|
2015-05-08 01:36:40 +00:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2015-07-09 07:29:13 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
2015-10-05 02:03:48 +00:00
|
|
|
#include "gmp-audio-decode.h"
|
|
|
|
#include "gmp-video-decode.h"
|
2016-04-22 03:42:11 +00:00
|
|
|
#include "DecoderDoctorDiagnostics.h"
|
2014-11-18 09:13:02 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaKeySystemAccess,
|
|
|
|
mParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaKeySystemAccess)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaKeySystemAccess)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaKeySystemAccess)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
MediaKeySystemAccess::MediaKeySystemAccess(nsPIDOMWindowInner* aParent,
|
2015-08-31 04:08:51 +00:00
|
|
|
const nsAString& aKeySystem,
|
2015-10-27 01:10:51 +00:00
|
|
|
const nsAString& aCDMVersion,
|
|
|
|
const MediaKeySystemConfiguration& aConfig)
|
2014-11-18 09:13:02 +00:00
|
|
|
: mParent(aParent)
|
|
|
|
, mKeySystem(aKeySystem)
|
2015-08-31 04:08:51 +00:00
|
|
|
, mCDMVersion(aCDMVersion)
|
2015-10-27 01:10:51 +00:00
|
|
|
, mConfig(aConfig)
|
2014-11-18 09:13:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MediaKeySystemAccess::~MediaKeySystemAccess()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
MediaKeySystemAccess::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-11-18 09:13:02 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return MediaKeySystemAccessBinding::Wrap(aCx, this, aGivenProto);
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
nsPIDOMWindowInner*
|
2014-11-18 09:13:02 +00:00
|
|
|
MediaKeySystemAccess::GetParentObject() const
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-31 04:08:51 +00:00
|
|
|
MediaKeySystemAccess::GetKeySystem(nsString& aOutKeySystem) const
|
2014-11-18 09:13:02 +00:00
|
|
|
{
|
2015-12-04 04:35:40 +00:00
|
|
|
aOutKeySystem.Assign(mKeySystem);
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 01:10:51 +00:00
|
|
|
void
|
|
|
|
MediaKeySystemAccess::GetConfiguration(MediaKeySystemConfiguration& aConfig)
|
|
|
|
{
|
|
|
|
aConfig = mConfig;
|
|
|
|
}
|
|
|
|
|
2014-11-18 09:13:02 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
MediaKeySystemAccess::CreateMediaKeys(ErrorResult& aRv)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MediaKeys> keys(new MediaKeys(mParent, mKeySystem, mCDMVersion));
|
2014-11-18 09:13:02 +00:00
|
|
|
return keys->Init(aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
HaveGMPFor(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsCString& aKeySystem,
|
|
|
|
const nsCString& aAPI,
|
|
|
|
const nsCString& aTag = EmptyCString())
|
|
|
|
{
|
|
|
|
nsTArray<nsCString> tags;
|
|
|
|
tags.AppendElement(aKeySystem);
|
|
|
|
if (!aTag.IsEmpty()) {
|
|
|
|
tags.AppendElement(aTag);
|
|
|
|
}
|
|
|
|
bool hasPlugin = false;
|
|
|
|
if (NS_FAILED(aGMPService->HasPluginForAPI(aAPI,
|
|
|
|
&tags,
|
|
|
|
&hasPlugin))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return hasPlugin;
|
|
|
|
}
|
|
|
|
|
2015-05-08 01:36:40 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
static bool
|
2015-06-26 15:06:21 +00:00
|
|
|
AdobePluginFileExists(const nsACString& aVersionStr,
|
|
|
|
const nsAString& aFilename)
|
2015-05-08 01:36:40 +00:00
|
|
|
{
|
2015-09-01 05:31:48 +00:00
|
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
2015-07-09 07:29:13 +00:00
|
|
|
|
2015-05-08 01:36:40 +00:00
|
|
|
nsCOMPtr<nsIFile> path;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(path));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = path->Append(NS_LITERAL_STRING("gmp-eme-adobe"));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = path->AppendNative(aVersionStr);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-26 15:06:21 +00:00
|
|
|
rv = path->Append(aFilename);
|
2015-05-08 01:36:40 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool exists = false;
|
|
|
|
return NS_SUCCEEDED(path->Exists(&exists)) && exists;
|
|
|
|
}
|
2015-06-26 15:06:21 +00:00
|
|
|
|
|
|
|
static bool
|
|
|
|
AdobePluginDLLExists(const nsACString& aVersionStr)
|
|
|
|
{
|
|
|
|
return AdobePluginFileExists(aVersionStr, NS_LITERAL_STRING("eme-adobe.dll"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
AdobePluginVoucherExists(const nsACString& aVersionStr)
|
|
|
|
{
|
|
|
|
return AdobePluginFileExists(aVersionStr, NS_LITERAL_STRING("eme-adobe.voucher"));
|
|
|
|
}
|
2015-05-08 01:36:40 +00:00
|
|
|
#endif
|
|
|
|
|
2015-09-01 05:31:48 +00:00
|
|
|
/* static */ bool
|
|
|
|
MediaKeySystemAccess::IsGMPPresentOnDisk(const nsAString& aKeySystem,
|
|
|
|
const nsACString& aVersion,
|
|
|
|
nsACString& aOutMessage)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
// We need to be able to access the filesystem, so call this in the
|
|
|
|
// main process via ContentChild.
|
|
|
|
ContentChild* contentChild = ContentChild::GetSingleton();
|
|
|
|
if (NS_WARN_IF(!contentChild)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCString message;
|
|
|
|
bool result = false;
|
|
|
|
bool ok = contentChild->SendIsGMPPresentOnDisk(nsString(aKeySystem), nsCString(aVersion),
|
|
|
|
&result, &message);
|
|
|
|
aOutMessage = message;
|
|
|
|
return ok && result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isPresent = true;
|
|
|
|
|
|
|
|
#if XP_WIN
|
|
|
|
if (aKeySystem.EqualsLiteral("com.adobe.primetime")) {
|
|
|
|
if (!AdobePluginDLLExists(aVersion)) {
|
|
|
|
NS_WARNING("Adobe EME plugin disappeared from disk!");
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Adobe DLL was expected to be on disk but was not");
|
|
|
|
isPresent = false;
|
|
|
|
}
|
|
|
|
if (!AdobePluginVoucherExists(aVersion)) {
|
|
|
|
NS_WARNING("Adobe EME voucher disappeared from disk!");
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Adobe plugin voucher was expected to be on disk but was not");
|
|
|
|
isPresent = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isPresent) {
|
|
|
|
// Reset the prefs that Firefox's GMP downloader sets, so that
|
|
|
|
// Firefox will try to download the plugin next time the updater runs.
|
|
|
|
Preferences::ClearUser("media.gmp-eme-adobe.lastUpdate");
|
|
|
|
Preferences::ClearUser("media.gmp-eme-adobe.version");
|
|
|
|
} else if (!EMEVoucherFileExists()) {
|
|
|
|
// Gecko doesn't have a voucher file for the plugin-container.
|
|
|
|
// Adobe EME isn't going to work, so don't advertise that it will.
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Plugin-container voucher not present");
|
|
|
|
isPresent = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return isPresent;
|
|
|
|
}
|
|
|
|
|
2015-02-20 01:38:08 +00:00
|
|
|
static MediaKeySystemStatus
|
|
|
|
EnsureMinCDMVersion(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsAString& aKeySystem,
|
2015-06-26 22:16:52 +00:00
|
|
|
int32_t aMinCdmVersion,
|
2015-08-31 04:08:51 +00:00
|
|
|
nsACString& aOutMessage,
|
|
|
|
nsACString& aOutCdmVersion)
|
2015-02-20 01:38:08 +00:00
|
|
|
{
|
|
|
|
nsTArray<nsCString> tags;
|
|
|
|
tags.AppendElement(NS_ConvertUTF16toUTF8(aKeySystem));
|
2015-02-24 14:03:56 +00:00
|
|
|
bool hasPlugin;
|
2015-02-20 01:38:08 +00:00
|
|
|
nsAutoCString versionStr;
|
|
|
|
if (NS_FAILED(aGMPService->GetPluginVersionForAPI(NS_LITERAL_CSTRING(GMP_API_DECRYPTOR),
|
2015-03-26 09:58:43 +00:00
|
|
|
&tags,
|
2015-02-24 14:03:56 +00:00
|
|
|
&hasPlugin,
|
2015-06-26 15:06:25 +00:00
|
|
|
versionStr))) {
|
2015-06-26 22:16:52 +00:00
|
|
|
aOutMessage = NS_LITERAL_CSTRING("GetPluginVersionForAPI failed");
|
2015-02-20 01:38:08 +00:00
|
|
|
return MediaKeySystemStatus::Error;
|
|
|
|
}
|
|
|
|
|
2015-08-31 04:08:51 +00:00
|
|
|
aOutCdmVersion = versionStr;
|
|
|
|
|
2015-02-24 14:03:56 +00:00
|
|
|
if (!hasPlugin) {
|
2015-06-26 22:16:52 +00:00
|
|
|
aOutMessage = NS_LITERAL_CSTRING("CDM is not installed");
|
2015-02-24 14:03:56 +00:00
|
|
|
return MediaKeySystemStatus::Cdm_not_installed;
|
|
|
|
}
|
|
|
|
|
2015-09-01 05:31:48 +00:00
|
|
|
if (!MediaKeySystemAccess::IsGMPPresentOnDisk(aKeySystem, versionStr, aOutMessage)) {
|
|
|
|
return MediaKeySystemStatus::Cdm_not_installed;
|
2015-05-08 01:36:40 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 09:59:07 +00:00
|
|
|
nsresult rv;
|
|
|
|
int32_t version = versionStr.ToInteger(&rv);
|
|
|
|
if (aMinCdmVersion != NO_CDM_VERSION &&
|
|
|
|
(NS_FAILED(rv) || version < 0 || aMinCdmVersion > version)) {
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Installed CDM version insufficient");
|
|
|
|
return MediaKeySystemStatus::Cdm_insufficient_version;
|
|
|
|
}
|
|
|
|
|
2015-02-20 01:38:08 +00:00
|
|
|
return MediaKeySystemStatus::Available;
|
|
|
|
}
|
|
|
|
|
2014-11-18 09:13:02 +00:00
|
|
|
/* static */
|
2015-02-13 19:52:42 +00:00
|
|
|
MediaKeySystemStatus
|
2015-02-20 01:38:08 +00:00
|
|
|
MediaKeySystemAccess::GetKeySystemStatus(const nsAString& aKeySystem,
|
2015-06-26 22:16:52 +00:00
|
|
|
int32_t aMinCdmVersion,
|
2015-08-31 04:08:51 +00:00
|
|
|
nsACString& aOutMessage,
|
|
|
|
nsACString& aOutCdmVersion)
|
2014-11-18 09:13:02 +00:00
|
|
|
{
|
2016-05-10 01:02:28 +00:00
|
|
|
MOZ_ASSERT(MediaPrefs::EMEEnabled());
|
2014-11-18 09:13:02 +00:00
|
|
|
nsCOMPtr<mozIGeckoMediaPluginService> mps =
|
|
|
|
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
|
|
|
|
if (NS_WARN_IF(!mps)) {
|
2015-06-26 22:16:52 +00:00
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Failed to get GMP service");
|
2015-02-13 19:52:42 +00:00
|
|
|
return MediaKeySystemStatus::Error;
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
|
|
|
|
2015-02-13 19:52:42 +00:00
|
|
|
if (aKeySystem.EqualsLiteral("org.w3.clearkey")) {
|
|
|
|
if (!Preferences::GetBool("media.eme.clearkey.enabled", true)) {
|
2015-06-26 22:16:52 +00:00
|
|
|
aOutMessage = NS_LITERAL_CSTRING("ClearKey was disabled");
|
2015-02-13 19:52:42 +00:00
|
|
|
return MediaKeySystemStatus::Cdm_disabled;
|
|
|
|
}
|
2015-08-31 04:08:51 +00:00
|
|
|
return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 03:36:22 +00:00
|
|
|
#ifdef MOZ_ADOBE_EME
|
|
|
|
if (aKeySystem.EqualsLiteral("com.adobe.primetime")) {
|
|
|
|
if (!Preferences::GetBool("media.gmp-eme-adobe.enabled", false)) {
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Adobe EME disabled");
|
|
|
|
return MediaKeySystemStatus::Cdm_disabled;
|
|
|
|
}
|
2014-11-18 09:13:02 +00:00
|
|
|
#ifdef XP_WIN
|
2016-06-09 03:36:22 +00:00
|
|
|
// Win Vista and later only.
|
|
|
|
if (!IsVistaOrLater()) {
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Minimum Windows version (Vista) not met for Adobe EME");
|
|
|
|
return MediaKeySystemStatus::Cdm_not_supported;
|
|
|
|
}
|
2015-08-31 04:08:03 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
2016-06-09 03:36:22 +00:00
|
|
|
if (!nsCocoaFeatures::OnLionOrLater()) {
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Minimum MacOSX version (10.7) not met for Adobe EME");
|
|
|
|
return MediaKeySystemStatus::Cdm_not_supported;
|
2016-05-30 23:00:55 +00:00
|
|
|
}
|
2016-06-09 03:36:22 +00:00
|
|
|
#endif
|
|
|
|
return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
2016-06-09 03:36:22 +00:00
|
|
|
#endif
|
2014-11-18 09:13:02 +00:00
|
|
|
|
2016-06-09 03:36:22 +00:00
|
|
|
#ifdef MOZ_WIDEVINE_EME
|
|
|
|
if (aKeySystem.EqualsLiteral("com.widevine.alpha")) {
|
2016-04-12 04:12:21 +00:00
|
|
|
#ifdef XP_WIN
|
2016-06-09 03:36:22 +00:00
|
|
|
// Win Vista and later only.
|
|
|
|
if (!IsVistaOrLater()) {
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Minimum Windows version (Vista) not met for Widevine EME");
|
|
|
|
return MediaKeySystemStatus::Cdm_not_supported;
|
|
|
|
}
|
2016-05-13 02:00:29 +00:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
2016-06-09 03:36:22 +00:00
|
|
|
if (!nsCocoaFeatures::OnLionOrLater()) {
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Minimum MacOSX version (10.7) not met for Widevine EME");
|
|
|
|
return MediaKeySystemStatus::Cdm_not_supported;
|
|
|
|
}
|
2016-04-12 04:12:21 +00:00
|
|
|
#endif
|
2016-06-09 03:36:22 +00:00
|
|
|
if (!Preferences::GetBool("media.gmp-widevinecdm.enabled", false)) {
|
|
|
|
aOutMessage = NS_LITERAL_CSTRING("Widevine EME disabled");
|
|
|
|
return MediaKeySystemStatus::Cdm_disabled;
|
2016-04-12 04:12:21 +00:00
|
|
|
}
|
2016-06-09 03:36:22 +00:00
|
|
|
return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
|
2016-04-12 04:12:20 +00:00
|
|
|
}
|
2016-06-09 03:36:22 +00:00
|
|
|
#endif
|
2016-04-12 04:12:20 +00:00
|
|
|
|
2015-02-13 19:52:42 +00:00
|
|
|
return MediaKeySystemStatus::Cdm_not_supported;
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2015-10-05 02:03:48 +00:00
|
|
|
GMPDecryptsAndDecodesAAC(mozIGeckoMediaPluginService* aGMPS,
|
2016-04-22 03:42:11 +00:00
|
|
|
const nsAString& aKeySystem,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2014-11-18 09:13:02 +00:00
|
|
|
{
|
2015-10-05 02:03:48 +00:00
|
|
|
MOZ_ASSERT(HaveGMPFor(aGMPS,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_DECRYPTOR)));
|
|
|
|
return HaveGMPFor(aGMPS,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_AUDIO_DECODER),
|
2016-04-12 04:12:22 +00:00
|
|
|
NS_LITERAL_CSTRING("aac"));
|
2015-10-05 02:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GMPDecryptsAndDecodesH264(mozIGeckoMediaPluginService* aGMPS,
|
2016-04-22 03:42:11 +00:00
|
|
|
const nsAString& aKeySystem,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-05 02:03:48 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(HaveGMPFor(aGMPS,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_DECRYPTOR)));
|
|
|
|
return HaveGMPFor(aGMPS,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
2015-12-15 01:07:01 +00:00
|
|
|
NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
|
2016-04-12 04:12:22 +00:00
|
|
|
NS_LITERAL_CSTRING("h264"));
|
2015-10-05 02:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If this keysystem's CDM explicitly says it doesn't support decoding,
|
|
|
|
// that means it's OK with passing the decrypted samples back to Gecko
|
2016-04-12 04:12:22 +00:00
|
|
|
// for decoding.
|
2015-10-05 02:03:48 +00:00
|
|
|
static bool
|
|
|
|
GMPDecryptsAndGeckoDecodesH264(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsAString& aKeySystem,
|
2016-04-22 03:42:11 +00:00
|
|
|
const nsAString& aContentType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-05 02:03:48 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(HaveGMPFor(aGMPService,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_DECRYPTOR)));
|
|
|
|
MOZ_ASSERT(IsH264ContentType(aContentType));
|
2016-04-12 04:12:22 +00:00
|
|
|
return !HaveGMPFor(aGMPService,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
|
|
|
|
NS_LITERAL_CSTRING("h264")) &&
|
2016-04-22 03:42:11 +00:00
|
|
|
MP4Decoder::CanHandleMediaType(aContentType, aDiagnostics);
|
2015-10-05 02:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
GMPDecryptsAndGeckoDecodesAAC(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsAString& aKeySystem,
|
2016-04-22 03:42:11 +00:00
|
|
|
const nsAString& aContentType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-05 02:03:48 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(HaveGMPFor(aGMPService,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_DECRYPTOR)));
|
|
|
|
MOZ_ASSERT(IsAACContentType(aContentType));
|
2016-04-12 04:12:22 +00:00
|
|
|
|
2016-04-22 03:42:11 +00:00
|
|
|
if (HaveGMPFor(aGMPService,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_AUDIO_DECODER),
|
|
|
|
NS_LITERAL_CSTRING("aac"))) {
|
|
|
|
// We do have a GMP for AAC -> Gecko itself does *not* decode AAC.
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-12 04:12:22 +00:00
|
|
|
#if defined(MOZ_WIDEVINE_EME) && defined(XP_WIN)
|
2016-04-22 03:42:11 +00:00
|
|
|
// Widevine CDM doesn't include an AAC decoder. So if WMF can't
|
|
|
|
// decode AAC, and a codec wasn't specified, be conservative
|
|
|
|
// and reject the MediaKeys request, since our policy is to prevent
|
|
|
|
// the Adobe GMP's unencrypted AAC decoding path being used to
|
|
|
|
// decode content decrypted by the Widevine CDM.
|
|
|
|
if (aKeySystem.EqualsLiteral("com.widevine.alpha") &&
|
|
|
|
!WMFDecoderModule::HasAAC()) {
|
|
|
|
if (aDiagnostics) {
|
|
|
|
aDiagnostics->SetKeySystemIssue(
|
|
|
|
DecoderDoctorDiagnostics::eWidevineWithNoWMF);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-04-12 04:12:22 +00:00
|
|
|
#endif
|
2016-04-22 03:42:11 +00:00
|
|
|
return MP4Decoder::CanHandleMediaType(aContentType, aDiagnostics);
|
2015-10-05 02:03:48 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 01:10:51 +00:00
|
|
|
static bool
|
|
|
|
IsSupportedAudio(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsAString& aKeySystem,
|
2016-04-22 03:42:11 +00:00
|
|
|
const nsAString& aAudioType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-27 01:10:51 +00:00
|
|
|
{
|
|
|
|
return IsAACContentType(aAudioType) &&
|
2016-04-22 03:42:11 +00:00
|
|
|
(GMPDecryptsAndDecodesAAC(aGMPService, aKeySystem, aDiagnostics) ||
|
|
|
|
GMPDecryptsAndGeckoDecodesAAC(aGMPService, aKeySystem, aAudioType, aDiagnostics));
|
2015-10-27 01:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsSupportedVideo(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsAString& aKeySystem,
|
2016-04-22 03:42:11 +00:00
|
|
|
const nsAString& aVideoType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-27 01:10:51 +00:00
|
|
|
{
|
|
|
|
return IsH264ContentType(aVideoType) &&
|
2016-04-22 03:42:11 +00:00
|
|
|
(GMPDecryptsAndDecodesH264(aGMPService, aKeySystem, aDiagnostics) ||
|
|
|
|
GMPDecryptsAndGeckoDecodesH264(aGMPService, aKeySystem, aVideoType, aDiagnostics));
|
2015-10-27 01:10:51 +00:00
|
|
|
}
|
|
|
|
|
2015-10-05 02:03:48 +00:00
|
|
|
static bool
|
|
|
|
IsSupported(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsAString& aKeySystem,
|
2016-04-22 03:42:11 +00:00
|
|
|
const MediaKeySystemConfiguration& aConfig,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-05 02:03:48 +00:00
|
|
|
{
|
2015-10-27 01:10:51 +00:00
|
|
|
if (aConfig.mInitDataType.IsEmpty() &&
|
|
|
|
aConfig.mAudioType.IsEmpty() &&
|
|
|
|
aConfig.mVideoType.IsEmpty()) {
|
|
|
|
// Not an old-style request.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-27 01:10:51 +00:00
|
|
|
// Backwards compatibility with legacy MediaKeySystemConfiguration method.
|
|
|
|
if (!aConfig.mInitDataType.IsEmpty() &&
|
|
|
|
!aConfig.mInitDataType.EqualsLiteral("cenc")) {
|
2014-11-18 09:13:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-05 02:03:48 +00:00
|
|
|
if (!aConfig.mAudioType.IsEmpty() &&
|
2016-04-22 03:42:11 +00:00
|
|
|
!IsSupportedAudio(aGMPService, aKeySystem, aConfig.mAudioType, aDiagnostics)) {
|
2014-11-18 09:13:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-05 02:03:48 +00:00
|
|
|
if (!aConfig.mVideoType.IsEmpty() &&
|
2016-04-22 03:42:11 +00:00
|
|
|
!IsSupportedVideo(aGMPService, aKeySystem, aConfig.mVideoType, aDiagnostics)) {
|
2015-10-05 02:03:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-27 01:10:51 +00:00
|
|
|
|
2015-10-05 02:03:48 +00:00
|
|
|
return true;
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
|
|
|
|
2016-04-12 04:12:22 +00:00
|
|
|
static bool
|
|
|
|
IsSupportedInitDataType(const nsString& aCandidate, const nsAString& aKeySystem)
|
|
|
|
{
|
|
|
|
// All supported keySystems can handle "cenc" initDataType.
|
|
|
|
// ClearKey also supports "keyids" and "webm" initDataTypes.
|
|
|
|
return aCandidate.EqualsLiteral("cenc") ||
|
2016-04-12 04:12:22 +00:00
|
|
|
((aKeySystem.EqualsLiteral("org.w3.clearkey")
|
|
|
|
#ifdef MOZ_WIDEVINE_EME
|
|
|
|
|| aKeySystem.EqualsLiteral("com.widevine.alpha")
|
|
|
|
#endif
|
|
|
|
) &&
|
2016-04-12 04:12:22 +00:00
|
|
|
(aCandidate.EqualsLiteral("keyids") || aCandidate.EqualsLiteral("webm)")));
|
|
|
|
}
|
|
|
|
|
2015-10-27 01:10:51 +00:00
|
|
|
static bool
|
|
|
|
GetSupportedConfig(mozIGeckoMediaPluginService* aGMPService,
|
|
|
|
const nsAString& aKeySystem,
|
|
|
|
const MediaKeySystemConfiguration& aCandidate,
|
2016-04-22 03:42:11 +00:00
|
|
|
MediaKeySystemConfiguration& aOutConfig,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-27 01:10:51 +00:00
|
|
|
{
|
|
|
|
MediaKeySystemConfiguration config;
|
|
|
|
config.mLabel = aCandidate.mLabel;
|
|
|
|
if (aCandidate.mInitDataTypes.WasPassed()) {
|
|
|
|
nsTArray<nsString> initDataTypes;
|
|
|
|
for (const nsString& candidate : aCandidate.mInitDataTypes.Value()) {
|
2016-04-12 04:12:22 +00:00
|
|
|
if (IsSupportedInitDataType(candidate, aKeySystem)) {
|
2015-11-27 04:13:40 +00:00
|
|
|
initDataTypes.AppendElement(candidate);
|
2015-10-27 01:10:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (initDataTypes.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
config.mInitDataTypes.Construct();
|
|
|
|
config.mInitDataTypes.Value().Assign(initDataTypes);
|
|
|
|
}
|
|
|
|
if (aCandidate.mAudioCapabilities.WasPassed()) {
|
|
|
|
nsTArray<MediaKeySystemMediaCapability> caps;
|
|
|
|
for (const MediaKeySystemMediaCapability& cap : aCandidate.mAudioCapabilities.Value()) {
|
2016-04-22 03:42:11 +00:00
|
|
|
if (IsSupportedAudio(aGMPService, aKeySystem, cap.mContentType, aDiagnostics)) {
|
2015-10-27 01:10:51 +00:00
|
|
|
caps.AppendElement(cap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (caps.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
config.mAudioCapabilities.Construct();
|
|
|
|
config.mAudioCapabilities.Value().Assign(caps);
|
|
|
|
}
|
|
|
|
if (aCandidate.mVideoCapabilities.WasPassed()) {
|
|
|
|
nsTArray<MediaKeySystemMediaCapability> caps;
|
|
|
|
for (const MediaKeySystemMediaCapability& cap : aCandidate.mVideoCapabilities.Value()) {
|
2016-04-22 03:42:11 +00:00
|
|
|
if (IsSupportedVideo(aGMPService, aKeySystem, cap.mContentType, aDiagnostics)) {
|
2015-10-27 01:10:51 +00:00
|
|
|
caps.AppendElement(cap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (caps.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
config.mVideoCapabilities.Construct();
|
|
|
|
config.mVideoCapabilities.Value().Assign(caps);
|
|
|
|
}
|
|
|
|
|
2016-04-12 04:12:22 +00:00
|
|
|
#if defined(MOZ_WIDEVINE_EME) && defined(XP_WIN)
|
|
|
|
// Widevine CDM doesn't include an AAC decoder. So if WMF can't decode AAC,
|
|
|
|
// and a codec wasn't specified, be conservative and reject the MediaKeys request.
|
|
|
|
if (aKeySystem.EqualsLiteral("com.widevine.alpha") &&
|
|
|
|
(!aCandidate.mAudioCapabilities.WasPassed() ||
|
|
|
|
!aCandidate.mVideoCapabilities.WasPassed()) &&
|
|
|
|
!WMFDecoderModule::HasAAC()) {
|
2016-04-22 03:42:11 +00:00
|
|
|
if (aDiagnostics) {
|
|
|
|
aDiagnostics->SetKeySystemIssue(
|
|
|
|
DecoderDoctorDiagnostics::eWidevineWithNoWMF);
|
|
|
|
}
|
2016-04-12 04:12:22 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-27 01:10:51 +00:00
|
|
|
aOutConfig = config;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backwards compatibility with legacy requestMediaKeySystemAccess with fields
|
|
|
|
// from old MediaKeySystemOptions dictionary.
|
2014-11-18 09:13:02 +00:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
MediaKeySystemAccess::IsSupported(const nsAString& aKeySystem,
|
2016-04-22 03:42:11 +00:00
|
|
|
const Sequence<MediaKeySystemConfiguration>& aConfigs,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2014-11-18 09:13:02 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<mozIGeckoMediaPluginService> mps =
|
|
|
|
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
|
|
|
|
if (NS_WARN_IF(!mps)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-05 02:03:48 +00:00
|
|
|
if (!HaveGMPFor(mps,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_DECRYPTOR))) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-11-18 09:13:02 +00:00
|
|
|
|
2015-10-27 01:10:51 +00:00
|
|
|
for (const MediaKeySystemConfiguration& config : aConfigs) {
|
2016-04-22 03:42:11 +00:00
|
|
|
if (mozilla::dom::IsSupported(mps, aKeySystem, config, aDiagnostics)) {
|
2015-10-05 02:03:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-11-18 09:13:02 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-27 01:10:51 +00:00
|
|
|
/* static */
|
|
|
|
bool
|
|
|
|
MediaKeySystemAccess::GetSupportedConfig(const nsAString& aKeySystem,
|
|
|
|
const Sequence<MediaKeySystemConfiguration>& aConfigs,
|
2016-04-22 03:42:11 +00:00
|
|
|
MediaKeySystemConfiguration& aOutConfig,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-10-27 01:10:51 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<mozIGeckoMediaPluginService> mps =
|
|
|
|
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
|
|
|
|
if (NS_WARN_IF(!mps)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HaveGMPFor(mps,
|
|
|
|
NS_ConvertUTF16toUTF8(aKeySystem),
|
|
|
|
NS_LITERAL_CSTRING(GMP_API_DECRYPTOR))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const MediaKeySystemConfiguration& config : aConfigs) {
|
2016-04-22 03:42:11 +00:00
|
|
|
if (mozilla::dom::GetSupportedConfig(
|
|
|
|
mps, aKeySystem, config, aOutConfig, aDiagnostics)) {
|
2015-10-27 01:10:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-13 19:52:42 +00:00
|
|
|
/* static */
|
|
|
|
void
|
2016-01-30 17:05:36 +00:00
|
|
|
MediaKeySystemAccess::NotifyObservers(nsPIDOMWindowInner* aWindow,
|
2015-02-16 21:25:11 +00:00
|
|
|
const nsAString& aKeySystem,
|
2015-02-13 19:52:42 +00:00
|
|
|
MediaKeySystemStatus aStatus)
|
|
|
|
{
|
|
|
|
RequestMediaKeySystemAccessNotification data;
|
|
|
|
data.mKeySystem = aKeySystem;
|
|
|
|
data.mStatus = aStatus;
|
|
|
|
nsAutoString json;
|
|
|
|
data.ToJSON(json);
|
2015-07-03 02:29:46 +00:00
|
|
|
EME_LOG("MediaKeySystemAccess::NotifyObservers() %s", NS_ConvertUTF16toUTF8(json).get());
|
2015-02-13 19:52:42 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
2015-02-16 21:25:11 +00:00
|
|
|
obs->NotifyObservers(aWindow, "mediakeys-request", json.get());
|
2015-02-13 19:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 09:13:02 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|