Bug 1268262: ignore callbacks after connection got established r=jib a=gchang
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Thu, 02 Feb 2017 13:17:51 -0800
changeset 376144 a7b005f337be2df0562726b811ccbeb9f1df8829
parent 376143 8bd8cdf859ca487996b0dce19fb31b30a1c14589
child 376145 7f88a549492704d04ae61d6219c08362e3b2c1ea
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib, gchang
bugs1268262
milestone53.0a2
Bug 1268262: ignore callbacks after connection got established r=jib a=gchang MozReview-Commit-ID: ELrapnbiPy2
dom/presentation/PresentationDataChannelSessionTransport.js
dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
--- a/dom/presentation/PresentationDataChannelSessionTransport.js
+++ b/dom/presentation/PresentationDataChannelSessionTransport.js
@@ -73,16 +73,20 @@ PresentationTransportBuilder.prototype =
 
     // |this._listener == null| will throw since the control channel is
     // abnormally closed.
     this._peerConnection.onicecandidate = aEvent => aEvent.candidate &&
       this._listener.sendIceCandidate(JSON.stringify(aEvent.candidate));
 
     this._peerConnection.onnegotiationneeded = () => {
       log("onnegotiationneeded with role " + this._role);
+      if (!this._peerConnection) {
+        log("ignoring negotiationneeded without PeerConnection");
+        return;
+      }
       this._peerConnection.createOffer()
           .then(aOffer => this._peerConnection.setLocalDescription(aOffer))
           .then(() => this._listener
                           .sendOffer(new PresentationDataChannelDescription(this._peerConnection.localDescription)))
           .catch(e => this._reportError(e));
     }
 
     switch (this._role) {
@@ -132,16 +136,18 @@ PresentationTransportBuilder.prototype =
   _setDataChannel: function() {
     this._dataChannel.onopen = () => {
       log("data channel is open, notify the listener, role " + this._role);
 
       // Handoff the ownership of _peerConnection and _dataChannel to
       // _sessionTransport
       this._sessionTransport = new PresentationTransport();
       this._sessionTransport.init(this._peerConnection, this._dataChannel, this._window);
+      this._peerConnection.onicecandidate = null;
+      this._peerConnection.onnegotiationneeded = null;
       this._peerConnection = this._dataChannel = null;
 
       this._listener.onSessionTransport(this._sessionTransport);
       this._sessionTransport.callback.notifyTransportReady();
 
       this._cleanup(Cr.NS_OK);
     };
 
@@ -215,16 +221,20 @@ PresentationTransportBuilder.prototype =
                          .RTCSessionDescription(JSON.parse(aAnswer.dataChannelSDP));
 
     this._peerConnection.setRemoteDescription(answer).catch(e => this._reportError(e));
     this._isControlChannelNeeded = false;
   },
 
   onIceCandidate: function(aCandidate) {
     log("onIceCandidate: " + aCandidate + " with role " + this._role);
+    if (!this._window || !this._peerConnection) {
+      log("ignoring ICE candidate after connection");
+      return;
+    }
     let candidate = new this._window.RTCIceCandidate(JSON.parse(aCandidate));
     this._peerConnection.addIceCandidate(candidate).catch(e => this._reportError(e));
   },
 
   notifyDisconnected: function(aReason) {
     log("notifyDisconnected reason: " + aReason);
 
     if (aReason != Cr.NS_OK) {
--- a/dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
+++ b/dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
@@ -215,16 +215,17 @@ function finish() {
   info("test finished, teardown");
   Services.prefs.clearUserPref(loadingTimeoutPref);
 
   SimpleTest.finish();
 }
 
 function error(aError) {
   ok(false, "report Error " + aError.name + ":" + aError.message);
+  gReject();
 }
 
 function runTests() {
   Services.prefs.setIntPref(loadingTimeoutPref, 30000);
 
   testBuilder()
   .then(testClientSendMessage)
   .then(testServerSendMessage)