Bug 1354721 - Add to XPIDL nsIGeo.Prov.: debugLogger() and draft
authorGarvan Keeley <garvankeeley@gmail.com>
Tue, 11 Apr 2017 12:23:27 -0400
changeset 560582 28cff1d72c4ac6c761c8559c7b2106e0b19a51bd
parent 560580 e6bc8d02d2c79e66b1b5502364dc2551e69c71c5
child 560583 a7d652fb42ad8b299141fefd89347aa1d03c5287
push id53462
push userbmo:gkeeley@mozilla.com
push dateTue, 11 Apr 2017 16:32:16 +0000
bugs1354721
milestone55.0a1
Bug 1354721 - Add to XPIDL nsIGeo.Prov.: debugLogger() and enableLoggingToListener() functions. Only have meaningful logging data so far reported for network geo provider. The rest of the providers have empty implemention of debugLogger(). MozReview-Commit-ID: 3CliBJNQSjo
dom/geolocation/nsGeolocation.cpp
dom/system/NetworkGeolocationProvider.js
dom/system/mac/CoreLocationLocationProvider.mm
xpcom/system/nsIGeolocationProvider.idl
--- a/dom/geolocation/nsGeolocation.cpp
+++ b/dom/geolocation/nsGeolocation.cpp
@@ -314,16 +314,17 @@ nsGeolocationRequest::nsGeolocationReque
   }
 }
 
 nsGeolocationRequest::~nsGeolocationRequest()
 {
   StopTimeoutTimer();
 }
 
+
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGeolocationRequest)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentPermissionRequest)
   NS_INTERFACE_MAP_ENTRY(nsIContentPermissionRequest)
   NS_INTERFACE_MAP_ENTRY(nsIGeolocationUpdate)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGeolocationRequest)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsGeolocationRequest)
@@ -610,16 +611,22 @@ NS_IMETHODIMP
 nsGeolocationRequest::NotifyError(uint16_t aErrorCode)
 {
   MOZ_ASSERT(NS_IsMainThread());
   RefPtr<PositionError> positionError = new PositionError(mLocator, aErrorCode);
   positionError->NotifyCallback(mErrorCallback);
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsGeolocationRequest::DebugLogger(char const*)
+{
+  return NS_OK;
+}
+
 void
 nsGeolocationRequest::Shutdown()
 {
   MOZ_ASSERT(!mShutdown, "request shutdown twice");
   mShutdown = true;
 
   StopTimeoutTimer();
 
@@ -804,16 +811,22 @@ nsGeolocationService::SetCachedPosition(
 }
 
 CachedPositionAndAccuracy
 nsGeolocationService::GetCachedPosition()
 {
   return mLastPosition;
 }
 
+NS_IMETHODIMP
+nsGeolocationService::DebugLogger(char const*)
+{
+  return NS_OK;
+}
+
 nsresult
 nsGeolocationService::StartDevice(nsIPrincipal *aPrincipal)
 {
   if (!sGeoEnabled) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   // We do not want to keep the geolocation devices online
@@ -991,16 +1004,22 @@ Geolocation::Geolocation()
 
 Geolocation::~Geolocation()
 {
   if (mService) {
     Shutdown();
   }
 }
 
+NS_IMETHODIMP
+Geolocation::DebugLogger(char const*)
+{
+  return NS_OK;
+}
+
 nsresult
 Geolocation::Init(nsPIDOMWindowInner* aContentDom)
 {
   // Remember the window
   if (aContentDom) {
     mOwner = do_GetWeakReference(aContentDom);
     if (!mOwner) {
       return NS_ERROR_FAILURE;
--- a/dom/system/NetworkGeolocationProvider.js
+++ b/dom/system/NetworkGeolocationProvider.js
@@ -9,16 +9,17 @@ Components.utils.import("resource://gre/
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cu = Components.utils;
 
 const POSITION_UNAVAILABLE = Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE;
 
 var gLoggingEnabled = false;
+var externalDebugLogger = null;
 
 /*
    The gLocationRequestTimeout controls how long we wait on receiving an update
    from the Wifi subsystem.  If this timer fires, we believe the Wifi scan has
    had a problem and we no longer can use Wifi to position the user this time
    around (we will continue to be hopeful that Wifi will recover).
 
    This timeout value is also used when Wifi scanning is disabled (see
@@ -31,16 +32,19 @@ var gLocationRequestTimeout = 5000;
 var gWifiScanningEnabled = true;
 
 function LOG(aMsg) {
   if (gLoggingEnabled) {
     aMsg = "*** WIFI GEO: " + aMsg + "\n";
     Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(aMsg);
     dump(aMsg);
   }
+  if (externalDebugLogger) {
+    externalDebugLogger(aMsg);
+  }
 }
 
 function CachedRequest(loc, cellInfo, wifiList) {
   this.location = loc;
 
   let wifis = new Set();
   if (wifiList) {
     for (let i = 0; i < wifiList.length; i++) {
@@ -304,16 +308,17 @@ WifiGeoPositionProvider.prototype = {
 
     if(this.wifiService) {
       this.wifiService.stopWatching(this);
       this.wifiService = null;
     }
 
     this.listener = null;
     this.started = false;
+    externalDebugLogger = null;
   },
 
   setHighAccuracy: function(enable) {
   },
 
   onChange: function(accessPoints) {
 
     // we got some wifi data, rearm the timer.
@@ -408,17 +413,21 @@ WifiGeoPositionProvider.prototype = {
                                                   xhr.response.location.lng,
                                                   xhr.response.accuracy);
 
       this.listener.update(newLocation);
       gCachedRequest = new CachedRequest(newLocation, data.cellTowers, data.wifiAccessPoints);
     }).bind(this);
 
     var requestData = JSON.stringify(data);
-    LOG("sending " + requestData);
+
+    LOG(`Scanned WIFI AP count: ${wifiData ? wifiData.length : 0}, ` +
+        `Sending WIFI AP count: ${data.wifiAccessPoints ? data.wifiAccessPoints.length : 0}, ` +
+        `Cell count: ${data.cellTowers ? data.cellTowers.length : 0}`);
     xhr.send(requestData);
   },
 
   enableLoggingToListener: function(isEnabled) {
+    externalDebugLogger = (isEnabled) ? this.listener.debugLogger : null;
   }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiGeoPositionProvider]);
--- a/dom/system/mac/CoreLocationLocationProvider.mm
+++ b/dom/system/mac/CoreLocationLocationProvider.mm
@@ -256,8 +256,20 @@ CoreLocationLocationProvider::CancelMLSF
 {
   if (!mMLSFallbackProvider) {
     return;
   }
 
   mMLSFallbackProvider->Shutdown();
   mMLSFallbackProvider = nullptr;
 }
+
+NS_IMETHODIMP
+CoreLocationLocationProvider::EnableLoggingToListener(bool)
+{
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+CoreLocationLocationProvider::MLSUpdate::DebugLogger(char const*)
+{
+  return NS_OK;
+}
\ No newline at end of file
--- a/xpcom/system/nsIGeolocationProvider.idl
+++ b/xpcom/system/nsIGeolocationProvider.idl
@@ -32,16 +32,22 @@ interface nsIGeolocationUpdate : nsISupp
    * The parameter refers to one of the constants in the
    * nsIDOMGeoPositionError interface.
    * Use this to report spurious errors coming from the
    * provider; for errors occurring inside the methods in
    * the nsIGeolocationProvider interface, just use the return
    * value.
    */
   void notifyError(in unsigned short error);
+
+  /**
+   * If nsIGeolocationProvider.enableLoggingToListener is enabled,
+   * additional details about the update is provided.
+   */
+  void debugLogger(in string msg);
 };
 
 
 /**
  * Interface provides location information to the nsGeolocator
  * via the nsIDOMGeolocationCallback interface.  After
  * startup is called, any geo location change should call
  * callback.update().
@@ -67,16 +73,23 @@ interface nsIGeolocationProvider : nsISu
    */
   void shutdown();
 
   /**
    * hint to provide to use any amount of power to provide a better result
    */
   void setHighAccuracy(in boolean enable);
 
+  /**
+   * Enable logging the internals of requests as part of the update
+   * in nsIGeolocationUpdate. This not exposed to HTML Geo api, it is for browser
+   * chrome permission level only.
+   * Implementors: Please minimize PII (i.e. log wifi AP count, but not MACs).
+   */
+  void enableLoggingToListener(in boolean enable);
 };
 
 %{C++
 /*
     This must be implemented by geolocation providers.  It
     must support nsIGeolocationProvider.
 */
 #define NS_GEOLOCATION_PROVIDER_CONTRACTID "@mozilla.org/geolocation/provider;1"