diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media.js b/browser/base/content/test/webrtc/browser_devices_get_user_media.js index 7a6ee1988f56..cc6cdac6e788 100644 --- a/browser/base/content/test/webrtc/browser_devices_get_user_media.js +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media.js @@ -455,7 +455,7 @@ var gTests = [ ok(gIdentityHandler._identityPopup.hidden, "control center should be hidden"); if ("nsISystemStatusBar" in Ci) { let activeStreams = webrtcUI.getActiveStreams(true, false, false); - webrtcUI.showSharingDoorhanger(activeStreams[0]); + webrtcUI.showSharingDoorhanger(activeStreams[0], "Devices"); } else { let win = diff --git a/browser/base/content/webrtcIndicator.js b/browser/base/content/webrtcIndicator.js index a8bb64367c48..3016070313d7 100644 --- a/browser/base/content/webrtcIndicator.js +++ b/browser/base/content/webrtcIndicator.js @@ -88,15 +88,16 @@ function updateWindowAttr(attr, value) { function onPopupMenuShowing(event) { let popup = event.target; + let type = popup.getAttribute("type"); let activeStreams; - if (popup.getAttribute("type") == "Devices") + if (type == "Devices") activeStreams = webrtcUI.getActiveStreams(true, true, false); else activeStreams = webrtcUI.getActiveStreams(false, false, true); if (activeStreams.length == 1) { - webrtcUI.showSharingDoorhanger(activeStreams[0]); + webrtcUI.showSharingDoorhanger(activeStreams[0], type); event.preventDefault(); return; } @@ -117,7 +118,9 @@ function onPopupMenuHiding(event) { } function onPopupMenuCommand(event) { - webrtcUI.showSharingDoorhanger(event.target.stream); + let item = event.target; + webrtcUI.showSharingDoorhanger(item.stream, + item.parentNode.getAttribute("type")); } function onFirefoxButtonClick(event) { diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index 40b04af2910f..edba70982285 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -136,7 +136,7 @@ this.webrtcUI = { this._streams = this._streams.filter(stream => stream.browser != aBrowser); }, - showSharingDoorhanger: function(aActiveStream) { + showSharingDoorhanger: function(aActiveStream, aType) { let browserWindow = aActiveStream.browser.ownerGlobal; if (aActiveStream.tab) { browserWindow.gBrowser.selectedTab = aActiveStream.tab; @@ -697,7 +697,12 @@ function getGlobalIndicator() { .getService(Ci.nsISystemStatusBar), _command: function(aEvent) { - webrtcUI.showSharingDoorhanger(aEvent.target.stream); + let type = this.getAttribute("type"); + if (type == "Camera" || type == "Microphone") + type = "Devices"; + else if (type == "Window" || type == "Application" || type == "Browser") + type = "Screen"; + webrtcUI.showSharingDoorhanger(aEvent.target.stream, type); }, _popupShowing: function(aEvent) { @@ -730,6 +735,7 @@ function getGlobalIndicator() { menuitem = this.ownerDocument.createElement("menuitem"); menuitem.setAttribute("label", bundle.GetStringFromName("webrtcIndicator.controlSharing.menuitem")); + menuitem.setAttribute("type", type); menuitem.stream = stream; menuitem.addEventListener("command", indicator._command); @@ -751,6 +757,7 @@ function getGlobalIndicator() { labelId = "webrtcIndicator.controlSharingOn.menuitem"; label = stream.browser.contentTitle || stream.uri; item.setAttribute("label", bundle.formatStringFromName(labelId, [label], 1)); + item.setAttribute("type", type); item.stream = stream; item.addEventListener("command", indicator._command); this.appendChild(item); @@ -825,6 +832,17 @@ function onTabSharingMenuPopupShowing(e) { let menuitem = doc.createElement("menuitem"); menuitem.setAttribute("label", bundle.getFormattedString(stringName, [origin])); menuitem.stream = streamInfo; + + // We can only open 1 doorhanger at a time. Guessing that users would be + // most eager to control screen/window/app sharing, and only then + // camera/microphone sharing, in that (decreasing) order of priority. + let doorhangerType; + if ((/Screen|Window|Application/).test(stringName)) { + doorhangerType = "Screen"; + } else { + doorhangerType = "Devices"; + } + menuitem.setAttribute("doorhangertype", doorhangerType); menuitem.addEventListener("command", onTabSharingMenuPopupCommand); e.target.appendChild(menuitem); } @@ -836,7 +854,8 @@ function onTabSharingMenuPopupHiding(e) { } function onTabSharingMenuPopupCommand(e) { - webrtcUI.showSharingDoorhanger(e.target.stream); + let type = e.target.getAttribute("doorhangertype"); + webrtcUI.showSharingDoorhanger(e.target.stream, type); } function showOrCreateMenuForWindow(aWindow) {