From da7974f079e71b77cbc10309827708aa73d0ff96 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Tue, 28 Apr 2015 18:29:57 +0300 Subject: [PATCH] Bug 1158868 - PeerConnection should not depend on navigator.onLine r=jesup --- dom/media/PeerConnection.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/dom/media/PeerConnection.js b/dom/media/PeerConnection.js index a3bd9cc09658..689e7ad66673 100644 --- a/dom/media/PeerConnection.js +++ b/dom/media/PeerConnection.js @@ -149,14 +149,18 @@ GlobalPCList.prototype = { this._networkdown = false; } } else if (topic == "network:app-offline-status-changed") { - // App just went offline. The subject also contains the appId, - // but navigator.onLine checks that for us - if (!this._networkdown && !this._win.navigator.onLine) { - for (let winId in this._list) { + // App changed offline status. The subject contains the appId for which + // we need to check the status + let appId = subject.QueryInterface(Ci.nsIAppOfflineInfo).appId; + let ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService); + for (let winId in this._list) { + if (appId != this._list[winId]._appId) { + continue; + } + if (ios.isAppOffline(appId)) { cleanupWinId(this._list, winId); } } - this._networkdown = !this._win.navigator.onLine; } else if (topic == "gmp-plugin-crash") { // a plugin crashed; if it's associated with any of our PCs, fire an // event to the DOM window @@ -324,7 +328,19 @@ RTCPeerConnection.prototype = { }); this._mustValidateRTCConfiguration(rtcConfig, "RTCPeerConnection constructor passed invalid RTCConfiguration"); - if (_globalPCList._networkdown || !this._win.navigator.onLine) { + + // Save the appId + this._appId = Cu.getWebIDLCallerPrincipal().appId; + + // Get the offline status for this appId + let appOffline = false; + if (this._appId != Ci.nsIScriptSecurityManager.NO_APP_ID && + this._appId != Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) { + let ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService); + appOffline = ios.isAppOffline(this._appId); + } + + if (_globalPCList._networkdown || appOffline) { throw new this._win.DOMException( "Can't create RTCPeerConnections when the network is down", "InvalidStateError");