mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-11 10:08:41 +00:00
Backed out changeset f54af6237ce9 (bug 1000040) for causing bug 1035172
This commit is contained in:
parent
9ab07f78c0
commit
32a827b499
@ -12,7 +12,7 @@ Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||
|
||||
const NETWORKSERVICE_CONTRACTID = "@mozilla.org/network/service;1";
|
||||
const NETWORKSERVICE_CID = Components.ID("{48c13741-aec9-4a86-8962-432011708261}");
|
||||
const NETWORKSERVICE_CID = Components.ID("{baec696c-c78d-42db-8b44-603f8fbfafb4}");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "gNetworkWorker",
|
||||
"@mozilla.org/network/worker;1",
|
||||
@ -542,81 +542,6 @@ NetworkService.prototype = {
|
||||
});
|
||||
},
|
||||
|
||||
getInterfaces: function(callback) {
|
||||
let params = {
|
||||
cmd: "getInterfaces",
|
||||
isAsync: true
|
||||
};
|
||||
|
||||
this.controlMessage(params, function(data) {
|
||||
if(DEBUG) debug("getInterfaces result: " + JSON.stringify(data));
|
||||
let success = !isError(data.resultCode);
|
||||
callback.getInterfacesResult(success, data.interfaceList);
|
||||
});
|
||||
},
|
||||
|
||||
setInterfaceConfig: function(config, callback) {
|
||||
config.cmd = "setInterfaceConfig";
|
||||
config.isAsync = true;
|
||||
|
||||
this.controlMessage(config, function(data) {
|
||||
if(DEBUG) debug("setInterfaceConfig result: " + JSON.stringify(data));
|
||||
let success = !isError(data.resultCode);
|
||||
callback.setInterfaceConfigResult(success);
|
||||
});
|
||||
},
|
||||
|
||||
getInterfaceConfig: function(ifname, callback) {
|
||||
let params = {
|
||||
cmd: "getInterfaceConfig",
|
||||
ifname: ifname,
|
||||
isAsync: true
|
||||
};
|
||||
|
||||
this.controlMessage(params, function(data) {
|
||||
if(DEBUG) debug("getInterfaceConfig result: " + JSON.stringify(data));
|
||||
let success = !isError(data.resultCode);
|
||||
let result = { ip: data.ipAddr,
|
||||
prefix: data.maskLength,
|
||||
link: data.flag,
|
||||
mac: data.macAddr };
|
||||
callback.getInterfaceConfigResult(success, result);
|
||||
});
|
||||
},
|
||||
|
||||
runDhcp: function(ifname, callback) {
|
||||
let params = {
|
||||
cmd: "runDhcp",
|
||||
ifname: ifname,
|
||||
isBlocking: true
|
||||
};
|
||||
|
||||
this.controlMessage(params, function(data) {
|
||||
if(DEBUG) debug("runDhcp result: " + JSON.stringify(data));
|
||||
let success = data.success;
|
||||
let result = {
|
||||
ip: data.ipAddr,
|
||||
gateway: data.gateway,
|
||||
dns1: data.dns1,
|
||||
dns2: data.dns2,
|
||||
prefix: data.maskLength,
|
||||
server: data.server
|
||||
};
|
||||
|
||||
callback.runDhcpResult(success, result);
|
||||
});
|
||||
},
|
||||
|
||||
stopDhcp: function(ifname) {
|
||||
let params = {
|
||||
cmd: "stopDhcp",
|
||||
ifname: ifname,
|
||||
isAsync: true
|
||||
};
|
||||
|
||||
this.controlMessage(params);
|
||||
},
|
||||
|
||||
shutdown: false,
|
||||
|
||||
observe: function observe(aSubject, aTopic, aData) {
|
||||
|
@ -1,3 +1,3 @@
|
||||
# NetworkService.js
|
||||
component {48c13741-aec9-4a86-8962-432011708261} NetworkService.js
|
||||
contract @mozilla.org/network/service;1 {48c13741-aec9-4a86-8962-432011708261}
|
||||
component {baec696c-c78d-42db-8b44-603f8fbfafb4} NetworkService.js
|
||||
contract @mozilla.org/network/service;1 {baec696c-c78d-42db-8b44-603f8fbfafb4}
|
||||
|
@ -111,7 +111,7 @@ CommandFunc NetworkUtils::sWifiEnableChain[] = {
|
||||
NetworkUtils::startAccessPointDriver,
|
||||
NetworkUtils::setAccessPoint,
|
||||
NetworkUtils::startSoftAP,
|
||||
NetworkUtils::setConfig,
|
||||
NetworkUtils::setInterfaceUp,
|
||||
NetworkUtils::tetherInterface,
|
||||
NetworkUtils::setIpForwardingEnabled,
|
||||
NetworkUtils::tetheringStatus,
|
||||
@ -152,7 +152,7 @@ CommandFunc NetworkUtils::sWifiRetryChain[] = {
|
||||
NetworkUtils::startAccessPointDriver,
|
||||
NetworkUtils::setAccessPoint,
|
||||
NetworkUtils::startSoftAP,
|
||||
NetworkUtils::setConfig,
|
||||
NetworkUtils::setInterfaceUp,
|
||||
NetworkUtils::tetherInterface,
|
||||
NetworkUtils::setIpForwardingEnabled,
|
||||
NetworkUtils::tetheringStatus,
|
||||
@ -168,7 +168,7 @@ CommandFunc NetworkUtils::sWifiOperationModeChain[] = {
|
||||
};
|
||||
|
||||
CommandFunc NetworkUtils::sUSBEnableChain[] = {
|
||||
NetworkUtils::setConfig,
|
||||
NetworkUtils::setInterfaceUp,
|
||||
NetworkUtils::enableNat,
|
||||
NetworkUtils::setIpForwardingEnabled,
|
||||
NetworkUtils::tetherInterface,
|
||||
@ -201,7 +201,7 @@ CommandFunc NetworkUtils::sUpdateUpStreamChain[] = {
|
||||
};
|
||||
|
||||
CommandFunc NetworkUtils::sStartDhcpServerChain[] = {
|
||||
NetworkUtils::setConfig,
|
||||
NetworkUtils::setInterfaceUp,
|
||||
NetworkUtils::startTethering,
|
||||
NetworkUtils::setDhcpServerSuccess
|
||||
};
|
||||
@ -240,21 +240,6 @@ CommandFunc NetworkUtils::sSetDnsChain[] = {
|
||||
NetworkUtils::setInterfaceDns
|
||||
};
|
||||
|
||||
CommandFunc NetworkUtils::sGetInterfacesChain[] = {
|
||||
NetworkUtils::getInterfaceList,
|
||||
NetworkUtils::getInterfacesSuccess
|
||||
};
|
||||
|
||||
CommandFunc NetworkUtils::sSetInterfaceConfigChain[] = {
|
||||
NetworkUtils::setConfig,
|
||||
NetworkUtils::setInterfaceConfigSuccess
|
||||
};
|
||||
|
||||
CommandFunc NetworkUtils::sGetInterfaceConfigChain[] = {
|
||||
NetworkUtils::getConfig,
|
||||
NetworkUtils::getInterfaceConfigSuccess
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to get the mask from given prefix length.
|
||||
*/
|
||||
@ -337,15 +322,6 @@ static void join(nsTArray<nsCString>& array,
|
||||
#undef CHECK_LEN
|
||||
}
|
||||
|
||||
static void convertUTF8toUTF16(nsTArray<nsCString>& narrow,
|
||||
nsTArray<nsString>& wide,
|
||||
uint32_t length)
|
||||
{
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
wide.AppendElement(NS_ConvertUTF8toUTF16(narrow[i].get()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to get network interface properties from the system property table.
|
||||
*/
|
||||
@ -710,9 +686,9 @@ void NetworkUtils::setAlarm(CommandChain* aChain,
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
void NetworkUtils::setConfig(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
void NetworkUtils::setInterfaceUp(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char command[MAX_COMMAND_SIZE];
|
||||
if (SDK_VERSION >= 16) {
|
||||
@ -947,26 +923,6 @@ void NetworkUtils::setInterfaceDns(CommandChain* aChain,
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
void NetworkUtils::getInterfaceList(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char command[MAX_COMMAND_SIZE];
|
||||
snprintf(command, MAX_COMMAND_SIZE - 1, "interface list");
|
||||
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
void NetworkUtils::getConfig(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char command[MAX_COMMAND_SIZE];
|
||||
snprintf(command, MAX_COMMAND_SIZE - 1, "interface getcfg %s", GET_CHAR(mIfname));
|
||||
|
||||
doCommand(command, aChain, aCallback);
|
||||
}
|
||||
|
||||
#undef GET_CHAR
|
||||
#undef GET_FIELD
|
||||
|
||||
@ -1107,75 +1063,6 @@ void NetworkUtils::setDnsFail(NetworkParams& aOptions, NetworkResultOptions& aRe
|
||||
postMessage(aOptions, aResult);
|
||||
}
|
||||
|
||||
void NetworkUtils::getInterfacesFail(NetworkParams& aOptions, NetworkResultOptions& aResult)
|
||||
{
|
||||
postMessage(aOptions, aResult);
|
||||
}
|
||||
|
||||
void NetworkUtils::getInterfacesSuccess(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
NS_ConvertUTF16toUTF8 reason(aResult.mResultReason);
|
||||
memcpy(buf, reason.get(), strlen(reason.get()));
|
||||
|
||||
nsTArray<nsCString> result;
|
||||
split(buf, INTERFACE_DELIMIT, result);
|
||||
|
||||
nsTArray<nsString> interfaceList;
|
||||
uint32_t length = result.Length();
|
||||
convertUTF8toUTF16(result, interfaceList, length);
|
||||
|
||||
aResult.mInterfaceList.Construct();
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
aResult.mInterfaceList.Value().AppendElement(interfaceList[i]);
|
||||
}
|
||||
|
||||
postMessage(aChain->getParams(), aResult);
|
||||
}
|
||||
|
||||
void NetworkUtils::setInterfaceConfigFail(NetworkParams& aOptions, NetworkResultOptions& aResult)
|
||||
{
|
||||
postMessage(aOptions, aResult);
|
||||
}
|
||||
|
||||
void NetworkUtils::setInterfaceConfigSuccess(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
postMessage(aChain->getParams(), aResult);
|
||||
}
|
||||
|
||||
void NetworkUtils::getInterfaceConfigFail(NetworkParams& aOptions, NetworkResultOptions& aResult)
|
||||
{
|
||||
postMessage(aOptions, aResult);
|
||||
}
|
||||
|
||||
void NetworkUtils::getInterfaceConfigSuccess(CommandChain* aChain,
|
||||
CommandCallback aCallback,
|
||||
NetworkResultOptions& aResult)
|
||||
{
|
||||
char buf[BUF_SIZE];
|
||||
NS_ConvertUTF16toUTF8 reason(aResult.mResultReason);
|
||||
memcpy(buf, reason.get(), strlen(reason.get()));
|
||||
|
||||
nsTArray<nsCString> result;
|
||||
split(buf, NETD_MESSAGE_DELIMIT, result);
|
||||
|
||||
ASSIGN_FIELD_VALUE(mMacAddr, NS_ConvertUTF8toUTF16(result[0]))
|
||||
ASSIGN_FIELD_VALUE(mIpAddr, NS_ConvertUTF8toUTF16(result[1]))
|
||||
ASSIGN_FIELD_VALUE(mMaskLength, atof(result[2].get()))
|
||||
|
||||
if (result[3].Find("up")) {
|
||||
ASSIGN_FIELD_VALUE(mFlag, NS_ConvertUTF8toUTF16("up"))
|
||||
} else {
|
||||
ASSIGN_FIELD_VALUE(mFlag, NS_ConvertUTF8toUTF16("down"))
|
||||
}
|
||||
|
||||
postMessage(aChain->getParams(), aResult);
|
||||
}
|
||||
|
||||
#undef ASSIGN_FIELD
|
||||
#undef ASSIGN_FIELD_VALUE
|
||||
|
||||
@ -1240,14 +1127,6 @@ void NetworkUtils::ExecuteCommand(NetworkParams aOptions)
|
||||
enableUsbRndis(aOptions);
|
||||
} else if (aOptions.mCmd.EqualsLiteral("updateUpStream")) {
|
||||
updateUpStream(aOptions);
|
||||
} else if (aOptions.mCmd.EqualsLiteral("getInterfaces")) {
|
||||
getInterfaces(aOptions);
|
||||
} else if (aOptions.mCmd.EqualsLiteral("stopDhcp")) {
|
||||
stopDhcp(aOptions);
|
||||
} else if (aOptions.mCmd.EqualsLiteral("setInterfaceConfig")) {
|
||||
setInterfaceConfig(aOptions);
|
||||
} else if (aOptions.mCmd.EqualsLiteral("getInterfaceConfig")) {
|
||||
getInterfaceConfig(aOptions);
|
||||
} else {
|
||||
WARN("unknon message");
|
||||
return;
|
||||
@ -1837,7 +1716,7 @@ bool NetworkUtils::enableUsbRndis(NetworkParams& aOptions)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling upstream interface change event.
|
||||
* handling upstream interface change event.
|
||||
*/
|
||||
bool NetworkUtils::updateUpStream(NetworkParams& aOptions)
|
||||
{
|
||||
@ -1845,42 +1724,6 @@ bool NetworkUtils::updateUpStream(NetworkParams& aOptions)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop dhcp client deamon.
|
||||
*/
|
||||
bool NetworkUtils::stopDhcp(NetworkParams& aOptions)
|
||||
{
|
||||
mNetUtils->do_dhcp_stop(GET_CHAR(mIfname));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get existing network interfaces.
|
||||
*/
|
||||
bool NetworkUtils::getInterfaces(NetworkParams& aOptions)
|
||||
{
|
||||
RUN_CHAIN(aOptions, sGetInterfacesChain, getInterfacesFail)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set network config for a specified interface.
|
||||
*/
|
||||
bool NetworkUtils::setInterfaceConfig(NetworkParams& aOptions)
|
||||
{
|
||||
RUN_CHAIN(aOptions, sSetInterfaceConfigChain, setInterfaceConfigFail)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get network config of a specified interface.
|
||||
*/
|
||||
bool NetworkUtils::getInterfaceConfig(NetworkParams& aOptions)
|
||||
{
|
||||
RUN_CHAIN(aOptions, sGetInterfaceConfigChain, getInterfaceConfigFail)
|
||||
return true;
|
||||
}
|
||||
|
||||
void NetworkUtils::sendBroadcastMessage(uint32_t code, char* reason)
|
||||
{
|
||||
NetworkResultOptions result;
|
||||
|
@ -72,7 +72,6 @@ public:
|
||||
mCurInternalIfname = aOther.mCurInternalIfname;
|
||||
mCurExternalIfname = aOther.mCurExternalIfname;
|
||||
mThreshold = aOther.mThreshold;
|
||||
mIsBlocking = aOther.mIsBlocking;
|
||||
}
|
||||
|
||||
NetworkParams(const mozilla::dom::NetworkCommandOptions& aOther) {
|
||||
@ -149,7 +148,6 @@ public:
|
||||
COPY_OPT_STRING_FIELD(mCurInternalIfname, EmptyString())
|
||||
COPY_OPT_STRING_FIELD(mCurExternalIfname, EmptyString())
|
||||
COPY_OPT_FIELD(mThreshold, -1)
|
||||
COPY_OPT_FIELD(mIsBlocking, false)
|
||||
|
||||
#undef COPY_SEQUENCE_FIELD
|
||||
#undef COPY_OPT_STRING_FIELD
|
||||
@ -200,7 +198,6 @@ public:
|
||||
nsString mCurInternalIfname;
|
||||
nsString mCurExternalIfname;
|
||||
long mThreshold;
|
||||
bool mIsBlocking;
|
||||
};
|
||||
|
||||
// CommandChain store the necessary information to execute command one by one.
|
||||
@ -284,10 +281,6 @@ private:
|
||||
bool setUSBTethering(NetworkParams& aOptions);
|
||||
bool enableUsbRndis(NetworkParams& aOptions);
|
||||
bool updateUpStream(NetworkParams& aOptions);
|
||||
bool getInterfaces(NetworkParams& aOptions);
|
||||
bool stopDhcp(NetworkParams& aOptions);
|
||||
bool setInterfaceConfig(NetworkParams& aOptions);
|
||||
bool getInterfaceConfig(NetworkParams& aOptions);
|
||||
|
||||
/**
|
||||
* function pointer array holds all netd commands should be executed
|
||||
@ -309,9 +302,6 @@ private:
|
||||
static CommandFunc sNetworkInterfaceDisableAlarmChain[];
|
||||
static CommandFunc sNetworkInterfaceSetAlarmChain[];
|
||||
static CommandFunc sSetDnsChain[];
|
||||
static CommandFunc sGetInterfacesChain[];
|
||||
static CommandFunc sSetInterfaceConfigChain[];
|
||||
static CommandFunc sGetInterfaceConfigChain[];
|
||||
|
||||
/**
|
||||
* Individual netd command stored in command chain.
|
||||
@ -348,9 +338,6 @@ private:
|
||||
static void disableNat(PARAMS);
|
||||
static void setDefaultInterface(PARAMS);
|
||||
static void setInterfaceDns(PARAMS);
|
||||
static void getInterfaceList(PARAMS);
|
||||
static void setConfig(PARAMS);
|
||||
static void getConfig(PARAMS);
|
||||
static void wifiTetheringSuccess(PARAMS);
|
||||
static void usbTetheringSuccess(PARAMS);
|
||||
static void networkInterfaceStatsSuccess(PARAMS);
|
||||
@ -358,9 +345,6 @@ private:
|
||||
static void updateUpStreamSuccess(PARAMS);
|
||||
static void setDhcpServerSuccess(PARAMS);
|
||||
static void wifiOperationModeSuccess(PARAMS);
|
||||
static void getInterfacesSuccess(PARAMS);
|
||||
static void setInterfaceConfigSuccess(PARAMS);
|
||||
static void getInterfaceConfigSuccess(PARAMS);
|
||||
#undef PARAMS
|
||||
|
||||
/**
|
||||
@ -376,9 +360,6 @@ private:
|
||||
static void networkInterfaceStatsFail(PARAMS);
|
||||
static void networkInterfaceAlarmFail(PARAMS);
|
||||
static void setDnsFail(PARAMS);
|
||||
static void getInterfacesFail(PARAMS);
|
||||
static void setInterfaceConfigFail(PARAMS);
|
||||
static void getInterfaceConfigFail(PARAMS);
|
||||
#undef PARAMS
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,6 @@ using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::ipc;
|
||||
|
||||
#define PROPERTY_VALUE_MAX 80
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
nsCOMPtr<nsIThread> gWorkerThread;
|
||||
@ -39,15 +37,6 @@ public:
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
#define COPY_FIELD(prop) mResult.prop = aResult.prop;
|
||||
#define COPY_SEQUENCE_FIELD(prop, type) \
|
||||
if (aResult.prop.WasPassed()) { \
|
||||
mozilla::dom::Sequence<type > const & currentValue = aResult.prop.InternalValue(); \
|
||||
uint32_t length = currentValue.Length(); \
|
||||
mResult.prop.Construct(); \
|
||||
for (uint32_t idx = 0; idx < length; idx++) { \
|
||||
mResult.prop.Value().AppendElement(currentValue[idx]); \
|
||||
} \
|
||||
}
|
||||
COPY_FIELD(mId)
|
||||
COPY_FIELD(mRet)
|
||||
COPY_FIELD(mBroadcast)
|
||||
@ -64,16 +53,6 @@ public:
|
||||
COPY_FIELD(mSuccess)
|
||||
COPY_FIELD(mCurExternalIfname)
|
||||
COPY_FIELD(mCurInternalIfname)
|
||||
COPY_FIELD(mIpAddr)
|
||||
COPY_FIELD(mGateway)
|
||||
COPY_FIELD(mDns1)
|
||||
COPY_FIELD(mDns2)
|
||||
COPY_FIELD(mServer)
|
||||
COPY_FIELD(mLease)
|
||||
COPY_FIELD(mVendorInfo)
|
||||
COPY_FIELD(mMaskLength)
|
||||
COPY_FIELD(mFlag)
|
||||
COPY_SEQUENCE_FIELD(mInterfaceList, nsString)
|
||||
#undef COPY_FIELD
|
||||
}
|
||||
|
||||
@ -113,66 +92,6 @@ private:
|
||||
NetworkParams mParams;
|
||||
};
|
||||
|
||||
// Runnable used for blocking command.
|
||||
class RunDhcpEvent : public nsRunnable
|
||||
{
|
||||
public:
|
||||
RunDhcpEvent(const NetworkParams& aParams)
|
||||
: mParams(aParams)
|
||||
{}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
nsAutoPtr<NetUtils> netUtils;
|
||||
netUtils = new NetUtils();
|
||||
|
||||
NetworkResultOptions result;
|
||||
result.mId = mParams.mId;
|
||||
|
||||
int32_t status;
|
||||
char ipaddr[PROPERTY_VALUE_MAX];
|
||||
char gateway[PROPERTY_VALUE_MAX];
|
||||
uint32_t prefixLength;
|
||||
char dns1[PROPERTY_VALUE_MAX];
|
||||
char dns2[PROPERTY_VALUE_MAX];
|
||||
char server[PROPERTY_VALUE_MAX];
|
||||
uint32_t lease;
|
||||
char vendorinfo[PROPERTY_VALUE_MAX];
|
||||
status = netUtils->do_dhcp_do_request(NS_ConvertUTF16toUTF8(mParams.mIfname).get(),
|
||||
ipaddr,
|
||||
gateway,
|
||||
&prefixLength,
|
||||
dns1,
|
||||
dns2,
|
||||
server,
|
||||
&lease,
|
||||
vendorinfo);
|
||||
|
||||
|
||||
if (status == 0) {
|
||||
// run dhcp success.
|
||||
result.mSuccess = true;
|
||||
result.mIpAddr = NS_ConvertUTF8toUTF16(ipaddr);
|
||||
result.mGateway = NS_ConvertUTF8toUTF16(gateway);
|
||||
result.mDns1 = NS_ConvertUTF8toUTF16(dns1);
|
||||
result.mDns2 = NS_ConvertUTF8toUTF16(dns2);
|
||||
result.mServer = NS_ConvertUTF8toUTF16(server);
|
||||
result.mLease = lease;
|
||||
result.mVendorInfo = NS_ConvertUTF8toUTF16(vendorinfo);
|
||||
result.mMaskLength = prefixLength;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable = new NetworkResultDispatcher(result);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
private:
|
||||
NetworkParams mParams;
|
||||
};
|
||||
|
||||
// Runnable used dispatch netd result on the worker thread.
|
||||
class NetdEventRunnable : public nsRunnable
|
||||
{
|
||||
@ -305,14 +224,8 @@ NetworkWorker::PostMessage(JS::Handle<JS::Value> aOptions, JSContext* aCx)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NetworkParams NetworkParams(options);
|
||||
|
||||
if (NetworkParams.mIsBlocking) {
|
||||
NetworkWorker::HandleBlockingCommand(NetworkParams);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Dispatch the command to the control thread.
|
||||
NetworkParams NetworkParams(options);
|
||||
nsCOMPtr<nsIRunnable> runnable = new NetworkCommandDispatcher(NetworkParams);
|
||||
if (gWorkerThread) {
|
||||
gWorkerThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL);
|
||||
@ -320,24 +233,6 @@ NetworkWorker::PostMessage(JS::Handle<JS::Value> aOptions, JSContext* aCx)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
NetworkWorker::HandleBlockingCommand(NetworkParams& aOptions)
|
||||
{
|
||||
if (aOptions.mCmd.EqualsLiteral("runDhcp")) {
|
||||
NetworkWorker::RunDhcp(aOptions);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
NetworkWorker::RunDhcp(NetworkParams& aOptions)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable = new RunDhcpEvent(aOptions);
|
||||
nsCOMPtr<nsIThread> thread;
|
||||
NS_NewThread(getter_AddRefs(thread), runnable);
|
||||
}
|
||||
|
||||
void
|
||||
NetworkWorker::DispatchNetworkResult(const NetworkResultOptions& aOptions)
|
||||
{
|
||||
|
@ -11,8 +11,6 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsThread.h"
|
||||
|
||||
class NetworkParams;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class NetworkWorker MOZ_FINAL : public nsINetworkWorker
|
||||
@ -31,9 +29,6 @@ private:
|
||||
|
||||
static void NotifyResult(mozilla::dom::NetworkResultOptions& aResult);
|
||||
|
||||
void HandleBlockingCommand(NetworkParams& aParams);
|
||||
void RunDhcp(NetworkParams& aParams);
|
||||
|
||||
nsCOMPtr<nsINetworkEventListener> mListener;
|
||||
};
|
||||
|
||||
|
@ -101,65 +101,10 @@ interface nsIUpdateUpStreamCallback : nsISupports
|
||||
void updateUpStreamResult(in boolean success, in DOMString externalIfname);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(4a9166f3-7e4f-4d10-bb5c-b49ee21d6184)]
|
||||
interface nsIRunDhcpCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* Callback function used to report the result of dhcp request.
|
||||
*
|
||||
* @param success
|
||||
* Boolean to indicate the operation is successful or not.
|
||||
*/
|
||||
void runDhcpResult(in boolean success, in jsval result);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(88e3ee22-f1b3-4fa0-8a5d-793fb827c42c)]
|
||||
interface nsIGetInterfacesCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* Callback function used to return the list of existing network interfaces.
|
||||
*
|
||||
* @param success
|
||||
* Boolean to indicate the operation is successful or not.
|
||||
* @param interfaceList
|
||||
* An array of interface name.
|
||||
*/
|
||||
void getInterfacesResult(in boolean success, in jsval interfaceList);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(064e02a3-d2c0-42c5-a293-1efa84056100)]
|
||||
interface nsIGetInterfaceConfigCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* Callback function used to return the network config of a given interface.
|
||||
*
|
||||
* @param success
|
||||
* Boolean to indicate the operation is successful or not.
|
||||
* @param result
|
||||
* .ip: Ip address.
|
||||
* .prefix: mask length.
|
||||
* .link: network link properties.
|
||||
* .mac: mac address.
|
||||
*/
|
||||
void getInterfaceConfigResult(in boolean success, in jsval result);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(b370f360-6ba8-4517-a4f9-31e8f004ee91)]
|
||||
interface nsISetInterfaceConfigCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* Callback function used to set network cofig for a specified interface.
|
||||
*
|
||||
* @param success
|
||||
* Boolean to indicate the operation is successful or not.
|
||||
*/
|
||||
void setInterfaceConfigResult(in boolean success);
|
||||
};
|
||||
|
||||
/**
|
||||
* Provide network services.
|
||||
*/
|
||||
[scriptable, uuid(48c13741-aec9-4a86-8962-432011708261)]
|
||||
[scriptable, uuid(f96461fa-e844-45d2-a6c3-8cd23ab0916b)]
|
||||
interface nsINetworkService : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -400,53 +345,4 @@ interface nsINetworkService : nsISupports
|
||||
void updateUpStream(in jsval previous,
|
||||
in jsval current,
|
||||
in nsIUpdateUpStreamCallback callback);
|
||||
|
||||
/**
|
||||
* Run Dhcp request.
|
||||
*
|
||||
* @param ifname
|
||||
* Target interface.
|
||||
* @param callback
|
||||
* Callback function to report the result.
|
||||
*/
|
||||
void runDhcp(in DOMString ifname, in nsIRunDhcpCallback callback);
|
||||
|
||||
/**
|
||||
* Stop Dhcp daemon.
|
||||
*
|
||||
* @param ifname
|
||||
* Target interface.
|
||||
*/
|
||||
void stopDhcp(in DOMString ifname);
|
||||
|
||||
/*
|
||||
* Obtain interfaces list.
|
||||
*
|
||||
* @param callback
|
||||
* Callback function to return the result.
|
||||
*/
|
||||
void getInterfaces(in nsIGetInterfacesCallback callback);
|
||||
|
||||
/**
|
||||
* Set config for a network interface.
|
||||
*
|
||||
* @param config
|
||||
* .ifname: Target interface.
|
||||
* .ip: Ip address.
|
||||
* .prefix: mask length.
|
||||
* .link: network link properties.
|
||||
* @param callback
|
||||
* Callback function to report the result.
|
||||
*/
|
||||
void setInterfaceConfig(in jsval config, in nsISetInterfaceConfigCallback callback);
|
||||
|
||||
/**
|
||||
* Get config of a network interface.
|
||||
*
|
||||
* @param ifname
|
||||
* Target interface.
|
||||
* @param callback
|
||||
* Callback function to report the result.
|
||||
*/
|
||||
void getInterfaceConfig(in DOMString ifname, in nsIGetInterfaceConfigCallback callback);
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/**
|
||||
* This dictionary holds the parameters sent to the network worker.
|
||||
* This dictionnary holds the parameters sent to the network worker.
|
||||
*/
|
||||
dictionary NetworkCommandOptions
|
||||
{
|
||||
@ -55,7 +55,6 @@ dictionary NetworkCommandOptions
|
||||
DOMString preExternalIfname; // for "updateUpStream".
|
||||
DOMString curInternalIfname; // for "updateUpStream".
|
||||
DOMString curExternalIfname; // for "updateUpStream".
|
||||
boolean isBlocking; // for "runDhcp".
|
||||
};
|
||||
|
||||
/**
|
||||
@ -82,18 +81,4 @@ dictionary NetworkResultOptions
|
||||
boolean success = false; // for "setDhcpServer".
|
||||
DOMString curExternalIfname = ""; // for "updateUpStream".
|
||||
DOMString curInternalIfname = ""; // for "updateUpStream".
|
||||
|
||||
DOMString ipAddr = ""; // for "runDhcp", "getInterfaceConfig".
|
||||
DOMString gateway = ""; // for "runDhcp".
|
||||
DOMString dns1 = ""; // for "runDhcp".
|
||||
DOMString dns2 = ""; // for "runDhcp".
|
||||
DOMString server = ""; // for "runDhcp".
|
||||
short lease = 0; // for "runDhcp".
|
||||
DOMString vendorInfo = ""; // for "runDhcp".
|
||||
short maskLength = 0; // for "runDhcp".
|
||||
|
||||
DOMString flag = "down"; // for "getInterfaceConfig".
|
||||
DOMString macAddr = ""; // for "getInterfaceConfig".
|
||||
|
||||
sequence<DOMString> interfaceList; // for "getInterfaceList".
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user