Bug 677256 - Migrate to Google Location Service v2. r=stover
authorDoug Turner <dougt@dougt.org>
Tue, 09 Aug 2011 13:02:39 -0700
changeset 76808 861e1307c43c06c74b623b9dd6af591f646ecd31
parent 76807 e79dbde50f8e5b61a6b2586ce02b6de19136cdb5
child 76809 fae3f1a9327b0270f33df3150be8bcbd6139fcd3
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstover
bugs677256
milestone9.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 677256 - Migrate to Google Location Service v2. r=stover
browser/app/profile/firefox.js
dom/system/NetworkGeolocationProvider.js
dom/tests/mochitest/geolocation/geolocation_common.js
dom/tests/mochitest/geolocation/network_geolocation.sjs
mobile/app/mobile.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -876,17 +876,17 @@ pref("browser.privatebrowsing.autostart"
 // Whether we should skip prompting before starting the private browsing mode
 pref("browser.privatebrowsing.dont_prompt_on_enter", false);
 
 // Don't try to alter this pref, it'll be reset the next time you use the
 // bookmarking dialog
 pref("browser.bookmarks.editDialog.firstEditField", "namePicker");
 
 // base url for the wifi geolocation network provider
-pref("geo.wifi.uri", "https://www.google.com/loc/json");
+pref("geo.wifi.uri", "https://maps.googleapis.com/maps/api/browserlocation/json");
 pref("geo.wifi.protocol", 0);
 
 // Whether to use a panel that looks like an OS X sheet for customization
 #ifdef XP_MACOSX
 pref("toolbar.customization.usesheet", true);
 #else
 pref("toolbar.customization.usesheet", false);
 #endif
old mode 100755
new mode 100644
--- a/dom/system/NetworkGeolocationProvider.js
+++ b/dom/system/NetworkGeolocationProvider.js
@@ -1,427 +1,311 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Network Location Provider for GLS.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2011
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Doug Turner <dougt@dougt.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+
+// Do not use this API without permission from Google.
+// See http://www.google.com/support/enterprise/bin/request.py?contact_type=gme&utm_campaign=en-us-ptr-mz
+// for more information.
+
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 
-var gLoggingEnabled = false;
-var gTestingEnabled = false;
-
-function nowInSeconds()
-{
-    return Date.now() / 1000;
-}
+let gLoggingEnabled = false;
+let gTestingEnabled = false;
 
 function LOG(aMsg) {
   if (gLoggingEnabled)
   {
     aMsg = "*** WIFI GEO: " + aMsg + "\n";
     Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(aMsg);
     dump(aMsg);
   }
 }
 
-function WifiGeoAddressObject(streetNumber, street, premises, city, county, region, country, countryCode, postalCode) {
-
-  this.streetNumber = streetNumber;
-  this.street       = street;
-  this.premises     = premises;
-  this.city         = city;
-  this.county       = county;
-  this.region       = region;
-  this.country      = country;
-  this.countryCode  = countryCode;
-  this.postalCode   = postalCode;
+function WifiGeoCoordsObject(lat, lon, acc, alt, altacc) {
+  this.latitude = lat;
+  this.longitude = lon;
+  this.accuracy = acc;
+  this.altitude = alt;
+  this.altitudeAccuracy = altacc;
 }
 
-WifiGeoAddressObject.prototype = {
-
-    QueryInterface:   XPCOMUtils.generateQI([Ci.nsIDOMGeoPositionAddress]),
-
-    classInfo: XPCOMUtils.generateCI({interfaces: [Ci.nsIDOMGeoPositionAddress],
-                                      flags: Ci.nsIClassInfo.DOM_OBJECT})
-};
-
-function WifiGeoCoordsObject(lat, lon, acc, alt, altacc) {
-    this.latitude = lat;
-    this.longitude = lon;
-    this.accuracy = acc;
-    this.altitude = alt;
-    this.altitudeAccuracy = altacc;
-};
-
 WifiGeoCoordsObject.prototype = {
 
-    QueryInterface:   XPCOMUtils.generateQI([Ci.nsIDOMGeoPositionCoords]),
-
-    classInfo: XPCOMUtils.generateCI({interfaces: [Ci.nsIDOMGeoPositionCoords],
-                                      flags: Ci.nsIClassInfo.DOM_OBJECT,
-                                      classDescription: "wifi geo position coords object"}),
+  QueryInterface:  XPCOMUtils.generateQI([Ci.nsIDOMGeoPositionCoords]),
 
-    latitude: 0,
-    longitude: 0,
-    accuracy: 0,
-    altitude: 0,
-    altitudeAccuracy: 0,
-
+  classInfo: XPCOMUtils.generateCI({interfaces: [Ci.nsIDOMGeoPositionCoords],
+                                    flags: Ci.nsIClassInfo.DOM_OBJECT,
+                                    classDescription: "wifi geo position coords object"}),
 };
 
-function WifiGeoPositionObject(location) {
-
-    this.coords = new WifiGeoCoordsObject(location.latitude,
-                                          location.longitude,
-                                          location.accuracy || 12450, // .5 * circumference of earth.
-                                          location.altitude || 0,
-                                          location.altitude_accuracy || 0);
-
-    if (location.address) {
-        let address = location.address;
-        this.address = new WifiGeoAddressObject(address.street_number || null,
-                                                address.street || null,
-                                                address.premises || null,
-                                                address.city || null,
-                                                address.county || null,
-                                                address.region || null,
-                                                address.country || null,
-                                                address.country_code || null,
-                                                address.postal_code || null);
-    }
-    else
-      this.address = null;
-
-    this.timestamp = Date.now();
-};
+function WifiGeoPositionObject(lat, lng, acc) {
+  this.coords = new WifiGeoCoordsObject(lat, lng, acc, 0, 0);
+  this.address = null;
+  this.timestamp = Date.now();
+}
 
 WifiGeoPositionObject.prototype = {
 
-    QueryInterface:   XPCOMUtils.generateQI([Ci.nsIDOMGeoPosition]),
+  QueryInterface:   XPCOMUtils.generateQI([Ci.nsIDOMGeoPosition]),
 
-    // Class Info is required to be able to pass objects back into the DOM.
-    classInfo: XPCOMUtils.generateCI({interfaces: [Ci.nsIDOMGeoPosition],
-                                      flags: Ci.nsIClassInfo.DOM_OBJECT,
-                                      classDescription: "wifi geo location position object"}),
-
-    coords: null,
-    timestamp: 0,
+  // Class Info is required to be able to pass objects back into the DOM.
+  classInfo: XPCOMUtils.generateCI({interfaces: [Ci.nsIDOMGeoPosition],
+                                    flags: Ci.nsIClassInfo.DOM_OBJECT,
+                                    classDescription: "wifi geo location position object"}),
 };
 
-function HELD() {};
- // For information about the HELD format, see:
- // http://tools.ietf.org/html/draft-thomson-geopriv-held-measurements-05
-HELD.encode = function(requestObject) {
-    // XML Header
-    var requestString = "<locationRequest xmlns=\"urn:ietf:params:xml:ns:geopriv:held\">";
-    // Measurements
-    if (requestObject.wifi_towers && requestObject.wifi_towers.length > 0) {
-      requestString += "<measurements xmlns=\"urn:ietf:params:xml:ns:geopriv:lm\">";
-      requestString += "<wifi xmlns=\"urn:ietf:params:xml:ns:geopriv:lm:wifi\">";
-      for (var i=0; i < requestObject.wifi_towers.length; ++i) {
-        requestString += "<neighbourWap>";
-        requestString += "<bssid>" + requestObject.wifi_towers[i].mac_address     + "</bssid>";
-        requestString += "<ssid>"  + requestObject.wifi_towers[i].ssid            + "</ssid>";
-        requestString += "<rssi>"  + requestObject.wifi_towers[i].signal_strength + "</rssi>";
-        requestString += "</neighbourWap>";
-      }
-      // XML Footer
-      requestString += "</wifi></measurements>";
+function WifiGeoPositionProvider() {
+  try {
+    gLoggingEnabled = Services.prefs.getBoolPref("geo.wifi.logging.enabled");
+  } catch (e) {}
+
+  try {
+    gTestingEnabled = Services.prefs.getBoolPref("geo.wifi.testing");
+  } catch (e) {}
+
+  wifiService = null;
+  timer = null;
+  hasSeenWiFi = false;
+  started = false;
+}
+
+WifiGeoPositionProvider.prototype = {
+  classID:          Components.ID("{77DA64D3-7458-4920-9491-86CC9914F904}"),
+  QueryInterface:   XPCOMUtils.generateQI([Ci.nsIGeolocationProvider,
+                                           Ci.nsIWifiListener,
+                                           Ci.nsITimerCallback]),
+  startup:  function() {
+    if (this.started)
+      return;
+    this.started = true;
+    this.hasSeenWiFi = false;
+
+    LOG("startup called.  testing mode is" + gTestingEnabled);
+
+    // if we don't see anything in 5 seconds, kick of one IP geo lookup.
+    // if we are testing, just hammer this callback so that we are more or less
+    // always sending data.  It doesn't matter if we have an access point or not.
+    this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+    if (!gTestingEnabled)
+      this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT);
+    else
+      this.timer.initWithCallback(this, 200, this.timer.TYPE_REPEATING_SLACK);
+  },
+
+  watch: function(c) {
+    LOG("watch called");
+    if (!this.wifiService) {
+      this.wifiService = Cc["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);
+      this.wifiService.startWatching(this);
     }
-    requestString += "</locationRequest>";
-    return requestString;
-};
+  },
 
-// Decode a HELD response into a Gears-style object
-HELD.decode = function(responseXML) {
-    // Find a Circle object in PIDF-LO and decode
-    function nsResolver(prefix) {
-        var ns = {
-            'held': 'urn:ietf:params:xml:ns:geopriv:held',
-            'pres': 'urn:ietf:params:xml:ns:pidf',
-            'gp': 'urn:ietf:params:xml:ns:pidf:geopriv10',
-            'gml': 'http://www.opengis.net/gml',
-            'gs': 'http://www.opengis.net/pidflo/1.0',
-        };
-        return ns[prefix] || null;
+  shutdown: function() { 
+    LOG("shutdown called");
+    if(this.wifiService) {
+      this.wifiService.stopWatching(this);
+      this.wifiService = null;
+    }
+    if (this.timer != null) {
+      this.timer.cancel();
+      this.timer = null;
     }
 
-    var xpathEval = Components.classes["@mozilla.org/dom/xpath-evaluator;1"].createInstance(Ci.nsIDOMXPathEvaluator);
+    // Although we aren't using cookies, we should err on the side of not
+    // saving any access tokens if the user asked us not to save cookies or
+    // has changed the lifetimePolicy.  The access token in these cases is
+    // used and valid for the life of this object (eg. between startup and
+    // shutdown).
+    if (Services.prefs.getIntPref("network.cookie.lifetimePolicy") != 0)
+      Services.prefs.deleteBranch("geo.wifi.access_token.");
+    this.started = false;
+  },
 
-    // Grab values out of XML via XPath
-    var pos = xpathEval.evaluate(
-        '/held:locationResponse/pres:presence/pres:tuple/pres:status/gp:geopriv/gp:location-info/gs:Circle/gml:pos',
-        responseXML,
-        nsResolver,
-        Ci.nsIDOMXPathResult.STRING_TYPE,
-        null);
+  getAccessTokenForURL: function(url)
+  {
+    // check to see if we have an access token:
+    let accessToken = "";
+    try {
+      let accessTokenPrefName = "geo.wifi.access_token." + url;
+      accessToken = Services.prefs.getCharPref(accessTokenPrefName);
+
+      // check to see if it has expired
+      let accessTokenDate = Services.prefs.getIntPref(accessTokenPrefName + ".time");
+      
+      let accessTokenInterval = 1209600;  // seconds in 2 weeks
+      try {
+        accessTokenInterval = Services.prefs.getIntPref("geo.wifi.access_token.recycle_interval");
+      } catch (e) {}
+            
+      if ((Date.now() / 1000) - accessTokenDate > accessTokenInterval)
+        accessToken = "";
+    }
+    catch (e) {
+      accessToken = "";
+    }
+    return accessToken;
+  },
 
-    var rad = xpathEval.evaluate(
-        '/held:locationResponse/pres:presence/pres:tuple/pres:status/gp:geopriv/gp:location-info/gs:Circle/gs:radius',
-        responseXML,
-        nsResolver,
-        Ci.nsIDOMXPathResult.NUMBER_TYPE,
-        null );
+  onChange: function(accessPoints) {
+    LOG("onChange called");
+    this.hasSeenWiFi = true;
+
+    let providerUrlBase = Services.prefs.getCharPref("geo.wifi.uri");
+    let providerUrl;
+
+    let query = providerUrlBase.indexOf("?");
+    if (query == -1)
+      providerUrl = providerUrlBase + "?"
+    else
+      providerUrl = providerUrlBase + "&";
+    providerUrl = providerUrl + "browser=firefox&sensor=true";
+    
+
+    let accessToken = this.getAccessTokenForURL(providerUrlBase);
+    if (accessToken !== "")
+      providerUrl = providerUrl + "&access_token="+access_token;
 
-    var uom = xpathEval.evaluate(
-        '/held:locationResponse/pres:presence/pres:tuple/pres:status/gp:geopriv/gp:location-info/gs:Circle/gs:radius/@uom',
-        responseXML,
-        nsResolver,
-        Ci.nsIDOMXPathResult.STRING_TYPE,
-        null);
+    function sort(a, b) {
+      return b.signal - a.signal;
+    };
+
+    function encode(ap) {
+      // make sure that the ssid doesn't contain any | chars.
+      ap.ssid = ap.ssid.replace("|", "\\|");
+      // gls service parses the | as fields
+      return "&wifi=mac:"+ap.mac+"|ssid:"+ap.ssid+"|ss:"+ap.signal;
+    };
 
-    // Bail if we don't have a valid result (all values && uom==meters)
-    if ((pos.stringValue == null) ||
-        (rad.numberValue == null) ||
-        (uom.stringValue == null) ||
-        (uom.stringValue != "urn:ogc:def:uom:EPSG::9001")) {
-        return null;
+    if (accessPoints) {
+        accessPoints.sort(sort).map(encode).join("");
+        // max length is 2k.  make sure we are under that
+        let x = providerUrl.length - 2000;
+        if (x >= 0) {
+            // we need to trim
+            let doomed = providerUrl.lastIndexOf("&", 2000);
+            LOG("Doomed:"+doomed);
+            providerUrl = providerUrl.substring(0, doomed);
+        }
     }
 
-    // Split the pos value into lat/long
-    var coords = pos.stringValue.split(/[ \t\n]+/);
-
-    // Fill out the object to return:
-    var obj = {
-        location: {
-            latitude: parseFloat(coords[0]),
-            longitude: parseFloat(coords[1]),
-            accuracy: rad.numberValue
-        }
-    };
-    return obj;
-}  
+    providerUrl = encodeURI(providerUrl);
+    LOG("************************************* Sending request:\n" + providerUrl + "\n");
 
-function WifiGeoPositionProvider() {
-    this.prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).QueryInterface(Ci.nsIPrefService);
-    try {
-        gLoggingEnabled = this.prefService.getBoolPref("geo.wifi.logging.enabled");
-    } catch (e) {}
-
-    try {
-        gTestingEnabled = this.prefService.getBoolPref("geo.wifi.testing");
-    } catch (e) {}
-
-};
-
-WifiGeoPositionProvider.prototype = {
-    classID:          Components.ID("{77DA64D3-7458-4920-9491-86CC9914F904}"),
-    QueryInterface:   XPCOMUtils.generateQI([Ci.nsIGeolocationProvider,
-                                             Ci.nsIWifiListener,
-                                             Ci.nsITimerCallback]),
+    // send our request to a wifi geolocation network provider:
+    let xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
+                        .createInstance(Ci.nsIXMLHttpRequest);
 
-    prefService:     null,
-    wifi_service:    null,
-    timer:           null,
-    hasSeenWiFi:     false,
-    started:         false,
-
-    startup:         function() {
-        if (this.started == true)
-            return;
-
-        this.started = true;
+    // This is a background load
+    xhr.mozBackgroundRequest = true;
+    xhr.open("GET", providerUrl, false);
+    xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
+    xhr.onerror = function(req) {
+        LOG("onerror: " + req);
+    };
+    xhr.onload = function (req) {  
+        LOG("service returned: " + req.target.responseText);
+        response = JSON.parse(req.target.responseText);
+        /*
+          {
+            "status": "OK",
+            "accuracy": 150.0,
+            "location": {
+              "lat": -33.85702,
+              "lng": 151.21494
+            },
+            "access_token": "quijibo"
+          }
+        */
 
-        LOG("startup called.  testing mode is" + gTestingEnabled);
-        // if we don't see anything in 5 seconds, kick of one IP geo lookup.
-        // if we are testing, just hammer this callback so that we are more or less
-        // always sending data.  It doesn't matter if we have an access point or not.
-        this.hasSeenWiFi = false;
-        this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-        if (gTestingEnabled == false)
-            this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT);
-        else
-            this.timer.initWithCallback(this, 200, this.timer.TYPE_REPEATING_SLACK);
-    },
+        if (response.status != "OK")
+          return;
 
-    watch: function(c) {
-        LOG("watch called");
-        if (!this.wifi_service) {
-            this.wifi_service = Cc["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);
-            this.wifi_service.startWatching(this);
-        }
-    },
+        if (response.location) {
+          let newLocation = new WifiGeoPositionObject(response.location.lat,
+                                                      response.location.lng,
+                                                      response.accuracy);
 
-    shutdown: function() { 
-        LOG("shutdown  called");
-        if(this.wifi_service)
-            this.wifi_service.stopWatching(this);
-        this.wifi_service = null;
-
-        if (this.timer != null) {
-            this.timer.cancel();
-            this.timer = null;
+          let update = Cc["@mozilla.org/geolocation/service;1"].getService(Ci.nsIGeolocationUpdate);
+          update.update(newLocation);
         }
 
-        // Although we aren't using cookies, we should err on the side of not
-        // saving any access tokens if the user asked us not to save cookies or
-        // has changed the lifetimePolicy.  The access token in these cases is
-        // used and valid for the life of this object (eg. between startup and
-        // shutdown).e
-        let prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-        if (prefBranch.getIntPref("network.cookie.lifetimePolicy") != 0)
-            prefBranch.deleteBranch("geo.wifi.access_token.");
-
-        this.started = false;
-    },
-
-    getAccessTokenForURL: function(url)
-    {
-        // check to see if we have an access token:
-        var accessToken = "";
-        
-        try {
-            var accessTokenPrefName = "geo.wifi.access_token." + url;
-            accessToken = this.prefService.getCharPref(accessTokenPrefName);
-            
-            // check to see if it has expired
-            var accessTokenDate = this.prefService.getIntPref(accessTokenPrefName + ".time");
-            
-            var accessTokenInterval = 1209600;  /* seconds in 2 weeks */
-            try {
-                accessTokenInterval = this.prefService.getIntPref("geo.wifi.access_token.recycle_interval");
-            } catch (e) {}
-            
-            if (nowInSeconds() - accessTokenDate > accessTokenInterval)
-                accessToken = "";
-        }
-        catch (e) {
-            accessToken = "";
-        }
-        return accessToken;
-    },
-
-    onChange: function(accessPoints) {
-
-        LOG("onChange called");
-        this.hasSeenWiFi = true;
-
-        // send our request to a wifi geolocation network provider:
-        var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
-                            .createInstance(Ci.nsIXMLHttpRequest);
-
-        // This is a background load
-        xhr.mozBackgroundRequest = true;
-
-        var provider_url      = this.prefService.getCharPref("geo.wifi.uri");
-        var provider_protocol = 0;
-        try {
-            provider_protocol = this.prefService.getIntPref("geo.wifi.protocol");
-        } catch (e) {}
-
-        LOG("provider url = " + provider_url);
-
-        xhr.open("POST", provider_url, false);
-        
-        // set something so that we can strip cookies
-        xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
-            
-        xhr.onerror = function(req) {
-            LOG("onerror: " + req);
-        };
-
-        xhr.onload = function (req) {  
-
-            LOG("xhr onload...");
+        // Check to see if we have a new access token
+        let newAccessToken = response.access_token;
+        if (newAccessToken !== undefined)
+        {
+          let accessToken = "";
+          let accessTokenPrefName = "geo.wifi.access_token." + providerUrlBase;
+          try { accessToken = Services.prefs.getCharPref(accessTokenPrefName); } catch (e) {}
 
-            try { 
-                // if we get a bad response, we will throw and never report a location
-                var response;
-                switch (provider_protocol) {
-                    case 1:
-                        LOG("service returned: " + req.target.responseXML);
-                        response = HELD.decode(req.target.responseXML);
-                        break;
-                    case 0:
-                    default:
-                        LOG("service returned: " + req.target.responseText);
-                        response = JSON.parse(req.target.responseText);
-                }
-            } catch (e) {
-                LOG("Parse failed");
-                return;
-            }
-
-            // response looks something like:
-            // {"location":{"latitude":51.5090332,"longitude":-0.1212726,"accuracy":150.0},"access_token":"2:jVhRZJ-j6PiRchH_:RGMrR0W1BiwdZs12"}
-
-            // Check to see if we have a new access token
-            var newAccessToken = response.access_token;
-            if (newAccessToken != undefined)
-            {
-                var prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-                var accessToken = "";
-                var accessTokenPrefName = "geo.wifi.access_token." + req.target.channel.URI.spec;
-                try { accessToken = prefService.getCharPref(accessTokenPrefName); } catch (e) {}
-
-                if (accessToken != newAccessToken) {
-                    // no match, lets cache
-                    LOG("New Access Token: " + newAccessToken + "\n" + accessTokenPrefName);
-                    
-                    try {
-                        prefService.setIntPref(accessTokenPrefName + ".time", nowInSeconds());
-                        prefService.setCharPref(accessTokenPrefName, newAccessToken);
-                    } catch (x) {
-                        // XXX temporary hack for bug 575346 to allow geolocation to function
-                    }
-                }
-            }
-
-            if (response.location) {
-                var newLocation = new WifiGeoPositionObject(response.location);
-
-                var update = Cc["@mozilla.org/geolocation/service;1"].getService(Ci.nsIGeolocationUpdate);
-                update.update(newLocation);
-            }
-        };
+          if (accessToken != newAccessToken) {
+            // no match, lets cache
+              LOG("New Access Token: " + newAccessToken + "\n" + accessTokenPrefName);
+              try {
+                Services.prefs.setIntPref(accessTokenPrefName + ".time", nowInSeconds());
+                Services.prefs.setCharPref(accessTokenPrefName, newAccessToken);
+              } catch (x) {
+                  // XXX temporary hack for bug 575346 to allow geolocation to function
+              }
+          }
+        }
+    };
 
-        var accessToken = this.getAccessTokenForURL(provider_url);
-
-        var request = {
-            version: "1.1.0",
-            request_address: true,
-        };
-
-        if (accessToken != "")
-            request.access_token = accessToken;
+    LOG("************************************* ------>>>> sending.");
+    xhr.send(null);
+  },
 
-        if (accessPoints != null) {
-            function filterBlankSSIDs(ap) ap.ssid != ""
-            function deconstruct(ap) ({
-                    mac_address: ap.mac,
-                        ssid: ap.ssid,
-                        signal_strength: ap.signal
-                        })
-            request.wifi_towers = accessPoints.filter(filterBlankSSIDs).map(deconstruct);
-        }
+  onError: function (code) {
+    LOG("wifi error: " + code);
+  },
 
-        var requestString;
-        switch (provider_protocol) {
-          case 1:
-              requestString = HELD.encode(request);
-              break;
-          case 0:
-          default:
-              requestString = JSON.stringify(request);
-        }
-        LOG("client sending: " + requestString);
- 
-        try {
-          xhr.send(requestString);
-        } catch (e) {}
-    },
-
-    onError: function (code) {
-        LOG("wifi error: " + code);
-    },
-
-    notify: function (timer) {
-        if (!gTestingEnabled) {
-            if (this.hasSeenWiFi == false)
-                this.onChange(null);
-            this.timer = null;
-            return;
-        }
-        // if we are testing, we need to hammer this.
+  notify: function (timer) {
+    if (gTestingEnabled) {
+      // if we are testing, timer is repeating
+      this.onChange(null);
+    }
+    else {
+      if (!this.hasSeenWiFi)
         this.onChange(null);
-    },
-
+      this.timer = null;
+    }
+  },
 };
 
-var NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiGeoPositionProvider]);
+let NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiGeoPositionProvider]);
--- a/dom/tests/mochitest/geolocation/geolocation_common.js
+++ b/dom/tests/mochitest/geolocation/geolocation_common.js
@@ -72,20 +72,20 @@ function check_geolocation(location) {
 
   // eventually, coords may be optional (eg, when civic addresses are supported)
   ok("coords" in location, "Check to see if this location has a coords");
 
   var coords = location.coords;
 
   ok("latitude" in coords, "Check to see if there is a latitude");
   ok("longitude" in coords, "Check to see if there is a longitude");
-  ok("altitude" in coords, "Check to see if there is a altitude");
   ok("accuracy" in coords, "Check to see if there is a accuracy");
-  ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy");
-
+  
+  // optional ok("altitude" in coords, "Check to see if there is a altitude");
+  // optional ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy");
   // optional ok("heading" in coords, "Check to see if there is a heading");
   // optional ok("speed" in coords, "Check to see if there is a speed");
 
   ok (location.coords.latitude  == 37.41857, "lat matches known value");
   ok (location.coords.longitude == -122.08769, "lon matches known value");
-  ok(location.coords.altitude == 42, "alt matches known value");
-  ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
+  // optional  ok(location.coords.altitude == 42, "alt matches known value");
+  // optional  ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
 }
--- a/dom/tests/mochitest/geolocation/network_geolocation.sjs
+++ b/dom/tests/mochitest/geolocation/network_geolocation.sjs
@@ -14,45 +14,26 @@ function parseQueryString(str)
     params[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
   }
 
   return params;
 }
 
 function getPosition(action)
 {  
-    // this isn't the w3c data structure, it is the network location provider structure.
-
-  var address = {
-      street_number: "street_number",
-      street: "street",
-      premises: "premises",
-      city: "city",
-      county: "county",
-      region: "region",
-      country: "country",
-      country_code: "country_code",
-      postal_code: "postal_code",
-  };
-
-
-  var coords = {
-    latitude: 37.41857,
-    longitude: -122.08769,
-
-    altitude: 42,
+  var response = {
+    status: "OK",
+    location: {
+      lat: 37.41857,
+      lng: -122.08769,
+    },
     accuracy: (action == "worse-accuracy") ? 100 : 42,
-    altitude_accuracy: 42,
   };
   
-  var geoposition = {
-    location: coords,
-  };
-
-  return JSON.stringify(geoposition);
+  return JSON.stringify(response);
 }
 
 function handleRequest(request, response)
 {
   var params = parseQueryString(request.queryString);
 
   if (params.action == "stop-responding") {
       return;
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -367,17 +367,17 @@ pref("privacy.item.syncAccount", true);
 #ifdef MOZ_PLATFORM_MAEMO
 pref("plugins.force.wmode", "opaque");
 #endif
 
 // URL to the Learn More link XXX this is the firefox one.  Bug 495578 fixes this.
 pref("browser.geolocation.warning.infoURL", "http://www.mozilla.com/%LOCALE%/firefox/geolocation/");
 
 // base url for the wifi geolocation network provider
-pref("geo.wifi.uri", "https://www.google.com/loc/json");
+pref("geo.wifi.uri", "https://maps.googleapis.com/maps/api/browserlocation/json");
 
 // enable geo
 pref("geo.enabled", true);
 
 // content sink control -- controls responsiveness during page load
 // see https://bugzilla.mozilla.org/show_bug.cgi?id=481566#c9
 pref("content.sink.enable_perf_mode",  2); // 0 - switch, 1 - interactive, 2 - perf
 pref("content.sink.pending_event_mode", 0);