Bug 1314445 - Remove unused ParseKeySystem(). r=gerald draft
authorChris Pearce <cpearce@mozilla.com>
Wed, 02 Nov 2016 13:56:23 +1300
changeset 432840 aed95e2b024af6fa36f0da96f564966c8d7f3a7d
parent 432839 1a8356740cbb9d73f7d851cb82f8b71c0ca364c4
child 432841 9c9ddf6b2b9df845a2807186e8649684e9227ee3
push id34444
push usercpearce@mozilla.com
push dateWed, 02 Nov 2016 22:51:27 +0000
reviewersgerald
bugs1314445
milestone52.0a1
Bug 1314445 - Remove unused ParseKeySystem(). r=gerald MozReview-Commit-ID: KdIpvet73LR
dom/media/eme/EMEUtils.cpp
dom/media/eme/EMEUtils.h
dom/media/eme/MediaKeySystemAccessManager.cpp
dom/media/gtest/TestEME.cpp
dom/media/gtest/moz.build
--- a/dom/media/eme/EMEUtils.cpp
+++ b/dom/media/eme/EMEUtils.cpp
@@ -14,101 +14,16 @@ LogModule* GetEMELog() {
   return log;
 }
 
 LogModule* GetEMEVerboseLog() {
   static LazyLogModule log("EMEV");
   return log;
 }
 
-static bool
-ContainsOnlyDigits(const nsAString& aString)
-{
-  nsAString::const_iterator iter, end;
-  aString.BeginReading(iter);
-  aString.EndReading(end);
-  while (iter != end) {
-    char16_t ch = *iter;
-    if (ch < '0' || ch > '9') {
-      return false;
-    }
-    iter++;
-  }
-  return true;
-}
-
-static bool
-ParseKeySystem(const nsAString& aExpectedKeySystem,
-               const nsAString& aInputKeySystem,
-               int32_t& aOutCDMVersion)
-{
-  if (!StringBeginsWith(aInputKeySystem, aExpectedKeySystem)) {
-    return false;
-  }
-
-  if (aInputKeySystem.Length() > aExpectedKeySystem.Length() + 8) {
-    // Allow up to 8 bytes for the ".version" field. 8 bytes should
-    // be enough for any versioning scheme...
-    NS_WARNING("Input KeySystem including was suspiciously long");
-    return false;
-  }
-
-  const char16_t* versionStart = aInputKeySystem.BeginReading() + aExpectedKeySystem.Length();
-  const char16_t* end = aInputKeySystem.EndReading();
-  if (versionStart == end) {
-    // No version supplied with keysystem.
-    aOutCDMVersion = NO_CDM_VERSION;
-    return true;
-  }
-  if (*versionStart != '.') {
-    // version not in correct format.
-    NS_WARNING("EME keySystem version string not prefixed by '.'");
-    return false;
-  }
-  versionStart++;
-  const nsAutoString versionStr(Substring(versionStart, end));
-  if (!ContainsOnlyDigits(versionStr)) {
-    NS_WARNING("Non-digit character in EME keySystem string's version suffix");
-    return false;
-  }
-  nsresult rv;
-  int32_t version = versionStr.ToInteger(&rv);
-  if (NS_FAILED(rv) || version < 0) {
-    NS_WARNING("Invalid version in EME keySystem string");
-    return false;
-  }
-  aOutCDMVersion = version;
-
-  return true;
-}
-
-static const char16_t *const sKeySystems[] = {
-  u"org.w3.clearkey",
-  u"com.adobe.primetime",
-  u"com.widevine.alpha",
-};
-
-bool
-ParseKeySystem(const nsAString& aInputKeySystem,
-               nsAString& aOutKeySystem,
-               int32_t& aOutCDMVersion)
-{
-  for (const char16_t* keySystem : sKeySystems) {
-    int32_t minCDMVersion = NO_CDM_VERSION;
-    if (ParseKeySystem(nsDependentString(keySystem),
-                       aInputKeySystem,
-                       minCDMVersion)) {
-      aOutKeySystem = keySystem;
-      aOutCDMVersion = minCDMVersion;
-      return true;
-    }
-  }
-  return false;
-}
-
 ArrayData
 GetArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView)
 {
   MOZ_ASSERT(aBufferOrView.IsArrayBuffer() || aBufferOrView.IsArrayBufferView());
   if (aBufferOrView.IsArrayBuffer()) {
     const dom::ArrayBuffer& buffer = aBufferOrView.GetAsArrayBuffer();
     buffer.ComputeLengthAndData();
     return ArrayData(buffer.Data(), buffer.Length());
--- a/dom/media/eme/EMEUtils.h
+++ b/dom/media/eme/EMEUtils.h
@@ -32,36 +32,16 @@ class ArrayBufferViewOrArrayBuffer;
     #define EME_LOG(...)
   #endif
 
   #ifndef EME_VERBOSE_LOG
     #define EME_VERBOSE_LOG(...)
   #endif
 #endif
 
-#define NO_CDM_VERSION -1
-
-// Checks a keySystem string against a whitelist, and determines whether
-// the keySystem is in the whitelist, and extracts the requested minimum
-// CDM version.
-//
-// Format of EME keysystems:
-// com.domain.keysystem[.minVersionAsInt]
-// i.e. org.w3.clearkey, com.adobe.primetime.7
-//
-// Returns true if aKeySystem contains a valid keySystem which we support,
-// false otherwise.
-//
-// On success, aOutKeySystem contains the keySystem string stripped of the
-// min version number, and aOutMinCDMVersion contains the min version number
-// if present. If it was not present, aOutMinCDMVersion is NO_CDM_VERSION.
-bool ParseKeySystem(const nsAString& aKeySystem,
-                    nsAString& aOutKeySystem,
-                    int32_t& aOutMinCDMVersion);
-
 // Helper function to extract a copy of data coming in from JS in an
 // (ArrayBuffer or ArrayBufferView) IDL typed function argument.
 //
 // Only call this on a properly initialized ArrayBufferViewOrArrayBuffer.
 void
 CopyArrayBufferViewOrArrayBufferData(const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView,
                                      nsTArray<uint8_t>& aOutData);
 
--- a/dom/media/eme/MediaKeySystemAccessManager.cpp
+++ b/dom/media/eme/MediaKeySystemAccessManager.cpp
@@ -88,25 +88,24 @@ MediaKeySystemAccessManager::Request(Det
                           NS_LITERAL_CSTRING("Candidate MediaKeySystemConfigs is empty"));
     // Don't notify DecoderDoctor, as there's nothing we or the user can
     // do to fix this situation; the site is using the API wrong.
     return;
   }
 
   DecoderDoctorDiagnostics diagnostics;
 
-  // Parse keysystem, split it out into keySystem prefix, and version suffix.
-  nsAutoString keySystem;
-  int32_t minCdmVersion = NO_CDM_VERSION;
-  if (!ParseKeySystem(aKeySystem, keySystem, minCdmVersion)) {
+  // Ensure keysystem is supported.
+  if (!IsWidevineKeySystem(aKeySystem) &&
+      !IsClearkeyKeySystem(aKeySystem) &&
+      !IsPrimetimeKeySystem(aKeySystem)) {
     // Not to inform user, because nothing to do if the keySystem is not
     // supported.
     aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
-                          NS_LITERAL_CSTRING("Key system string is invalid,"
-                                             " or key system is unsupported"));
+                          NS_LITERAL_CSTRING("Key system is unsupported"));
     diagnostics.StoreMediaKeySystemAccess(mWindow->GetExtantDoc(),
                                           aKeySystem, false, __func__);
     return;
   }
 
   if (!MediaPrefs::EMEEnabled() && !IsClearkeyKeySystem(aKeySystem)) {
     // EME disabled by user, send notification to chrome so UI can inform user.
     // Clearkey is allowed even when EME is disabled because we want the pref
@@ -118,63 +117,63 @@ MediaKeySystemAccessManager::Request(Det
                           NS_LITERAL_CSTRING("EME has been preffed off"));
     diagnostics.StoreMediaKeySystemAccess(mWindow->GetExtantDoc(),
                                           aKeySystem, false, __func__);
     return;
   }
 
   nsAutoCString message;
   MediaKeySystemStatus status =
-    MediaKeySystemAccess::GetKeySystemStatus(keySystem, message);
+    MediaKeySystemAccess::GetKeySystemStatus(aKeySystem, message);
 
   nsPrintfCString msg("MediaKeySystemAccess::GetKeySystemStatus(%s) "
                       "result=%s msg='%s'",
-                      NS_ConvertUTF16toUTF8(keySystem).get(),
+                      NS_ConvertUTF16toUTF8(aKeySystem).get(),
                       MediaKeySystemStatusValues::strings[(size_t)status].value,
                       message.get());
   LogToBrowserConsole(NS_ConvertUTF8toUTF16(msg));
 
   if (status == MediaKeySystemStatus::Cdm_not_installed &&
-      (IsPrimetimeKeySystem(keySystem) || IsWidevineKeySystem(keySystem))) {
+      (IsPrimetimeKeySystem(aKeySystem) || IsWidevineKeySystem(aKeySystem))) {
     // 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 &&
         AwaitInstall(aPromise, aKeySystem, aConfigs)) {
       // Notify chrome that we're going to wait for the CDM to download/update.
       // Note: If we're re-trying, we don't re-send the notification,
       // as chrome is already displaying the "we can't play, updating"
       // notification.
-      MediaKeySystemAccess::NotifyObservers(mWindow, keySystem, status);
+      MediaKeySystemAccess::NotifyObservers(mWindow, aKeySystem, status);
     } else {
       // We waited or can't wait for an update and we still can't service
       // the request. Give up. Chrome will still be showing a "I can't play,
       // updating" notification.
       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) {
     // 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);
+    MediaKeySystemAccess::NotifyObservers(mWindow, aKeySystem, status);
     aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR, message);
     return;
   }
 
   MediaKeySystemConfiguration config;
-  if (MediaKeySystemAccess::GetSupportedConfig(keySystem, aConfigs, config, &diagnostics)) {
+  if (MediaKeySystemAccess::GetSupportedConfig(aKeySystem, aConfigs, config, &diagnostics)) {
     RefPtr<MediaKeySystemAccess> access(
       new MediaKeySystemAccess(mWindow, aKeySystem, config));
     aPromise->MaybeResolve(access);
     diagnostics.StoreMediaKeySystemAccess(mWindow->GetExtantDoc(),
                                           aKeySystem, true, __func__);
     return;
   }
   // Not to inform user, because nothing to do if the corresponding keySystem
deleted file mode 100644
--- a/dom/media/gtest/TestEME.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#include "gtest/gtest.h"
-#include "mozilla/EMEUtils.h"
-
-using namespace std;
-using namespace mozilla;
-
-struct ParseKeySystemTestCase {
-  const char16_t* mInputKeySystemString;
-  int32_t mOutCDMVersion;
-  bool mShouldPass;
-};
-
-const ParseKeySystemTestCase ParseKeySystemTests[] = {
-  {
-    u"org.w3.clearkey",
-    NO_CDM_VERSION,
-    true,
-  }, {
-    u"org.w3.clearkey.123",
-    123,
-    true,
-  }, {
-    u"org.w3.clearkey.-1",
-    NO_CDM_VERSION,
-    false,
-  }, {
-    u"org.w3.clearkey.NaN",
-    NO_CDM_VERSION,
-    false,
-  }, {
-    u"org.w3.clearkey.0",
-    0,
-    true,
-  }, {
-    u"org.w3.clearkey.123567890123567890123567890123567890123567890",
-    NO_CDM_VERSION,
-    false,
-  }, {
-    u"org.w3.clearkey.0.1",
-    NO_CDM_VERSION,
-    false,
-  }
-};
-
-TEST(EME, EMEParseKeySystem) {
-  const nsAutoString clearkey(u"org.w3.clearkey");
-  for (const ParseKeySystemTestCase& test : ParseKeySystemTests) {
-    nsAutoString keySystem;
-    int32_t version;
-    bool rv = ParseKeySystem(nsDependentString(test.mInputKeySystemString),
-                             keySystem,
-                             version);
-    EXPECT_EQ(rv, test.mShouldPass) << "parse should succeed if expected to";
-    if (!test.mShouldPass) {
-      continue;
-    }
-    EXPECT_TRUE(keySystem.Equals(clearkey)) << NS_ConvertUTF16toUTF8(keySystem).get(); //"should extract expected keysystem" << ;
-    EXPECT_EQ(test.mOutCDMVersion, version) << "should extract expected version";
-  }
-}
--- a/dom/media/gtest/moz.build
+++ b/dom/media/gtest/moz.build
@@ -2,17 +2,16 @@
 # vim: set filetype=python:
 # 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/.
 
 UNIFIED_SOURCES += [
     'MockMediaResource.cpp',
     'TestAudioCompactor.cpp',
-    'TestEME.cpp',
     'TestGMPCrossOrigin.cpp',
     'TestGMPRemoveAndDelete.cpp',
     'TestGMPUtils.cpp',
     'TestIntervalSet.cpp',
     'TestMediaDataDecoder.cpp',
     'TestMediaEventSource.cpp',
     'TestMediaFormatReader.cpp',
     'TestMozPromise.cpp',
@@ -54,17 +53,16 @@ TEST_HARNESS_FILES.gtest += [
     'test_case_1224363.vp8.ivf',
     'test_case_1224369.vp8.ivf',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 LOCAL_INCLUDES += [
     '/dom/media',
-    '/dom/media/eme',
     '/dom/media/encoder',
     '/dom/media/fmp4',
     '/dom/media/gmp',
     '/security/certverifier',
     '/security/pkix/include',
 ]
 
 FINAL_LIBRARY = 'xul-gtest'