2014-06-24 22:12:07 -07:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2012-03-14 13:39:15 -07:00
|
|
|
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2012-03-20 08:59:38 -07:00
|
|
|
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
2012-03-14 13:39:15 -07:00
|
|
|
|
2012-04-11 10:05:35 -07:00
|
|
|
const DEBUG = false; // set to false to suppress debug messages
|
2012-03-14 13:39:15 -07:00
|
|
|
|
|
|
|
const DOMWIFIMANAGER_CONTRACTID = "@mozilla.org/wifimanager;1";
|
2014-04-09 20:34:29 -07:00
|
|
|
const DOMWIFIMANAGER_CID = Components.ID("{c9b5f09e-25d2-40ca-aef4-c4d13d93c706}");
|
2012-03-14 13:39:15 -07:00
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
function MozWifiNetwork() {
|
2012-03-14 13:39:15 -07:00
|
|
|
}
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
MozWifiNetwork.prototype = {
|
|
|
|
|
|
|
|
init: function(aWindow) {
|
|
|
|
this._window = aWindow;
|
|
|
|
},
|
|
|
|
|
|
|
|
__init: function(obj) {
|
|
|
|
for (let key in obj) {
|
|
|
|
this[key] = obj[key];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{c01fd751-43c0-460a-8b64-abf652ec7220}"),
|
|
|
|
contractID: "@mozilla.org/mozwifinetwork;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
|
|
|
Ci.nsIDOMGlobalPropertyInitializer])
|
|
|
|
};
|
|
|
|
|
|
|
|
function MozWifiConnection(obj) {
|
|
|
|
this.status = obj.status;
|
|
|
|
this.network = obj.network;
|
2012-07-02 01:58:17 -07:00
|
|
|
}
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
MozWifiConnection.prototype = {
|
|
|
|
classID: Components.ID("{23579da4-201b-4319-bd42-9b7f337343ac}"),
|
|
|
|
contractID: "@mozilla.org/mozwificonnection;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports])
|
2012-07-02 01:58:17 -07:00
|
|
|
};
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
function MozWifiConnectionInfo(obj) {
|
|
|
|
this.signalStrength = obj.signalStrength;
|
|
|
|
this.relSignalStrength = obj.relSignalStrength;
|
|
|
|
this.linkSpeed = obj.linkSpeed;
|
|
|
|
this.ipAddress = obj.ipAddress;
|
2014-04-09 20:34:29 -07:00
|
|
|
}
|
2014-03-21 11:44:05 -07:00
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
MozWifiConnectionInfo.prototype = {
|
|
|
|
classID: Components.ID("{83670352-6ed4-4c35-8de9-402296a1959c}"),
|
|
|
|
contractID: "@mozilla.org/mozwificonnectioninfo;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports])
|
|
|
|
}
|
2014-04-14 03:24:21 -07:00
|
|
|
|
2014-05-18 19:29:21 -07:00
|
|
|
function MozWifiCapabilities(obj) {
|
|
|
|
this.security = obj.security;
|
|
|
|
this.eapMethod = obj.eapMethod;
|
|
|
|
this.eapPhase2 = obj.eapPhase2;
|
|
|
|
this.certificate = obj.certificate;
|
|
|
|
}
|
|
|
|
|
|
|
|
MozWifiCapabilities.prototype = {
|
|
|
|
classID: Components.ID("08c88ece-8092-481b-863b-5515a52e411a"),
|
|
|
|
contractID: "@mozilla.org/mozwificapabilities;1",
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports])
|
|
|
|
}
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
function DOMWifiManager() {
|
|
|
|
this.defineEventHandlerGetterSetter("onstatuschange");
|
2014-07-03 23:37:55 -07:00
|
|
|
this.defineEventHandlerGetterSetter("onconnectioninfoupdate");
|
2014-04-09 20:34:29 -07:00
|
|
|
this.defineEventHandlerGetterSetter("onenabled");
|
|
|
|
this.defineEventHandlerGetterSetter("ondisabled");
|
2014-07-03 23:37:55 -07:00
|
|
|
this.defineEventHandlerGetterSetter("onstationinfoupdate");
|
2014-04-09 20:34:29 -07:00
|
|
|
}
|
2014-04-14 03:24:21 -07:00
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
DOMWifiManager.prototype = {
|
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
|
|
|
classDescription: "DOMWifiManager",
|
|
|
|
classID: DOMWIFIMANAGER_CID,
|
|
|
|
contractID: DOMWIFIMANAGER_CONTRACTID,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
|
2013-11-19 21:33:10 -08:00
|
|
|
Ci.nsISupportsWeakReference,
|
|
|
|
Ci.nsIObserver]),
|
2012-03-14 13:39:15 -07:00
|
|
|
|
|
|
|
// nsIDOMGlobalPropertyInitializer implementation
|
|
|
|
init: function(aWindow) {
|
|
|
|
// Maintain this state for synchronous APIs.
|
|
|
|
this._currentNetwork = null;
|
2012-04-08 20:32:17 -07:00
|
|
|
this._connectionStatus = "disconnected";
|
2012-09-03 21:26:56 -07:00
|
|
|
this._enabled = false;
|
2012-03-26 09:26:32 -07:00
|
|
|
this._lastConnectionInfo = null;
|
2014-05-18 19:29:21 -07:00
|
|
|
this._capabilities = null;
|
2014-01-22 00:37:40 -08:00
|
|
|
this._stationNumber = 0;
|
2012-03-14 13:39:15 -07:00
|
|
|
|
2012-09-03 21:26:56 -07:00
|
|
|
const messages = ["WifiManager:getNetworks:Return:OK", "WifiManager:getNetworks:Return:NO",
|
2012-09-27 11:18:34 -07:00
|
|
|
"WifiManager:getKnownNetworks:Return:OK", "WifiManager:getKnownNetworks:Return:NO",
|
2012-03-14 13:39:15 -07:00
|
|
|
"WifiManager:associate:Return:OK", "WifiManager:associate:Return:NO",
|
2012-03-26 09:27:10 -07:00
|
|
|
"WifiManager:forget:Return:OK", "WifiManager:forget:Return:NO",
|
2012-08-16 15:19:51 -07:00
|
|
|
"WifiManager:wps:Return:OK", "WifiManager:wps:Return:NO",
|
2012-09-24 02:05:47 -07:00
|
|
|
"WifiManager:setPowerSavingMode:Return:OK", "WifiManager:setPowerSavingMode:Return:NO",
|
2013-08-22 03:22:25 -07:00
|
|
|
"WifiManager:setHttpProxy:Return:OK", "WifiManager:setHttpProxy:Return:NO",
|
2013-06-23 20:02:30 -07:00
|
|
|
"WifiManager:setStaticIpMode:Return:OK", "WifiManager:setStaticIpMode:Return:NO",
|
2014-04-30 04:58:40 -07:00
|
|
|
"WifiManager:importCert:Return:OK", "WifiManager:importCert:Return:NO",
|
2014-04-30 04:58:45 -07:00
|
|
|
"WifiManager:getImportedCerts:Return:OK", "WifiManager:getImportedCerts:Return:NO",
|
2014-04-28 00:50:11 -07:00
|
|
|
"WifiManager:deleteCert:Return:OK", "WifiManager:deleteCert:Return:NO",
|
2014-08-07 02:19:31 -07:00
|
|
|
"WifiManager:setWifiEnabled:Return:OK", "WifiManager:setWifiEnabled:Return:NO",
|
2012-06-28 03:01:51 -07:00
|
|
|
"WifiManager:wifiDown", "WifiManager:wifiUp",
|
2012-03-20 08:31:10 -07:00
|
|
|
"WifiManager:onconnecting", "WifiManager:onassociate",
|
2012-03-26 09:26:32 -07:00
|
|
|
"WifiManager:onconnect", "WifiManager:ondisconnect",
|
2012-08-16 15:19:51 -07:00
|
|
|
"WifiManager:onwpstimeout", "WifiManager:onwpsfail",
|
2014-07-03 23:37:55 -07:00
|
|
|
"WifiManager:onwpsoverlap", "WifiManager:connectioninfoupdate",
|
2014-01-22 00:37:40 -08:00
|
|
|
"WifiManager:onauthenticating", "WifiManager:onconnectingfailed",
|
2014-07-03 23:37:55 -07:00
|
|
|
"WifiManager:stationinfoupdate"];
|
2013-07-08 14:55:42 -07:00
|
|
|
this.initDOMRequestHelper(aWindow, messages);
|
2012-03-14 13:39:15 -07:00
|
|
|
this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
|
|
|
|
2012-03-26 09:26:32 -07:00
|
|
|
var state = this._mm.sendSyncMessage("WifiManager:getState")[0];
|
2012-03-27 12:04:16 -07:00
|
|
|
if (state) {
|
2014-04-09 20:34:29 -07:00
|
|
|
this._currentNetwork = this._convertWifiNetwork(state.network);
|
|
|
|
this._lastConnectionInfo = this._convertConnectionInfo(state.connectionInfo);
|
2012-03-27 12:04:16 -07:00
|
|
|
this._enabled = state.enabled;
|
2012-04-08 20:32:17 -07:00
|
|
|
this._connectionStatus = state.status;
|
2012-09-27 11:14:06 -07:00
|
|
|
this._macAddress = state.macAddress;
|
2014-05-18 19:29:21 -07:00
|
|
|
this._capabilities = this._convertWifiCapabilities(state.capabilities);
|
2012-03-27 12:04:16 -07:00
|
|
|
} else {
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._lastConnectionInfo = null;
|
2012-04-08 20:32:17 -07:00
|
|
|
this._enabled = false;
|
|
|
|
this._connectionStatus = "disconnected";
|
2012-09-27 11:14:06 -07:00
|
|
|
this._macAddress = "";
|
2012-03-27 12:04:16 -07:00
|
|
|
}
|
2012-03-14 13:39:15 -07:00
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
_convertWifiNetworkToJSON: function(aNetwork) {
|
|
|
|
let json = {};
|
|
|
|
|
|
|
|
for (let key in aNetwork) {
|
|
|
|
// In WifiWorker.js there are lots of check using "key in network".
|
|
|
|
// So if the value of any property of WifiNetwork is undefined, do not clone it.
|
|
|
|
if (aNetwork[key] != undefined) {
|
|
|
|
json[key] = aNetwork[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return json;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertWifiNetwork: function(aNetwork) {
|
|
|
|
let network = aNetwork ? new this._window.MozWifiNetwork(aNetwork) : null;
|
|
|
|
return network;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertWifiNetworks: function(aNetworks) {
|
2014-10-03 01:05:51 -07:00
|
|
|
let networks = new this._window.Array();
|
2014-04-09 20:34:29 -07:00
|
|
|
for (let i in aNetworks) {
|
|
|
|
networks.push(this._convertWifiNetwork(aNetworks[i]));
|
|
|
|
}
|
|
|
|
return networks;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertConnection: function(aConn) {
|
|
|
|
let conn = aConn ? new MozWifiConnection(aConn) : null;
|
|
|
|
return conn;
|
|
|
|
},
|
|
|
|
|
|
|
|
_convertConnectionInfo: function(aInfo) {
|
|
|
|
let info = aInfo ? new MozWifiConnectionInfo(aInfo) : null;
|
|
|
|
return info;
|
2012-03-14 13:39:15 -07:00
|
|
|
},
|
|
|
|
|
2014-05-18 19:29:21 -07:00
|
|
|
_convertWifiCapabilities: function(aCapabilities) {
|
|
|
|
let capabilities = aCapabilities ?
|
|
|
|
new MozWifiCapabilities(aCapabilities) : null;
|
|
|
|
return capabilities;
|
|
|
|
},
|
|
|
|
|
2012-03-14 13:39:15 -07:00
|
|
|
_sendMessageForRequest: function(name, data, request) {
|
2012-03-20 08:59:38 -07:00
|
|
|
let id = this.getRequestId(request);
|
2012-03-14 13:39:15 -07:00
|
|
|
this._mm.sendAsyncMessage(name, { data: data, rid: id, mid: this._id });
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveMessage: function(aMessage) {
|
|
|
|
let msg = aMessage.json;
|
|
|
|
if (msg.mid && msg.mid != this._id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
let request;
|
2014-03-12 03:25:32 -07:00
|
|
|
if (msg.rid) {
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
if (!request) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 13:39:15 -07:00
|
|
|
switch (aMessage.name) {
|
2014-08-07 02:19:31 -07:00
|
|
|
case "WifiManager:setWifiEnabled:Return:OK":
|
|
|
|
Services.DOMRequest.fireSuccess(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:setWifiEnabled:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, "Unable to enable/disable Wifi");
|
|
|
|
break;
|
|
|
|
|
2012-03-14 13:39:15 -07:00
|
|
|
case "WifiManager:getNetworks:Return:OK":
|
2014-04-09 20:34:29 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, this._convertWifiNetworks(msg.data));
|
2012-03-14 13:39:15 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:getNetworks:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, "Unable to scan for networks");
|
|
|
|
break;
|
|
|
|
|
2012-09-27 11:18:34 -07:00
|
|
|
case "WifiManager:getKnownNetworks:Return:OK":
|
2014-04-09 20:34:29 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, this._convertWifiNetworks(msg.data));
|
2012-09-27 11:18:34 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:getKnownNetworks:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, "Unable to get known networks");
|
|
|
|
break;
|
|
|
|
|
2012-03-14 13:39:15 -07:00
|
|
|
case "WifiManager:associate:Return:OK":
|
|
|
|
Services.DOMRequest.fireSuccess(request, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:associate:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, "Unable to add the network");
|
|
|
|
break;
|
|
|
|
|
2012-03-26 09:27:10 -07:00
|
|
|
case "WifiManager:forget:Return:OK":
|
|
|
|
Services.DOMRequest.fireSuccess(request, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:forget:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2012-08-16 15:19:51 -07:00
|
|
|
case "WifiManager:wps:Return:OK":
|
2014-04-09 20:34:29 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, msg.data);
|
2012-08-16 15:19:51 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:wps:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2012-09-24 02:05:47 -07:00
|
|
|
case "WifiManager:setPowerSavingMode:Return:OK":
|
2014-04-09 20:34:29 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, msg.data);
|
2012-09-24 02:05:47 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:setPowerSavingMode:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2013-08-22 03:22:25 -07:00
|
|
|
case "WifiManager:setHttpProxy:Return:OK":
|
2014-04-09 20:34:29 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, msg.data);
|
2013-08-22 03:22:25 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:setHttpProxy:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2013-06-23 20:02:30 -07:00
|
|
|
case "WifiManager:setStaticIpMode:Return:OK":
|
2014-04-09 20:34:29 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, msg.data);
|
2013-06-23 20:02:30 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:setStaticIpMode:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2014-04-30 04:58:40 -07:00
|
|
|
case "WifiManager:importCert:Return:OK":
|
2014-10-07 03:06:03 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, Cu.cloneInto(msg.data, this._window));
|
2014-04-30 04:58:40 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:importCert:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2014-04-30 04:58:45 -07:00
|
|
|
case "WifiManager:getImportedCerts:Return:OK":
|
2014-10-07 03:06:03 -07:00
|
|
|
Services.DOMRequest.fireSuccess(request, Cu.cloneInto(msg.data, this._window));
|
2014-04-30 04:58:45 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:getImportedCerts:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2014-04-28 00:50:11 -07:00
|
|
|
case "WifiManager:deleteCert:Return:OK":
|
|
|
|
Services.DOMRequest.fireSuccess(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:deleteCert:Return:NO":
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2012-06-28 03:01:51 -07:00
|
|
|
case "WifiManager:wifiDown":
|
|
|
|
this._enabled = false;
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._fireEnabledOrDisabled(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:wifiUp":
|
|
|
|
this._enabled = true;
|
2013-03-15 09:58:41 -07:00
|
|
|
this._macAddress = msg.macAddress;
|
2012-06-28 03:01:51 -07:00
|
|
|
this._fireEnabledOrDisabled(true);
|
|
|
|
break;
|
|
|
|
|
2012-03-20 08:31:10 -07:00
|
|
|
case "WifiManager:onconnecting":
|
2014-04-09 20:34:29 -07:00
|
|
|
this._currentNetwork = this._convertWifiNetwork(msg.network);
|
2012-04-08 20:32:17 -07:00
|
|
|
this._connectionStatus = "connecting";
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-03-20 08:31:10 -07:00
|
|
|
break;
|
|
|
|
|
2012-03-14 13:39:15 -07:00
|
|
|
case "WifiManager:onassociate":
|
2014-04-09 20:34:29 -07:00
|
|
|
this._currentNetwork = this._convertWifiNetwork(msg.network);
|
2012-04-08 20:32:17 -07:00
|
|
|
this._connectionStatus = "associated";
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-03-14 13:39:15 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:onconnect":
|
2014-04-09 20:34:29 -07:00
|
|
|
this._currentNetwork = this._convertWifiNetwork(msg.network);
|
2012-04-08 20:32:17 -07:00
|
|
|
this._connectionStatus = "connected";
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-03-14 13:39:15 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:ondisconnect":
|
|
|
|
this._currentNetwork = null;
|
2012-04-08 20:32:17 -07:00
|
|
|
this._connectionStatus = "disconnected";
|
2012-03-26 09:26:32 -07:00
|
|
|
this._lastConnectionInfo = null;
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-03-26 09:26:32 -07:00
|
|
|
break;
|
|
|
|
|
2012-08-16 15:19:51 -07:00
|
|
|
case "WifiManager:onwpstimeout":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "wps-timedout";
|
|
|
|
this._lastConnectionInfo = null;
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-08-16 15:19:51 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:onwpsfail":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "wps-failed";
|
|
|
|
this._lastConnectionInfo = null;
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-08-16 15:19:51 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:onwpsoverlap":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "wps-overlapped";
|
|
|
|
this._lastConnectionInfo = null;
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-08-16 15:19:51 -07:00
|
|
|
break;
|
|
|
|
|
2014-07-03 23:37:55 -07:00
|
|
|
case "WifiManager:connectioninfoupdate":
|
2014-04-09 20:34:29 -07:00
|
|
|
this._lastConnectionInfo = this._convertConnectionInfo(msg);
|
2012-03-26 09:26:32 -07:00
|
|
|
this._fireConnectionInfoUpdate(msg);
|
2012-03-14 13:39:15 -07:00
|
|
|
break;
|
2012-08-28 12:14:26 -07:00
|
|
|
case "WifiManager:onconnectingfailed":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "connectingfailed";
|
|
|
|
this._lastConnectionInfo = null;
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2012-08-28 12:14:26 -07:00
|
|
|
break;
|
2014-04-25 03:41:26 -07:00
|
|
|
case "WifiManager:onauthenticating":
|
2014-09-17 00:08:18 -07:00
|
|
|
this._currentNetwork = this._convertWifiNetwork(msg.network);
|
2014-04-25 03:41:26 -07:00
|
|
|
this._connectionStatus = "authenticating";
|
2014-09-17 00:08:18 -07:00
|
|
|
this._fireStatusChangeEvent(msg.network);
|
2014-04-25 03:41:26 -07:00
|
|
|
break;
|
2014-07-03 23:37:55 -07:00
|
|
|
case "WifiManager:stationinfoupdate":
|
2014-01-22 00:37:40 -08:00
|
|
|
this._stationNumber = msg.station;
|
|
|
|
this._fireStationInfoUpdate(msg);
|
|
|
|
break;
|
2012-03-14 13:39:15 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-09-17 00:08:18 -07:00
|
|
|
_fireStatusChangeEvent: function StatusChangeEvent(aNetwork) {
|
2014-04-09 20:34:29 -07:00
|
|
|
var event = new this._window.MozWifiStatusChangeEvent("statuschange",
|
2014-09-17 00:08:18 -07:00
|
|
|
{ network: this._convertWifiNetwork(aNetwork),
|
2014-04-09 20:34:29 -07:00
|
|
|
status: this._connectionStatus
|
|
|
|
});
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(event);
|
2012-03-26 09:26:32 -07:00
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
_fireConnectionInfoUpdate: function onConnectionInfoUpdate(info) {
|
|
|
|
var evt = new this._window.MozWifiConnectionInfoEvent("connectioninfoupdate",
|
|
|
|
{ network: this._currentNetwork,
|
|
|
|
signalStrength: info.signalStrength,
|
|
|
|
relSignalStrength: info.relSignalStrength,
|
|
|
|
linkSpeed: info.linkSpeed,
|
|
|
|
ipAddress: info.ipAddress,
|
|
|
|
});
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(evt);
|
2012-03-14 13:39:15 -07:00
|
|
|
},
|
|
|
|
|
2012-06-28 03:01:51 -07:00
|
|
|
_fireEnabledOrDisabled: function enabledDisabled(enabled) {
|
2014-04-09 20:34:29 -07:00
|
|
|
var evt = new this._window.Event(enabled ? "enabled" : "disabled");
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(evt);
|
2012-06-28 03:01:51 -07:00
|
|
|
},
|
|
|
|
|
2014-01-22 00:37:40 -08:00
|
|
|
_fireStationInfoUpdate: function onStationInfoUpdate(info) {
|
2014-07-03 23:37:55 -07:00
|
|
|
var evt = new this._window.MozWifiStationInfoEvent("stationinfoupdate",
|
2014-01-22 00:37:40 -08:00
|
|
|
{ station: this._stationNumber}
|
|
|
|
);
|
|
|
|
this.__DOM_IMPL__.dispatchEvent(evt);
|
|
|
|
},
|
|
|
|
|
2014-08-07 02:19:31 -07:00
|
|
|
setWifiEnabled: function setWifiEnabled(enabled) {
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:setWifiEnabled", enabled, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
getNetworks: function getNetworks() {
|
2012-03-20 08:59:38 -07:00
|
|
|
var request = this.createRequest();
|
2012-03-14 13:39:15 -07:00
|
|
|
this._sendMessageForRequest("WifiManager:getNetworks", null, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
getKnownNetworks: function getKnownNetworks() {
|
2012-09-27 11:18:34 -07:00
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:getKnownNetworks", null, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
associate: function associate(network) {
|
2012-03-20 08:59:38 -07:00
|
|
|
var request = this.createRequest();
|
2014-04-09 20:34:29 -07:00
|
|
|
this._sendMessageForRequest("WifiManager:associate",
|
|
|
|
this._convertWifiNetworkToJSON(network), request);
|
2012-03-14 13:39:15 -07:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
forget: function forget(network) {
|
2012-04-13 00:54:11 -07:00
|
|
|
var request = this.createRequest();
|
2014-04-09 20:34:29 -07:00
|
|
|
this._sendMessageForRequest("WifiManager:forget",
|
|
|
|
this._convertWifiNetworkToJSON(network), request);
|
2012-03-26 09:27:10 -07:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
wps: function wps(detail) {
|
2012-08-16 15:19:51 -07:00
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:wps", detail, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
setPowerSavingMode: function setPowerSavingMode(enabled) {
|
2012-09-24 02:05:47 -07:00
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:setPowerSavingMode", enabled, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
setHttpProxy: function setHttpProxy(network, info) {
|
2013-08-22 03:22:25 -07:00
|
|
|
var request = this.createRequest();
|
2014-04-09 20:34:29 -07:00
|
|
|
this._sendMessageForRequest("WifiManager:setHttpProxy",
|
|
|
|
{ network: this._convertWifiNetworkToJSON(network), info:info}, request);
|
2013-08-22 03:22:25 -07:00
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
setStaticIpMode: function setStaticIpMode(network, info) {
|
2013-06-23 20:02:30 -07:00
|
|
|
var request = this.createRequest();
|
2014-04-09 20:34:29 -07:00
|
|
|
this._sendMessageForRequest("WifiManager:setStaticIpMode",
|
|
|
|
{ network: this._convertWifiNetworkToJSON(network), info: info}, request);
|
2013-06-23 20:02:30 -07:00
|
|
|
return request;
|
2014-04-30 04:58:40 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
importCert: function nsIDOMWifiManager_importCert(certBlob, certPassword, certNickname) {
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:importCert",
|
|
|
|
{
|
|
|
|
certBlob: certBlob,
|
|
|
|
certPassword: certPassword,
|
|
|
|
certNickname: certNickname
|
|
|
|
}, request);
|
|
|
|
return request;
|
2014-04-30 04:58:45 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getImportedCerts: function nsIDOMWifiManager_getImportedCerts() {
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:getImportedCerts", null, request);
|
|
|
|
return request;
|
2014-04-28 00:50:11 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
deleteCert: function nsIDOMWifiManager_deleteCert(certNickname) {
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:deleteCert",
|
|
|
|
{
|
|
|
|
certNickname: certNickname
|
|
|
|
}, request);
|
|
|
|
return request;
|
2013-06-23 20:02:30 -07:00
|
|
|
},
|
|
|
|
|
2012-03-14 13:39:15 -07:00
|
|
|
get enabled() {
|
|
|
|
return this._enabled;
|
|
|
|
},
|
|
|
|
|
2012-09-27 11:14:06 -07:00
|
|
|
get macAddress() {
|
|
|
|
return this._macAddress;
|
|
|
|
},
|
|
|
|
|
2012-04-08 20:32:17 -07:00
|
|
|
get connection() {
|
2014-04-09 20:34:29 -07:00
|
|
|
let _connection = this._convertConnection({ status: this._connectionStatus,
|
|
|
|
network: this._currentNetwork,
|
|
|
|
});
|
|
|
|
return _connection;
|
2012-03-14 13:39:15 -07:00
|
|
|
},
|
|
|
|
|
2012-07-31 14:27:46 -07:00
|
|
|
get connectionInformation() {
|
2014-04-09 20:34:29 -07:00
|
|
|
return this._lastConnectionInfo;
|
2014-04-14 03:24:21 -07:00
|
|
|
},
|
|
|
|
|
2014-05-18 19:29:21 -07:00
|
|
|
get capabilities() {
|
|
|
|
return this._capabilities;
|
|
|
|
},
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
defineEventHandlerGetterSetter: function(name) {
|
|
|
|
Object.defineProperty(this, name, {
|
|
|
|
get: function() {
|
|
|
|
return this.__DOM_IMPL__.getEventHandler(name);
|
|
|
|
},
|
|
|
|
set: function(handler) {
|
|
|
|
this.__DOM_IMPL__.setEventHandler(name, handler);
|
|
|
|
}
|
|
|
|
});
|
2014-04-14 03:24:21 -07:00
|
|
|
},
|
2012-03-14 13:39:15 -07:00
|
|
|
};
|
|
|
|
|
2014-04-09 20:34:29 -07:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
|
2014-05-18 19:29:21 -07:00
|
|
|
DOMWifiManager, MozWifiNetwork, MozWifiConnection, MozWifiCapabilities,
|
|
|
|
MozWifiConnectionInfo
|
2014-04-09 20:34:29 -07:00
|
|
|
]);
|
2012-03-14 13:39:15 -07:00
|
|
|
|
2015-09-15 11:19:45 -07:00
|
|
|
var debug;
|
2012-03-14 13:39:15 -07:00
|
|
|
if (DEBUG) {
|
|
|
|
debug = function (s) {
|
2012-03-16 09:51:05 -07:00
|
|
|
dump("-*- DOMWifiManager component: " + s + "\n");
|
2012-03-14 13:39:15 -07:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
debug = function (s) {};
|
|
|
|
}
|