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.
denyGUMRequest({callID: aSubject.callID}, error);
},
aSubject.innerWindowID);
aSubject.innerWindowID,
aSubject.callID);
}
function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSecure) {

View File

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

View File

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

View File

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

View File

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

View File

@ -492,9 +492,10 @@ MediaPermissionManager::HandleRequest(RefPtr<dom::GetUserMediaRequest> &req)
{
nsString callID;
req->GetCallID(callID);
uint64_t innerWindowID = req->InnerWindowID();
nsCOMPtr<nsPIDOMWindow> innerWindow = static_cast<nsPIDOMWindow*>
(nsGlobalWindow::GetInnerWindowWithId(req->InnerWindowID()));
(nsGlobalWindow::GetInnerWindowWithId(innerWindowID));
if (!innerWindow) {
MOZ_ASSERT(false, "No inner window");
return NS_ERROR_FAILURE;
@ -509,7 +510,9 @@ MediaPermissionManager::HandleRequest(RefPtr<dom::GetUserMediaRequest> &req)
req->GetConstraints(constraints);
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);
return NS_OK;

View File

@ -408,7 +408,13 @@ partial interface Navigator {
// The originating innerWindowID is needed to
// avoid calling the callbacks if the window has
// 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

View File

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

View File

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