Bug 1224766 - forward callID to disambiguate multiple gUM requests from same window. r=jesup,smaug

--HG--
extra : rebase_source : 038e5b2eb6d2332da05c2c7dc44dc6ed3dde3d83
This commit is contained in:
Jan-Ivar Bruaroey 2016-01-07 17:30:10 -05:00
parent 7a3453ad7a
commit d7d3df857d
9 changed files with 33 additions and 14 deletions

View File

@ -138,7 +138,8 @@ function handleGUMRequest(aSubject, aTopic, aData) {
// and allow the user to plug in a device, instead of immediately failing. // and allow the user to plug in a device, instead of immediately failing.
denyGUMRequest({callID: aSubject.callID}, error); denyGUMRequest({callID: aSubject.callID}, error);
}, },
aSubject.innerWindowID); aSubject.innerWindowID,
aSubject.callID);
} }
function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSecure) { function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSecure) {

View File

@ -1394,6 +1394,7 @@ Navigator::MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
MozGetUserMediaDevicesSuccessCallback& aOnSuccess, MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
NavigatorUserMediaErrorCallback& aOnError, NavigatorUserMediaErrorCallback& aOnError,
uint64_t aInnerWindowID, uint64_t aInnerWindowID,
const nsAString& aCallID,
ErrorResult& aRv) ErrorResult& aRv)
{ {
CallbackObjectHolder<MozGetUserMediaDevicesSuccessCallback, CallbackObjectHolder<MozGetUserMediaDevicesSuccessCallback,
@ -1413,7 +1414,7 @@ Navigator::MozGetUserMediaDevices(const MediaStreamConstraints& aConstraints,
MediaManager* manager = MediaManager::Get(); MediaManager* manager = MediaManager::Get();
aRv = manager->GetUserMediaDevices(mWindow, aConstraints, onsuccess, onerror, aRv = manager->GetUserMediaDevices(mWindow, aConstraints, onsuccess, onerror,
aInnerWindowID); aInnerWindowID, aCallID);
} }
#endif #endif

View File

@ -297,6 +297,7 @@ public:
MozGetUserMediaDevicesSuccessCallback& aOnSuccess, MozGetUserMediaDevicesSuccessCallback& aOnSuccess,
NavigatorUserMediaErrorCallback& aOnError, NavigatorUserMediaErrorCallback& aOnError,
uint64_t aInnerWindowID, uint64_t aInnerWindowID,
const nsAString& aCallID,
ErrorResult& aRv); ErrorResult& aRv);
#endif // MOZ_MEDIA_NAVIGATOR #endif // MOZ_MEDIA_NAVIGATOR

View File

@ -2420,7 +2420,8 @@ MediaManager::GetUserMediaDevices(nsPIDOMWindow* aWindow,
const MediaStreamConstraints& aConstraints, const MediaStreamConstraints& aConstraints,
nsIGetUserMediaDevicesSuccessCallback* aOnSuccess, nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
nsIDOMGetUserMediaErrorCallback* aOnFailure, nsIDOMGetUserMediaErrorCallback* aOnFailure,
uint64_t aWindowId) uint64_t aWindowId,
const nsAString& aCallID)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onSuccess(aOnSuccess); nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onSuccess(aOnSuccess);
@ -2438,10 +2439,12 @@ MediaManager::GetUserMediaDevices(nsPIDOMWindow* aWindow,
for (auto& callID : *callIDs) { for (auto& callID : *callIDs) {
GetUserMediaTask* task; GetUserMediaTask* task;
if (mActiveCallbacks.Get(callID, &task)) { if (!aCallID.Length() || aCallID == callID) {
nsCOMPtr<nsIWritableVariant> array = MediaManager_ToJSArray(*task->mSourceSet); if (mActiveCallbacks.Get(callID, &task)) {
onSuccess->OnSuccess(array); nsCOMPtr<nsIWritableVariant> array = MediaManager_ToJSArray(*task->mSourceSet);
return NS_OK; onSuccess->OnSuccess(array);
return NS_OK;
}
} }
} }
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;

View File

@ -459,7 +459,8 @@ public:
const dom::MediaStreamConstraints& aConstraints, const dom::MediaStreamConstraints& aConstraints,
nsIGetUserMediaDevicesSuccessCallback* onSuccess, nsIGetUserMediaDevicesSuccessCallback* onSuccess,
nsIDOMGetUserMediaErrorCallback* onError, nsIDOMGetUserMediaErrorCallback* onError,
uint64_t aInnerWindowID = 0); uint64_t aInnerWindowID = 0,
const nsAString& aCallID = nsString());
nsresult EnumerateDevices(nsPIDOMWindow* aWindow, nsresult EnumerateDevices(nsPIDOMWindow* aWindow,
nsIGetUserMediaDevicesSuccessCallback* aOnSuccess, nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,

View File

@ -492,9 +492,10 @@ MediaPermissionManager::HandleRequest(RefPtr<dom::GetUserMediaRequest> &req)
{ {
nsString callID; nsString callID;
req->GetCallID(callID); req->GetCallID(callID);
uint64_t innerWindowID = req->InnerWindowID();
nsCOMPtr<nsPIDOMWindow> innerWindow = static_cast<nsPIDOMWindow*> nsCOMPtr<nsPIDOMWindow> innerWindow = static_cast<nsPIDOMWindow*>
(nsGlobalWindow::GetInnerWindowWithId(req->InnerWindowID())); (nsGlobalWindow::GetInnerWindowWithId(innerWindowID));
if (!innerWindow) { if (!innerWindow) {
MOZ_ASSERT(false, "No inner window"); MOZ_ASSERT(false, "No inner window");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -509,7 +510,9 @@ MediaPermissionManager::HandleRequest(RefPtr<dom::GetUserMediaRequest> &req)
req->GetConstraints(constraints); req->GetConstraints(constraints);
RefPtr<MediaManager> MediaMgr = MediaManager::GetInstance(); RefPtr<MediaManager> MediaMgr = MediaManager::GetInstance();
nsresult rv = MediaMgr->GetUserMediaDevices(innerWindow, constraints, onSuccess, onError); nsresult rv = MediaMgr->GetUserMediaDevices(innerWindow, constraints,
onSuccess, onError,
innerWindowID, callID);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return NS_OK; return NS_OK;

View File

@ -408,7 +408,13 @@ partial interface Navigator {
// The originating innerWindowID is needed to // The originating innerWindowID is needed to
// avoid calling the callbacks if the window has // avoid calling the callbacks if the window has
// navigated away. It is optional only as legacy. // navigated away. It is optional only as legacy.
optional unsigned long long innerWindowID = 0); optional unsigned long long innerWindowID = 0,
// The callID is needed in case of multiple
// concurrent requests to find the right one.
// It is optional only as legacy.
// TODO: Rewrite to not need this method anymore,
// now that devices are enumerated earlier.
optional DOMString callID = "");
}; };
#endif // MOZ_MEDIA_NAVIGATOR #endif // MOZ_MEDIA_NAVIGATOR

View File

@ -121,7 +121,8 @@ var WebrtcUI = {
function (error) { function (error) {
Cu.reportError(error); Cu.reportError(error);
}, },
aSubject.innerWindowID); aSubject.innerWindowID,
aSubject.callID);
}, },
getDeviceButtons: function(audioDevices, videoDevices, aCallID) { getDeviceButtons: function(audioDevices, videoDevices, aCallID) {

View File

@ -22,7 +22,7 @@ function handlePCRequest(aSubject, aTopic, aData) {
} }
function handleGumRequest(aSubject, aTopic, aData) { function handleGumRequest(aSubject, aTopic, aData) {
let { windowID, callID } = aSubject; let { windowID, innerWindowID, callID } = aSubject;
let constraints = aSubject.getConstraints(); let constraints = aSubject.getConstraints();
let contentWindow = Services.wm.getOuterWindowWithId(windowID); let contentWindow = Services.wm.getOuterWindowWithId(windowID);
@ -35,7 +35,9 @@ function handleGumRequest(aSubject, aTopic, aData) {
}, },
function (error) { function (error) {
denyRequest(callID, error); denyRequest(callID, error);
}); },
innerWindowID,
callID);
} }
function prompt(aWindow, aCallID, aAudioRequested, aVideoRequested, aDevices) { function prompt(aWindow, aCallID, aAudioRequested, aVideoRequested, aDevices) {