Bug 1313202 - Convert InvalidAccessErrors coming out of the Widevine CDM to TypeErrors like Chrome does. r?gerald draft
authorChris Pearce <cpearce@mozilla.com>
Thu, 27 Oct 2016 14:04:10 +1300
changeset 429984 445bd30414d5aa49f7424afff993aae8f8fe0ab5
parent 429983 35ce6986bdc7e486b757df53fc59a63fb97014c3
child 535103 7cdf8c142e53529d2d6607e763d29cba27fd3fe2
push id33714
push usercpearce@mozilla.com
push dateThu, 27 Oct 2016 01:09:28 +0000
reviewersgerald
bugs1313202
milestone52.0a1
Bug 1313202 - Convert InvalidAccessErrors coming out of the Widevine CDM to TypeErrors like Chrome does. r?gerald MozReview-Commit-ID: FEY08LZheTf
dom/media/gmp/GMPDecryptorParent.cpp
dom/media/gmp/GMPMessageUtils.h
dom/media/gmp/gmp-api/gmp-decryption.h
dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
--- a/dom/media/gmp/GMPDecryptorParent.cpp
+++ b/dom/media/gmp/GMPDecryptorParent.cpp
@@ -240,16 +240,17 @@ GMPExToNsresult(GMPDOMException aDomExce
     case kGMPInvalidStateError: return NS_ERROR_DOM_INVALID_STATE_ERR;
     case kGMPSyntaxError: return NS_ERROR_DOM_SYNTAX_ERR;
     case kGMPInvalidModificationError: return NS_ERROR_DOM_INVALID_MODIFICATION_ERR;
     case kGMPInvalidAccessError: return NS_ERROR_DOM_INVALID_ACCESS_ERR;
     case kGMPSecurityError: return NS_ERROR_DOM_SECURITY_ERR;
     case kGMPAbortError: return NS_ERROR_DOM_ABORT_ERR;
     case kGMPQuotaExceededError: return NS_ERROR_DOM_QUOTA_EXCEEDED_ERR;
     case kGMPTimeoutError: return NS_ERROR_DOM_TIMEOUT_ERR;
+    case kGMPTypeError: return NS_ERROR_DOM_TYPE_ERR;
     default: return NS_ERROR_DOM_UNKNOWN_ERR;
   }
 }
 
 bool
 GMPDecryptorParent::RecvRejectPromise(const uint32_t& aPromiseId,
                                       const GMPDOMException& aException,
                                       const nsCString& aMessage)
--- a/dom/media/gmp/GMPMessageUtils.h
+++ b/dom/media/gmp/GMPMessageUtils.h
@@ -29,16 +29,17 @@ struct GMPDomExceptionValidator {
       case kGMPInvalidStateError:
       case kGMPSyntaxError:
       case kGMPInvalidModificationError:
       case kGMPInvalidAccessError:
       case kGMPSecurityError:
       case kGMPAbortError:
       case kGMPQuotaExceededError:
       case kGMPTimeoutError:
+      case kGMPTypeError:
         return true;
       default:
         return false;
     }
   }
 };
 
 template <>
--- a/dom/media/gmp/gmp-api/gmp-decryption.h
+++ b/dom/media/gmp/gmp-api/gmp-decryption.h
@@ -74,17 +74,18 @@ enum GMPDOMException {
   kGMPNotSupportedError = 9,
   kGMPInvalidStateError = 11,
   kGMPSyntaxError = 12,
   kGMPInvalidModificationError = 13,
   kGMPInvalidAccessError = 15,
   kGMPSecurityError = 18,
   kGMPAbortError = 20,
   kGMPQuotaExceededError = 22,
-  kGMPTimeoutError = 23
+  kGMPTimeoutError = 23,
+  kGMPTypeError = 52
 };
 
 enum GMPSessionMessageType {
   kGMPLicenseRequest = 0,
   kGMPLicenseRenewal = 1,
   kGMPLicenseRelease = 2,
   kGMPIndividualizationRequest = 3,
   kGMPMessageInvalid = 4 // Must always be last.
--- a/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
+++ b/dom/media/gmp/widevine-adapter/WidevineDecryptor.cpp
@@ -316,17 +316,22 @@ WidevineDecryptor::OnResolvePromise(uint
 }
 
 static GMPDOMException
 ToGMPDOMException(cdm::Error aError)
 {
   switch (aError) {
     case kNotSupportedError: return kGMPNotSupportedError;
     case kInvalidStateError: return kGMPInvalidStateError;
-    case kInvalidAccessError: return kGMPInvalidAccessError;
+    case kInvalidAccessError:
+      // Note: Chrome converts kInvalidAccessError to TypeError, since the
+      // Chromium CDM API doesn't have a type error enum value. The EME spec
+      // requires TypeError in some places, so we do the same conversion.
+      // See bug 1313202.
+      return kGMPTypeError;
     case kQuotaExceededError: return kGMPQuotaExceededError;
     case kUnknownError: return kGMPInvalidModificationError; // Note: Unique placeholder.
     case kClientError: return kGMPAbortError; // Note: Unique placeholder.
     case kOutputError: return kGMPSecurityError; // Note: Unique placeholder.
   };
   return kGMPTimeoutError; // Note: Unique placeholder.
 }