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
--- 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!!!");
}
}