Bug 917102 - 0003. DOM API implementation. r=mrbkap
authorChuck Lee <chulee@mozilla.com>
Wed, 30 Apr 2014 19:58:40 +0800
changeset 181541 c9cb944fae53cc18abd3376d83ca7fbb2171c0b2
parent 181540 7c032a129e9309b6bbfb603d8c4b11dc91374d13
child 181542 0a2b7638782904f4cccf6ae8304bd9731f9d984b
push id6743
push userryanvm@gmail.com
push dateMon, 05 May 2014 14:13:07 +0000
treeherderb2g-inbound@0a2b76387829 [default view] [failures only]
reviewersmrbkap
bugs917102
milestone32.0a1
Bug 917102 - 0003. DOM API implementation. r=mrbkap
dom/wifi/DOMWifiManager.js
dom/wifi/DOMWifiManager.manifest
dom/wifi/WifiWorker.js
--- a/dom/wifi/DOMWifiManager.js
+++ b/dom/wifi/DOMWifiManager.js
@@ -89,16 +89,17 @@ DOMWifiManager.prototype = {
     const messages = ["WifiManager:getNetworks:Return:OK", "WifiManager:getNetworks:Return:NO",
                       "WifiManager:getKnownNetworks:Return:OK", "WifiManager:getKnownNetworks:Return:NO",
                       "WifiManager:associate:Return:OK", "WifiManager:associate:Return:NO",
                       "WifiManager:forget:Return:OK", "WifiManager:forget:Return:NO",
                       "WifiManager:wps:Return:OK", "WifiManager:wps:Return:NO",
                       "WifiManager:setPowerSavingMode:Return:OK", "WifiManager:setPowerSavingMode:Return:NO",
                       "WifiManager:setHttpProxy:Return:OK", "WifiManager:setHttpProxy:Return:NO",
                       "WifiManager:setStaticIpMode:Return:OK", "WifiManager:setStaticIpMode:Return:NO",
+                      "WifiManager:importCert:Return:OK", "WifiManager:importCert:Return:NO",
                       "WifiManager:wifiDown", "WifiManager:wifiUp",
                       "WifiManager:onconnecting", "WifiManager:onassociate",
                       "WifiManager:onconnect", "WifiManager:ondisconnect",
                       "WifiManager:onwpstimeout", "WifiManager:onwpsfail",
                       "WifiManager:onwpsoverlap", "WifiManager:connectionInfoUpdate",
                       "WifiManager:onconnectingfailed"];
     this.initDOMRequestHelper(aWindow, messages);
     this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
@@ -150,16 +151,35 @@ DOMWifiManager.prototype = {
     return conn;
   },
 
   _convertConnectionInfo: function(aInfo) {
     let info = aInfo ? new MozWifiConnectionInfo(aInfo) : null;
     return info;
   },
 
+  _genReadonlyPropDesc: function(value) {
+    return {
+      enumerable: true, configurable: false, writable: false, value: value
+    };
+  },
+
+  _convertWifiCertificateInfo: function(aInfo) {
+    let propList = {};
+    for (let k in aInfo) {
+      propList[k] = this._genReadonlyPropDesc(aInfo[k]);
+    }
+
+    let info = Cu.createObjectIn(this._window);
+    Object.defineProperties(info, propList);
+    Cu.makeObjectPropsNormal(info);
+
+    return info;
+  },
+
   _sendMessageForRequest: function(name, data, request) {
     let id = this.getRequestId(request);
     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)
@@ -233,16 +253,24 @@ DOMWifiManager.prototype = {
       case "WifiManager:setStaticIpMode:Return:OK":
         Services.DOMRequest.fireSuccess(request, msg.data);
         break;
 
       case "WifiManager:setStaticIpMode:Return:NO":
         Services.DOMRequest.fireError(request, msg.data);
         break;
 
+      case "WifiManager:importCert:Return:OK":
+        Services.DOMRequest.fireSuccess(request, this._convertWifiCertificateInfo(msg.data));
+        break;
+
+      case "WifiManager:importCert:Return:NO":
+        Services.DOMRequest.fireError(request, msg.data);
+        break;
+
       case "WifiManager:wifiDown":
         this._enabled = false;
         this._currentNetwork = null;
         this._fireEnabledOrDisabled(false);
         break;
 
       case "WifiManager:wifiUp":
         this._enabled = true;
@@ -380,16 +408,27 @@ DOMWifiManager.prototype = {
 
   setStaticIpMode: function setStaticIpMode(network, info) {
     var request = this.createRequest();
     this._sendMessageForRequest("WifiManager:setStaticIpMode",
                                 { network: this._convertWifiNetworkToJSON(network), info: info}, request);
     return request;
   },
 
+  importCert: function nsIDOMWifiManager_importCert(certBlob, certPassword, certNickname) {
+    var request = this.createRequest();
+    this._sendMessageForRequest("WifiManager:importCert",
+                                {
+                                  certBlob: certBlob,
+                                  certPassword: certPassword,
+                                  certNickname: certNickname
+                                }, request);
+    return request;
+  },
+
   get enabled() {
     return this._enabled;
   },
 
   get macAddress() {
     return this._macAddress;
   },
 
--- a/dom/wifi/DOMWifiManager.manifest
+++ b/dom/wifi/DOMWifiManager.manifest
@@ -5,8 +5,11 @@ contract @mozilla.org/wifimanager;1 {c9b
 component {c01fd751-43c0-460a-8b64-abf652ec7220} DOMWifiManager.js
 contract @mozilla.org/mozwifinetwork;1 {c01fd751-43c0-460a-8b64-abf652ec7220}
 
 component {23579da4-201b-4319-bd42-9b7f337343ac} DOMWifiManager.js
 contract @mozilla.org/mozwificonnection;1 {23579da4-201b-4319-bd42-9b7f337343ac}
 
 component {83670352-6ed4-4c35-8de9-402296a1959c} DOMWifiManager.js
 contract @mozilla.org/mozwificonnectioninfo;1 {83670352-6ed4-4c35-8de9-402296a1959c}
+
+component {ad5c5295-85fb-4460-8e0c-e130d3f029ab} DOMWifiManager.js
+contract @mozilla.org/mozwificertificateinfo;1 {ad5c5295-85fb-4460-8e0c-e130d3f029ab}
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -6,16 +6,17 @@
 
 "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");
 Cu.import("resource://gre/modules/systemlibs.js");
+Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/WifiCommand.jsm");
 Cu.import("resource://gre/modules/WifiNetUtil.jsm");
 Cu.import("resource://gre/modules/WifiP2pManager.jsm");
 Cu.import("resource://gre/modules/WifiP2pWorkerObserver.jsm");
 
 var DEBUG = false; // set to true to show debug messages.
 
 const WIFIWORKER_CONTRACTID = "@mozilla.org/wifi/worker;1";
@@ -1354,16 +1355,35 @@ var WifiManager = (function() {
       }
     });
   };
 
   manager.getCapabilities = function() {
     return capabilities;
   }
 
+  // Cert Services
+  let wifiCertService = Cc["@mozilla.org/wifi/certservice;1"];
+  if (wifiCertService) {
+    wifiCertService = wifiCertService.getService(Ci.nsIWifiCertService);
+    wifiCertService.start(wifiListener);
+  } else {
+    debug("No wifi CA service component available");
+  }
+
+  manager.importCert = function(caInfo, callback) {
+    var id = idgen++;
+    if (callback) {
+      controlCallbacks[id] = callback;
+    }
+
+    wifiCertService.importCert(id, caInfo.certBlob, caInfo.certPassword,
+                               caInfo.certNickname);
+  }
+
   return manager;
 })();
 
 // Get unique key for a network, now the key is created by escape(SSID)+Security.
 // So networks of same SSID but different security mode can be identified.
 function getNetworkKey(network)
 {
   var ssid = "",
@@ -1620,16 +1640,17 @@ function WifiWorker() {
   this._mm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
                .getService(Ci.nsIMessageListenerManager);
   const messages = ["WifiManager:getNetworks", "WifiManager:getKnownNetworks",
                     "WifiManager:associate", "WifiManager:forget",
                     "WifiManager:wps", "WifiManager:getState",
                     "WifiManager:setPowerSavingMode",
                     "WifiManager:setHttpProxy",
                     "WifiManager:setStaticIpMode",
+                    "WifiManager:importCert",
                     "child-process-shutdown"];
 
   messages.forEach((function(msgName) {
     this._mm.addMessageListener(msgName, this);
   }).bind(this));
 
   Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
 
@@ -2572,16 +2593,19 @@ WifiWorker.prototype = {
         this.setPowerSavingMode(msg);
         break;
       case "WifiManager:setHttpProxy":
         this.setHttpProxy(msg);
         break;
       case "WifiManager:setStaticIpMode":
         this.setStaticIpMode(msg);
         break;
+      case "WifiManager:importCert":
+        this.importCert(msg);
+        break;
       case "WifiManager:getState": {
         let i;
         if ((i = this._domManagers.indexOf(msg.manager)) === -1) {
           this._domManagers.push(msg.manager);
         }
 
         let net = this.currentNetwork ? netToDOM(this.currentNetwork) : null;
         return { network: net,
@@ -3062,16 +3086,40 @@ WifiWorker.prototype = {
       if (ok) {
         self._sendMessage(message, true, true, msg);
       } else {
         self._sendMessage(message, false, "Set static ip mode failed", msg);
       }
     });
   },
 
+  importCert: function importCert(msg) {
+    const message = "WifiManager:importCert:Return";
+    let self = this;
+
+    WifiManager.importCert(msg.data, function(data) {
+      if (data.status === 0) {
+        let usageString = ["ServerCert"];
+        let usageArray = [];
+        for (let i = 0; i < usageString.length; i++) {
+          if (data.usageFlag & (0x01 << i)) {
+            usageArray.push(usageString[i]);
+          }
+        }
+
+        self._sendMessage(message, true, {
+          nickname: data.nickname,
+          usage: usageArray
+        }, msg);
+      } else {
+        self._sendMessage(message, false, "Import Cert failed", msg);
+      }
+    });
+  },
+
   // This is a bit ugly, but works. In particular, this depends on the fact
   // that RadioManager never actually tries to get the worker from us.
   get worker() { throw "Not implemented"; },
 
   shutdown: function() {
     debug("shutting down ...");
     this.queueRequest({command: "setWifiEnabled", value: false}, function(data) {
       this.setWifiEnabled(false, this._setWifiEnabledCallback.bind(this));