Bug 1275856 - Fire MediaRecorderErrorEvent in media recorder. r?jib draft
authorBryce Van Dyk <bvandyk@mozilla.com>
Mon, 07 Aug 2017 09:48:42 +1200
changeset 643702 ef203841e683c02b798f2f1741aebb1267c0d5a8
parent 643701 d7b0ede6e3cb8763b6e07bad5c8abe570e74367c
child 643703 6beeb455c3abebb2fda04a6a6ee73de9d1c02e15
push id73193
push userbvandyk@mozilla.com
push dateThu, 10 Aug 2017 02:35:51 +0000
reviewersjib
bugs1275856
milestone57.0a1
Bug 1275856 - Fire MediaRecorderErrorEvent in media recorder. r?jib The MediaRecorder is current not behaving as per the spec in regards to async errors. The spec states that in such a scenario a MediaRecorderErrorEvent which wraps a DOMException should be fired. This changeset updates the recorder to do so. MozReview-Commit-ID: xt4ipCmbiu
dom/media/MediaRecorder.cpp
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -12,17 +12,17 @@
 #include "MediaDecoder.h"
 #include "MediaEncoder.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/AudioStreamTrack.h"
 #include "mozilla/dom/BlobEvent.h"
 #include "mozilla/dom/File.h"
-#include "mozilla/dom/RecordErrorEvent.h"
+#include "mozilla/dom/MediaRecorderErrorEvent.h"
 #include "mozilla/dom/VideoStreamTrack.h"
 #include "nsAutoPtr.h"
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include "nsIDocument.h"
 #include "nsIPermissionManager.h"
 #include "nsIPrincipal.h"
 #include "nsIScriptError.h"
@@ -1389,35 +1389,29 @@ MediaRecorder::DispatchSimpleEvent(const
 void
 MediaRecorder::NotifyError(nsresult aRv)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");
   nsresult rv = CheckInnerWindowCorrectness();
   if (NS_FAILED(rv)) {
     return;
   }
-  nsString errorMsg;
+  MediaRecorderErrorEventInit init;
+  init.mBubbles = false;
+  init.mCancelable = false;
   switch (aRv) {
-  case NS_ERROR_DOM_SECURITY_ERR:
-    errorMsg = NS_LITERAL_STRING("SecurityError");
-    break;
-  case NS_ERROR_OUT_OF_MEMORY:
-    errorMsg = NS_LITERAL_STRING("OutOfMemoryError");
-    break;
-  default:
-    errorMsg = NS_LITERAL_STRING("GenericError");
+    case NS_ERROR_DOM_SECURITY_ERR:
+      init.mError = DOMException::Create(aRv);
+      break;
+    default:
+      init.mError = DOMException::Create(NS_ERROR_DOM_UNKNOWN_ERR);
   }
 
-  RecordErrorEventInit init;
-  init.mBubbles = false;
-  init.mCancelable = false;
-  init.mName = errorMsg;
-
-  RefPtr<RecordErrorEvent> event =
-    RecordErrorEvent::Constructor(this, NS_LITERAL_STRING("error"), init);
+  RefPtr<MediaRecorderErrorEvent> event = MediaRecorderErrorEvent::Constructor(
+    this, NS_LITERAL_STRING("error"), init);
   event->SetTrusted(true);
 
   rv = DispatchDOMEvent(nullptr, event, nullptr, nullptr);
   if (NS_FAILED(rv)) {
     NS_ERROR("Failed to dispatch the error event!!!");
   }
 }