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:
Blake Kaplan 2012-08-22 11:34:42 -07:00
Родитель de3319a962
Коммит ebe791c890
1 изменённых файлов: 42 добавлений и 35 удалений

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

@ -1878,30 +1878,33 @@ WifiWorker.prototype = {
this._mm.sendAsyncMessage("WifiManager:" + message, data);
},
_sendMessage: function(message, success, data, rid, mid) {
this._mm.sendAsyncMessage(message + (success ? ":OK" : ":NO"),
{ data: data, rid: rid, mid: mid });
_sendMessage: function(message, success, data, msg) {
msg.manager.sendAsyncMessage(message + (success ? ":OK" : ":NO"),
{ data: data, rid: msg.rid, mid: msg.mid });
},
receiveMessage: function MessageManager_receiveMessage(aMessage) {
let msg = aMessage.json;
let msg = aMessage.json || {};
msg.manager = aMessage.target.QueryInterface(Ci.nsIFrameMessageManager);
switch (aMessage.name) {
case "WifiManager:setEnabled":
this.setWifiEnabled(msg.data, msg.rid, msg.mid);
this.setWifiEnabled(msg);
break;
case "WifiManager:getNetworks":
this.getNetworks(msg.rid, msg.mid);
this.getNetworks(msg);
break;
case "WifiManager:associate":
this.associate(msg.data, msg.rid, msg.mid);
this.associate(msg);
break;
case "WifiManager:forget":
this.forget(msg.data, msg.rid, msg.mid);
this.forget(msg);
break;
case "WifiManager:wps":
this.wps(msg.data, msg.rid, msg.mid);
this.wps(msg);
break;
case "WifiManager:getState": {
// TODO add aMessage.target to our map of targets.
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
return { network: net,
connectionInfo: this._lastConnectionInfo,
@ -1911,15 +1914,15 @@ WifiWorker.prototype = {
}
},
getNetworks: function(rid, mid) {
getNetworks: function(msg) {
const message = "WifiManager:getNetworks:Return";
if (WifiManager.state === "UNINITIALIZED") {
this._sendMessage(message, false, "Wifi is disabled", rid, mid);
this._sendMessage(message, false, "Wifi is disabled", msg);
return;
}
this.waitForScan((function (networks) {
this._sendMessage(message, networks !== null, networks, rid, mid);
this._sendMessage(message, networks !== null, networks, msg);
}).bind(this));
WifiManager.scan(true, function() {});
},
@ -1934,7 +1937,7 @@ WifiWorker.prototype = {
do {
let req = this._stateRequests.shift();
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.
} while (success &&
@ -1974,23 +1977,25 @@ WifiWorker.prototype = {
WifiManager.start();
},
setWifiEnabled: function(enable, rid, mid) {
setWifiEnabled: function(msg) {
// There are two problems that we're trying to solve here:
// - 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
// and handle each on/off request in turn.
// - Because we can't pass a callback to WifiManager.start, we need to
// 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)
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 message = "WifiManager:associate:Return";
let network = msg.data;
if (WifiManager.state === "UNINITIALIZED") {
this._sendMessage(message, false, "Wifi is disabled", rid, mid);
this._sendMessage(message, false, "Wifi is disabled", msg);
return;
}
@ -2005,10 +2010,10 @@ WifiWorker.prototype = {
if (WifiManager.state === "DISCONNECTED" ||
WifiManager.state === "SCANNING") {
WifiManager.reconnect(function (ok) {
self._sendMessage(message, ok, ok, rid, mid);
self._sendMessage(message, ok, ok, msg);
});
} else {
self._sendMessage(message, ok, ok, rid, mid);
self._sendMessage(message, ok, ok, msg);
}
});
}
@ -2032,7 +2037,7 @@ WifiWorker.prototype = {
privnet.netId = configured.netId;
WifiManager.updateNetwork(privnet, (function(ok) {
if (!ok) {
this._sendMessage(message, false, "Network is misconfigured", rid, mid);
this._sendMessage(message, false, "Network is misconfigured", msg);
return;
}
@ -2046,7 +2051,7 @@ WifiWorker.prototype = {
privnet.disabled = 0;
WifiManager.addNetwork(privnet, (function(ok) {
if (!ok) {
this._sendMessage(message, false, "Network is misconfigured", rid, mid);
this._sendMessage(message, false, "Network is misconfigured", msg);
return;
}
@ -2056,16 +2061,17 @@ WifiWorker.prototype = {
}
},
forget: function(network, rid, mid) {
forget: function(msg) {
const message = "WifiManager:forget:Return";
let network = msg.data;
if (WifiManager.state === "UNINITIALIZED") {
this._sendMessage(message, false, "Wifi is disabled", rid, mid);
this._sendMessage(message, false, "Wifi is disabled", msg);
return;
}
let ssid = network.ssid;
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;
}
@ -2075,46 +2081,47 @@ WifiWorker.prototype = {
(this.currentNetwork.ssid === ssid));
WifiManager.removeNetwork(configured.netId, function(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;
return;
}
WifiManager.saveConfig(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";
let self = this;
let detail = msg.data;
if (detail.method === "pbc") {
WifiManager.wpsPbc(function(ok) {
if (ok)
self._sendMessage(message, true, true, rid, mid);
self._sendMessage(message, true, true, msg);
else
self._sendMessage(message, false, "WPS PBC failed", rid, mid);
self._sendMessage(message, false, "WPS PBC failed", msg);
});
} else if (detail.method === "pin") {
WifiManager.wpsPin(detail.pin, function(pin) {
if (pin)
self._sendMessage(message, true, pin, rid, mid);
self._sendMessage(message, true, pin, msg);
else
self._sendMessage(message, false, "WPS PIN failed", rid, mid);
self._sendMessage(message, false, "WPS PIN failed", msg);
});
} else if (detail.method === "cancel") {
WifiManager.wpsCancel(function(ok) {
if (ok)
self._sendMessage(message, true, true, rid, mid);
self._sendMessage(message, true, true, msg);
else
self._sendMessage(message, false, "WPS Cancel failed", rid, mid);
self._sendMessage(message, false, "WPS Cancel failed", msg);
});
} else {
self._sendMessage(message, false, "Invalid WPS method=" + detail.method,
rid, mid);
msg);
}
},