Bug 1114433 - location.reload() leaves behind dangling gUM permission prompt, r=felipe.

This commit is contained in:
Florian Quèze 2015-01-16 22:20:46 +01:00
parent 711bcb73a3
commit ae363b2565
2 changed files with 35 additions and 3 deletions

View File

@ -27,13 +27,21 @@ this.ContentWebRTC = {
Services.obs.addObserver(removeBrowserSpecificIndicator, "recording-window-ended", false);
},
// Called only for 'unload' to remove pending gUM prompts in reloaded frames.
handleEvent: function(aEvent) {
let contentWindow = aEvent.target.defaultView;
let mm = getMessageManagerForWindow(contentWindow);
for (let key of contentWindow.pendingGetUserMediaRequests.keys())
mm.sendAsyncMessage("webrtc:CancelRequest", key);
},
receiveMessage: function(aMessage) {
switch (aMessage.name) {
case "webrtc:Allow":
let callID = aMessage.data.callID;
let contentWindow = Services.wm.getOuterWindowWithId(aMessage.data.windowID);
let devices = contentWindow.pendingGetUserMediaRequests.get(callID);
contentWindow.pendingGetUserMediaRequests.delete(callID);
forgetRequest(contentWindow, callID);
let allowedDevices = Cc["@mozilla.org/supports-array;1"]
.createInstance(Ci.nsISupportsArray);
@ -112,8 +120,10 @@ function prompt(aContentWindow, aWindowID, aCallID, aConstraints, aDevices, aSec
return;
}
if (!aContentWindow.pendingGetUserMediaRequests)
if (!aContentWindow.pendingGetUserMediaRequests) {
aContentWindow.pendingGetUserMediaRequests = new Map();
aContentWindow.addEventListener("unload", ContentWebRTC);
}
aContentWindow.pendingGetUserMediaRequests.set(aCallID, devices);
let request = {
@ -143,9 +153,17 @@ function denyRequest(aData, aError) {
return;
let contentWindow = Services.wm.getOuterWindowWithId(aData.windowID);
if (contentWindow.pendingGetUserMediaRequests)
contentWindow.pendingGetUserMediaRequests.delete(aData.callID);
forgetRequest(contentWindow, aData.callID);
}
function forgetRequest(aContentWindow, aCallID) {
aContentWindow.pendingGetUserMediaRequests.delete(aCallID);
if (aContentWindow.pendingGetUserMediaRequests.size)
return;
aContentWindow.removeEventListener("unload", ContentWebRTC);
aContentWindow.pendingGetUserMediaRequests = null;
}
function updateIndicators() {
let contentWindowSupportsArray = MediaManagerService.activeMediaCaptureWindows;

View File

@ -28,6 +28,7 @@ this.webrtcUI = {
let mm = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
mm.addMessageListener("webrtc:Request", this);
mm.addMessageListener("webrtc:CancelRequest", this);
mm.addMessageListener("webrtc:UpdateBrowserIndicators", this);
},
@ -42,6 +43,7 @@ this.webrtcUI = {
let mm = Cc["@mozilla.org/globalmessagemanager;1"]
.getService(Ci.nsIMessageListenerManager);
mm.removeMessageListener("webrtc:Request", this);
mm.removeMessageListener("webrtc:CancelRequest", this);
mm.removeMessageListener("webrtc:UpdateBrowserIndicators", this);
},
@ -125,6 +127,9 @@ this.webrtcUI = {
case "webrtc:Request":
prompt(aMessage.target, aMessage.data);
break;
case "webrtc:CancelRequest":
removePrompt(aMessage.target, aMessage.data);
break;
case "webrtc:UpdatingIndicators":
webrtcUI._streams = [];
break;
@ -435,6 +440,15 @@ function prompt(aBrowser, aRequest) {
chromeWin.PopupNotifications.show(aBrowser, "webRTC-shareDevices", message,
anchorId, mainAction, secondaryActions,
options);
notification.callID = aRequest.callID;
}
function removePrompt(aBrowser, aCallId) {
let chromeWin = aBrowser.ownerDocument.defaultView;
let notification =
chromeWin.PopupNotifications.getNotification("webRTC-shareDevices", aBrowser);
if (notification && notification.callID == aCallId)
notification.remove();
}
function getGlobalIndicator() {