Bug 1314445 - Make MediaKeySystemAccess use GMPService::HasPluginForAPI. r=gerald
Removes callers of GMPService::GetPluginVersionForAPI().
MozReview-Commit-ID: KZcyfDAfTR7
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -112,103 +112,90 @@ HaveGMPFor(mozIGeckoMediaPluginService*
if (NS_FAILED(aGMPService->HasPluginForAPI(aAPI,
&tags,
&hasPlugin))) {
return false;
}
return hasPlugin;
}
-static MediaKeySystemStatus
-EnsureMinCDMVersion(mozIGeckoMediaPluginService* aGMPService,
- const nsAString& aKeySystem,
- int32_t aMinCdmVersion,
- nsACString& aOutMessage,
- nsACString& aOutCdmVersion)
+static bool
+HavePluginForKeySystem(const nsCString& aKeySystem)
{
- nsTArray<nsCString> tags;
- tags.AppendElement(NS_ConvertUTF16toUTF8(aKeySystem));
- bool hasPlugin;
- nsAutoCString versionStr;
- if (NS_FAILED(aGMPService->GetPluginVersionForAPI(NS_LITERAL_CSTRING(GMP_API_DECRYPTOR),
- &tags,
- &hasPlugin,
- versionStr))) {
- aOutMessage = NS_LITERAL_CSTRING("GetPluginVersionForAPI failed");
- return MediaKeySystemStatus::Error;
+ bool havePlugin = false;
+ nsCOMPtr<mozIGeckoMediaPluginService> mps =
+ do_GetService("@mozilla.org/gecko-media-plugin-service;1");
+ if (mps) {
+ havePlugin = HaveGMPFor(mps,
+ aKeySystem,
+ NS_LITERAL_CSTRING(GMP_API_DECRYPTOR));
}
+#ifdef MOZ_WIDGET_ANDROID
+ // Check if we can use MediaDrm for this keysystem.
+ if (!havePlugin) {
+ havePlugin = mozilla::java::MediaDrmProxy::IsSchemeSupported(aKeySystem);
+ }
+#endif
+ return havePlugin;
+}
- aOutCdmVersion = versionStr;
-
- if (!hasPlugin) {
+static MediaKeySystemStatus
+EnsureCDMInstalled(const nsAString& aKeySystem,
+ nsACString& aOutMessage)
+{
+ if (!HavePluginForKeySystem(NS_ConvertUTF16toUTF8(aKeySystem))) {
aOutMessage = NS_LITERAL_CSTRING("CDM is not installed");
return MediaKeySystemStatus::Cdm_not_installed;
}
- 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;
- }
-
return MediaKeySystemStatus::Available;
}
/* static */
MediaKeySystemStatus
MediaKeySystemAccess::GetKeySystemStatus(const nsAString& aKeySystem,
- int32_t aMinCdmVersion,
- nsACString& aOutMessage,
- nsACString& aOutCdmVersion)
+ nsACString& aOutMessage)
{
MOZ_ASSERT(MediaPrefs::EMEEnabled() || IsClearkeyKeySystem(aKeySystem));
- nsCOMPtr<mozIGeckoMediaPluginService> mps =
- do_GetService("@mozilla.org/gecko-media-plugin-service;1");
- if (NS_WARN_IF(!mps)) {
- aOutMessage = NS_LITERAL_CSTRING("Failed to get GMP service");
- return MediaKeySystemStatus::Error;
- }
if (IsClearkeyKeySystem(aKeySystem)) {
- return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
+ return EnsureCDMInstalled(aKeySystem, aOutMessage);
}
if (Preferences::GetBool("media.gmp-eme-adobe.visible", false)) {
if (IsPrimetimeKeySystem(aKeySystem)) {
if (!Preferences::GetBool("media.gmp-eme-adobe.enabled", false)) {
aOutMessage = NS_LITERAL_CSTRING("Adobe EME disabled");
return MediaKeySystemStatus::Cdm_disabled;
}
#ifdef XP_WIN
// 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;
}
#endif
- return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
+ return EnsureCDMInstalled(aKeySystem, aOutMessage);
}
}
if (IsWidevineKeySystem(aKeySystem)) {
if (Preferences::GetBool("media.gmp-widevinecdm.visible", false)) {
#ifdef XP_WIN
// 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;
}
#endif
if (!Preferences::GetBool("media.gmp-widevinecdm.enabled", false)) {
aOutMessage = NS_LITERAL_CSTRING("Widevine EME disabled");
return MediaKeySystemStatus::Cdm_disabled;
}
- return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
+ return EnsureCDMInstalled(aKeySystem, aOutMessage);
#ifdef MOZ_WIDGET_ANDROID
} else if (Preferences::GetBool("media.mediadrm-widevinecdm.visible", false)) {
nsCString keySystem = NS_ConvertUTF16toUTF8(aKeySystem);
bool supported = mozilla::java::MediaDrmProxy::IsSchemeSupported(keySystem);
if (!supported) {
aOutMessage = NS_LITERAL_CSTRING("Widevine CDM is not available");
return MediaKeySystemStatus::Cdm_not_installed;
}
@@ -313,36 +300,16 @@ struct KeySystemConfig
KeySystemFeatureSupport mDistinctiveIdentifier = KeySystemFeatureSupport::Prohibited;
nsTArray<MediaKeySessionType> mSessionTypes;
nsTArray<nsString> mVideoRobustness;
nsTArray<nsString> mAudioRobustness;
KeySystemContainerSupport mMP4;
KeySystemContainerSupport mWebM;
};
-bool
-HavePluginForKeySystem(const nsCString& aKeySystem)
-{
- bool havePlugin = false;
- nsCOMPtr<mozIGeckoMediaPluginService> mps =
- do_GetService("@mozilla.org/gecko-media-plugin-service;1");
- if (mps) {
- havePlugin = HaveGMPFor(mps,
- aKeySystem,
- NS_LITERAL_CSTRING(GMP_API_DECRYPTOR));
- }
-#ifdef MOZ_WIDGET_ANDROID
- // Check if we can use MediaDrm for this keysystem.
- if (!havePlugin) {
- havePlugin = mozilla::java::MediaDrmProxy::IsSchemeSupported(aKeySystem);
- }
-#endif
- return havePlugin;
-}
-
static nsTArray<KeySystemConfig>
GetSupportedKeySystems()
{
nsTArray<KeySystemConfig> keySystemConfigs;
{
if (HavePluginForKeySystem(kEMEKeySystemClearkey)) {
KeySystemConfig clearkey;
--- a/dom/media/eme/MediaKeySystemAccess.h
+++ b/dom/media/eme/MediaKeySystemAccess.h
@@ -46,19 +46,17 @@ public:
void GetKeySystem(nsString& aRetVal) const;
void GetConfiguration(MediaKeySystemConfiguration& aConfig);
already_AddRefed<Promise> CreateMediaKeys(ErrorResult& aRv);
static MediaKeySystemStatus GetKeySystemStatus(const nsAString& aKeySystem,
- int32_t aMinCdmVersion,
- nsACString& aOutExceptionMessage,
- nsACString& aOutCdmVersion);
+ nsACString& aOutExceptionMessage);
static bool IsSupported(const nsAString& aKeySystem,
const Sequence<MediaKeySystemConfiguration>& aConfigs,
DecoderDoctorDiagnostics* aDiagnostics);
static void NotifyObservers(nsPIDOMWindowInner* aWindow,
const nsAString& aKeySystem,
MediaKeySystemStatus aStatus);
--- a/dom/media/eme/MediaKeySystemAccessManager.cpp
+++ b/dom/media/eme/MediaKeySystemAccessManager.cpp
@@ -117,31 +117,27 @@ MediaKeySystemAccessManager::Request(Det
aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("EME has been preffed off"));
diagnostics.StoreMediaKeySystemAccess(mWindow->GetExtantDoc(),
aKeySystem, false, __func__);
return;
}
nsAutoCString message;
- nsAutoCString cdmVersion;
MediaKeySystemStatus status =
- MediaKeySystemAccess::GetKeySystemStatus(keySystem, minCdmVersion, message, cdmVersion);
+ MediaKeySystemAccess::GetKeySystemStatus(keySystem, message);
- nsPrintfCString msg("MediaKeySystemAccess::GetKeySystemStatus(%s, minVer=%d) "
- "result=%s version='%s' msg='%s'",
+ nsPrintfCString msg("MediaKeySystemAccess::GetKeySystemStatus(%s) "
+ "result=%s msg='%s'",
NS_ConvertUTF16toUTF8(keySystem).get(),
- minCdmVersion,
MediaKeySystemStatusValues::strings[(size_t)status].value,
- cdmVersion.get(),
message.get());
LogToBrowserConsole(NS_ConvertUTF8toUTF16(msg));
- if ((status == MediaKeySystemStatus::Cdm_not_installed ||
- status == MediaKeySystemStatus::Cdm_insufficient_version) &&
+ if (status == MediaKeySystemStatus::Cdm_not_installed &&
(IsPrimetimeKeySystem(keySystem) || IsWidevineKeySystem(keySystem))) {
// These are cases which could be resolved by downloading a new(er) CDM.
// When we send the status to chrome, chrome's GMPProvider will attempt to
// download or update the CDM. In AwaitInstall() we add listeners to wait
// for the update to complete, and we'll call this function again with
// aType==Subsequent once the download has completed and the GMPService
// has had a new plugin added. AwaitInstall() sets a timer to fail if the
// update/download takes too long or fails.
@@ -159,28 +155,21 @@ MediaKeySystemAccessManager::Request(Det
aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("Gave up while waiting for a CDM update"));
}
diagnostics.StoreMediaKeySystemAccess(mWindow->GetExtantDoc(),
aKeySystem, false, __func__);
return;
}
if (status != MediaKeySystemStatus::Available) {
- if (status != MediaKeySystemStatus::Error) {
- // Failed due to user disabling something, send a notification to
- // chrome, so we can show some UI to explain how the user can rectify
- // the situation.
- MediaKeySystemAccess::NotifyObservers(mWindow, keySystem, status);
- aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR, message);
- return;
- }
- aPromise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR,
- NS_LITERAL_CSTRING("GetKeySystemAccess failed"));
- diagnostics.StoreMediaKeySystemAccess(mWindow->GetExtantDoc(),
- aKeySystem, false, __func__);
+ // Failed due to user disabling something, send a notification to
+ // chrome, so we can show some UI to explain how the user can rectify
+ // the situation.
+ MediaKeySystemAccess::NotifyObservers(mWindow, keySystem, status);
+ aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR, message);
return;
}
MediaKeySystemConfiguration config;
if (MediaKeySystemAccess::GetSupportedConfig(keySystem, aConfigs, config, &diagnostics)) {
RefPtr<MediaKeySystemAccess> access(
new MediaKeySystemAccess(mWindow, aKeySystem, config));
aPromise->MaybeResolve(access);
@@ -280,22 +269,18 @@ MediaKeySystemAccessManager::Observe(nsI
// initial request.
// Note: We don't have a way to communicate from chrome that the CDM has
// failed to download, so we'll just let the timeout fail us in that case.
nsTArray<PendingRequest> requests;
for (size_t i = mRequests.Length(); i > 0; i--) {
const size_t index = i - i;
PendingRequest& request = mRequests[index];
nsAutoCString message;
- nsAutoCString cdmVersion;
MediaKeySystemStatus status =
- MediaKeySystemAccess::GetKeySystemStatus(request.mKeySystem,
- NO_CDM_VERSION,
- message,
- cdmVersion);
+ MediaKeySystemAccess::GetKeySystemStatus(request.mKeySystem, message);
if (status == MediaKeySystemStatus::Cdm_not_installed) {
// Not yet installed, don't retry. Keep waiting until timeout.
continue;
}
// Status has changed, retry request.
requests.AppendElement(Move(request));
mRequests.RemoveElementAt(index);
}