Bug 736092 - Notify on the 'connecting' state so the UI can update itself properly. r=cjones
authorBlake Kaplan <mrbkap@gmail.com>
Tue, 20 Mar 2012 16:31:10 +0100
changeset 90015 29d7555d52fb699782eca46a56a9eaa2569ecb34
parent 90014 6e9a8454ccaea8ff8c6b50b99bc59c72d62dbf7c
child 90016 ac271854f43d9ffd7e56faa17381fa069983354f
push id7433
push usermak77@bonardo.net
push dateThu, 22 Mar 2012 12:09:51 +0000
treeherdermozilla-inbound@7eb412d5eabc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs736092
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 736092 - Notify on the 'connecting' state so the UI can update itself properly. r=cjones
dom/wifi/DOMWifiManager.js
dom/wifi/WifiWorker.js
dom/wifi/nsIWifi.idl
--- a/dom/wifi/DOMWifiManager.js
+++ b/dom/wifi/DOMWifiManager.js
@@ -50,17 +50,18 @@ DOMWifiManager.prototype = {
 
     Services.obs.addObserver(this, "inner-window-destroyed", false);
     let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
     this.innerWindowID = util.currentInnerWindowID;
 
     this._messages = ["WifiManager:setEnabled:Return:OK", "WifiManager:setEnabled:Return:NO",
                       "WifiManager:getNetworks:Return:OK", "WifiManager:getNetworks:Return:NO",
                       "WifiManager:associate:Return:OK", "WifiManager:associate:Return:NO",
-                      "WifiManager:onassociate", "WifiManager:onconnect", "WifiManager:ondisconnect"];
+                      "WifiManager:onconnecting", "WifiManager:onassociate",
+                      "WifiManager:onconnect", "WifiManager:ondisconnect"];
     this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
 
     this._messages.forEach((function(msgName) {
       this._mm.addMessageListener(msgName, this);
     }).bind(this));
 
     this._id = this._getRandomId();
     this._requests = Object.create(null);
@@ -77,16 +78,17 @@ DOMWifiManager.prototype = {
     let wId = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
     if (wId == this.innerWindowID) {
       this._messages.forEach((function(msgName) {
         this._mm.removeMessageListener(msgName, this);
       }).bind(this));
 
       Services.obs.removeObserver(this, "inner-window-destroyed");
       this._window = null;
+      this._onConnecting = null;
       this._onAssociate = null;
       this._onConnect = null;
       this._onDisconnect = null;
     }
   },
 
   _getRandomId: function() {
     return Cc["@mozilla.org/uuid-generator;1"]
@@ -142,16 +144,21 @@ DOMWifiManager.prototype = {
         Services.DOMRequest.fireSuccess(request, true);
         break;
 
       case "WifiManager:associate:Return:NO":
         request = this._takeRequest(msg.rid);
         Services.DOMRequest.fireError(request, "Unable to add the network");
         break;
 
+      case "WifiManager:onconnecting":
+        this._currentNetwork = msg.network;
+        this._fireOnConnecting(msg.network);
+        break;
+
       case "WifiManager:onassociate":
         this._currentNetwork = msg.network;
         this._fireOnAssociate(msg.network);
         break;
 
       case "WifiManager:onconnect":
         this._currentNetwork = msg.network;
         this._fireOnConnect(msg.network);
@@ -159,16 +166,21 @@ DOMWifiManager.prototype = {
 
       case "WifiManager:ondisconnect":
         this._fireOnDisconnect(this._currentNetwork);
         this._currentNetwork = null;
         break;
     }
   },
 
+  _fireOnConnecting: function onConnecting(network) {
+    if (this._onConnecting)
+      this._onConnecting.handleEvent(new WifiStateChangeEvent(network));
+  },
+
   _fireOnAssociate: function onAssociate(network) {
     if (this._onAssociate)
       this._onAssociate.handleEvent(new WifiStateChangeEvent(network));
   },
 
   _fireOnConnect: function onConnect(network) {
     if (this._onConnect)
       this._onConnect.handleEvent(new WifiStateChangeEvent(network));
@@ -212,16 +224,22 @@ DOMWifiManager.prototype = {
   },
 
   get connectedNetwork() {
     if (!this._hasPrivileges)
       throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
     return this._currentNetwork;
   },
 
+  set onconnecting(callback) {
+    if (!this._hasPrivileges)
+      throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
+    this._onConnecting = callback;
+  },
+
   set onassociate(callback) {
     if (!this._hasPrivileges)
       throw new Components.Exception("Denied", Cr.NS_ERROR_FAILURE);
     this._onAssociate = callback;
   },
 
   set onconnect(callback) {
     if (!this._hasPrivileges)
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -1217,16 +1217,17 @@ function WifiWorker() {
       // need to detect if we're looping in this state and bail out.
       WifiManager.reconnect(function(){});
     } else if (this.state === "ASSOCIATING") {
       // id has not yet been filled in, so we can only report the ssid and
       // bssid.
       self.currentNetwork =
         { bssid: WifiManager.connectionInfo.bssid,
           ssid: quote(WifiManager.connectionInfo.ssid) };
+      self._fireEvent("onconnecting", { network: netToDOM(self.currentNetwork) });
     } else if (this.state === "ASSOCIATED") {
       self.currentNetwork.netId = this.id;
       WifiManager.getNetworkConfiguration(self.currentNetwork, function (){});
     } else if (this.state === "COMPLETED") {
       // Now that we've successfully completed the connection, re-enable the
       // rest of our networks.
       // XXX Need to do this eventually if the user entered an incorrect
       // password. For now, we require user interaction to break the loop and
--- a/dom/wifi/nsIWifi.idl
+++ b/dom/wifi/nsIWifi.idl
@@ -87,26 +87,29 @@ interface nsIDOMWifiManager : nsISupport
     readonly attribute boolean enabled;
 
     /**
      * A network object describing the currently connected network.
      */
     readonly attribute jsval connectedNetwork;
 
     /**
-     * These three functions serve as state notification listeners.
+     * These four functions serve as state notification listeners.
+     * onconnecting: Fires when we start the process of connecting to a
+     *               network.
      * onassociate: Fires when we have connected to an access point but do not
      *              yet have an IP address.
      * onconnect: Fires once we are fully connected to an access point and can
      *            access the internet.
      * ondisconnect: Fires when we either fail to connect to an access point
      *               (transition: onassociate -> ondisconnect) or when we were
      *               connected to a network but have disconnected for any
      *               reason (transition: onconnect -> ondisconnect).
      */
+             attribute nsIDOMEventListener onconnecting;
              attribute nsIDOMEventListener onassociate;
              attribute nsIDOMEventListener onconnect;
              attribute nsIDOMEventListener ondisconnect;
 };
 
 [scriptable, uuid(4674c6f1-ea64-44db-ac2f-e7bd6514dfd6)]
 interface nsIDOMWifiStateChangeEvent : nsIDOMEvent {
     /**