Bug 1037405 - implement the screen sharing urlbar indicator, r=Gijs.
authorFlorian Quèze <florian@queze.net>
Fri, 18 Jul 2014 12:14:29 +0200
changeset 216791 fce93bbebc7840a004a70f7ed6ac9864c0974e99
parent 216790 31ba153201ecd10cfa111c65fecc8e028ef97430
child 216792 b6dd8895df4808cd150ceed81bb90b6b0d542be0
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1037405
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1037405 - implement the screen sharing urlbar indicator, r=Gijs.
browser/base/content/browser-webrtcUI.js
browser/locales/en-US/chrome/browser/browser.properties
browser/modules/webrtcUI.jsm
--- a/browser/base/content/browser-webrtcUI.js
+++ b/browser/base/content/browser-webrtcUI.js
@@ -54,12 +54,17 @@ let WebrtcIndicator = {
 
     let browserWindow = streamData.browser.ownerDocument.defaultView;
     if (streamData.tab) {
       browserWindow.gBrowser.selectedTab = streamData.tab;
     } else {
       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();
   }
 }
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -510,16 +510,18 @@ getUserMedia.always.label = Always Share
 getUserMedia.always.accesskey = A
 getUserMedia.denyRequest.label = Don't Share
 getUserMedia.denyRequest.accesskey = D
 getUserMedia.never.label = Never Share
 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
 getUserMedia.stopSharing.accesskey = S
 
 # Mixed Content Blocker Doorhanger Notification
 # LOCALIZATION NOTE - %S is brandShortName
 mixedContentBlocked.message = %S has blocked content that isn't secure.
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -216,16 +216,18 @@ function prompt(aContentWindow, aCallID,
 
       let chromeDoc = this.browser.ownerDocument;
 
       if (aTopic == "shown") {
         let PopupNotifications = chromeDoc.defaultView.PopupNotifications;
         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);
       }
 
       if (aTopic != "showing")
         return false;
 
       // DENY_ACTION is handled immediately by MediaManager, but handling
       // of ALLOW_ACTION is delayed until the popupshowing event
@@ -376,16 +378,18 @@ function prompt(aContentWindow, aCallID,
       };
       return false;
     }
   };
 
   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);
 }
 
 function updateIndicators() {
   webrtcUI.showGlobalIndicator =
     MediaManagerService.activeMediaCaptureWindows.Count() > 0;
 
@@ -393,82 +397,115 @@ function updateIndicators() {
   while (e.hasMoreElements())
     e.getNext().WebrtcIndicator.updateButton();
 
   for (let {browser: browser} of webrtcUI.activeStreams)
     showBrowserSpecificIndicator(browser);
 }
 
 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;
   }
 
   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)
                          .getInterface(Ci.nsIDOMWindowUtils)
                          .currentInnerWindowID;
   let mainAction = {
     label: stringBundle.getString("getUserMedia.continueSharing.label"),
     accessKey: stringBundle.getString("getUserMedia.continueSharing.accesskey"),
     callback: function () {},
     dismiss: true
   };
   let secondaryActions = [{
     label: stringBundle.getString("getUserMedia.stopSharing.label"),
     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 = {
     hideNotNow: true,
     dismissed: true,
     eventCallback: function(aTopic) {
       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";
     }
   };
-  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);
+  }
 }