зеркало из https://github.com/mozilla/gecko-dev.git
Bug 736091 - Add a forgetNetwork function that forgets the requested network. If the requested network is the current network, we reconnect to the next available network. r=cjones
--HG-- extra : rebase_source : b68cd9c99dcf31e9274d603d88300340ee1ebf60
This commit is contained in:
Родитель
300ad5576c
Коммит
be9bfeacb2
|
@ -53,6 +53,7 @@ DOMWifiManager.prototype = {
|
|||
const messages = ["WifiManager:setEnabled:Return:OK", "WifiManager:setEnabled:Return:NO",
|
||||
"WifiManager:getNetworks:Return:OK", "WifiManager:getNetworks:Return:NO",
|
||||
"WifiManager:associate:Return:OK", "WifiManager:associate:Return:NO",
|
||||
"WifiManager:forget:Return:OK", "WifiManager:forget:Return:NO",
|
||||
"WifiManager:onconnecting", "WifiManager:onassociate",
|
||||
"WifiManager:onconnect", "WifiManager:ondisconnect",
|
||||
"WifiManager:connectionInfoUpdate"];
|
||||
|
@ -124,6 +125,16 @@ DOMWifiManager.prototype = {
|
|||
Services.DOMRequest.fireError(request, "Unable to add the network");
|
||||
break;
|
||||
|
||||
case "WifiManager:forget:Return:OK":
|
||||
request = this._takeRequest(msg.rid);
|
||||
Services.DOMRequest.fireSuccess(request, true);
|
||||
break;
|
||||
|
||||
case "WifiManager:forget:Return:NO":
|
||||
request = this._takeRequest(msg.rid);
|
||||
Services.DOMRequest.fireError(request, msg.data);
|
||||
break;
|
||||
|
||||
case "WifiManager:onconnecting":
|
||||
this._currentNetwork = msg.network;
|
||||
this._fireOnConnecting(msg.network);
|
||||
|
@ -207,6 +218,14 @@ DOMWifiManager.prototype = {
|
|||
return request;
|
||||
},
|
||||
|
||||
forget: function nsIDOMWifiManager_forget(network) {
|
||||
if (!this._hasPrivileges)
|
||||
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
||||
var request = Services.DOMRequest.createRequest(this._window);
|
||||
this._sendMessageForRequest("WifiManager:forget", network, request);
|
||||
return request;
|
||||
},
|
||||
|
||||
get enabled() {
|
||||
if (!this._hasPrivileges)
|
||||
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
||||
|
|
|
@ -1153,6 +1153,7 @@ function WifiWorker() {
|
|||
|
||||
this._lastConnectionInfo = null;
|
||||
this._connectionInfoTimer = null;
|
||||
this._reconnectOnDisconnect = false;
|
||||
|
||||
// Given a connection status network, takes a network from
|
||||
// self.configuredNetworks and prepares it for the DOM.
|
||||
|
@ -1224,31 +1225,10 @@ function WifiWorker() {
|
|||
debug("Got mac: " + mac);
|
||||
});
|
||||
|
||||
WifiManager.getConfiguredNetworks(function(networks) {
|
||||
if (!networks) {
|
||||
debug("Unable to get configured networks");
|
||||
return;
|
||||
}
|
||||
|
||||
this._highestPriority = -1;
|
||||
|
||||
// Convert between netId-based and ssid-based indexing.
|
||||
for (let net in networks) {
|
||||
let network = networks[net];
|
||||
if (!network.ssid) {
|
||||
delete networks[net]; // TODO support these?
|
||||
continue;
|
||||
}
|
||||
|
||||
if (network.priority && network.priority > self._highestPriority)
|
||||
self._highestPriority = network.priority;
|
||||
networks[dequote(network.ssid)] = network;
|
||||
delete networks[net];
|
||||
}
|
||||
|
||||
self.configuredNetworks = networks;
|
||||
|
||||
self._reloadConfiguredNetworks(function(ok) {
|
||||
// Prime this.networks.
|
||||
if (!ok)
|
||||
return;
|
||||
self.waitForScan(function firstScan() {});
|
||||
});
|
||||
}
|
||||
|
@ -1309,6 +1289,13 @@ function WifiWorker() {
|
|||
} else if (this.state === "DISCONNECTED") {
|
||||
self._fireEvent("ondisconnect", {});
|
||||
self.currentNetwork = null;
|
||||
|
||||
// We've disconnected from a network because of a call to forgetNetwork.
|
||||
// Reconnect to the next available network (if any).
|
||||
if (self._reconnectOnDisconnect) {
|
||||
self._reconnectOnDisconnect = false;
|
||||
WifiManager.reconnect(function(){});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1475,6 +1462,35 @@ WifiWorker.prototype = {
|
|||
this._lastConnectionInfo = null;
|
||||
},
|
||||
|
||||
_reloadConfiguredNetworks: function(callback) {
|
||||
WifiManager.getConfiguredNetworks((function(networks) {
|
||||
if (!networks) {
|
||||
debug("Unable to get configured networks");
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
this._highestPriority = -1;
|
||||
|
||||
// Convert between netId-based and ssid-based indexing.
|
||||
for (let net in networks) {
|
||||
let network = networks[net];
|
||||
if (!network.ssid) {
|
||||
delete networks[net]; // TODO support these?
|
||||
continue;
|
||||
}
|
||||
|
||||
if (network.priority && network.priority > this._highestPriority)
|
||||
this._highestPriority = network.priority;
|
||||
networks[dequote(network.ssid)] = network;
|
||||
delete networks[net];
|
||||
}
|
||||
|
||||
this.configuredNetworks = networks;
|
||||
callback(true);
|
||||
}).bind(this));
|
||||
},
|
||||
|
||||
// Important side effect: calls WifiManager.saveConfig.
|
||||
_reprioritizeNetworks: function(callback) {
|
||||
// First, sort the networks in orer of their priority.
|
||||
|
@ -1564,6 +1580,9 @@ WifiWorker.prototype = {
|
|||
case "WifiManager:associate":
|
||||
this.associate(msg.data, msg.rid, msg.mid);
|
||||
break;
|
||||
case "WifiManager:forget":
|
||||
this.forget(msg.data, msg.rid, msg.mid);
|
||||
break;
|
||||
case "WifiManager:getState": {
|
||||
let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
|
||||
return { network: net,
|
||||
|
@ -1655,6 +1674,32 @@ WifiWorker.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
forget: function(network, rid, mid) {
|
||||
const message = "WifiManager:forget:Return";
|
||||
let ssid = network.ssid;
|
||||
if (!(ssid in this.configuredNetworks)) {
|
||||
this._sendMessage(message, false, "Trying to forget an unknown network", rid, mid);
|
||||
return;
|
||||
}
|
||||
|
||||
let self = this;
|
||||
let configured = this.configuredNetworks[ssid];
|
||||
this._reconnectOnDisconnect = (this._currentNetwork.ssid === ssid);
|
||||
WifiManager.removeNetwork(configured.netId, function(ok) {
|
||||
if (!ok) {
|
||||
self._sendMessage(message, false, "Unable to remove the network", rid, mid);
|
||||
self._reconnectOnDisconnect = false;
|
||||
return;
|
||||
}
|
||||
|
||||
WifiManager.saveConfig(function() {
|
||||
self._reloadConfiguredNetworks(function() {
|
||||
self._sendMessage(message, true, true, rid, mid);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// This is a bit ugly, but works. In particular, this depends on the fact
|
||||
// that RadioManager never actually tries to get the worker from us.
|
||||
get worker() { throw "Not implemented"; },
|
||||
|
|
|
@ -47,7 +47,7 @@ interface nsIWifi : nsISupports {
|
|||
void shutdown();
|
||||
};
|
||||
|
||||
[scriptable, uuid(7df14510-f58b-4c9a-9e35-a39a94255941)]
|
||||
[scriptable, uuid(36e4137b-dc8b-47e2-a90c-6adfb731fc41)]
|
||||
interface nsIDOMWifiManager : nsISupports {
|
||||
/**
|
||||
* TODO Remove in favor of a settings API.
|
||||
|
@ -80,6 +80,18 @@ interface nsIDOMWifiManager : nsISupports {
|
|||
*/
|
||||
nsIDOMDOMRequest associate(in jsval network);
|
||||
|
||||
/**
|
||||
* Given a network, removes it from the list of networks that we'll
|
||||
* automatically connect to. In order to re-connect to the network, it is
|
||||
* necessary to call associate on it.
|
||||
* @param network A network object with the SSID of the network to remove.
|
||||
* onsuccess: We have removed this network. If we were previously
|
||||
* connected to it, we have started reconnecting to the next
|
||||
* network in the list.
|
||||
* onerror: We were unable to remove the network.
|
||||
*/
|
||||
nsIDOMDOMRequest forget(in jsval network);
|
||||
|
||||
/**
|
||||
* TODO Remove in favor of a settings API.
|
||||
* Returns whether or not wifi is currently enabled.
|
||||
|
|
Загрузка…
Ссылка в новой задаче