Bug 1107967 - 'Stop sharing' doesn't work on teared off tabs, r=felipe.
This commit is contained in:
@@ -70,6 +70,13 @@ this.webrtcUI = {
|
||||
});
|
||||
},
|
||||
|
||||
swapBrowserForNotification: function(aOldBrowser, aNewBrowser) {
|
||||
for (let stream of this._streams) {
|
||||
if (stream.browser == aOldBrowser)
|
||||
stream.browser = aNewBrowser;
|
||||
};
|
||||
},
|
||||
|
||||
showSharingDoorhanger: function(aActiveStream, aType) {
|
||||
let browserWindow = aActiveStream.browser.ownerDocument.defaultView;
|
||||
if (aActiveStream.tab) {
|
||||
@@ -184,6 +191,8 @@ function prompt(aBrowser, aRequest) {
|
||||
let string = stringBundle.getString("getUserMedia.shareSelectedDevices.label");
|
||||
mainLabel = PluralForm.get(requestTypes.length, string);
|
||||
}
|
||||
|
||||
let notification; // Used by action callbacks.
|
||||
let mainAction = {
|
||||
label: mainLabel,
|
||||
accessKey: stringBundle.getString("getUserMedia.shareSelectedDevices.accesskey"),
|
||||
@@ -198,7 +207,7 @@ function prompt(aBrowser, aRequest) {
|
||||
label: stringBundle.getString("getUserMedia.denyRequest.label"),
|
||||
accessKey: stringBundle.getString("getUserMedia.denyRequest.accesskey"),
|
||||
callback: function () {
|
||||
denyRequest(aBrowser, aRequest);
|
||||
denyRequest(notification.browser, aRequest);
|
||||
}
|
||||
}
|
||||
];
|
||||
@@ -208,7 +217,7 @@ function prompt(aBrowser, aRequest) {
|
||||
label: stringBundle.getString("getUserMedia.never.label"),
|
||||
accessKey: stringBundle.getString("getUserMedia.never.accesskey"),
|
||||
callback: function () {
|
||||
denyRequest(aBrowser, aRequest);
|
||||
denyRequest(notification.browser, aRequest);
|
||||
// Let someone save "Never" for http sites so that they can be stopped from
|
||||
// bothering you with doorhangers.
|
||||
let perms = Services.perms;
|
||||
@@ -282,10 +291,10 @@ function prompt(aBrowser, aRequest) {
|
||||
allowedDevices.push(videoDevices[0].deviceIndex);
|
||||
if (audioDevices.length && micPerm == perms.ALLOW_ACTION)
|
||||
allowedDevices.push(audioDevices[0].deviceIndex);
|
||||
aBrowser.messageManager.sendAsyncMessage("webrtc:Allow",
|
||||
{callID: aRequest.callID,
|
||||
windowID: aRequest.windowID,
|
||||
devices: allowedDevices});
|
||||
let mm = this.browser.messageManager;
|
||||
mm.sendAsyncMessage("webrtc:Allow", {callID: aRequest.callID,
|
||||
windowID: aRequest.windowID,
|
||||
devices: allowedDevices});
|
||||
this.remove();
|
||||
return true;
|
||||
}
|
||||
@@ -404,14 +413,14 @@ function prompt(aBrowser, aRequest) {
|
||||
}
|
||||
|
||||
if (!allowedDevices.length) {
|
||||
denyRequest(aBrowser, aRequest);
|
||||
denyRequest(notification.browser, aRequest);
|
||||
return;
|
||||
}
|
||||
|
||||
aBrowser.messageManager.sendAsyncMessage("webrtc:Allow",
|
||||
{callID: aRequest.callID,
|
||||
windowID: aRequest.windowID,
|
||||
devices: allowedDevices});
|
||||
let mm = notification.browser.messageManager
|
||||
mm.sendAsyncMessage("webrtc:Allow", {callID: aRequest.callID,
|
||||
windowID: aRequest.windowID,
|
||||
devices: allowedDevices});
|
||||
};
|
||||
return false;
|
||||
}
|
||||
@@ -422,8 +431,10 @@ function prompt(aBrowser, aRequest) {
|
||||
anchorId = "webRTC-shareMicrophone-notification-icon";
|
||||
if (requestTypes.indexOf("Screen") != -1)
|
||||
anchorId = "webRTC-shareScreen-notification-icon";
|
||||
chromeWin.PopupNotifications.show(aBrowser, "webRTC-shareDevices", message,
|
||||
anchorId, mainAction, secondaryActions, options);
|
||||
notification =
|
||||
chromeWin.PopupNotifications.show(aBrowser, "webRTC-shareDevices", message,
|
||||
anchorId, mainAction, secondaryActions,
|
||||
options);
|
||||
}
|
||||
|
||||
function getGlobalIndicator() {
|
||||
@@ -701,6 +712,7 @@ function updateBrowserSpecificIndicator(aBrowser, aState) {
|
||||
let stringBundle = chromeWin.gNavigatorBundle;
|
||||
|
||||
let windowId = aState.windowId;
|
||||
let notification; // Used by action callbacks.
|
||||
let mainAction = {
|
||||
label: stringBundle.getString("getUserMedia.continueSharing.label"),
|
||||
accessKey: stringBundle.getString("getUserMedia.continueSharing.accesskey"),
|
||||
@@ -721,27 +733,35 @@ function updateBrowserSpecificIndicator(aBrowser, aState) {
|
||||
perms.testExactPermission(uri, "microphone") == perms.ALLOW_ACTION)
|
||||
perms.remove(host, "microphone");
|
||||
|
||||
aBrowser.messageManager.sendAsyncMessage("webrtc:StopSharing", windowId);
|
||||
let mm = notification.browser.messageManager;
|
||||
mm.sendAsyncMessage("webrtc:StopSharing", windowId);
|
||||
}
|
||||
}];
|
||||
let options = {
|
||||
hideNotNow: true,
|
||||
dismissed: true,
|
||||
eventCallback: function(aTopic) {
|
||||
eventCallback: function(aTopic, aNewBrowser) {
|
||||
if (aTopic == "shown") {
|
||||
let PopupNotifications = this.browser.ownerDocument.defaultView.PopupNotifications;
|
||||
let popupId = captureState == "Microphone" ? "Microphone" : "Devices";
|
||||
PopupNotifications.panel.firstChild.setAttribute("popupid", "webRTC-sharing" + popupId);
|
||||
}
|
||||
return aTopic == "swapping";
|
||||
|
||||
if (aTopic == "swapping") {
|
||||
webrtcUI.swapBrowserForNotification(this.browser, aNewBrowser);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (captureState) {
|
||||
let anchorId = captureState == "Microphone" ? "webRTC-sharingMicrophone-notification-icon"
|
||||
: "webRTC-sharingDevices-notification-icon";
|
||||
let message = stringBundle.getString("getUserMedia.sharing" + captureState + ".message2");
|
||||
chromeWin.PopupNotifications.show(aBrowser, "webRTC-sharingDevices", message,
|
||||
anchorId, mainAction, secondaryActions, options);
|
||||
notification =
|
||||
chromeWin.PopupNotifications.show(aBrowser, "webRTC-sharingDevices", message,
|
||||
anchorId, mainAction, secondaryActions, options);
|
||||
}
|
||||
else {
|
||||
removeBrowserNotification(aBrowser,"webRTC-sharingDevices");
|
||||
@@ -753,31 +773,39 @@ function updateBrowserSpecificIndicator(aBrowser, aState) {
|
||||
return;
|
||||
}
|
||||
|
||||
let screenSharingNotif; // Used by action callbacks.
|
||||
options = {
|
||||
hideNotNow: true,
|
||||
dismissed: true,
|
||||
eventCallback: function(aTopic) {
|
||||
eventCallback: function(aTopic, aNewBrowser) {
|
||||
if (aTopic == "shown") {
|
||||
let PopupNotifications = this.browser.ownerDocument.defaultView.PopupNotifications;
|
||||
PopupNotifications.panel.firstChild.setAttribute("popupid", "webRTC-sharingScreen");
|
||||
}
|
||||
return aTopic == "swapping";
|
||||
|
||||
if (aTopic == "swapping") {
|
||||
webrtcUI.swapBrowserForNotification(this.browser, aNewBrowser);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
secondaryActions = [{
|
||||
label: stringBundle.getString("getUserMedia.stopSharing.label"),
|
||||
accessKey: stringBundle.getString("getUserMedia.stopSharing.accesskey"),
|
||||
callback: function () {
|
||||
aBrowser.messageManager.sendAsyncMessage("webrtc:StopSharing",
|
||||
"screen:" + windowId);
|
||||
let mm = screenSharingNotif.browser.messageManager;
|
||||
mm.sendAsyncMessage("webrtc:StopSharing", "screen:" + windowId);
|
||||
}
|
||||
}];
|
||||
// If we are sharing both a window and the screen, we show 'Screen'.
|
||||
let stringId = "getUserMedia.sharing" + aState.screen;
|
||||
chromeWin.PopupNotifications.show(aBrowser, "webRTC-sharingScreen",
|
||||
stringBundle.getString(stringId + ".message"),
|
||||
"webRTC-sharingScreen-notification-icon",
|
||||
mainAction, secondaryActions, options);
|
||||
screenSharingNotif =
|
||||
chromeWin.PopupNotifications.show(aBrowser, "webRTC-sharingScreen",
|
||||
stringBundle.getString(stringId + ".message"),
|
||||
"webRTC-sharingScreen-notification-icon",
|
||||
mainAction, secondaryActions, options);
|
||||
}
|
||||
|
||||
function removeBrowserNotification(aBrowser, aNotificationId) {
|
||||
|
||||
Reference in New Issue
Block a user