2012-03-14 20:39:15 +00:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 15:59:38 +00:00
|
|
|
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
|
2012-03-14 20:39:15 +00:00
|
|
|
|
2012-04-11 17:05:35 +00:00
|
|
|
const DEBUG = false; // set to false to suppress debug messages
|
2012-03-14 20:39:15 +00:00
|
|
|
|
|
|
|
const DOMWIFIMANAGER_CONTRACTID = "@mozilla.org/wifimanager;1";
|
|
|
|
const DOMWIFIMANAGER_CID = Components.ID("{2cf775a7-1837-410c-9e26-323c42e076da}");
|
|
|
|
|
2012-03-16 16:51:05 +00:00
|
|
|
function DOMWifiManager() {
|
2012-03-14 20:39:15 +00:00
|
|
|
}
|
|
|
|
|
2012-07-02 08:58:17 +00:00
|
|
|
function exposeCurrentNetwork(currentNetwork) {
|
|
|
|
currentNetwork.__exposedProps__ = exposeCurrentNetwork.currentNetworkApi;
|
|
|
|
}
|
|
|
|
|
|
|
|
exposeCurrentNetwork.currentNetworkApi = {
|
|
|
|
ssid: "r",
|
2013-07-08 11:41:48 +00:00
|
|
|
security: "r",
|
2012-11-08 07:32:16 +00:00
|
|
|
capabilities: "r",
|
2012-07-02 08:58:17 +00:00
|
|
|
known: "r"
|
|
|
|
};
|
|
|
|
|
|
|
|
// For smaller, read-only APIs, we expose any property that doesn't begin with
|
|
|
|
// an underscore.
|
|
|
|
function exposeReadOnly(obj) {
|
|
|
|
var exposedProps = {};
|
|
|
|
for (let i in obj) {
|
|
|
|
if (i[0] === "_")
|
|
|
|
continue;
|
|
|
|
exposedProps[i] = "r";
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.__exposedProps__ = exposedProps;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2012-03-16 16:51:05 +00:00
|
|
|
DOMWifiManager.prototype = {
|
2012-03-20 15:59:38 +00:00
|
|
|
__proto__: DOMRequestIpcHelper.prototype,
|
|
|
|
|
2012-03-14 20:39:15 +00:00
|
|
|
classID: DOMWIFIMANAGER_CID,
|
|
|
|
classInfo: XPCOMUtils.generateCI({classID: DOMWIFIMANAGER_CID,
|
|
|
|
contractID: DOMWIFIMANAGER_CONTRACTID,
|
2012-03-16 16:51:05 +00:00
|
|
|
classDescription: "DOMWifiManager",
|
2012-03-14 20:39:15 +00:00
|
|
|
interfaces: [Ci.nsIDOMWifiManager],
|
|
|
|
flags: Ci.nsIClassInfo.DOM_OBJECT}),
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMWifiManager,
|
2013-07-08 21:55:42 +00:00
|
|
|
Ci.nsIDOMGlobalPropertyInitializer,
|
|
|
|
Ci.nsISupportsWeakReference]),
|
2012-03-14 20:39:15 +00:00
|
|
|
|
|
|
|
// nsIDOMGlobalPropertyInitializer implementation
|
|
|
|
init: function(aWindow) {
|
|
|
|
let principal = aWindow.document.nodePrincipal;
|
|
|
|
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
|
|
|
|
|
2012-07-16 15:44:52 +00:00
|
|
|
let perm = principal == secMan.getSystemPrincipal()
|
|
|
|
? Ci.nsIPermissionManager.ALLOW_ACTION
|
|
|
|
: Services.perms.testExactPermissionFromPrincipal(principal, "wifi-manage");
|
2012-03-14 20:39:15 +00:00
|
|
|
|
|
|
|
// Only pages with perm set can use the wifi manager.
|
|
|
|
this._hasPrivileges = perm == Ci.nsIPermissionManager.ALLOW_ACTION;
|
|
|
|
|
2013-04-16 08:54:00 +00:00
|
|
|
if (!this._hasPrivileges) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-03-14 20:39:15 +00:00
|
|
|
// Maintain this state for synchronous APIs.
|
|
|
|
this._currentNetwork = null;
|
2012-04-09 03:32:17 +00:00
|
|
|
this._connectionStatus = "disconnected";
|
2012-09-04 04:26:56 +00:00
|
|
|
this._enabled = false;
|
2012-03-26 16:26:32 +00:00
|
|
|
this._lastConnectionInfo = null;
|
2012-03-14 20:39:15 +00:00
|
|
|
|
2012-09-04 04:26:56 +00:00
|
|
|
const messages = ["WifiManager:getNetworks:Return:OK", "WifiManager:getNetworks:Return:NO",
|
2012-09-27 18:18:34 +00:00
|
|
|
"WifiManager:getKnownNetworks:Return:OK", "WifiManager:getKnownNetworks:Return:NO",
|
2012-03-14 20:39:15 +00:00
|
|
|
"WifiManager:associate:Return:OK", "WifiManager:associate:Return:NO",
|
2012-03-26 16:27:10 +00:00
|
|
|
"WifiManager:forget:Return:OK", "WifiManager:forget:Return:NO",
|
2012-08-16 22:19:51 +00:00
|
|
|
"WifiManager:wps:Return:OK", "WifiManager:wps:Return:NO",
|
2012-09-24 09:05:47 +00:00
|
|
|
"WifiManager:setPowerSavingMode:Return:OK", "WifiManager:setPowerSavingMode:Return:NO",
|
2013-06-24 03:02:30 +00:00
|
|
|
"WifiManager:setStaticIpMode:Return:OK", "WifiManager:setStaticIpMode:Return:NO",
|
2012-06-28 10:01:51 +00:00
|
|
|
"WifiManager:wifiDown", "WifiManager:wifiUp",
|
2012-03-20 15:31:10 +00:00
|
|
|
"WifiManager:onconnecting", "WifiManager:onassociate",
|
2012-03-26 16:26:32 +00:00
|
|
|
"WifiManager:onconnect", "WifiManager:ondisconnect",
|
2012-08-16 22:19:51 +00:00
|
|
|
"WifiManager:onwpstimeout", "WifiManager:onwpsfail",
|
2012-08-28 19:14:26 +00:00
|
|
|
"WifiManager:onwpsoverlap", "WifiManager:connectionInfoUpdate",
|
|
|
|
"WifiManager:onconnectingfailed"];
|
2013-07-08 21:55:42 +00:00
|
|
|
this.initDOMRequestHelper(aWindow, messages);
|
2012-03-14 20:39:15 +00:00
|
|
|
this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
|
|
|
|
|
2012-03-26 16:26:32 +00:00
|
|
|
var state = this._mm.sendSyncMessage("WifiManager:getState")[0];
|
2012-03-27 19:04:16 +00:00
|
|
|
if (state) {
|
|
|
|
this._currentNetwork = state.network;
|
2012-07-02 08:58:17 +00:00
|
|
|
if (this._currentNetwork)
|
|
|
|
exposeCurrentNetwork(this._currentNetwork);
|
2012-03-27 19:04:16 +00:00
|
|
|
this._lastConnectionInfo = state.connectionInfo;
|
|
|
|
this._enabled = state.enabled;
|
2012-04-09 03:32:17 +00:00
|
|
|
this._connectionStatus = state.status;
|
2012-09-27 18:14:06 +00:00
|
|
|
this._macAddress = state.macAddress;
|
2012-03-27 19:04:16 +00:00
|
|
|
} else {
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._lastConnectionInfo = null;
|
2012-04-09 03:32:17 +00:00
|
|
|
this._enabled = false;
|
|
|
|
this._connectionStatus = "disconnected";
|
2012-09-27 18:14:06 +00:00
|
|
|
this._macAddress = "";
|
2012-03-27 19:04:16 +00:00
|
|
|
}
|
2012-03-14 20:39:15 +00:00
|
|
|
},
|
|
|
|
|
2012-03-20 15:59:38 +00:00
|
|
|
uninit: function() {
|
2012-06-28 10:01:51 +00:00
|
|
|
this._onStatusChange = null;
|
2012-03-26 16:26:32 +00:00
|
|
|
this._onConnectionInfoUpdate = null;
|
2012-06-28 10:01:51 +00:00
|
|
|
this._onEnabled = null;
|
|
|
|
this._onDisabled = null;
|
2012-03-14 20:39:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_sendMessageForRequest: function(name, data, request) {
|
2012-03-20 15:59:38 +00:00
|
|
|
let id = this.getRequestId(request);
|
2012-03-14 20:39:15 +00: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;
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "WifiManager:getNetworks:Return:OK":
|
2012-03-20 15:59:38 +00:00
|
|
|
request = this.takeRequest(msg.rid);
|
2012-07-02 08:58:17 +00:00
|
|
|
Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
|
2012-03-14 20:39:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:getNetworks:Return:NO":
|
2012-03-20 15:59:38 +00:00
|
|
|
request = this.takeRequest(msg.rid);
|
2012-03-14 20:39:15 +00:00
|
|
|
Services.DOMRequest.fireError(request, "Unable to scan for networks");
|
|
|
|
break;
|
|
|
|
|
2012-09-27 18:18:34 +00:00
|
|
|
case "WifiManager:getKnownNetworks:Return:OK":
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:getKnownNetworks:Return:NO":
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
Services.DOMRequest.fireError(request, "Unable to get known networks");
|
|
|
|
break;
|
|
|
|
|
2012-03-14 20:39:15 +00:00
|
|
|
case "WifiManager:associate:Return:OK":
|
2012-03-20 15:59:38 +00:00
|
|
|
request = this.takeRequest(msg.rid);
|
2012-03-14 20:39:15 +00:00
|
|
|
Services.DOMRequest.fireSuccess(request, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:associate:Return:NO":
|
2012-03-20 15:59:38 +00:00
|
|
|
request = this.takeRequest(msg.rid);
|
2012-03-14 20:39:15 +00:00
|
|
|
Services.DOMRequest.fireError(request, "Unable to add the network");
|
|
|
|
break;
|
|
|
|
|
2012-03-26 16:27:10 +00:00
|
|
|
case "WifiManager:forget:Return:OK":
|
2012-04-13 07:54:11 +00:00
|
|
|
request = this.takeRequest(msg.rid);
|
2012-03-26 16:27:10 +00:00
|
|
|
Services.DOMRequest.fireSuccess(request, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:forget:Return:NO":
|
2012-04-13 07:54:11 +00:00
|
|
|
request = this.takeRequest(msg.rid);
|
2012-03-26 16:27:10 +00:00
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2012-08-16 22:19:51 +00:00
|
|
|
case "WifiManager:wps:Return:OK":
|
|
|
|
request = this.takeRequest(msg.rid);
|
2012-08-22 19:41:31 +00:00
|
|
|
Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
|
2012-08-16 22:19:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:wps:Return:NO":
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2012-09-24 09:05:47 +00:00
|
|
|
case "WifiManager:setPowerSavingMode:Return:OK":
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:setPowerSavingMode:Return:NO":
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2013-06-24 03:02:30 +00:00
|
|
|
case "WifiManager:setStaticIpMode:Return:OK":
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:setStaticIpMode:Return:NO":
|
|
|
|
request = this.takeRequest(msg.rid);
|
|
|
|
Services.DOMRequest.fireError(request, msg.data);
|
|
|
|
break;
|
|
|
|
|
2012-06-28 10:01:51 +00:00
|
|
|
case "WifiManager:wifiDown":
|
|
|
|
this._enabled = false;
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._fireEnabledOrDisabled(false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:wifiUp":
|
|
|
|
this._enabled = true;
|
2013-03-15 16:58:41 +00:00
|
|
|
this._macAddress = msg.macAddress;
|
2012-06-28 10:01:51 +00:00
|
|
|
this._fireEnabledOrDisabled(true);
|
|
|
|
break;
|
|
|
|
|
2012-03-20 15:31:10 +00:00
|
|
|
case "WifiManager:onconnecting":
|
|
|
|
this._currentNetwork = msg.network;
|
2012-07-02 08:58:17 +00:00
|
|
|
exposeCurrentNetwork(this._currentNetwork);
|
2012-04-09 03:32:17 +00:00
|
|
|
this._connectionStatus = "connecting";
|
2012-04-13 09:07:54 +00:00
|
|
|
this._fireStatusChangeEvent();
|
2012-03-20 15:31:10 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-14 20:39:15 +00:00
|
|
|
case "WifiManager:onassociate":
|
|
|
|
this._currentNetwork = msg.network;
|
2012-07-02 08:58:17 +00:00
|
|
|
exposeCurrentNetwork(this._currentNetwork);
|
2012-04-09 03:32:17 +00:00
|
|
|
this._connectionStatus = "associated";
|
2012-04-13 09:07:54 +00:00
|
|
|
this._fireStatusChangeEvent();
|
2012-03-14 20:39:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:onconnect":
|
|
|
|
this._currentNetwork = msg.network;
|
2012-07-02 08:58:17 +00:00
|
|
|
exposeCurrentNetwork(this._currentNetwork);
|
2012-04-09 03:32:17 +00:00
|
|
|
this._connectionStatus = "connected";
|
2012-04-13 09:07:54 +00:00
|
|
|
this._fireStatusChangeEvent();
|
2012-03-14 20:39:15 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:ondisconnect":
|
|
|
|
this._currentNetwork = null;
|
2012-04-09 03:32:17 +00:00
|
|
|
this._connectionStatus = "disconnected";
|
2012-03-26 16:26:32 +00:00
|
|
|
this._lastConnectionInfo = null;
|
2012-04-13 09:07:54 +00:00
|
|
|
this._fireStatusChangeEvent();
|
2012-03-26 16:26:32 +00:00
|
|
|
break;
|
|
|
|
|
2012-08-16 22:19:51 +00:00
|
|
|
case "WifiManager:onwpstimeout":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "wps-timedout";
|
|
|
|
this._lastConnectionInfo = null;
|
|
|
|
this._fireStatusChangeEvent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:onwpsfail":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "wps-failed";
|
|
|
|
this._lastConnectionInfo = null;
|
|
|
|
this._fireStatusChangeEvent();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "WifiManager:onwpsoverlap":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "wps-overlapped";
|
|
|
|
this._lastConnectionInfo = null;
|
|
|
|
this._fireStatusChangeEvent();
|
|
|
|
break;
|
|
|
|
|
2012-03-26 16:26:32 +00:00
|
|
|
case "WifiManager:connectionInfoUpdate":
|
|
|
|
this._lastConnectionInfo = msg;
|
|
|
|
this._fireConnectionInfoUpdate(msg);
|
2012-03-14 20:39:15 +00:00
|
|
|
break;
|
2012-08-28 19:14:26 +00:00
|
|
|
case "WifiManager:onconnectingfailed":
|
|
|
|
this._currentNetwork = null;
|
|
|
|
this._connectionStatus = "connectingfailed";
|
|
|
|
this._lastConnectionInfo = null;
|
|
|
|
this._fireStatusChangeEvent();
|
|
|
|
break;
|
2012-03-14 20:39:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-13 09:07:54 +00:00
|
|
|
_fireStatusChangeEvent: function StatusChangeEvent() {
|
|
|
|
if (this._onStatusChange) {
|
2012-06-16 18:14:12 +00:00
|
|
|
debug("StatusChangeEvent");
|
|
|
|
var event = new this._window.MozWifiStatusChangeEvent("statusChangeEvent",
|
|
|
|
{ network: this._currentNetwork,
|
|
|
|
status: this._connectionStatus
|
|
|
|
});
|
2012-04-13 09:07:54 +00:00
|
|
|
this._onStatusChange.handleEvent(event);
|
|
|
|
}
|
2012-03-26 16:26:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_fireConnectionInfoUpdate: function connectionInfoUpdate(info) {
|
|
|
|
if (this._onConnectionInfoUpdate) {
|
2012-06-16 18:14:12 +00:00
|
|
|
debug("ConnectionInfoEvent");
|
|
|
|
var evt = new this._window.MozWifiConnectionInfoEvent("connectionInfoEvent",
|
|
|
|
{ network: this._currentNetwork,
|
|
|
|
signalStrength: info.signalStrength,
|
|
|
|
relSignalStrength: info.relSignalStrength,
|
2012-09-27 18:14:06 +00:00
|
|
|
linkSpeed: info.linkSpeed,
|
|
|
|
ipAddress: info.ipAddress,
|
2012-06-16 18:14:12 +00:00
|
|
|
});
|
2012-03-27 10:13:20 +00:00
|
|
|
this._onConnectionInfoUpdate.handleEvent(evt);
|
2012-03-14 20:39:15 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-06-28 10:01:51 +00:00
|
|
|
_fireEnabledOrDisabled: function enabledDisabled(enabled) {
|
|
|
|
var handler = enabled ? this._onEnabled : this._onDisabled;
|
|
|
|
if (handler) {
|
|
|
|
var evt = new this._window.Event("WifiEnabled");
|
|
|
|
handler.handleEvent(evt);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-14 20:39:15 +00:00
|
|
|
// nsIDOMWifiManager
|
|
|
|
getNetworks: function nsIDOMWifiManager_getNetworks() {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
2012-03-20 15:59:38 +00:00
|
|
|
var request = this.createRequest();
|
2012-03-14 20:39:15 +00:00
|
|
|
this._sendMessageForRequest("WifiManager:getNetworks", null, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-09-27 18:18:34 +00:00
|
|
|
getKnownNetworks: function nsIDOMWifiManager_getKnownNetworks() {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:getKnownNetworks", null, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-14 20:39:15 +00:00
|
|
|
associate: function nsIDOMWifiManager_associate(network) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
2012-03-20 15:59:38 +00:00
|
|
|
var request = this.createRequest();
|
2012-03-14 20:39:15 +00:00
|
|
|
this._sendMessageForRequest("WifiManager:associate", network, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-26 16:27:10 +00:00
|
|
|
forget: function nsIDOMWifiManager_forget(network) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
2012-04-13 07:54:11 +00:00
|
|
|
var request = this.createRequest();
|
2012-03-26 16:27:10 +00:00
|
|
|
this._sendMessageForRequest("WifiManager:forget", network, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-08-16 22:19:51 +00:00
|
|
|
wps: function nsIDOMWifiManager_wps(detail) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:wps", detail, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-09-24 09:05:47 +00:00
|
|
|
setPowerSavingMode: function nsIDOMWifiManager_setPowerSavingMode(enabled) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:setPowerSavingMode", enabled, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2013-06-24 03:02:30 +00:00
|
|
|
setStaticIpMode: function nsIDOMWifiManager_setStaticIpMode(network, info) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
var request = this.createRequest();
|
|
|
|
this._sendMessageForRequest("WifiManager:setStaticIpMode", {network: network,info: info}, request);
|
|
|
|
return request;
|
|
|
|
},
|
|
|
|
|
2012-03-14 20:39:15 +00:00
|
|
|
get enabled() {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
return this._enabled;
|
|
|
|
},
|
|
|
|
|
2012-09-27 18:14:06 +00:00
|
|
|
get macAddress() {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
return this._macAddress;
|
|
|
|
},
|
|
|
|
|
2012-04-09 03:32:17 +00:00
|
|
|
get connection() {
|
2012-03-14 20:39:15 +00:00
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
2012-07-02 08:58:17 +00:00
|
|
|
return exposeReadOnly({ status: this._connectionStatus,
|
|
|
|
network: this._currentNetwork });
|
2012-03-14 20:39:15 +00:00
|
|
|
},
|
|
|
|
|
2012-07-31 21:27:46 +00:00
|
|
|
get connectionInformation() {
|
2012-03-26 16:26:32 +00:00
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
2012-08-02 22:36:23 +00:00
|
|
|
return this._lastConnectionInfo
|
|
|
|
? exposeReadOnly(this._lastConnectionInfo)
|
|
|
|
: null;
|
2012-03-26 16:26:32 +00:00
|
|
|
},
|
|
|
|
|
2012-04-13 09:07:54 +00:00
|
|
|
set onstatuschange(callback) {
|
2012-03-14 20:39:15 +00:00
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
2012-04-13 09:07:54 +00:00
|
|
|
this._onStatusChange = callback;
|
2012-03-26 16:26:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set connectionInfoUpdate(callback) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
this._onConnectionInfoUpdate = callback;
|
2012-06-28 10:01:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
set onenabled(callback) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
this._onEnabled = callback;
|
|
|
|
},
|
|
|
|
|
|
|
|
set ondisabled(callback) {
|
|
|
|
if (!this._hasPrivileges)
|
|
|
|
throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
|
|
|
|
this._onDisabled = callback;
|
2012-03-14 20:39:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DOMWifiManager]);
|
2012-03-14 20:39:15 +00:00
|
|
|
|
|
|
|
let debug;
|
|
|
|
if (DEBUG) {
|
|
|
|
debug = function (s) {
|
2012-03-16 16:51:05 +00:00
|
|
|
dump("-*- DOMWifiManager component: " + s + "\n");
|
2012-03-14 20:39:15 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
debug = function (s) {};
|
|
|
|
}
|