Bug 1037415 - remove existing webrtc indicator in the browser toolbar r=florian, a=sledru
authorTim Taubert <ttaubert@mozilla.com>
Wed, 23 Jul 2014 17:34:31 +0200
changeset 209240 1e62aaf2657bc3827c40c9adf36804c491a4e457
parent 209239 b5e67236050a369a20db6d98ba0fe6f242ed3b87
child 209241 f950b4da188706d626781426e6f8b5d0385d0071
push id6608
push userflorian@queze.net
push dateTue, 05 Aug 2014 14:18:56 +0000
treeherdermozilla-aurora@2597220a5926 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, sledru
bugs1037415
milestone33.0a2
Bug 1037415 - remove existing webrtc indicator in the browser toolbar r=florian, a=sledru
browser/base/content/browser-webrtcUI.js
browser/base/content/browser.js
browser/base/content/browser.xul
browser/base/content/popup-notifications.inc
browser/base/content/test/general/browser_devices_get_user_media.js
browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
browser/base/content/test/general/head.js
browser/components/customizableui/src/CustomizableUI.jsm
browser/modules/BrowserUITelemetry.jsm
browser/modules/webrtcUI.jsm
browser/themes/osx/browser.css
browser/themes/shared/browser.inc
browser/themes/shared/toolbarbuttons.inc.css
deleted file mode 100644
--- a/browser/base/content/browser-webrtcUI.js
+++ /dev/null
@@ -1,70 +0,0 @@
-# -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-let WebrtcIndicator = {
-  init: function () {
-    let temp = {};
-    Cu.import("resource:///modules/webrtcUI.jsm", temp);
-    this.UIModule = temp.webrtcUI;
-
-    this.updateButton();
-  },
-
-  get button() {
-    delete this.button;
-    return this.button = document.getElementById("webrtc-status-button");
-  },
-
-  updateButton: function () {
-    this.button.hidden = !this.UIModule.showGlobalIndicator;
-  },
-
-  fillPopup: function (aPopup) {
-    this._menuitemData = new WeakMap;
-    for (let streamData of this.UIModule.getActiveStreams(true, true, true)) {
-      let pageURI = Services.io.newURI(streamData.uri, null, null);
-      let menuitem = document.createElement("menuitem");
-      menuitem.setAttribute("class", "menuitem-iconic");
-      menuitem.setAttribute("label", streamData.browser.contentTitle || streamData.uri);
-      menuitem.setAttribute("tooltiptext", streamData.uri);
-      PlacesUtils.favicons.getFaviconURLForPage(pageURI, function (aURI) {
-        if (aURI) {
-          let iconURL = PlacesUtils.favicons.getFaviconLinkForIcon(aURI).spec;
-          menuitem.setAttribute("image", iconURL);
-        }
-      });
-
-      this._menuitemData.set(menuitem, streamData);
-
-      aPopup.appendChild(menuitem);
-    }
-  },
-
-  clearPopup: function (aPopup) {
-    while (aPopup.lastChild)
-      aPopup.removeChild(aPopup.lastChild);
-  },
-
-  menuCommand: function (aMenuitem) {
-    let streamData = this._menuitemData.get(aMenuitem);
-    if (!streamData)
-      return;
-
-    let browserWindow = streamData.browser.ownerDocument.defaultView;
-    if (streamData.tab) {
-      browserWindow.gBrowser.selectedTab = streamData.tab;
-    } else {
-      streamData.browser.focus();
-    }
-    browserWindow.focus();
-    let notif = PopupNotifications.getNotification("webRTC-sharingDevices",
-                                                   streamData.browser);
-    if (!notif) {
-      notif = PopupNotifications.getNotification("webRTC-sharingScreen",
-                                                 streamData.browser);
-    }
-    notif.reshow();
-  }
-}
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -155,16 +155,19 @@ XPCOMUtils.defineLazyModuleGetter(this, 
   "resource:///modules/SitePermissions.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "SessionStore",
   "resource:///modules/sessionstore/SessionStore.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "fxAccounts",
   "resource://gre/modules/FxAccounts.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "gWebRTCUI",
+  "resource:///modules/webrtcUI.jsm", "webrtcUI");
+
 #ifdef MOZ_CRASHREPORTER
 XPCOMUtils.defineLazyModuleGetter(this, "TabCrashReporter",
   "resource:///modules/TabCrashReporter.jsm");
 #endif
 
 let gInitialPages = [
   "about:blank",
   "about:newtab",
@@ -182,17 +185,16 @@ let gInitialPages = [
 #include browser-loop.js
 #include browser-places.js
 #include browser-plugins.js
 #include browser-safebrowsing.js
 #include browser-social.js
 #include browser-tabPreviews.js
 #include browser-tabview.js
 #include browser-thumbnails.js
-#include browser-webrtcUI.js
 #include browser-gestureSupport.js
 
 #ifdef MOZ_DATA_REPORTING
 #include browser-data-submission-info-bar.js
 #endif
 
 #ifdef MOZ_SERVICES_SYNC
 #include browser-syncui.js
@@ -1160,17 +1162,16 @@ var gBrowserInit = {
     gRemoteTabsUI.init();
 
     // Initialize the full zoom setting.
     // We do this before the session restore service gets initialized so we can
     // apply full zoom settings to tabs restored by the session restore service.
     FullZoom.init();
     PanelUI.init();
     LightweightThemeListener.init();
-    WebrtcIndicator.init();
 
 #ifdef MOZ_CRASHREPORTER
     if (gMultiProcessBrowser)
       TabCrashReporter.init();
 #endif
 
     if (mustLoadSidebar) {
       let sidebar = document.getElementById("sidebar");
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -664,17 +664,17 @@
            Should you need to add items to the toolbar here, make sure to also add them
            to the default placements of buttons in CustomizableUI.jsm, so the
            customization code doesn't get confused.
       -->
     <toolbar id="nav-bar" class="toolbar-primary chromeclass-toolbar"
              aria-label="&navbarCmd.label;"
              fullscreentoolbar="true" mode="icons" customizable="true"
              iconsize="small"
-             defaultset="urlbar-container,search-container,webrtc-status-button,bookmarks-menu-button,downloads-button,home-button,loop-call-button,social-share-button,social-toolbar-item"
+             defaultset="urlbar-container,search-container,bookmarks-menu-button,downloads-button,home-button,loop-call-button,social-share-button,social-toolbar-item"
              customizationtarget="nav-bar-customization-target"
              overflowable="true"
              overflowbutton="nav-bar-overflow-button"
              overflowtarget="widget-overflow-list"
              overflowpanel="widget-overflow"
              context="toolbar-context-menu">
 
       <hbox id="nav-bar-customization-target" flex="1">
@@ -783,29 +783,16 @@
 
         <toolbaritem id="search-container" title="&searchItem.title;"
                      align="center" class="chromeclass-toolbar-additional panel-wide-item"
                      cui-areatype="toolbar"
                      flex="100" persist="width" removable="true">
           <searchbar id="searchbar" flex="1"/>
         </toolbaritem>
 
-        <toolbarbutton id="webrtc-status-button"
-                       class="toolbarbutton-1 chromeclass-toolbar-additional"
-                       type="menu"
-                       hidden="true"
-                       orient="horizontal"
-                       label="&webrtcIndicatorButton.label;"
-                       tooltiptext="&webrtcIndicatorButton.tooltip;"
-                       overflows="false">
-          <menupopup onpopupshowing="WebrtcIndicator.fillPopup(this);"
-                     onpopuphiding="WebrtcIndicator.clearPopup(this);"
-                     oncommand="WebrtcIndicator.menuCommand(event.target);"/>
-        </toolbarbutton>
-
         <toolbarbutton id="bookmarks-menu-button"
                        class="toolbarbutton-1 chromeclass-toolbar-additional"
                        persist="class"
                        removable="true"
                        type="menu-button"
                        label="&bookmarksMenuButton.label;"
                        tooltip="dynamic-shortcut-tooltip"
                        anchor="dropmarker"
--- a/browser/base/content/popup-notifications.inc
+++ b/browser/base/content/popup-notifications.inc
@@ -20,17 +20,17 @@
       </popupnotificationcontent>
 
       <popupnotificationcontent id="webRTC-selectWindowOrScreen" orient="vertical">
         <separator class="thin"/>
         <label value="&getUserMedia.selectWindowOrScreen.label;"
                accesskey="&getUserMedia.selectWindowOrScreen.accesskey;"
                control="webRTC-selectWindow-menulist"/>
         <menulist id="webRTC-selectWindow-menulist"
-                  oncommand="WebrtcIndicator.UIModule.updateMainActionLabel(this);">
+                  oncommand="gWebRTCUI.updateMainActionLabel(this);">
           <menupopup id="webRTC-selectWindow-menupopup"/>
         </menulist>
         <description id="webRTC-all-windows-shared" hidden="true">&getUserMedia.allWindowsShared.message;</description>
       </popupnotificationcontent>
 
       <popupnotificationcontent id="webRTC-selectMicrophone" orient="vertical">
         <separator class="thin"/>
         <label value="&getUserMedia.selectMicrophone.label;"
--- a/browser/base/content/test/general/browser_devices_get_user_media.js
+++ b/browser/base/content/test/general/browser_devices_get_user_media.js
@@ -180,18 +180,17 @@ function closeStream(aAlreadyClosed) {
 
   if (!aAlreadyClosed)
     yield promiseObserverCalled("recording-device-events");
 
   yield promiseNoPopupNotification("webRTC-sharingDevices");
   if (!aAlreadyClosed)
     expectObserverCalled("recording-window-ended");
 
-  let statusButton = document.getElementById("webrtc-status-button");
-  ok(statusButton.hidden, "WebRTC status button hidden");
+  assertWebRTCIndicatorStatus(false);
 }
 
 function checkDeviceSelectors(aAudio, aVideo) {
   let micSelector = document.getElementById("webRTC-selectMicrophone");
   if (aAudio)
     ok(!micSelector.hidden, "microphone selector visible");
   else
     ok(micSelector.hidden, "microphone selector hidden");
@@ -200,28 +199,27 @@ function checkDeviceSelectors(aAudio, aV
   if (aVideo)
     ok(!cameraSelector.hidden, "camera selector visible");
   else
     ok(cameraSelector.hidden, "camera selector hidden");
 }
 
 function checkSharingUI() {
   yield promisePopupNotification("webRTC-sharingDevices");
-  let statusButton = document.getElementById("webrtc-status-button");
-  ok(!statusButton.hidden, "WebRTC status button visible");
+
+  assertWebRTCIndicatorStatus(true);
 }
 
 function checkNotSharing() {
   is(getMediaCaptureState(), "none", "expected nothing to be shared");
 
   ok(!PopupNotifications.getNotification("webRTC-sharingDevices"),
      "no webRTC-sharingDevices popup notification");
 
-  let statusButton = document.getElementById("webrtc-status-button");
-  ok(statusButton.hidden, "WebRTC status button hidden");
+  assertWebRTCIndicatorStatus(false);
 }
 
 let gTests = [
 
 {
   desc: "getUserMedia audio+video",
   run: function checkAudioVideo() {
     yield promisePopupNotificationShown("webRTC-shareDevices", () => {
--- a/browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
+++ b/browser/base/content/test/general/browser_devices_get_user_media_about_urls.js
@@ -117,18 +117,17 @@ function closeStream(aAlreadyClosed) {
 
   if (!aAlreadyClosed)
     yield promiseObserverCalled("recording-device-events");
 
   yield promiseNoPopupNotification("webRTC-sharingDevices");
   if (!aAlreadyClosed)
     expectObserverCalled("recording-window-ended");
 
-  let statusButton = document.getElementById("webrtc-status-button");
-  ok(statusButton.hidden, "WebRTC status button hidden");
+  assertWebRTCIndicatorStatus(false);
 }
 
 function loadPage(aUrl) {
   let deferred = Promise.defer();
 
   gTab.linkedBrowser.addEventListener("load", function onload() {
     gTab.linkedBrowser.removeEventListener("load", onload, true);
 
--- a/browser/base/content/test/general/head.js
+++ b/browser/base/content/test/general/head.js
@@ -506,8 +506,14 @@ function promiseTabLoadEvent(tab, url, e
     deferred.reject(new Error("Timed out while waiting for a '" + eventType + "'' event"));
   }, 30000);
 
   tab.linkedBrowser.addEventListener(eventType, handle, true, true);
   if (url)
     tab.linkedBrowser.loadURI(url);
   return deferred.promise;
 }
+
+function assertWebRTCIndicatorStatus(expected) {
+  let ui = Cu.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI;
+  let msg = "WebRTC indicator " + (expected ? "visible" : "hidden");
+  is(ui.showGlobalIndicator, expected, msg);
+}
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -197,17 +197,16 @@ let CustomizableUIInternal = {
 
     this.registerArea(CustomizableUI.AREA_NAVBAR, {
       legacy: true,
       type: CustomizableUI.TYPE_TOOLBAR,
       overflowable: true,
       defaultPlacements: [
         "urlbar-container",
         "search-container",
-        "webrtc-status-button",
         "bookmarks-menu-button",
         "downloads-button",
         "home-button",
         "loop-call-button",
         "social-share-button",
       ],
       defaultCollapsed: false,
     }, true);
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -43,17 +43,16 @@ XPCOMUtils.defineLazyGetter(this, "DEFAU
       "find-button",
       "preferences-button",
       "add-ons-button",
       "developer-button",
     ],
     "nav-bar": [
       "urlbar-container",
       "search-container",
-      "webrtc-status-button",
       "bookmarks-menu-button",
       "downloads-button",
       "home-button",
       "social-share-button",
     ],
     // It's true that toolbar-menubar is not visible
     // on OS X, but the XUL node is definitely present
     // in the document.
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -550,21 +550,16 @@ function getGlobalIndicator() {
 
 var gIndicatorWindow = null;
 
 function updateIndicators() {
   let contentWindowSupportsArray = MediaManagerService.activeMediaCaptureWindows;
   let count = contentWindowSupportsArray.Count();
 
   webrtcUI.showGlobalIndicator = count > 0;
-
-  let e = Services.wm.getEnumerator("navigator:browser");
-  while (e.hasMoreElements())
-    e.getNext().WebrtcIndicator.updateButton();
-
   webrtcUI.showCameraIndicator = false;
   webrtcUI.showMicrophoneIndicator = false;
   webrtcUI.showScreenSharingIndicator = "";
 
   for (let i = 0; i < count; ++i) {
     let contentWindow = contentWindowSupportsArray.GetElementAt(i);
     let camera = {}, microphone = {}, screen = {}, window = {};
     MediaManagerService.mediaCaptureWindowState(contentWindow, camera,
--- a/browser/themes/osx/browser.css
+++ b/browser/themes/osx/browser.css
@@ -770,20 +770,16 @@ toolbar .toolbarbutton-1 > .toolbarbutto
   #zoom-out-button@toolbarButtonPressed@ {
     -moz-image-region: rect(18px, 558px, 36px, 540px);
   }
 
   #zoom-in-button@toolbarButtonPressed@ {
     -moz-image-region: rect(18px, 576px, 36px, 558px);
   }
 
-  #webrtc-status-button@toolbarButtonPressed@ {
-    -moz-image-region: rect(18px, 594px, 36px, 576px);
-  }
-
   #nav-bar-overflow-button@toolbarButtonPressed@ {
     -moz-image-region: rect(18px, 612px, 36px, 594px);
   }
 
   #tabview-button@toolbarButtonPressed@ {
     -moz-image-region: rect(18px, 648px, 36px, 630px);
   }
 
@@ -1082,24 +1078,16 @@ toolbar .toolbarbutton-1 > .toolbarbutto
   #zoom-controls[cui-areatype="toolbar"] > #zoom-in-button {
     -moz-image-region: rect(0, 1152px, 36px, 1116px);
   }
 
   #zoom-controls[cui-areatype="toolbar"] > #zoom-in-button:hover:active:not([disabled="true"]) {
     -moz-image-region: rect(36px, 1152px, 72px, 1116px);
   }
 
-  #webrtc-status-button {
-    -moz-image-region: rect(0, 1188px, 36px, 1152px);
-  }
-
-  #webrtc-status-button:hover:active:not([disabled="true"]) {
-    -moz-image-region: rect(36px, 1188px, 72px, 1152px);
-  }
-
   #nav-bar-overflow-button {
     -moz-image-region: rect(0, 1224px, 36px, 1188px);
   }
 
   #nav-bar-overflow-button:hover:active:not([disabled="true"]) {
     -moz-image-region: rect(36px, 1224px, 72px, 1188px);
   }
 
--- a/browser/themes/shared/browser.inc
+++ b/browser/themes/shared/browser.inc
@@ -1,13 +1,13 @@
 %filter substitution
 
 % Note that zoom-reset-button is a bit different since it doesn't use an image and thus has the image with display: none.
 %define nestedButtons #zoom-out-button, #zoom-reset-button, #zoom-in-button, #cut-button, #copy-button, #paste-button
-%define primaryToolbarButtons #back-button, #forward-button, #home-button, #print-button, #downloads-button, #bookmarks-menu-button, #new-tab-button, #new-window-button, #fullscreen-button, #sync-button, #feed-button, #tabview-button, #webrtc-status-button, #social-share-button, #open-file-button, #find-button, #developer-button, #preferences-button, #privatebrowsing-button, #save-page-button, #switch-to-metro-button, #add-ons-button, #history-panelmenu, #nav-bar-overflow-button, #PanelUI-menu-button, #characterencoding-button, #email-link-button, #sidebar-button, @nestedButtons@, #e10s-button
+%define primaryToolbarButtons #back-button, #forward-button, #home-button, #print-button, #downloads-button, #bookmarks-menu-button, #new-tab-button, #new-window-button, #fullscreen-button, #sync-button, #feed-button, #tabview-button, #social-share-button, #open-file-button, #find-button, #developer-button, #preferences-button, #privatebrowsing-button, #save-page-button, #switch-to-metro-button, #add-ons-button, #history-panelmenu, #nav-bar-overflow-button, #PanelUI-menu-button, #characterencoding-button, #email-link-button, #sidebar-button, @nestedButtons@, #e10s-button
 
 %ifdef XP_MACOSX
 % Prior to 10.7 there wasn't a native fullscreen button so we use #restore-button to exit fullscreen
 % and want it to behave like other toolbar buttons.
 %define primaryToolbarButtons @primaryToolbarButtons@, #restore-button
 %endif
 
 %define inAnyPanel :-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true])
--- a/browser/themes/shared/toolbarbuttons.inc.css
+++ b/browser/themes/shared/toolbarbuttons.inc.css
@@ -143,20 +143,16 @@ toolbar[brighttext] #sync-button[status=
 #zoom-controls:not(@inAnyPanel@) > #zoom-out-button {
   -moz-image-region: rect(0, 558px, 18px, 540px);
 }
 
 #zoom-controls:not(@inAnyPanel@) > #zoom-in-button {
   -moz-image-region: rect(0, 576px, 18px, 558px);
 }
 
-#webrtc-status-button {
-  -moz-image-region: rect(0, 594px, 18px, 576px);
-}
-
 #nav-bar-overflow-button {
   -moz-image-region: rect(0, 612px, 18px, 594px);
 }
 
 #nav-bar-overflow-button:-moz-locale-dir(rtl) > .toolbarbutton-icon {
   transform: scaleX(-1);
 }