Bug 1288320 - Define each keysystem string as specific identifier instead of placing some.keysystem everywhere. r=cpearce
authorJames Cheng <jacheng@mozilla.com>
Wed, 27 Jul 2016 16:07:46 +0800
changeset 347016 5f98e30cc66ebe5b5e3aaf4071d8c69e85a4ae91
parent 347015 4730019ab44c34c7fe99e347647a25ba2b53b628
child 347017 bcb2a29ee460a790e11ee9178dd62ceddf7f79fe
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1288320
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1288320 - Define each keysystem string as specific identifier instead of placing some.keysystem everywhere. r=cpearce MozReview-Commit-ID: 1bwPRhMOawu
dom/media/eme/EMEUtils.cpp
dom/media/eme/EMEUtils.h
dom/media/eme/MediaKeySystemAccess.cpp
dom/media/eme/MediaKeySystemAccessManager.cpp
dom/media/gmp/GMPParent.cpp
dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
--- a/dom/media/eme/EMEUtils.cpp
+++ b/dom/media/eme/EMEUtils.cpp
@@ -130,28 +130,28 @@ CopyArrayBufferViewOrArrayBufferData(con
     return;
   }
   aOutData.AppendElements(data.mData, data.mLength);
 }
 
 nsString
 KeySystemToGMPName(const nsAString& aKeySystem)
 {
-  if (aKeySystem.EqualsLiteral("com.adobe.primetime")) {
+  if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime)) {
     return NS_LITERAL_STRING("gmp-eme-adobe");
   }
-  if (aKeySystem.EqualsLiteral("org.w3.clearkey")) {
+  if (aKeySystem.EqualsASCII(kEMEKeySystemClearkey)) {
     return NS_LITERAL_STRING("gmp-clearkey");
   }
-  if (aKeySystem.EqualsLiteral("com.widevine.alpha")) {
+  if (aKeySystem.EqualsASCII(kEMEKeySystemWidevine)) {
     return NS_LITERAL_STRING("gmp-widevinecdm");
   }
   MOZ_ASSERT(false, "We should only call this for known GMPs");
   return EmptyString();
 }
 
 bool
 IsClearkeyKeySystem(const nsAString& aKeySystem)
 {
-  return aKeySystem.EqualsLiteral("org.w3.clearkey");
+  return aKeySystem.EqualsASCII(kEMEKeySystemClearkey);
 }
 
 } // namespace mozilla
--- a/dom/media/eme/EMEUtils.h
+++ b/dom/media/eme/EMEUtils.h
@@ -8,16 +8,20 @@
 #define EME_LOG_H_
 
 #include "mozilla/Logging.h"
 #include "nsString.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 
+static const char* const kEMEKeySystemClearkey = "org.w3.clearkey";
+static const char* const kEMEKeySystemWidevine = "com.widevine.alpha";
+static const char* const kEMEKeySystemPrimetime = "com.adobe.primetime";
+
 namespace dom {
 class ArrayBufferViewOrArrayBuffer;
 }
 
 #ifndef EME_LOG
   LogModule* GetEMELog();
   #define EME_LOG(...) MOZ_LOG(GetEMELog(), mozilla::LogLevel::Debug, (__VA_ARGS__))
   #define EME_LOG_ENABLED() MOZ_LOG_TEST(GetEMELog(), mozilla::LogLevel::Debug)
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -186,17 +186,17 @@ MediaKeySystemAccess::IsGMPPresentOnDisk
                                                    &result, &message);
     aOutMessage = message;
     return ok && result;
   }
 
   bool isPresent = true;
 
 #if XP_WIN
-  if (aKeySystem.EqualsLiteral("com.adobe.primetime")) {
+  if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime)) {
     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");
@@ -271,39 +271,39 @@ MediaKeySystemAccess::GetKeySystemStatus
   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 (aKeySystem.EqualsLiteral("org.w3.clearkey")) {
+  if (aKeySystem.EqualsASCII(kEMEKeySystemClearkey)) {
     return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
   }
 
   if (Preferences::GetBool("media.gmp-eme-adobe.visible", false)) {
-    if (aKeySystem.EqualsLiteral("com.adobe.primetime")) {
+    if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime)) {
       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);
     }
   }
 
   if (Preferences::GetBool("media.gmp-widevinecdm.visible", false)) {
-    if (aKeySystem.EqualsLiteral("com.widevine.alpha")) {
+    if (aKeySystem.EqualsASCII(kEMEKeySystemWidevine)) {
 #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)) {
@@ -421,17 +421,17 @@ static const nsTArray<KeySystemConfig>&
 GetSupportedKeySystems()
 {
   if (!sKeySystemConfigs) {
     sKeySystemConfigs = new nsTArray<KeySystemConfig>();
     ClearOnShutdown(&sKeySystemConfigs);
 
     {
       KeySystemConfig clearkey;
-      clearkey.mKeySystem = NS_LITERAL_STRING("org.w3.clearkey");
+      clearkey.mKeySystem = NS_ConvertUTF8toUTF16(kEMEKeySystemClearkey);
       clearkey.mInitDataTypes.AppendElement(NS_LITERAL_STRING("cenc"));
       clearkey.mInitDataTypes.AppendElement(NS_LITERAL_STRING("keyids"));
       clearkey.mInitDataTypes.AppendElement(NS_LITERAL_STRING("webm"));
       clearkey.mPersistentState = KeySystemFeatureSupport::Requestable;
       clearkey.mDistinctiveIdentifier = KeySystemFeatureSupport::Prohibited;
       clearkey.mSessionTypes.AppendElement(MediaKeySessionType::Temporary);
       clearkey.mSessionTypes.AppendElement(MediaKeySessionType::Persistent_license);
 #if defined(XP_WIN)
@@ -453,17 +453,17 @@ GetSupportedKeySystems()
       clearkey.mWebM.SetCanDecrypt(GMP_CODEC_VORBIS);
       clearkey.mWebM.SetCanDecrypt(GMP_CODEC_OPUS);
       clearkey.mWebM.SetCanDecrypt(GMP_CODEC_VP8);
       clearkey.mWebM.SetCanDecrypt(GMP_CODEC_VP9);
       sKeySystemConfigs->AppendElement(Move(clearkey));
     }
     {
       KeySystemConfig widevine;
-      widevine.mKeySystem = NS_LITERAL_STRING("com.widevine.alpha");
+      widevine.mKeySystem = NS_ConvertUTF8toUTF16(kEMEKeySystemWidevine);
       widevine.mInitDataTypes.AppendElement(NS_LITERAL_STRING("cenc"));
       widevine.mInitDataTypes.AppendElement(NS_LITERAL_STRING("keyids"));
       widevine.mInitDataTypes.AppendElement(NS_LITERAL_STRING("webm"));
       widevine.mPersistentState = KeySystemFeatureSupport::Requestable;
       widevine.mDistinctiveIdentifier = KeySystemFeatureSupport::Prohibited;
       widevine.mSessionTypes.AppendElement(MediaKeySessionType::Temporary);
       widevine.mAudioRobustness.AppendElement(NS_LITERAL_STRING("SW_SECURE_CRYPTO"));
       widevine.mVideoRobustness.AppendElement(NS_LITERAL_STRING("SW_SECURE_DECODE"));
@@ -484,17 +484,17 @@ GetSupportedKeySystems()
       //widevine.mWebM.SetCanDecrypt(GMP_CODEC_VORBIS);
       //widevine.mWebM.SetCanDecrypt(GMP_CODEC_OPUS);
       //widevine.mWebM.SetCanDecryptAndDecode(GMP_CODEC_VP8);
       //widevine.mWebM.SetCanDecryptAndDecode(GMP_CODEC_VP9);
       sKeySystemConfigs->AppendElement(Move(widevine));
     }
     {
       KeySystemConfig primetime;
-      primetime.mKeySystem = NS_LITERAL_STRING("com.adobe.primetime");
+      primetime.mKeySystem = NS_ConvertUTF8toUTF16(kEMEKeySystemPrimetime);
       primetime.mInitDataTypes.AppendElement(NS_LITERAL_STRING("cenc"));
       primetime.mPersistentState = KeySystemFeatureSupport::Required;
       primetime.mDistinctiveIdentifier = KeySystemFeatureSupport::Required;
       primetime.mSessionTypes.AppendElement(MediaKeySessionType::Temporary);
       primetime.mMP4.SetCanDecryptAndDecode(GMP_CODEC_AAC);
       primetime.mMP4.SetCanDecryptAndDecode(GMP_CODEC_H264);
       sKeySystemConfigs->AppendElement(Move(primetime));
     }
@@ -559,17 +559,17 @@ CanDecryptAndDecode(mozIGeckoMediaPlugin
 
 #if 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, 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 (codec == GMP_CODEC_AAC &&
-        aKeySystem.EqualsLiteral("com.widevine.alpha") &&
+        aKeySystem.EqualsASCII(kEMEKeySystemWidevine) &&
         !WMFDecoderModule::HasAAC()) {
       if (aDiagnostics) {
         aDiagnostics->SetKeySystemIssue(
           DecoderDoctorDiagnostics::eWidevineWithNoWMF);
       }
     }
 #endif
     return false;
@@ -1126,17 +1126,17 @@ GetSupportedConfig(mozIGeckoMediaPluginS
     }
   }
 
   // Note: Omitting steps 20-22. We don't ask for consent.
 
 #if 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.mKeySystem.EqualsLiteral("com.widevine.alpha") &&
+  if (aKeySystem.mKeySystem.EqualsASCII(kEMEKeySystemWidevine) &&
       (aCandidate.mAudioCapabilities.IsEmpty() ||
        aCandidate.mVideoCapabilities.IsEmpty()) &&
      !WMFDecoderModule::HasAAC()) {
     if (aDiagnostics) {
       aDiagnostics->SetKeySystemIssue(
         DecoderDoctorDiagnostics::eWidevineWithNoWMF);
     }
     EME_LOG("MediaKeySystemConfiguration (label='%s') rejected; "
--- a/dom/media/eme/MediaKeySystemAccessManager.cpp
+++ b/dom/media/eme/MediaKeySystemAccessManager.cpp
@@ -137,18 +137,18 @@ MediaKeySystemAccessManager::Request(Det
                       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) &&
-      (keySystem.EqualsLiteral("com.adobe.primetime") ||
-       keySystem.EqualsLiteral("com.widevine.alpha"))) {
+      (keySystem.EqualsASCII(kEMEKeySystemPrimetime) ||
+       keySystem.EqualsASCII(kEMEKeySystemWidevine))) {
     // 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.
     if (aType == RequestType::Initial &&
--- a/dom/media/gmp/GMPParent.cpp
+++ b/dom/media/gmp/GMPParent.cpp
@@ -575,17 +575,17 @@ GMPParent::SupportsAPI(const nsCString& 
     nsTArray<nsCString>& tags = mCapabilities[i].mAPITags;
     for (uint32_t j = 0; j < tags.Length(); j++) {
       if (tags[j].Equals(aTag)) {
 #ifdef XP_WIN
         // Clearkey on Windows advertises that it can decode in its GMP info
         // file, but uses Windows Media Foundation to decode. That's not present
         // on Windows XP, and on some Vista, Windows N, and KN variants without
         // certain services packs.
-        if (tags[j].EqualsLiteral("org.w3.clearkey")) {
+        if (tags[j].Equals(kEMEKeySystemClearkey)) {
           if (mCapabilities[i].mAPIName.EqualsLiteral(GMP_API_VIDEO_DECODER)) {
             if (!WMFDecoderModule::HasH264()) {
               continue;
             }
           } else if (mCapabilities[i].mAPIName.EqualsLiteral(GMP_API_AUDIO_DECODER)) {
             if (!WMFDecoderModule::HasAAC()) {
               continue;
             }
@@ -893,17 +893,17 @@ GMPParent::ReadGMPInfoFile(nsIFile* aFil
                       mDisplayName.get());
         return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
       }
 #endif
 #ifdef XP_WIN
       // Adobe GMP doesn't work without SSE2. Check the tags to see if
       // the decryptor is for the Adobe GMP, and refuse to load it if
       // SSE2 isn't supported.
-      if (cap.mAPITags.Contains(NS_LITERAL_CSTRING("com.adobe.primetime")) &&
+      if (cap.mAPITags.Contains(nsCString(kEMEKeySystemPrimetime)) &&
           !mozilla::supports_sse2()) {
         return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
       }
 #endif // XP_WIN
     }
 
     mCapabilities.AppendElement(Move(cap));
   }
@@ -948,21 +948,21 @@ GMPParent::ParseChromiumManifest(nsStrin
   }
 
   mDisplayName = NS_ConvertUTF16toUTF8(m.mName);
   mDescription = NS_ConvertUTF16toUTF8(m.mDescription);
   mVersion = NS_ConvertUTF16toUTF8(m.mVersion);
 
   GMPCapability video(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER));
   video.mAPITags.AppendElement(NS_LITERAL_CSTRING("h264"));
-  video.mAPITags.AppendElement(NS_LITERAL_CSTRING("com.widevine.alpha"));
+  video.mAPITags.AppendElement(nsCString(kEMEKeySystemWidevine));
   mCapabilities.AppendElement(Move(video));
 
   GMPCapability decrypt(NS_LITERAL_CSTRING(GMP_API_DECRYPTOR));
-  decrypt.mAPITags.AppendElement(NS_LITERAL_CSTRING("com.widevine.alpha"));
+  decrypt.mAPITags.AppendElement(nsCString(kEMEKeySystemWidevine));
   mCapabilities.AppendElement(Move(decrypt));
 
   MOZ_ASSERT(mName.EqualsLiteral("widevinecdm"));
   mAdapter = NS_LITERAL_STRING("widevine");
 #ifdef XP_WIN
   mLibs = NS_LITERAL_CSTRING("dxva2.dll");
 #endif
 
--- a/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
+++ b/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
@@ -7,23 +7,23 @@
 #include "content_decryption_module.h"
 #include "WidevineDecryptor.h"
 #include "WidevineUtils.h"
 #include "WidevineVideoDecoder.h"
 #include "gmp-api/gmp-entrypoints.h"
 #include "gmp-api/gmp-decryption.h"
 #include "gmp-api/gmp-video-codec.h"
 #include "gmp-api/gmp-platform.h"
+#include "mozilla/EMEUtils.h"
 #include "mozilla/StaticPtr.h"
 
 static const GMPPlatformAPI* sPlatform = nullptr;
 
 namespace mozilla {
 
-const char* WidevineKeySystem = "com.widevine.alpha";
 StaticRefPtr<CDMWrapper> sCDMWrapper;
 
 GMPErr GMPGetCurrentTime(GMPTimestamp* aOutTime) {
   return sPlatform->getcurrenttime(aOutTime);
 }
 
 // Call on main thread only.
 GMPErr GMPSetTimerOnMainThread(GMPTask* aTask, int64_t aTimeoutMS) {
@@ -105,18 +105,18 @@ WidevineAdapter::GMPGetAPI(const char* a
         aAPIName, aHostAPI, aPluginAPI, this);
       return GMPGenericErr;
     }
 
     WidevineDecryptor* decryptor = new WidevineDecryptor();
 
     auto cdm = reinterpret_cast<cdm::ContentDecryptionModule*>(
       create(cdm::ContentDecryptionModule::kVersion,
-             WidevineKeySystem,
-             strlen(WidevineKeySystem),
+             kEMEKeySystemWidevine,
+             strlen(kEMEKeySystemWidevine),
              &GetCdmHost,
              decryptor));
     if (!cdm) {
       Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p) this=0x%p FAILED to create cdm",
           aAPIName, aHostAPI, aPluginAPI, this);
       return GMPGenericErr;
     }
     Log("cdm: 0x%x", cdm);
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
@@ -7,16 +7,17 @@
 #include "GMPDecoderModule.h"
 #include "DecoderDoctorDiagnostics.h"
 #include "GMPAudioDecoder.h"
 #include "GMPVideoDecoder.h"
 #include "MediaDataDecoderProxy.h"
 #include "MediaPrefs.h"
 #include "mozIGeckoMediaPluginService.h"
 #include "nsServiceManagerUtils.h"
+#include "mozilla/EMEUtils.h"
 #include "mozilla/StaticMutex.h"
 #include "gmp-audio-decode.h"
 #include "gmp-video-decode.h"
 #ifdef XP_WIN
 #include "WMFDecoderModule.h"
 #endif
 
 namespace mozilla {
@@ -98,17 +99,17 @@ GMPDecoderModule::DecoderNeedsConversion
 static bool
 HasGMPFor(const nsACString& aAPI,
           const nsACString& aCodec,
           const nsACString& aGMP)
 {
 #ifdef XP_WIN
   // gmp-clearkey uses WMF for decoding, so if we're using clearkey we must
   // verify that WMF works before continuing.
-  if (aGMP.EqualsLiteral("org.w3.clearkey")) {
+  if (aGMP.Equals(kEMEKeySystemClearkey)) {
     RefPtr<WMFDecoderModule> pdm(new WMFDecoderModule());
     if (aCodec.EqualsLiteral("aac") &&
         !pdm->SupportsMimeType(NS_LITERAL_CSTRING("audio/mp4a-latm"),
                                /* DecoderDoctorDiagnostics* */ nullptr)) {
       return false;
     }
     if (aCodec.EqualsLiteral("h264") &&
         !pdm->SupportsMimeType(NS_LITERAL_CSTRING("video/avc"),
@@ -138,19 +139,19 @@ StaticMutex sGMPCodecsMutex;
 
 struct GMPCodecs {
   const char* mKeySystem;
   bool mHasAAC;
   bool mHasH264;
 };
 
 static GMPCodecs sGMPCodecs[] = {
-  { "org.w3.clearkey", false, false },
-  { "com.adobe.primetime", false, false },
-  { "com.widevine.alpha", false, false },
+  { kEMEKeySystemClearkey, false, false },
+  { kEMEKeySystemWidevine, false, false },
+  { kEMEKeySystemPrimetime, false, false },
 };
 
 void
 GMPDecoderModule::UpdateUsableCodecs()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   StaticMutexAutoLock lock(sGMPCodecsMutex);
@@ -177,27 +178,27 @@ GMPDecoderModule::Init()
 
 /* static */
 const Maybe<nsCString>
 GMPDecoderModule::PreferredGMP(const nsACString& aMimeType)
 {
   Maybe<nsCString> rv;
   if (aMimeType.EqualsLiteral("audio/mp4a-latm")) {
     switch (MediaPrefs::GMPAACPreferred()) {
-      case 1: rv.emplace(NS_LITERAL_CSTRING("org.w3.clearkey")); break;
-      case 2: rv.emplace(NS_LITERAL_CSTRING("com.adobe.primetime")); break;
+      case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break;
+      case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break;
       default: break;
     }
   }
 
   if (aMimeType.EqualsLiteral("video/avc") ||
       aMimeType.EqualsLiteral("video/mp4")) {
     switch (MediaPrefs::GMPH264Preferred()) {
-      case 1: rv.emplace(NS_LITERAL_CSTRING("org.w3.clearkey")); break;
-      case 2: rv.emplace(NS_LITERAL_CSTRING("com.adobe.primetime")); break;
+      case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break;
+      case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break;
       default: break;
     }
   }
 
   return rv;
 }
 
 /* static */