diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index 401445b46021..a5b8e32ad966 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -78,6 +78,12 @@ function handleRequest(aSubject, aTopic, aData) { prompt(browser, callID, params.audio, params.video, devices); }, function (error) { + // bug 827146 -- In the future, the UI should catch NO_DEVICES_FOUND + // and allow the user to plug in a device, instead of immediately failing. + let msg = Cc["@mozilla.org/supports-string;1"]. + createInstance(Ci.nsISupportsString); + msg.data = error; + Services.obs.notifyObservers(msg, "getUserMedia:response:deny", callID); Cu.reportError(error); } ); diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 65a6106b85b1..b370f91cc4ed 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -61,7 +61,7 @@ public: ErrorCallbackRunnable( already_AddRefed aSuccess, already_AddRefed aError, - const nsString& aErrorMsg, uint64_t aWindowID) + const nsAString& aErrorMsg, uint64_t aWindowID) : mSuccess(aSuccess) , mError(aError) , mErrorMsg(aErrorMsg) @@ -553,7 +553,7 @@ public: } nsresult - Denied() + Denied(const nsAString& aErrorMsg) { // We add a disabled listener to the StreamListeners array until accepted // If this was the only active MediaStream, remove the window from the list. @@ -561,7 +561,7 @@ public: // This is safe since we're on main-thread, and the window can only // be invalidated from the main-thread (see OnNavigation) nsCOMPtr error(mError); - error->OnError(NS_LITERAL_STRING("PERMISSION_DENIED")); + error->OnError(aErrorMsg); // Should happen *after* error runs for consistency, but may not matter nsRefPtr manager(MediaManager::GetInstance()); @@ -570,7 +570,7 @@ public: // This will re-check the window being alive on main-thread // Note: we must remove the listener on MainThread as well NS_DispatchToMainThread(new ErrorCallbackRunnable( - mSuccess, mError, NS_LITERAL_STRING("PERMISSION_DENIED"), mWindowID + mSuccess, mError, aErrorMsg, mWindowID )); // MUST happen after ErrorCallbackRunnable Run()s, as it checks the active window list @@ -1197,7 +1197,7 @@ MediaManager::Observe(nsISupports* aSubject, const char* aTopic, array->Count(&len); MOZ_ASSERT(len); if (!len) { - gUMRunnable->Denied(); // neither audio nor video were selected + gUMRunnable->Denied(NS_LITERAL_STRING("PERMISSION_DENIED")); // neither audio nor video were selected return NS_OK; } for (uint32_t i = 0; i < len; i++) { @@ -1225,6 +1225,16 @@ MediaManager::Observe(nsISupports* aSubject, const char* aTopic, } if (!strcmp(aTopic, "getUserMedia:response:deny")) { + nsString errorMessage(NS_LITERAL_STRING("PERMISSION_DENIED")); + + if (aSubject) { + nsCOMPtr msg(do_QueryInterface(aSubject)); + MOZ_ASSERT(msg); + msg->GetData(errorMessage); + if (errorMessage.IsEmpty()) + errorMessage.Assign(NS_LITERAL_STRING("UNKNOWN_ERROR")); + } + nsString key(aData); nsRefPtr runnable; if (!mActiveCallbacks.Get(key, getter_AddRefs(runnable))) { @@ -1234,7 +1244,7 @@ MediaManager::Observe(nsISupports* aSubject, const char* aTopic, GetUserMediaRunnable* gUMRunnable = static_cast(runnable.get()); - gUMRunnable->Denied(); + gUMRunnable->Denied(errorMessage); return NS_OK; }