summaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--browser/app/profile/firefox.js6
-rw-r--r--dom/system/NetworkGeolocationProvider.js41
2 files changed, 34 insertions, 13 deletions
diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js
index 82f8e45a5..acb5cfa5d 100644
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1249,11 +1249,7 @@ pref("plain_text.wrap_long_lines", true);
pref("dom.debug.propagate_gesture_events_through_content", false);
// The request URL of the GeoLocation backend.
-#ifdef RELEASE_OR_BETA
-pref("geo.wifi.uri", "https://www.googleapis.com/geolocation/v1/geolocate?key=%GOOGLE_API_KEY%");
-#else
-pref("geo.wifi.uri", "https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%");
-#endif
+pref("geo.wifi.uri", "http://ip-api.com/json/?fields=lat,lon,status,message");
#ifdef XP_MACOSX
#ifdef RELEASE_OR_BETA
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) {