summaryrefslogtreecommitdiffstats
path: root/dom/system/NetworkGeolocationProvider.js
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2017-09-11 18:50:38 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-02-02 19:35:20 +0100
commit100db2d197aac98e3e9e0f59e4cbe7d902373cba (patch)
treef047e88b385ae617acdcfa4f87f058c414165c67 /dom/system/NetworkGeolocationProvider.js
parent6d3a0633543c2f6dfa3cb82aab519ac5fbd33e35 (diff)
downloadUXP-100db2d197aac98e3e9e0f59e4cbe7d902373cba.tar
UXP-100db2d197aac98e3e9e0f59e4cbe7d902373cba.tar.gz
UXP-100db2d197aac98e3e9e0f59e4cbe7d902373cba.tar.lz
UXP-100db2d197aac98e3e9e0f59e4cbe7d902373cba.tar.xz
UXP-100db2d197aac98e3e9e0f59e4cbe7d902373cba.zip
Switch GeoLocation to IP-API.com with minimal requests.
Diffstat (limited to 'dom/system/NetworkGeolocationProvider.js')
-rw-r--r--dom/system/NetworkGeolocationProvider.js41
1 files changed, 33 insertions, 8 deletions
diff --git a/dom/system/NetworkGeolocationProvider.js b/dom/system/NetworkGeolocationProvider.js
index ea2abe55f..ad15ed802 100644
--- a/dom/system/NetworkGeolocationProvider.js
+++ b/dom/system/NetworkGeolocationProvider.js
@@ -219,9 +219,20 @@ WifiGeoCoordsObject.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGeoPositionCoords])
};
-function WifiGeoPositionObject(lat, lng, acc) {
+function WifiGeoPositionObject(lat, lng, acc, cc, tz, zip, city, rc, region, country, isp, org, as) {
this.coords = new WifiGeoCoordsObject(lat, lng, acc, 0, 0);
this.address = null;
+ this.countrycode = cc;
+ this.timezone = tz;
+ this.zipcode = zip;
+ this.postalcode = zip;
+ this.city = city;
+ this.regioncode = rc;
+ this.region = region;
+ this.country = country;
+ this.isp = isp;
+ this.org = org;
+ this.as = as;
this.timestamp = Date.now();
}
@@ -431,41 +442,54 @@ WifiGeoPositionProvider.prototype = {
let xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(Ci.nsIXMLHttpRequest);
- this.notifyListener("locationUpdatePending");
+ // XXX: Dead code?
+ // this.notifyListener("locationUpdatePending");
try {
- xhr.open("POST", url, true);
+ xhr.open("GET", url, true);
xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
} catch (e) {
this.notifyListener("notifyError",
[POSITION_UNAVAILABLE]);
return;
}
- xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
xhr.responseType = "json";
xhr.mozBackgroundRequest = true;
xhr.timeout = Services.prefs.getIntPref("geo.wifi.xhr.timeout");
+
xhr.ontimeout = (function() {
LOG("Location request XHR timed out.")
this.notifyListener("notifyError",
[POSITION_UNAVAILABLE]);
}).bind(this);
+
xhr.onerror = (function() {
this.notifyListener("notifyError",
[POSITION_UNAVAILABLE]);
}).bind(this);
+
xhr.onload = (function() {
LOG("server returned status: " + xhr.status + " --> " + JSON.stringify(xhr.response));
if ((xhr.channel instanceof Ci.nsIHttpChannel && xhr.status != 200) ||
- !xhr.response || !xhr.response.location) {
+ !xhr.response || xhr.response.status == 'fail') {
this.notifyListener("notifyError",
[POSITION_UNAVAILABLE]);
return;
}
- let newLocation = new WifiGeoPositionObject(xhr.response.location.lat,
- xhr.response.location.lng,
- xhr.response.accuracy);
+ let newLocation = new WifiGeoPositionObject(xhr.response.lat,
+ xhr.response.lon,
+ null, //accuracy not provided
+ xhr.response.countryCode,
+ xhr.response.timezone,
+ xhr.response.zip,
+ xhr.response.city,
+ xhr.response.region,
+ xhr.response.regionName,
+ xhr.response.country,
+ xhr.response.isp,
+ xhr.response.org,
+ xhr.response.as);
this.notifyListener("update", [newLocation]);
gCachedRequest = new CachedRequest(newLocation, data.cellTowers, data.wifiAccessPoints);
@@ -478,6 +502,7 @@ WifiGeoPositionProvider.prototype = {
notifyListener: function(listenerFunc, args) {
args = args || [];
+ LOG("Notify listener " + listenerFunc);
try {
this.listener[listenerFunc].apply(this.listener, args);
} catch(e) {