Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 787552 - Expose the IP address and MAC address to content. r=vcha…
Browse files Browse the repository at this point in the history
…ng f=kaze
  • Loading branch information
mrbkap committed Sep 27, 2012
1 parent 66203f3 commit baf6584
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
14 changes: 12 additions & 2 deletions content/events/src/nsDOMWifiEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,22 @@ nsDOMMozWifiConnectionInfoEvent::GetLinkSpeed(int32_t* aLinkSpeed)
return NS_OK;
}

NS_IMETHODIMP
nsDOMMozWifiConnectionInfoEvent::GetIpAddress(nsAString& aIpAddress)
{
aIpAddress = mIpAddress;
return NS_OK;
}

NS_IMETHODIMP
nsDOMMozWifiConnectionInfoEvent::InitMozWifiConnectionInfoEvent(const nsAString& aType,
bool aCanBubble,
bool aCancelable,
nsIVariant *aNetwork,
int16_t aSignalStrength,
int16_t aRelSignalStrength,
int32_t aLinkSpeed)
int32_t aLinkSpeed,
const nsAString &aIpAddress)
{
nsresult rv = nsDOMEvent::InitEvent(aType, aCanBubble, aCancelable);
NS_ENSURE_SUCCESS(rv, rv);
Expand All @@ -144,6 +152,7 @@ nsDOMMozWifiConnectionInfoEvent::InitMozWifiConnectionInfoEvent(const nsAString&
mSignalStrength = aSignalStrength;
mRelSignalStrength = aRelSignalStrength;
mLinkSpeed = aLinkSpeed;
mIpAddress = aIpAddress;

return NS_OK;
}
Expand All @@ -156,7 +165,8 @@ nsDOMMozWifiConnectionInfoEvent::InitFromCtor(const nsAString& aType,
nsresult rv = d.Init(aCx, aVal);
NS_ENSURE_SUCCESS(rv, rv);
return InitMozWifiConnectionInfoEvent(aType, d.bubbles, d.cancelable, d.network,
d.signalStrength, d.relSignalStrength, d.linkSpeed);
d.signalStrength, d.relSignalStrength, d.linkSpeed,
d.ipAddress);
}

nsresult
Expand Down
5 changes: 3 additions & 2 deletions content/events/src/nsDOMWifiEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class nsDOMMozWifiStatusChangeEvent : public nsDOMEvent,
public:
nsDOMMozWifiStatusChangeEvent(nsPresContext* aPresContext, nsEvent* aEvent)
: nsDOMEvent(aPresContext, aEvent) {}

NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMMozWifiStatusChangeEvent, nsDOMEvent)
// Forward to base class
Expand All @@ -37,7 +37,7 @@ class nsDOMMozWifiConnectionInfoEvent : public nsDOMEvent,
public:
nsDOMMozWifiConnectionInfoEvent(nsPresContext* aPresContext, nsEvent* aEvent)
: nsDOMEvent(aPresContext, aEvent) {}

NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMMozWifiConnectionInfoEvent, nsDOMEvent)
// Forward to base class
Expand All @@ -52,6 +52,7 @@ class nsDOMMozWifiConnectionInfoEvent : public nsDOMEvent,
int16_t mSignalStrength;
int16_t mRelSignalStrength;
int32_t mLinkSpeed;
nsString mIpAddress;
};

#endif // nsDOMWifiEvent_h__
1 change: 1 addition & 0 deletions dom/interfaces/events/nsIWifiEventInits.idl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ dictionary MozWifiConnectionInfoEventInit : EventInit
short signalStrength;
short relSignalStrength;
long linkSpeed;
DOMString ipAddress;
};
11 changes: 10 additions & 1 deletion dom/wifi/DOMWifiManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ DOMWifiManager.prototype = {
this._lastConnectionInfo = state.connectionInfo;
this._enabled = state.enabled;
this._connectionStatus = state.status;
this._macAddress = state.macAddress;
} else {
this._currentNetwork = null;
this._lastConnectionInfo = null;
this._enabled = false;
this._connectionStatus = "disconnected";
this._macAddress = "";
}
},
Expand Down Expand Up @@ -266,7 +268,8 @@ DOMWifiManager.prototype = {
{ network: this._currentNetwork,
signalStrength: info.signalStrength,
relSignalStrength: info.relSignalStrength,
linkSpeed: info.linkSpeed
linkSpeed: info.linkSpeed,
ipAddress: info.ipAddress,
});
this._onConnectionInfoUpdate.handleEvent(evt);
}
Expand Down Expand Up @@ -327,6 +330,12 @@ DOMWifiManager.prototype = {
return this._enabled;
},
get macAddress() {
if (!this._hasPrivileges)
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
return this._macAddress;
},
get connection() {
if (!this._hasPrivileges)
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
Expand Down
16 changes: 14 additions & 2 deletions dom/wifi/WifiWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ function WifiWorker() {
this.configuredNetworks = Object.create(null);

this.currentNetwork = null;
this.ipAddress = "";

this._lastConnectionInfo = null;
this._connectionInfoTimer = null;
Expand Down Expand Up @@ -1486,6 +1487,7 @@ function WifiWorker() {
WifiManager.enabled = true;
self._updateWifiSetting(true);
WifiManager.getMacAddress(function (mac) {
self.macAddress = mac;
debug("Got mac: " + mac);
});

Expand Down Expand Up @@ -1607,6 +1609,7 @@ function WifiWorker() {
case "DISCONNECTED":
self._fireEvent("ondisconnect", {});
self.currentNetwork = null;
self.ipAddress = "";

WifiManager.connectionDropped(function() {
// We've disconnected from a network because of a call to forgetNetwork.
Expand Down Expand Up @@ -1656,6 +1659,13 @@ function WifiWorker() {
kNetworkInterfaceStateChangedTopic,
null);

self.ipAddress = this.info.ipaddr_str;

// We start the connection information timer when we associate, but
// don't have our IP address until here. Make sure that we fire a new
// connectionInformation event with the IP address the next time the
// timer fires.
self._lastConnectionInfo = null;
self._fireEvent("onconnect", { network: netToDOM(self.currentNetwork) });
} else {
WifiManager.reassociate(function(){});
Expand Down Expand Up @@ -1824,7 +1834,8 @@ WifiWorker.prototype = {
let info = { signalStrength: rssi,
relSignalStrength: calculateSignal(rssi),
linkSpeed: linkspeed };
linkSpeed: linkspeed,
ipAddress: self.ipAddress };
let last = self._lastConnectionInfo;
// Only fire the event if the link speed changed or the signal
Expand Down Expand Up @@ -2016,7 +2027,8 @@ WifiWorker.prototype = {
return { network: net,
connectionInfo: this._lastConnectionInfo,
enabled: WifiManager.enabled,
status: translateState(WifiManager.state) };
status: translateState(WifiManager.state),
macAddress: this.macAddress };
}
case "WifiManager:managerFinished": {
for (let i = 0; i < this._domManagers.length; ++i) {
Expand Down
17 changes: 14 additions & 3 deletions dom/wifi/nsIWifi.idl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface nsIWifi : nsISupports
void shutdown();
};

[scriptable, uuid(e3a967e0-015e-11e2-a21f-0800200c9a66)]
[scriptable, uuid(65286912-141e-4aec-ba48-cb7d74851fd8)]
interface nsIDOMWifiManager : nsISupports
{
/**
Expand Down Expand Up @@ -81,6 +81,11 @@ interface nsIDOMWifiManager : nsISupports
*/
readonly attribute boolean enabled;

/**
* Returns the MAC address of the wifi adapter.
*/
readonly attribute DOMString macAddress;

/**
* An non-null object containing the following information:
* - status ("disconnected", "connecting", "associated", "connected")
Expand Down Expand Up @@ -154,7 +159,7 @@ interface nsIDOMMozWifiStatusChangeEvent : nsIDOMEvent
in DOMString status);
};

[scriptable, builtinclass, uuid(34994296-d694-4aed-953d-fc25ee25c050)]
[scriptable, builtinclass, uuid(1717f9d9-5fd8-43d8-a098-55924c6d37de)]
interface nsIDOMMozWifiConnectionInfoEvent : nsIDOMEvent
{
/**
Expand All @@ -177,11 +182,17 @@ interface nsIDOMMozWifiConnectionInfoEvent : nsIDOMEvent
*/
readonly attribute long linkSpeed;

/**
* IP address in the dotted quad format.
*/
readonly attribute DOMString ipAddress;

[noscript] void initMozWifiConnectionInfoEvent(in DOMString aType,
in boolean aCanBubble,
in boolean aCancelable,
in nsIVariant aNetwork,
in short signalStrength,
in short relSignalStrength,
in long linkSpeed);
in long linkSpeed,
in DOMString ipAddress);
};

0 comments on commit baf6584

Please sign in to comment.