Bug 861716 - ensure webrtcIndicator init() done before calling updateIndicatorState(). r?florian draft
authorMunro Chiang <mchiang@mozilla.com>
Fri, 09 Jun 2017 14:28:37 +0800
changeset 591879 143ebcba8fc028382d19d5a2623a767a4f90b3a2
parent 591878 40c0678135b2b6752eec7a91b20e9b752599f950
child 632650 7d722815d7066db8d5044258d8cdce6e35536e98
push id63201
push userbmo:mchiang@mozilla.com
push dateFri, 09 Jun 2017 17:11:11 +0000
reviewersflorian
bugs861716
milestone55.0a1
Bug 861716 - ensure webrtcIndicator init() done before calling updateIndicatorState(). r?florian MozReview-Commit-ID: F6lQyGr7AQa
browser/modules/webrtcUI.jsm
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -816,22 +816,30 @@ function prompt(aBrowser, aRequest) {
 function removePrompt(aBrowser, aCallId) {
   let chromeWin = aBrowser.ownerGlobal;
   let notification =
     chromeWin.PopupNotifications.getNotification("webRTC-shareDevices", aBrowser);
   if (notification && notification.callID == aCallId)
     notification.remove();
 }
 
+var gIndicatorWindowInited;
+
 function getGlobalIndicator() {
   if (AppConstants.platform != "macosx") {
+    gIndicatorWindowInited = false;
     const INDICATOR_CHROME_URI = "chrome://browser/content/webrtcIndicator.xul";
     const features = "chrome,dialog=yes,titlebar=no,popup=yes";
+    let win = Services.ww.openWindow(null, INDICATOR_CHROME_URI, "_blank", features, []);
 
-    return Services.ww.openWindow(null, INDICATOR_CHROME_URI, "_blank", features, []);
+    win.addEventListener("load", () => {
+      gIndicatorWindowInited = true;
+    }, {once: true});
+
+    return win;
   }
 
   let indicator = {
     _camera: null,
     _microphone: null,
     _screen: null,
 
     _hiddenDoc: Cc["@mozilla.org/appshell/appShellService;1"]
@@ -1020,16 +1028,24 @@ function showOrCreateMenuForWindow(aWind
 function maybeAddMenuIndicator(window) {
   if (webrtcUI.showGlobalIndicator) {
     showOrCreateMenuForWindow(window);
   }
 }
 
 var gIndicatorWindow = null;
 
+function updateIndicatorState() {
+  try {
+    gIndicatorWindow.updateIndicatorState();
+  } catch (err) {
+    Cu.reportError(`error in gIndicatorWindow.updateIndicatorState(): ${err.message}`);
+  }
+}
+
 function updateIndicators(data, target) {
   if (data) {
     // the global indicators specific to this process
     let indicators;
     if (webrtcUI.processIndicators.has(target)) {
       indicators = webrtcUI.processIndicators.get(target);
     } else {
       indicators = {};
@@ -1061,19 +1077,21 @@ function updateIndicators(data, target) 
       }
     }
   }
 
   if (webrtcUI.showGlobalIndicator) {
     if (!gIndicatorWindow) {
       gIndicatorWindow = getGlobalIndicator();
     } else {
-      try {
-        gIndicatorWindow.updateIndicatorState();
-      } catch (err) {
-        Cu.reportError(`error in gIndicatorWindow.updateIndicatorState(): ${err.message}`);
+      if (AppConstants.platform == "macosx" || gIndicatorWindowInited) {
+        updateIndicatorState();
+      } else {
+        gIndicatorWindow.addEventListener("load", () => {
+          updateIndicatorState();
+        }, {once: true});
       }
     }
   } else if (gIndicatorWindow) {
     gIndicatorWindow.close();
     gIndicatorWindow = null;
   }
 }