Bug 1157400 - Port Chromium WinXP wifi scanner to gecko. r=mcmanus
authorGarvan Keeley <gkeeley@mozilla.com>
Wed, 03 Jun 2015 08:26:47 -0400
changeset 246992 faacf69f83adec2f2c0bbaf49a548b6e65db1ae9
parent 246991 74e541ff80e178e3c6e6da1118fd2744206e8741
child 246993 ceac60b1409eabfb797723a614517acab66ae90c
push id28848
push userryanvm@gmail.com
push dateWed, 03 Jun 2015 20:00:13 +0000
treeherdermozilla-central@0920f2325a6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1157400
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1157400 - Port Chromium WinXP wifi scanner to gecko. r=mcmanus
netwerk/wifi/moz.build
netwerk/wifi/nsWifiMonitor.h
netwerk/wifi/nsWifiScannerWin.cpp
netwerk/wifi/win_wifiScanner.h
--- a/netwerk/wifi/moz.build
+++ b/netwerk/wifi/moz.build
@@ -39,16 +39,17 @@ elif CONFIG['OS_ARCH'] in ('DragonFly', 
     UNIFIED_SOURCES += [
         'nsWifiScannerFreeBSD.cpp',
     ]
 elif CONFIG['OS_ARCH'] == 'WINNT':
     UNIFIED_SOURCES += [
         'nsWifiScannerWin.cpp',
         'win_wifiScanner.cpp',
         'win_wlanLibrary.cpp',
+        'win_xp_wifiScanner.cpp'
     ]
 elif CONFIG['OS_ARCH'] == 'SunOS':
     CXXFLAGS += CONFIG['GLIB_CFLAGS']
     UNIFIED_SOURCES += [
         'nsWifiScannerSolaris.cpp',
     ]
 
 if CONFIG['NECKO_WIFI_DBUS']:
--- a/netwerk/wifi/nsWifiMonitor.h
+++ b/netwerk/wifi/nsWifiMonitor.h
@@ -71,17 +71,17 @@ class nsWifiMonitor final : nsIRunnable,
   mozilla::Atomic<bool> mThreadComplete;
   nsCOMPtr<nsIThread> mThread;
 
   nsTArray<nsWifiListener> mListeners;
 
   mozilla::ReentrantMonitor mReentrantMonitor;
 
 #ifdef XP_WIN
-  nsAutoPtr<WinWifiScanner> mWinWifiScanner;
+  nsAutoPtr<WindowsWifiScannerInterface> mWinWifiScanner;
 #endif
 };
 #else
 #include "nsIWifi.h"
 class nsWifiMonitor final : nsIWifiMonitor, nsIWifiScanResultsReady, nsIObserver
 {
  public:
   NS_DECL_ISUPPORTS
--- a/netwerk/wifi/nsWifiScannerWin.cpp
+++ b/netwerk/wifi/nsWifiScannerWin.cpp
@@ -7,16 +7,18 @@
 // moz headers (alphabetical)
 #include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIMutableArray.h"
 #include "nsServiceManagerUtils.h"
 #include "nsWifiAccessPoint.h"
 #include "win_wifiScanner.h"
+#include "win_xp_wifiScanner.h"
+#include "mozilla/WindowsVersion.h"
 
 using namespace mozilla;
 
 /**
  * `nsWifiMonitor` is declared in the cross-platform nsWifiMonitor.h and
  * is mostly defined in the cross-platform nsWifiMonitor.cpp. This function
  * is implemented in various platform-specific files but the implementation
  * is almost identical in each file. We relegate the Windows-specific
@@ -24,17 +26,24 @@ using namespace mozilla;
  * issues like calling listeners here. Hopefully this file can be merged
  * with the other implementations of `nsWifiMonitor::DoScan` since a lot
  * of the code is identical
  */
 nsresult
 nsWifiMonitor::DoScan()
 {
     if (!mWinWifiScanner) {
-      mWinWifiScanner = new WinWifiScanner();
+      if (IsWin2003OrLater()) {
+        mWinWifiScanner = new WinWifiScanner();
+        LOG(("Using Windows 2003+ wifi scanner."));
+      } else {
+        mWinWifiScanner = new WinXPWifiScanner();
+        LOG(("Using Windows XP wifi scanner."));
+      }
+
       if (!mWinWifiScanner) {
         // TODO: Probably return OOM error
         return NS_ERROR_FAILURE;
       }
     }
 
     // Regularly get the access point data.
 
--- a/netwerk/wifi/win_wifiScanner.h
+++ b/netwerk/wifi/win_wifiScanner.h
@@ -6,20 +6,27 @@
 
 // Moz headers (alphabetical)
 #include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "win_wlanLibrary.h"
 
 class nsWifiAccessPoint;
 
-class WinWifiScanner {
+// This class allows the wifi monitor to use WinWifiScanner and WinXPWifiScanner interchangeably.
+class WindowsWifiScannerInterface {
+public:
+  virtual nsresult GetAccessPointsFromWLAN(nsCOMArray<nsWifiAccessPoint> &accessPoints) = 0;
+};
+
+
+class WinWifiScanner : public WindowsWifiScannerInterface {
  public:
   WinWifiScanner();
-  ~WinWifiScanner();
+  virtual ~WinWifiScanner();
 
   /**
    * GetAccessPointsFromWLAN
    *
    * Scans the available wireless interfaces for nearby access points and
    * populates the supplied collection with them
    *
    * @param accessPoints The collection to populate with available APs