Bug 1037405 - implement the screen sharing urlbar indicator, r=Gijs.

--HG--
extra : rebase_source : ae477beaae5553db887589bd5ce314fb2a63c2ef
This commit is contained in:
Florian Quèze 2014-07-18 12:14:29 +02:00
parent 2512f2c908
commit a99226a382
3 changed files with 66 additions and 22 deletions

View File

@ -59,7 +59,12 @@ let WebrtcIndicator = {
streamData.browser.focus();
}
browserWindow.focus();
PopupNotifications.getNotification("webRTC-sharingDevices",
streamData.browser).reshow();
let notif = PopupNotifications.getNotification("webRTC-sharingDevices",
streamData.browser);
if (!notif) {
notif = PopupNotifications.getNotification("webRTC-sharingScreen",
streamData.browser);
}
notif.reshow();
}
}

View File

@ -515,6 +515,8 @@ getUserMedia.never.accesskey = N
getUserMedia.sharingCamera.message2 = You are currently sharing your camera with this page.
getUserMedia.sharingMicrophone.message2 = You are currently sharing your microphone with this page.
getUserMedia.sharingCameraAndMicrophone.message2 = You are currently sharing your camera and microphone with this page.
getUserMedia.sharingScreen.message = You are currently sharing your screen with this page.
getUserMedia.sharingWindow.message = You are currently sharing a window with this page.
getUserMedia.continueSharing.label = Continue Sharing
getUserMedia.continueSharing.accesskey = C
getUserMedia.stopSharing.label = Stop Sharing

View File

@ -221,6 +221,8 @@ function prompt(aContentWindow, aCallID, aAudio, aVideo, aDevices, aSecure) {
let popupId = "Devices";
if (requestTypes.length == 1 && requestTypes[0] == "Microphone")
popupId = "Microphone";
if (requestTypes.indexOf("Screen") != -1)
popupId = "Screen";
PopupNotifications.panel.firstChild.setAttribute("popupid", "webRTC-share" + popupId);
}
@ -381,6 +383,8 @@ function prompt(aContentWindow, aCallID, aAudio, aVideo, aDevices, aSecure) {
let anchorId = "webRTC-shareDevices-notification-icon";
if (requestTypes.length == 1 && requestTypes[0] == "Microphone")
anchorId = "webRTC-shareMicrophone-notification-icon";
if (requestTypes.indexOf("Screen") != -1)
anchorId = "webRTC-shareScreen-notification-icon";
chromeWin.PopupNotifications.show(browser, "webRTC-shareDevices", message,
anchorId, mainAction, secondaryActions, options);
}
@ -398,18 +402,17 @@ function updateIndicators() {
}
function showBrowserSpecificIndicator(aBrowser) {
let hasVideo = {};
let hasAudio = {};
let camera = {}, microphone = {}, screen = {}, window = {};
MediaManagerService.mediaCaptureWindowState(aBrowser.contentWindow,
hasVideo, hasAudio);
camera, microphone, screen, window);
let captureState;
if (hasVideo.value && hasAudio.value) {
if (camera.value && microphone.value) {
captureState = "CameraAndMicrophone";
} else if (hasVideo.value) {
} else if (camera.value) {
captureState = "Camera";
} else if (hasAudio.value) {
} else if (microphone.value) {
captureState = "Microphone";
} else {
} else if (!screen.value && !window.value) {
Cu.reportError("showBrowserSpecificIndicator: got neither video nor audio access");
return;
}
@ -417,8 +420,6 @@ function showBrowserSpecificIndicator(aBrowser) {
let chromeWin = aBrowser.ownerDocument.defaultView;
let stringBundle = chromeWin.gNavigatorBundle;
let message = stringBundle.getString("getUserMedia.sharing" + captureState + ".message2");
let uri = aBrowser.contentWindow.document.documentURIObject;
let windowId = aBrowser.contentWindow
.QueryInterface(Ci.nsIInterfaceRequestor)
@ -435,14 +436,22 @@ function showBrowserSpecificIndicator(aBrowser) {
accessKey: stringBundle.getString("getUserMedia.stopSharing.accesskey"),
callback: function () {
let perms = Services.perms;
if (hasVideo.value &&
if (camera.value &&
perms.testExactPermission(uri, "camera") == perms.ALLOW_ACTION)
perms.remove(uri.host, "camera");
if (hasAudio.value &&
if (microphone.value &&
perms.testExactPermission(uri, "microphone") == perms.ALLOW_ACTION)
perms.remove(uri.host, "microphone");
Services.obs.notifyObservers(null, "getUserMedia:revoke", windowId);
// Performing an action from a notification removes it, but if the page
// uses screensharing and a device, we may have another notification to remove.
let outerWindowID = Services.wm.getCurrentInnerWindowWithId(windowId)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils)
.outerWindowID;
removeBrowserSpecificIndicator(null, null, outerWindowID);
}
}];
let options = {
@ -457,18 +466,46 @@ function showBrowserSpecificIndicator(aBrowser) {
return aTopic == "swapping";
}
};
let anchorId = captureState == "Microphone" ? "webRTC-sharingMicrophone-notification-icon"
: "webRTC-sharingDevices-notification-icon";
chromeWin.PopupNotifications.show(aBrowser, "webRTC-sharingDevices", message,
anchorId, mainAction, secondaryActions, options);
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);
}
// Now handle the screen sharing indicator.
if (!screen.value && !window.value)
return;
options = {
hideNotNow: true,
dismissed: true,
eventCallback: function(aTopic) {
if (aTopic == "shown") {
let PopupNotifications = this.browser.ownerDocument.defaultView.PopupNotifications;
PopupNotifications.panel.firstChild.setAttribute("popupid", "webRTC-sharingScreen");
}
return aTopic == "swapping";
}
};
// If we are sharing both a window and the screen, show 'Screen'.
let stringId = "getUserMedia.sharing" + (screen.value ? "Screen" : "Window") + ".message";
chromeWin.PopupNotifications.show(aBrowser, "webRTC-sharingScreen",
stringBundle.getString(stringId),
"webRTC-sharingScreen-notification-icon",
mainAction, secondaryActions, options);
}
function removeBrowserSpecificIndicator(aSubject, aTopic, aData) {
let browser = getBrowserForWindowId(aData);
let PopupNotifications = browser.ownerDocument.defaultView.PopupNotifications;
let notification = PopupNotifications &&
PopupNotifications.getNotification("webRTC-sharingDevices",
browser);
if (notification)
PopupNotifications.remove(notification);
if (!PopupNotifications)
return;
for (let notifId of ["webRTC-sharingDevices", "webRTC-sharingScreen"]) {
let notification = PopupNotifications.getNotification(notifId, browser);
if (notification)
PopupNotifications.remove(notification);
}
}