зеркало из https://github.com/mozilla/gecko-dev.git
Bug 777203 - Respond to requests by sending our response directly back to the manager instead of broadcasting the response everywhere. r=gwagner
--HG-- extra : rebase_source : 52636b4eaeebbfe331bd8a0a89ca1ce91d6414ba
This commit is contained in:
Родитель
de3319a962
Коммит
ebe791c890
|
@ -1878,30 +1878,33 @@ WifiWorker.prototype = {
|
||||||
this._mm.sendAsyncMessage("WifiManager:" + message, data);
|
this._mm.sendAsyncMessage("WifiManager:" + message, data);
|
||||||
},
|
},
|
||||||
|
|
||||||
_sendMessage: function(message, success, data, rid, mid) {
|
_sendMessage: function(message, success, data, msg) {
|
||||||
this._mm.sendAsyncMessage(message + (success ? ":OK" : ":NO"),
|
msg.manager.sendAsyncMessage(message + (success ? ":OK" : ":NO"),
|
||||||
{ data: data, rid: rid, mid: mid });
|
{ data: data, rid: msg.rid, mid: msg.mid });
|
||||||
},
|
},
|
||||||
|
|
||||||
receiveMessage: function MessageManager_receiveMessage(aMessage) {
|
receiveMessage: function MessageManager_receiveMessage(aMessage) {
|
||||||
let msg = aMessage.json;
|
let msg = aMessage.json || {};
|
||||||
|
msg.manager = aMessage.target.QueryInterface(Ci.nsIFrameMessageManager);
|
||||||
|
|
||||||
switch (aMessage.name) {
|
switch (aMessage.name) {
|
||||||
case "WifiManager:setEnabled":
|
case "WifiManager:setEnabled":
|
||||||
this.setWifiEnabled(msg.data, msg.rid, msg.mid);
|
this.setWifiEnabled(msg);
|
||||||
break;
|
break;
|
||||||
case "WifiManager:getNetworks":
|
case "WifiManager:getNetworks":
|
||||||
this.getNetworks(msg.rid, msg.mid);
|
this.getNetworks(msg);
|
||||||
break;
|
break;
|
||||||
case "WifiManager:associate":
|
case "WifiManager:associate":
|
||||||
this.associate(msg.data, msg.rid, msg.mid);
|
this.associate(msg);
|
||||||
break;
|
break;
|
||||||
case "WifiManager:forget":
|
case "WifiManager:forget":
|
||||||
this.forget(msg.data, msg.rid, msg.mid);
|
this.forget(msg);
|
||||||
break;
|
break;
|
||||||
case "WifiManager:wps":
|
case "WifiManager:wps":
|
||||||
this.wps(msg.data, msg.rid, msg.mid);
|
this.wps(msg);
|
||||||
break;
|
break;
|
||||||
case "WifiManager:getState": {
|
case "WifiManager:getState": {
|
||||||
|
// TODO add aMessage.target to our map of targets.
|
||||||
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
|
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
|
||||||
return { network: net,
|
return { network: net,
|
||||||
connectionInfo: this._lastConnectionInfo,
|
connectionInfo: this._lastConnectionInfo,
|
||||||
|
@ -1911,15 +1914,15 @@ WifiWorker.prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getNetworks: function(rid, mid) {
|
getNetworks: function(msg) {
|
||||||
const message = "WifiManager:getNetworks:Return";
|
const message = "WifiManager:getNetworks:Return";
|
||||||
if (WifiManager.state === "UNINITIALIZED") {
|
if (WifiManager.state === "UNINITIALIZED") {
|
||||||
this._sendMessage(message, false, "Wifi is disabled", rid, mid);
|
this._sendMessage(message, false, "Wifi is disabled", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.waitForScan((function (networks) {
|
this.waitForScan((function (networks) {
|
||||||
this._sendMessage(message, networks !== null, networks, rid, mid);
|
this._sendMessage(message, networks !== null, networks, msg);
|
||||||
}).bind(this));
|
}).bind(this));
|
||||||
WifiManager.scan(true, function() {});
|
WifiManager.scan(true, function() {});
|
||||||
},
|
},
|
||||||
|
@ -1934,7 +1937,7 @@ WifiWorker.prototype = {
|
||||||
do {
|
do {
|
||||||
let req = this._stateRequests.shift();
|
let req = this._stateRequests.shift();
|
||||||
this._sendMessage("WifiManager:setEnabled:Return",
|
this._sendMessage("WifiManager:setEnabled:Return",
|
||||||
success, state, req.rid, req.mid);
|
success, state, req);
|
||||||
|
|
||||||
// Don't remove more than one request if the previous one failed.
|
// Don't remove more than one request if the previous one failed.
|
||||||
} while (success &&
|
} while (success &&
|
||||||
|
@ -1974,23 +1977,25 @@ WifiWorker.prototype = {
|
||||||
WifiManager.start();
|
WifiManager.start();
|
||||||
},
|
},
|
||||||
|
|
||||||
setWifiEnabled: function(enable, rid, mid) {
|
setWifiEnabled: function(msg) {
|
||||||
// There are two problems that we're trying to solve here:
|
// There are two problems that we're trying to solve here:
|
||||||
// - If we get multiple requests to turn on and off wifi before the
|
// - If we get multiple requests to turn on and off wifi before the
|
||||||
// current request has finished, then we need to queue up the requests
|
// current request has finished, then we need to queue up the requests
|
||||||
// and handle each on/off request in turn.
|
// and handle each on/off request in turn.
|
||||||
// - Because we can't pass a callback to WifiManager.start, we need to
|
// - Because we can't pass a callback to WifiManager.start, we need to
|
||||||
// have a way to communicate with our onsupplicantconnection callback.
|
// have a way to communicate with our onsupplicantconnection callback.
|
||||||
this._stateRequests.push({ enabled: enable, rid: rid, mid: mid });
|
msg.enabled = msg.data;
|
||||||
|
this._stateRequests.push(msg);
|
||||||
if (this._stateRequests.length === 1)
|
if (this._stateRequests.length === 1)
|
||||||
WifiManager.setWifiEnabled(enable, this._setWifiEnabledCallback.bind(this));
|
WifiManager.setWifiEnabled(msg.enabled, this._setWifiEnabledCallback.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
associate: function(network, rid, mid) {
|
associate: function(msg) {
|
||||||
const MAX_PRIORITY = 9999;
|
const MAX_PRIORITY = 9999;
|
||||||
const message = "WifiManager:associate:Return";
|
const message = "WifiManager:associate:Return";
|
||||||
|
let network = msg.data;
|
||||||
if (WifiManager.state === "UNINITIALIZED") {
|
if (WifiManager.state === "UNINITIALIZED") {
|
||||||
this._sendMessage(message, false, "Wifi is disabled", rid, mid);
|
this._sendMessage(message, false, "Wifi is disabled", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2005,10 +2010,10 @@ WifiWorker.prototype = {
|
||||||
if (WifiManager.state === "DISCONNECTED" ||
|
if (WifiManager.state === "DISCONNECTED" ||
|
||||||
WifiManager.state === "SCANNING") {
|
WifiManager.state === "SCANNING") {
|
||||||
WifiManager.reconnect(function (ok) {
|
WifiManager.reconnect(function (ok) {
|
||||||
self._sendMessage(message, ok, ok, rid, mid);
|
self._sendMessage(message, ok, ok, msg);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self._sendMessage(message, ok, ok, rid, mid);
|
self._sendMessage(message, ok, ok, msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2032,7 +2037,7 @@ WifiWorker.prototype = {
|
||||||
privnet.netId = configured.netId;
|
privnet.netId = configured.netId;
|
||||||
WifiManager.updateNetwork(privnet, (function(ok) {
|
WifiManager.updateNetwork(privnet, (function(ok) {
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
this._sendMessage(message, false, "Network is misconfigured", rid, mid);
|
this._sendMessage(message, false, "Network is misconfigured", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2046,7 +2051,7 @@ WifiWorker.prototype = {
|
||||||
privnet.disabled = 0;
|
privnet.disabled = 0;
|
||||||
WifiManager.addNetwork(privnet, (function(ok) {
|
WifiManager.addNetwork(privnet, (function(ok) {
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
this._sendMessage(message, false, "Network is misconfigured", rid, mid);
|
this._sendMessage(message, false, "Network is misconfigured", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2056,16 +2061,17 @@ WifiWorker.prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
forget: function(network, rid, mid) {
|
forget: function(msg) {
|
||||||
const message = "WifiManager:forget:Return";
|
const message = "WifiManager:forget:Return";
|
||||||
|
let network = msg.data;
|
||||||
if (WifiManager.state === "UNINITIALIZED") {
|
if (WifiManager.state === "UNINITIALIZED") {
|
||||||
this._sendMessage(message, false, "Wifi is disabled", rid, mid);
|
this._sendMessage(message, false, "Wifi is disabled", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ssid = network.ssid;
|
let ssid = network.ssid;
|
||||||
if (!(ssid in this.configuredNetworks)) {
|
if (!(ssid in this.configuredNetworks)) {
|
||||||
this._sendMessage(message, false, "Trying to forget an unknown network", rid, mid);
|
this._sendMessage(message, false, "Trying to forget an unknown network", msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2075,46 +2081,47 @@ WifiWorker.prototype = {
|
||||||
(this.currentNetwork.ssid === ssid));
|
(this.currentNetwork.ssid === ssid));
|
||||||
WifiManager.removeNetwork(configured.netId, function(ok) {
|
WifiManager.removeNetwork(configured.netId, function(ok) {
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
self._sendMessage(message, false, "Unable to remove the network", rid, mid);
|
self._sendMessage(message, false, "Unable to remove the network", msg);
|
||||||
self._reconnectOnDisconnect = false;
|
self._reconnectOnDisconnect = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WifiManager.saveConfig(function() {
|
WifiManager.saveConfig(function() {
|
||||||
self._reloadConfiguredNetworks(function() {
|
self._reloadConfiguredNetworks(function() {
|
||||||
self._sendMessage(message, true, true, rid, mid);
|
self._sendMessage(message, true, true, msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
wps: function(detail, rid, mid) {
|
wps: function(msg) {
|
||||||
const message = "WifiManager:wps:Return";
|
const message = "WifiManager:wps:Return";
|
||||||
let self = this;
|
let self = this;
|
||||||
|
let detail = msg.data;
|
||||||
if (detail.method === "pbc") {
|
if (detail.method === "pbc") {
|
||||||
WifiManager.wpsPbc(function(ok) {
|
WifiManager.wpsPbc(function(ok) {
|
||||||
if (ok)
|
if (ok)
|
||||||
self._sendMessage(message, true, true, rid, mid);
|
self._sendMessage(message, true, true, msg);
|
||||||
else
|
else
|
||||||
self._sendMessage(message, false, "WPS PBC failed", rid, mid);
|
self._sendMessage(message, false, "WPS PBC failed", msg);
|
||||||
});
|
});
|
||||||
} else if (detail.method === "pin") {
|
} else if (detail.method === "pin") {
|
||||||
WifiManager.wpsPin(detail.pin, function(pin) {
|
WifiManager.wpsPin(detail.pin, function(pin) {
|
||||||
if (pin)
|
if (pin)
|
||||||
self._sendMessage(message, true, pin, rid, mid);
|
self._sendMessage(message, true, pin, msg);
|
||||||
else
|
else
|
||||||
self._sendMessage(message, false, "WPS PIN failed", rid, mid);
|
self._sendMessage(message, false, "WPS PIN failed", msg);
|
||||||
});
|
});
|
||||||
} else if (detail.method === "cancel") {
|
} else if (detail.method === "cancel") {
|
||||||
WifiManager.wpsCancel(function(ok) {
|
WifiManager.wpsCancel(function(ok) {
|
||||||
if (ok)
|
if (ok)
|
||||||
self._sendMessage(message, true, true, rid, mid);
|
self._sendMessage(message, true, true, msg);
|
||||||
else
|
else
|
||||||
self._sendMessage(message, false, "WPS Cancel failed", rid, mid);
|
self._sendMessage(message, false, "WPS Cancel failed", msg);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self._sendMessage(message, false, "Invalid WPS method=" + detail.method,
|
self._sendMessage(message, false, "Invalid WPS method=" + detail.method,
|
||||||
rid, mid);
|
msg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче