Bug 1442294 - Downgrade global streaming indicator when a higher priority device has been disabled. r=florian draft
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 08 Mar 2018 14:08:21 +0100
changeset 764827 20668e90464a585421fd854462208f2a592301f8
parent 764770 a6a32fb286fa9e5d5f6d5b3b77423ab6b96c9502
push id101866
push userjhofmann@mozilla.com
push dateThu, 08 Mar 2018 13:09:08 +0000
reviewersflorian
bugs1442294
milestone60.0a1
Bug 1442294 - Downgrade global streaming indicator when a higher priority device has been disabled. r=florian MozReview-Commit-ID: 6GxXNsB6xYy
browser/base/content/test/webrtc/head.js
browser/modules/ContentWebRTC.jsm
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -470,16 +470,20 @@ async function checkSharingUI(aExpected,
 
   let doc = aWin.document;
   // First check the icon above the control center (i) icon.
   let identityBox = doc.getElementById("identity-box");
   ok(identityBox.hasAttribute("sharing"), "sharing attribute is set");
   let sharing = identityBox.getAttribute("sharing");
   if (aExpected.screen)
     is(sharing, "screen", "showing screen icon in the identity block");
+  else if (aExpected.video == STATE_CAPTURE_ENABLED)
+    is(sharing, "camera", "showing camera icon in the identity block");
+  else if (aExpected.audio == STATE_CAPTURE_ENABLED)
+    is(sharing, "microphone", "showing mic icon in the identity block");
   else if (aExpected.video)
     is(sharing, "camera", "showing camera icon in the identity block");
   else if (aExpected.audio)
     is(sharing, "microphone", "showing mic icon in the identity block");
 
   let allStreamsPaused = Object.values(aExpected).every(isPaused);
   is(identityBox.hasAttribute("paused"), allStreamsPaused,
      "sharing icon(s) should be in paused state when paused");
--- a/browser/modules/ContentWebRTC.jsm
+++ b/browser/modules/ContentWebRTC.jsm
@@ -379,30 +379,41 @@ function getTabStateForContentWindow(aCo
     tabState.screen = "ScreenPaused";
   else if (window.value == MediaManagerService.STATE_CAPTURE_DISABLED)
     tabState.screen = "WindowPaused";
   else if (app.value == MediaManagerService.STATE_CAPTURE_DISABLED)
     tabState.screen = "ApplicationPaused";
   else if (browser.value == MediaManagerService.STATE_CAPTURE_DISABLED)
     tabState.screen = "BrowserPaused";
 
-  if (tabState.screen) {
+  let screenEnabled = tabState.screen && !tabState.screen.includes("Paused");
+  let cameraEnabled = tabState.camera == MediaManagerService.STATE_CAPTURE_ENABLED;
+  let microphoneEnabled = tabState.microphone == MediaManagerService.STATE_CAPTURE_ENABLED;
+
+  // tabState.sharing controls which global indicator should be shown
+  // for the tab. It should always be set to the _enabled_ device which
+  // we consider most intrusive (screen > camera > microphone).
+  if (screenEnabled) {
+    tabState.sharing = "screen";
+  } else if (cameraEnabled) {
+    tabState.sharing = "camera";
+  } else if (microphoneEnabled) {
+    tabState.sharing = "microphone";
+  } else if (tabState.screen) {
     tabState.sharing = "screen";
   } else if (tabState.camera) {
     tabState.sharing = "camera";
   } else if (tabState.microphone) {
     tabState.sharing = "microphone";
   }
 
   // The stream is considered paused when we're sharing something
   // but all devices are off or set to disabled.
   tabState.paused = tabState.sharing &&
-    (!tabState.screen || tabState.screen.includes("Paused")) &&
-    tabState.camera != MediaManagerService.STATE_CAPTURE_ENABLED &&
-    tabState.microphone != MediaManagerService.STATE_CAPTURE_ENABLED;
+    !screenEnabled && !cameraEnabled && !microphoneEnabled;
 
   tabState.windowId = getInnerWindowIDForWindow(aContentWindow);
   tabState.documentURI = aContentWindow.document.documentURI;
 
   return tabState;
 }
 
 function getInnerWindowIDForWindow(aContentWindow) {