Bug 1632717 - r=jwalden
authorBryce Seager van Dyk <bvandyk@mozilla.com>
Wed, 29 Apr 2020 20:11:25 +0000
changeset 527711 bbf0b2e8dde29518d3bccb09ee64a9365e401387
parent 527710 5f9d51e4bd44828aeb63284ad42c469347848979
child 527712 b97ab5796dec6061b5689483ec2bc2371ba598f3
push id37368
push userbtara@mozilla.com
push dateFri, 01 May 2020 21:45:51 +0000
treeherdermozilla-central@0f9c5a59e45d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1632717
milestone77.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 1632717 - r=jwalden Differential Revision: https://phabricator.services.mozilla.com/D72476
dom/media/eme/EMEUtils.cpp
dom/media/eme/EMEUtils.h
dom/media/eme/MediaEncryptedEvent.cpp
dom/media/eme/MediaKeyMessageEvent.cpp
--- a/dom/media/eme/EMEUtils.cpp
+++ b/dom/media/eme/EMEUtils.cpp
@@ -1,15 +1,17 @@
 /* -*- 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 "mozilla/EMEUtils.h"
+
+#include "jsfriendapi.h"
 #include "mozilla/dom/UnionTypes.h"
 
 namespace mozilla {
 
 LogModule* GetEMELog() {
   static LazyLogModule log("EME");
   return log;
 }
@@ -18,40 +20,50 @@ LogModule* GetEMEVerboseLog() {
   static LazyLogModule log("EMEV");
   return log;
 }
 
 ArrayData GetArrayBufferViewOrArrayBufferData(
     const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView) {
   MOZ_ASSERT(aBufferOrView.IsArrayBuffer() ||
              aBufferOrView.IsArrayBufferView());
+  JS::AutoCheckCannotGC nogc;
   if (aBufferOrView.IsArrayBuffer()) {
     const dom::ArrayBuffer& buffer = aBufferOrView.GetAsArrayBuffer();
     buffer.ComputeState();
     return ArrayData(buffer.Data(), buffer.Length());
   } else if (aBufferOrView.IsArrayBufferView()) {
     const dom::ArrayBufferView& bufferview =
         aBufferOrView.GetAsArrayBufferView();
     bufferview.ComputeState();
     return ArrayData(bufferview.Data(), bufferview.Length());
   }
   return ArrayData(nullptr, 0);
 }
 
 void CopyArrayBufferViewOrArrayBufferData(
     const dom::ArrayBufferViewOrArrayBuffer& aBufferOrView,
     nsTArray<uint8_t>& aOutData) {
+  JS::AutoCheckCannotGC nogc;
   ArrayData data = GetArrayBufferViewOrArrayBufferData(aBufferOrView);
   aOutData.Clear();
   if (!data.IsValid()) {
     return;
   }
   aOutData.AppendElements(data.mData, data.mLength);
 }
 
+void CopyArrayBufferViewOrArrayBufferData(const dom::ArrayBuffer& aBuffer,
+                                          nsTArray<uint8_t>& aOutData) {
+  JS::AutoCheckCannotGC nogc;
+  aBuffer.ComputeState();
+  aOutData.Clear();
+  aOutData.AppendElements(aBuffer.Data(), aBuffer.Length());
+}
+
 bool IsClearkeyKeySystem(const nsAString& aKeySystem) {
   return aKeySystem.EqualsLiteral(EME_KEY_SYSTEM_CLEARKEY);
 }
 
 bool IsWidevineKeySystem(const nsAString& aKeySystem) {
   return aKeySystem.EqualsLiteral(EME_KEY_SYSTEM_WIDEVINE);
 }
 
--- a/dom/media/eme/EMEUtils.h
+++ b/dom/media/eme/EMEUtils.h
@@ -42,16 +42,20 @@ LogModule* GetEMEVerboseLog();
 // 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);
 
+// Overload for ArrayBuffer
+void CopyArrayBufferViewOrArrayBufferData(const dom::ArrayBuffer& aBufferOrView,
+                                          nsTArray<uint8_t>& aOutData);
+
 struct ArrayData {
   explicit ArrayData(const uint8_t* aData, size_t aLength)
       : mData(aData), mLength(aLength) {}
   const uint8_t* mData;
   const size_t mLength;
   bool IsValid() const { return mData != nullptr && mLength != 0; }
   bool operator==(const nsTArray<uint8_t>& aOther) const {
     return mLength == aOther.Length() &&
--- a/dom/media/eme/MediaEncryptedEvent.cpp
+++ b/dom/media/eme/MediaEncryptedEvent.cpp
@@ -73,18 +73,20 @@ already_AddRefed<MediaEncryptedEvent> Me
     const MediaKeyNeededEventInit& aEventInitDict, ErrorResult& aRv) {
   nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
   RefPtr<MediaEncryptedEvent> e = new MediaEncryptedEvent(owner);
   bool trusted = e->Init(owner);
   e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
   e->mInitDataType = aEventInitDict.mInitDataType;
   if (!aEventInitDict.mInitData.IsNull()) {
     const auto& a = aEventInitDict.mInitData.Value();
-    a.ComputeState();
-    e->mInitData = ArrayBuffer::Create(aGlobal.Context(), a.Length(), a.Data());
+    nsTArray<uint8_t> initData;
+    CopyArrayBufferViewOrArrayBufferData(a, initData);
+    e->mInitData = ArrayBuffer::Create(aGlobal.Context(), initData.Length(),
+                                       initData.Elements());
     if (!e->mInitData) {
       aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
       return nullptr;
     }
   }
   e->SetTrusted(trusted);
   return e.forget();
 }
--- a/dom/media/eme/MediaKeyMessageEvent.cpp
+++ b/dom/media/eme/MediaKeyMessageEvent.cpp
@@ -71,20 +71,20 @@ already_AddRefed<MediaKeyMessageEvent> M
 
 already_AddRefed<MediaKeyMessageEvent> MediaKeyMessageEvent::Constructor(
     const GlobalObject& aGlobal, const nsAString& aType,
     const MediaKeyMessageEventInit& aEventInitDict, ErrorResult& aRv) {
   nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
   RefPtr<MediaKeyMessageEvent> e = new MediaKeyMessageEvent(owner);
   bool trusted = e->Init(owner);
   e->InitEvent(aType, aEventInitDict.mBubbles, aEventInitDict.mCancelable);
-  aEventInitDict.mMessage.ComputeState();
-  e->mMessage =
-      ArrayBuffer::Create(aGlobal.Context(), aEventInitDict.mMessage.Length(),
-                          aEventInitDict.mMessage.Data());
+  nsTArray<uint8_t> initData;
+  CopyArrayBufferViewOrArrayBufferData(aEventInitDict.mMessage, initData);
+  e->mMessage = ArrayBuffer::Create(aGlobal.Context(), initData.Length(),
+                                    initData.Elements());
   if (!e->mMessage) {
     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     return nullptr;
   }
   e->mMessageType = aEventInitDict.mMessageType;
   e->SetTrusted(trusted);
   e->SetComposed(aEventInitDict.mComposed);
   return e.forget();