Bug 861716 - ensure webrtcIndicator init() done before calling updateIndicatorState(). r?florian
MozReview-Commit-ID: F6lQyGr7AQa
--- 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;
}
}