Bug 1234492 - Part 2 - Use the role definition in nsIPresentationService, r=smaug

--HG--
extra : rebase_source : 3e04a5cb6e5a6f20730f6d0a4d45a376405aec66
This commit is contained in:
KuoE0 2016-04-18 02:23:00 +02:00
Родитель 846c1e60ec
Коммит f4bf3654a2
7 изменённых файлов: 26 добавлений и 37 удалений

Просмотреть файл

@ -20,7 +20,6 @@ const PRESENTATIONTRANSPORT_CONTRACTID = "mozilla.org/presentation/datachanneltr
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);
}
@ -41,7 +40,6 @@ PresentationDataChannelDescription.prototype = {
}
};
function PresentationTransportBuilder() {
log("PresentationTransportBuilder construct");
this._isControlChannelNeeded = true;
@ -54,8 +52,8 @@ PresentationTransportBuilder.prototype = {
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;
}
@ -65,8 +63,8 @@ PresentationTransportBuilder.prototype = {
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;
@ -81,7 +79,7 @@ PresentationTransportBuilder.prototype = {
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
@ -89,13 +87,13 @@ PresentationTransportBuilder.prototype = {
.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();
@ -133,7 +131,7 @@ PresentationTransportBuilder.prototype = {
_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
@ -168,7 +166,7 @@ PresentationTransportBuilder.prototype = {
this._peerConnection = null;
}
this._type = null;
this._role = null;
this._window = null;
if (this._controlChannel) {
@ -187,13 +185,13 @@ PresentationTransportBuilder.prototype = {
// 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));
@ -210,13 +208,13 @@ PresentationTransportBuilder.prototype = {
},
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));
@ -226,7 +224,7 @@ PresentationTransportBuilder.prototype = {
},
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));
},
@ -247,7 +245,6 @@ PresentationTransportBuilder.prototype = {
},
};
function PresentationTransport() {
this._messageQueue = [];
this._closeReason = Cr.NS_OK;
@ -287,7 +284,6 @@ PresentationTransport.prototype = {
this._callback.notifyData(aEvent.data);
};
this._dataChannel.onerror = aError => {
log("data channel onerror " + aError.name + ":" + aError.message);
if (this._callback) {

Просмотреть файл

@ -660,7 +660,7 @@ PresentationControllingInfo::NotifyOpened()
mBuilder = builder;
mTransportType = nsIPresentationChannelDescription::TYPE_DATACHANNEL;
return builder->BuildDataChannelTransport(nsIPresentationSessionTransportBuilder::TYPE_SENDER,
return builder->BuildDataChannelTransport(nsIPresentationService::ROLE_CONTROLLER,
GetWindow(),
mControlChannel,
this);
@ -874,7 +874,7 @@ PresentationPresentingInfo::InitTransportAndSendAnswer()
mBuilder = builder;
mTransportType = nsIPresentationChannelDescription::TYPE_DATACHANNEL;
rv = builder->BuildDataChannelTransport(nsIPresentationSessionTransportBuilder::TYPE_RECEIVER,
rv = builder->BuildDataChannelTransport(nsIPresentationService::ROLE_RECEIVER,
GetWindow(),
mControlChannel,
this);

Просмотреть файл

@ -107,7 +107,7 @@ PresentationTCPSessionTransport::BuildTCPSenderTransport(nsISocketTransport* aTr
return rv;
}
mType = nsIPresentationSessionTransportBuilder::TYPE_SENDER;
mRole = nsIPresentationService::ROLE_CONTROLLER;
nsCOMPtr<nsIPresentationSessionTransport> sessionTransport = do_QueryObject(this);
nsCOMPtr<nsIRunnable> onSessionTransportRunnable =
@ -118,7 +118,6 @@ PresentationTCPSessionTransport::BuildTCPSenderTransport(nsISocketTransport* aTr
NS_DispatchToCurrentThread(onSessionTransportRunnable);
nsCOMPtr<nsIRunnable> setReadyStateRunnable =
NS_NewRunnableMethodWithArgs<ReadyState>(this,
&PresentationTCPSessionTransport::SetReadyState,
@ -190,7 +189,7 @@ PresentationTCPSessionTransport::BuildTCPReceiverTransport(nsIPresentationChanne
return rv;
}
mType = nsIPresentationSessionTransportBuilder::TYPE_RECEIVER;
mRole = nsIPresentationService::ROLE_RECEIVER;
nsCOMPtr<nsIPresentationSessionTransport> sessionTransport = do_QueryObject(this);
nsCOMPtr<nsIRunnable> runnable =

Просмотреть файл

@ -85,7 +85,7 @@ private:
nsresult mCloseStatus;
bool mDataNotificationEnabled;
uint8_t mType = 0;
uint8_t mRole = 0;
// Raw socket streams
nsCOMPtr<nsISocketTransport> mTransport;

Просмотреть файл

@ -22,8 +22,6 @@ interface nsIPresentationSessionTransportBuilderListener : nsISupports
[scriptable, uuid(2fdbe67d-80f9-48dc-8237-5bef8fa19801)]
interface nsIPresentationSessionTransportBuilder : nsISupports
{
const unsigned short TYPE_SENDER = 1;
const unsigned short TYPE_RECEIVER = 2;
};
/**

Просмотреть файл

@ -230,7 +230,7 @@ const mockedSessionTransport = {
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);
@ -240,7 +240,7 @@ const mockedSessionTransport = {
},
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 = {
@ -256,10 +256,10 @@ const mockedSessionTransport = {
}, 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);

Просмотреть файл

@ -20,7 +20,6 @@
SimpleTest.waitForExplicitFinish();
const loadingTimeoutPref = "presentation.receiver.loading.timeout";
var clientBuilder;
@ -123,7 +122,6 @@ const serverCallback = {
},
};
const clientListener = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationSessionTransportBuilderListener]),
onSessionTransport: function(aTransport) {
@ -149,7 +147,6 @@ const serverListener = {
}
}
function testBuilder() {
return new Promise(function(aResolve, aReject) {
gResolve = aResolve;
@ -166,13 +163,13 @@ function testBuilder() {
.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);
@ -231,7 +228,6 @@ function runTests() {
.then(finish)
.catch(error);
}
window.addEventListener("load", function() {