Bug 1051855 - Window sharing indicator on the URL bar stays on after stream.stop has been called. r=Gijs, a=sledru
authorFlorian Quèze <florian@queze.net>
Thu, 14 Aug 2014 19:29:49 +0200
changeset 217602 c78e3dc81484fa9fe3764579499a14b38f361645
parent 217601 1373e74fff1ad05297ee0af525c9d11d5fde5ce3
child 217603 57cdea2c224d33d72cd3e2c5501f9cbf4db8dcb3
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, sledru
bugs1051855
milestone33.0a2
Bug 1051855 - Window sharing indicator on the URL bar stays on after stream.stop has been called. r=Gijs, a=sledru
browser/modules/webrtcUI.jsm
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -585,44 +585,41 @@ function updateIndicators() {
       webrtcUI.showCameraIndicator = true;
     if (microphone.value)
       webrtcUI.showMicrophoneIndicator = true;
     if (screen.value)
       webrtcUI.showScreenSharingIndicator = "Screen";
     else if (window.value && !webrtcUI.showScreenSharingIndicator)
       webrtcUI.showScreenSharingIndicator = "Window";
 
-    showBrowserSpecificIndicator(getBrowserForWindow(contentWindow));
+    updateBrowserSpecificIndicator(getBrowserForWindow(contentWindow));
   }
 
   if (webrtcUI.showGlobalIndicator) {
     if (!gIndicatorWindow)
       gIndicatorWindow = getGlobalIndicator();
     else
       gIndicatorWindow.updateIndicatorState();
   } else if (gIndicatorWindow) {
     gIndicatorWindow.close();
     gIndicatorWindow = null;
   }
 }
 
-function showBrowserSpecificIndicator(aBrowser) {
+function updateBrowserSpecificIndicator(aBrowser) {
   let camera = {}, microphone = {}, screen = {}, window = {};
   MediaManagerService.mediaCaptureWindowState(aBrowser.contentWindow,
                                               camera, microphone, screen, window);
   let captureState;
   if (camera.value && microphone.value) {
     captureState = "CameraAndMicrophone";
   } else if (camera.value) {
     captureState = "Camera";
   } else if (microphone.value) {
     captureState = "Microphone";
-  } 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 uri = aBrowser.contentWindow.document.documentURIObject;
   let windowId = aBrowser.contentWindow
                          .QueryInterface(Ci.nsIInterfaceRequestor)
@@ -671,20 +668,25 @@ function showBrowserSpecificIndicator(aB
   };
   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);
   }
+  else {
+    removeBrowserNotification(aBrowser,"webRTC-sharingDevices");
+  }
 
   // Now handle the screen sharing indicator.
-  if (!screen.value && !window.value)
+  if (!screen.value && !window.value) {
+    removeBrowserNotification(aBrowser,"webRTC-sharingScreen");
     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");
@@ -695,20 +697,19 @@ function showBrowserSpecificIndicator(aB
   // 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;
-  if (!PopupNotifications)
-    return;
+function removeBrowserNotification(aBrowser, aNotificationId) {
+  let win = aBrowser.ownerDocument.defaultView;
+  let notification =
+    win.PopupNotifications.getNotification(aNotificationId, aBrowser);
+  if (notification)
+    win.PopupNotifications.remove(notification);
+}
 
-  for (let notifId of ["webRTC-sharingDevices", "webRTC-sharingScreen"]) {
-    let notification = PopupNotifications.getNotification(notifId, browser);
-    if (notification)
-      PopupNotifications.remove(notification);
-  }
+function removeBrowserSpecificIndicator(aSubject, aTopic, aData) {
+  updateBrowserSpecificIndicator(getBrowserForWindowId(aData));
 }