Bug 1313788 - Remove DOM/wifi and related code. r?jst draft
authorMichelangelo De Simone <mdesimone@mozilla.com>
Tue, 08 Nov 2016 15:02:45 -0800
changeset 439376 533d3a623d9f2049a96c7420daf6a999d0bef69e
parent 439375 79feeed4293336089590320a9f30a813fade8e3c
child 537153 cb8ca2aca7cb9228bd30b42735abcb4b0854b01d
push id35990
push usermdesimone@mozilla.com
push dateWed, 16 Nov 2016 00:17:00 +0000
reviewersjst
bugs1313788
milestone53.0a1
Bug 1313788 - Remove DOM/wifi and related code. r?jst MozReview-Commit-ID: BRT6bSvPpT
dom/events/test/test_all_synthetic_events.html
dom/moz.build
dom/permission/tests/mochitest.ini
dom/permission/tests/test_wifi-manage.html
dom/webidl/MozWifiCapabilities.webidl
dom/webidl/MozWifiConnectionInfoEvent.webidl
dom/webidl/MozWifiManager.webidl
dom/webidl/MozWifiP2pManager.webidl
dom/webidl/MozWifiP2pStatusChangeEvent.webidl
dom/webidl/MozWifiStationInfoEvent.webidl
dom/webidl/MozWifiStatusChangeEvent.webidl
dom/webidl/WifiOptions.webidl
dom/webidl/moz.build
dom/wifi/DOMWifiManager.js
dom/wifi/DOMWifiManager.manifest
dom/wifi/DOMWifiP2pManager.js
dom/wifi/DOMWifiP2pManager.manifest
dom/wifi/StateMachine.jsm
dom/wifi/WifiCertService.cpp
dom/wifi/WifiCertService.h
dom/wifi/WifiCommand.jsm
dom/wifi/WifiHotspotUtils.cpp
dom/wifi/WifiHotspotUtils.h
dom/wifi/WifiNetUtil.jsm
dom/wifi/WifiP2pManager.jsm
dom/wifi/WifiP2pWorkerObserver.jsm
dom/wifi/WifiProxyService.cpp
dom/wifi/WifiProxyService.h
dom/wifi/WifiUtils.cpp
dom/wifi/WifiUtils.h
dom/wifi/WifiWorker.h
dom/wifi/WifiWorker.js
dom/wifi/WifiWorker.manifest
dom/wifi/moz.build
dom/wifi/nsIWifi.idl
dom/wifi/nsIWifiCertService.idl
dom/wifi/nsIWifiService.idl
dom/wifi/test/marionette/head.js
dom/wifi/test/marionette/manifest.ini
dom/wifi/test/marionette/test_wifi_associate.js
dom/wifi/test/marionette/test_wifi_associate_WPA_EAP_PEAP.js
dom/wifi/test/marionette/test_wifi_associate_WPA_EAP_TLS.js
dom/wifi/test/marionette/test_wifi_associate_WPA_EAP_TTLS.js
dom/wifi/test/marionette/test_wifi_associate_wo_connect.js
dom/wifi/test/marionette/test_wifi_auto_connect.js
dom/wifi/test/marionette/test_wifi_enable.js
dom/wifi/test/marionette/test_wifi_enable_api.js
dom/wifi/test/marionette/test_wifi_manage_pkcs12_certificate.js
dom/wifi/test/marionette/test_wifi_manage_server_certificate.js
dom/wifi/test/marionette/test_wifi_manage_user_certificate.js
dom/wifi/test/marionette/test_wifi_scan.js
dom/wifi/test/marionette/test_wifi_static_ip.js
dom/wifi/test/marionette/test_wifi_tethering_wifi_active.js
dom/wifi/test/marionette/test_wifi_tethering_wifi_disabled.js
dom/wifi/test/marionette/test_wifi_tethering_wifi_inactive.js
dom/xbl/test/file_bug946815.xhtml
dom/xbl/test/mochitest.ini
testing/marionette/harness/marionette/tests/webapi-tests.ini
--- a/dom/events/test/test_all_synthetic_events.html
+++ b/dom/events/test/test_all_synthetic_events.html
@@ -274,28 +274,16 @@ const kEventConstructors = {
   MozSmsEvent:                               { create: function (aName, aProps) {
                                                          return new MozSmsEvent(aName, aProps);
                                                        },
                                              },
   MozStkCommandEvent:                        { create: function (aName, aProps) {
                                                           return new MozStkCommandEvent(aName, aProps);
                                                        },
                                              },
-  MozWifiConnectionInfoEvent:                { create: function (aName, aProps) {
-                                                         return new MozWifiConnectionInfoEvent(aName, aProps);
-                                                       },
-                                             },
-  MozWifiStatusChangeEvent:                  { create: function (aName, aProps) {
-                                                          return new MozWifiStatusChangeEvent(aName, aProps);
-                                                       },
-                                             },
-  MozWifiStationInfoEvent:                   { create: function (aName, aProps) {
-                                                          return new MozWifiStationInfoEvent(aName, aProps);
-                                                       },
-                                             },
   MutationEvent:                             { create: function (aName, aProps) {
                                                          var e = document.createEvent("mutationevent");
                                                          e.initMutationEvent(aName, aProps.bubbles, aProps.cancelable,
                                                                              aProps.relatedNode, aProps.prevValue, aProps.newValue,
                                                                              aProps.attrName, aProps.attrChange);
                                                          return e;
                                                        },
                                              },
--- a/dom/moz.build
+++ b/dom/moz.build
@@ -105,17 +105,16 @@ DIRS += [
 
 if CONFIG['OS_ARCH'] == 'WINNT':
     DIRS += ['plugins/ipc/hangui']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     DIRS += [
         'speakermanager',
         'tethering',
-        'wifi',
     ]
 
 if CONFIG['MOZ_SECUREELEMENT']:
     DIRS += ['secureelement']
 
 if CONFIG['MOZ_B2G']:
     DIRS += [
         'downloads',
--- a/dom/permission/tests/mochitest.ini
+++ b/dom/permission/tests/mochitest.ini
@@ -22,10 +22,8 @@ skip-if = true
 [test_udp-socket.html]
 skip-if = true
 [test_keyboard.html]
 # skip-if = toolkit == 'android'
 skip-if = true
 [test_input-manage.html]
 # skip-if = toolkit == 'android'
 skip-if = true
-[test_wifi-manage.html]
-skip-if = true
deleted file mode 100644
--- a/dom/permission/tests/test_wifi-manage.html
+++ /dev/null
@@ -1,41 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=815105
--->
-<head>
-  <meta charset="utf-8">
-  <title>Test for Bug 815105 </title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=815105">Mozilla Bug 815105 </a>
-<p id="display"></p>
-<div id="content" style="display: none"></div>
-<pre id="test">
-<script type="application/javascript;version=1.8" src="file_framework.js"></script>
-<script type="application/javascript;version=1.8">
-function verifier(success, failure) {
-  try {
-    this.getObj().enabled;
-    success("Got wifi");
-  } catch (e) {
-    failure("Got an exception " + e);
-  }
-}
-
-var gData = [
-  {
-    perm: ["wifi-manage"],
-    needParentPerm: true,
-    obj: "mozWifiManager",
-    webidl: "MozWifiManager",
-    verifier: verifier.toSource(),
-  },
-]
-</script>
-</pre>
-</body>
-</html>
-
deleted file mode 100644
--- a/dom/webidl/MozWifiCapabilities.webidl
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* 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/.
- */
-
-/*
- * The capabilities of Wifi. These are guaranteed not to change over the
- * lifetime of that particular instance.
- */
-enum WifiSecurityMethod {
-  "OPEN",
-  "WEP",
-  "WPA-PSK",
-  "WPA-EAP"
-};
-
-enum WifiWpaMethod {
-  "SIM",
-  "PEAP",
-  "TTLS",
-  "TLS"
-};
-
-enum WifiWpaPhase2Method {
-  "MSCHAPV2",
-  "GTC"
-};
-
-enum WifiWpaCertificate {
-  "SERVER",
-  "USER"
-};
-
-[JSImplementation="@mozilla.org/mozwificapabilities;1",
- Func="Navigator::HasWifiManagerSupport"]
-interface MozWifiCapabilities {
-  [Constant, Cached] readonly attribute sequence<WifiSecurityMethod> security;
-  [Constant, Cached] readonly attribute sequence<WifiWpaMethod> eapMethod;
-  [Constant, Cached] readonly attribute sequence<WifiWpaPhase2Method> eapPhase2;
-  [Constant, Cached] readonly attribute sequence<WifiWpaCertificate> certificate;
-
-  jsonifier;
-};
-
deleted file mode 100644
--- a/dom/webidl/MozWifiConnectionInfoEvent.webidl
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[Constructor(DOMString type, optional MozWifiConnectionInfoEventInit eventInitDict)]
-interface MozWifiConnectionInfoEvent : Event
-{
-  /**
-   * Network object with an SSID field.
-   */
-  readonly attribute any network;
-
-  /**
-   * Strength of the signal to network, in dBm between -55 and -100 dBm.
-   */
-  readonly attribute short signalStrength;
-
-  /**
-   * Relative signal strength between 0 and 100.
-   */
-  readonly attribute short relSignalStrength;
-
-  /**
-   * Link speed in Mb/s.
-   */
-  readonly attribute long linkSpeed;
-
-  /**
-   * IP address in the dotted quad format.
-   */
-  readonly attribute DOMString? ipAddress;
-};
-
-dictionary MozWifiConnectionInfoEventInit : EventInit
-{
-  any network = null;
-  short signalStrength = 0;
-  short relSignalStrength = 0;
-  long linkSpeed = 0;
-  DOMString ipAddress = "";
-};
deleted file mode 100644
--- a/dom/webidl/MozWifiManager.webidl
+++ /dev/null
@@ -1,347 +0,0 @@
-/* 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/. */
-
-enum WifiWPSMethod {
-  "pbc",
-  "pin",
-  "cancel"
-};
-
-enum ConnectionStatus {
-  "connecting",
-  "authenticating",
-  "associated",
-  "connected",
-  "disconnected",
-  "wps-timedout",
-  "wps-failed",
-  "wps-overlapped",
-  "connectingfailed"
-};
-
-dictionary WifiWPSInfo {
-  WifiWPSMethod method;
-  DOMString? pin;
-  DOMString? bssid;
-};
-
-dictionary NetworkProperties {
-  DOMString ssid;
-  long mode;
-  long frequency;
-  sequence<DOMString>? security;
-  sequence<DOMString>? capabilities;
-  boolean known;
-  boolean connected;
-  boolean hidden;
-  DOMString bssid;
-  DOMString signalStrength;
-  long relSignalStrength;
-  DOMString psk;
-  DOMString wep;
-  DOMString wep_key0;
-  DOMString wep_key1;
-  DOMString wep_key2;
-  DOMString wep_key3;
-  long wep_tx_keyidx;
-  long priority;
-  long scan_ssid;
-  DOMString keyManagement;
-  DOMString identity;
-  DOMString password;
-  DOMString auth_alg;
-  DOMString phase1;
-  DOMString phase2;
-  DOMString eap;
-  DOMString pin;
-  boolean dontConnect;
-  DOMString serverCertificate;
-  DOMString subjectMatch;
-  DOMString userCertificate;
-};
-
-[Constructor(optional NetworkProperties properties),
- JSImplementation="@mozilla.org/mozwifinetwork;1",
- Func="Navigator::HasWifiManagerSupport"]
-interface MozWifiNetwork {
-  readonly attribute DOMString ssid;
-  readonly attribute long mode;
-  readonly attribute long frequency;
-  [Constant, Cached] readonly attribute sequence<DOMString>? security;
-  [Constant, Cached] readonly attribute sequence<DOMString>? capabilities;
-  readonly attribute boolean known;
-  readonly attribute boolean connected;
-  readonly attribute boolean hidden;
-
-           attribute DOMString? bssid;
-           attribute DOMString? signalStrength;
-           attribute long? relSignalStrength;
-           attribute DOMString? psk;
-           attribute DOMString? wep;
-           attribute DOMString? wep_key0;
-           attribute DOMString? wep_key1;
-           attribute DOMString? wep_key2;
-           attribute DOMString? wep_key3;
-           attribute long? wep_tx_keyidx;
-           attribute long? priority;
-           attribute long? scan_ssid;
-           attribute DOMString? keyManagement;
-           attribute DOMString? identity;
-           attribute DOMString? password;
-           attribute DOMString? auth_alg;
-           attribute DOMString? phase1;
-           attribute DOMString? phase2;
-           attribute DOMString? eap;
-           attribute DOMString? pin;
-           attribute boolean? dontConnect;
-           attribute DOMString? serverCertificate;
-           attribute DOMString? subjectMatch;
-           attribute DOMString? userCertificate;
-};
-
-[JSImplementation="@mozilla.org/mozwificonnection;1",
- ChromeOnly]
-interface MozWifiConnection {
-  readonly attribute ConnectionStatus status;
-  readonly attribute MozWifiNetwork? network;
-};
-
-[JSImplementation="@mozilla.org/mozwificonnectioninfo;1",
- ChromeOnly]
-interface MozWifiConnectionInfo {
-  readonly attribute short signalStrength;
-  readonly attribute short relSignalStrength;
-  readonly attribute long linkSpeed;
-  readonly attribute DOMString? ipAddress;
-};
-
-dictionary IPConfiguration {
-  boolean enabled;
-  DOMString ipaddr;
-  DOMString proxy;
-  short maskLength;
-  DOMString gateway;
-  DOMString dns1;
-  DOMString dns2;
-};
-
-[JSImplementation="@mozilla.org/wifimanager;1",
- NavigatorProperty="mozWifiManager",
- Func="Navigator::HasWifiManagerSupport",
- UnsafeInPrerendering]
-interface MozWifiManager : EventTarget {
-  /**
-   * Turn on/off wifi functionality.
-   * @param enable true for enable, false for disable.
-   * onsuccess: Wifi enable/disable successfully, including no status change.
-   * onerror: Wifi enable/disable failed or prohibited.
-   */
-  DOMRequest setWifiEnabled(boolean enabled);
-
-  /**
-   * Returns the list of currently available networks.
-   * onsuccess: We have obtained the current list of networks. request.value
-   *            is an object whose property names are SSIDs and values are
-   *            network objects.
-   * onerror: We were unable to obtain a list of property names.
-   */
-  DOMRequest getNetworks();
-
-  /**
-   * Returns the list of networks known to the system that will be
-   * automatically connected to if they're in range.
-   * onsuccess: request.value is an object whose property names are
-   *            SSIDs and values are network objects.
-   * onerror: We were unable to obtain a list of known networks.
-   */
-  DOMRequest getKnownNetworks();
-
-  /**
-   * Takes one of the networks returned from getNetworks and tries to
-   * connect to it.
-   * @param network A network object with information about the network,
-   *                such as the SSID, key management desired, etc.
-   * onsuccess: We have started attempting to associate with the network.
-   *            request.value is true.
-   * onerror: We were unable to select the network. This most likely means a
-   *          configuration error.
-   */
-  DOMRequest associate(MozWifiNetwork network);
-
-  /**
-   * Given a network, removes it from the list of networks that we'll
-   * automatically connect to. In order to re-connect to the network, it is
-   * necessary to call associate on it.
-   * @param network A network object with the SSID of the network to remove.
-   * onsuccess: We have removed this network. If we were previously
-   *            connected to it, we have started reconnecting to the next
-   *            network in the list.
-   * onerror: We were unable to remove the network.
-   */
-  DOMRequest forget(MozWifiNetwork network);
-
-  /**
-   * Wi-Fi Protected Setup functionality.
-   * @param detail WPS detail which has 'method' and 'pin' field.
-   *               The possible method field values are:
-   *                 - pbc: The Push Button Configuration.
-   *                 - pin: The PIN configuration.
-   *                 - cancel: Request to cancel WPS in progress.
-   *               If method field is 'pin', 'pin' field can exist and has
-   *               a PIN number.
-   *               If method field is 'pin', 'bssid' field can exist and has
-   *               a opposite BSSID.
-   * onsuccess: We have successfully started/canceled wps.
-   * onerror: We have failed to start/cancel wps.
-   */
-  DOMRequest wps(optional WifiWPSInfo detail);
-
-  /**
-   * Turn on/off wifi power saving mode.
-   * @param enabled true or false.
-   * onsuccess: We have successfully turn on/off wifi power saving mode.
-   * onerror: We have failed to turn on/off wifi power saving mode.
-   */
-  DOMRequest setPowerSavingMode(boolean enabled);
-
-  /**
-   * Given a network, configure using static IP instead of running DHCP
-   * @param network A network object with the SSID of the network to set static ip.
-   * @param info info should have following field:
-   *        - enabled True to enable static IP, false to use DHCP
-   *        - ipaddr configured static IP address
-   *        - proxy configured proxy server address
-   *        - maskLength configured mask length
-   *        - gateway configured gateway address
-   *        - dns1 configured first DNS server address
-   *        - dns2 configured seconf DNS server address
-   * onsuccess: We have successfully configure the static ip mode.
-   * onerror: We have failed to configure the static ip mode.
-   */
-  DOMRequest setStaticIpMode(MozWifiNetwork network, optional IPConfiguration info);
-
-  /**
-   * Given a network, configure http proxy when using wifi.
-   * @param network A network object with the SSID of the network to set http proxy.
-   * @param info info should have following field:
-   *        - httpProxyHost ip address of http proxy.
-   *        - httpProxyPort port of http proxy, set 0 to use default port 8080.
-   *        set info to null to clear http proxy.
-   * onsuccess: We have successfully configure http proxy.
-   * onerror: We have failed to configure http proxy.
-   */
-  DOMRequest setHttpProxy(MozWifiNetwork network, any info);
-
-  /**
-   * Import a certificate file, only support CA certificate now.
-   * @param certBlob A Blob object containing raw data of certificate to be imported.
-   *                 Supported format: binary/base64 encoded DER certificates.
-   *                                   (.der/.crt/.cer/.pem)
-   *                 Cause error if importing certificates already imported.
-   * @param certPassword Password of certificate.
-   * @param certNickname User assigned nickname for imported certificate.
-   *                     Nickname must be unique, it causes error on redundant nickname.
-   * onsuccess: We have successfully imported certificate. request.result is an
-   *            object, containing information of imported CA:
-   *            {
-   *              nickname:  Nickname of imported CA, String.
-   *              usage:     Supported usage of imported CA, Array of String,
-   *                         includes: "ServerCert".
-   *            }
-   * onerror: We have failed to import certificate.
-   */
-  DOMRequest importCert(Blob certBlob,
-                        DOMString certPassword,
-                        DOMString certNickname);
-
-  /**
-   * Get list of imported WIFI certificates.
-   * onsuccess: We have successfully gotten imported certificate list.
-   *            request.result is an object using nickname as key, array of usage
-   *            string as value.
-   *            request.result[USAGE] = [CA_NICKNAME1, CA_NICKNAME2, ...]
-   *            USAGE string includes: "ServerCert".
-   * onerror: We have failed to list certificate.
-   */
-  DOMRequest getImportedCerts();
-
-  /**
-   * Delete an imported certificate.
-   * @param certNickname Nickname of imported to be deleted.
-   * onsuccess: We have successfully deleted certificate.
-   * onerror: We have failed to delete certificate.
-   */
-  DOMRequest deleteCert(DOMString certNickname);
-
-  /**
-   * Returns whether or not wifi is currently enabled.
-   */
-  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")
-   *  - network
-   *
-   *  Note that the object returned is read only. Any changes required must
-   *  be done by calling other APIs.
-   */
-  readonly attribute MozWifiConnection connection;
-
-  /**
-   * A connectionInformation object with the same information found in an
-   * MozWifiConnectionInfoEvent (but without the network).
-   * If we are not currently connected to a network, this will be null.
-   */
-  readonly attribute MozWifiConnectionInfo? connectionInformation;
-
-  /**
-   * Capabilities of Wifi.
-   */
-  readonly attribute MozWifiCapabilities? capabilities;
-
-  /**
-   * State notification listeners. These all take an
-   * MozWifiStatusChangeEvent with the new status and a network (which may be
-   * null).
-   *
-   * The possible statuses are:
-   *   - connecting: Fires when we start the process of connecting to a
-   *                 network.
-   *   - associated: Fires when we have connected to an access point but do
-   *                 not yet have an IP address.
-   *   - connected: Fires once we are fully connected to an access point and
-   *                can access the internet.
-   *   - disconnected: Fires when we either fail to connect to an access
-   *                   point (transition: associated -> disconnected) or
-   *                   when we were connected to a network but have
-   *                   disconnected for any reason (transition: connected ->
-   *                   disconnected).
-   */
-  attribute EventHandler onstatuschange;
-
-  /**
-   * An event listener that is called with information about the signal
-   * strength and link speed every 5 seconds.
-   */
-  attribute EventHandler onconnectioninfoupdate;
-
-  /**
-   * These two events fire when the wifi system is brought online or taken
-   * offline.
-   */
-  attribute EventHandler onenabled;
-  attribute EventHandler ondisabled;
-
-  /**
-   * An event listener that is called with information about the number
-   * of wifi stations connected to wifi hotspot every 5 seconds.
-   */
-  attribute EventHandler onstationinfoupdate;
-};
deleted file mode 100644
--- a/dom/webidl/MozWifiP2pManager.webidl
+++ /dev/null
@@ -1,147 +0,0 @@
-/* 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/. */
-
-enum WPSMethod {
-  "pbc",
-  "keypad",
-  "display"
-};
-
-dictionary WPSInfo {
-  WPSMethod method;
-  DOMString pin;
-};
-
-[JSImplementation="@mozilla.org/wifip2pgroupowner;1",
- Func="Navigator::HasWifiManagerSupport"]
-interface MozWifiP2pGroupOwner {
-  readonly attribute DOMString groupName;
-  readonly attribute DOMString macAddress;
-  readonly attribute DOMString ipAddress;
-  readonly attribute DOMString passphrase;
-  readonly attribute DOMString ssid;
-  readonly attribute any wpsCapabilities;
-  readonly attribute unsigned long freq;
-  readonly attribute boolean isLocal;
-};
-
-[JSImplementation="@mozilla.org/wifip2pmanager;1",
- NavigatorProperty="mozWifiP2pManager",
- Func="Navigator::HasWifiManagerSupport"]
-interface MozWifiP2pManager : EventTarget
-{
-  /**
-   * Enable/Disable wifi direct scan.
-   *
-   * onsuccess: Succeeded in starting/stopping wifi direct scan.
-   * onerror:   Failed to start/stop wifi direct scan.
-   *
-   */
-  DOMRequest setScanEnabled(boolean enabled);
-
-  /**
-   * Connect to a peer with given configuration.
-   *
-   * @param address The peer MAC address we are going to connect.
-   * @param wpsMethod The WPS method we want to use.
-   * @param goIntent Number from 0 ~ 15 to indicate how much we want to be
-   *                 the group owner.
-   *
-   * onsuccess: Succeeded in issueing a 'connect' request. It doesn't mean we
-   *            have connected to the peer.
-   *
-   * onerror:   Failed to issue a 'connect' request, probably due to an
-   *            invalid peer address, unsupported wps method or any
-   *            preliminary error.
-   *
-   **/
-  DOMRequest connect(DOMString address, WPSMethod wpsMethod, optional byte goIntent);
-
-  /**
-   * Disconnect with a peer.
-   *
-   * @param address The mac address of the peer.
-   *
-   * onsuccess: Succeeded to issue a 'disconnect' request. It doesn't mean we
-   *            have disconnected with the peer.
-   *
-   * onerror:   Failed to issue a 'disconnect' request, probably due to the
-   *            invalid peer address or any preliminary error.
-   *
-   */
-  DOMRequest disconnect(DOMString address);
-
-  /**
-   * Get peer list
-   *
-   * onsuccess: Command success, req.result contains an array of peer objects.
-   * onerror: Command failed.
-   *
-   * Peer object format:
-   *   .address          MAC address of the peer (string)
-   *   .name             the peer's device name (string)
-   *   .isGroupOwner     if the peer is the group owner (boolean)
-   *   .wpsCapabilities  array of the supported |WPSMethod|
-   *   .connectionStatus one of { "disconnected", "connecting", "connected", "disconnecting" }
-   *
-   */
-  DOMRequest getPeerList();
-
-  /**
-   * Set pairing confirmation result.
-   *
-   * @param accepted Boolean to indicate whether we accepted the request or not.
-   * @param pin The user input pin number if the wps method is keypad.
-   *
-   * onsuccess: Command succeeded.
-   * onerror:   Command failed.
-   *
-   */
-  DOMRequest setPairingConfirmation(boolean accepted, optional DOMString pin);
-
-  /**
-   * Set device name.
-   *
-   * @param devieName The new device name we are going to set.
-   *
-   * onsuccess: Command succeeded.
-   * onerror:   Command failed.
-   *
-   */
-  DOMRequest setDeviceName(DOMString deviceName);
-
-  /**
-   * Returns if Wifi Direct is enabled.
-   *
-   */
-  readonly attribute boolean enabled;
-
-  /**
-   * The current group owner, null if none.
-   */
-  readonly attribute MozWifiP2pGroupOwner? groupOwner;
-
-  /**
-   * An event listener that is called whenever the Wifi Direct peer list is
-   * updated. Use getPeerList() to get the up-to-date peer list.
-   */
-  attribute EventHandler onpeerinfoupdate;
-
-  /**
-   * An event listener that is called whenever Wifi Direct status changed.
-   * The address of the changed peer will be stored in event.peerList.
-   * See MozWifiP2pStatusChangeEvent.webidl.
-   */
-  attribute EventHandler onstatuschange;
-
-  /**
-   * An event listener that is called whenever Wifi Direct is enabled.
-   */
-  attribute EventHandler onenabled;
-
-  /**
-   * An event listener that is called whenever Wifi Direct is disabled.
-   */
-  attribute EventHandler ondisabled;
-};
deleted file mode 100644
--- a/dom/webidl/MozWifiP2pStatusChangeEvent.webidl
+++ /dev/null
@@ -1,20 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[Constructor(DOMString type, optional MozWifiP2pStatusChangeEventInit eventInitDict), 
- Func="Navigator::HasWifiManagerSupport"]
-interface MozWifiP2pStatusChangeEvent : Event
-{
-  /**
-   * The mac address of the peer whose status has just changed.
-   */
-  readonly attribute DOMString peerAddress;
-};
-
-dictionary MozWifiP2pStatusChangeEventInit : EventInit
-{
-  DOMString peerAddress = "";
-};
deleted file mode 100644
--- a/dom/webidl/MozWifiStationInfoEvent.webidl
+++ /dev/null
@@ -1,19 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[Constructor(DOMString type, optional MozWifiStationInfoEventInit eventInitDict)]
-interface MozWifiStationInfoEvent : Event
-{
-  /**
-   * The number of wifi stations connected to wifi hotspot.
-   */
-  readonly attribute short station;
-};
-
-dictionary MozWifiStationInfoEventInit : EventInit
-{
-  short station = 0;
-};
deleted file mode 100644
--- a/dom/webidl/MozWifiStatusChangeEvent.webidl
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/.
- */
-
-[Constructor(DOMString type, optional MozWifiStatusChangeEventInit eventInitDict)]
-interface MozWifiStatusChangeEvent : Event
-{
-  /**
-   * Network object with a SSID field describing the network affected by
-   * this change. This might be null.
-   */
-  readonly attribute any network;
-
-  /**
-   * String describing the current status of the wifi manager. See above for
-   * the possible values.
-   */
-  readonly attribute DOMString? status;
-};
-
-dictionary MozWifiStatusChangeEventInit : EventInit
-{
-  any network = null;
-  DOMString status = "";
-};
deleted file mode 100644
--- a/dom/webidl/WifiOptions.webidl
+++ /dev/null
@@ -1,38 +0,0 @@
-/* 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/. */
-
-/**
-  * This dictionnary holds the parameters sent to the wifi service.
-  */
-dictionary WifiCommandOptions
-{
-  long      id = 0;       // opaque id.
-  DOMString cmd = "";     // the command name.
-  DOMString request;      // for "command"
-};
-
-/**
-  * This dictionnary holds the parameters sent back to WifiWorker.js
-  */
-dictionary WifiResultOptions
-{
-  long      id = 0;             // opaque id.
-  long      status = 0;         // the return status of the command.
-                                // Used by most commands.
-  DOMString reply = "";         // for "command".
-};
-
-
-/**
-  * This dictionary holds the callback parameter sent back from WifiCertService
-  * to WifiWorker, and should only be passed around in chrome process.
-  */
-dictionary WifiCertServiceResultOptions
-{
-  long            id = 0;         // request id in WifiWorker.
-  long            status = 0;     // error code of the request, 0 indicates success.
-  unsigned short  usageFlag = 0;  // usage flag of certificate, the flag is defined
-                                  // in nsIWifiCertService.idl
-  DOMString       nickname = "";  // nickname of certificate of the request.
-};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -564,17 +564,16 @@ WEBIDL_FILES = [
     'WaveShaperNode.webidl',
     'WebComponents.webidl',
     'WebGL2RenderingContext.webidl',
     'WebGLRenderingContext.webidl',
     'WebKitCSSMatrix.webidl',
     'WebSocket.webidl',
     'WheelEvent.webidl',
     'WidevineCDMManifest.webidl',
-    'WifiOptions.webidl',
     'WindowOrWorkerGlobalScope.webidl',
     'WindowRoot.webidl',
     'Worker.webidl',
     'WorkerDebuggerGlobalScope.webidl',
     'WorkerGlobalScope.webidl',
     'WorkerLocation.webidl',
     'WorkerNavigator.webidl',
     'Worklet.webidl',
@@ -681,19 +680,16 @@ if CONFIG['MOZ_SECUREELEMENT']:
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     WEBIDL_FILES += [
         'MozNetworkStats.webidl',
         'MozNetworkStatsAlarm.webidl',
         'MozNetworkStatsData.webidl',
         'MozNetworkStatsInterface.webidl',
         'MozNetworkStatsManager.webidl',
         'MozSpeakerManager.webidl',
-        'MozWifiCapabilities.webidl',
-        'MozWifiManager.webidl',
-        'MozWifiP2pManager.webidl',
     ]
 else:
     WEBIDL_FILES += [
         'InstallTrigger.webidl',
     ]
 
 GENERATED_EVENTS_WEBIDL_FILES = [
     'AddonEvent.webidl',
@@ -757,24 +753,16 @@ if CONFIG['MOZ_WEBSPEECH']:
 
 if CONFIG['MOZ_GAMEPAD']:
     GENERATED_EVENTS_WEBIDL_FILES += [
         'GamepadAxisMoveEvent.webidl',
         'GamepadButtonEvent.webidl',
         'GamepadEvent.webidl',
     ]
 
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
-    GENERATED_EVENTS_WEBIDL_FILES += [
-        'MozWifiConnectionInfoEvent.webidl',
-        'MozWifiP2pStatusChangeEvent.webidl',
-        'MozWifiStationInfoEvent.webidl',
-        'MozWifiStatusChangeEvent.webidl',
-    ]
-
 if CONFIG['MOZ_BUILD_APP'] in ['browser', 'xulrunner'] or CONFIG['MOZ_SUITE']:
     WEBIDL_FILES += [
         'BrowserFeedWriter.webidl',
     ]
 
 if CONFIG['MOZ_BUILD_APP'] in ['browser', 'mobile/android', 'xulrunner']:
     WEBIDL_FILES += [
         'External.webidl',
deleted file mode 100644
--- a/dom/wifi/DOMWifiManager.js
+++ /dev/null
@@ -1,543 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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");
-Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
-
-const DEBUG = false; // set to false to suppress debug messages
-
-const DOMWIFIMANAGER_CONTRACTID = "@mozilla.org/wifimanager;1";
-const DOMWIFIMANAGER_CID        = Components.ID("{c9b5f09e-25d2-40ca-aef4-c4d13d93c706}");
-
-function MozWifiNetwork() {
-}
-
-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;
-}
-
-MozWifiConnection.prototype = {
-  classID: Components.ID("{23579da4-201b-4319-bd42-9b7f337343ac}"),
-  contractID: "@mozilla.org/mozwificonnection;1",
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports])
-};
-
-function MozWifiConnectionInfo(obj) {
-  this.signalStrength = obj.signalStrength;
-  this.relSignalStrength = obj.relSignalStrength;
-  this.linkSpeed = obj.linkSpeed;
-  this.ipAddress = obj.ipAddress;
-}
-
-MozWifiConnectionInfo.prototype = {
-  classID: Components.ID("{83670352-6ed4-4c35-8de9-402296a1959c}"),
-  contractID: "@mozilla.org/mozwificonnectioninfo;1",
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports])
-}
-
-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])
-}
-
-function DOMWifiManager() {
-  this.defineEventHandlerGetterSetter("onstatuschange");
-  this.defineEventHandlerGetterSetter("onconnectioninfoupdate");
-  this.defineEventHandlerGetterSetter("onenabled");
-  this.defineEventHandlerGetterSetter("ondisabled");
-  this.defineEventHandlerGetterSetter("onstationinfoupdate");
-}
-
-DOMWifiManager.prototype = {
-  __proto__: DOMRequestIpcHelper.prototype,
-  classDescription: "DOMWifiManager",
-  classID: DOMWIFIMANAGER_CID,
-  contractID: DOMWIFIMANAGER_CONTRACTID,
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
-                                         Ci.nsISupportsWeakReference,
-                                         Ci.nsIObserver]),
-
-  // nsIDOMGlobalPropertyInitializer implementation
-  init: function(aWindow) {
-    // Maintain this state for synchronous APIs.
-    this._currentNetwork = null;
-    this._connectionStatus = "disconnected";
-    this._enabled = false;
-    this._lastConnectionInfo = null;
-    this._capabilities = null;
-    this._stationNumber = 0;
-
-    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:getImportedCerts:Return:OK", "WifiManager:getImportedCerts:Return:NO",
-                      "WifiManager:deleteCert:Return:OK", "WifiManager:deleteCert:Return:NO",
-                      "WifiManager:setWifiEnabled:Return:OK", "WifiManager:setWifiEnabled:Return:NO",
-                      "WifiManager:wifiDown", "WifiManager:wifiUp",
-                      "WifiManager:onconnecting", "WifiManager:onassociate",
-                      "WifiManager:onconnect", "WifiManager:ondisconnect",
-                      "WifiManager:onwpstimeout", "WifiManager:onwpsfail",
-                      "WifiManager:onwpsoverlap", "WifiManager:connectioninfoupdate",
-                      "WifiManager:onauthenticating", "WifiManager:onconnectingfailed",
-                      "WifiManager:stationinfoupdate"];
-    this.initDOMRequestHelper(aWindow, messages);
-    this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
-
-    var state = this._mm.sendSyncMessage("WifiManager:getState")[0];
-    if (state) {
-      this._currentNetwork = this._convertWifiNetwork(state.network);
-      this._lastConnectionInfo = this._convertConnectionInfo(state.connectionInfo);
-      this._enabled = state.enabled;
-      this._connectionStatus = state.status;
-      this._macAddress = state.macAddress;
-      this._capabilities = this._convertWifiCapabilities(state.capabilities);
-    } else {
-      this._currentNetwork = null;
-      this._lastConnectionInfo = null;
-      this._enabled = false;
-      this._connectionStatus = "disconnected";
-      this._macAddress = "";
-    }
-  },
-
-  _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) {
-    let networks = new this._window.Array();
-    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;
-  },
-
-  _convertWifiCapabilities: function(aCapabilities) {
-    let capabilities = aCapabilities ?
-                         new MozWifiCapabilities(aCapabilities) : null;
-    return capabilities;
-  },
-
-  _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)
-      return;
-
-    let request;
-    if (msg.rid) {
-      request = this.takeRequest(msg.rid);
-      if (!request) {
-        return;
-      }
-    }
-
-    switch (aMessage.name) {
-      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;
-
-      case "WifiManager:getNetworks:Return:OK":
-        Services.DOMRequest.fireSuccess(request, this._convertWifiNetworks(msg.data));
-        break;
-
-      case "WifiManager:getNetworks:Return:NO":
-        Services.DOMRequest.fireError(request, "Unable to scan for networks");
-        break;
-
-      case "WifiManager:getKnownNetworks:Return:OK":
-        Services.DOMRequest.fireSuccess(request, this._convertWifiNetworks(msg.data));
-        break;
-
-      case "WifiManager:getKnownNetworks:Return:NO":
-        Services.DOMRequest.fireError(request, "Unable to get known networks");
-        break;
-
-      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;
-
-      case "WifiManager:forget:Return:OK":
-        Services.DOMRequest.fireSuccess(request, true);
-        break;
-
-      case "WifiManager:forget:Return:NO":
-        Services.DOMRequest.fireError(request, msg.data);
-        break;
-
-      case "WifiManager:wps:Return:OK":
-        Services.DOMRequest.fireSuccess(request, msg.data);
-        break;
-
-      case "WifiManager:wps:Return:NO":
-        Services.DOMRequest.fireError(request, msg.data);
-        break;
-
-      case "WifiManager:setPowerSavingMode:Return:OK":
-        Services.DOMRequest.fireSuccess(request, msg.data);
-        break;
-
-      case "WifiManager:setPowerSavingMode:Return:NO":
-        Services.DOMRequest.fireError(request, msg.data);
-        break;
-
-      case "WifiManager:setHttpProxy:Return:OK":
-        Services.DOMRequest.fireSuccess(request, msg.data);
-        break;
-
-      case "WifiManager:setHttpProxy:Return:NO":
-        Services.DOMRequest.fireError(request, msg.data);
-        break;
-
-      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, Cu.cloneInto(msg.data, this._window));
-        break;
-
-      case "WifiManager:importCert:Return:NO":
-        Services.DOMRequest.fireError(request, msg.data);
-        break;
-
-      case "WifiManager:getImportedCerts:Return:OK":
-        Services.DOMRequest.fireSuccess(request, Cu.cloneInto(msg.data, this._window));
-        break;
-
-      case "WifiManager:getImportedCerts:Return:NO":
-        Services.DOMRequest.fireError(request, msg.data);
-        break;
-
-      case "WifiManager:deleteCert:Return:OK":
-        Services.DOMRequest.fireSuccess(request, msg.data);
-        break;
-
-      case "WifiManager:deleteCert: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;
-        this._macAddress = msg.macAddress;
-        this._fireEnabledOrDisabled(true);
-        break;
-
-      case "WifiManager:onconnecting":
-        this._currentNetwork = this._convertWifiNetwork(msg.network);
-        this._connectionStatus = "connecting";
-        this._fireStatusChangeEvent(msg.network);
-        break;
-
-      case "WifiManager:onassociate":
-        this._currentNetwork = this._convertWifiNetwork(msg.network);
-        this._connectionStatus = "associated";
-        this._fireStatusChangeEvent(msg.network);
-        break;
-
-      case "WifiManager:onconnect":
-        this._currentNetwork = this._convertWifiNetwork(msg.network);
-        this._connectionStatus = "connected";
-        this._fireStatusChangeEvent(msg.network);
-        break;
-
-      case "WifiManager:ondisconnect":
-        this._currentNetwork = null;
-        this._connectionStatus = "disconnected";
-        this._lastConnectionInfo = null;
-        this._fireStatusChangeEvent(msg.network);
-        break;
-
-      case "WifiManager:onwpstimeout":
-        this._currentNetwork = null;
-        this._connectionStatus = "wps-timedout";
-        this._lastConnectionInfo = null;
-        this._fireStatusChangeEvent(msg.network);
-        break;
-
-      case "WifiManager:onwpsfail":
-        this._currentNetwork = null;
-        this._connectionStatus = "wps-failed";
-        this._lastConnectionInfo = null;
-        this._fireStatusChangeEvent(msg.network);
-        break;
-
-      case "WifiManager:onwpsoverlap":
-        this._currentNetwork = null;
-        this._connectionStatus = "wps-overlapped";
-        this._lastConnectionInfo = null;
-        this._fireStatusChangeEvent(msg.network);
-        break;
-
-      case "WifiManager:connectioninfoupdate":
-        this._lastConnectionInfo = this._convertConnectionInfo(msg);
-        this._fireConnectionInfoUpdate(msg);
-        break;
-      case "WifiManager:onconnectingfailed":
-        this._currentNetwork = null;
-        this._connectionStatus = "connectingfailed";
-        this._lastConnectionInfo = null;
-        this._fireStatusChangeEvent(msg.network);
-        break;
-      case "WifiManager:onauthenticating":
-        this._currentNetwork = this._convertWifiNetwork(msg.network);
-        this._connectionStatus = "authenticating";
-        this._fireStatusChangeEvent(msg.network);
-        break;
-      case "WifiManager:stationinfoupdate":
-        this._stationNumber = msg.station;
-        this._fireStationInfoUpdate(msg);
-        break;
-    }
-  },
-
-  _fireStatusChangeEvent: function StatusChangeEvent(aNetwork) {
-    var event = new this._window.MozWifiStatusChangeEvent("statuschange",
-                                                          { network: this._convertWifiNetwork(aNetwork),
-                                                            status: this._connectionStatus
-                                                          });
-    this.__DOM_IMPL__.dispatchEvent(event);
-  },
-
-  _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);
-  },
-
-  _fireEnabledOrDisabled: function enabledDisabled(enabled) {
-    var evt = new this._window.Event(enabled ? "enabled" : "disabled");
-    this.__DOM_IMPL__.dispatchEvent(evt);
-  },
-
-  _fireStationInfoUpdate: function onStationInfoUpdate(info) {
-    var evt = new this._window.MozWifiStationInfoEvent("stationinfoupdate",
-                                                       { station: this._stationNumber}
-                                                      );
-    this.__DOM_IMPL__.dispatchEvent(evt);
-  },
-
-  setWifiEnabled: function setWifiEnabled(enabled) {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:setWifiEnabled", enabled, request);
-    return request;
-  },
-
-  getNetworks: function getNetworks() {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:getNetworks", null, request);
-    return request;
-  },
-
-  getKnownNetworks: function getKnownNetworks() {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:getKnownNetworks", null, request);
-    return request;
-  },
-
-  associate: function associate(network) {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:associate",
-                                this._convertWifiNetworkToJSON(network), request);
-    return request;
-  },
-
-  forget: function forget(network) {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:forget",
-                                this._convertWifiNetworkToJSON(network), request);
-    return request;
-  },
-
-  wps: function wps(detail) {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:wps", detail, request);
-    return request;
-  },
-
-  setPowerSavingMode: function setPowerSavingMode(enabled) {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:setPowerSavingMode", enabled, request);
-    return request;
-  },
-
-  setHttpProxy: function setHttpProxy(network, info) {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:setHttpProxy",
-                                { network: this._convertWifiNetworkToJSON(network), info:info}, request);
-    return request;
-  },
-
-  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;
-  },
-
-  getImportedCerts: function nsIDOMWifiManager_getImportedCerts() {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:getImportedCerts", null, request);
-    return request;
-  },
-
-  deleteCert: function nsIDOMWifiManager_deleteCert(certNickname) {
-    var request = this.createRequest();
-    this._sendMessageForRequest("WifiManager:deleteCert",
-                                {
-                                  certNickname: certNickname
-                                }, request);
-    return request;
-  },
-
-  get enabled() {
-    return this._enabled;
-  },
-
-  get macAddress() {
-    return this._macAddress;
-  },
-
-  get connection() {
-    let _connection = this._convertConnection({ status: this._connectionStatus,
-                                                network: this._currentNetwork,
-                                              });
-    return _connection;
-  },
-
-  get connectionInformation() {
-    return this._lastConnectionInfo;
-  },
-
-  get capabilities() {
-    return this._capabilities;
-  },
-
-  defineEventHandlerGetterSetter: function(name) {
-    Object.defineProperty(this, name, {
-      get: function() {
-        return this.__DOM_IMPL__.getEventHandler(name);
-      },
-      set: function(handler) {
-        this.__DOM_IMPL__.setEventHandler(name, handler);
-      }
-    });
-  },
-};
-
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
-  DOMWifiManager, MozWifiNetwork, MozWifiConnection, MozWifiCapabilities,
-  MozWifiConnectionInfo
-]);
-
-var debug;
-if (DEBUG) {
-  debug = function (s) {
-    dump("-*- DOMWifiManager component: " + s + "\n");
-  };
-} else {
-  debug = function (s) {};
-}
deleted file mode 100644
--- a/dom/wifi/DOMWifiManager.manifest
+++ /dev/null
@@ -1,18 +0,0 @@
-# DOMWifiManager.js
-component {c9b5f09e-25d2-40ca-aef4-c4d13d93c706} DOMWifiManager.js
-contract @mozilla.org/wifimanager;1 {c9b5f09e-25d2-40ca-aef4-c4d13d93c706}
-
-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}
-
-component {08c88ece-8092-481b-863b-5515a52e411a} DOMWifiManager.js
-contract @mozilla.org/mozwificapabilities;1 {08c88ece-8092-481b-863b-5515a52e411a}
deleted file mode 100644
--- a/dom/wifi/DOMWifiP2pManager.js
+++ /dev/null
@@ -1,328 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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");
-Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
-
-const DEBUG = false;
-
-// interface MozWifiP2pGroupOwner implementation.
-
-function MozWifiP2pGroupOwner(aGo) {
-  this.groupName = aGo.groupName;
-  this.macAddress = aGo.macAddress;
-  this.ipAddress = aGo.ipAddress;
-  this.passphrase = aGo.passphrase;
-  this.ssid = aGo.ssid;
-  this.wpsCapabilities = aGo.wpsCapabilities;
-  this.freq = aGo.freq;
-  this.isLocal = aGo.isLocal;
-}
-
-MozWifiP2pGroupOwner.prototype = {
-  classID: Components.ID("{a9b81450-349d-11e3-aa6e-0800200c9a66}"),
-  contractID: "@mozilla.org/wifip2pgroupowner;1",
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports])
-};
-
-// interface MozWifiP2pManager implementation.
-
-const MOZ_WIFIP2PMANAGER_CONTRACTID = "@mozilla.org/wifip2pmanager;1";
-const MOZ_WIFIP2PMANAGER_CID        = Components.ID("{8d9125a0-3498-11e3-aa6e-0800200c9a66}");
-
-function MozWifiP2pManager() {
-  this.defineEventHandlerGetterSetter("onstatuschange");
-  this.defineEventHandlerGetterSetter("onpeerinfoupdate");
-  this.defineEventHandlerGetterSetter("onenabled");
-  this.defineEventHandlerGetterSetter("ondisabled");
-
-  this.currentPeer = null;
-  this.enabled = false;
-  this.groupOwner = null;
-}
-
-// For smaller, read-only APIs, we expose any property that doesn't begin with
-// an underscore.
-function exposeReadOnly(obj) {
-  let exposedProps = {};
-  for (let i in obj) {
-    if (i[0] === "_") {
-      continue;
-    }
-    exposedProps[i] = "r";
-  }
-
-  obj.__exposedProps__ = exposedProps;
-  return obj;
-}
-
-function debug(msg) {
-  if (DEBUG) {
-    dump('-------------- MozWifiP2pManager: ' + msg);
-  }
-}
-
-MozWifiP2pManager.prototype = {
-  __proto__: DOMRequestIpcHelper.prototype,
-
-  classID:        MOZ_WIFIP2PMANAGER_CID,
-  contractID:     MOZ_WIFIP2PMANAGER_CONTRACTID,
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGlobalPropertyInitializer,
-                                         Ci.nsISupportsWeakReference,
-                                         Ci.nsIObserver,
-                                         Ci.nsISupports]),
-
-  //
-  // nsIDOMGlobalPropertyInitializer implementation.
-  //
-
-  init: function(aWindow) {
-    const messages = ["WifiP2pManager:setScanEnabled:Return:OK",
-                      "WifiP2pManager:setScanEnabled:Return:NO",
-                      "WifiP2pManager:getPeerList:Return:OK",
-                      "WifiP2pManager:getPeerList:Return:NO",
-                      "WifiP2pManager:connect:Return:OK",
-                      "WifiP2pManager:connect:Return:NO",
-                      "WifiP2pManager:disconnect:Return:OK",
-                      "WifiP2pManager:disconnect:Return:NO",
-                      "WifiP2pManager:setPairingConfirmation:Return",
-                      "WifiP2pManager:setDeviceName:Return:OK",
-                      "WifiP2pManager:setDeviceName:Return:NO",
-
-                      "WifiP2pManager:p2pDown",
-                      "WifiP2pManager:p2pUp",
-                      "WifiP2pManager:onconnecting",
-                      "WifiP2pManager:onconnected",
-                      "WifiP2pManager:ondisconnected",
-                      "WifiP2pManager:ongroupnstop",
-                      "WifiP2pManager:onconnectingfailed",
-                      "WifiP2pManager:onwpstimeout",
-                      "WifiP2pManager:onwpsfail",
-                      "WifiP2pManager:onpeerinfoupdate",
-                      ];
-
-    this.initDOMRequestHelper(aWindow, messages);
-    this._mm = Cc["@mozilla.org/childprocessmessagemanager;1"].getService(Ci.nsISyncMessageSender);
-
-    // Notify the internal a new DOM mananger is created.
-    let state = this._mm.sendSyncMessage("WifiP2pManager:getState")[0];
-    if (state) {
-      debug('State: ' + JSON.stringify(state));
-      this.enabled = state.enabled;
-      this.currentPeer = state.currentPeer;
-      if (state.groupOwner) {
-        this.groupOwner = new MozWifiP2pGroupOwner(state.groupOwner);
-      }
-    } else {
-      debug('Failed to get state');
-    }
-  },
-
-  uninit: function() {
-  },
-
-  _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) {
-      return;
-    }
-
-    let request;
-    switch (aMessage.name) {
-     case "WifiP2pManager:setScanEnabled:Return:OK":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
-        break;
-
-      case "WifiP2pManager:setScanEnabled:Return:NO":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireError(request, "Unable to enable/disable Wifi P2P peer discovery.");
-        break;
-
-     case "WifiP2pManager:getPeerList:Return:OK":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireSuccess(request, Cu.cloneInto(msg.data, this._window));
-        break;
-
-      case "WifiP2pManager:getPeerList:Return:NO":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireError(request, "Unable to disable Wifi P2P peer discovery.");
-        break;
-
-      case "WifiP2pManager:connect:Return:OK":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
-        break;
-
-      case "WifiP2pManager:connect:Return:NO":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireError(request, "Unable to connect to Wifi P2P peer.");
-        break;
-
-      case "WifiP2pManager:disconnect:Return:OK":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
-        break;
-
-      case "WifiP2pManager:disconnect:Return:NO":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireError(request, "Unable to disconnect to Wifi P2P peer.");
-        break;
-
-      case "WifiP2pManager:setDeviceName:Return:OK":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireSuccess(request, exposeReadOnly(msg.data));
-        break;
-
-      case "WifiP2pManager:setDeviceName:Return:NO":
-        request = this.takeRequest(msg.rid);
-        Services.DOMRequest.fireError(request, "Unable to set device name.");
-        break;
-
-      case "WifiP2pManager:p2pDown":
-        this.enabled = false;
-        this.currentPeer = null;
-        this._fireEnabledOrDisabled(false);
-        break;
-
-      case "WifiP2pManager:p2pUp":
-        this.enabled = true;
-        this._fireEnabledOrDisabled(true);
-        break;
-
-      case "WifiP2pManager:onconnecting":
-        debug('onconnecting with peer: ' + JSON.stringify(msg.peer));
-        this.currentPeer = msg.peer;
-        this._fireStatusChangeEvent(msg.peer.address);
-        break;
-
-      case "WifiP2pManager:onconnected":
-        debug('onconnected with peer: ' + JSON.stringify(msg.peer));
-        this.currentPeer = msg.peer;
-        this.groupOwner = new MozWifiP2pGroupOwner(msg.groupOwner);
-        this._fireStatusChangeEvent(msg.peer.address);
-        break;
-
-      case "WifiP2pManager:ondisconnected":
-        debug('ondisconnected with peer: ' + JSON.stringify(msg.peer));
-        this.currentPeer = null;
-        this.groupOwner = null;
-        this._fireStatusChangeEvent(msg.peer.address);
-        break;
-
-      case "WifiP2pManager:onconnectingfailed":
-        this._fireStatusChangeEvent(null);
-        break;
-
-      case "WifiP2pManager:onwpstimeout":
-        this._fireStatusChangeEvent(null);
-        break;
-
-      case "WifiP2pManager:onwpsfail":
-        this._fireStatusChangeEvent(null);
-        break;
-
-      case "WifiP2pManager:onpeerinfoupdate":
-        this._firePeerInfoUpdateEvent();
-        break;
-    }
-  },
-
-  _firePeerInfoUpdateEvent: function PeerInfoUpdate() {
-    let evt = new this._window.Event("peerinfoupdate");
-    this.__DOM_IMPL__.dispatchEvent(evt);
-  },
-
-  _fireStatusChangeEvent: function WifiP2pStatusChange(peerAddress) {
-    let evt = new this._window.MozWifiP2pStatusChangeEvent("statuschange",
-                                                           { peerAddress: peerAddress });
-    this.__DOM_IMPL__.dispatchEvent(evt);
-  },
-
-  _fireEnabledOrDisabled: function enabledDisabled(enabled) {
-    let evt = new this._window.Event(enabled ? "enabled" : "disabled");
-    this.__DOM_IMPL__.dispatchEvent(evt);
-  },
-
-  //
-  // WifiP2pManager.webidl implementation.
-  //
-
-  enableScan: function () {
-    let request = this.createRequest();
-    this._sendMessageForRequest("WifiP2pManager:enableScan", null, request);
-    return request;
-  },
-
-  disableScan: function () {
-    let request = this.createRequest();
-    this._sendMessageForRequest("WifiP2pManager:disableScan", null, request);
-    return request;
-  },
-
-  setScanEnabled: function(enabled) {
-    let request = this.createRequest();
-    this._sendMessageForRequest("WifiP2pManager:setScanEnabled", enabled, request);
-    return request;
-  },
-
-  connect: function (address, wpsMethod, goIntent) {
-    let request = this.createRequest();
-    let connectionInfo = { address: address, wpsMethod: wpsMethod, goIntent: goIntent };
-    this._sendMessageForRequest("WifiP2pManager:connect", connectionInfo, request);
-    return request;
-  },
-
-  disconnect: function (address) {
-    let request = this.createRequest();
-    this._sendMessageForRequest("WifiP2pManager:disconnect", address, request);
-    return request;
-  },
-
-  getPeerList: function () {
-    let request = this.createRequest();
-    this._sendMessageForRequest("WifiP2pManager:getPeerList", null, request);
-    return request;
-  },
-
-  setPairingConfirmation: function (accepted, pin) {
-    let request = this.createRequest();
-    let result = { accepted: accepted, pin: pin };
-    this._sendMessageForRequest("WifiP2pManager:setPairingConfirmation", result, request);
-    return request;
-  },
-
-  setDeviceName: function(newDeviceName) {
-    let request = this.createRequest();
-    this._sendMessageForRequest("WifiP2pManager:setDeviceName", newDeviceName, request);
-    return request;
-  },
-
-  // Helpers.
-  defineEventHandlerGetterSetter: function(event) {
-    Object.defineProperty(this, event, {
-      get: function() {
-        return this.__DOM_IMPL__.getEventHandler(event);
-      },
-
-      set: function(handler) {
-        this.__DOM_IMPL__.setEventHandler(event, handler);
-      }
-    });
-  },
-};
-
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MozWifiP2pManager, MozWifiP2pGroupOwner]);
deleted file mode 100644
--- a/dom/wifi/DOMWifiP2pManager.manifest
+++ /dev/null
@@ -1,6 +0,0 @@
-# DOMWifiP2pManager.js
-component {8d9125a0-3498-11e3-aa6e-0800200c9a66} DOMWifiP2pManager.js
-contract @mozilla.org/wifip2pmanager;1 {8d9125a0-3498-11e3-aa6e-0800200c9a66}
-
-component {a9b81450-349d-11e3-aa6e-0800200c9a66} DOMWifiP2pManager.js
-contract @mozilla.org/wifip2pgroupowner;1 {a9b81450-349d-11e3-aa6e-0800200c9a66}
\ No newline at end of file
deleted file mode 100644
--- a/dom/wifi/StateMachine.jsm
+++ /dev/null
@@ -1,205 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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/Services.jsm");
-
-this.EXPORTED_SYMBOLS = ["StateMachine"];
-
-const DEBUG = false;
-
-this.StateMachine = function(aDebugTag) {
-  function debug(aMsg) {
-    dump('-------------- StateMachine:' + aDebugTag + ': ' + aMsg);
-  }
-
-  var sm = {};
-
-  var _initialState;
-  var _curState;
-  var _prevState;
-  var _paused;
-  var _eventQueue = [];
-  var _deferredEventQueue = [];
-  var _defaultEventHandler;
-
-  // Public interfaces.
-
-  sm.setDefaultEventHandler = function(aDefaultEventHandler) {
-    _defaultEventHandler = aDefaultEventHandler;
-  };
-
-  sm.start = function(aInitialState) {
-    _initialState = aInitialState;
-    sm.gotoState(_initialState);
-  };
-
-  sm.sendEvent = function (aEvent) {
-    if (!_initialState) {
-      if (DEBUG) {
-        debug('StateMachine is not running. Call StateMachine.start() first.');
-      }
-      return;
-    }
-    _eventQueue.push(aEvent);
-    asyncCall(handleFirstEvent);
-  };
-
-  sm.getPreviousState = function() {
-    return _prevState;
-  };
-
-  sm.getCurrentState = function() {
-    return _curState;
-  };
-
-  // State object maker.
-  // @param aName string for this state's name.
-  // @param aDelegate object:
-  //    .handleEvent: required.
-  //    .enter: called before entering this state (optional).
-  //    .exit: called before exiting this state (optional).
-  sm.makeState = function (aName, aDelegate) {
-    if (!aDelegate.handleEvent) {
-      throw "handleEvent is a required delegate function.";
-    }
-    var nop = function() {};
-    return {
-      name: aName,
-      enter: (aDelegate.enter || nop),
-      exit: (aDelegate.exit || nop),
-      handleEvent: aDelegate.handleEvent
-    };
-  };
-
-  sm.deferEvent = function (aEvent) {
-    // The definition of a 'deferred event' is:
-    //     We are not able to handle this event now but after receiving
-    //     certain event or entering a new state, we might be able to handle
-    //     it. For example, we couldn't handle CONNECT_EVENT in the
-    //     diconnecting state. But once we finish doing "disconnecting", we
-    //     could then handle CONNECT_EVENT!
-    //
-    // So, the deferred event may be handled in the following cases:
-    //     1. Once we entered a new state.
-    //     2. Once we handled a regular event.
-    if (DEBUG) {
-      debug('Deferring event: ' + JSON.stringify(aEvent));
-    }
-    _deferredEventQueue.push(aEvent);
-  };
-
-  // Goto the new state. If the current state is null, the exit
-  // function won't be called.
-  sm.gotoState = function (aNewState) {
-    if (_curState) {
-      if (DEBUG) {
-        debug("exiting state: " + _curState.name);
-      }
-      _curState.exit();
-    }
-
-    _prevState = _curState;
-    _curState = aNewState;
-
-    if (DEBUG) {
-      debug("entering state: " + _curState.name);
-    }
-    _curState.enter();
-
-    // We are in the new state now. We got a chance to handle the
-    // deferred events.
-    handleDeferredEvents();
-
-    sm.resume();
-  };
-
-  // No incoming event will be handled after you call pause().
-  // (But they will be queued.)
-  sm.pause = function() {
-    _paused = true;
-  };
-
-  // Continue to handle incoming events.
-  sm.resume = function() {
-    _paused = false;
-    asyncCall(handleFirstEvent);
-  };
-
-  //----------------------------------------------------------
-  // Private stuff
-  //----------------------------------------------------------
-
-  function asyncCall(f) {
-    Services.tm.currentThread.dispatch(f, Ci.nsIThread.DISPATCH_NORMAL);
-  }
-
-  function handleFirstEvent() {
-    var hadDeferredEvents;
-
-    if (0 === _eventQueue.length) {
-      return;
-    }
-
-    if (_paused) {
-      return; // The state machine is paused now.
-    }
-
-    hadDeferredEvents = _deferredEventQueue.length > 0;
-
-    handleOneEvent(_eventQueue.shift()); // The handler may defer this event.
-
-    // We've handled one event. If we had deferred events before, now is
-    // a good chance to handle them.
-    if (hadDeferredEvents) {
-      handleDeferredEvents();
-    }
-
-    // Continue to handle the next regular event.
-    handleFirstEvent();
-  }
-
-  function handleDeferredEvents() {
-    if (_deferredEventQueue.length && DEBUG) {
-      debug('Handle deferred events: ' + _deferredEventQueue.length);
-    }
-    for (let i = 0; i < _deferredEventQueue.length; i++) {
-      handleOneEvent(_deferredEventQueue.shift());
-    }
-  }
-
-  function handleOneEvent(aEvent)
-  {
-    if (DEBUG) {
-      debug('Handling event: ' + JSON.stringify(aEvent));
-    }
-
-    var handled = _curState.handleEvent(aEvent);
-
-    if (undefined === handled) {
-      throw "handleEvent returns undefined: " + _curState.name;
-    }
-    if (!handled) {
-      // Event is not handled in the current state. Try handleEventCommon().
-      handled = (_defaultEventHandler ? _defaultEventHandler(aEvent) : handled);
-    }
-    if (undefined === handled) {
-      throw "handleEventCommon returns undefined: " + _curState.name;
-    }
-    if (!handled) {
-      if (DEBUG) {
-        debug('!!!!!!!!! FIXME !!!!!!!!! Event not handled: ' + JSON.stringify(aEvent));
-      }
-    }
-
-    return handled;
-  }
-
-  return sm;
-};
deleted file mode 100644
--- a/dom/wifi/WifiCertService.cpp
+++ /dev/null
@@ -1,536 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#include "WifiCertService.h"
-
-#include "mozilla/ClearOnShutdown.h"
-#include "mozilla/EndianUtils.h"
-#include "mozilla/ModuleUtils.h"
-#include "mozilla/RefPtr.h"
-#include "mozilla/dom/File.h"
-#include "mozilla/dom/ToJSValue.h"
-#include "cert.h"
-#include "certdb.h"
-#include "CryptoTask.h"
-#include "nsIDOMBlob.h"
-#include "nsIWifiService.h"
-#include "nsNetUtil.h"
-#include "nsIInputStream.h"
-#include "nsServiceManagerUtils.h"
-#include "nsXULAppAPI.h"
-#include "ScopedNSSTypes.h"
-
-#define NS_WIFICERTSERVICE_CID \
-  { 0x83585afd, 0x0e11, 0x43aa, {0x83, 0x46, 0xf3, 0x4d, 0x97, 0x5e, 0x46, 0x77} }
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-namespace mozilla {
-
-// The singleton Wifi Cert service, to be used on the main thread.
-StaticRefPtr<WifiCertService> gWifiCertService;
-
-class ImportCertTask final: public CryptoTask
-{
-public:
-  ImportCertTask(int32_t aId, Blob* aCertBlob,
-                 const nsAString& aCertPassword,
-                 const nsAString& aCertNickname)
-    : mBlob(aCertBlob)
-    , mPassword(aCertPassword)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    mResult.mId = aId;
-    mResult.mStatus = 0;
-    mResult.mUsageFlag = 0;
-    mResult.mNickname = aCertNickname;
-  }
-
-private:
-  virtual void ReleaseNSSResources() {}
-
-  virtual nsresult CalculateResult() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    // read data from blob.
-    nsCString blobBuf;
-    nsresult rv = ReadBlob(blobBuf);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    char* buf;
-    uint32_t size = blobBuf.GetMutableData(&buf);
-    if (size == 0) {
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-
-    // Try import as DER format first.
-    rv = ImportDERBlob(buf, size);
-    if (NS_SUCCEEDED(rv)) {
-      return rv;
-    }
-
-    // Try import as PKCS#12 format.
-    return ImportPKCS12Blob(buf, size, mPassword);
-  }
-
-  virtual void CallCallback(nsresult rv)
-  {
-    if (NS_FAILED(rv)) {
-      mResult.mStatus = -1;
-    }
-    gWifiCertService->DispatchResult(mResult);
-  }
-
-  nsresult ImportDERBlob(char* buf, uint32_t size)
-  {
-    // Create certificate object.
-    ScopedCERTCertificate cert(CERT_DecodeCertFromPackage(buf, size));
-    if (!cert) {
-      return MapSECStatus(SECFailure);
-    }
-
-    // Import certificate.
-    return ImportCert(cert);
-  }
-
-  static SECItem*
-  HandleNicknameCollision(SECItem* aOldNickname, PRBool* aCancel, void* aWincx)
-  {
-    const char* dummyName = "Imported User Cert";
-    const size_t dummyNameLen = strlen(dummyName);
-    SECItem* newNick = ::SECITEM_AllocItem(nullptr, nullptr, dummyNameLen + 1);
-    if (!newNick) {
-      return nullptr;
-    }
-
-    newNick->type = siAsciiString;
-    // Dummy name, will be renamed later.
-    memcpy(newNick->data, dummyName, dummyNameLen + 1);
-    newNick->len = dummyNameLen;
-
-    return newNick;
-  }
-
-  static SECStatus
-  HandleNicknameUpdate(const CERTCertificate *aCert,
-                       const SECItem *default_nickname,
-                       SECItem **new_nickname,
-                       void *arg)
-  {
-    WifiCertServiceResultOptions *result = (WifiCertServiceResultOptions *)arg;
-
-    nsCString userNickname;
-    CopyUTF16toUTF8(result->mNickname, userNickname);
-
-    nsCString fullNickname;
-    if (aCert->isRoot && (aCert->nsCertType & NS_CERT_TYPE_SSL_CA)) {
-      // Accept self-signed SSL CA as server certificate.
-      fullNickname.AssignLiteral("WIFI_SERVERCERT_");
-      fullNickname += userNickname;
-      result->mUsageFlag |= nsIWifiCertService::WIFI_CERT_USAGE_FLAG_SERVER;
-    } else if (aCert->nsCertType & NS_CERT_TYPE_SSL_CLIENT) {
-      // User Certificate
-      fullNickname.AssignLiteral("WIFI_USERCERT_");
-      fullNickname += userNickname;
-      result->mUsageFlag |= nsIWifiCertService::WIFI_CERT_USAGE_FLAG_USER;
-    }
-    char* nickname;
-    uint32_t length = fullNickname.GetMutableData(&nickname);
-
-    SECItem* newNick = ::SECITEM_AllocItem(nullptr, nullptr, length + 1);
-    if (!newNick) {
-      return SECFailure;
-    }
-
-    newNick->type = siAsciiString;
-    memcpy(newNick->data, nickname, length + 1);
-    newNick->len = length;
-
-    *new_nickname = newNick;
-    return SECSuccess;
-  }
-
-  nsresult ImportPKCS12Blob(char* buf, uint32_t size, const nsAString& aPassword)
-  {
-    nsString password(aPassword);
-
-    // password is null-terminated wide-char string.
-    // passwordItem is required to be big-endian form of password, stored in char
-    // array, including the null-termination.
-    uint32_t length = password.Length() + 1;
-    ScopedSECItem passwordItem(
-      ::SECITEM_AllocItem(nullptr, nullptr, length * sizeof(nsString::char_type)));
-
-    if (!passwordItem) {
-      return NS_ERROR_FAILURE;
-    }
-
-    mozilla::NativeEndian::copyAndSwapToBigEndian(passwordItem->data,
-                                                  password.BeginReading(),
-                                                  length);
-    // Create a decoder.
-    ScopedSEC_PKCS12DecoderContext p12dcx(SEC_PKCS12DecoderStart(
-                                            passwordItem, nullptr, nullptr,
-                                            nullptr, nullptr, nullptr, nullptr,
-                                            nullptr));
-
-    if (!p12dcx) {
-      return NS_ERROR_FAILURE;
-    }
-
-    // Assign data to decorder.
-    SECStatus srv = SEC_PKCS12DecoderUpdate(p12dcx,
-                                            reinterpret_cast<unsigned char*>(buf),
-                                            size);
-    if (srv != SECSuccess) {
-      return MapSECStatus(srv);
-    }
-
-    // Verify certificates.
-    srv = SEC_PKCS12DecoderVerify(p12dcx);
-    if (srv != SECSuccess) {
-      return MapSECStatus(srv);
-    }
-
-    // Set certificate nickname and usage flag.
-    srv = SEC_PKCS12DecoderRenameCertNicknames(p12dcx, HandleNicknameUpdate,
-                                               &mResult);
-
-    // Validate certificates.
-    srv = SEC_PKCS12DecoderValidateBags(p12dcx, HandleNicknameCollision);
-    if (srv != SECSuccess) {
-      return MapSECStatus(srv);
-    }
-
-    // Initialize slot.
-    ScopedPK11SlotInfo slot(PK11_GetInternalKeySlot());
-    if (!slot) {
-      return NS_ERROR_FAILURE;
-    }
-    if (PK11_NeedLogin(slot) && PK11_NeedUserInit(slot)) {
-      srv = PK11_InitPin(slot, "", "");
-      if (srv != SECSuccess) {
-        return MapSECStatus(srv);
-      }
-    }
-
-    // Import cert and key.
-    srv = SEC_PKCS12DecoderImportBags(p12dcx);
-    if (srv != SECSuccess) {
-      return MapSECStatus(srv);
-    }
-
-    // User certificate must be imported from PKCS#12.
-    return (mResult.mUsageFlag & nsIWifiCertService::WIFI_CERT_USAGE_FLAG_USER)
-            ? NS_OK : NS_ERROR_FAILURE;
-  }
-
-  nsresult ReadBlob(/*out*/ nsCString& aBuf)
-  {
-    NS_ENSURE_ARG_POINTER(mBlob);
-
-    static const uint64_t MAX_FILE_SIZE = 16384;
-
-    ErrorResult rv;
-    uint64_t size = mBlob->GetSize(rv);
-    if (NS_WARN_IF(rv.Failed())) {
-      return rv.StealNSResult();
-    }
-
-    if (size > MAX_FILE_SIZE) {
-      return NS_ERROR_FILE_TOO_BIG;
-    }
-
-    nsCOMPtr<nsIInputStream> inputStream;
-    mBlob->GetInternalStream(getter_AddRefs(inputStream), rv);
-    if (NS_WARN_IF(rv.Failed())) {
-      return rv.StealNSResult();
-    }
-
-    rv = NS_ReadInputStreamToString(inputStream, aBuf, (uint32_t)size);
-    if (NS_WARN_IF(rv.Failed())) {
-      return rv.StealNSResult();
-    }
-
-    return NS_OK;
-  }
-
-  nsresult ImportCert(CERTCertificate* aCert)
-  {
-    nsCString userNickname, fullNickname;
-
-    CopyUTF16toUTF8(mResult.mNickname, userNickname);
-    // Determine certificate nickname by adding prefix according to its type.
-    if (aCert->isRoot && (aCert->nsCertType & NS_CERT_TYPE_SSL_CA)) {
-      // Accept self-signed SSL CA as server certificate.
-      fullNickname.AssignLiteral("WIFI_SERVERCERT_");
-      fullNickname += userNickname;
-      mResult.mUsageFlag |= nsIWifiCertService::WIFI_CERT_USAGE_FLAG_SERVER;
-    } else if (aCert->nsCertType & NS_CERT_TYPE_SSL_CLIENT) {
-      // User Certificate
-      fullNickname.AssignLiteral("WIFI_USERCERT_");
-      fullNickname += userNickname;
-      mResult.mUsageFlag |= nsIWifiCertService::WIFI_CERT_USAGE_FLAG_USER;
-    } else {
-      return NS_ERROR_ABORT;
-    }
-
-    char* nickname;
-    uint32_t length;
-    length = fullNickname.GetMutableData(&nickname);
-    if (length == 0) {
-      return NS_ERROR_UNEXPECTED;
-    }
-
-    // Import certificate, duplicated nickname will cause error.
-    SECStatus srv = CERT_AddTempCertToPerm(aCert, nickname, nullptr);
-    if (srv != SECSuccess) {
-      return MapSECStatus(srv);
-    }
-
-    return NS_OK;
-  }
-
-  RefPtr<Blob> mBlob;
-  nsString mPassword;
-  WifiCertServiceResultOptions mResult;
-};
-
-class DeleteCertTask final: public CryptoTask
-{
-public:
-  DeleteCertTask(int32_t aId, const nsAString& aCertNickname)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-
-    mResult.mId = aId;
-    mResult.mStatus = 0;
-    mResult.mUsageFlag = 0;
-    mResult.mNickname = aCertNickname;
-  }
-
-private:
-  virtual void ReleaseNSSResources() {}
-
-  virtual nsresult CalculateResult() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-
-    nsCString userNickname;
-    CopyUTF16toUTF8(mResult.mNickname, userNickname);
-
-    // Delete server certificate.
-    nsCString serverCertName("WIFI_SERVERCERT_", 16);
-    serverCertName += userNickname;
-    nsresult rv = deleteCert(serverCertName);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    // Delete user certificate and private key.
-    nsCString userCertName("WIFI_USERCERT_", 14);
-    userCertName += userNickname;
-    rv = deleteCert(userCertName);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    return NS_OK;
-  }
-
-  nsresult deleteCert(const nsCString &aCertNickname)
-  {
-    ScopedCERTCertificate cert(
-      CERT_FindCertByNickname(CERT_GetDefaultCertDB(), aCertNickname.get())
-    );
-    // Because we delete certificates in blind, so it's acceptable to delete
-    // a non-exist certificate.
-    if (!cert) {
-      return NS_OK;
-    }
-
-    ScopedPK11SlotInfo slot(
-      PK11_KeyForCertExists(cert, nullptr, nullptr)
-    );
-
-    SECStatus srv;
-    if (slot) {
-      // Delete private key along with certificate.
-      srv = PK11_DeleteTokenCertAndKey(cert, nullptr);
-    } else {
-      srv = SEC_DeletePermCertificate(cert);
-    }
-
-    if (srv != SECSuccess) {
-      return MapSECStatus(srv);
-    }
-
-    return NS_OK;
-  }
-
-  virtual void CallCallback(nsresult rv)
-  {
-    if (NS_FAILED(rv)) {
-      mResult.mStatus = -1;
-    }
-    gWifiCertService->DispatchResult(mResult);
-  }
-
-  WifiCertServiceResultOptions mResult;
-};
-
-NS_IMPL_ISUPPORTS(WifiCertService, nsIWifiCertService)
-
-NS_IMETHODIMP
-WifiCertService::Start(nsIWifiEventListener* aListener)
-{
-  MOZ_ASSERT(aListener);
-
-  mListener = aListener;
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-WifiCertService::Shutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mListener = nullptr;
-
-  return NS_OK;
-}
-
-void
-WifiCertService::DispatchResult(const WifiCertServiceResultOptions& aOptions)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mozilla::AutoSafeJSContext cx;
-  JS::RootedValue val(cx);
-  nsCString dummyInterface;
-
-  if (!ToJSValue(cx, aOptions, &val)) {
-    return;
-  }
-
-  // Certll the listener with a JS value.
-  mListener->OnCommand(val, dummyInterface);
-}
-
-WifiCertService::WifiCertService()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!gWifiCertService);
-}
-
-WifiCertService::~WifiCertService()
-{
-  MOZ_ASSERT(!gWifiCertService);
-
-  nsNSSShutDownPreventionLock locker;
-  if (isAlreadyShutDown()) {
-    return;
-  }
-  shutdown(ShutdownCalledFrom::Object);
-}
-
-already_AddRefed<WifiCertService>
-WifiCertService::FactoryCreate()
-{
-  if (!XRE_IsParentProcess()) {
-    return nullptr;
-  }
-
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!gWifiCertService) {
-    gWifiCertService = new WifiCertService();
-    ClearOnShutdown(&gWifiCertService);
-  }
-
-  RefPtr<WifiCertService> service = gWifiCertService.get();
-  return service.forget();
-}
-
-NS_IMETHODIMP
-WifiCertService::ImportCert(int32_t aId, nsIDOMBlob* aCertBlob,
-                            const nsAString& aCertPassword,
-                            const nsAString& aCertNickname)
-{
-  RefPtr<Blob> blob = static_cast<Blob*>(aCertBlob);
-  RefPtr<CryptoTask> task = new ImportCertTask(aId, blob, aCertPassword,
-                                               aCertNickname);
-  return task->Dispatch("WifiImportCert");
-}
-
-NS_IMETHODIMP
-WifiCertService::DeleteCert(int32_t aId, const nsAString& aCertNickname)
-{
-  RefPtr<CryptoTask> task = new DeleteCertTask(aId, aCertNickname);
-  return task->Dispatch("WifiDeleteCert");
-}
-
-NS_IMETHODIMP
-WifiCertService::HasPrivateKey(const nsAString& aCertNickname, bool *aHasKey)
-{
-  *aHasKey = false;
-
-  nsNSSShutDownPreventionLock locker;
-  if (isAlreadyShutDown()) {
-    return NS_ERROR_NOT_AVAILABLE;
-  }
-
-  nsCString certNickname;
-  CopyUTF16toUTF8(aCertNickname, certNickname);
-
-  ScopedCERTCertificate cert(
-    CERT_FindCertByNickname(CERT_GetDefaultCertDB(), certNickname.get())
-  );
-  if (!cert) {
-    return NS_OK;
-  }
-
-  ScopedPK11SlotInfo slot(
-    PK11_KeyForCertExists(cert, nullptr, nullptr)
-  );
-  if (slot) {
-    *aHasKey = true;
-  }
-
-  return NS_OK;
-}
-
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(WifiCertService,
-                                         WifiCertService::FactoryCreate)
-
-NS_DEFINE_NAMED_CID(NS_WIFICERTSERVICE_CID);
-
-static const mozilla::Module::CIDEntry kWifiCertServiceCIDs[] = {
-  { &kNS_WIFICERTSERVICE_CID, false, nullptr, WifiCertServiceConstructor },
-  { nullptr }
-};
-
-static const mozilla::Module::ContractIDEntry kWifiCertServiceContracts[] = {
-  { "@mozilla.org/wifi/certservice;1", &kNS_WIFICERTSERVICE_CID },
-  { nullptr }
-};
-
-static const mozilla::Module kWifiCertServiceModule = {
-  mozilla::Module::kVersion,
-  kWifiCertServiceCIDs,
-  kWifiCertServiceContracts,
-  nullptr
-};
-
-} // namespace mozilla
-
-NSMODULE_DEFN(WifiCertServiceModule) = &kWifiCertServiceModule;
deleted file mode 100644
--- a/dom/wifi/WifiCertService.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#ifndef WifiCertService_h
-#define WifiCertService_h
-
-#include "nsIWifiCertService.h"
-#include "nsCOMPtr.h"
-#include "nsNSSShutDown.h"
-#include "nsThread.h"
-#include "mozilla/dom/WifiOptionsBinding.h"
-
-namespace mozilla {
-namespace dom {
-
-class WifiCertService final : public nsIWifiCertService,
-                              public nsNSSShutDownObject
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIWIFICERTSERVICE
-
-  static already_AddRefed<WifiCertService>
-  FactoryCreate();
-  void DispatchResult(const mozilla::dom::WifiCertServiceResultOptions& aOptions);
-
-private:
-  WifiCertService();
-  ~WifiCertService();
-  virtual void virtualDestroyNSSReference() {};
-  nsCOMPtr<nsIWifiEventListener> mListener;
-};
-
-} // namespce dom
-} // namespace mozilla
-
-#endif // WifiCertService_h
deleted file mode 100644
--- a/dom/wifi/WifiCommand.jsm
+++ /dev/null
@@ -1,594 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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";
-
-this.EXPORTED_SYMBOLS = ["WifiCommand"];
-
-const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
-
-Cu.import("resource://gre/modules/systemlibs.js");
-
-const SUPP_PROP = "init.svc.wpa_supplicant";
-const WPA_SUPPLICANT = "wpa_supplicant";
-const DEBUG = false;
-
-this.WifiCommand = function(aControlMessage, aInterface, aSdkVersion) {
-  function debug(msg) {
-    if (DEBUG) {
-      dump('-------------- WifiCommand: ' + msg);
-    }
-  }
-
-  var command = {};
-
-  //-------------------------------------------------
-  // Utilities.
-  //-------------------------------------------------
-  command.getSdkVersion = function() {
-    return aSdkVersion;
-  };
-
-  //-------------------------------------------------
-  // General commands.
-  //-------------------------------------------------
-
-  command.loadDriver = function (callback) {
-    voidControlMessage("load_driver", function(status) {
-      callback(status);
-    });
-  };
-
-  command.unloadDriver = function (callback) {
-    voidControlMessage("unload_driver", function(status) {
-      callback(status);
-    });
-  };
-
-  command.startSupplicant = function (callback) {
-    voidControlMessage("start_supplicant", callback);
-  };
-
-  command.killSupplicant = function (callback) {
-    // It is interesting to note that this function does exactly what
-    // wifi_stop_supplicant does. Unforunately, on the Galaxy S2, Samsung
-    // changed that function in a way that means that it doesn't recognize
-    // wpa_supplicant as already running. Therefore, we have to roll our own
-    // version here.
-    stopProcess(SUPP_PROP, WPA_SUPPLICANT, callback);
-  };
-
-  command.terminateSupplicant = function (callback) {
-    doBooleanCommand("TERMINATE", "OK", callback);
-  };
-
-  command.stopSupplicant = function (callback) {
-    voidControlMessage("stop_supplicant", callback);
-  };
-
-  command.listNetworks = function (callback) {
-    doStringCommand("LIST_NETWORKS", callback);
-  };
-
-  command.addNetwork = function (callback) {
-    doIntCommand("ADD_NETWORK", callback);
-  };
-
-  command.setNetworkVariable = function (netId, name, value, callback) {
-    doBooleanCommand("SET_NETWORK " + netId + " " + name + " " +
-                      value, "OK", callback);
-  };
-
-  command.getNetworkVariable = function (netId, name, callback) {
-    doStringCommand("GET_NETWORK " + netId + " " + name, callback);
-  };
-
-  command.removeNetwork = function (netId, callback) {
-    doBooleanCommand("REMOVE_NETWORK " + netId, "OK", callback);
-  };
-
-  command.enableNetwork = function (netId, disableOthers, callback) {
-    doBooleanCommand((disableOthers ? "SELECT_NETWORK " : "ENABLE_NETWORK ") +
-                     netId, "OK", callback);
-  };
-
-  command.disableNetwork = function (netId, callback) {
-    doBooleanCommand("DISABLE_NETWORK " + netId, "OK", callback);
-  };
-
-  command.status = function (callback) {
-    doStringCommand("STATUS", callback);
-  };
-
-  command.ping = function (callback) {
-    doBooleanCommand("PING", "PONG", callback);
-  };
-
-  command.scanResults = function (callback) {
-    doStringCommand("SCAN_RESULTS", callback);
-  };
-
-  command.disconnect = function (callback) {
-    doBooleanCommand("DISCONNECT", "OK", callback);
-  };
-
-  command.reconnect = function (callback) {
-    doBooleanCommand("RECONNECT", "OK", callback);
-  };
-
-  command.reassociate = function (callback) {
-    doBooleanCommand("REASSOCIATE", "OK", callback);
-  };
-
-  command.setBackgroundScan = function (enable, callback) {
-    doBooleanCommand("SET pno " + (enable ? "1" : "0"),
-                     "OK",
-                     function(ok) {
-                       callback(true, ok);
-                     });
-  };
-
-  command.doSetScanMode = function (setActive, callback) {
-    doBooleanCommand(setActive ?
-                     "DRIVER SCAN-ACTIVE" :
-                     "DRIVER SCAN-PASSIVE", "OK", callback);
-  };
-
-  command.scan = function (callback) {
-    doBooleanCommand("SCAN", "OK", callback);
-  };
-
-  command.setLogLevel = function (level, callback) {
-    doBooleanCommand("LOG_LEVEL " + level, "OK", callback);
-  };
-
-  command.getLogLevel = function (callback) {
-    doStringCommand("LOG_LEVEL", callback);
-  };
-
-  command.wpsPbc = function (callback, iface) {
-    let cmd = 'WPS_PBC';
-
-    // If the network interface is specified and we are based on JB,
-    // append the argument 'interface=[iface]' to the supplicant command.
-    //
-    // Note: The argument "interface" is only required for wifi p2p on JB.
-    //       For other cases, the argument is useless and even leads error.
-    //       Check the evil work here:
-    //       http://androidxref.com/4.2.2_r1/xref/external/wpa_supplicant_8/wpa_supplicant/ctrl_iface_unix.c#172
-    //
-    if (iface && isJellybean()) {
-      cmd += (' inferface=' + iface);
-    }
-
-    doBooleanCommand(cmd, "OK", callback);
-  };
-
-  command.wpsPin = function (detail, callback) {
-    let cmd = 'WPS_PIN ';
-
-    // See the comment above in wpsPbc().
-    if (detail.iface && isJellybean()) {
-      cmd += ('inferface=' + iface + ' ');
-    }
-
-    cmd += (detail.bssid === undefined ? "any" : detail.bssid);
-    cmd += (detail.pin === undefined ? "" : (" " + detail.pin));
-
-    doStringCommand(cmd, callback);
-  };
-
-  command.wpsCancel = function (callback) {
-    doBooleanCommand("WPS_CANCEL", "OK", callback);
-  };
-
-  command.startDriver = function (callback) {
-    doBooleanCommand("DRIVER START", "OK");
-  };
-
-  command.stopDriver = function (callback) {
-    doBooleanCommand("DRIVER STOP", "OK");
-  };
-
-  command.startPacketFiltering = function (callback) {
-    var commandChain = ["DRIVER RXFILTER-ADD 0",
-                        "DRIVER RXFILTER-ADD 1",
-                        "DRIVER RXFILTER-ADD 3",
-                        "DRIVER RXFILTER-START"];
-
-    doBooleanCommandChain(commandChain, callback);
-  };
-
-  command.stopPacketFiltering = function (callback) {
-    var commandChain = ["DRIVER RXFILTER-STOP",
-                        "DRIVER RXFILTER-REMOVE 3",
-                        "DRIVER RXFILTER-REMOVE 1",
-                        "DRIVER RXFILTER-REMOVE 0"];
-
-    doBooleanCommandChain(commandChain, callback);
-  };
-
-  command.doGetRssi = function (cmd, callback) {
-    doCommand(cmd, function(data) {
-      var rssi = -200;
-
-      if (!data.status) {
-        // If we are associating, the reply is "OK".
-        var reply = data.reply;
-        if (reply !== "OK") {
-          // Format is: <SSID> rssi XX". SSID can contain spaces.
-          var offset = reply.lastIndexOf("rssi ");
-          if (offset !== -1) {
-            rssi = reply.substr(offset + 5) | 0;
-          }
-        }
-      }
-      callback(rssi);
-    });
-  };
-
-  command.getRssi = function (callback) {
-    command.doGetRssi("DRIVER RSSI", callback);
-  };
-
-  command.getRssiApprox = function (callback) {
-    command.doGetRssi("DRIVER RSSI-APPROX", callback);
-  };
-
-  command.getLinkSpeed = function (callback) {
-    doStringCommand("DRIVER LINKSPEED", function(reply) {
-      if (reply) {
-        reply = reply.split(" ")[1] | 0; // Format: LinkSpeed XX
-      }
-      callback(reply);
-    });
-  };
-
-  let infoKeys = [{regexp: /RSSI=/i,      prop: 'rssi'},
-                  {regexp: /LINKSPEED=/i, prop: 'linkspeed'}];
-
-  command.getConnectionInfoICS = function (callback) {
-    doStringCommand("SIGNAL_POLL", function(reply) {
-      if (!reply) {
-        callback(null);
-        return;
-      }
-
-      // Find any values matching |infoKeys|. This gets executed frequently
-      // enough that we want to avoid creating intermediate strings as much as
-      // possible.
-      let rval = {};
-      for (let i = 0; i < infoKeys.length; i++) {
-        let re = infoKeys[i].regexp;
-        let iKeyStart = reply.search(re);
-        if (iKeyStart !== -1) {
-          let prop = infoKeys[i].prop;
-          let iValueStart = reply.indexOf('=', iKeyStart) + 1;
-          let iNewlineAfterValue = reply.indexOf('\n', iValueStart);
-          let iValueEnd = iNewlineAfterValue !== -1
-                        ? iNewlineAfterValue
-                        : reply.length;
-          rval[prop] = reply.substring(iValueStart, iValueEnd) | 0;
-        }
-      }
-
-      callback(rval);
-    });
-  };
-
-  command.getMacAddress = function (callback) {
-    doStringCommand("DRIVER MACADDR", function(reply) {
-      if (reply) {
-        reply = reply.split(" ")[2]; // Format: Macaddr = XX.XX.XX.XX.XX.XX
-      }
-      callback(reply);
-    });
-  };
-
-  command.connectToHostapd = function(callback) {
-    voidControlMessage("connect_to_hostapd", callback);
-  };
-
-  command.closeHostapdConnection = function(callback) {
-    voidControlMessage("close_hostapd_connection", callback);
-  };
-
-  command.hostapdCommand = function (callback, request) {
-    var msg = { cmd:     "hostapd_command",
-                request: request,
-                iface:   aInterface };
-
-    aControlMessage(msg, function(data) {
-      callback(data.status ? null : data.reply);
-    });
-  };
-
-  command.hostapdGetStations = function (callback) {
-    var msg = { cmd:     "hostapd_get_stations",
-                iface:   aInterface };
-
-    aControlMessage(msg, function(data) {
-      callback(data.status);
-    });
-  };
-
-  command.setPowerModeICS = function (mode, callback) {
-    doBooleanCommand("DRIVER POWERMODE " + (mode === "AUTO" ? 0 : 1), "OK", callback);
-  };
-
-  command.setPowerModeJB = function (mode, callback) {
-    doBooleanCommand("SET ps " + (mode === "AUTO" ? 1 : 0), "OK", callback);
-  };
-
-  command.getPowerMode = function (callback) {
-    doStringCommand("DRIVER GETPOWER", function(reply) {
-      if (reply) {
-        reply = (reply.split()[2]|0); // Format: powermode = XX
-      }
-      callback(reply);
-    });
-  };
-
-  command.setNumAllowedChannels = function (numChannels, callback) {
-    doBooleanCommand("DRIVER SCAN-CHANNELS " + numChannels, "OK", callback);
-  };
-
-  command.getNumAllowedChannels = function (callback) {
-    doStringCommand("DRIVER SCAN-CHANNELS", function(reply) {
-      if (reply) {
-        reply = (reply.split()[2]|0); // Format: Scan-Channels = X
-      }
-      callback(reply);
-    });
-  };
-
-  command.setBluetoothCoexistenceMode = function (mode, callback) {
-    doBooleanCommand("DRIVER BTCOEXMODE " + mode, "OK", callback);
-  };
-
-  command.setBluetoothCoexistenceScanMode = function (mode, callback) {
-    doBooleanCommand("DRIVER BTCOEXSCAN-" + (mode ? "START" : "STOP"),
-                     "OK", callback);
-  };
-
-  command.saveConfig = function (callback) {
-    // Make sure we never write out a value for AP_SCAN other than 1.
-    doBooleanCommand("AP_SCAN 1", "OK", function(ok) {
-      doBooleanCommand("SAVE_CONFIG", "OK", callback);
-    });
-  };
-
-  command.reloadConfig = function (callback) {
-    doBooleanCommand("RECONFIGURE", "OK", callback);
-  };
-
-  command.setScanResultHandling = function (mode, callback) {
-    doBooleanCommand("AP_SCAN " + mode, "OK", callback);
-  };
-
-  command.addToBlacklist = function (bssid, callback) {
-    doBooleanCommand("BLACKLIST " + bssid, "OK", callback);
-  };
-
-  command.clearBlacklist = function (callback) {
-    doBooleanCommand("BLACKLIST clear", "OK", callback);
-  };
-
-  command.setSuspendOptimizationsICS = function (enabled, callback) {
-    doBooleanCommand("DRIVER SETSUSPENDOPT " + (enabled ? 0 : 1),
-                     "OK", callback);
-  };
-
-  command.setSuspendOptimizationsJB = function (enabled, callback) {
-    doBooleanCommand("DRIVER SETSUSPENDMODE " + (enabled ? 1 : 0),
-                     "OK", callback);
-  };
-
-  command.connectToSupplicant = function(callback) {
-    voidControlMessage("connect_to_supplicant", callback);
-  };
-
-  command.closeSupplicantConnection = function(callback) {
-    voidControlMessage("close_supplicant_connection", callback);
-  };
-
-  command.getMacAddress = function(callback) {
-    doStringCommand("DRIVER MACADDR", function(reply) {
-      if (reply) {
-        reply = reply.split(" ")[2]; // Format: Macaddr = XX.XX.XX.XX.XX.XX
-      }
-      callback(reply);
-    });
-  };
-
-  command.setDeviceName = function(deviceName, callback) {
-    doBooleanCommand("SET device_name " + deviceName, "OK", callback);
-  };
-
-  //-------------------------------------------------
-  // P2P commands.
-  //-------------------------------------------------
-
-  command.p2pProvDiscovery = function(address, wpsMethod, callback) {
-    var command = "P2P_PROV_DISC " + address + " " + wpsMethod;
-    doBooleanCommand(command, "OK", callback);
-  };
-
-  command.p2pConnect = function(config, callback) {
-    var command = "P2P_CONNECT " + config.address + " " + config.wpsMethodWithPin + " ";
-    if (config.joinExistingGroup) {
-      command += "join";
-    } else {
-      command += "go_intent=" + config.goIntent;
-    }
-
-    debug('P2P connect command: ' + command);
-    doBooleanCommand(command, "OK", callback);
-  };
-
-  command.p2pGroupRemove = function(iface, callback) {
-    debug("groupRemove()");
-    doBooleanCommand("P2P_GROUP_REMOVE " + iface, "OK", callback);
-  };
-
-  command.p2pEnable = function(detail, callback) {
-    var commandChain = ["SET device_name "    + detail.deviceName,
-                        "SET device_type "    + detail.deviceType,
-                        "SET config_methods " + detail.wpsMethods,
-                        "P2P_SET conc_pref sta",
-                        "P2P_FLUSH"];
-
-    doBooleanCommandChain(commandChain, callback);
-  };
-
-  command.p2pDisable = function(callback) {
-    doBooleanCommand("P2P_SET disabled 1", "OK", callback);
-  };
-
-  command.p2pEnableScan = function(timeout, callback) {
-    doBooleanCommand("P2P_FIND " + timeout, "OK", callback);
-  };
-
-  command.p2pDisableScan = function(callback) {
-    doBooleanCommand("P2P_STOP_FIND", "OK", callback);
-  };
-
-  command.p2pGetGroupCapab = function(address, callback) {
-    command.p2pPeer(address, function(reply) {
-      debug('p2p_peer reply: ' + reply);
-      if (!reply) {
-        callback(0);
-        return;
-      }
-      var capab = /group_capab=0x([0-9a-fA-F]+)/.exec(reply)[1];
-      if (!capab) {
-        callback(0);
-      } else {
-        callback(parseInt(capab, 16));
-      }
-    });
-  };
-
-  command.p2pPeer = function(address, callback) {
-    doStringCommand("P2P_PEER " + address, callback);
-  };
-
-  command.p2pGroupAdd = function(netId, callback) {
-    doBooleanCommand("P2P_GROUP_ADD persistent=" + netId, callback);
-  };
-
-  command.p2pReinvoke = function(netId, address, callback) {
-    doBooleanCommand("P2P_INVITE persistent=" + netId + " peer=" + address, "OK", callback);
-  };
-
-  //----------------------------------------------------------
-  // Private stuff.
-  //----------------------------------------------------------
-
-  function voidControlMessage(cmd, callback) {
-    aControlMessage({ cmd: cmd, iface: aInterface }, function (data) {
-      callback(data.status);
-    });
-  }
-
-  function doCommand(request, callback) {
-    var msg = { cmd:     "command",
-                request: request,
-                iface:   aInterface };
-
-    aControlMessage(msg, callback);
-  }
-
-  function doIntCommand(request, callback) {
-    doCommand(request, function(data) {
-      callback(data.status ? -1 : (data.reply|0));
-    });
-  }
-
-  function doBooleanCommand(request, expected, callback) {
-    doCommand(request, function(data) {
-      callback(data.status ? false : (data.reply === expected));
-    });
-  }
-
-  function doStringCommand(request, callback) {
-    doCommand(request, function(data) {
-      callback(data.status ? null : data.reply);
-    });
-  }
-
-  function doBooleanCommandChain(commandChain, callback, i) {
-    if (undefined === i) {
-      i = 0;
-    }
-
-    doBooleanCommand(commandChain[i], "OK", function(ok) {
-      if (!ok) {
-        return callback(false);
-      }
-      i++;
-      if (i === commandChain.length || !commandChain[i]) {
-        // Reach the end or empty command.
-        return callback(true);
-      }
-      doBooleanCommandChain(commandChain, callback, i);
-    });
-  }
-
-  //--------------------------------------------------
-  // Helper functions.
-  //--------------------------------------------------
-
-  function stopProcess(service, process, callback) {
-    var count = 0;
-    var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    function tick() {
-      let result = libcutils.property_get(service);
-      if (result === null) {
-        callback();
-        return;
-      }
-      if (result === "stopped" || ++count >= 5) {
-        // Either we succeeded or ran out of time.
-        timer = null;
-        callback();
-        return;
-      }
-
-      // Else it's still running, continue waiting.
-      timer.initWithCallback(tick, 1000, Ci.nsITimer.TYPE_ONE_SHOT);
-    }
-
-    setProperty("ctl.stop", process, tick);
-  }
-
-  // Wrapper around libcutils.property_set that returns true if setting the
-  // value was successful.
-  // Note that the callback is not called asynchronously.
-  function setProperty(key, value, callback) {
-    let ok = true;
-    try {
-      libcutils.property_set(key, value);
-    } catch(e) {
-      ok = false;
-    }
-    callback(ok);
-  }
-
-  function isJellybean() {
-    // According to http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
-    // ----------------------------------------------------
-    // | Platform Version   | API Level |   VERSION_CODE  |
-    // ----------------------------------------------------
-    // | Android 4.1, 4.1.1 |    16     |  JELLY_BEAN_MR2 |
-    // | Android 4.2, 4.2.2 |    17     |  JELLY_BEAN_MR1 |
-    // | Android 4.3        |    18     |    JELLY_BEAN   |
-    // ----------------------------------------------------
-    return aSdkVersion === 16 || aSdkVersion === 17 || aSdkVersion === 18;
-  }
-
-  return command;
-};
deleted file mode 100644
--- a/dom/wifi/WifiHotspotUtils.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#include "WifiHotspotUtils.h"
-#include <dlfcn.h>
-#include <errno.h>
-#include <string.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <cutils/properties.h>
-
-#include "prinit.h"
-#include "mozilla/Assertions.h"
-#include "mozilla/Sprintf.h"
-#include "nsDebug.h"
-#include "nsPrintfCString.h"
-
-static void* sWifiHotspotUtilsLib;
-static PRCallOnceType sInitWifiHotspotUtilsLib;
-// Socket pair used to exit from a blocking read.
-static struct wpa_ctrl* ctrl_conn;
-static const char *ctrl_iface_dir = "/data/misc/wifi/hostapd";
-static char *ctrl_ifname = nullptr;
-
-DEFINE_DLFUNC(wpa_ctrl_open, struct wpa_ctrl*, const char*)
-DEFINE_DLFUNC(wpa_ctrl_close, void, struct wpa_ctrl*)
-DEFINE_DLFUNC(wpa_ctrl_attach, int32_t, struct wpa_ctrl*)
-DEFINE_DLFUNC(wpa_ctrl_detach, int32_t, struct wpa_ctrl*)
-DEFINE_DLFUNC(wpa_ctrl_request, int32_t, struct wpa_ctrl*,
-              const char*, size_t cmd_len, char *reply,
-              size_t *reply_len, void (*msg_cb)(char *msg, size_t len))
-
-
-static PRStatus
-InitWifiHotspotUtilsLib()
-{
-  sWifiHotspotUtilsLib = dlopen("/system/lib/libwpa_client.so", RTLD_LAZY);
-  // We might fail to open the hardware lib. That's OK.
-  return PR_SUCCESS;
-}
-
-static void*
-GetWifiHotspotLibHandle()
-{
-  PR_CallOnce(&sInitWifiHotspotUtilsLib, InitWifiHotspotUtilsLib);
-  return sWifiHotspotUtilsLib;
-}
-
-struct wpa_ctrl *
-WifiHotspotUtils::openConnection(const char *ifname)
-{
-  if (!ifname) {
-    return nullptr;
-  }
-
-  USE_DLFUNC(wpa_ctrl_open)
-  ctrl_conn = wpa_ctrl_open(nsPrintfCString("%s/%s", ctrl_iface_dir, ifname).get());
-  return ctrl_conn;
-}
-
-int32_t
-WifiHotspotUtils::sendCommand(struct wpa_ctrl *ctrl, const char *cmd,
-                              char *reply, size_t *reply_len)
-{
-  int32_t ret;
-
-  if (!ctrl_conn) {
-    NS_WARNING(nsPrintfCString("Not connected to hostapd - \"%s\" command dropped.\n", cmd).get());
-    return -1;
-  }
-
-  USE_DLFUNC(wpa_ctrl_request)
-  ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), reply, reply_len, nullptr);
-  if (ret == -2) {
-    NS_WARNING(nsPrintfCString("'%s' command timed out.\n", cmd).get());
-    return -2;
-  } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
-    return -1;
-  }
-
-  // Make the reply printable.
-  reply[*reply_len] = '\0';
-  if (strncmp(cmd, "STA-FIRST", 9) == 0 ||
-      strncmp(cmd, "STA-NEXT", 8) == 0) {
-    char *pos = reply;
-
-    while (*pos && *pos != '\n')
-      pos++;
-    *pos = '\0';
-  }
-
-  return 0;
-}
-
-
-// static
-void*
-WifiHotspotUtils::GetSharedLibrary()
-{
-  void* wpaClientLib = GetWifiHotspotLibHandle();
-  if (!wpaClientLib) {
-    NS_WARNING("No /system/lib/libwpa_client.so");
-  }
-  return wpaClientLib;
-}
-
-int32_t WifiHotspotUtils::do_wifi_connect_to_hostapd()
-{
-  struct dirent *dent;
-
-  DIR *dir = opendir(ctrl_iface_dir);
-  if (dir) {
-    while ((dent = readdir(dir))) {
-      if (strcmp(dent->d_name, ".") == 0 ||
-          strcmp(dent->d_name, "..") == 0) {
-        continue;
-      }
-      ctrl_ifname = strdup(dent->d_name);
-      break;
-    }
-    closedir(dir);
-  }
-
-  ctrl_conn = openConnection(ctrl_ifname);
-  if (!ctrl_conn) {
-    NS_WARNING(nsPrintfCString("Unable to open connection to hostapd on \"%s\": %s",
-               ctrl_ifname, strerror(errno)).get());
-    return -1;
-  }
-
-  USE_DLFUNC(wpa_ctrl_attach)
-  if (wpa_ctrl_attach(ctrl_conn) != 0) {
-    USE_DLFUNC(wpa_ctrl_close)
-    wpa_ctrl_close(ctrl_conn);
-    ctrl_conn = nullptr;
-    return -1;
-  }
-
-  return 0;
-}
-
-int32_t WifiHotspotUtils::do_wifi_close_hostapd_connection()
-{
-  if (!ctrl_conn) {
-    NS_WARNING("Invalid ctrl_conn.");
-    return -1;
-  }
-
-  USE_DLFUNC(wpa_ctrl_detach)
-  if (wpa_ctrl_detach(ctrl_conn) < 0) {
-    NS_WARNING("Failed to detach wpa_ctrl.");
-  }
-
-  USE_DLFUNC(wpa_ctrl_close)
-  wpa_ctrl_close(ctrl_conn);
-  ctrl_conn = nullptr;
-  return 0;
-}
-
-int32_t WifiHotspotUtils::do_wifi_hostapd_command(const char *command,
-                                                  char *reply,
-                                                  size_t *reply_len)
-{
-  return sendCommand(ctrl_conn, command, reply, reply_len);
-}
-
-int32_t WifiHotspotUtils::do_wifi_hostapd_get_stations()
-{
-  char addr[32], cmd[64];
-  int stations = 0;
-  size_t addrLen = sizeof(addr);
-
-  if (sendCommand(ctrl_conn, "STA-FIRST", addr, &addrLen)) {
-    return 0;
-  }
-  stations++;
-
-  SprintfLiteral(cmd, "STA-NEXT %s", addr);
-  while (sendCommand(ctrl_conn, cmd, addr, &addrLen) == 0) {
-    stations++;
-    SprintfLiteral(cmd, "STA-NEXT %s", addr);
-  }
-
-  return stations;
-}
deleted file mode 100644
--- a/dom/wifi/WifiHotspotUtils.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-/**
- * Abstraction on top of the network support from libnetutils that we
- * use to set up network connections.
- */
-
-#ifndef WifiHotspotUtils_h
-#define WifiHotspotUtils_h
-
-// Forward declaration.
-struct wpa_ctrl;
-
-class WifiHotspotUtils
-{
-public:
-  static void* GetSharedLibrary();
-
-  int32_t do_wifi_connect_to_hostapd();
-  int32_t do_wifi_close_hostapd_connection();
-  int32_t do_wifi_hostapd_command(const char *command,
-                                  char *reply,
-                                  size_t *reply_len);
-  int32_t do_wifi_hostapd_get_stations();
-
-private:
-  struct wpa_ctrl * openConnection(const char *ifname);
-  int32_t sendCommand(struct wpa_ctrl *ctrl, const char *cmd,
-                      char *reply, size_t *reply_len);
-};
-
-// Defines a function type with the right arguments and return type.
-#define DEFINE_DLFUNC(name, ret, args...) typedef ret (*FUNC##name)(args);
-
-// Set up a dlsymed function ready to use.
-#define USE_DLFUNC(name)                                                      \
-  FUNC##name name = (FUNC##name) dlsym(GetSharedLibrary(), #name);            \
-  if (!name) {                                                                \
-    MOZ_CRASH("Symbol not found in shared library : " #name);                 \
-  }
-
-#endif // WifiHotspotUtils_h
deleted file mode 100644
--- a/dom/wifi/WifiNetUtil.jsm
+++ /dev/null
@@ -1,154 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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/systemlibs.js");
-
-XPCOMUtils.defineLazyServiceGetter(this, "gNetworkService",
-                                   "@mozilla.org/network/service;1",
-                                   "nsINetworkService");
-
-this.EXPORTED_SYMBOLS = ["WifiNetUtil"];
-
-const DHCP_PROP = "init.svc.dhcpcd";
-const DHCP      = "dhcpcd";
-const DEBUG     = false;
-
-this.WifiNetUtil = function(controlMessage) {
-  function debug(msg) {
-    if (DEBUG) {
-      dump('-------------- NetUtil: ' + msg);
-    }
-  }
-
-  var util = {};
-
-  util.runDhcp = function (ifname, gen, callback) {
-    util.stopDhcp(ifname, function() {
-      gNetworkService.dhcpRequest(ifname, function(success, dhcpInfo) {
-        util.runIpConfig(ifname, dhcpInfo, function(data) {
-          callback(data, gen);
-        });
-      });
-    });
-  };
-
-  util.stopDhcp = function (ifname, callback) {
-    // This function does exactly what dhcp_stop does. Unforunately, if we call
-    // this function twice before the previous callback is returned. We may block
-    // our self waiting for the callback. It slows down the wifi startup procedure.
-    // Therefore, we have to roll our own version here.
-    let dhcpService = DHCP_PROP + "_" + ifname;
-    let suffix = (ifname.substr(0, 3) === "p2p") ? "p2p" : ifname;
-    let processName = DHCP + "_" + suffix;
-
-    // The implementation of |dhcp_do_request| would wait until the
-    // |result_prop_name| (e.g. dhcp.wlan0.result) to be non-null
-    // or 30 second timeout. So we manually change the result property
-    // to 'ko' to avoid timeout.
-    //
-    // http://androidxref.com/4.4.4_r1/xref/system/core/libnetutils/dhcp_utils.c#234
-    setProperty('dhcp.' + suffix + '.result', 'ko', function() {
-      stopProcess(dhcpService, processName, callback);
-    });
-  };
-
-  util.startDhcpServer = function (config, callback) {
-    gNetworkService.setDhcpServer(true, config, function (error) {
-      callback(!error);
-    });
-  };
-
-  util.stopDhcpServer = function (callback) {
-    gNetworkService.setDhcpServer(false, null, function (error) {
-      callback(!error);
-    });
-  };
-
-  util.runIpConfig = function (name, data, callback) {
-    if (!data) {
-      debug("IP config failed to run");
-      callback({ info: data });
-      return;
-    }
-
-    setProperty("net." + name + ".dns1", ipToString(data.dns1),
-                function(ok) {
-      if (!ok) {
-        debug("Unable to set net.<ifname>.dns1");
-        return;
-      }
-      setProperty("net." + name + ".dns2", ipToString(data.dns2),
-                  function(ok) {
-        if (!ok) {
-          debug("Unable to set net.<ifname>.dns2");
-          return;
-        }
-        setProperty("net." + name + ".gw", ipToString(data.gateway),
-                    function(ok) {
-          if (!ok) {
-            debug("Unable to set net.<ifname>.gw");
-            return;
-          }
-          callback({ info: data });
-        });
-      });
-    });
-  };
-
-  //--------------------------------------------------
-  // Helper functions.
-  //--------------------------------------------------
-
-  function stopProcess(service, process, callback) {
-    var count = 0;
-    var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    function tick() {
-      let result = libcutils.property_get(service);
-      if (result === null) {
-        callback();
-        return;
-      }
-      if (result === "stopped" || ++count >= 5) {
-        // Either we succeeded or ran out of time.
-        timer = null;
-        callback();
-        return;
-      }
-
-      // Else it's still running, continue waiting.
-      timer.initWithCallback(tick, 1000, Ci.nsITimer.TYPE_ONE_SHOT);
-    }
-
-    setProperty("ctl.stop", process, tick);
-  }
-
-  // Wrapper around libcutils.property_set that returns true if setting the
-  // value was successful.
-  // Note that the callback is not called asynchronously.
-  function setProperty(key, value, callback) {
-    let ok = true;
-    try {
-      libcutils.property_set(key, value);
-    } catch(e) {
-      ok = false;
-    }
-    callback(ok);
-  }
-
-  function ipToString(n) {
-    return String((n >>  0) & 0xFF) + "." +
-                 ((n >>  8) & 0xFF) + "." +
-                 ((n >> 16) & 0xFF) + "." +
-                 ((n >> 24) & 0xFF);
-  }
-
-  return util;
-};
deleted file mode 100644
--- a/dom/wifi/WifiP2pManager.jsm
+++ /dev/null
@@ -1,1649 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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/StateMachine.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/systemlibs.js");
-
-XPCOMUtils.defineLazyServiceGetter(this, "gSysMsgr",
-                                   "@mozilla.org/system-message-internal;1",
-                                   "nsISystemMessagesInternal");
-
-XPCOMUtils.defineLazyServiceGetter(this, "gNetworkManager",
-                                   "@mozilla.org/network/manager;1",
-                                   "nsINetworkManager");
-
-XPCOMUtils.defineLazyServiceGetter(this, "gNetworkService",
-                                   "@mozilla.org/network/service;1",
-                                   "nsINetworkService");
-
-this.EXPORTED_SYMBOLS = ["WifiP2pManager"];
-
-const EVENT_IGNORED                      = -1;
-const EVENT_UNKNOWN                      = -2;
-
-// Events from supplicant for p2p.
-const EVENT_P2P_DEVICE_FOUND             = 0;
-const EVENT_P2P_DEVICE_LOST              = 1;
-const EVENT_P2P_GROUP_STARTED            = 2;
-const EVENT_P2P_GROUP_REMOVED            = 3;
-const EVENT_P2P_PROV_DISC_PBC_REQ        = 4;
-const EVENT_P2P_PROV_DISC_PBC_RESP       = 5;
-const EVENT_P2P_PROV_DISC_SHOW_PIN       = 6;
-const EVENT_P2P_PROV_DISC_ENTER_PIN      = 7;
-const EVENT_P2P_GO_NEG_REQUEST           = 8;
-const EVENT_P2P_GO_NEG_SUCCESS           = 9;
-const EVENT_P2P_GO_NEG_FAILURE           = 10;
-const EVENT_P2P_GROUP_FORMATION_SUCCESS  = 11;
-const EVENT_P2P_GROUP_FORMATION_FAILURE  = 12;
-const EVENT_P2P_FIND_STOPPED             = 13;
-const EVENT_P2P_INVITATION_RESULT        = 14;
-const EVENT_P2P_INVITATION_RECEIVED      = 15;
-const EVENT_P2P_PROV_DISC_FAILURE        = 16;
-
-// Events from supplicant but not p2p specific.
-const EVENT_AP_STA_DISCONNECTED          = 100;
-const EVENT_AP_STA_CONNECTED             = 101;
-
-// Events from DOM.
-const EVENT_P2P_SET_PAIRING_CONFIRMATION = 1000;
-const EVENT_P2P_CMD_CONNECT              = 1001;
-const EVENT_P2P_CMD_DISCONNECT           = 1002;
-const EVENT_P2P_CMD_ENABLE               = 1003;
-const EVENT_P2P_CMD_DISABLE              = 1004;
-const EVENT_P2P_CMD_ENABLE_SCAN          = 1005;
-const EVENT_P2P_CMD_DISABLE_SCAN         = 1006;
-const EVENT_P2P_CMD_BLOCK_SCAN           = 1007;
-const EVENT_P2P_CMD_UNBLOCK_SCAN         = 1008;
-
-// Internal events.
-const EVENT_TIMEOUT_PAIRING_CONFIRMATION = 10000;
-const EVENT_TIMEOUT_NEG_REQ              = 10001;
-const EVENT_TIMEOUT_CONNECTING           = 10002;
-const EVENT_P2P_ENABLE_SUCCESS           = 10003;
-const EVENT_P2P_ENABLE_FAILED            = 10004;
-const EVENT_P2P_DISABLE_SUCCESS          = 10005;
-
-// WPS method string.
-const WPS_METHOD_PBC     = "pbc";
-const WPS_METHOD_DISPLAY = "display";
-const WPS_METHOD_KEYPAD  = "keypad";
-
-// Role string.
-const P2P_ROLE_GO     = "GO";
-const P2P_ROLE_CLIENT = "client";
-
-// System message for pairing request.
-const PAIRING_REQUEST_SYS_MSG = "wifip2p-pairing-request";
-
-// Configuration.
-const P2P_INTERFACE_NAME = "p2p0";
-const DEFAULT_GO_INTENT = 15;
-const DEFAULT_P2P_DEVICE_NAME = "FirefoxPhone";
-const P2P_SCAN_TIMEOUT_SEC = 120;
-const DEFAULT_P2P_WPS_METHODS = "virtual_push_button physical_display keypad"; // For wpa_supplicant.
-const DEFAULT_P2P_DEVICE_TYPE = "10-0050F204-5"; // For wpa_supplicant.
-
-const GO_NETWORK_INTERFACE = {
-  ip:         "192.168.2.1",
-  maskLength: 24,
-  gateway:    "192.168.2.1",
-  dns1:       "0.0.0.0",
-  dns2:       "0.0.0.0",
-  dhcpServer: "192.168.2.1"
-};
-
-const GO_DHCP_SERVER_IP_RANGE = {
-  startIp: "192.168.2.10",
-  endIp:   "192.168.2.30"
-};
-
-var gDebug = false;
-
-// Device Capability bitmap
-const DEVICE_CAPAB_SERVICE_DISCOVERY         = 1;
-const DEVICE_CAPAB_CLIENT_DISCOVERABILITY    = 1<<1;
-const DEVICE_CAPAB_CONCURRENT_OPER           = 1<<2;
-const DEVICE_CAPAB_INFRA_MANAGED             = 1<<3;
-const DEVICE_CAPAB_DEVICE_LIMIT              = 1<<4;
-const DEVICE_CAPAB_INVITATION_PROCEDURE      = 1<<5;
-
-// Group Capability bitmap
-const GROUP_CAPAB_GROUP_OWNER                = 1;
-const GROUP_CAPAB_PERSISTENT_GROUP           = 1<<1;
-const GROUP_CAPAB_GROUP_LIMIT                = 1<<2;
-const GROUP_CAPAB_INTRA_BSS_DIST             = 1<<3;
-const GROUP_CAPAB_CROSS_CONN                 = 1<<4;
-const GROUP_CAPAB_PERSISTENT_RECONN          = 1<<5;
-const GROUP_CAPAB_GROUP_FORMATION            = 1<<6;
-
-// Constants defined in wpa_supplicants.
-const DEV_PW_REGISTRAR_SPECIFIED = 5;
-const DEV_PW_USER_SPECIFIED      = 1;
-const DEV_PW_PUSHBUTTON          = 4;
-
-this.WifiP2pManager = function (aP2pCommand, aNetUtil) {
-  function debug(aMsg) {
-    if (gDebug) {
-      dump('-------------- WifiP2pManager: ' + aMsg);
-    }
-  }
-
-  let manager = {};
-
-  let _stateMachine = P2pStateMachine(aP2pCommand, aNetUtil);
-
-  // Set debug flag to true or false.
-  //
-  // @param aDebug Boolean to indicate enabling or disabling the debug flag.
-  manager.setDebug = function(aDebug) {
-    gDebug = aDebug;
-  };
-
-  // Set observer of observing internal state machine events.
-  //
-  // @param aObserver Used to notify WifiWorker what's happening
-  //        in the internal p2p state machine.
-  manager.setObserver = function(aObserver) {
-    _stateMachine.setObserver(aObserver);
-  };
-
-  // Handle wpa_supplicant events.
-  //
-  // @param aEventString string from wpa_supplicant.
-  manager.handleEvent = function(aEventString) {
-    let event = parseEventString(aEventString);
-    if (EVENT_UNKNOWN === event.id || EVENT_IGNORED === event.id) {
-      debug('Unknow or ignored event: ' + aEventString);
-      return false;
-    }
-    return _stateMachine.sendEvent(event);
-  };
-
-  // Set the confirmation of pairing request.
-  //
-  // @param aResult Object of confirmation result which contains:
-  //    .accepted: user granted.
-  //    .pin: pin code which is displaying or input by user.
-  //    .wpsMethod: string of "pbc" or "display" or "keypad".
-  manager.setPairingConfirmation = function(aResult) {
-    let event = {
-      id: EVENT_P2P_SET_PAIRING_CONFIRMATION,
-      info: {
-        accepted: aResult.accepted,
-        pin: aResult.pin
-      }
-    };
-    _stateMachine.sendEvent(event);
-  };
-
-  // Connect to a known peer.
-  //
-  // @param aAddress MAC address of the peer to connect.
-  // @param aWpsMethod String of "pbc" or "display" or "keypad".
-  // @param aGoIntent Number from 0 to 15.
-  // @param aCallback Callback |true| on attempting to connect.
-  //                          |false| on failed to connect.
-  manager.connect = function(aAddress, aWpsMethod, aGoIntent, aCallback) {
-    let event = {
-      id: EVENT_P2P_CMD_CONNECT,
-      info: {
-        wpsMethod: aWpsMethod,
-        address: aAddress,
-        goIntent: aGoIntent,
-        onDoConnect: aCallback
-      }
-    };
-    _stateMachine.sendEvent(event);
-  };
-
-  // Disconnect with a known peer.
-  //
-  // @param aAddress The address the user desires to disconect.
-  // @param aCallback Callback |true| on "attempting" to disconnect.
-  //                           |false| on failed to disconnect.
-  manager.disconnect = function(aAddress, aCallback) {
-    let event = {
-      id: EVENT_P2P_CMD_DISCONNECT,
-      info: {
-        address: aAddress,
-        onDoDisconnect: aCallback
-      }
-    };
-    _stateMachine.sendEvent(event);
-  };
-
-  // Enable/disable wifi p2p.
-  //
-  // @param aEnabled |true| to enable, |false| to disable.
-  // @param aCallbacks object for callbacks:
-  //   .onEnabled
-  //   .onDisabled
-  //   .onSupplicantConnected
-  manager.setEnabled = function(aEnabled, aCallbacks) {
-    let event = {
-      id: (aEnabled ? EVENT_P2P_CMD_ENABLE : EVENT_P2P_CMD_DISABLE),
-      info: {
-        onEnabled: aCallbacks.onEnabled,
-        onDisabled: aCallbacks.onDisabled,
-        onSupplicantConnected: aCallbacks.onSupplicantConnected
-      }
-    };
-    _stateMachine.sendEvent(event);
-  };
-
-  // Enable/disable the wifi p2p scan.
-  //
-  // @param aEnabled |true| to enable scan, |false| to disable scan.
-  // @param aCallback Callback |true| on success to enable/disable scan.
-  //                           |false| on failed to enable/disable scan.
-  manager.setScanEnabled = function(aEnabled, aCallback) {
-    let event = {
-      id: (aEnabled ? EVENT_P2P_CMD_ENABLE_SCAN : EVENT_P2P_CMD_DISABLE_SCAN),
-      info: { callback: aCallback }
-    };
-    _stateMachine.sendEvent(event);
-  };
-
-  // Block wifi p2p scan.
-  manager.blockScan = function() {
-    _stateMachine.sendEvent({ id: EVENT_P2P_CMD_BLOCK_SCAN });
-  };
-
-  // Un-block and do the pending scan if any.
-  manager.unblockScan = function() {
-    _stateMachine.sendEvent({ id: EVENT_P2P_CMD_UNBLOCK_SCAN });
-  };
-
-  // Set the p2p device name.
-  manager.setDeviceName = function(newDeivceName, callback) {
-    aP2pCommand.setDeviceName(newDeivceName, callback);
-  };
-
-  // Parse wps_supplicant event string.
-  //
-  // @param aEventString The raw event string from wpa_supplicant.
-  //
-  // @return Object:
-  //   .id: a number to represent an event.
-  //   .info: the additional information carried by this event string.
-  function parseEventString(aEventString) {
-    if (isIgnoredEvent(aEventString)) {
-      return { id: EVENT_IGNORED };
-    }
-
-    let match = RegExp("p2p_dev_addr=([0-9a-fA-F:]+) " +
-                       "pri_dev_type=([0-9a-zA-Z-]+) " +
-                       "name='(.*)' " +
-                       "config_methods=0x([0-9a-fA-F]+) " +
-                       "dev_capab=0x([0-9a-fA-F]+) " +
-                       "group_capab=0x([0-9a-fA-F]+) ").exec(aEventString + ' ');
-
-    let tokens = aEventString.split(" ");
-
-    let id = EVENT_UNKNOWN;
-
-    // general info.
-    let info = {};
-
-    if (match) {
-      info = {
-        address:   match[1] ? match[1] : null,
-        type:      match[2] ? match[2] : null,
-        name:      match[3] ? match[3] : null,
-        wpsFlag:   match[4] ? parseInt(match[4], 16) : null,
-        devFlag:   match[5] ? parseInt(match[5], 16) : null,
-        groupFlag: match[6] ? parseInt(match[6], 16) : null
-      };
-    }
-
-    if (0 === aEventString.indexOf("P2P-DEVICE-FOUND")) {
-      id = EVENT_P2P_DEVICE_FOUND;
-      info.wpsCapabilities = wpsFlagToCapabilities(info.wpsFlag);
-      info.isGroupOwner = isPeerGroupOwner(info.groupFlag);
-    } else if (0 === aEventString.indexOf("P2P-DEVICE-LOST")) {
-      // e.g. "P2P-DEVICE-LOST p2p_dev_addr=5e:0a:5b:15:1f:80".
-      id = EVENT_P2P_DEVICE_LOST;
-      info.address = /p2p_dev_addr=([0-9a-f:]+)/.exec(aEventString)[1];
-    } else if (0 === aEventString.indexOf("P2P-GROUP-STARTED")) {
-      // e.g. "P2P-GROUP-STARTED wlan0-p2p-0 GO ssid="DIRECT-3F Testing
-      //       passphrase="12345678" go_dev_addr=02:40:61:c2:f3:b7 [PERSISTENT]".
-
-      id = EVENT_P2P_GROUP_STARTED;
-      let groupMatch = RegExp('ssid="(.*)" ' +
-                              'freq=([0-9]*) ' +
-                              '(passphrase|psk)=([^ ]+) ' +
-                              'go_dev_addr=([0-9a-f:]+)').exec(aEventString);
-      info.ssid = groupMatch[1];
-      info.freq = groupMatch[2];
-      if ('passphrase' === groupMatch[3]) {
-        let s = groupMatch[4]; // e.g. "G7jHkkz9".
-        info.passphrase = s.substring(1, s.length-1); // Trim the double quote.
-      } else { // psk
-        info.psk = groupMatch[4];
-      }
-      info.goAddress = groupMatch[5];
-      info.ifname = tokens[1];
-      info.role = tokens[2];
-    } else if (0 === aEventString.indexOf("P2P-GROUP-REMOVED")) {
-      id = EVENT_P2P_GROUP_REMOVED;
-      // e.g. "P2P-GROUP-REMOVED wlan0-p2p-0 GO".
-      info.ifname = tokens[1];
-      info.role = tokens[2];
-    } else if (0 === aEventString.indexOf("P2P-PROV-DISC-PBC-REQ")) {
-      id = EVENT_P2P_PROV_DISC_PBC_REQ;
-      info.wpsMethod = WPS_METHOD_PBC;
-    } else if (0 === aEventString.indexOf("P2P-PROV-DISC-PBC-RESP")) {
-      id = EVENT_P2P_PROV_DISC_PBC_RESP;
-      // The address is different from the general pattern.
-      info.address = aEventString.split(" ")[1];
-      info.wpsMethod = WPS_METHOD_PBC;
-    } else if (0 === aEventString.indexOf("P2P-PROV-DISC-SHOW-PIN")) {
-      id = EVENT_P2P_PROV_DISC_SHOW_PIN;
-      // Obtain peer address and pin from tokens.
-      info.address = tokens[1];
-      info.pin     = tokens[2];
-      info.wpsMethod = WPS_METHOD_DISPLAY;
-    } else if (0 === aEventString.indexOf("P2P-PROV-DISC-ENTER-PIN")) {
-      id = EVENT_P2P_PROV_DISC_ENTER_PIN;
-      // Obtain peer address from tokens.
-      info.address = tokens[1];
-      info.wpsMethod = WPS_METHOD_KEYPAD;
-    } else if (0 === aEventString.indexOf("P2P-GO-NEG-REQUEST")) {
-      id = EVENT_P2P_GO_NEG_REQUEST;
-      info.address = tokens[1];
-      switch (parseInt(tokens[2].split("=")[1], 10)) {
-        case DEV_PW_REGISTRAR_SPECIFIED: // (5) Peer is display.
-          info.wpsMethod = WPS_METHOD_KEYPAD;
-          break;
-        case DEV_PW_USER_SPECIFIED: // (1) Peer is keypad.
-          info.wpsMethod = WPS_METHOD_DISPLAY;
-          break;
-        case DEV_PW_PUSHBUTTON: // (4) Peer is pbc.
-          info.wpsMethod = WPS_METHOD_PBC;
-          break;
-        default:
-          debug('Unknown wps method from event P2P-GO-NEG-REQUEST');
-          break;
-      }
-    } else if (0 === aEventString.indexOf("P2P-GO-NEG-SUCCESS")) {
-      id = EVENT_P2P_GO_NEG_SUCCESS;
-    } else if (0 === aEventString.indexOf("P2P-GO-NEG-FAILURE")) {
-      id = EVENT_P2P_GO_NEG_FAILURE;
-    } else if (0 === aEventString.indexOf("P2P-GROUP-FORMATION-FAILURE")) {
-      id = EVENT_P2P_GROUP_FORMATION_FAILURE;
-    } else if (0 === aEventString.indexOf("P2P-GROUP-FORMATION-SUCCESS")) {
-      id = EVENT_P2P_GROUP_FORMATION_SUCCESS;
-    } else if (0 === aEventString.indexOf("P2P-FIND-STOPPED")) {
-      id = EVENT_P2P_FIND_STOPPED;
-    } else if (0 === aEventString.indexOf("P2P-INVITATION-RESULT")) {
-      id = EVENT_P2P_INVITATION_RESULT;
-      info.status = /status=([0-9]+)/.exec(aEventString)[1];
-    } else if (0 === aEventString.indexOf("P2P-INVITATION-RECEIVED")) {
-      // e.g. "P2P-INVITATION-RECEIVED sa=32:85:a9:da:e6:1f persistent=7".
-      id = EVENT_P2P_INVITATION_RECEIVED;
-      info.address = /sa=([0-9a-f:]+)/.exec(aEventString)[1];
-      info.netId = /persistent=([0-9]+)/.exec(aEventString)[1];
-    } else if (0 === aEventString.indexOf("P2P-PROV-DISC-FAILURE")) {
-      id = EVENT_P2P_PROV_DISC_FAILURE;
-    } else {
-      // Not P2P event but we do receive it. Try to recognize it.
-      if (0 === aEventString.indexOf("AP-STA-DISCONNECTED")) {
-        id = EVENT_AP_STA_DISCONNECTED;
-        info.address = tokens[1];
-      } else if (0 === aEventString.indexOf("AP-STA-CONNECTED")) {
-        id = EVENT_AP_STA_CONNECTED;
-        info.address = tokens[1];
-      } else {
-        // Neither P2P event nor recognized supplicant event.
-        debug('Unknwon event string: ' + aEventString);
-      }
-    }
-
-    let event = {id: id, info: info};
-    debug('Event parsing result: ' + aEventString + ": " + JSON.stringify(event));
-
-    return event;
-  }
-
-  function isIgnoredEvent(aEventString) {
-    const IGNORED_EVENTS = [
-      "CTRL-EVENT-BSS-ADDED",
-      "CTRL-EVENT-BSS-REMOVED",
-      "CTRL-EVENT-SCAN-RESULTS",
-      "CTRL-EVENT-STATE-CHANGE",
-      "WPS-AP-AVAILABLE",
-      "WPS-ENROLLEE-SEEN"
-    ];
-    for(let i = 0; i < IGNORED_EVENTS.length; i++) {
-      if (0 === aEventString.indexOf(IGNORED_EVENTS[i])) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-  function isPeerGroupOwner(aGroupFlag) {
-    return (aGroupFlag & GROUP_CAPAB_GROUP_OWNER) !== 0;
-  }
-
-  // Convert flag to a wps capability array.
-  //
-  // @param aWpsFlag Number that represents the wps capabilities.
-  // @return Array of WPS flag.
-  function wpsFlagToCapabilities(aWpsFlag) {
-    let wpsCapabilities = [];
-    if (aWpsFlag & 0x8) {
-      wpsCapabilities.push(WPS_METHOD_DISPLAY);
-    }
-    if (aWpsFlag & 0x80) {
-      wpsCapabilities.push(WPS_METHOD_PBC);
-    }
-    if (aWpsFlag & 0x100) {
-      wpsCapabilities.push(WPS_METHOD_KEYPAD);
-    }
-    return wpsCapabilities;
-  }
-
-  _stateMachine.start();
-  return manager;
-};
-
-function P2pStateMachine(aP2pCommand, aNetUtil) {
-  function debug(aMsg) {
-    if (gDebug) {
-      dump('-------------- WifiP2pStateMachine: ' + aMsg);
-    }
-  }
-
-  let p2pSm = {};  // The state machine to return.
-
-  let _sm = StateMachine('WIFIP2P'); // The general purpose state machine.
-
-  // Information we need to keep track across states.
-  let _observer;
-
-  let _onEnabled;
-  let _onDisabled;
-  let _onSupplicantConnected;
-  let _savedConfig = {}; // Configuration used to do P2P_CONNECT.
-  let _groupInfo = {};   // The information of the group we have formed.
-  let _removedGroupInfo = {}; // Used to store the group info we are going to remove.
-
-  let _scanBlocked = false;
-  let _scanPostponded = false;
-
-  let _localDevice = {
-    address: "",
-    deviceName: DEFAULT_P2P_DEVICE_NAME + "_" + libcutils.property_get("ro.build.product"),
-    wpsCapabilities: [WPS_METHOD_PBC, WPS_METHOD_KEYPAD, WPS_METHOD_DISPLAY]
-  };
-
-  let _p2pNetworkInterface = {
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]),
-
-    info: {
-      QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInfo]),
-
-      state: Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTED,
-      type: Ci.nsINetworkInfo.NETWORK_TYPE_WIFI_P2P,
-      name: P2P_INTERFACE_NAME,
-      ips: [],
-      prefixLengths: [],
-      dnses: [],
-      gateways: [],
-
-      getAddresses: function (ips, prefixLengths) {
-        ips.value = this.ips.slice();
-        prefixLengths.value = this.prefixLengths.slice();
-
-        return this.ips.length;
-      },
-
-      getGateways: function (count) {
-        if (count) {
-          count.value = this.gateways.length;
-        }
-        return this.gateways.slice();
-      },
-
-      getDnses: function (count) {
-        if (count) {
-          count.value = this.dnses.length;
-        }
-        return this.dnses.slice();
-      }
-    },
-
-    httpProxyHost: null,
-    httpProxyPort: null,
-
-    // help
-    registered: false
-  };
-
-  //---------------------------------------------------------
-  // State machine APIs.
-  //---------------------------------------------------------
-
-  // Register the observer which is implemented in WifiP2pWorkerObserver.jsm.
-  //
-  // @param aObserver:
-  //   .onEnabled
-  //   .onDisbaled
-  //   .onPeerFound
-  //   .onPeerLost
-  //   .onConnecting
-  //   .onConnected
-  //   .onDisconnected
-  //   .onLocalDeviceChanged
-  p2pSm.setObserver = function(aObserver) {
-    _observer = aObserver;
-  };
-
-  p2pSm.start = function() {
-    _sm.start(stateDisabled);
-  };
-
-  p2pSm.sendEvent = function(aEvent) {
-    let willBeHandled = isInP2pManagedState(_sm.getCurrentState());
-    _sm.sendEvent(aEvent);
-    return willBeHandled;
-  };
-
-  // Initialize internal state machine _sm.
-  _sm.setDefaultEventHandler(handleEventCommon);
-
-  //----------------------------------------------------------
-  // State definition.
-  //----------------------------------------------------------
-
-  // The initial state.
-  var stateDisabled = _sm.makeState("DISABLED", {
-    enter: function() {
-      _onEnabled = null;
-      _onSupplicantConnected = null;
-      _savedConfig = null;
-      _groupInfo = null;
-      _removedGroupInfo = null;
-      _scanBlocked = false;
-      _scanPostponded = false;
-
-      unregisterP2pNetworkInteface();
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_CMD_ENABLE:
-          _onEnabled = aEvent.info.onEnabled;
-          _onSupplicantConnected = aEvent.info.onSupplicantConnected;
-          _sm.gotoState(stateEnabling);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-      return true;
-    }
-  });
-
-  // The state where we are trying to enable wifi p2p.
-  var stateEnabling = _sm.makeState("ENABLING", {
-    enter: function() {
-
-      function onFailure()
-      {
-        _onEnabled(false);
-        _observer.onDisabled();
-        _sm.gotoState(stateDisabled);
-      }
-
-      function onSuccess()
-      {
-        _onEnabled(true);
-        _observer.onEnabled();
-        _sm.gotoState(stateInactive);
-      }
-
-      _sm.pause();
-
-      // This function will only call back on success.
-      function connectToSupplicantIfNeeded(callback) {
-        if (aP2pCommand.getSdkVersion() >= 19) {
-          // No need to connect to supplicant on KK. Call back directly.
-          callback();
-          return;
-        }
-        aP2pCommand.connectToSupplicant(function (status) {
-          if (0 !== status) {
-            debug('Failed to connect to p2p0');
-            onFailure();
-            return;
-          }
-          debug('wpa_supplicant p2p0 connected!');
-          _onSupplicantConnected();
-          callback();
-        });
-      }
-
-      // Step 1: Connect to p2p0 if needed.
-      connectToSupplicantIfNeeded(function callback () {
-        let detail;
-
-        // Step 2: Get MAC address.
-        if (!_localDevice.address) {
-          aP2pCommand.getMacAddress(function (address) {
-            if (!address) {
-              debug('Failed to get MAC address....');
-              onFailure();
-              return;
-            }
-            debug('Got mac address: ' + address);
-            _localDevice.address = address;
-            _observer.onLocalDeviceChanged(_localDevice);
-          });
-        }
-
-        // Step 3: Enable p2p with the device name and wps methods.
-        detail = { deviceName: _localDevice.deviceName,
-                   deviceType: libcutils.property_get("ro.moz.wifi.p2p_device_type") || DEFAULT_P2P_DEVICE_TYPE,
-                   wpsMethods: libcutils.property_get("ro.moz.wifi.p2p_wps_methods") || DEFAULT_P2P_WPS_METHODS };
-
-        aP2pCommand.p2pEnable(detail, function (success) {
-          if (!success) {
-            debug('Failed to enable p2p');
-            onFailure();
-            return;
-          }
-
-          debug('P2P is enabled! Enabling net interface...');
-
-          // Step 4: Enable p2p0 net interface. wpa_supplicant may have
-          //         already done it for us.
-          gNetworkService.enableInterface(P2P_INTERFACE_NAME, function (success) {
-            onSuccess();
-          });
-        });
-      });
-    },
-
-    handleEvent: function(aEvent) {
-      // We won't receive any event since all of them will be blocked.
-      return true;
-    }
-  });
-
-  // The state just after enabling wifi direct.
-  var stateInactive = _sm.makeState("INACTIVE", {
-    enter: function() {
-      registerP2pNetworkInteface();
-
-      if (_sm.getPreviousState() !== stateEnabling) {
-        _observer.onDisconnected(_savedConfig);
-      }
-
-      _savedConfig = null; // Used to connect p2p peer.
-      _groupInfo   = null; // The information of the formed group.
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        // Receiving the following 3 states implies someone is trying to
-        // connect to me.
-        case EVENT_P2P_PROV_DISC_PBC_REQ:
-        case EVENT_P2P_PROV_DISC_SHOW_PIN:
-        case EVENT_P2P_PROV_DISC_ENTER_PIN:
-          debug('Someone is trying to connect to me: ' + JSON.stringify(aEvent.info));
-
-          _savedConfig = {
-            name:      aEvent.info.name,
-            address:   aEvent.info.address,
-            wpsMethod: aEvent.info.wpsMethod,
-            goIntent:  DEFAULT_GO_INTENT,
-            pin:       aEvent.info.pin // EVENT_P2P_PROV_DISC_SHOW_PIN only.
-          };
-
-          _sm.gotoState(stateWaitingForConfirmation);
-          break;
-
-        // Connect to a peer.
-        case EVENT_P2P_CMD_CONNECT:
-          debug('Trying to connect to peer: ' + JSON.stringify(aEvent.info));
-
-          _savedConfig = {
-            address:   aEvent.info.address,
-            wpsMethod: aEvent.info.wpsMethod,
-            goIntent:  aEvent.info.goIntent
-          };
-
-          _sm.gotoState(stateProvisionDiscovery);
-          aEvent.info.onDoConnect(true);
-          break;
-
-        case EVENT_P2P_INVITATION_RECEIVED:
-          _savedConfig = {
-            address: aEvent.info.address,
-            wpsMethod: WPS_METHOD_PBC,
-            goIntent: DEFAULT_GO_INTENT,
-            netId: aEvent.info.netId
-          };
-          _sm.gotoState(stateWaitingForInvitationConfirmation);
-          break;
-
-        case EVENT_P2P_GROUP_STARTED:
-          // Most likely the peer just reinvoked a peristen group and succeeeded.
-
-          _savedConfig = { address: aEvent.info.goAddress };
-
-          _sm.pause();
-          handleGroupStarted(aEvent.info, function (success) {
-            _sm.resume();
-          });
-          break;
-
-        case EVENT_AP_STA_DISCONNECTED:
-          // We will hit this case when we used to be a group owner and
-          // requested to remove the group we owned.
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-      return true;
-    },
-  });
-
-  // Waiting for user's confirmation.
-  var stateWaitingForConfirmation = _sm.makeState("WAITING_FOR_CONFIRMATION", {
-    timeoutTimer: null,
-
-    enter: function() {
-      gSysMsgr.broadcastMessage(PAIRING_REQUEST_SYS_MSG, _savedConfig);
-      this.timeoutTimer = initTimeoutTimer(30000, EVENT_TIMEOUT_PAIRING_CONFIRMATION);
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_SET_PAIRING_CONFIRMATION:
-          if (!aEvent.info.accepted) {
-            debug('User rejected this request');
-            _sm.gotoState(stateInactive); // Reset to inactive state.
-            break;
-          }
-
-          debug('User accepted this request');
-
-          // The only information we may have to grab from user.
-          _savedConfig.pin = aEvent.info.pin;
-
-          // The case that user requested to form a group ealier on.
-          // Just go to connecting state and do p2p_connect.
-          if (_sm.getPreviousState() === stateProvisionDiscovery) {
-            _sm.gotoState(stateConnecting);
-            break;
-          }
-
-          // Otherwise, wait for EVENT_P2P_GO_NEG_REQUEST.
-          _sm.gotoState(stateWaitingForNegReq);
-          break;
-
-        case EVENT_TIMEOUT_PAIRING_CONFIRMATION:
-          debug('Confirmation timeout!');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_P2P_GO_NEG_REQUEST:
-          _sm.deferEvent(aEvent);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-
-      return true;
-    },
-
-    exit: function() {
-      this.timeoutTimer.cancel();
-      this.timeoutTimer = null;
-    }
-  });
-
-  var stateWaitingForNegReq = _sm.makeState("WAITING_FOR_NEG_REQ", {
-    timeoutTimer: null,
-
-    enter: function() {
-      debug('Wait for EVENT_P2P_GO_NEG_REQUEST');
-      this.timeoutTimer = initTimeoutTimer(30000, EVENT_TIMEOUT_NEG_REQ);
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_GO_NEG_REQUEST:
-          if (aEvent.info.wpsMethod !== _savedConfig.wpsMethod) {
-            debug('Unmatched wps method: ' + aEvent.info.wpsMethod + ", " + _savedConfig.wpsMetho);
-          }
-          _sm.gotoState(stateConnecting);
-          break;
-
-        case EVENT_TIMEOUT_NEG_REQ:
-          debug("Waiting for NEG-REQ timeout");
-          _sm.gotoState(stateInactive);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-      return true;
-    },
-
-    exit: function() {
-      this.timeoutTimer.cancel();
-      this.timeoutTimer = null;
-    }
-  });
-
-  // Waiting for user's confirmation for invitation.
-  var stateWaitingForInvitationConfirmation = _sm.makeState("WAITING_FOR_INV_CONFIRMATION", {
-    timeoutTimer: null,
-
-    enter: function() {
-      gSysMsgr.broadcastMessage(PAIRING_REQUEST_SYS_MSG, _savedConfig);
-      this.timeoutTimer = initTimeoutTimer(30000, EVENT_TIMEOUT_PAIRING_CONFIRMATION);
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_SET_PAIRING_CONFIRMATION:
-          if (!aEvent.info.accepted) {
-            debug('User rejected this request');
-            _sm.gotoState(stateInactive); // Reset to inactive state.
-            break;
-          }
-
-          debug('User accepted this request');
-          _sm.pause();
-          aP2pCommand.p2pGetGroupCapab(_savedConfig.address, function (gc) {
-            let isPeeGroupOwner = gc & GROUP_CAPAB_GROUP_OWNER;
-            _sm.gotoState(isPeeGroupOwner ? stateGroupAdding : stateReinvoking);
-          });
-
-          break;
-
-        case EVENT_TIMEOUT_PAIRING_CONFIRMATION:
-          debug('Confirmation timeout!');
-          _sm.gotoState(stateInactive);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-
-      return true;
-    },
-
-    exit: function() {
-      this.timeoutTimer.cancel();
-      this.timeoutTimer = null;
-    }
-  });
-
-  var stateGroupAdding = _sm.makeState("GROUP_ADDING", {
-    timeoutTimer: null,
-
-    enter: function() {
-      let self = this;
-
-      _observer.onConnecting(_savedConfig);
-
-      _sm.pause();
-      aP2pCommand.p2pGroupAdd(_savedConfig.netId, function (success) {
-        if (!success) {
-          _sm.gotoState(stateInactive);
-          return;
-        }
-        // Waiting for EVENT_P2P_GROUP_STARTED.
-        self.timeoutTimer = initTimeoutTimer(60000, EVENT_TIMEOUT_CONNECTING);
-        _sm.resume();
-      });
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_GROUP_STARTED:
-          _sm.pause();
-          handleGroupStarted(aEvent.info, function (success) {
-            _sm.resume();
-          });
-          break;
-
-        case EVENT_P2P_GO_NEG_FAILURE:
-          debug('Negotiation failure. Go back to inactive state');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_TIMEOUT_CONNECTING:
-          debug('Connecting timeout! Go back to inactive state');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_P2P_GROUP_FORMATION_SUCCESS:
-        case EVENT_P2P_GO_NEG_SUCCESS:
-          break;
-
-        case EVENT_P2P_GROUP_FORMATION_FAILURE:
-          debug('Group formation failure');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_P2P_GROUP_REMOVED:
-          debug('Received P2P-GROUP-REMOVED due to previous failed handleGroupdStarted()');
-          _removedGroupInfo = {
-            role:   aEvent.info.role,
-            ifname: aEvent.info.ifname
-          };
-          _sm.gotoState(stateDisconnecting);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-
-      return true;
-    },
-
-    exit: function() {
-      this.timeoutTimer.cancel();
-      this.timeoutTimer = null;
-    }
-  });
-
-  var stateReinvoking = _sm.makeState("REINVOKING", {
-    timeoutTimer: null,
-
-    enter: function() {
-      let self = this;
-
-      _observer.onConnecting(_savedConfig);
-      _sm.pause();
-      aP2pCommand.p2pReinvoke(_savedConfig.netId, _savedConfig.address, function(success) {
-        if (!success) {
-          _sm.gotoState(stateInactive);
-          return;
-        }
-        // Waiting for EVENT_P2P_GROUP_STARTED.
-        self.timeoutTimer = initTimeoutTimer(60000, EVENT_TIMEOUT_CONNECTING);
-        _sm.resume();
-      });
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_GROUP_STARTED:
-          _sm.pause();
-          handleGroupStarted(aEvent.info, function(success) {
-            _sm.resume();
-          });
-          break;
-
-        case EVENT_P2P_GO_NEG_FAILURE:
-          debug('Negotiation failure. Go back to inactive state');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_TIMEOUT_CONNECTING:
-          debug('Connecting timeout! Go back to inactive state');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_P2P_GROUP_FORMATION_SUCCESS:
-        case EVENT_P2P_GO_NEG_SUCCESS:
-          break;
-
-        case EVENT_P2P_GROUP_FORMATION_FAILURE:
-          debug('Group formation failure');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_P2P_GROUP_REMOVED:
-          debug('Received P2P-GROUP-REMOVED due to previous failed handleGroupdStarted()');
-          _removedGroupInfo = {
-            role:   aEvent.info.role,
-            ifname: aEvent.info.ifname
-          };
-          _sm.gotoState(stateDisconnecting);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-
-      return true;
-    },
-
-    exit: function() {
-      this.timeoutTimer.cancel();
-    }
-  });
-
-  var stateProvisionDiscovery = _sm.makeState("PROVISION_DISCOVERY", {
-    enter: function() {
-      function onDiscoveryCommandSent(success) {
-        if (!success) {
-          _sm.gotoState(stateInactive);
-          debug('Failed to send p2p_prov_disc. Go back to inactive state.');
-          return;
-        }
-
-        debug('p2p_prov_disc has been sent.');
-
-        _sm.resume();
-        // Waiting for EVENT_P2P_PROV_DISC_PBC_RESP or
-        //             EVENT_P2P_PROV_DISC_SHOW_PIN or
-        //             EVENT_P2P_PROV_DISC_ENTER_PIN.
-      }
-
-      _sm.pause();
-      aP2pCommand.p2pProvDiscovery(_savedConfig.address,
-                                   toPeerWpsMethod(_savedConfig.wpsMethod),
-                                   onDiscoveryCommandSent);
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_PROV_DISC_PBC_RESP:
-          _sm.gotoState(stateConnecting); // No need for local user grant.
-          break;
-        case EVENT_P2P_PROV_DISC_SHOW_PIN:
-        case EVENT_P2P_PROV_DISC_ENTER_PIN:
-          if (aEvent.info.wpsMethod !== _savedConfig.wpsMethod) {
-            debug('Unmatched wps method: ' + aEvent.info.wpsMethod + ":" + _savedConfig.wpsMethod);
-          }
-          if (EVENT_P2P_PROV_DISC_SHOW_PIN === aEvent.id) {
-            _savedConfig.pin = aEvent.info.pin;
-          }
-          _sm.gotoState(stateWaitingForConfirmation);
-          break;
-
-        case EVENT_P2P_PROV_DISC_FAILURE:
-          _sm.gotoState(stateInactive);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-      return true;
-    }
-  });
-
-  // We are going to connect to the peer.
-  // |_savedConfig| is supposed to have been filled properly.
-  var stateConnecting = _sm.makeState("CONNECTING", {
-    timeoutTimer: null,
-
-    enter: function() {
-      let self = this;
-
-      if (null === _savedConfig.goIntent) {
-        _savedConfig.goIntent = DEFAULT_GO_INTENT;
-      }
-
-      _observer.onConnecting(_savedConfig);
-
-      let wpsMethodWithPin;
-      if (WPS_METHOD_KEYPAD === _savedConfig.wpsMethod ||
-          WPS_METHOD_DISPLAY === _savedConfig.wpsMethod) {
-        // e.g. '12345678 display or '12345678 keypad'.
-        wpsMethodWithPin = (_savedConfig.pin + ' ' + _savedConfig.wpsMethod);
-      } else {
-        // e.g. 'pbc'.
-        wpsMethodWithPin = _savedConfig.wpsMethod;
-      }
-
-      _sm.pause();
-
-      aP2pCommand.p2pGetGroupCapab(_savedConfig.address, function(gc) {
-        debug('group capabilities of ' + _savedConfig.address + ': ' + gc);
-
-        let isPeerGroupOwner = gc & GROUP_CAPAB_GROUP_OWNER;
-        let config = { address:           _savedConfig.address,
-                       wpsMethodWithPin:  wpsMethodWithPin,
-                       goIntent:          _savedConfig.goIntent,
-                       joinExistingGroup: isPeerGroupOwner };
-
-        aP2pCommand.p2pConnect(config, function (success) {
-          if (!success) {
-            debug('Failed to send p2p_connect');
-            _sm.gotoState(stateInactive);
-            return;
-          }
-          debug('Waiting for EVENT_P2P_GROUP_STARTED.');
-          self.timeoutTimer = initTimeoutTimer(60000, EVENT_TIMEOUT_CONNECTING);
-          _sm.resume();
-        });
-      });
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_GROUP_STARTED:
-          _sm.pause();
-          handleGroupStarted(aEvent.info, function (success) {
-            _sm.resume();
-          });
-          break;
-
-        case EVENT_P2P_GO_NEG_FAILURE:
-          debug('Negotiation failure. Go back to inactive state');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_TIMEOUT_CONNECTING:
-          debug('Connecting timeout! Go back to inactive state');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_P2P_GROUP_FORMATION_SUCCESS:
-        case EVENT_P2P_GO_NEG_SUCCESS:
-          break;
-
-        case EVENT_P2P_GROUP_FORMATION_FAILURE:
-          debug('Group formation failure');
-          _sm.gotoState(stateInactive);
-          break;
-
-        case EVENT_P2P_GROUP_REMOVED:
-          debug('Received P2P-GROUP-REMOVED due to previous failed ' +
-                'handleGroupdStarted()');
-          _removedGroupInfo = {
-            role:   aEvent.info.role,
-            ifname: aEvent.info.ifname
-          };
-          _sm.gotoState(stateDisconnecting);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-
-      return true;
-    },
-
-    exit: function() {
-      this.timeoutTimer.cancel();
-    }
-  });
-
-  var stateConnected = _sm.makeState("CONNECTED", {
-    groupOwner: null,
-
-    enter: function() {
-      this.groupOwner = {
-        macAddress: _groupInfo.goAddress,
-        ipAddress:  _groupInfo.networkInterface.info.gateways[0],
-        passphrase: _groupInfo.passphrase,
-        ssid:       _groupInfo.ssid,
-        freq:       _groupInfo.freq,
-        isLocal:    _groupInfo.isGroupOwner
-      };
-
-      if (!_groupInfo.isGroupOwner) {
-        _observer.onConnected(this.groupOwner, _savedConfig);
-      } else {
-        // If I am a group owner, notify onConnected until EVENT_AP_STA_CONNECTED
-        // is received.
-      }
-
-      _removedGroupInfo = null;
-    },
-
-    handleEvent: function(aEvent) {
-      switch (aEvent.id) {
-        case EVENT_AP_STA_CONNECTED:
-          if (_groupInfo.isGroupOwner) {
-            _observer.onConnected(this.groupOwner, _savedConfig);
-          }
-          break;
-
-        case EVENT_P2P_GROUP_REMOVED:
-          _removedGroupInfo = {
-            role:   aEvent.info.role,
-            ifname: aEvent.info.ifname
-          };
-          _sm.gotoState(stateDisconnecting);
-          break;
-
-        case EVENT_AP_STA_DISCONNECTED:
-          debug('Client disconnected: ' + aEvent.info.address);
-
-          // Now we suppose it's the only client. Remove my group.
-          _sm.pause();
-          aP2pCommand.p2pGroupRemove(_groupInfo.ifname, function (success) {
-            debug('Requested to remove p2p group. Wait for EVENT_P2P_GROUP_REMOVED.');
-            _sm.resume();
-          });
-          break;
-
-        case EVENT_P2P_CMD_DISCONNECT:
-          // Since we only support single connection, we can ignore
-          // the given peer address.
-          _sm.pause();
-          aP2pCommand.p2pGroupRemove(_groupInfo.ifname, function(success) {
-            aEvent.info.onDoDisconnect(true);
-            _sm.resume();
-          });
-
-          debug('Sent disconnect command. Wait for EVENT_P2P_GROUP_REMOVED.');
-          break;
-
-        case EVENT_P2P_PROV_DISC_PBC_REQ:
-        case EVENT_P2P_PROV_DISC_SHOW_PIN:
-        case EVENT_P2P_PROV_DISC_ENTER_PIN:
-          debug('Someone is trying to connect to me: ' + JSON.stringify(aEvent.info));
-
-          _savedConfig = {
-            name:      aEvent.info.name,
-            address:   aEvent.info.address,
-            wpsMethod: aEvent.info.wpsMethod,
-            pin:       aEvent.info.pin
-          };
-
-          _sm.gotoState(stateWaitingForJoiningConfirmation);
-          break;
-
-        default:
-          return false;
-      } // end of switch
-      return true;
-    }
-  });
-
-  var stateWaitingForJoiningConfirmation = _sm.makeState("WAITING_FOR_JOINING_CONFIRMATION", {
-    timeoutTimer: null,
-
-    enter: function() {
-      gSysMsgr.broadcastMessage(PAIRING_REQUEST_SYS_MSG, _savedConfig);
-      this.timeoutTimer = initTimeoutTimer(30000, EVENT_TIMEOUT_PAIRING_CONFIRMATION);
-    },
-
-    handleEvent: function (aEvent) {
-      switch (aEvent.id) {
-        case EVENT_P2P_SET_PAIRING_CONFIRMATION:
-          if (!aEvent.info.accepted) {
-            debug('User rejected invitation!');
-            _sm.gotoState(stateConnected);
-            break;
-          }
-
-          let onWpsCommandSent = function(success) {
-            _observer.onConnecting(_savedConfig);
-            _sm.gotoState(stateConnected);
-          };
-
-          _sm.pause();
-          if (WPS_METHOD_PBC === _savedConfig.wpsMethod) {
-            aP2pCommand.wpsPbc(onWpsCommandSent, _groupInfo.ifname);
-          } else {
-            let detail = { pin: _savedConfig.pin, iface: _groupInfo.ifname };
-            aP2pCommand.wpsPin(detail, onWpsCommandSent);
-          }
-          break;
-
-        case EVENT_TIMEOUT_PAIRING_CONFIRMATION:
-          debug('WAITING_FOR_JOINING_CONFIRMATION timeout!');
-          _sm.gotoState(stateConnected);
-          break;
-
-        default:
-          return false;
-      } // End of switch.
-      return true;
-    },
-
-    exit: function() {
-      this.timeoutTimer.cancel();
-      this.timeoutTimer = null;
-    }
-  });
-
-  var stateDisconnecting = _sm.makeState("DISCONNECTING", {
-    enter: function() {
-      _sm.pause();
-      handleGroupRemoved(_removedGroupInfo, function (success) {
-        if (!success) {
-          debug('Failed to handle group removed event. What can I do?');
-        }
-        _sm.gotoState(stateInactive);
-      });
-    },
-
-    handleEvent: function(aEvent) {
-      return false; // We will not receive any event in this state.
-    }
-  });
-
-  var stateDisabling = _sm.makeState("DISABLING", {
-    enter: function() {
-      _sm.pause();
-      aNetUtil.stopDhcpServer(function (success) { // Stopping DHCP server is harmless.
-        debug('Stop DHCP server result: ' + success);
-        aP2pCommand.p2pDisable(function(success) {
-          debug('P2P function disabled');
-          closeSupplicantConnectionIfNeeded(function() {
-            debug('Supplicant connection closed');
-            gNetworkService.disableInterface(P2P_INTERFACE_NAME, function (success){
-              debug('Disabled interface: ' + P2P_INTERFACE_NAME);
-              _onDisabled(true);
-              _observer.onDisabled();
-              _sm.gotoState(stateDisabled);
-            });
-          });
-        });
-      });
-
-      function closeSupplicantConnectionIfNeeded(callback) {
-        // No need to connect to supplicant on KK. Call back directly.
-        if (aP2pCommand.getSdkVersion() >= 19) {
-          callback();
-          return;
-        }
-        aP2pCommand.closeSupplicantConnection(callback);
-      }
-    },
-
-    handleEvent: function(aEvent) {
-      return false; // We will not receive any event in this state.
-    }
-  });
-
-  //----------------------------------------------------------
-  // Helper functions.
-  //----------------------------------------------------------
-
-  // Handle 'P2P_GROUP_STARTED' event. Note that this function
-  // will also do the state transitioning and error handling.
-  //
-  // @param aInfo Information carried by "P2P_GROUP_STARTED" event:
-  //   .role: P2P_ROLE_GO or P2P_ROLE_CLIENT
-  //   .ssid:
-  //   .freq:
-  //   .passphrase: Used to connect to GO for legacy device.
-  //   .goAddress:
-  //   .ifname: e.g. p2p-p2p0
-  //
-  // @param aCallback Callback function.
-  function handleGroupStarted(aInfo, aCallback) {
-    debug('handleGroupStarted: ' + JSON.stringify(aInfo));
-
-    function onSuccess()
-    {
-      _sm.gotoState(stateConnected);
-      aCallback(true);
-    }
-
-    function onFailure()
-    {
-      debug('Failed to handleGroupdStarted(). Remove the group...');
-      aP2pCommand.p2pGroupRemove(aInfo.ifname, function (success) {
-        aCallback(false);
-
-        if (success) {
-          return; // Stay in current state and wait for EVENT_P2P_GROUP_REMOVED.
-        }
-
-        debug('p2pGroupRemove command error!');
-        _sm.gotoState(stateInactive);
-      });
-    }
-
-    // Save this group information.
-    _groupInfo = aInfo;
-    _groupInfo.isGroupOwner = (P2P_ROLE_GO === aInfo.role);
-
-    if (_groupInfo.isGroupOwner) {
-      debug('Group owner. Start DHCP server');
-      let dhcpServerConfig = { ifname: aInfo.ifname,
-                               startIp: GO_DHCP_SERVER_IP_RANGE.startIp,
-                               endIp: GO_DHCP_SERVER_IP_RANGE.endIp,
-                               serverIp: GO_NETWORK_INTERFACE.ip,
-                               maskLength: GO_NETWORK_INTERFACE.maskLength };
-
-      aNetUtil.startDhcpServer(dhcpServerConfig, function (success) {
-        if (!success) {
-          debug('Failed to start DHCP server');
-          onFailure();
-          return;
-        }
-
-        // Update p2p network interface.
-        _p2pNetworkInterface.info.state = Ci.nsINetworkInfo.NETWORK_STATE_CONNECTED;
-        _p2pNetworkInterface.info.ips = [GO_NETWORK_INTERFACE.ip];
-        _p2pNetworkInterface.info.prefixLengths = [GO_NETWORK_INTERFACE.maskLength];
-        _p2pNetworkInterface.info.gateways = [GO_NETWORK_INTERFACE.ip];
-        handleP2pNetworkInterfaceStateChanged();
-
-        _groupInfo.networkInterface = _p2pNetworkInterface;
-
-        debug('Everything is done. Happy p2p GO~');
-        onSuccess();
-      });
-
-      return;
-    }
-
-    // We are the client.
-
-    debug("Client. Request IP from DHCP server on interface: " + _groupInfo.ifname);
-
-    aNetUtil.runDhcp(aInfo.ifname, 0, function(dhcpData) {
-      if(!dhcpData || !dhcpData.info) {
-        debug('Failed to run DHCP client');
-        onFailure();
-        return;
-      }
-
-      // Save network interface.
-      debug("DHCP request success: " + JSON.stringify(dhcpData.info));
-
-      // Update p2p network interface.
-      let maskLength =
-        netHelpers.getMaskLength(netHelpers.stringToIP(dhcpData.info.mask_str));
-      if (!maskLength) {
-        maskLength = 32; // max prefix for IPv4.
-      }
-      _p2pNetworkInterface.info.state = Ci.nsINetworkInfo.NETWORK_STATE_CONNECTED;
-      _p2pNetworkInterface.info.ips = [dhcpData.info.ipaddr_str];
-      _p2pNetworkInterface.info.prefixLengths = [maskLength];
-      if (typeof dhcpData.info.dns1_str == "string" &&
-          dhcpData.info.dns1_str.length) {
-        _p2pNetworkInterface.info.dnses.push(dhcpData.info.dns1_str);
-      }
-      if (typeof dhcpData.info.dns2_str == "string" &&
-          dhcpData.info.dns2_str.length) {
-        _p2pNetworkInterface.info.dnses.push(dhcpData.info.dns2_str);
-      }
-      _p2pNetworkInterface.info.gateways = [dhcpData.info.gateway_str];
-      handleP2pNetworkInterfaceStateChanged();
-
-      _groupInfo.networkInterface = _p2pNetworkInterface;
-
-      debug('Happy p2p client~');
-      onSuccess();
-    });
-  }
-
-  function resetP2pNetworkInterface() {
-    _p2pNetworkInterface.info.state = Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTED;
-    _p2pNetworkInterface.info.ips = [];
-    _p2pNetworkInterface.info.prefixLengths = [];
-    _p2pNetworkInterface.info.dnses = [];
-    _p2pNetworkInterface.info.gateways = [];
-  }
-
-  function registerP2pNetworkInteface() {
-    if (!_p2pNetworkInterface.registered) {
-      resetP2pNetworkInterface();
-      gNetworkManager.registerNetworkInterface(_p2pNetworkInterface);
-      _p2pNetworkInterface.registered = true;
-    }
-  }
-
-  function unregisterP2pNetworkInteface() {
-    if (_p2pNetworkInterface.registered) {
-      resetP2pNetworkInterface();
-      gNetworkManager.unregisterNetworkInterface(_p2pNetworkInterface);
-      _p2pNetworkInterface.registered = false;
-    }
-  }
-
-  function handleP2pNetworkInterfaceStateChanged() {
-    gNetworkManager.updateNetworkInterface(_p2pNetworkInterface);
-  }
-
-  // Handle 'P2P_GROUP_STARTED' event.
-  //
-  // @param aInfo information carried by "P2P_GROUP_REMOVED" event:
-  //   .ifname
-  //   .role: "GO" or "client".
-  //
-  // @param aCallback Callback function.
-  function handleGroupRemoved(aInfo, aCallback) {
-    if (!_groupInfo) {
-      debug('No group info. Why?');
-      aCallback(true);
-      return;
-    }
-    if (_groupInfo.ifname !== aInfo.ifname ||
-        _groupInfo.role   !== aInfo.role) {
-      debug('Unmatched group info: ' + JSON.stringify(_groupInfo) +
-            ' v.s. ' + JSON.stringify(aInfo));
-    }
-
-    // Update p2p network interface.
-    _p2pNetworkInterface.info.state = Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTED;
-    handleP2pNetworkInterfaceStateChanged();
-
-    if (P2P_ROLE_GO === aInfo.role) {
-      aNetUtil.stopDhcpServer(function(success) {
-        debug('Stop DHCP server result: ' + success);
-        aCallback(true);
-      });
-    } else {
-      aNetUtil.stopDhcp(aInfo.ifname, function() {
-        aCallback(true);
-      });
-    }
-  }
-
-  // Non state-specific event handler.
-  function handleEventCommon(aEvent) {
-    switch (aEvent.id) {
-      case EVENT_P2P_DEVICE_FOUND:
-        _observer.onPeerFound(aEvent.info);
-        break;
-
-      case EVENT_P2P_DEVICE_LOST:
-        _observer.onPeerLost(aEvent.info);
-        break;
-
-      case EVENT_P2P_CMD_DISABLE:
-        _onDisabled = aEvent.info.onDisabled;
-        _sm.gotoState(stateDisabling);
-        break;
-
-      case EVENT_P2P_CMD_ENABLE_SCAN:
-        if (_scanBlocked) {
-          _scanPostponded = true;
-          aEvent.info.callback(true);
-          break;
-        }
-        aP2pCommand.p2pEnableScan(P2P_SCAN_TIMEOUT_SEC, aEvent.info.callback);
-        break;
-
-      case EVENT_P2P_CMD_DISABLE_SCAN:
-        aP2pCommand.p2pDisableScan(aEvent.info.callback);
-        break;
-
-      case EVENT_P2P_FIND_STOPPED:
-        break;
-
-      case EVENT_P2P_CMD_BLOCK_SCAN:
-        _scanBlocked = true;
-        aP2pCommand.p2pDisableScan(function(success) {});
-        break;
-
-      case EVENT_P2P_CMD_UNBLOCK_SCAN:
-        _scanBlocked = false;
-        if (_scanPostponded) {
-          aP2pCommand.p2pEnableScan(P2P_SCAN_TIMEOUT_SEC, function(success) {});
-        }
-        break;
-
-      case EVENT_P2P_CMD_CONNECT:
-      case EVENT_P2P_CMD_DISCONNECT:
-        debug("The current state couldn't handle connect/disconnect request. Ignore it.");
-        break;
-
-      default:
-        return false;
-    } // End of switch.
-    return true;
-  }
-
-  function isInP2pManagedState(aState) {
-    let p2pManagedStates = [stateWaitingForConfirmation,
-                            stateWaitingForNegReq,
-                            stateProvisionDiscovery,
-                            stateWaitingForInvitationConfirmation,
-                            stateGroupAdding,
-                            stateReinvoking,
-                            stateConnecting,
-                            stateConnected,
-                            stateDisconnecting];
-
-    for (let i = 0; i < p2pManagedStates.length; i++) {
-      if (aState === p2pManagedStates[i]) {
-        return true;
-      }
-    }
-
-    return false;
-  }
-
-  function initTimeoutTimer(aTimeoutMs, aTimeoutEvent) {
-    let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    function onTimerFired() {
-      _sm.sendEvent({ id: aTimeoutEvent });
-      timer = null;
-    }
-    timer.initWithCallback(onTimerFired.bind(this), aTimeoutMs,
-                           Ci.nsITimer.TYPE_ONE_SHOT);
-    return timer;
-  }
-
-  // Converts local WPS method to peer WPS method.
-  function toPeerWpsMethod(aLocalWpsMethod) {
-    switch (aLocalWpsMethod) {
-      case WPS_METHOD_DISPLAY:
-        return WPS_METHOD_KEYPAD;
-      case WPS_METHOD_KEYPAD:
-        return WPS_METHOD_DISPLAY;
-      case WPS_METHOD_PBC:
-        return WPS_METHOD_PBC;
-      default:
-        return WPS_METHOD_PBC; // Use "push button" as the default method.
-    }
-  }
-
-  return p2pSm;
-}
-
-this.WifiP2pManager.INTERFACE_NAME = P2P_INTERFACE_NAME;
deleted file mode 100644
--- a/dom/wifi/WifiP2pWorkerObserver.jsm
+++ /dev/null
@@ -1,319 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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;
-
-const CONNECTION_STATUS_DISCONNECTED  = "disconnected";
-const CONNECTION_STATUS_CONNECTING    = "connecting";
-const CONNECTION_STATUS_CONNECTED     = "connected";
-const CONNECTION_STATUS_DISCONNECTING = "disconnecting";
-
-const DEBUG = false;
-
-this.EXPORTED_SYMBOLS = ["WifiP2pWorkerObserver"];
-
-// WifiP2pWorkerObserver resides in WifiWorker to handle DOM message
-// by either 1) returning internally maintained information or
-//           2) delegating to aDomMsgResponder. It is also responsible
-// for observing events from WifiP2pManager and dispatch to DOM.
-//
-// @param aDomMsgResponder handles DOM messages, including
-//        - setScanEnabled
-//        - connect
-//        - disconnect
-//        - setPairingConfirmation
-//        The instance is actually WifiP2pManager.
-this.WifiP2pWorkerObserver = function(aDomMsgResponder) {
-  function debug(aMsg) {
-    if (DEBUG) {
-      dump('-------------- WifiP2pWorkerObserver: ' + aMsg);
-    }
-  }
-
-  // Private member variables.
-  let _localDevice;
-  let _peerList = {}; // List of P2pDevice.
-  let _domManagers = [];
-  let _enabled = false;
-  let _groupOwner = null;
-  let _currentPeer = null;
-
-  // Constructor of P2pDevice. It will be exposed to DOM.
-  //
-  // @param aPeer object representing a P2P device:
-  //   .name: string for the device name.
-  //   .address: Mac address.
-  //   .isGroupOwner: boolean to indicate if this device is the group owner.
-  //   .wpsCapabilities: array of string of {"pbc", "display", "keypad"}.
-  function P2pDevice(aPeer) {
-    this.address = aPeer.address;
-    this.name = (aPeer.name ? aPeer.name : aPeer.address);
-    this.isGroupOwner = aPeer.isGroupOwner;
-    this.wpsCapabilities = aPeer.wpsCapabilities;
-    this.connectionStatus = CONNECTION_STATUS_DISCONNECTED;
-
-    // Since this object will be exposed to web, defined the exposed
-    // properties here.
-    this.__exposedProps__ = {
-      address: "r",
-      name: "r",
-      isGroupOwner: "r",
-      wpsCapabilities: "r",
-      connectionStatus: "r"
-    };
-  }
-
-  // Constructor of P2pGroupOwner.
-  //
-  // @param aGroupOwner:
-  //   .macAddress
-  //   .ipAddress
-  //   .passphrase
-  //   .ssid
-  //   .freq
-  //   .isLocal
-  function P2pGroupOwner(aGroupOwner) {
-    this.macAddress = aGroupOwner.macAddress; // The identifier to get further information.
-    this.ipAddress = aGroupOwner.ipAddress;
-    this.passphrase = aGroupOwner.passphrase;
-    this.ssid = aGroupOwner.ssid; // e.g. DIRECT-xy.
-    this.freq = aGroupOwner.freq;
-    this.isLocal = aGroupOwner.isLocal;
-
-    let detail = _peerList[aGroupOwner.macAddress];
-    if (detail) {
-      this.name = detail.name;
-      this.wpsCapabilities = detail.wpsCapabilities;
-    } else if (_localDevice.address === this.macAddress) {
-      this.name = _localDevice.name;
-      this.wpsCapabilities = _localDevice.wpsCapabilities;
-    } else {
-      debug("We don't know this group owner: " + aGroupOwner.macAddress);
-      this.name = aGroupOwner.macAddress;
-      this.wpsCapabilities = [];
-    }
-  }
-
-  function fireEvent(aMessage, aData) {
-    debug('domManager: ' + JSON.stringify(_domManagers));
-    _domManagers.forEach(function(manager) {
-      // Note: We should never have a dead message manager here because we
-      // observe our child message managers shutting down below.
-      manager.sendAsyncMessage("WifiP2pManager:" + aMessage, aData);
-    });
-  }
-
-  function addDomManager(aMsg) {
-    if (-1 === _domManagers.indexOf(aMsg.manager)) {
-      _domManagers.push(aMsg.manager);
-    }
-  }
-
-  function returnMessage(aMessage, aSuccess, aData, aMsg) {
-    let rMsg = aMessage + ":Return:" + (aSuccess ? "OK" : "NO");
-    aMsg.manager.sendAsyncMessage(rMsg,
-                                 { data: aData, rid: aMsg.rid, mid: aMsg.mid });
-  }
-
-  function handlePeerListUpdated() {
-    fireEvent("onpeerinfoupdate", {});
-  }
-
-  // Return a literal object as the constructed object.
-  return {
-    onLocalDeviceChanged: function(aDevice) {
-      _localDevice = aDevice;
-      debug('Local device updated to: ' + JSON.stringify(_localDevice));
-    },
-
-    onEnabled: function() {
-      _peerList = [];
-      _enabled = true;
-      fireEvent("p2pUp", {});
-    },
-
-    onDisbaled: function() {
-      _enabled = false;
-      fireEvent("p2pDown", {});
-    },
-
-    onPeerFound: function(aPeer) {
-      let newFoundPeer = new P2pDevice(aPeer);
-      let origianlPeer = _peerList[aPeer.address];
-      _peerList[aPeer.address] = newFoundPeer;
-      if (origianlPeer) {
-        newFoundPeer.connectionStatus = origianlPeer.connectionStatus;
-      }
-      handlePeerListUpdated();
-    },
-
-    onPeerLost: function(aPeer) {
-      let lostPeer = _peerList[aPeer.address];
-      if (!lostPeer) {
-        debug('Unknown peer lost: ' + aPeer.address);
-        return;
-      }
-      delete _peerList[aPeer.address];
-      handlePeerListUpdated();
-    },
-
-    onConnecting: function(aPeer) {
-      let peer = _peerList[aPeer.address];
-      if (!peer) {
-        debug('Unknown peer connecting: ' + aPeer.address);
-        peer = new P2pDevice(aPeer);
-        _peerList[aPeer.address] = peer;
-        handlePeerListUpdated();
-      }
-      peer.connectionStatus = CONNECTION_STATUS_CONNECTING;
-
-      fireEvent('onconnecting', { peer: peer });
-    },
-
-    onConnected: function(aGroupOwner, aPeer) {
-      let go = new P2pGroupOwner(aGroupOwner);
-      let peer = _peerList[aPeer.address];
-      if (!peer) {
-        debug('Unknown peer connected: ' + aPeer.address);
-        peer = new P2pDevice(aPeer);
-        _peerList[aPeer.address] = peer;
-        handlePeerListUpdated();
-      }
-      peer.connectionStatus = CONNECTION_STATUS_CONNECTED;
-      peer.isGroupOwner = (aPeer.address === aGroupOwner.address);
-
-      _groupOwner = go;
-      _currentPeer = peer;
-
-      fireEvent('onconnected', { groupOwner: go, peer: peer });
-    },
-
-    onDisconnected: function(aPeer) {
-      let peer = _peerList[aPeer.address];
-      if (!peer) {
-        debug('Unknown peer disconnected: ' + aPeer.address);
-        return;
-      }
-
-      peer.connectionStatus = CONNECTION_STATUS_DISCONNECTED;
-
-      _groupOwner = null;
-      _currentPeer = null;
-
-      fireEvent('ondisconnected', { peer: peer });
-    },
-
-    getObservedDOMMessages: function() {
-      return [
-        "WifiP2pManager:getState",
-        "WifiP2pManager:getPeerList",
-        "WifiP2pManager:setScanEnabled",
-        "WifiP2pManager:connect",
-        "WifiP2pManager:disconnect",
-        "WifiP2pManager:setPairingConfirmation",
-        "WifiP2pManager:setDeviceName"
-      ];
-    },
-
-    onDOMMessage: function(aMessage) {
-      let msg = aMessage.data || {};
-      msg.manager = aMessage.target;
-
-      if ("child-process-shutdown" === aMessage.name) {
-        let i;
-        if (-1 !== (i = _domManagers.indexOf(msg.manager))) {
-          _domManagers.splice(i, 1);
-        }
-        return;
-      }
-
-      if (!aMessage.target.assertPermission("wifi-manage")) {
-        return;
-      }
-
-      switch (aMessage.name) {
-        case "WifiP2pManager:getState": // A new DOM manager is created.
-          addDomManager(msg);
-          return { // Synchronous call. Simply return it.
-            enabled: _enabled,
-            groupOwner: _groupOwner,
-            currentPeer: _currentPeer
-          };
-
-        case "WifiP2pManager:setScanEnabled":
-          {
-            let enabled = msg.data;
-
-            aDomMsgResponder.setScanEnabled(enabled, function(success) {
-              returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg);
-            });
-          }
-          break;
-
-        case "WifiP2pManager:getPeerList":
-          {
-            // Convert the object to an array.
-            let peerArray = [];
-            for (let key in _peerList) {
-              if (_peerList.hasOwnProperty(key)) {
-                peerArray.push(_peerList[key]);
-              }
-            }
-
-            returnMessage(aMessage.name, true, peerArray, msg);
-          }
-          break;
-
-        case "WifiP2pManager:connect":
-          {
-            let peer = msg.data;
-
-            let onDoConnect = function(success) {
-              returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg);
-            };
-
-            aDomMsgResponder.connect(peer.address, peer.wpsMethod,
-                                     peer.goIntent, onDoConnect);
-          }
-          break;
-
-        case "WifiP2pManager:disconnect":
-          {
-            let address = msg.data;
-
-            aDomMsgResponder.disconnect(address, function(success) {
-              returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg);
-            });
-          }
-          break;
-
-        case "WifiP2pManager:setPairingConfirmation":
-          {
-            let result = msg.data;
-            aDomMsgResponder.setPairingConfirmation(result);
-            returnMessage(aMessage.name, true, true, msg);
-          }
-          break;
-
-        case "WifiP2pManager:setDeviceName":
-          {
-            let newDeviceName = msg.data;
-            aDomMsgResponder.setDeviceName(newDeviceName, function(success) {
-              returnMessage(aMessage.name, success, (success ? true : "ERROR"), msg);
-            });
-          }
-          break;
-
-        default:
-          if (0 === aMessage.name.indexOf("WifiP2pManager:")) {
-            debug("DOM WifiP2pManager message not handled: " + aMessage.name);
-          }
-      } // End of switch.
-    }
-  };
-};
deleted file mode 100644
--- a/dom/wifi/WifiProxyService.cpp
+++ /dev/null
@@ -1,357 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#include "WifiProxyService.h"
-#include "nsServiceManagerUtils.h"
-#include "mozilla/ModuleUtils.h"
-#include "mozilla/ClearOnShutdown.h"
-#include "mozilla/dom/ToJSValue.h"
-#include "nsXULAppAPI.h"
-#include "WifiUtils.h"
-
-#ifdef MOZ_TASK_TRACER
-#include "GeckoTaskTracer.h"
-using namespace mozilla::tasktracer;
-#endif
-
-#define NS_WIFIPROXYSERVICE_CID \
-  { 0xc6c9be7e, 0x744f, 0x4222, {0xb2, 0x03, 0xcd, 0x55, 0xdf, 0xc8, 0xbc, 0x12} }
-
-using namespace mozilla;
-using namespace mozilla::dom;
-
-namespace mozilla {
-
-// The singleton Wifi service, to be used on the main thread.
-static StaticRefPtr<WifiProxyService> gWifiProxyService;
-
-// The singleton supplicant class, that can be used on any thread.
-static UniquePtr<WpaSupplicant> gWpaSupplicant;
-
-// Runnable used dispatch the WaitForEvent result on the main thread.
-class WifiEventDispatcher : public Runnable
-{
-public:
-  WifiEventDispatcher(const nsAString& aEvent, const nsACString& aInterface)
-    : mEvent(aEvent)
-    , mInterface(aInterface)
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    gWifiProxyService->DispatchWifiEvent(mEvent, mInterface);
-    return NS_OK;
-  }
-
-private:
-  nsString mEvent;
-  nsCString mInterface;
-};
-
-// Runnable used to call WaitForEvent on the event thread.
-class EventRunnable : public Runnable
-{
-public:
-  EventRunnable(const nsACString& aInterface)
-    : mInterface(aInterface)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-    nsAutoString event;
-    gWpaSupplicant->WaitForEvent(event, mInterface);
-    if (!event.IsEmpty()) {
-#ifdef MOZ_TASK_TRACER
-      // Make wifi initialization events to be the source events of TaskTracer,
-      // and originate the rest correlation tasks from here.
-      AutoSourceEvent taskTracerEvent(SourceEventType::Wifi);
-      AddLabel("%s %s", mInterface.get(), NS_ConvertUTF16toUTF8(event).get());
-#endif
-      nsCOMPtr<nsIRunnable> runnable = new WifiEventDispatcher(event, mInterface);
-      NS_DispatchToMainThread(runnable);
-    }
-    return NS_OK;
-  }
-
-private:
-  nsCString mInterface;
-};
-
-// Runnable used dispatch the Command result on the main thread.
-class WifiResultDispatcher : public Runnable
-{
-public:
-  WifiResultDispatcher(WifiResultOptions& aResult, const nsACString& aInterface)
-    : mResult(aResult)
-    , mInterface(aInterface)
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-    gWifiProxyService->DispatchWifiResult(mResult, mInterface);
-    return NS_OK;
-  }
-
-private:
-  WifiResultOptions mResult;
-  nsCString mInterface;
-};
-
-// Runnable used to call SendCommand on the control thread.
-class ControlRunnable : public Runnable
-{
-public:
-  ControlRunnable(CommandOptions aOptions, const nsACString& aInterface)
-    : mOptions(aOptions)
-    , mInterface(aInterface)
-  {
-    MOZ_ASSERT(NS_IsMainThread());
-  }
-
-  NS_IMETHOD Run() override
-  {
-    WifiResultOptions result;
-    if (gWpaSupplicant->ExecuteCommand(mOptions, result, mInterface)) {
-      nsCOMPtr<nsIRunnable> runnable = new WifiResultDispatcher(result, mInterface);
-      NS_DispatchToMainThread(runnable);
-    }
-    return NS_OK;
-  }
-private:
-   CommandOptions mOptions;
-   nsCString mInterface;
-};
-
-NS_IMPL_ISUPPORTS(WifiProxyService, nsIWifiProxyService)
-
-WifiProxyService::WifiProxyService()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(!gWifiProxyService);
-}
-
-WifiProxyService::~WifiProxyService()
-{
-  MOZ_ASSERT(!gWifiProxyService);
-}
-
-already_AddRefed<WifiProxyService>
-WifiProxyService::FactoryCreate()
-{
-  if (!XRE_IsParentProcess()) {
-    return nullptr;
-  }
-
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!gWifiProxyService) {
-    gWifiProxyService = new WifiProxyService();
-    ClearOnShutdown(&gWifiProxyService);
-
-    gWpaSupplicant = MakeUnique<WpaSupplicant>();
-    ClearOnShutdown(&gWpaSupplicant);
-  }
-
-  RefPtr<WifiProxyService> service = gWifiProxyService.get();
-  return service.forget();
-}
-
-NS_IMETHODIMP
-WifiProxyService::Start(nsIWifiEventListener* aListener,
-                        const char ** aInterfaces,
-                        uint32_t aNumOfInterfaces)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  MOZ_ASSERT(aListener);
-
-#if ANDROID_VERSION >= 19
-  // KK changes the way mux'ing/demux'ing different supplicant interfaces
-  // (e.g. wlan0/p2p0) from multi-sockets to single socket embedded with
-  // prefixed interface name (e.g. IFNAME=wlan0 xxxxxx). Therefore, we use
-  // the first given interface as the global interface for KK.
-  aNumOfInterfaces = 1;
-#endif
-
-  nsresult rv;
-
-  // Since EventRunnable runs in the manner of blocking, we have to
-  // spin a thread for each interface.
-  // (See the WpaSupplicant::WaitForEvent)
-  mEventThreadList.SetLength(aNumOfInterfaces);
-  for (uint32_t i = 0; i < aNumOfInterfaces; i++) {
-    mEventThreadList[i].mInterface = aInterfaces[i];
-    rv = NS_NewThread(getter_AddRefs(mEventThreadList[i].mThread));
-    if (NS_FAILED(rv)) {
-      NS_WARNING("Can't create wifi event thread");
-      Shutdown();
-      return NS_ERROR_FAILURE;
-    }
-  }
-
-  rv = NS_NewThread(getter_AddRefs(mControlThread));
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Can't create wifi control thread");
-    Shutdown();
-    return NS_ERROR_FAILURE;
-  }
-
-  mListener = aListener;
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-WifiProxyService::Shutdown()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  for (size_t i = 0; i < mEventThreadList.Length(); i++) {
-    if (mEventThreadList[i].mThread) {
-      mEventThreadList[i].mThread->Shutdown();
-      mEventThreadList[i].mThread = nullptr;
-    }
-  }
-
-  mEventThreadList.Clear();
-
-  if (mControlThread) {
-    mControlThread->Shutdown();
-    mControlThread = nullptr;
-  }
-
-  mListener = nullptr;
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-WifiProxyService::SendCommand(JS::Handle<JS::Value> aOptions,
-                              const nsACString& aInterface,
-                              JSContext* aCx)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-  WifiCommandOptions options;
-
-  if (!options.Init(aCx, aOptions)) {
-    NS_WARNING("Bad dictionary passed to WifiProxyService::SendCommand");
-    return NS_ERROR_FAILURE;
-  }
-
-  if (!mControlThread) {
-    return NS_ERROR_FAILURE;
-  }
-
-  // Dispatch the command to the control thread.
-  CommandOptions commandOptions(options);
-  nsCOMPtr<nsIRunnable> runnable = new ControlRunnable(commandOptions, aInterface);
-  mControlThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-WifiProxyService::WaitForEvent(const nsACString& aInterface)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-#if ANDROID_VERSION >= 19
-  // We will only have one global interface for KK.
-  if (!mEventThreadList.IsEmpty()) {
-    nsCOMPtr<nsIRunnable> runnable = new EventRunnable(aInterface);
-    mEventThreadList[0].mThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL);
-    return NS_OK;
-  }
-#else
-  // Dispatch to the event thread which has the given interface name
-  for (size_t i = 0; i < mEventThreadList.Length(); i++) {
-    if (mEventThreadList[i].mInterface.Equals(aInterface)) {
-      nsCOMPtr<nsIRunnable> runnable = new EventRunnable(aInterface);
-      mEventThreadList[i].mThread->Dispatch(runnable, nsIEventTarget::DISPATCH_NORMAL);
-      return NS_OK;
-    }
-  }
-#endif
-
-  return NS_ERROR_FAILURE;
-}
-
-void
-WifiProxyService::DispatchWifiResult(const WifiResultOptions& aOptions, const nsACString& aInterface)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mozilla::AutoSafeJSContext cx;
-  JS::Rooted<JS::Value> val(cx);
-
-  if (!ToJSValue(cx, aOptions, &val)) {
-    return;
-  }
-
-  if (mListener) {
-    // Call the listener with a JS value.
-    mListener->OnCommand(val, aInterface);
-  }
-}
-
-void
-WifiProxyService::DispatchWifiEvent(const nsAString& aEvent, const nsACString& aInterface)
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-#if ANDROID_VERSION < 19
-  mListener->OnWaitEvent(aEvent, aInterface);
-#else
-  // The interface might be embedded in the event string such as
-  // "IFNAME=wlan0 CTRL-EVENT-BSS-ADDED 65 3c:94:d5:7c:11:8b".
-  // Parse the interface name from the event string and use p2p0
-  // as the default interface if "IFNAME" is not found.
-  nsAutoString event;
-  nsAutoString embeddedInterface(NS_LITERAL_STRING("p2p0"));
-  if (StringBeginsWith(aEvent, NS_LITERAL_STRING("IFNAME"))) {
-    int32_t ifnameFrom = aEvent.FindChar('=') + 1;
-    int32_t ifnameTo = aEvent.FindChar(' ') - 1;
-    embeddedInterface = Substring(aEvent, ifnameFrom, ifnameTo - ifnameFrom + 1);
-    event = Substring(aEvent, aEvent.FindChar(' ') + 1);
-  }
-  else {
-    event = aEvent;
-  }
-  mListener->OnWaitEvent(event, NS_ConvertUTF16toUTF8(embeddedInterface));
-#endif
-}
-
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(WifiProxyService,
-                                         WifiProxyService::FactoryCreate)
-
-NS_DEFINE_NAMED_CID(NS_WIFIPROXYSERVICE_CID);
-
-static const mozilla::Module::CIDEntry kWifiProxyServiceCIDs[] = {
-  { &kNS_WIFIPROXYSERVICE_CID, false, nullptr, WifiProxyServiceConstructor },
-  { nullptr }
-};
-
-static const mozilla::Module::ContractIDEntry kWifiProxyServiceContracts[] = {
-  { "@mozilla.org/wifi/service;1", &kNS_WIFIPROXYSERVICE_CID },
-  { nullptr }
-};
-
-static const mozilla::Module kWifiProxyServiceModule = {
-  mozilla::Module::kVersion,
-  kWifiProxyServiceCIDs,
-  kWifiProxyServiceContracts,
-  nullptr
-};
-
-} // namespace mozilla
-
-NSMODULE_DEFN(WifiProxyServiceModule) = &kWifiProxyServiceModule;
deleted file mode 100644
--- a/dom/wifi/WifiProxyService.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#ifndef WifiProxyService_h
-#define WifiProxyService_h
-
-#include "nsIWifiService.h"
-#include "nsCOMPtr.h"
-#include "nsThread.h"
-#include "mozilla/dom/WifiOptionsBinding.h"
-#include "nsTArray.h"
-
-namespace mozilla {
-
-class WifiProxyService final : public nsIWifiProxyService
-{
-private:
-  struct EventThreadListEntry
-  {
-    nsCOMPtr<nsIThread> mThread;
-    nsCString mInterface;
-  };
-
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIWIFIPROXYSERVICE
-
-  static already_AddRefed<WifiProxyService>
-  FactoryCreate();
-
-  void DispatchWifiEvent(const nsAString& aEvent, const nsACString& aInterface);
-  void DispatchWifiResult(const mozilla::dom::WifiResultOptions& aOptions,
-                          const nsACString& aInterface);
-
-private:
-  WifiProxyService();
-  ~WifiProxyService();
-
-  nsTArray<EventThreadListEntry> mEventThreadList;
-  nsCOMPtr<nsIThread> mControlThread;
-  nsCOMPtr<nsIWifiEventListener> mListener;
-};
-
-} // namespace mozilla
-
-#endif // WifiProxyService_h
deleted file mode 100644
--- a/dom/wifi/WifiUtils.cpp
+++ /dev/null
@@ -1,521 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#include "WifiUtils.h"
-#include <dlfcn.h>
-#include <errno.h>
-#include <cutils/properties.h>
-#include "prinit.h"
-#include "mozilla/Sprintf.h"
-#include "js/CharacterEncoding.h"
-
-using namespace mozilla::dom;
-
-#define BUFFER_SIZE        4096
-#define COMMAND_SIZE       256
-
-// Intentionally not trying to dlclose() this handle. That's playing
-// Russian roulette with security bugs.
-static void* sWifiLib;
-static PRCallOnceType sInitWifiLib;
-
-static PRStatus
-InitWifiLib()
-{
-  sWifiLib = dlopen("/system/lib/libhardware_legacy.so", RTLD_LAZY);
-  // We might fail to open the hardware lib. That's OK.
-  return PR_SUCCESS;
-}
-
-static void*
-GetSharedLibrary()
-{
-  PR_CallOnce(&sInitWifiLib, InitWifiLib);
-  return sWifiLib;
-}
-
-static bool
-GetWifiP2pSupported()
-{
-  char propP2pSupported[PROPERTY_VALUE_MAX];
-  property_get("ro.moz.wifi.p2p_supported", propP2pSupported, "0");
-  return (0 == strcmp(propP2pSupported, "1"));
-}
-
-static int
-hex2num(char c)
-{
-  if (c >= '0' && c <= '9')
-    return c - '0';
-  if (c >= 'a' && c <= 'f')
-    return c - 'a' + 10;
-  if (c >= 'A' && c <= 'F')
-    return c - 'A' + 10;
-  return -1;
-}
-
-static int
-hex2byte(const char* hex)
-{
-  int a, b;
-  a = hex2num(*hex++);
-  if (a < 0)
-    return -1;
-  b = hex2num(*hex++);
-  if (b < 0)
-    return -1;
-  return (a << 4) | b;
-}
-
-// This function is equivalent to printf_decode() at src/utils/common.c in
-// the supplicant.
-
-static uint32_t
-convertToBytes(char* buf, uint32_t maxlen, const char* str)
-{
-  const char *pos = str;
-  uint32_t len = 0;
-  int val;
-
-  while (*pos) {
-    if (len == maxlen)
-      break;
-    switch (*pos) {
-    case '\\':
-      pos++;
-      switch (*pos) {
-      case '\\':
-        buf[len++] = '\\';
-        pos++;
-        break;
-      case '"':
-        buf[len++] = '"';
-        pos++;
-        break;
-      case 'n':
-        buf[len++] = '\n';
-        pos++;
-        break;
-      case 'r':
-        buf[len++] = '\r';
-        pos++;
-        break;
-      case 't':
-        buf[len++] = '\t';
-        pos++;
-        break;
-      case 'e':
-        buf[len++] = '\e';
-        pos++;
-        break;
-      case 'x':
-        pos++;
-        val = hex2byte(pos);
-        if (val < 0) {
-          val = hex2num(*pos);
-          if (val < 0)
-            break;
-          buf[len++] = val;
-          pos++;
-        } else {
-          buf[len++] = val;
-          pos += 2;
-        }
-        break;
-      case '0':
-      case '1':
-      case '2':
-      case '3':
-      case '4':
-      case '5':
-      case '6':
-      case '7':
-        val = *pos++ - '0';
-        if (*pos >= '0' && *pos <= '7')
-          val = val * 8 + (*pos++ - '0');
-        if (*pos >= '0' && *pos <= '7')
-          val = val * 8 + (*pos++ - '0');
-        buf[len++] = val;
-        break;
-      default:
-        break;
-      }
-      break;
-    default:
-      buf[len++] = *pos++;
-      break;
-    }
-  }
-  return len;
-}
-
-// This is the same algorithm as in InflateUTF8StringToBuffer with Copy and
-// while ignoring invalids.
-// https://mxr.mozilla.org/mozilla-central/source/js/src/vm/CharacterEncoding.cpp#231
-
-static const uint32_t REPLACE_UTF8 = 0xFFFD;
-
-static void
-LossyConvertUTF8toUTF16(const char* aInput, uint32_t aLength, nsAString& aOut)
-{
-  JS::UTF8Chars src(aInput, aLength);
-
-  char16_t dst[aLength]; // Allocating for worst case.
-
-  // Count how many char16_t characters are needed in the inflated string.
-  // |i| is the index into |src|, and |j| is the the index into |dst|.
-  size_t srclen = src.length();
-  uint32_t j = 0;
-  for (uint32_t i = 0; i < srclen; i++, j++) {
-    uint32_t v = uint32_t(src[i]);
-    if (v == uint32_t('\0') && i < srclen - 1) {
-      // If the leading byte is '\0' and it's not the last byte,
-      // just ignore it to prevent from being truncated. This could
-      // be caused by |convertToBytes| (e.g. \x00 would be converted to '\0')
-      j--;
-      continue;
-    }
-    if (!(v & 0x80)) {
-      // ASCII code unit.  Simple copy.
-      dst[j] = char16_t(v);
-    } else {
-      // Non-ASCII code unit.  Determine its length in bytes (n).
-      uint32_t n = 1;
-      while (v & (0x80 >> n))
-        n++;
-
-  #define INVALID(report, arg, n2)                          \
-      do {                                                  \
-        n = n2;                                             \
-        goto invalidMultiByteCodeUnit;                      \
-      } while (0)
-
-      // Check the leading byte.
-      if (n < 2 || n > 4)
-        INVALID(ReportInvalidCharacter, i, 1);
-
-      // Check that |src| is large enough to hold an n-byte code unit.
-      if (i + n > srclen)
-        INVALID(ReportBufferTooSmall, /* dummy = */ 0, 1);
-
-      // Check the second byte.  From Unicode Standard v6.2, Table 3-7
-      // Well-Formed UTF-8 Byte Sequences.
-      if ((v == 0xE0 && ((uint8_t)src[i + 1] & 0xE0) != 0xA0) ||  // E0 A0~BF
-        (v == 0xED && ((uint8_t)src[i + 1] & 0xE0) != 0x80) ||  // ED 80~9F
-        (v == 0xF0 && ((uint8_t)src[i + 1] & 0xF0) == 0x80) ||  // F0 90~BF
-        (v == 0xF4 && ((uint8_t)src[i + 1] & 0xF0) != 0x80))    // F4 80~8F
-      {
-        INVALID(ReportInvalidCharacter, i, 1);
-      }
-
-      // Check the continuation bytes.
-      for (uint32_t m = 1; m < n; m++)
-        if ((src[i + m] & 0xC0) != 0x80)
-          INVALID(ReportInvalidCharacter, i, m);
-
-      // Determine the code unit's length in char16_t units and act accordingly.
-      v = JS::Utf8ToOneUcs4Char((uint8_t *)&src[i], n);
-      if (v < 0x10000) {
-        // The n-byte UTF8 code unit will fit in a single char16_t.
-        dst[j] = char16_t(v);
-      } else {
-        v -= 0x10000;
-        if (v <= 0xFFFFF) {
-          // The n-byte UTF8 code unit will fit in two char16_t units.
-          dst[j] = char16_t((v >> 10) + 0xD800);
-          j++;
-          dst[j] = char16_t((v & 0x3FF) + 0xDC00);
-        } else {
-          // The n-byte UTF8 code unit won't fit in two char16_t units.
-          INVALID(ReportTooBigCharacter, v, 1);
-        }
-      }
-
-    invalidMultiByteCodeUnit:
-      // Move i to the last byte of the multi-byte code unit;  the loop
-      // header will do the final i++ to move to the start of the next
-      // code unit.
-      i += n - 1;
-    }
-  }
-
-  dst[j] = 0;
-  aOut = dst;
-}
-
-// Helper to check we have loaded the hardware shared library.
-#define CHECK_HWLIB(ret)                                                      \
-  void* hwLib = GetSharedLibrary();                                           \
-  if (!hwLib) {                                                               \
-    NS_WARNING("No /system/lib/libhardware_legacy.so");                       \
-    return ret;                                                               \
-  }
-
-#define DEFAULT_IMPL(name, ret, args...) \
-  DEFINE_DLFUNC(name, ret, args...)      \
-  ret do_##name(args) {                  \
-    USE_DLFUNC(name)                     \
-    return name(args);                   \
-  }
-
-// ICS implementation.
-class ICSWpaSupplicantImpl : public WpaSupplicantImpl
-{
-public:
-  DEFAULT_IMPL(wifi_load_driver, int32_t, )
-  DEFAULT_IMPL(wifi_unload_driver, int32_t, )
-
-  DEFINE_DLFUNC(wifi_wait_for_event, int32_t, char*, size_t)
-  int32_t do_wifi_wait_for_event(const char *iface, char *buf, size_t len) {
-    USE_DLFUNC(wifi_wait_for_event)
-    return wifi_wait_for_event(buf, len);
-  }
-
-  DEFINE_DLFUNC(wifi_command, int32_t, const char*, char*, size_t*)
-  int32_t do_wifi_command(const char* iface, const char* cmd, char* buf, size_t* len) {
-    USE_DLFUNC(wifi_command)
-    return wifi_command(cmd, buf, len);
-  }
-
-  DEFINE_DLFUNC(wifi_start_supplicant, int32_t, )
-  int32_t do_wifi_start_supplicant(int32_t) {
-    USE_DLFUNC(wifi_start_supplicant)
-    return wifi_start_supplicant();
-  }
-
-  DEFINE_DLFUNC(wifi_stop_supplicant, int32_t)
-  int32_t do_wifi_stop_supplicant(int32_t) {
-    USE_DLFUNC(wifi_stop_supplicant)
-    return wifi_stop_supplicant();
-  }
-
-  DEFINE_DLFUNC(wifi_connect_to_supplicant, int32_t, )
-  int32_t do_wifi_connect_to_supplicant(const char* iface) {
-    USE_DLFUNC(wifi_connect_to_supplicant)
-    return wifi_connect_to_supplicant();
-  }
-
-  DEFINE_DLFUNC(wifi_close_supplicant_connection, void, )
-  void do_wifi_close_supplicant_connection(const char* iface) {
-    USE_DLFUNC(wifi_close_supplicant_connection)
-    return wifi_close_supplicant_connection();
-  }
-};
-
-// JB implementation.
-// We only redefine the methods that have a different signature than on ICS.
-class JBWpaSupplicantImpl : public ICSWpaSupplicantImpl
-{
-public:
-  DEFINE_DLFUNC(wifi_wait_for_event, int32_t, const char*, char*, size_t)
-  int32_t do_wifi_wait_for_event(const char* iface, char* buf, size_t len) {
-    USE_DLFUNC(wifi_wait_for_event)
-    return wifi_wait_for_event(iface, buf, len);
-  }
-
-  DEFINE_DLFUNC(wifi_command, int32_t, const char*, const char*, char*, size_t*)
-  int32_t do_wifi_command(const char* iface, const char* cmd, char* buf, size_t* len) {
-    USE_DLFUNC(wifi_command)
-    return wifi_command(iface, cmd, buf, len);
-  }
-
-  DEFINE_DLFUNC(wifi_start_supplicant, int32_t, int32_t)
-  int32_t do_wifi_start_supplicant(int32_t arg) {
-    USE_DLFUNC(wifi_start_supplicant)
-    return wifi_start_supplicant(arg);
-  }
-
-  DEFINE_DLFUNC(wifi_stop_supplicant, int32_t, int32_t)
-  int32_t do_wifi_stop_supplicant(int32_t arg) {
-    USE_DLFUNC(wifi_stop_supplicant)
-    return wifi_stop_supplicant(arg);
-  }
-
-  DEFINE_DLFUNC(wifi_connect_to_supplicant, int32_t, const char*)
-  int32_t do_wifi_connect_to_supplicant(const char* iface) {
-    USE_DLFUNC(wifi_connect_to_supplicant)
-    return wifi_connect_to_supplicant(iface);
-  }
-
-  DEFINE_DLFUNC(wifi_close_supplicant_connection, void, const char*)
-  void do_wifi_close_supplicant_connection(const char* iface) {
-    USE_DLFUNC(wifi_close_supplicant_connection)
-    wifi_close_supplicant_connection(iface);
-  }
-};
-
-// KK implementation.
-// We only redefine the methods that have a different signature than on ICS.
-class KKWpaSupplicantImpl : public ICSWpaSupplicantImpl
-{
-public:
-  DEFINE_DLFUNC(wifi_start_supplicant, int32_t, int32_t)
-  int32_t do_wifi_start_supplicant(int32_t arg) {
-    USE_DLFUNC(wifi_start_supplicant)
-    return wifi_start_supplicant(arg);
-  }
-
-  DEFINE_DLFUNC(wifi_stop_supplicant, int32_t, int32_t)
-  int32_t do_wifi_stop_supplicant(int32_t arg) {
-    USE_DLFUNC(wifi_stop_supplicant)
-    return wifi_stop_supplicant(arg);
-  }
-
-  DEFINE_DLFUNC(wifi_command, int32_t, const char*, char*, size_t*)
-  int32_t do_wifi_command(const char* iface, const char* cmd, char* buf, size_t* len) {
-    char command[COMMAND_SIZE];
-    if (!strcmp(iface, "p2p0")) {
-      // Commands for p2p0 interface don't need prefix
-      SprintfLiteral(command, "%s", cmd);
-    }
-    else {
-      SprintfLiteral(command, "IFNAME=%s %s", iface, cmd);
-    }
-    USE_DLFUNC(wifi_command)
-    return wifi_command(command, buf, len);
-  }
-};
-
-// Concrete class to use to access the wpa supplicant.
-WpaSupplicant::WpaSupplicant()
-{
-  char propVersion[PROPERTY_VALUE_MAX];
-  property_get("ro.build.version.sdk", propVersion, "0");
-  mSdkVersion = strtol(propVersion, nullptr, 10);
-
-  if (mSdkVersion < 16) {
-    mImpl = MakeUnique<ICSWpaSupplicantImpl>();
-  } else if (mSdkVersion < 19) {
-    mImpl = MakeUnique<JBWpaSupplicantImpl>();
-  } else {
-    mImpl = MakeUnique<KKWpaSupplicantImpl>();
-  }
-  mWifiHotspotUtils = MakeUnique<WifiHotspotUtils>();
-};
-
-void WpaSupplicant::WaitForEvent(nsAString& aEvent, const nsCString& aInterface)
-{
-  CHECK_HWLIB()
-
-  char buffer[BUFFER_SIZE];
-  int32_t ret = mImpl->do_wifi_wait_for_event(aInterface.get(), buffer, BUFFER_SIZE);
-  CheckBuffer(buffer, ret, aEvent);
-}
-
-#define GET_CHAR(prop) NS_ConvertUTF16toUTF8(aOptions.prop).get()
-
-/**
- * Make a subnet mask.
- */
-uint32_t WpaSupplicant::MakeMask(uint32_t len) {
-  uint32_t mask = 0;
-  for (uint32_t i = 0; i < len; ++i) {
-    mask |= (0x80000000 >> i);
-  }
-  return ntohl(mask);
-}
-
-bool WpaSupplicant::ExecuteCommand(CommandOptions aOptions,
-                                   WifiResultOptions& aResult,
-                                   const nsCString& aInterface)
-{
-  CHECK_HWLIB(false)
-
-  if (!mWifiHotspotUtils->GetSharedLibrary()) {
-    return false;
-  }
-
-  // Always correlate the opaque ids.
-  aResult.mId = aOptions.mId;
-
-  if (aOptions.mCmd.EqualsLiteral("command")) {
-    size_t len = BUFFER_SIZE - 1;
-    char buffer[BUFFER_SIZE];
-    NS_ConvertUTF16toUTF8 request(aOptions.mRequest);
-    aResult.mStatus = mImpl->do_wifi_command(aInterface.get(), request.get(), buffer, &len);
-    nsString value;
-    if (aResult.mStatus == 0) {
-      if (buffer[len - 1] == '\n') { // remove trailing new lines.
-        len--;
-      }
-      buffer[len] = '\0';
-      CheckBuffer(buffer, len, value);
-    }
-    aResult.mReply = value;
-  } else if (aOptions.mCmd.EqualsLiteral("close_supplicant_connection")) {
-    mImpl->do_wifi_close_supplicant_connection(aInterface.get());
-  } else if (aOptions.mCmd.EqualsLiteral("load_driver")) {
-    aResult.mStatus = mImpl->do_wifi_load_driver();
-  } else if (aOptions.mCmd.EqualsLiteral("unload_driver")) {
-    aResult.mStatus = mImpl->do_wifi_unload_driver();
-  } else if (aOptions.mCmd.EqualsLiteral("start_supplicant")) {
-    aResult.mStatus = mImpl->do_wifi_start_supplicant(GetWifiP2pSupported() ? 1 : 0);
-  } else if (aOptions.mCmd.EqualsLiteral("stop_supplicant")) {
-    aResult.mStatus = mImpl->do_wifi_stop_supplicant(0);
-  } else if (aOptions.mCmd.EqualsLiteral("connect_to_supplicant")) {
-    aResult.mStatus = mImpl->do_wifi_connect_to_supplicant(aInterface.get());
-  } else if (aOptions.mCmd.EqualsLiteral("hostapd_command")) {
-    size_t len = BUFFER_SIZE - 1;
-    char buffer[BUFFER_SIZE];
-    NS_ConvertUTF16toUTF8 request(aOptions.mRequest);
-    aResult.mStatus = mWifiHotspotUtils->do_wifi_hostapd_command(request.get(),
-                                                                 buffer,
-                                                                 &len);
-    nsString value;
-    if (aResult.mStatus == 0) {
-      if (buffer[len - 1] == '\n') { // remove trailing new lines.
-        len--;
-      }
-      buffer[len] = '\0';
-      CheckBuffer(buffer, len, value);
-    }
-    aResult.mReply = value;
-  } else if (aOptions.mCmd.EqualsLiteral("hostapd_get_stations")) {
-    aResult.mStatus = mWifiHotspotUtils->do_wifi_hostapd_get_stations();
-  } else if (aOptions.mCmd.EqualsLiteral("connect_to_hostapd")) {
-    aResult.mStatus = mWifiHotspotUtils->do_wifi_connect_to_hostapd();
-  } else if (aOptions.mCmd.EqualsLiteral("close_hostapd_connection")) {
-    aResult.mStatus = mWifiHotspotUtils->do_wifi_close_hostapd_connection();
-
-  } else {
-    NS_WARNING("WpaSupplicant::ExecuteCommand : Unknown command");
-    printf_stderr("WpaSupplicant::ExecuteCommand : Unknown command: %s",
-      NS_ConvertUTF16toUTF8(aOptions.mCmd).get());
-    return false;
-  }
-
-  return true;
-}
-
-// Checks the buffer and do the utf processing.
-void
-WpaSupplicant::CheckBuffer(char* buffer, int32_t length,
-                           nsAString& aEvent)
-{
-  if (length <= 0 || length >= (BUFFER_SIZE - 1)) {
-    NS_WARNING("WpaSupplicant::CheckBuffer: Invalid buffer length");
-    return;
-  }
-
-  if (mSdkVersion < 18) {
-    buffer[length] = 0;
-    LossyConvertUTF8toUTF16(buffer, length, aEvent);
-    return;
-  }
-
-  // After Android JB4.3, the SSIDs have been converted into printable form.
-  // In most of cases, SSIDs do not use unprintable characters, but IEEE 802.11
-  // standard does not limit the used character set, so anything could be used
-  // in an SSID. Convert it to raw data form here.
-  char bytesBuffer[BUFFER_SIZE];
-  uint32_t bytes = convertToBytes(bytesBuffer, length, buffer);
-  if (bytes <= 0 || bytes >= BUFFER_SIZE) {
-    NS_WARNING("WpaSupplicant::CheckBuffer: Invalid bytesbuffer length");
-    return;
-  }
-  bytesBuffer[bytes] = 0;
-  LossyConvertUTF8toUTF16(bytesBuffer, bytes, aEvent);
-}
deleted file mode 100644
--- a/dom/wifi/WifiUtils.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-/**
- * Abstraction on top of the wifi support from libhardware_legacy that we
- * use to talk to the wpa_supplicant.
- */
-
-#ifndef WifiUtils_h
-#define WifiUtils_h
-
-#include "nsString.h"
-#include "mozilla/dom/WifiOptionsBinding.h"
-#include "mozilla/UniquePtr.h"
-#include "WifiHotspotUtils.h"
-
-// Needed to add a copy constructor to WifiCommandOptions.
-struct CommandOptions
-{
-public:
-  CommandOptions(const mozilla::dom::WifiCommandOptions& aOther) {
-
-#define COPY_OPT_FIELD(prop, defaultValue)            \
-    if (aOther.prop.WasPassed()) {                    \
-      prop = aOther.prop.Value();                     \
-    } else {                                          \
-      prop = defaultValue;                            \
-    }
-
-#define COPY_FIELD(prop) prop = aOther.prop;
-    COPY_FIELD(mId)
-    COPY_FIELD(mCmd)
-    COPY_OPT_FIELD(mRequest, EmptyString())
-
-#undef COPY_OPT_FIELD
-#undef COPY_FIELD
-  }
-
-  // All the fields, not Optional<> anymore to get copy constructors.
-  nsString mCmd;
-  int32_t mId;
-  nsString mRequest;
-};
-
-// Abstract class that exposes libhardware_legacy functions we need for
-// wifi management.
-// We use the ICS signatures here since they are likely more future-proof.
-class WpaSupplicantImpl
-{
-public:
-  // Suppress warning from |UniquePtr|
-  virtual ~WpaSupplicantImpl() {}
-
-  virtual int32_t
-  do_wifi_wait_for_event(const char *iface, char *buf, size_t len) = 0; // KK == ICS != JB
-
-  virtual int32_t
-  do_wifi_command(const char* iface, const char* cmd, char* buff, size_t* len) = 0; // KK == ICS != JB
-
-  virtual int32_t
-  do_wifi_load_driver() = 0;
-
-  virtual int32_t
-  do_wifi_unload_driver() = 0;
-
-  virtual int32_t
-  do_wifi_start_supplicant(int32_t) = 0; // ICS != JB == KK
-
-  virtual int32_t
-  do_wifi_stop_supplicant(int32_t) = 0; //ICS != JB == KK
-
-  virtual int32_t
-  do_wifi_connect_to_supplicant(const char* iface) = 0; // KK == ICS != JB
-
-  virtual void
-  do_wifi_close_supplicant_connection(const char* iface) = 0; // KK == ICS != JB
-};
-
-// Concrete class to use to access the wpa supplicant.
-class WpaSupplicant final
-{
-public:
-  WpaSupplicant();
-
-  // Use nsCString as the type of aInterface to guarantee it's
-  // null-terminated so that we can pass it to c API without
-  // conversion
-  void WaitForEvent(nsAString& aEvent, const nsCString& aInterface);
-  bool ExecuteCommand(CommandOptions aOptions,
-                      mozilla::dom::WifiResultOptions& result,
-                      const nsCString& aInterface);
-
-private:
-  UniquePtr<WpaSupplicantImpl> mImpl;
-  UniquePtr<WifiHotspotUtils> mWifiHotspotUtils;
-
-  uint32_t mSdkVersion;
-
-protected:
-  void CheckBuffer(char* buffer, int32_t length, nsAString& aEvent);
-  uint32_t MakeMask(uint32_t len);
-};
-
-#endif // WifiUtils_h
deleted file mode 100644
--- a/dom/wifi/WifiWorker.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#define NS_WIFIWORKER_CID \
-{ 0xA14E8977, 0xD259, 0x433A, \
-  { 0xA8, 0x8D, 0x58, 0xDD, 0x44, 0x65, 0x7E, 0x5B } }
deleted file mode 100644
--- a/dom/wifi/WifiWorker.js
+++ /dev/null
@@ -1,3928 +0,0 @@
-/* -*- indent-tabs-mode: nil; js-indent-level: 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");
-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";
-const WIFIWORKER_CID        = Components.ID("{a14e8977-d259-433a-a88d-58dd44657e5b}");
-
-const WIFIWORKER_WORKER     = "resource://gre/modules/wifi_worker.js";
-
-const kMozSettingsChangedObserverTopic   = "mozsettings-changed";
-
-const MAX_RETRIES_ON_AUTHENTICATION_FAILURE = 2;
-const MAX_SUPPLICANT_LOOP_ITERATIONS = 4;
-const MAX_RETRIES_ON_DHCP_FAILURE = 2;
-
-// Settings DB path for wifi
-const SETTINGS_WIFI_ENABLED            = "wifi.enabled";
-const SETTINGS_WIFI_DEBUG_ENABLED      = "wifi.debugging.enabled";
-// Settings DB path for Wifi tethering.
-const SETTINGS_WIFI_TETHERING_ENABLED  = "tethering.wifi.enabled";
-const SETTINGS_WIFI_SSID               = "tethering.wifi.ssid";
-const SETTINGS_WIFI_SECURITY_TYPE      = "tethering.wifi.security.type";
-const SETTINGS_WIFI_SECURITY_PASSWORD  = "tethering.wifi.security.password";
-const SETTINGS_WIFI_IP                 = "tethering.wifi.ip";
-const SETTINGS_WIFI_PREFIX             = "tethering.wifi.prefix";
-const SETTINGS_WIFI_DHCPSERVER_STARTIP = "tethering.wifi.dhcpserver.startip";
-const SETTINGS_WIFI_DHCPSERVER_ENDIP   = "tethering.wifi.dhcpserver.endip";
-const SETTINGS_WIFI_DNS1               = "tethering.wifi.dns1";
-const SETTINGS_WIFI_DNS2               = "tethering.wifi.dns2";
-
-// Settings DB path for USB tethering.
-const SETTINGS_USB_DHCPSERVER_STARTIP  = "tethering.usb.dhcpserver.startip";
-const SETTINGS_USB_DHCPSERVER_ENDIP    = "tethering.usb.dhcpserver.endip";
-
-// Default value for WIFI tethering.
-const DEFAULT_WIFI_IP                  = "192.168.1.1";
-const DEFAULT_WIFI_PREFIX              = "24";
-const DEFAULT_WIFI_DHCPSERVER_STARTIP  = "192.168.1.10";
-const DEFAULT_WIFI_DHCPSERVER_ENDIP    = "192.168.1.30";
-const DEFAULT_WIFI_SSID                = "FirefoxHotspot";
-const DEFAULT_WIFI_SECURITY_TYPE       = "open";
-const DEFAULT_WIFI_SECURITY_PASSWORD   = "1234567890";
-const DEFAULT_DNS1                     = "8.8.8.8";
-const DEFAULT_DNS2                     = "8.8.4.4";
-
-// Default value for USB tethering.
-const DEFAULT_USB_DHCPSERVER_STARTIP   = "192.168.0.10";
-const DEFAULT_USB_DHCPSERVER_ENDIP     = "192.168.0.30";
-
-const WIFI_FIRMWARE_AP            = "AP";
-const WIFI_FIRMWARE_STATION       = "STA";
-const WIFI_SECURITY_TYPE_NONE     = "open";
-const WIFI_SECURITY_TYPE_WPA_PSK  = "wpa-psk";
-const WIFI_SECURITY_TYPE_WPA2_PSK = "wpa2-psk";
-
-const NETWORK_INTERFACE_UP   = "up";
-const NETWORK_INTERFACE_DOWN = "down";
-
-const DEFAULT_WLAN_INTERFACE = "wlan0";
-
-const DRIVER_READY_WAIT = 2000;
-
-const SUPP_PROP = "init.svc.wpa_supplicant";
-const WPA_SUPPLICANT = "wpa_supplicant";
-const DHCP_PROP = "init.svc.dhcpcd";
-const DHCP = "dhcpcd";
-
-const MODE_ESS = 0;
-const MODE_IBSS = 1;
-
-XPCOMUtils.defineLazyServiceGetter(this, "gNetworkManager",
-                                   "@mozilla.org/network/manager;1",
-                                   "nsINetworkManager");
-
-XPCOMUtils.defineLazyServiceGetter(this, "gNetworkService",
-                                   "@mozilla.org/network/service;1",
-                                   "nsINetworkService");
-
-XPCOMUtils.defineLazyServiceGetter(this, "gSettingsService",
-                                   "@mozilla.org/settingsService;1",
-                                   "nsISettingsService");
-
-XPCOMUtils.defineLazyServiceGetter(this, "gTetheringService",
-                                   "@mozilla.org/tethering/service;1",
-                                   "nsITetheringService");
-
-// A note about errors and error handling in this file:
-// The libraries that we use in this file are intended for C code. For
-// C code, it is natural to return -1 for errors and 0 for success.
-// Therefore, the code that interacts directly with the worker uses this
-// convention (note: command functions do get boolean results since the
-// command always succeeds and we do a string/boolean check for the
-// expected results).
-var WifiManager = (function() {
-  var manager = {};
-
-  function getStartupPrefs() {
-    return {
-      sdkVersion: parseInt(libcutils.property_get("ro.build.version.sdk"), 10),
-      unloadDriverEnabled: libcutils.property_get("ro.moz.wifi.unloaddriver") === "1",
-      schedScanRecovery: libcutils.property_get("ro.moz.wifi.sched_scan_recover") === "false" ? false : true,
-      driverDelay: libcutils.property_get("ro.moz.wifi.driverDelay"),
-      p2pSupported: libcutils.property_get("ro.moz.wifi.p2p_supported") === "1",
-      eapSimSupported: libcutils.property_get("ro.moz.wifi.eapsim_supported") === "1",
-      ibssSupported: libcutils.property_get("ro.moz.wifi.ibss_supported", "true") === "true",
-      ifname: libcutils.property_get("wifi.interface")
-    };
-  }
-
-  let {sdkVersion, unloadDriverEnabled, schedScanRecovery,
-       driverDelay, p2pSupported, eapSimSupported, ibssSupported, ifname} = getStartupPrefs();
-
-  let capabilities = {
-    security: ["OPEN", "WEP", "WPA-PSK", "WPA-EAP"],
-    eapMethod: ["PEAP", "TTLS", "TLS"],
-    eapPhase2: ["MSCHAPV2"],
-    certificate: ["SERVER"],
-    mode: [MODE_ESS]
-  };
-  if (eapSimSupported) {
-    capabilities.eapMethod.unshift("SIM");
-  }
-  if (ibssSupported) {
-    capabilities.mode.push(MODE_IBSS);
-  }
-
-  let wifiListener = {
-    onWaitEvent: function(event, iface) {
-      if (manager.ifname === iface && handleEvent(event)) {
-        waitForEvent(iface);
-      } else if (p2pSupported) {
-        // Please refer to
-        // http://androidxref.com/4.4.2_r1/xref/frameworks/base/wifi/java/android/net/wifi/WifiMonitor.java#519
-        // for interface event mux/demux rules. In short words, both
-        // 'p2p0' and 'p2p-' should go to Wifi P2P state machine.
-        if (WifiP2pManager.INTERFACE_NAME === iface || -1 !== iface.indexOf('p2p-')) {
-          // If the connection is closed, wifi.c::wifi_wait_for_event()
-          // will still return 'CTRL-EVENT-TERMINATING  - connection closed'
-          // rather than blocking. So when we see this special event string,
-          // just return immediately.
-          const TERMINATED_EVENT = 'CTRL-EVENT-TERMINATING  - connection closed';
-          if (-1 !== event.indexOf(TERMINATED_EVENT)) {
-            return;
-          }
-          p2pManager.handleEvent(event);
-          waitForEvent(iface);
-        }
-      }
-    },
-
-    onCommand: function(event, iface) {
-      onmessageresult(event, iface);
-    }
-  }
-
-  manager.ifname = ifname;
-  manager.connectToSupplicant = false;
-  // Emulator build runs to here.
-  // The debug() should only be used after WifiManager.
-  if (!ifname) {
-    manager.ifname = DEFAULT_WLAN_INTERFACE;
-  }
-  manager.schedScanRecovery = schedScanRecovery;
-  manager.driverDelay = driverDelay ? parseInt(driverDelay, 10) : DRIVER_READY_WAIT;
-
-  // Regular Wifi stuff.
-  var netUtil = WifiNetUtil(controlMessage);
-  var wifiCommand = WifiCommand(controlMessage, manager.ifname, sdkVersion);
-
-  // Wifi P2P stuff
-  var p2pManager;
-  if (p2pSupported) {
-    let p2pCommand = WifiCommand(controlMessage, WifiP2pManager.INTERFACE_NAME, sdkVersion);
-    p2pManager = WifiP2pManager(p2pCommand, netUtil);
-  }
-
-  let wifiService = Cc["@mozilla.org/wifi/service;1"];
-  if (wifiService) {
-    wifiService = wifiService.getService(Ci.nsIWifiProxyService);
-    let interfaces = [manager.ifname];
-    if (p2pSupported) {
-      interfaces.push(WifiP2pManager.INTERFACE_NAME);
-    }
-    wifiService.start(wifiListener, interfaces, interfaces.length);
-  } else {
-    debug("No wifi service component available!");
-  }
-
-  // Callbacks to invoke when a reply arrives from the wifi service.
-  var controlCallbacks = Object.create(null);
-  var idgen = 0;
-
-  function controlMessage(obj, callback) {
-    var id = idgen++;
-    obj.id = id;
-    if (callback) {
-      controlCallbacks[id] = callback;
-    }
-    wifiService.sendCommand(obj, obj.iface);
-  }
-
-  let onmessageresult = function(data, iface) {
-    var id = data.id;
-    var callback = controlCallbacks[id];
-    if (callback) {
-      callback(data);
-      delete controlCallbacks[id];
-    }
-  }
-
-  // Polling the status worker
-  var recvErrors = 0;
-
-  function waitForEvent(iface) {
-    wifiService.waitForEvent(iface);
-  }
-
-  // Commands to the control worker.
-
-  var driverLoaded = false;
-
-  function loadDriver(callback) {
-    if (driverLoaded) {
-      callback(0);
-      return;
-    }
-
-    wifiCommand.loadDriver(function (status) {
-      driverLoaded = (status >= 0);
-      callback(status)
-    });
-  }
-
-  function unloadDriver(type, callback) {
-    if (!unloadDriverEnabled) {
-      // Unloading drivers is generally unnecessary and
-      // can trigger bugs in some drivers.
-      // On properly written drivers, bringing the interface
-      // down powers down the interface.
-      if (type === WIFI_FIRMWARE_STATION) {
-        notify("supplicantlost", { success: true });
-      }
-      callback(0);
-      return;
-    }
-
-    wifiCommand.unloadDriver(function(status) {
-      driverLoaded = (status < 0);
-      if (type === WIFI_FIRMWARE_STATION) {
-        notify("supplicantlost", { success: true });
-      }
-      callback(status);
-    });
-  }
-
-  // A note about background scanning:
-  // Normally, background scanning shouldn't be necessary as wpa_supplicant
-  // has the capability to automatically schedule its own scans at appropriate
-  // intervals. However, with some drivers, this appears to get stuck after
-  // three scans, so we enable the driver's background scanning to work around
-  // that when we're not connected to any network. This ensures that we'll
-  // automatically reconnect to networks if one falls out of range.
-  var reEnableBackgroundScan = false;
-
-  // NB: This is part of the internal API.
-  manager.backgroundScanEnabled = false;
-  function setBackgroundScan(enable, callback) {
-    var doEnable = (enable === "ON");
-    if (doEnable === manager.backgroundScanEnabled) {
-      callback(false, true);
-      return;
-    }
-
-    manager.backgroundScanEnabled = doEnable;
-    wifiCommand.setBackgroundScan(manager.backgroundScanEnabled, callback);
-  }
-
-  var scanModeActive = false;
-
-  function scan(forceActive, callback) {
-    if (forceActive && !scanModeActive) {
-      // Note: we ignore errors from doSetScanMode.
-      wifiCommand.doSetScanMode(true, function(ignore) {
-        setBackgroundScan("OFF", function(turned, ignore) {
-          reEnableBackgroundScan = turned;
-          manager.handlePreWifiScan();
-          wifiCommand.scan(function(ok) {
-            wifiCommand.doSetScanMode(false, function(ignore) {
-              // The result of scanCommand is the result of the actual SCAN
-              // request.
-              callback(ok);
-            });
-          });
-        });
-      });
-      return;
-    }
-    manager.handlePreWifiScan();
-    wifiCommand.scan(callback);
-  }
-
-  var debugEnabled = false;
-
-  function syncDebug() {
-    if (debugEnabled !== DEBUG) {
-      let wanted = DEBUG;
-      wifiCommand.setLogLevel(wanted ? "DEBUG" : "INFO", function(ok) {
-        if (ok)
-          debugEnabled = wanted;
-      });
-      if (p2pSupported && p2pManager) {
-        p2pManager.setDebug(DEBUG);
-      }
-    }
-  }
-
-  function getDebugEnabled(callback) {
-    wifiCommand.getLogLevel(function(level) {
-      if (level === null) {
-        debug("Unable to get wpa_supplicant's log level");
-        callback(false);
-        return;
-      }
-
-      var lines = level.split("\n");
-      for (let i = 0; i < lines.length; ++i) {
-        let match = /Current level: (.*)/.exec(lines[i]);
-        if (match) {
-          debugEnabled = match[1].toLowerCase() === "debug";
-          callback(true);
-          return;
-        }
-      }
-
-      // If we're here, we didn't get the current level.
-      callback(false);
-    });
-  }
-
-  function setScanMode(setActive, callback) {
-    scanModeActive = setActive;
-    wifiCommand.doSetScanMode(setActive, callback);
-  }
-
-  var httpProxyConfig = Object.create(null);
-
-  /**
-   * Given a network, configure http proxy when using wifi.
-   * @param network A network object to update http proxy
-   * @param info Info should have following field:
-   *        - httpProxyHost ip address of http proxy.
-   *        - httpProxyPort port of http proxy, set 0 to use default port 8080.
-   * @param callback callback function.
-   */
-  function configureHttpProxy(network, info, callback) {
-    if (!network)
-      return;
-
-    let networkKey = getNetworkKey(network);
-
-    if (!info || info.httpProxyHost === "") {
-      delete httpProxyConfig[networkKey];
-    } else {
-      httpProxyConfig[networkKey] = network;
-      httpProxyConfig[networkKey].httpProxyHost = info.httpProxyHost;
-      httpProxyConfig[networkKey].httpProxyPort = info.httpProxyPort;
-    }
-
-    callback(true);
-  }
-
-  function getHttpProxyNetwork(network) {
-    if (!network)
-      return null;
-
-    let networkKey = getNetworkKey(network);
-    return httpProxyConfig[networkKey];
-  }
-
-  function setHttpProxy(network) {
-    if (!network)
-      return;
-
-    // If we got here, arg network must be the currentNetwork, so we just update
-    // WifiNetworkInterface correspondingly and notify NetworkManager.
-    WifiNetworkInterface.httpProxyHost = network.httpProxyHost;
-    WifiNetworkInterface.httpProxyPort = network.httpProxyPort;
-
-    if (WifiNetworkInterface.info.state ==
-        Ci.nsINetworkInfo.NETWORK_STATE_CONNECTED) {
-      gNetworkManager.updateNetworkInterface(WifiNetworkInterface);
-    }
-  }
-
-  var staticIpConfig = Object.create(null);
-  function setStaticIpMode(network, info, callback) {
-    let setNetworkKey = getNetworkKey(network);
-    let curNetworkKey = null;
-    let currentNetwork = Object.create(null);
-    currentNetwork.netId = manager.connectionInfo.id;
-
-    manager.getNetworkConfiguration(currentNetwork, function () {
-      curNetworkKey = getNetworkKey(currentNetwork);
-
-      // Add additional information to static ip configuration
-      // It is used to compatiable with information dhcp callback.
-      info.ipaddr = netHelpers.stringToIP(info.ipaddr_str);
-      info.gateway = netHelpers.stringToIP(info.gateway_str);
-      info.mask_str = netHelpers.ipToString(netHelpers.makeMask(info.maskLength));
-
-      // Optional
-      info.dns1 = netHelpers.stringToIP(info.dns1_str);
-      info.dns2 = netHelpers.stringToIP(info.dns2_str);
-      info.proxy = netHelpers.stringToIP(info.proxy_str);
-
-      staticIpConfig[setNetworkKey] = info;
-
-      // If the ssid of current connection is the same as configured ssid
-      // It means we need update current connection to use static IP address.
-      if (setNetworkKey == curNetworkKey) {
-        // Use configureInterface directly doesn't work, the network interface
-        // and routing table is changed but still cannot connect to network
-        // so the workaround here is disable interface the enable again to
-        // trigger network reconnect with static ip.
-        gNetworkService.disableInterface(manager.ifname, function (ok) {
-          gNetworkService.enableInterface(manager.ifname, function (ok) {
-            callback(ok);
-          });
-        });
-        return;
-      }
-
-      callback(true);
-    });
-  }
-
-  var dhcpInfo = null;
-
-  function runStaticIp(ifname, key) {
-    debug("Run static ip");
-
-    // Read static ip information from settings.
-    let staticIpInfo;
-
-    if (!(key in staticIpConfig))
-      return;
-
-    staticIpInfo = staticIpConfig[key];
-
-    // Stop dhcpd when use static IP
-    if (dhcpInfo != null) {
-      netUtil.stopDhcp(manager.ifname, function() {});
-    }
-
-    // Set ip, mask length, gateway, dns to network interface
-    gNetworkService.configureInterface( { ifname: ifname,
-                                          ipaddr: staticIpInfo.ipaddr,
-                                          mask: staticIpInfo.maskLength,
-                                          gateway: staticIpInfo.gateway,
-                                          dns1: staticIpInfo.dns1,
-                                          dns2: staticIpInfo.dns2 }, function (data) {
-      netUtil.runIpConfig(ifname, staticIpInfo, function(data) {
-        dhcpInfo = data.info;
-        notify("networkconnected", data);
-      });
-    });
-  }
-
-  var suppressEvents = false;
-  function notify(eventName, eventObject) {
-    if (suppressEvents)
-      return;
-    var handler = manager["on" + eventName];
-    if (handler) {
-      if (!eventObject)
-        eventObject = ({});
-      handler.call(eventObject);
-    }
-  }
-
-  function notifyStateChange(fields) {
-    // If we're already in the COMPLETED state, we might receive events from
-    // the supplicant that tell us that we're re-authenticating or reminding
-    // us that we're associated to a network. In those cases, we don't need to
-    // do anything, so just ignore them.
-    if (manager.state === "COMPLETED" &&
-        fields.state !== "DISCONNECTED" &&
-        fields.state !== "INTERFACE_DISABLED" &&
-        fields.state !== "INACTIVE" &&
-        fields.state !== "SCANNING") {
-      return false;
-    }
-
-    // Stop background scanning if we're trying to connect to a network.
-    if (manager.backgroundScanEnabled &&
-        (fields.state === "ASSOCIATING" ||
-         fields.state === "ASSOCIATED" ||
-         fields.state === "FOUR_WAY_HANDSHAKE" ||
-         fields.state === "GROUP_HANDSHAKE" ||
-         fields.state === "COMPLETED")) {
-      setBackgroundScan("OFF", function() {});
-    }
-
-    fields.prevState = manager.state;
-    // Detect wpa_supplicant's loop iterations.
-    manager.supplicantLoopDetection(fields.prevState, fields.state);
-    notify("statechange", fields);
-
-    // Don't update state when and after disabling.
-    if (manager.state === "DISABLING" ||
-        manager.state === "UNINITIALIZED") {
-      return false;
-    }
-
-    manager.state = fields.state;
-    return true;
-  }
-
-  function parseStatus(status) {
-    if (status === null) {
-      debug("Unable to get wpa supplicant's status");
-      return;
-    }
-
-    var ssid;
-    var bssid;
-    var state;
-    var ip_address;
-    var id;
-
-    var lines = status.split("\n");
-    for (let i = 0; i < lines.length; ++i) {
-      let [key, value] = lines[i].split("=");
-      switch (key) {
-        case "wpa_state":
-          state = value;
-          break;
-        case "ssid":
-          ssid = value;
-          break;
-        case "bssid":
-          bssid = value;
-          break;
-        case "ip_address":
-          ip_address = value;
-          break;
-        case "id":
-          id = value;
-          break;
-      }
-    }
-
-    if (bssid && ssid) {
-      manager.connectionInfo.bssid = bssid;
-      manager.connectionInfo.ssid = ssid;
-      manager.connectionInfo.id = id;
-    }
-
-    if (ip_address)
-      dhcpInfo = { ip_address: ip_address };
-
-    notifyStateChange({ state: state, fromStatus: true });
-
-    // If we parse the status and the supplicant has already entered the
-    // COMPLETED state, then we need to set up DHCP right away.
-    if (state === "COMPLETED")
-      onconnected();
-  }
-
-  // try to connect to the supplicant
-  var connectTries = 0;
-  var retryTimer = null;
-  function connectCallback(ok) {
-    if (ok === 0) {
-      // Tell the event worker to start waiting for events.
-      retryTimer = null;
-      connectTries = 0;
-      recvErrors = 0;
-      manager.connectToSupplicant = true;
-      didConnectSupplicant(function(){});
-      return;
-    }
-    if (connectTries++ < 5) {
-      // Try again in 1 seconds.
-      if (!retryTimer)
-        retryTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-
-      retryTimer.initWithCallback(function(timer) {
-        wifiCommand.connectToSupplicant(connectCallback);
-      }, 1000, Ci.nsITimer.TYPE_ONE_SHOT);
-      return;
-    }
-
-    retryTimer = null;
-    connectTries = 0;
-    notify("supplicantlost", { success: false });
-  }
-
-  manager.connectionDropped = function(callback) {
-    // Reset network interface when connection drop
-    gNetworkService.configureInterface( { ifname: manager.ifname,
-                                          ipaddr: 0,
-                                          mask: 0,
-                                          gateway: 0,
-                                          dns1: 0,
-                                          dns2: 0 }, function (data) {
-    });
-
-    // If we got disconnected, kill the DHCP client in preparation for
-    // reconnection.
-    gNetworkService.resetConnections(manager.ifname, function() {
-      netUtil.stopDhcp(manager.ifname, function() {
-        callback();
-      });
-    });
-  }
-
-  manager.start = function() {
-    debug("detected SDK version " + sdkVersion);
-    wifiCommand.connectToSupplicant(connectCallback);
-  }
-
-  let dhcpRequestGen = 0;
-
-  function onconnected() {
-    // For now we do our own DHCP. In the future, this should be handed
-    // off to the Network Manager.
-    let currentNetwork = Object.create(null);
-    currentNetwork.netId = manager.connectionInfo.id;
-
-    manager.getNetworkConfiguration(currentNetwork, function (){
-      let key = getNetworkKey(currentNetwork);
-      if (staticIpConfig  &&
-          (key in staticIpConfig) &&
-          staticIpConfig[key].enabled) {
-          debug("Run static ip");
-          runStaticIp(manager.ifname, key);
-          return;
-      }
-      netUtil.runDhcp(manager.ifname, dhcpRequestGen++, function(data, gen) {
-        dhcpInfo = data.info;
-        debug('dhcpRequestGen: ' + dhcpRequestGen + ', gen: ' + gen);
-        if (!dhcpInfo) {
-          if (gen + 1 < dhcpRequestGen) {
-            debug('Do not bother younger DHCP request.');
-            return;
-          }
-          if (++manager.dhcpFailuresCount >= MAX_RETRIES_ON_DHCP_FAILURE) {
-            manager.dhcpFailuresCount = 0;
-            notify("disconnected", {connectionInfo: manager.connectionInfo});
-            return;
-          }
-          // NB: We have to call disconnect first. Otherwise, we only reauth with
-          // the existing AP and don't retrigger DHCP.
-          manager.disconnect(function() {
-            manager.reassociate(function(){});
-          });
-          return;
-        }
-
-        manager.dhcpFailuresCount = 0;
-        notify("networkconnected", data);
-      });
-    });
-  }
-
-  var supplicantStatesMap = (sdkVersion >= 15) ?
-    ["DISCONNECTED", "INTERFACE_DISABLED", "INACTIVE", "SCANNING",
-     "AUTHENTICATING", "ASSOCIATING", "ASSOCIATED", "FOUR_WAY_HANDSHAKE",
-     "GROUP_HANDSHAKE", "COMPLETED"]
-    :
-    ["DISCONNECTED", "INACTIVE", "SCANNING", "ASSOCIATING",
-     "ASSOCIATED", "FOUR_WAY_HANDSHAKE", "GROUP_HANDSHAKE",
-     "COMPLETED", "DORMANT", "UNINITIALIZED"];
-
-  var driverEventMap = { STOPPED: "driverstopped", STARTED: "driverstarted", HANGED: "driverhung" };
-
-  manager.getNetworkId = function (ssid, callback) {
-    manager.getConfiguredNetworks(function(networks) {
-      if (!networks) {
-        debug("Unable to get configured networks");
-        return callback(null);
-      }
-      for (let net in networks) {
-        let network = networks[net];
-        // Trying to get netId from
-        // 1. network matching SSID if SSID is provided.
-        // 2. current network if no SSID is provided, it's not guaranteed that
-        //    current network matches requested SSID.
-        if ((!ssid && network.status === "CURRENT") ||
-            (ssid && network.ssid && ssid === dequote(network.ssid))) {
-          return callback(net);
-        }
-      }
-      callback(null);
-    });
-  }
-
-  function handleWpaEapEvents(event) {
-    if (event.indexOf("CTRL-EVENT-EAP-FAILURE") !== -1) {
-      if (event.indexOf("EAP authentication failed") !== -1) {
-        notify("passwordmaybeincorrect");
-        if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-          manager.authenticationFailuresCount = 0;
-          notify("disconnected", {connectionInfo: manager.connectionInfo});
-        }
-      }
-      return true;
-    }
-    if (event.indexOf("CTRL-EVENT-EAP-TLS-CERT-ERROR") !== -1) {
-      // Cert Error
-      notify("passwordmaybeincorrect");
-      if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-        manager.authenticationFailuresCount = 0;
-        notify("disconnected", {connectionInfo: manager.connectionInfo});
-      }
-      return true;
-    }
-    if (event.indexOf("CTRL-EVENT-EAP-STARTED") !== -1) {
-      notifyStateChange({ state: "AUTHENTICATING" });
-      return true;
-    }
-    return true;
-  }
-
-  // Handle events sent to us by the event worker.
-  function handleEvent(event) {
-    debug("Event coming in: " + event);
-    if (event.indexOf("CTRL-EVENT-") !== 0 && event.indexOf("WPS") !== 0) {
-      // Handle connection fail exception on WEP-128, while password length
-      // is not 5 nor 13 bytes.
-      if (event.indexOf("Association request to the driver failed") !== -1) {
-        notify("passwordmaybeincorrect");
-        if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-          manager.authenticationFailuresCount = 0;
-          notify("disconnected", {connectionInfo: manager.connectionInfo});
-        }
-        return true;
-      }
-
-      if (event.indexOf("WPA:") == 0 &&
-          event.indexOf("pre-shared key may be incorrect") != -1) {
-        notify("passwordmaybeincorrect");
-      }
-
-      // This is ugly, but we need to grab the SSID here. BSSID is not guaranteed
-      // to be provided, so don't grab BSSID here.
-      var match = /Trying to associate with.*SSID[ =]'(.*)'/.exec(event);
-      if (match) {
-        debug("Matched: " + match[1] + "\n");
-        manager.connectionInfo.ssid = match[1];
-      }
-      return true;
-    }
-
-    var space = event.indexOf(" ");
-    var eventData = event.substr(0, space + 1);
-    if (eventData.indexOf("CTRL-EVENT-STATE-CHANGE") === 0) {
-      // Parse the event data.
-      var fields = {};
-      var tokens = event.substr(space + 1).split(" ");
-      for (var n = 0; n < tokens.length; ++n) {
-        var kv = tokens[n].split("=");
-        if (kv.length === 2)
-          fields[kv[0]] = kv[1];
-      }
-      if (!("state" in fields))
-        return true;
-      fields.state = supplicantStatesMap[fields.state];
-
-      // The BSSID field is only valid in the ASSOCIATING and ASSOCIATED
-      // states, except when we "reauth", except this seems to depend on the
-      // driver, so simply check to make sure that we don't have a null BSSID.
-      if (fields.BSSID !== "00:00:00:00:00:00")
-        manager.connectionInfo.bssid = fields.BSSID;
-
-      if (notifyStateChange(fields) && fields.state === "COMPLETED") {
-        onconnected();
-      }
-      return true;
-    }
-    if (eventData.indexOf("CTRL-EVENT-DRIVER-STATE") === 0) {
-      var handlerName = driverEventMap[eventData];
-      if (handlerName)
-        notify(handlerName);
-      return true;
-    }
-    if (eventData.indexOf("CTRL-EVENT-TERMINATING") === 0) {
-      // As long the monitor socket is not closed and we haven't seen too many
-      // recv errors yet, we will keep going for a bit longer.
-      if (event.indexOf("connection closed") === -1 &&
-          event.indexOf("recv error") !== -1 && ++recvErrors < 10)
-        return true;
-
-      notifyStateChange({ state: "DISCONNECTED", BSSID: null, id: -1 });
-
-      // If the supplicant is terminated as commanded, the supplicant lost
-      // notification will be sent after driver unloaded. In such case, the
-      // manager state will be "DISABLING" or "UNINITIALIZED".
-      // So if supplicant terminated with incorrect manager state, implying
-      // unexpected condition, we should notify supplicant lost here.
-      if (manager.state !== "DISABLING" && manager.state !== "UNINITIALIZED") {
-        notify("supplicantlost", { success: true });
-      }
-
-      if (manager.stopSupplicantCallback) {
-        cancelWaitForTerminateEventTimer();
-        // It's possible that the terminating event triggered by timer comes
-        // earlier than the event from wpa_supplicant. Since
-        // stopSupplicantCallback contains async. callbacks, swap it to local
-        // to prevent calling the callback twice.
-        let stopSupplicantCallback = manager.stopSupplicantCallback.bind(manager);
-        manager.stopSupplicantCallback = null;
-        stopSupplicantCallback();
-        stopSupplicantCallback = null;
-      }
-      return false;
-    }
-    if (eventData.indexOf("CTRL-EVENT-DISCONNECTED") === 0) {
-      var token = event.split(" ")[1];
-      var bssid = token.split("=")[1];
-      if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-        manager.authenticationFailuresCount = 0;
-        notify("disconnected", {connectionInfo: manager.connectionInfo});
-      }
-      manager.connectionInfo.bssid = null;
-      manager.connectionInfo.ssid = null;
-      manager.connectionInfo.id = -1;
-      return true;
-    }
-    if (eventData.indexOf("CTRL-EVENT-CONNECTED") === 0) {
-      // Format: CTRL-EVENT-CONNECTED - Connection to 00:1e:58:ec:d5:6d completed (reauth) [id=1 id_str=]
-      var bssid = event.split(" ")[4];
-
-      var keyword = "id=";
-      var id = event.substr(event.indexOf(keyword) + keyword.length).split(" ")[0];
-      // Read current BSSID here, it will always being provided.
-      manager.connectionInfo.id = id;
-      manager.connectionInfo.bssid = bssid;
-      return true;
-    }
-    if (eventData.indexOf("CTRL-EVENT-SCAN-RESULTS") === 0) {
-      debug("Notifying of scan results available");
-      if (reEnableBackgroundScan) {
-        reEnableBackgroundScan = false;
-        setBackgroundScan("ON", function() {});
-      }
-      manager.handlePostWifiScan();
-      notify("scanresultsavailable");
-      return true;
-    }
-    if (eventData.indexOf("CTRL-EVENT-EAP") === 0) {
-      return handleWpaEapEvents(event);
-    }
-    if (eventData.indexOf("CTRL-EVENT-ASSOC-REJECT") === 0) {
-      debug("CTRL-EVENT-ASSOC-REJECT: network error");
-      notify("passwordmaybeincorrect");
-      if (manager.authenticationFailuresCount > MAX_RETRIES_ON_AUTHENTICATION_FAILURE) {
-        manager.authenticationFailuresCount = 0;
-        debug("CTRL-EVENT-ASSOC-REJECT: disconnect network");
-        notify("disconnected", {connectionInfo: manager.connectionInfo});
-      }
-      return true;
-    }
-    if (eventData.indexOf("WPS-TIMEOUT") === 0) {
-      notifyStateChange({ state: "WPS_TIMEOUT", BSSID: null, id: -1 });
-      return true;
-    }
-    if (eventData.indexOf("WPS-FAIL") === 0) {
-      notifyStateChange({ state: "WPS_FAIL", BSSID: null, id: -1 });
-      return true;
-    }
-    if (eventData.indexOf("WPS-OVERLAP-DETECTED") === 0) {
-      notifyStateChange({ state: "WPS_OVERLAP_DETECTED", BSSID: null, id: -1 });
-      return true;
-    }
-    // Unknown event.
-    return true;
-  }
-
-  function setPowerSavingMode(enabled) {
-    let mode = enabled ? "AUTO" : "ACTIVE";
-    // Some wifi drivers may not implement this command. Set power mode
-    // even if suspend optimization command failed.
-    manager.setSuspendOptimizations(enabled, function(ok) {
-      manager.setPowerMode(mode, function() {});
-    });
-  }
-
-  function didConnectSupplicant(callback) {
-    waitForEvent(manager.ifname);
-
-    // Load up the supplicant state.
-    getDebugEnabled(function(ok) {
-      syncDebug();
-    });
-    wifiCommand.status(function(status) {
-      parseStatus(status);
-      notify("supplicantconnection");
-      callback();
-    });
-    // WPA supplicant already connected.
-    manager.setPowerSavingMode(true);
-    if (p2pSupported) {
-      manager.enableP2p(function(success) {});
-    }
-  }
-
-  function prepareForStartup(callback) {
-    let status = libcutils.property_get(DHCP_PROP + "_" + manager.ifname);
-    if (status !== "running") {
-      tryStopSupplicant();
-      return;
-    }
-    manager.connectionDropped(function() {
-      tryStopSupplicant();
-    });
-
-    // Ignore any errors and kill any currently-running supplicants. On some
-    // phones, stopSupplicant won't work for a supplicant that we didn't
-    // start, so we hand-roll it here.
-    function tryStopSupplicant () {
-      let status = libcutils.property_get(SUPP_PROP);
-      if (status !== "running") {
-        callback();
-        return;
-      }
-      suppressEvents = true;
-      wifiCommand.killSupplicant(function() {
-        gNetworkService.disableInterface(manager.ifname, function (ok) {
-          suppressEvents = false;
-          callback();
-        });
-      });
-    }
-  }
-
-  // Initial state.
-  manager.state = "UNINITIALIZED";
-  manager.tetheringState = "UNINITIALIZED";
-  manager.supplicantStarted = false;
-  manager.connectionInfo = { ssid: null, bssid: null, id: -1 };
-  manager.authenticationFailuresCount = 0;
-  manager.loopDetectionCount = 0;
-  manager.dhcpFailuresCount = 0;
-  manager.stopSupplicantCallback = null;
-
-  manager.__defineGetter__("enabled", function() {
-    switch (manager.state) {
-      case "UNINITIALIZED":
-      case "INITIALIZING":
-      case "DISABLING":
-        return false;
-      default:
-        return true;
-    }
-  });
-
-  var waitForTerminateEventTimer = null;
-  function cancelWaitForTerminateEventTimer() {
-    if (waitForTerminateEventTimer) {
-      waitForTerminateEventTimer.cancel();
-      waitForTerminateEventTimer = null;
-    }
-  };
-  function createWaitForTerminateEventTimer(onTimeout) {
-    if (waitForTerminateEventTimer) {
-      return;
-    }
-    waitForTerminateEventTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    waitForTerminateEventTimer.initWithCallback(onTimeout,
-                                                4000,
-                                                Ci.nsITimer.TYPE_ONE_SHOT);
-  };
-
-  var waitForDriverReadyTimer = null;
-  function cancelWaitForDriverReadyTimer() {
-    if (waitForDriverReadyTimer) {
-      waitForDriverReadyTimer.cancel();
-      waitForDriverReadyTimer = null;
-    }
-  };
-  function createWaitForDriverReadyTimer(onTimeout) {
-    waitForDriverReadyTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    waitForDriverReadyTimer.initWithCallback(onTimeout,
-                                             manager.driverDelay,
-                                             Ci.nsITimer.TYPE_ONE_SHOT);
-  };
-
-  // Public interface of the wifi service.
-  manager.setWifiEnabled = function(enabled, callback) {
-    if (enabled === manager.isWifiEnabled(manager.state)) {
-      callback("no change");
-      return;
-    }
-
-    if (enabled) {
-      manager.state = "INITIALIZING";
-      // Register as network interface.
-      WifiNetworkInterface.info.name = manager.ifname;
-      if (!WifiNetworkInterface.registered) {
-        gNetworkManager.registerNetworkInterface(WifiNetworkInterface);
-        WifiNetworkInterface.registered = true;
-      }
-      WifiNetworkInterface.info.state =
-        Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTED;
-      WifiNetworkInterface.info.ips = [];
-      WifiNetworkInterface.info.prefixLengths = [];
-      WifiNetworkInterface.info.gateways = [];
-      WifiNetworkInterface.info.dnses = [];
-      gNetworkManager.updateNetworkInterface(WifiNetworkInterface);
-
-      prepareForStartup(function() {
-        loadDriver(function (status) {
-          if (status < 0) {
-            callback(status);
-            manager.state = "UNINITIALIZED";
-            return;
-          }
-          // This command is mandatory for Nexus 4. But some devices like
-          // Galaxy S2 don't support it. Continue to start wpa_supplicant
-          // even if we fail to set wifi operation mode to station.
-          gNetworkService.setWifiOperationMode(manager.ifname,
-                                               WIFI_FIRMWARE_STATION,
-                                               function (status) {
-
-            function startSupplicantInternal() {
-              wifiCommand.startSupplicant(function (status) {
-                if (status < 0) {
-                  unloadDriver(WIFI_FIRMWARE_STATION, function() {
-                    callback(status);
-                  });
-                  manager.state = "UNINITIALIZED";
-                  return;
-                }
-
-                manager.supplicantStarted = true;
-                gNetworkService.enableInterface(manager.ifname, function (ok) {
-                  callback(ok ? 0 : -1);
-                });
-              });
-            }
-
-            function doStartSupplicant() {
-              cancelWaitForDriverReadyTimer();
-
-              if (!manager.connectToSupplicant) {
-                startSupplicantInternal();
-                return;
-              }
-              wifiCommand.closeSupplicantConnection(function () {
-                manager.connectToSupplicant = false;
-                // closeSupplicantConnection() will trigger onsupplicantlost
-                // and set manager.state to "UNINITIALIZED", we have to
-                // restore it here.
-                manager.state = "INITIALIZING";
-                startSupplicantInternal();
-              });
-            }
-            // Driver startup on certain platforms takes longer than it takes for us
-            // to return from loadDriver, so wait 2 seconds before starting
-            // the supplicant to give it a chance to start.
-            if (manager.driverDelay > 0) {
-              createWaitForDriverReadyTimer(doStartSupplicant);
-            } else {
-              doStartSupplicant();
-            }
-          });
-        });
-      });
-    } else {
-      manager.state = "DISABLING";
-      // Note these following calls ignore errors. If we fail to kill the
-      // supplicant gracefully, then we need to continue telling it to die
-      // until it does.
-      let doDisableWifi = function() {
-        manager.stopSupplicantCallback = (function () {
-          wifiCommand.stopSupplicant(function (status) {
-            wifiCommand.closeSupplicantConnection(function() {
-              manager.connectToSupplicant = false;
-              manager.state = "UNINITIALIZED";
-              gNetworkService.disableInterface(manager.ifname, function (ok) {
-                unloadDriver(WIFI_FIRMWARE_STATION, callback);
-              });
-            });
-          });
-        }).bind(this);
-
-        let terminateEventCallback = (function() {
-          handleEvent("CTRL-EVENT-TERMINATING");
-        }).bind(this);
-        createWaitForTerminateEventTimer(terminateEventCallback);
-
-        // We are going to terminate the connection between wpa_supplicant.
-        // Stop the polling timer immediately to prevent connection info update
-        // command blocking in control thread until socket timeout.
-        notify("stopconnectioninfotimer");
-
-        wifiCommand.terminateSupplicant(function (ok) {
-          manager.connectionDropped(function () {
-          });
-        });
-      }
-
-      if (p2pSupported) {
-        p2pManager.setEnabled(false, { onDisabled: doDisableWifi });
-      } else {
-        doDisableWifi();
-      }
-    }
-  }
-
-  var wifiHotspotStatusTimer = null;
-  function cancelWifiHotspotStatusTimer() {
-    if (wifiHotspotStatusTimer) {
-      wifiHotspotStatusTimer.cancel();
-      wifiHotspotStatusTimer = null;
-    }
-  }
-
-  function createWifiHotspotStatusTimer(onTimeout) {
-    wifiHotspotStatusTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    wifiHotspotStatusTimer.init(onTimeout, 5000, Ci.nsITimer.TYPE_REPEATING_SLACK);
-  }
-
-  // Get wifi interface and load wifi driver when enable Ap mode.
-  manager.setWifiApEnabled = function(enabled, configuration, callback) {
-    if (enabled === manager.isWifiTetheringEnabled(manager.tetheringState)) {
-      callback("no change");
-      return;
-    }
-
-    if (enabled) {
-      manager.tetheringState = "INITIALIZING";
-      loadDriver(function (status) {
-        if (status < 0) {
-          callback();
-          manager.tetheringState = "UNINITIALIZED";
-          if (wifiHotspotStatusTimer) {
-            cancelWifiHotspotStatusTimer();
-            wifiCommand.closeHostapdConnection(function(result) {
-            });
-          }
-          return;
-        }
-
-        function getWifiHotspotStatus() {
-          wifiCommand.hostapdGetStations(function(result) {
-            notify("stationinfoupdate", {station: result});
-          });
-        }
-
-        function doStartWifiTethering() {
-          cancelWaitForDriverReadyTimer();
-          WifiNetworkInterface.info.name =
-            libcutils.property_get("wifi.tethering.interface", manager.ifname);
-          gTetheringService.setWifiTethering(enabled,
-                                             WifiNetworkInterface.info.name,
-                                             configuration, function(result) {
-            if (result) {
-              manager.tetheringState = "UNINITIALIZED";
-            } else {
-              manager.tetheringState = "COMPLETED";
-              wifiCommand.connectToHostapd(function(result) {
-                if (result) {
-                  return;
-                }
-                // Create a timer to track the connection status.
-                createWifiHotspotStatusTimer(getWifiHotspotStatus);
-              });
-            }
-            // Pop out current request.
-            callback();
-            // Should we fire a dom event if we fail to set wifi tethering  ?
-            debug("Enable Wifi tethering result: " + (result ? result : "successfully"));
-          });
-        }
-
-        // Driver startup on certain platforms takes longer than it takes
-        // for us to return from loadDriver, so wait 2 seconds before
-        // turning on Wifi tethering.
-        createWaitForDriverReadyTimer(doStartWifiTethering);
-      });
-    } else {
-      cancelWifiHotspotStatusTimer();
-      gTetheringService.setWifiTethering(enabled, WifiNetworkInterface,
-                                         configuration, function(result) {
-        // Should we fire a dom event if we fail to set wifi tethering  ?
-        debug("Disable Wifi tethering result: " + (result ? result : "successfully"));
-        // Unload wifi driver even if we fail to control wifi tethering.
-        unloadDriver(WIFI_FIRMWARE_AP, function(status) {
-          if (status < 0) {
-            debug("Fail to unload wifi driver");
-          }
-          manager.tetheringState = "UNINITIALIZED";
-          callback();
-        });
-      });
-    }
-  }
-
-  manager.disconnect = wifiCommand.disconnect;
-  manager.reconnect = wifiCommand.reconnect;
-  manager.reassociate = wifiCommand.reassociate;
-
-  var networkConfigurationFields = [
-    {name: "ssid",          type: "string"},
-    {name: "bssid",         type: "string"},
-    {name: "psk",           type: "string"},
-    {name: "wep_key0",      type: "string"},
-    {name: "wep_key1",      type: "string"},
-    {name: "wep_key2",      type: "string"},
-    {name: "wep_key3",      type: "string"},
-    {name: "wep_tx_keyidx", type: "integer"},
-    {name: "priority",      type: "integer"},
-    {name: "key_mgmt",      type: "string"},
-    {name: "scan_ssid",     type: "string"},
-    {name: "disabled",      type: "integer"},
-    {name: "identity",      type: "string"},
-    {name: "password",      type: "string"},
-    {name: "auth_alg",      type: "string"},
-    {name: "phase1",        type: "string"},
-    {name: "phase2",        type: "string"},
-    {name: "eap",           type: "string"},
-    {name: "pin",           type: "string"},
-    {name: "pcsc",          type: "string"},
-    {name: "ca_cert",       type: "string"},
-    {name: "subject_match", type: "string"},
-    {name: "client_cert",   type: "string"},
-    {name: "private_key",   type: "stirng"},
-    {name: "engine",        type: "integer"},
-    {name: "engine_id",     type: "string"},
-    {name: "key_id",        type: "string"},
-    {name: "frequency",     type: "integer"},
-    {name: "mode",          type: "integer"}
-  ];
-  // These fields are only handled in IBSS (aka ad-hoc) mode
-  var ibssNetworkConfigurationFields = [
-    "frequency", "mode"
-  ];
-
-  manager.getNetworkConfiguration = function(config, callback) {
-    var netId = config.netId;
-    var done = 0;
-    for (var n = 0; n < networkConfigurationFields.length; ++n) {
-      let fieldName = networkConfigurationFields[n].name;
-      let fieldType = networkConfigurationFields[n].type;
-      wifiCommand.getNetworkVariable(netId, fieldName, function(value) {
-        if (value !== null) {
-          if (fieldType === "integer") {
-            config[fieldName] = parseInt(value, 10);
-          } else if ( fieldName == "ssid" && value[0] != '"' ) {
-            // SET_NETWORK will set a quoted ssid to wpa_supplicant.
-            // But if ssid contains non-ascii char, it will be converted into utf-8.
-            // For example: "Test的wifi" --> 54657374e79a8477696669
-            // When GET_NETWORK receive a un-quoted utf-8 ssid, it must be decoded and quoted.
-            config[fieldName] = quote(decodeURIComponent(value.replace(/[0-9a-f]{2}/g, '%$&')));
-          } else {
-            // value is string type by default.
-            config[fieldName] = value;
-          }
-        }
-        if (++done == networkConfigurationFields.length)
-          callback(config);
-      });
-    }
-  }
-  manager.setNetworkConfiguration = function(config, callback) {
-    var netId = config.netId;
-    var done = 0;
-    var errors = 0;
-
-    function hasValidProperty(name) {
-      return ((name in config) &&
-               config[name] != null &&
-               (["password", "wep_key0", "psk"].indexOf(name) === -1 ||
-                config[name] !== '*'));
-    }
-
-    function getModeFromConfig() {
-      /* we use the mode from the config, or ESS as default */
-      return hasValidProperty("mode") ? config["mode"] : MODE_ESS;
-    }
-
-    var mode = getModeFromConfig();
-
-    function validForMode(name, mode) {
-            /* all fields are valid for IBSS */
-      return (mode == MODE_IBSS) ||
-            /* IBSS fields are not valid for ESS */
-            ((mode == MODE_ESS) && !(name in ibssNetworkConfigurationFields));
-    }
-
-    for (var n = 0; n < networkConfigurationFields.length; ++n) {
-      let fieldName = networkConfigurationFields[n].name;
-      if (!hasValidProperty(fieldName) || !validForMode(fieldName, mode)) {
-        ++done;
-      } else {
-        wifiCommand.setNetworkVariable(netId, fieldName, config[fieldName], function(ok) {
-          if (!ok)
-            ++errors;
-          if (++done == networkConfigurationFields.length)
-            callback(errors == 0);
-        });
-      }
-    }
-    // If config didn't contain any of the fields we want, don't lose the error callback.
-    if (done == networkConfigurationFields.length)
-      callback(false);
-  }
-  manager.getConfiguredNetworks = function(callback) {
-    wifiCommand.listNetworks(function (reply) {
-      var networks = Object.create(null);
-      var lines = reply ? reply.split("\n") : 0;
-      if (lines.length <= 1) {
-        // We need to make sure we call the callback even if there are no
-        // configured networks.
-        callback(networks);
-        return;
-      }
-
-      var done = 0;
-      var errors = 0;
-      for (var n = 1; n < lines.length; ++n) {
-        var result = lines[n].split("\t");
-        var netId = parseInt(result[0], 10);
-        var config = networks[netId] = { netId: netId };
-        switch (result[3]) {
-        case "[CURRENT]":
-          config.status = "CURRENT";
-          break;
-        case "[DISABLED]":
-          config.status = "DISABLED";
-          break;
-        default:
-          config.status = "ENABLED";
-          break;
-        }
-        manager.getNetworkConfiguration(config, function (ok) {
-            if (!ok)
-              ++errors;
-            if (++done == lines.length - 1) {
-              if (errors) {
-                // If an error occured, delete the new netId.
-                wifiCommand.removeNetwork(netId, function() {
-                  callback(null);
-                });
-              } else {
-                callback(networks);
-              }
-            }
-        });
-      }
-    });
-  }
-  manager.addNetwork = function(config, callback) {
-    wifiCommand.addNetwork(function (netId) {
-      config.netId = netId;
-      manager.setNetworkConfiguration(config, function (ok) {
-        if (!ok) {
-          wifiCommand.removeNetwork(netId, function() { callback(false); });
-          return;
-        }
-
-        callback(ok);
-      });
-    });
-  }
-  manager.updateNetwork = function(config, callback) {
-    manager.setNetworkConfiguration(config, callback);
-  }
-  manager.removeNetwork = function(netId, callback) {
-    wifiCommand.removeNetwork(netId, callback);
-  }
-
-  manager.saveConfig = function(callback) {
-    wifiCommand.saveConfig(callback);
-  }
-  manager.enableNetwork = function(netId, disableOthers, callback) {
-    if (p2pSupported) {
-      // We have to stop wifi direct scan before associating to an AP.
-      // Otherwise we will get a "REJECT" wpa supplicant event.
-      p2pManager.setScanEnabled(false, function(success) {});
-    }
-    wifiCommand.enableNetwork(netId, disableOthers, callback);
-  }
-  manager.disableNetwork = function(netId, callback) {
-    wifiCommand.disableNetwork(netId, callback);
-  }
-  manager.getMacAddress = wifiCommand.getMacAddress;
-  manager.getScanResults = wifiCommand.scanResults;
-  manager.setScanMode = function(mode, callback) {
-    setScanMode(mode === "active", callback); // Use our own version.
-  }
-  manager.setBackgroundScan = setBackgroundScan; // Use our own version.
-  manager.scan = scan; // Use our own version.
-  manager.wpsPbc = wifiCommand.wpsPbc;
-  manager.wpsPin = wifiCommand.wpsPin;
-  manager.wpsCancel = wifiCommand.wpsCancel;
-  manager.setPowerMode = (sdkVersion >= 16)
-                         ? wifiCommand.setPowerModeJB
-                         : wifiCommand.setPowerModeICS;
-  manager.setPowerSavingMode = setPowerSavingMode;
-  manager.getHttpProxyNetwork = getHttpProxyNetwork;
-  manager.setHttpProxy = setHttpProxy;
-  manager.configureHttpProxy = configureHttpProxy;
-  manager.setSuspendOptimizations = (sdkVersion >= 16)
-                                   ? wifiCommand.setSuspendOptimizationsJB
-                                   : wifiCommand.setSuspendOptimizationsICS;
-  manager.setStaticIpMode = setStaticIpMode;
-  manager.getRssiApprox = wifiCommand.getRssiApprox;
-  manager.getLinkSpeed = wifiCommand.getLinkSpeed;
-  manager.getDhcpInfo = function() { return dhcpInfo; }
-  manager.getConnectionInfo = (sdkVersion >= 15)
-                              ? wifiCommand.getConnectionInfoICS
-                              : wifiCommand.getConnectionInfoGB;
-
-  manager.ensureSupplicantDetached = aCallback => {
-    if (!manager.enabled) {
-      aCallback();
-      return;
-    }
-    wifiCommand.closeSupplicantConnection(aCallback);
-  };
-
-  manager.isHandShakeState = function(state) {
-    switch (state) {
-      case "AUTHENTICATING":
-      case "ASSOCIATING":
-      case "ASSOCIATED":
-      case "FOUR_WAY_HANDSHAKE":
-      case "GROUP_HANDSHAKE":
-        return true;
-      case "DORMANT":
-      case "COMPLETED":
-      case "DISCONNECTED":
-      case "INTERFACE_DISABLED":
-      case "INACTIVE":
-      case "SCANNING":
-      case "UNINITIALIZED":
-      case "INVALID":
-      case "CONNECTED":
-      default:
-        return false;
-    }
-  }
-
-  manager.isWifiEnabled = function(state) {
-    switch (state) {
-      case "UNINITIALIZED":
-      case "DISABLING":
-        return false;
-      default:
-        return true;
-    }
-  }
-
-  manager.isWifiTetheringEnabled = function(state) {
-    switch (state) {
-      case "UNINITIALIZED":
-        return false;
-      default:
-        return true;
-    }
-  }
-
-  manager.syncDebug = syncDebug;
-  manager.stateOrdinal = function(state) {
-    return supplicantStatesMap.indexOf(state);
-  }
-  manager.supplicantLoopDetection = function(prevState, state) {
-    var isPrevStateInHandShake = manager.isHandShakeState(prevState);
-    var isStateInHandShake = manager.isHandShakeState(state);
-
-    if (isPrevStateInHandShake) {
-      if (isStateInHandShake) {
-        // Increase the count only if we are in the loop.
-        if (manager.stateOrdinal(state) > manager.stateOrdinal(prevState)) {
-          manager.loopDetectionCount++;
-        }
-        if (manager.loopDetectionCount > MAX_SUPPLICANT_LOOP_ITERATIONS) {
-          notify("disconnected", {connectionInfo: manager.connectionInfo});
-          manager.loopDetectionCount = 0;
-        }
-      }
-    } else {
-      // From others state to HandShake state. Reset the count.
-      if (isStateInHandShake) {
-        manager.loopDetectionCount = 0;
-      }
-    }
-  }
-
-  manager.handlePreWifiScan = function() {
-    if (p2pSupported) {
-      // Before doing regular wifi scan, we have to disable wifi direct
-      // scan first. Otherwise we will never get the scan result.
-      p2pManager.blockScan();
-    }
-  };
-
-  manager.handlePostWifiScan = function() {
-    if (p2pSupported) {
-      // After regular wifi scanning, we should restore the restricted
-      // wifi direct scan.
-      p2pManager.unblockScan();
-    }
-  };
-
-  //
-  // Public APIs for P2P.
-  //
-
-  manager.p2pSupported = function() {
-    return p2pSupported;
-  };
-
-  manager.getP2pManager = function() {
-    return p2pManager;
-  };
-
-  manager.enableP2p = function(callback) {
-    p2pManager.setEnabled(true, {
-      onSupplicantConnected: function() {
-        waitForEvent(WifiP2pManager.INTERFACE_NAME);
-      },
-
-      onEnabled: function(success) {
-        callback(success);
-      }
-    });
-  };
-
-  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);
-  }
-
-  manager.deleteCert = function(caInfo, callback) {
-    var id = idgen++;
-    if (callback) {
-      controlCallbacks[id] = callback;
-    }
-
-    wifiCertService.deleteCert(id, caInfo.certNickname);
-  }
-
-  manager.sdkVersion = function() {
-    return sdkVersion;
-  }
-
-  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 = "",
-      encryption = "OPEN";
-
-  if ("security" in network) {
-    // manager network object, represents an AP
-    // object structure
-    // {
-    //   .ssid           : SSID of AP
-    //   .security[]     : "WPA-PSK" for WPA-PSK
-    //                     "WPA-EAP" for WPA-EAP
-    //                     "WEP" for WEP
-    //                     "" for OPEN
-    //   other keys
-    // }
-
-    var security = network.security;
-    ssid = network.ssid;
-
-    for (let j = 0; j < security.length; j++) {
-      if (security[j] === "WPA-PSK") {
-        encryption = "WPA-PSK";
-        break;
-      } else if (security[j] === "WPA-EAP") {
-        encryption = "WPA-EAP";
-        break;
-      } else if (security[j] === "WEP") {
-        encryption = "WEP";
-        break;
-      }
-    }
-  } else if ("key_mgmt" in network) {
-    // configure network object, represents a network
-    // object structure
-    // {
-    //   .ssid           : SSID of network, quoted
-    //   .key_mgmt       : Encryption type
-    //                     "WPA-PSK" for WPA-PSK
-    //                     "WPA-EAP" for WPA-EAP
-    //                     "NONE" for WEP/OPEN
-    //   .auth_alg       : Encryption algorithm(WEP mode only)
-    //                     "OPEN_SHARED" for WEP
-    //   other keys
-    // }
-    var key_mgmt = network.key_mgmt,
-        auth_alg = network.auth_alg;
-    ssid = dequote(network.ssid);
-
-    if (key_mgmt == "WPA-PSK") {
-      encryption = "WPA-PSK";
-    } else if (key_mgmt.indexOf("WPA-EAP") != -1) {
-      encryption = "WPA-EAP";
-    } else if (key_mgmt == "NONE" && auth_alg === "OPEN SHARED") {
-      encryption = "WEP";
-    }
-  }
-
-  // ssid here must be dequoted, and it's safer to esacpe it.
-  // encryption won't be empty and always be assigned one of the followings :
-  // "OPEN"/"WEP"/"WPA-PSK"/"WPA-EAP".
-  // So for a invalid network object, the returned key will be "OPEN".
-  return escape(ssid) + encryption;
-}
-
-function getMode(flags) {
-  if (/\[IBSS/.test(flags))
-    return MODE_IBSS;
-
-  return MODE_ESS;
-}
-
-function getKeyManagement(flags) {
-  var types = [];
-  if (!flags)
-    return types;
-
-  if (/\[WPA2?-PSK/.test(flags))
-    types.push("WPA-PSK");
-  if (/\[WPA2?-EAP/.test(flags))
-    types.push("WPA-EAP");
-  if (/\[WEP/.test(flags))
-    types.push("WEP");
-  return types;
-}
-
-function getCapabilities(flags) {
-  var types = [];
-  if (!flags)
-    return types;
-
-  if (/\[WPS/.test(flags))
-    types.push("WPS");
-  return types;
-}
-
-// These constants shamelessly ripped from WifiManager.java
-// strength is the value returned by scan_results. It is nominally in dB. We
-// transform it into a percentage for clients looking to simply show a
-// relative indication of the strength of a network.
-const MIN_RSSI = -100;
-const MAX_RSSI = -55;
-
-function calculateSignal(strength) {
-  // Some wifi drivers represent their signal strengths as 8-bit integers, so
-  // in order to avoid negative numbers, they add 256 to the actual values.
-  // While we don't *know* that this is the case here, we make an educated
-  // guess.
-  if (strength > 0)
-    strength -= 256;
-
-  if (strength <= MIN_RSSI)
-    return 0;
-  if (strength >= MAX_RSSI)
-    return 100;
-  return Math.floor(((strength - MIN_RSSI) / (MAX_RSSI - MIN_RSSI)) * 100);
-}
-
-function Network(ssid, mode, frequency, security, password, capabilities) {
-  this.ssid = ssid;
-  this.mode = mode;
-  this.frequency = frequency;
-  this.security = security;
-
-  if (typeof password !== "undefined")
-    this.password = password;
-  if (capabilities !== undefined)
-    this.capabilities = capabilities;
-  // TODO connected here as well?
-
-  this.__exposedProps__ = Network.api;
-}
-
-Network.api = {
-  ssid: "r",
-  mode: "r",
-  frequency: "r",
-  security: "r",
-  capabilities: "r",
-  known: "r",
-
-  password: "rw",
-  keyManagement: "rw",
-  psk: "rw",
-  identity: "rw",
-  wep: "rw",
-  hidden: "rw",
-  eap: "rw",
-  pin: "rw",
-  phase1: "rw",
-  phase2: "rw",
-  serverCertificate: "rw",
-  userCertificate: "rw"
-};
-
-// Note: We never use ScanResult.prototype, so the fact that it's unrelated to
-// Network.prototype is OK.
-function ScanResult(ssid, bssid, frequency, flags, signal) {
-  Network.call(this, ssid, getMode(flags), frequency,
-               getKeyManagement(flags), undefined, getCapabilities(flags));
-  this.bssid = bssid;
-  this.signalStrength = signal;
-  this.relSignalStrength = calculateSignal(Number(signal));
-
-  this.__exposedProps__ = ScanResult.api;
-}
-
-// XXX This should probably live in the DOM-facing side, but it's hard to do
-// there, so we stick this here.
-ScanResult.api = {
-  bssid: "r",
-  signalStrength: "r",
-  relSignalStrength: "r",
-  connected: "r"
-};
-
-for (let i in Network.api) {
-  ScanResult.api[i] = Network.api[i];
-}
-
-function quote(s) {
-  return '"' + s + '"';
-}
-
-function dequote(s) {
-  if (s[0] != '"' || s[s.length - 1] != '"')
-    throw "Invalid argument, not a quoted string: " + s;
-  return s.substr(1, s.length - 2);
-}
-
-function isWepHexKey(s) {
-  if (s.length != 10 && s.length != 26 && s.length != 58)
-    return false;
-  return !/[^a-fA-F0-9]/.test(s);
-}
-
-
-var WifiNetworkInterface = {
-
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInterface]),
-
-  registered: false,
-
-  // nsINetworkInterface
-
-  NETWORK_STATE_UNKNOWN:       Ci.nsINetworkInfo.NETWORK_STATE_UNKNOWN,
-  NETWORK_STATE_CONNECTING:    Ci.nsINetworkInfo.CONNECTING,
-  NETWORK_STATE_CONNECTED:     Ci.nsINetworkInfo.CONNECTED,
-  NETWORK_STATE_DISCONNECTING: Ci.nsINetworkInfo.DISCONNECTING,
-  NETWORK_STATE_DISCONNECTED:  Ci.nsINetworkInfo.DISCONNECTED,
-
-  NETWORK_TYPE_WIFI:        Ci.nsINetworkInfo.NETWORK_TYPE_WIFI,
-  NETWORK_TYPE_MOBILE:      Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE,
-  NETWORK_TYPE_MOBILE_MMS:  Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_MMS,
-  NETWORK_TYPE_MOBILE_SUPL: Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE_SUPL,
-
-  info: {
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsINetworkInfo]),
-
-    state: Ci.nsINetworkInfo.NETWORK_STATE_UNKNOWN,
-
-    type: Ci.nsINetworkInfo.NETWORK_TYPE_WIFI,
-
-    name: null,
-
-    ips: [],
-
-    prefixLengths: [],
-
-    dnses: [],
-
-    gateways: [],
-
-    getAddresses: function (ips, prefixLengths) {
-      ips.value = this.ips.slice();
-      prefixLengths.value = this.prefixLengths.slice();
-
-      return this.ips.length;
-    },
-
-    getGateways: function (count) {
-      if (count) {
-        count.value = this.gateways.length;
-      }
-      return this.gateways.slice();
-    },
-
-    getDnses: function (count) {
-      if (count) {
-        count.value = this.dnses.length;
-      }
-      return this.dnses.slice();
-    }
-  },
-
-  httpProxyHost: null,
-
-  httpProxyPort: null
-};
-
-function WifiScanResult() {}
-
-// TODO Make the difference between a DOM-based network object and our
-// networks objects much clearer.
-var netToDOM;
-var netFromDOM;
-
-function WifiWorker() {
-  var self = this;
-
-  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",
-                    "WifiManager:getImportedCerts",
-                    "WifiManager:deleteCert",
-                    "WifiManager:setWifiEnabled",
-                    "WifiManager:setWifiTethering",
-                    "child-process-shutdown"];
-
-  messages.forEach((function(msgName) {
-    this._mm.addMessageListener(msgName, this);
-  }).bind(this));
-
-  Services.obs.addObserver(this, kMozSettingsChangedObserverTopic, false);
-  Services.obs.addObserver(this, "xpcom-shutdown", false);
-
-  this.wantScanResults = [];
-
-  this._needToEnableNetworks = false;
-  this._highestPriority = -1;
-
-  // Networks is a map from SSID -> a scan result.
-  this.networks = Object.create(null);
-
-  // ConfiguredNetworks is a map from SSID -> our view of a network. It only
-  // lists networks known to the wpa_supplicant. The SSID field (and other
-  // fields) are quoted for ease of use with WifiManager commands.
-  // Note that we don't have to worry about escaping embedded quotes since in
-  // all cases, the supplicant will take the last quotation that we pass it as
-  // the end of the string.
-  this.configuredNetworks = Object.create(null);
-  this._addingNetworks = Object.create(null);
-
-  this.currentNetwork = null;
-  this.ipAddress = "";
-  this.macAddress = null;
-
-  this._lastConnectionInfo = null;
-  this._connectionInfoTimer = null;
-  this._reconnectOnDisconnect = false;
-
-  // Create p2pObserver and assign to p2pManager.
-  if (WifiManager.p2pSupported()) {
-    this._p2pObserver = WifiP2pWorkerObserver(WifiManager.getP2pManager());
-    WifiManager.getP2pManager().setObserver(this._p2pObserver);
-
-    // Add DOM message observerd by p2pObserver to the message listener as well.
-    this._p2pObserver.getObservedDOMMessages().forEach((function(msgName) {
-      this._mm.addMessageListener(msgName, this);
-    }).bind(this));
-  }
-
-  // Users of instances of nsITimer should keep a reference to the timer until
-  // it is no longer needed in order to assure the timer is fired.
-  this._callbackTimer = null;
-
-  // XXX On some phones (Otoro and Unagi) the wifi driver doesn't play nicely
-  // with the automatic scans that wpa_supplicant does (it appears that the
-  // driver forgets that it's returned scan results and then refuses to try to
-  // rescan. In order to detect this case we start a timer when we enter the
-  // SCANNING state and reset it whenever we either get scan results or leave
-  // the SCANNING state. If the timer fires, we assume that we are stuck and
-  // forceably try to unstick the supplican, also turning on background
-  // scanning to avoid having to constantly poke the supplicant.
-
-  // How long we wait is controlled by the SCAN_STUCK_WAIT constant.
-  const SCAN_STUCK_WAIT = 12000;
-  this._scanStuckTimer = null;
-  this._turnOnBackgroundScan = false;
-
-  function startScanStuckTimer() {
-    if (WifiManager.schedScanRecovery) {
-      self._scanStuckTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-      self._scanStuckTimer.initWithCallback(scanIsStuck, SCAN_STUCK_WAIT,
-                                            Ci.nsITimer.TYPE_ONE_SHOT);
-    }
-  }
-
-  function scanIsStuck() {
-    // Uh-oh, we've waited too long for scan results. Disconnect (which
-    // guarantees that we leave the SCANNING state and tells wpa_supplicant to
-    // wait for our next command) ensure that background scanning is on and
-    // then try again.
-    debug("Determined that scanning is stuck, turning on background scanning!");
-    WifiManager.handlePostWifiScan();
-    WifiManager.disconnect(function(ok) {});
-    self._turnOnBackgroundScan = true;
-  }
-
-  // A list of requests to turn wifi on or off.
-  this._stateRequests = [];
-
-  // Given a connection status network, takes a network from
-  // self.configuredNetworks and prepares it for the DOM.
-  netToDOM = function(net) {
-    if (!net) {
-      return null;
-    }
-    var ssid = dequote(net.ssid);
-    var mode = net.mode;
-    var frequency = net.frequency;
-    var security = (net.key_mgmt === "NONE" && net.wep_key0) ? ["WEP"] :
-                   (net.key_mgmt && net.key_mgmt !== "NONE") ? [net.key_mgmt.split(" ")[0]] :
-                   [];
-    var password;
-    if (("psk" in net && net.psk) ||
-        ("password" in net && net.password) ||
-        ("wep_key0" in net && net.wep_key0)) {
-      password = "*";
-    }
-
-    var pub = new Network(ssid, mode, frequency, security, password);
-    if (net.identity)
-      pub.identity = dequote(net.identity);
-    if ("netId" in net)
-      pub.known = true;
-    if (net.scan_ssid === 1)
-      pub.hidden = true;
-    if ("ca_cert" in net && net.ca_cert &&
-        net.ca_cert.indexOf("keystore://WIFI_SERVERCERT_" === 0)) {
-      pub.serverCertificate = net.ca_cert.substr(27);
-    }
-    if(net.subject_match) {
-      pub.subjectMatch = net.subject_match;
-    }
-    if ("client_cert" in net && net.client_cert &&
-        net.client_cert.indexOf("keystore://WIFI_USERCERT_" === 0)) {
-      pub.userCertificate = net.client_cert.substr(25);
-    }
-    return pub;
-  };
-
-  netFromDOM = function(net, configured) {
-    // Takes a network from the DOM and makes it suitable for insertion into
-    // self.configuredNetworks (that is calling addNetwork will do the right
-    // thing).
-    // NB: Modifies net in place: safe since we don't share objects between
-    // the dom and the chrome code.
-
-    // Things that are useful for the UI but not to us.
-    delete net.bssid;
-    delete net.signalStrength;
-    delete net.relSignalStrength;
-    delete net.security;
-    delete net.capabilities;
-
-    if (!configured)
-      configured = {};
-
-    net.ssid = quote(net.ssid);
-
-    let wep = false;
-    if ("keyManagement" in net) {
-      if (net.keyManagement === "WEP") {
-        wep = true;
-        net.keyManagement = "NONE";
-      } else if (net.keyManagement === "WPA-EAP") {
-        net.keyManagement += " IEEE8021X";
-      }
-
-      configured.key_mgmt = net.key_mgmt = net.keyManagement; // WPA2-PSK, WPA-PSK, etc.
-      delete net.keyManagement;
-    } else {
-      configured.key_mgmt = net.key_mgmt = "NONE";
-    }
-
-    if (net.hidden) {
-      configured.scan_ssid = net.scan_ssid = 1;
-      delete net.hidden;
-    }
-
-    function checkAssign(name, checkStar) {
-      if (name in net) {
-        let value = net[name];
-        if (!value || (checkStar && value === '*')) {
-          if (name in configured)
-            net[name] = configured[name];
-          else
-            delete net[name];
-        } else {
-          configured[name] = net[name] = quote(value);
-        }
-      }
-    }
-
-    checkAssign("psk", true);
-    checkAssign("identity", false);
-    checkAssign("password", true);
-    if (wep && net.wep && net.wep != '*') {
-      configured.wep_key0 = net.wep_key0 = isWepHexKey(net.wep) ? net.wep : quote(net.wep);
-      configured.auth_alg = net.auth_alg = "OPEN SHARED";
-    }
-
-    function hasValidProperty(name) {
-      return ((name in net) && net[name] != null);
-    }
-
-    if (hasValidProperty("eap")) {
-      if (hasValidProperty("pin")) {
-        net.pin = quote(net.pin);
-      }
-
-      if (hasValidProperty("phase1"))
-        net.phase1 = quote(net.phase1);
-
-      if (hasValidProperty("phase2")) {
-        if (net.phase2 === "TLS") {
-          net.phase2 = quote("autheap=" + net.phase2);
-        } else { // PAP, MSCHAPV2, etc.
-          net.phase2 = quote("auth=" + net.phase2);
-        }
-      }
-
-      if (hasValidProperty("serverCertificate"))
-        net.ca_cert = quote("keystore://WIFI_SERVERCERT_" + net.serverCertificate);
-
-      if (hasValidProperty("subjectMatch"))
-        net.subject_match = quote(net.subjectMatch);
-
-      if (hasValidProperty("userCertificate")) {
-        let userCertName = "WIFI_USERCERT_" + net.userCertificate;
-        net.client_cert = quote("keystore://" + userCertName);
-
-        let wifiCertService = Cc["@mozilla.org/wifi/certservice;1"].
-                                getService(Ci.nsIWifiCertService);
-        if (wifiCertService.hasPrivateKey(userCertName)) {
-          if (WifiManager.sdkVersion() >= 19) {
-            // Use openssol engine instead of keystore protocol after Kitkat.
-            net.engine = 1;
-            net.engine_id = quote("keystore");
-            net.key_id = quote("WIFI_USERKEY_" + net.userCertificate);
-          } else {
-            net.private_key = quote("keystore://WIFI_USERKEY_" + net.userCertificate);
-          }
-        }
-      }
-    }
-
-    return net;
-  };
-
-  WifiManager.onsupplicantconnection = function() {
-    debug("Connected to supplicant");
-    // Give it a state other than UNINITIALIZED, INITIALIZING or DISABLING
-    // defined in getter function of WifiManager.enabled. It implies that
-    // we are ready to accept dom request from applications.
-    WifiManager.state = "DISCONNECTED";
-    self._reloadConfiguredNetworks(function(ok) {
-      // Prime this.networks.
-      if (!ok)
-        return;
-
-      // The select network command we used in associate() disables others networks.
-      // Enable them here to make sure wpa_supplicant helps to connect to known
-      // network automatically.
-      self._enableAllNetworks();
-      WifiManager.saveConfig(function() {})
-    });
-
-    // Notify everybody, even if they didn't ask us to come up.
-    WifiManager.getMacAddress(function (mac) {
-      self.macAddress = mac;
-      debug("Got mac: " + mac);
-      self._fireEvent("wifiUp", { macAddress: mac });
-      self.requestDone();
-    });
-
-    if (WifiManager.state === "SCANNING")
-      startScanStuckTimer();
-  };
-
-  WifiManager.onsupplicantlost = function() {
-    WifiManager.supplicantStarted = false;
-    WifiManager.state = "UNINITIALIZED";
-    debug("Supplicant died!");
-
-    // Notify everybody, even if they didn't ask us to come up.
-    self._fireEvent("wifiDown", {});
-    self.requestDone();
-  };
-
-  WifiManager.onpasswordmaybeincorrect = function() {
-    WifiManager.authenticationFailuresCount++;
-  };
-
-  WifiManager.ondisconnected = function() {
-    // We may fail to establish the connection, re-enable the
-    // rest of our networks.
-    if (self._needToEnableNetworks) {
-      self._enableAllNetworks();
-      self._needToEnableNetworks = false;
-    }
-
-    let connectionInfo = this.connectionInfo;
-    WifiManager.getNetworkId(connectionInfo.ssid, function(netId) {
-      // Trying to get netId from current network.
-      if (!netId &&
-          self.currentNetwork && self.currentNetwork.ssid &&
-          dequote(self.currentNetwork.ssid) == connectionInfo.ssid &&
-          typeof self.currentNetwork.netId !== "undefined") {
-        netId = self.currentNetwork.netId;
-      }
-      if (netId) {
-        WifiManager.disableNetwork(netId, function() {});
-      }
-    });
-    self._fireEvent("onconnectingfailed", {network: netToDOM(self.currentNetwork)});
-  }
-
-  WifiManager.onstatechange = function() {
-    debug("State change: " + this.prevState + " -> " + this.state);
-
-    if (self._connectionInfoTimer &&
-        this.state !== "CONNECTED" &&
-        this.state !== "COMPLETED") {
-      self._stopConnectionInfoTimer();
-    }
-
-    if (this.state !== "SCANNING" &&
-        self._scanStuckTimer) {
-      self._scanStuckTimer.cancel();
-      self._scanStuckTimer = null;
-    }
-
-    switch (this.state) {
-      case "DORMANT":
-        // The dormant state is a bad state to be in since we won't
-        // automatically connect. Try to knock us out of it. We only
-        // hit this state when we've failed to run DHCP, so trying
-        // again isn't the worst thing we can do. Eventually, we'll
-        // need to detect if we're looping in this state and bail out.
-        WifiManager.reconnect(function(){});
-        break;
-      case "ASSOCIATING":
-        // id has not yet been filled in, so we can only report the ssid and
-        // bssid. mode and frequency are simply made up.
-        self.currentNetwork =
-          { bssid: WifiManager.connectionInfo.bssid,
-            ssid: quote(WifiManager.connectionInfo.ssid),
-            mode: MODE_ESS,
-            frequency: 0};
-        WifiManager.getNetworkConfiguration(self.currentNetwork, function (){
-          // Notify again because we get complete network information.
-          self._fireEvent("onconnecting", { network: netToDOM(self.currentNetwork) });
-        });
-        break;
-      case "ASSOCIATED":
-        // set to full power mode when ready to do 4 way handsharke.
-        WifiManager.setPowerSavingMode(false);
-        if (!self.currentNetwork) {
-          self.currentNetwork =
-            { bssid: WifiManager.connectionInfo.bssid,
-              ssid: quote(WifiManager.connectionInfo.ssid) };
-        }
-        self.currentNetwork.netId = this.id;
-        WifiManager.getNetworkConfiguration(self.currentNetwork, function (){
-          // Notify again because we get complete network information.
-          self._fireEvent("onconnecting", { network: netToDOM(self.currentNetwork) });
-        });
-        break;
-      case "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
-        // select a better network!
-        if (self._needToEnableNetworks) {
-          self._enableAllNetworks();
-          self._needToEnableNetworks = false;
-        }
-
-        var _oncompleted = function() {
-          // The full authentication process is completed, reset the count.
-          WifiManager.authenticationFailuresCount = 0;
-          WifiManager.loopDetectionCount = 0;
-          self._startConnectionInfoTimer();
-          self._fireEvent("onassociate", { network: netToDOM(self.currentNetwork) });
-        };
-
-        // We get the ASSOCIATED event when we've associated but not connected, so
-        // wait until the handshake is complete.
-        if (this.fromStatus || !self.currentNetwork) {
-          // In this case, we connected to an already-connected wpa_supplicant,
-          // because of that we need to gather information about the current
-          // network here.
-          self.currentNetwork = { bssid: WifiManager.connectionInfo.bssid,
-                                  ssid: quote(WifiManager.connectionInfo.ssid),
-                                  netId: WifiManager.connectionInfo.id };
-          WifiManager.getNetworkConfiguration(self.currentNetwork, _oncompleted);
-        } else {
-          _oncompleted();
-        }
-        break;
-      case "CONNECTED":
-        // wifi connection complete, turn on the power saving mode.
-        WifiManager.setPowerSavingMode(true);
-        // BSSID is read after connected, update it.
-        self.currentNetwork.bssid = WifiManager.connectionInfo.bssid;
-        break;
-      case "DISCONNECTED":
-        // wpa_supplicant may give us a "DISCONNECTED" event even if
-        // we are already in "DISCONNECTED" state.
-        if ((WifiNetworkInterface.info.state ===
-             Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTED) &&
-             (this.prevState === "INITIALIZING" ||
-              this.prevState === "DISCONNECTED" ||
-              this.prevState === "INTERFACE_DISABLED" ||
-              this.prevState === "INACTIVE" ||
-              this.prevState === "UNINITIALIZED")) {
-          // When in disconnected mode, need to turn on wifi power saving mode.
-          WifiManager.setPowerSavingMode(true);
-          return;
-        }
-
-        self._fireEvent("ondisconnect", {network: netToDOM(self.currentNetwork)});
-
-        self.currentNetwork = null;
-        self.ipAddress = "";
-
-        if (self._turnOnBackgroundScan) {
-          self._turnOnBackgroundScan = false;
-          WifiManager.setBackgroundScan("ON", function(did_something, ok) {
-            WifiManager.reassociate(function() {});
-          });
-        }
-
-        WifiManager.connectionDropped(function() {
-          // We've disconnected from a network because of a call to forgetNetwork.
-          // Reconnect to the next available network (if any).
-          if (self._reconnectOnDisconnect) {
-            self._reconnectOnDisconnect = false;
-            WifiManager.reconnect(function(){});
-          }
-        });
-
-        WifiNetworkInterface.info.state =
-          Ci.nsINetworkInfo.NETWORK_STATE_DISCONNECTED;
-
-        // Update network infterface first then clear properties.
-        gNetworkManager.updateNetworkInterface(WifiNetworkInterface);
-        WifiNetworkInterface.info.ips = [];
-        WifiNetworkInterface.info.prefixLengths = [];
-        WifiNetworkInterface.info.gateways = [];
-        WifiNetworkInterface.info.dnses = [];
-
-
-        break;
-      case "WPS_TIMEOUT":
-        self._fireEvent("onwpstimeout", {});
-        break;
-      case "WPS_FAIL":
-        self._fireEvent("onwpsfail", {});
-        break;
-      case "WPS_OVERLAP_DETECTED":
-        self._fireEvent("onwpsoverlap", {});
-        break;
-      case "AUTHENTICATING":
-        self._fireEvent("onauthenticating", {network: netToDOM(self.currentNetwork)});
-        break;
-      case "SCANNING":
-        // If we're already scanning in the background, we don't need to worry
-        // about getting stuck while scanning.
-        if (!WifiManager.backgroundScanEnabled && WifiManager.enabled)
-          startScanStuckTimer();
-        break;
-    }
-  };
-
-  WifiManager.onnetworkconnected = function() {
-    if (!this.info || !this.info.ipaddr_str) {
-      debug("Network information is invalid.");
-      return;
-    }
-
-    let maskLength =
-      netHelpers.getMaskLength(netHelpers.stringToIP(this.info.mask_str));
-    if (!maskLength) {
-      maskLength = 32; // max prefix for IPv4.
-    }
-
-    let netConnect = WifiManager.getHttpProxyNetwork(self.currentNetwork);
-    if (netConnect) {
-      WifiNetworkInterface.httpProxyHost = netConnect.httpProxyHost;
-      WifiNetworkInterface.httpProxyPort = netConnect.httpProxyPort;
-    }
-
-    WifiNetworkInterface.info.state =
-      Ci.nsINetworkInfo.NETWORK_STATE_CONNECTED;
-    WifiNetworkInterface.info.ips = [this.info.ipaddr_str];
-    WifiNetworkInterface.info.prefixLengths = [maskLength];
-    WifiNetworkInterface.info.gateways = [this.info.gateway_str];
-    if (typeof this.info.dns1_str == "string" &&
-        this.info.dns1_str.length) {
-      WifiNetworkInterface.info.dnses.push(this.info.dns1_str);
-    }
-    if (typeof this.info.dns2_str == "string" &&
-        this.info.dns2_str.length) {
-      WifiNetworkInterface.info.dnses.push(this.info.dns2_str);
-    }
-    gNetworkManager.updateNetworkInterface(WifiNetworkInterface);
-
-    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) });
-  };
-
-  WifiManager.onscanresultsavailable = function() {
-    if (self._scanStuckTimer) {
-      // We got scan results! We must not be stuck for now, try again.
-      self._scanStuckTimer.cancel();
-      self._scanStuckTimer.initWithCallback(scanIsStuck, SCAN_STUCK_WAIT,
-                                            Ci.nsITimer.TYPE_ONE_SHOT);
-    }
-
-    if (self.wantScanResults.length === 0) {
-      debug("Scan results available, but we don't need them");
-      return;
-    }
-
-    debug("Scan results are available! Asking for them.");
-    WifiManager.getScanResults(function(r) {
-      // Failure.
-      if (!r) {
-        self.wantScanResults.forEach(function(callback) { callback(null) });
-        self.wantScanResults = [];
-        return;
-      }
-
-      let capabilities = WifiManager.getCapabilities();
-
-      // Now that we have scan results, there's no more need to continue
-      // scanning. Ignore any errors from this command.
-      WifiManager.setScanMode("inactive", function() {});
-      let lines = r.split("\n");
-      // NB: Skip the header line.
-      self.networksArray = [];
-      for (let i = 1; i < lines.length; ++i) {
-        // bssid / frequency / signal level / flags / ssid
-        var match = /([\S]+)\s+([\S]+)\s+([\S]+)\s+(\[[\S]+\])?\s(.*)/.exec(lines[i]);
-
-        if (match && match[5]) {
-          let ssid = match[5],
-              bssid = match[1],
-              frequency = match[2],
-              signalLevel = match[3],
-              flags = match[4];
-
-          /* Skip networks with unknown or unsupported modes. */
-          if (capabilities.mode.indexOf(getMode(flags)) == -1)
-            continue;
-
-          // If this is the first time that we've seen this SSID in the scan
-          // results, add it to the list along with any other information.
-          // Also, we use the highest signal strength that we see.
-          let network = new ScanResult(ssid, bssid, frequency, flags, signalLevel);
-
-          let networkKey = getNetworkKey(network);
-          let eapIndex = -1;
-          if (networkKey in self.configuredNetworks) {
-            let known = self.configuredNetworks[networkKey];
-            network.known = true;
-
-            if ("identity" in known && known.identity)
-              network.identity = dequote(known.identity);
-
-            // Note: we don't hand out passwords here! The * marks that there
-            // is a password that we're hiding.
-            if (("psk" in known && known.psk) ||
-                ("password" in known && known.password) ||
-                ("wep_key0" in known && known.wep_key0)) {
-              network.password = "*";
-            }
-          }
-
-          self.networksArray.push(network);
-          if (network.bssid === WifiManager.connectionInfo.bssid)
-            network.connected = true;
-
-          let signal = calculateSignal(Number(match[3]));
-          if (signal > network.relSignalStrength)
-            network.relSignalStrength = signal;
-        } else if (!match) {
-          debug("Match didn't find anything for: " + lines[i]);
-        }
-      }
-
-      self.wantScanResults.forEach(function(callback) { callback(self.networksArray) });
-      self.wantScanResults = [];
-    });
-  };
-
-  WifiManager.onstationinfoupdate = function() {
-    self._fireEvent("stationinfoupdate", { station: this.station });
-  };
-
-  WifiManager.onstopconnectioninfotimer = function() {
-    self._stopConnectionInfoTimer();
-  };
-
-  // Read the 'wifi.enabled' setting in order to start with a known
-  // value at boot time. The handle() will be called after reading.
-  //
-  // nsISettingsServiceCallback implementation.
-  var initWifiEnabledCb = {
-    handle: function handle(aName, aResult) {
-      if (aName !== SETTINGS_WIFI_ENABLED)
-        return;
-      if (aResult === null)
-        aResult = true;
-      self.handleWifiEnabled(aResult);
-    },
-    handleError: function handleError(aErrorMessage) {
-      debug("Error reading the 'wifi.enabled' setting. Default to wifi on.");
-      self.handleWifiEnabled(true);
-    }
-  };
-
-  var initWifiDebuggingEnabledCb = {
-    handle: function handle(aName, aResult) {
-      if (aName !== SETTINGS_WIFI_DEBUG_ENABLED)
-        return;
-      if (aResult === null)
-        aResult = false;
-      DEBUG = aResult;
-      updateDebug();
-    },
-    handleError: function handleError(aErrorMessage) {
-      debug("Error reading the 'wifi.debugging.enabled' setting. Default to debugging off.");
-      DEBUG = false;
-      updateDebug();
-    }
-  };
-
-  this.initTetheringSettings();
-
-  let lock = gSettingsService.createLock();
-  lock.get(SETTINGS_WIFI_ENABLED, initWifiEnabledCb);
-  lock.get(SETTINGS_WIFI_DEBUG_ENABLED, initWifiDebuggingEnabledCb);
-
-  lock.get(SETTINGS_WIFI_SSID, this);
-  lock.get(SETTINGS_WIFI_SECURITY_TYPE, this);
-  lock.get(SETTINGS_WIFI_SECURITY_PASSWORD, this);
-  lock.get(SETTINGS_WIFI_IP, this);
-  lock.get(SETTINGS_WIFI_PREFIX, this);
-  lock.get(SETTINGS_WIFI_DHCPSERVER_STARTIP, this);
-  lock.get(SETTINGS_WIFI_DHCPSERVER_ENDIP, this);
-  lock.get(SETTINGS_WIFI_DNS1, this);
-  lock.get(SETTINGS_WIFI_DNS2, this);
-  lock.get(SETTINGS_WIFI_TETHERING_ENABLED, this);
-
-  lock.get(SETTINGS_USB_DHCPSERVER_STARTIP, this);
-  lock.get(SETTINGS_USB_DHCPSERVER_ENDIP, this);
-
-  this._wifiTetheringSettingsToRead = [SETTINGS_WIFI_SSID,
-                                       SETTINGS_WIFI_SECURITY_TYPE,
-                                       SETTINGS_WIFI_SECURITY_PASSWORD,
-                                       SETTINGS_WIFI_IP,
-                                       SETTINGS_WIFI_PREFIX,
-                                       SETTINGS_WIFI_DHCPSERVER_STARTIP,
-                                       SETTINGS_WIFI_DHCPSERVER_ENDIP,
-                                       SETTINGS_WIFI_DNS1,
-                                       SETTINGS_WIFI_DNS2,
-                                       SETTINGS_WIFI_TETHERING_ENABLED,
-                                       SETTINGS_USB_DHCPSERVER_STARTIP,
-                                       SETTINGS_USB_DHCPSERVER_ENDIP];
-}
-
-function translateState(state) {
-  switch (state) {
-    case "INTERFACE_DISABLED":
-    case "INACTIVE":
-    case "SCANNING":
-    case "DISCONNECTED":
-    default:
-      return "disconnected";
-
-    case "AUTHENTICATING":
-    case "ASSOCIATING":
-    case "ASSOCIATED":
-    case "FOUR_WAY_HANDSHAKE":
-    case "GROUP_HANDSHAKE":
-      return "connecting";
-
-    case "COMPLETED":
-      return WifiManager.getDhcpInfo() ? "connected" : "associated";
-  }
-}
-
-WifiWorker.prototype = {
-  classID:   WIFIWORKER_CID,
-  classInfo: XPCOMUtils.generateCI({classID: WIFIWORKER_CID,
-                                    contractID: WIFIWORKER_CONTRACTID,
-                                    classDescription: "WifiWorker",
-                                    interfaces: [Ci.nsIWorkerHolder,
-                                                 Ci.nsIWifi,
-                                                 Ci.nsIObserver]}),
-
-  QueryInterface: XPCOMUtils.generateQI([Ci.nsIWorkerHolder,
-                                         Ci.nsIWifi,
-                                         Ci.nsIObserver,
-                                         Ci.nsISettingsServiceCallback]),
-
-  disconnectedByWifi: false,
-
-  disconnectedByWifiTethering: false,
-
-  _wifiTetheringSettingsToRead: [],
-
-  _oldWifiTetheringEnabledState: null,
-
-  tetheringSettings: {},
-
-  initTetheringSettings: function initTetheringSettings() {
-    this.tetheringSettings[SETTINGS_WIFI_TETHERING_ENABLED] = null;
-    this.tetheringSettings[SETTINGS_WIFI_SSID] = DEFAULT_WIFI_SSID;
-    this.tetheringSettings[SETTINGS_WIFI_SECURITY_TYPE] = DEFAULT_WIFI_SECURITY_TYPE;
-    this.tetheringSettings[SETTINGS_WIFI_SECURITY_PASSWORD] = DEFAULT_WIFI_SECURITY_PASSWORD;
-    this.tetheringSettings[SETTINGS_WIFI_IP] = DEFAULT_WIFI_IP;
-    this.tetheringSettings[SETTINGS_WIFI_PREFIX] = DEFAULT_WIFI_PREFIX;
-    this.tetheringSettings[SETTINGS_WIFI_DHCPSERVER_STARTIP] = DEFAULT_WIFI_DHCPSERVER_STARTIP;
-    this.tetheringSettings[SETTINGS_WIFI_DHCPSERVER_ENDIP] = DEFAULT_WIFI_DHCPSERVER_ENDIP;
-    this.tetheringSettings[SETTINGS_WIFI_DNS1] = DEFAULT_DNS1;
-    this.tetheringSettings[SETTINGS_WIFI_DNS2] = DEFAULT_DNS2;
-
-    this.tetheringSettings[SETTINGS_USB_DHCPSERVER_STARTIP] = DEFAULT_USB_DHCPSERVER_STARTIP;
-    this.tetheringSettings[SETTINGS_USB_DHCPSERVER_ENDIP] = DEFAULT_USB_DHCPSERVER_ENDIP;
-  },
-
-  // Internal methods.
-  waitForScan: function(callback) {
-    this.wantScanResults.push(callback);
-  },
-
-  // In order to select a specific network, we disable the rest of the
-  // networks known to us. However, in general, we want the supplicant to
-  // connect to which ever network it thinks is best, so when we select the
-  // proper network (or fail to), we need to re-enable the rest.
-  _enableAllNetworks: function() {
-    for (let key in this.configuredNetworks) {
-      let net = this.configuredNetworks[key];
-      WifiManager.enableNetwork(net.netId, false, function(ok) {
-        net.disabled = ok ? 1 : 0;
-      });
-    }
-  },
-
-  _startConnectionInfoTimer: function() {
-    if (this._connectionInfoTimer)
-      return;
-
-    var self = this;
-    function getConnectionInformation() {
-      WifiManager.getConnectionInfo(function(connInfo) {
-        // See comments in calculateSignal for information about this.
-        if (!connInfo) {
-          self._lastConnectionInfo = null;
-          return;
-        }
-
-        let { rssi, linkspeed } = connInfo;
-        if (rssi > 0)
-          rssi -= 256;
-        if (rssi <= MIN_RSSI)
-          rssi = MIN_RSSI;
-        else if (rssi >= MAX_RSSI)
-          rssi = MAX_RSSI;
-
-        let info = { signalStrength: rssi,
-                     relSignalStrength: calculateSignal(rssi),
-                     linkSpeed: linkspeed,
-                     ipAddress: self.ipAddress };
-        let last = self._lastConnectionInfo;
-
-        // Only fire the event if the link speed changed or the signal
-        // strength changed by more than 10%.
-        function tensPlace(percent) {
-          return (percent / 10) | 0;
-        }
-
-        if (last && last.linkSpeed === info.linkSpeed &&
-            last.ipAddress === info.ipAddress &&
-            tensPlace(last.relSignalStrength) === tensPlace(info.relSignalStrength)) {
-          return;
-        }
-
-        self._lastConnectionInfo = info;
-        debug("Firing connectioninfoupdate: " + uneval(info));
-        self._fireEvent("connectioninfoupdate", info);
-      });
-    }
-
-    // Prime our _lastConnectionInfo immediately and fire the event at the
-    // same time.
-    getConnectionInformation();
-
-    // Now, set up the timer for regular updates.
-    this._connectionInfoTimer =
-      Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    this._connectionInfoTimer.init(getConnectionInformation, 5000,
-                                   Ci.nsITimer.TYPE_REPEATING_SLACK);
-  },
-
-  _stopConnectionInfoTimer: function() {
-    if (!this._connectionInfoTimer)
-      return;
-
-    this._connectionInfoTimer.cancel();
-    this._connectionInfoTimer = null;
-    this._lastConnectionInfo = null;
-  },
-
-  _reloadConfiguredNetworks: function(callback) {
-    WifiManager.getConfiguredNetworks((function(networks) {
-      if (!networks) {
-        debug("Unable to get configured networks");
-        callback(false);
-        return;
-      }
-
-      this._highestPriority = -1;
-
-      // Convert between netId-based and ssid-based indexing.
-      for (let net in networks) {
-        let network = networks[net];
-        delete networks[net];
-
-        if (!network.ssid) {
-          WifiManager.removeNetwork(network.netId, function() {});
-          continue;
-        }
-
-        if (network.hasOwnProperty("priority") &&
-            network.priority > this._highestPriority) {
-          this._highestPriority = network.priority;
-        }
-
-        let networkKey = getNetworkKey(network);
-        // Accept latest config of same network(same SSID and same security).
-        if (networks[networkKey]) {
-          WifiManager.removeNetwork(networks[networkKey].netId, function() {});
-        }
-        networks[networkKey] = network;
-      }
-
-      this.configuredNetworks = networks;
-      callback(true);
-    }).bind(this));
-  },
-
-  // Important side effect: calls WifiManager.saveConfig.
-  _reprioritizeNetworks: function(callback) {
-    // First, sort the networks in orer of their priority.
-    var ordered = Object.getOwnPropertyNames(this.configuredNetworks);
-    let self = this;
-    ordered.sort(function(a, b) {
-      var neta = self.configuredNetworks[a],
-          netb = self.configuredNetworks[b];
-
-      // Sort unsorted networks to the end of the list.
-      if (isNaN(neta.priority))
-        return isNaN(netb.priority) ? 0 : 1;
-      if (isNaN(netb.priority))
-        return -1;
-      return netb.priority - neta.priority;
-    });
-
-    // Skip unsorted networks.
-    let newPriority = 0, i;
-    for (i = ordered.length - 1; i >= 0; --i) {
-      if (!isNaN(this.configuredNetworks[ordered[i]].priority))
-        break;
-    }
-
-    // No networks we care about?
-    if (i < 0) {
-      WifiManager.saveConfig(callback);
-      return;
-    }
-
-    // Now assign priorities from 0 to length, starting with the smallest
-    // priority and heading towards the highest (note the dependency between
-    // total and i here).
-    let done = 0, errors = 0, total = i + 1;
-    for (; i >= 0; --i) {
-      let network = this.configuredNetworks[ordered[i]];
-      network.priority = newPriority++;
-
-      // Note: networkUpdated declared below since it happens logically after
-      // this loop.
-      WifiManager.updateNetwork(network, networkUpdated);
-    }
-
-    function networkUpdated(ok) {
-      if (!ok)
-        ++errors;
-      if (++done === total) {
-        if (errors > 0) {
-          callback(false);
-          return;
-        }
-
-        WifiManager.saveConfig(function(ok) {
-          if (!ok) {
-            callback(false);
-            return;
-          }
-
-          self._reloadConfiguredNetworks(function(ok) {
-            callback(ok);
-          });
-        });
-      }
-    }
-  },
-
-  // nsIWifi
-
-  _domManagers: [],
-  _fireEvent: function(message, data) {
-    this._domManagers.forEach(function(manager) {
-      // Note: We should never have a dead message manager here because we
-      // observe our child message managers shutting down, below.
-      manager.sendAsyncMessage("WifiManager:" + message, data);
-    });
-  },
-
-  _sendMessage: function(message, success, data, msg) {
-    try {
-      msg.manager.sendAsyncMessage(message + (success ? ":OK" : ":NO"),
-                                   { data: data, rid: msg.rid, mid: msg.mid });
-    } catch (e) {
-      debug("sendAsyncMessage error : " + e);
-    }
-    this._splicePendingRequest(msg);
-  },
-
-  _domRequest: [],
-
-  _splicePendingRequest: function(msg) {
-    for (let i = 0; i < this._domRequest.length; i++) {
-      if (this._domRequest[i].msg === msg) {
-        this._domRequest.splice(i, 1);
-        return;
-      }
-    }
-  },
-
-  _clearPendingRequest: function() {
-    if (this._domRequest.length === 0) return;
-    this._domRequest.forEach((function(req) {
-      this._sendMessage(req.name + ":Return", false, "Wifi is disabled", req.msg);
-    }).bind(this));
-  },
-
-  receiveMessage: function MessageManager_receiveMessage(aMessage) {
-    let msg = aMessage.data || {};
-    msg.manager = aMessage.target;
-
-    if (WifiManager.p2pSupported()) {
-      // If p2pObserver returns something truthy, return it!
-      // Otherwise, continue to do the rest of tasks.
-      var p2pRet = this._p2pObserver.onDOMMessage(aMessage);
-      if (p2pRet) {
-        return p2pRet;
-      }
-    }
-
-    // Note: By the time we receive child-process-shutdown, the child process
-    // has already forgotten its permissions so we do this before the
-    // permissions check.
-    if (aMessage.name === "child-process-shutdown") {
-      let i;
-      if ((i = this._domManagers.indexOf(msg.manager)) != -1) {
-        this._domManagers.splice(i, 1);
-      }
-      for (i = this._domRequest.length - 1; i >= 0; i--) {
-        if (this._domRequest[i].msg.manager === msg.manager) {
-          this._domRequest.splice(i, 1);
-        }
-      }
-      return;
-    }
-
-    if (!aMessage.target.assertPermission("wifi-manage")) {
-      return;
-    }
-
-    // We are interested in DOMRequests only.
-    if (aMessage.name != "WifiManager:getState") {
-      this._domRequest.push({name: aMessage.name, msg:msg});
-    }
-
-    switch (aMessage.name) {
-      case "WifiManager:setWifiEnabled":
-        this.setWifiEnabled(msg);
-        break;
-      case "WifiManager:getNetworks":
-        this.getNetworks(msg);
-        break;
-      case "WifiManager:getKnownNetworks":
-        this.getKnownNetworks(msg);
-        break;
-      case "WifiManager:associate":
-        this.associate(msg);
-        break;
-      case "WifiManager:forget":
-        this.forget(msg);
-        break;
-      case "WifiManager:wps":
-        this.wps(msg);
-        break;
-      case "WifiManager:setPowerSavingMode":
-        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:getImportedCerts":
-        this.getImportedCerts(msg);
-        break;
-      case "WifiManager:deleteCert":
-        this.deleteCert(msg);
-        break;
-      case "WifiManager:setWifiTethering":
-        this.setWifiTethering(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,
-                 connectionInfo: this._lastConnectionInfo,
-                 enabled: WifiManager.enable