Bug 1234492 - Part 2: Use the role definition in nsIPresentationService. r=smaug
☠☠ backed out by 18ff4b609573 ☠ ☠
authorKuoE0 <kuoe0.tw@gmail.com>
Mon, 18 Apr 2016 15:13:54 +0800
changeset 318493 ac0e65743b5d8b64d22d7676f9f652d0c54076ff
parent 318492 801cac365dd931fd04d02fcae3dc5bc0c966f323
child 318494 94ec70bf8c2297109611568159521fd8dfb3a98c
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1234492
milestone48.0a1
Bug 1234492 - Part 2: Use the role definition in nsIPresentationService. r=smaug
dom/presentation/PresentationDataChannelSessionTransport.js
dom/presentation/PresentationSessionInfo.cpp
dom/presentation/PresentationTCPSessionTransport.cpp
dom/presentation/PresentationTCPSessionTransport.h
dom/presentation/interfaces/nsIPresentationSessionTransportBuilder.idl
dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
--- a/dom/presentation/PresentationDataChannelSessionTransport.js
+++ b/dom/presentation/PresentationDataChannelSessionTransport.js
@@ -15,17 +15,16 @@ function log(aMsg) {
 }
 
 const PRESENTATIONTRANSPORT_CID = Components.ID("{dd2bbf2f-3399-4389-8f5f-d382afb8b2d6}");
 const PRESENTATIONTRANSPORT_CONTRACTID = "mozilla.org/presentation/datachanneltransport;1";
 
 const PRESENTATIONTRANSPORTBUILDER_CID = Components.ID("{215b2f62-46e2-4004-a3d1-6858e56c20f3}");
 const PRESENTATIONTRANSPORTBUILDER_CONTRACTID = "mozilla.org/presentation/datachanneltransportbuilder;1";
 
-
 function PresentationDataChannelDescription(aDataChannelSDP) {
   this._dataChannelSDP = JSON.stringify(aDataChannelSDP);
 }
 
 PresentationDataChannelDescription.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationChannelDescription]),
   get type() {
     return nsIPresentationChannelDescription.TYPE_DATACHANNEL;
@@ -36,71 +35,70 @@ PresentationDataChannelDescription.proto
   get tcpPort() {
     return null;
   },
   get dataChannelSDP() {
     return this._dataChannelSDP;
   }
 };
 
-
 function PresentationTransportBuilder() {
   log("PresentationTransportBuilder construct");
   this._isControlChannelNeeded = true;
 }
 
 PresentationTransportBuilder.prototype = {
   classID: PRESENTATIONTRANSPORTBUILDER_CID,
   contractID: PRESENTATIONTRANSPORTBUILDER_CONTRACTID,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationDataChannelSessionTransportBuilder,
                                          Ci.nsIPresentationControlChannelListener,
                                          Ci.nsITimerCallback]),
 
-  buildDataChannelTransport: function(aType, aWindow, aControlChannel, aListener) {
-    if (!aType || !aWindow || !aControlChannel || !aListener) {
+  buildDataChannelTransport: function(aRole, aWindow, aControlChannel, aListener) {
+    if (!aRole || !aWindow || !aControlChannel || !aListener) {
       log("buildDataChannelTransport with illegal parameters");
       throw Cr.NS_ERROR_ILLEGAL_VALUE;
     }
 
     if (this._window) {
       log("buildDataChannelTransport has started.");
       throw Cr.NS_ERROR_UNEXPECTED;
     }
 
-    log("buildDataChannelTransport with type " + aType);
-    this._type = aType;
+    log("buildDataChannelTransport with role " + aRole);
+    this._role = aRole;
     this._window = aWindow;
     this._controlChannel = aControlChannel.QueryInterface(Ci.nsIPresentationControlChannel);
     this._controlChannel.listener = this;
     this._listener = aListener.QueryInterface(Ci.nsIPresentationSessionTransportBuilderListener);
 
     // TODO bug 1227053 set iceServers from |nsIPresentationDevice|
     this._peerConnection = new this._window.RTCPeerConnection();
 
     // |this._controlChannel == null| will throw since the control channel is
     // abnormally closed.
     this._peerConnection.onicecandidate = aEvent => aEvent.candidate &&
       this._controlChannel.sendIceCandidate(JSON.stringify(aEvent.candidate));
 
     this._peerConnection.onnegotiationneeded = () => {
-      log("onnegotiationneeded with type " + this._type);
+      log("onnegotiationneeded with role " + this._role);
       this._peerConnection.createOffer()
           .then(aOffer => this._peerConnection.setLocalDescription(aOffer))
           .then(() => this._controlChannel
                           .sendOffer(new PresentationDataChannelDescription(this._peerConnection.localDescription)))
           .catch(e => this._reportError(e));
     }
 
-    switch (this._type) {
-      case Ci.nsIPresentationSessionTransportBuilder.TYPE_SENDER:
+    switch (this._role) {
+      case Ci.nsIPresentationService.ROLE_CONTROLLER:
         this._dataChannel = this._peerConnection.createDataChannel("presentationAPI");
         this._setDataChannel();
         break;
 
-      case Ci.nsIPresentationSessionTransportBuilder.TYPE_RECEIVER:
+      case Ci.nsIPresentationService.ROLE_RECEIVER:
         this._peerConnection.ondatachannel = aEvent => {
           this._dataChannel = aEvent.channel;
           this._setDataChannel();
         }
         break;
       default:
        throw Cr.NS_ERROR_ILLEGAL_VALUE;
     }
@@ -128,17 +126,17 @@ PresentationTransportBuilder.prototype =
 
   _reportError: function(aError) {
     log("report Error " + aError.name + ":" + aError.message);
     this._cleanup(Cr.NS_ERROR_FAILURE);
   },
 
   _setDataChannel: function() {
     this._dataChannel.onopen = () => {
-      log("data channel is open, notify the listener, type " + this._type);
+      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._peerConnection = this._dataChannel = null;
 
       this._listener.onSessionTransport(this._sessionTransport);
@@ -163,17 +161,17 @@ PresentationTransportBuilder.prototype =
       this._dataChannel = null;
     }
 
     if (this._peerConnection) {
       this._peerConnection.close();
       this._peerConnection = null;
     }
 
-    this._type = null;
+    this._role = null;
     this._window = null;
 
     if (this._controlChannel) {
       this._controlChannel.close(aReason);
       this._controlChannel = null;
     }
 
     this._listener = null;
@@ -182,56 +180,56 @@ PresentationTransportBuilder.prototype =
     if (this._timer) {
       this._timer.cancel();
       this._timer = null;
     }
   },
 
   // nsIPresentationControlChannelListener
   onOffer: function(aOffer) {
-    if (this._type !== Ci.nsIPresentationSessionTransportBuilder.TYPE_RECEIVER ||
+    if (this._role !== Ci.nsIPresentationService.ROLE_RECEIVER ||
           this._sessionTransport) {
       log("onOffer status error");
       this._cleanup(Cr.NS_ERROR_FAILURE);
     }
 
-    log("onOffer: " + aOffer.dataChannelSDP + " with type " + this._type);
+    log("onOffer: " + aOffer.dataChannelSDP + " with role " + this._role);
 
     let offer = new this._window
                         .RTCSessionDescription(JSON.parse(aOffer.dataChannelSDP));
 
     this._peerConnection.setRemoteDescription(offer)
         .then(() => this._peerConnection.signalingState == "stable" ||
                       this._peerConnection.createAnswer())
         .then(aAnswer => this._peerConnection.setLocalDescription(aAnswer))
         .then(() => {
           this._isControlChannelNeeded = false;
           this._controlChannel
               .sendAnswer(new PresentationDataChannelDescription(this._peerConnection.localDescription))
         }).catch(e => this._reportError(e));
   },
 
   onAnswer: function(aAnswer) {
-    if (this._type !== Ci.nsIPresentationSessionTransportBuilder.TYPE_SENDER ||
+    if (this._role !== Ci.nsIPresentationService.ROLE_CONTROLLER ||
           this._sessionTransport) {
       log("onAnswer status error");
       this._cleanup(Cr.NS_ERROR_FAILURE);
     }
 
-    log("onAnswer: " + aAnswer.dataChannelSDP + " with type " + this._type);
+    log("onAnswer: " + aAnswer.dataChannelSDP + " with role " + this._role);
 
     let answer = new this._window
                          .RTCSessionDescription(JSON.parse(aAnswer.dataChannelSDP));
 
     this._peerConnection.setRemoteDescription(answer).catch(e => this._reportError(e));
     this._isControlChannelNeeded = false;
   },
 
   onIceCandidate: function(aCandidate) {
-    log("onIceCandidate: " + aCandidate + " with type " + this._type);
+    log("onIceCandidate: " + aCandidate + " with role " + this._role);
     let candidate = new this._window.RTCIceCandidate(JSON.parse(aCandidate));
     this._peerConnection.addIceCandidate(candidate).catch(e => this._reportError(e));
   },
 
   notifyOpened: function() {
     log("notifyOpened, should be opened beforehand");
   },
 
@@ -242,17 +240,16 @@ PresentationTransportBuilder.prototype =
       this._cleanup(aReason);
     } else if (this._isControlChannelNeeded) {
       this._cleanup(Cr.NS_ERROR_FAILURE);
     }
     this._controlChannel = null;
   },
 };
 
-
 function PresentationTransport() {
   this._messageQueue = [];
   this._closeReason = Cr.NS_OK;
 }
 
 PresentationTransport.prototype = {
   classID: PRESENTATIONTRANSPORT_CID,
   contractID: PRESENTATIONTRANSPORT_CONTRACTID,
@@ -282,17 +279,16 @@ PresentationTransport.prototype = {
       if (!this._enableDataNotification || !this._callback) {
         log("queue message");
         this._messageQueue.push(aEvent.data);
         return;
       }
       this._callback.notifyData(aEvent.data);
     };
 
-
     this._dataChannel.onerror = aError => {
       log("data channel onerror " + aError.name + ":" + aError.message);
       if (this._callback) {
         this._callback.notifyTransportClosed(Cr.NS_ERROR_FAILURE);
       }
       this._cleanup();
     }
   },
--- a/dom/presentation/PresentationSessionInfo.cpp
+++ b/dom/presentation/PresentationSessionInfo.cpp
@@ -655,17 +655,17 @@ PresentationControllingInfo::NotifyOpene
 
   if (NS_WARN_IF(!builder)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   mBuilder = builder;
   mTransportType = nsIPresentationChannelDescription::TYPE_DATACHANNEL;
 
-  return builder->BuildDataChannelTransport(nsIPresentationSessionTransportBuilder::TYPE_SENDER,
+  return builder->BuildDataChannelTransport(nsIPresentationService::ROLE_CONTROLLER,
                                             GetWindow(),
                                             mControlChannel,
                                             this);
 
 }
 
 NS_IMETHODIMP
 PresentationControllingInfo::NotifyClosed(nsresult aReason)
@@ -869,17 +869,17 @@ PresentationPresentingInfo::InitTranspor
       do_CreateInstance("@mozilla.org/presentation/datachanneltransportbuilder;1");
 
     if (NS_WARN_IF(!builder)) {
       return NS_ERROR_NOT_AVAILABLE;
     }
 
     mBuilder = builder;
     mTransportType = nsIPresentationChannelDescription::TYPE_DATACHANNEL;
-    rv = builder->BuildDataChannelTransport(nsIPresentationSessionTransportBuilder::TYPE_RECEIVER,
+    rv = builder->BuildDataChannelTransport(nsIPresentationService::ROLE_RECEIVER,
                                             GetWindow(),
                                             mControlChannel,
                                             this);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // delegate |onOffer| to builder
--- a/dom/presentation/PresentationTCPSessionTransport.cpp
+++ b/dom/presentation/PresentationTCPSessionTransport.cpp
@@ -102,28 +102,27 @@ PresentationTCPSessionTransport::BuildTC
   }
   mListener = aListener;
 
   nsresult rv = CreateStream();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  mType = nsIPresentationSessionTransportBuilder::TYPE_SENDER;
+  mRole = nsIPresentationService::ROLE_CONTROLLER;
 
   nsCOMPtr<nsIPresentationSessionTransport> sessionTransport = do_QueryObject(this);
   nsCOMPtr<nsIRunnable> onSessionTransportRunnable =
     NS_NewRunnableMethodWithArgs
       <nsIPresentationSessionTransport*>(mListener,
                                          &nsIPresentationSessionTransportBuilderListener::OnSessionTransport,
                                          sessionTransport);
 
   NS_DispatchToCurrentThread(onSessionTransportRunnable);
 
-
   nsCOMPtr<nsIRunnable> setReadyStateRunnable =
     NS_NewRunnableMethodWithArgs<ReadyState>(this,
                                              &PresentationTCPSessionTransport::SetReadyState,
                                              ReadyState::OPEN);
   return NS_DispatchToCurrentThread(setReadyStateRunnable);
 }
 
 NS_IMETHODIMP
@@ -185,17 +184,17 @@ PresentationTCPSessionTransport::BuildTC
 
   mTransport->SetEventSink(this, mainThread);
 
   rv = CreateStream();
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  mType = nsIPresentationSessionTransportBuilder::TYPE_RECEIVER;
+  mRole = nsIPresentationService::ROLE_RECEIVER;
 
   nsCOMPtr<nsIPresentationSessionTransport> sessionTransport = do_QueryObject(this);
   nsCOMPtr<nsIRunnable> runnable =
     NS_NewRunnableMethodWithArgs
       <nsIPresentationSessionTransport*>(mListener,
                                          &nsIPresentationSessionTransportBuilderListener::OnSessionTransport,
                                          sessionTransport);
   return NS_DispatchToCurrentThread(runnable);
--- a/dom/presentation/PresentationTCPSessionTransport.h
+++ b/dom/presentation/PresentationTCPSessionTransport.h
@@ -80,17 +80,17 @@ private:
     return mDataNotificationEnabled && mReadyState == ReadyState::OPEN;
   }
 
   ReadyState mReadyState;
   bool mAsyncCopierActive;
   nsresult mCloseStatus;
   bool mDataNotificationEnabled;
 
-  uint8_t mType = 0;
+  uint8_t mRole = 0;
 
   // Raw socket streams
   nsCOMPtr<nsISocketTransport> mTransport;
   nsCOMPtr<nsIInputStream> mSocketInputStream;
   nsCOMPtr<nsIOutputStream> mSocketOutputStream;
 
   // Input stream machinery
   nsCOMPtr<nsIInputStreamPump> mInputStreamPump;
--- a/dom/presentation/interfaces/nsIPresentationSessionTransportBuilder.idl
+++ b/dom/presentation/interfaces/nsIPresentationSessionTransportBuilder.idl
@@ -17,18 +17,16 @@ interface nsIPresentationSessionTranspor
   void onSessionTransport(in nsIPresentationSessionTransport transport);
 
   void onError(in nsresult reason);
 };
 
 [scriptable, uuid(2fdbe67d-80f9-48dc-8237-5bef8fa19801)]
 interface nsIPresentationSessionTransportBuilder : nsISupports
 {
-  const unsigned short TYPE_SENDER = 1;
-  const unsigned short TYPE_RECEIVER = 2;
 };
 
 /**
  * Builder for TCP session transport
  */
 [scriptable, uuid(cde36d6e-f471-4262-a70d-f932a26b21d9)]
 interface nsIPresentationTCPSessionTransportBuilder : nsIPresentationSessionTransportBuilder
 {
--- a/dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
+++ b/dom/presentation/tests/mochitest/PresentationSessionChromeScript.js
@@ -222,46 +222,46 @@ const mockedSessionTransport = {
     return this._callback;
   },
   get selfAddress() {
     return this._selfAddress;
   },
   buildTCPSenderTransport: function(transport, listener) {
     sendAsyncMessage('data-transport-initialized');
     this._listener = listener;
-    this._type = Ci.nsIPresentationSessionTransportBuilder.TYPE_SENDER;
+    this._role = Ci.nsIPresentationService.ROLE_CONTROLLER;
 
     setTimeout(()=>{
       this._listener.onSessionTransport(this);
       this._listener = null;
       this.simulateTransportReady();
     }, 0);
   },
   buildTCPReceiverTransport: function(description, listener) {
     this._listener = listener;
-    this._type = Ci.nsIPresentationSessionTransportBuilder.TYPE_RECEIVER;
+    this._role = Ci.nsIPresentationService.ROLE_CONTROLLER;
 
     var addresses = description.QueryInterface(Ci.nsIPresentationChannelDescription).tcpAddress;
     this._selfAddress = {
       QueryInterface: XPCOMUtils.generateQI([Ci.nsINetAddr]),
       address: (addresses.length > 0) ?
                 addresses.queryElementAt(0, Ci.nsISupportsCString).data : "",
       port: description.QueryInterface(Ci.nsIPresentationChannelDescription).tcpPort,
     };
 
     setTimeout(()=>{
       this._listener.onSessionTransport(this);
       this._listener = null;
     }, 0);
   },
   // in-process case
-  buildDataChannelTransport: function(type, window, controlChannel, listener) {
+  buildDataChannelTransport: function(role, window, controlChannel, listener) {
     dump("build data channel transport\n");
     this._listener = listener;
-    this._type = type;
+    this._role = role;
 
     var hasNavigator = window ? (typeof window.navigator != "undefined") : false;
     sendAsyncMessage('check-navigator', hasNavigator);
 
     setTimeout(()=>{
       this._listener.onSessionTransport(this);
       this._listener = null;
       this.simulateTransportReady();
--- a/dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
+++ b/dom/presentation/tests/mochitest/test_presentation_datachannel_sessiontransport.html
@@ -15,17 +15,16 @@
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 "use strict";
 
 SimpleTest.waitForExplicitFinish();
 
-
 const loadingTimeoutPref = "presentation.receiver.loading.timeout";
 
 var clientBuilder;
 var serverBuilder;
 var clientTransport;
 var serverTransport;
 var clientControlChannel;
 var serverControlChannel;
@@ -118,17 +117,16 @@ const serverCallback = {
     }
   },
   notifyData: function(aData) {
     is(aData, clientMessage, "Server transport receives data.");
     gResolve()
   },
 };
 
-
 const clientListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationSessionTransportBuilderListener]),
   onSessionTransport: function(aTransport) {
     info("Client Transport is built.");
     clientTransport = aTransport;
     clientTransport.callback = clientCallback;
   },
   onError: function(aError)  {
@@ -144,40 +142,39 @@ const serverListener = {
     serverTransport.callback = serverCallback;
     serverTransport.enableDataNotification();
   },
   onError: function(aError)  {
     ok(false, "server's builder reports error " + aError);
   }
 }
 
-
 function testBuilder() {
   return new Promise(function(aResolve, aReject) {
     gResolve = aResolve;
     gReject = aReject;
 
     clientControlChannel = new TestControlChannel();
     serverControlChannel = new TestControlChannel();
     clientControlChannel.remote = serverControlChannel;
     serverControlChannel.remote = clientControlChannel;
 
     clientBuilder = Cc["@mozilla.org/presentation/datachanneltransportbuilder;1"]
                       .createInstance(Ci.nsIPresentationDataChannelSessionTransportBuilder);
     serverBuilder = Cc["@mozilla.org/presentation/datachanneltransportbuilder;1"]
                       .createInstance(Ci.nsIPresentationDataChannelSessionTransportBuilder);
 
     clientBuilder
-      .buildDataChannelTransport(Ci.nsIPresentationSessionTransportBuilder.TYPE_SENDER,
+      .buildDataChannelTransport(Ci.nsIPresentationService.ROLE_CONTROLLER,
                                  window,
                                  clientControlChannel,
                                  clientListener);
 
     serverBuilder
-      .buildDataChannelTransport(Ci.nsIPresentationSessionTransportBuilder.TYPE_RECEIVER,
+      .buildDataChannelTransport(Ci.nsIPresentationService.ROLE_RECEIVER,
                                  window,
                                  serverControlChannel,
                                  serverListener);
   });
 }
 
 function testClientSendMessage() {
   return new Promise(function(aResolve, aReject) {
@@ -226,17 +223,16 @@ function runTests() {
 
   testBuilder()
   .then(testClientSendMessage)
   .then(testServerSendMessage)
   .then(testCloseSessionTransport)
   .then(finish)
   .catch(error);
 
-
 }
 
 window.addEventListener("load", function() {
   runTests();
 });
 
 </script>
 </pre>