Bug 1032097 - Part 4: Expose new APIs addHostRoute/removeHostRoute from NetworkManager. r=echen

--HG--
extra : rebase_source : 68a7c9b8086d64e053750f7d48a23d2a0aa53377
This commit is contained in:
Bevis Tseng 2014-08-15 16:23:44 +08:00
parent 1af8799014
commit 5f0c3bc4b9
2 changed files with 66 additions and 1 deletions

View File

@ -463,6 +463,41 @@ NetworkManager.prototype = {
return Promise.all(promises);
},
isValidatedNetwork: function(network) {
let isValid = false;
try {
isValid = (this.getNetworkId(network) in this.networkInterfaces);
} catch (e) {
debug("Invalid network interface: " + e);
}
return isValid;
},
addHostRoute: function(network, host) {
if (!this.isValidatedNetwork(network)) {
return Promise.reject("Invalid network interface.");
}
return this.resolveHostname(host)
.then((ipAddresses) => this._updateRoutes(true,
ipAddresses,
network.name,
network.getGateways()));
},
removeHostRoute: function(network, host) {
if (!this.isValidatedNetwork(network)) {
return Promise.reject("Invalid network interface.");
}
return this.resolveHostname(host)
.then((ipAddresses) => this._updateRoutes(false,
ipAddresses,
network.name,
network.getGateways()));
},
#ifdef MOZ_B2G_RIL
isNetworkTypeSecondaryMobile: function(type) {
return (type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE_MMS ||

View File

@ -97,7 +97,7 @@ interface nsINetworkInterface : nsISupports
/**
* Manage network interfaces.
*/
[scriptable, uuid(f3193805-c070-4d23-bd5c-a439eb8610c3)]
[scriptable, uuid(19822018-2454-11e4-baa7-2b5894f0af6f)]
interface nsINetworkManager : nsISupports
{
/**
@ -196,4 +196,34 @@ interface nsINetworkManager : nsISupports
in nsINetworkInterface networkInterface,
in jsval config,
in nsIWifiTetheringCallback callback);
/**
* Add host route to the specified network into routing table.
*
* @param network
* The network interface where the host to be routed to.
* @param host
* The host to be added.
* The host will be resolved in advance if it's not an ip-address.
*
* @return a Promise
* resolved if added; rejected, otherwise.
*/
jsval addHostRoute(in nsINetworkInterface network,
in DOMString host);
/**
* Remove host route to the specified network from routing table.
*
* @param network
* The network interface where the routing to be removed from.
* @param host
* The host routed to the network.
* The host will be resolved in advance if it's not an ip-address.
*
* @return a Promise
* resolved if removed; rejected, otherwise.
*/
jsval removeHostRoute(in nsINetworkInterface network,
in DOMString host);
};