mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-23 15:47:30 +09:00
Switch GeoLocation to IP-API.com with minimal requests.
This commit is contained in:
parent
3d983be76c
commit
0ff3276b09
2 changed files with 34 additions and 13 deletions
|
|
@ -1249,11 +1249,7 @@ pref("plain_text.wrap_long_lines", true);
|
||||||
pref("dom.debug.propagate_gesture_events_through_content", false);
|
pref("dom.debug.propagate_gesture_events_through_content", false);
|
||||||
|
|
||||||
// The request URL of the GeoLocation backend.
|
// The request URL of the GeoLocation backend.
|
||||||
#ifdef RELEASE_OR_BETA
|
pref("geo.wifi.uri", "http://ip-api.com/json/?fields=lat,lon,status,message");
|
||||||
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
|
|
||||||
|
|
||||||
#ifdef XP_MACOSX
|
#ifdef XP_MACOSX
|
||||||
#ifdef RELEASE_OR_BETA
|
#ifdef RELEASE_OR_BETA
|
||||||
|
|
|
||||||
|
|
@ -219,9 +219,20 @@ WifiGeoCoordsObject.prototype = {
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMGeoPositionCoords])
|
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.coords = new WifiGeoCoordsObject(lat, lng, acc, 0, 0);
|
||||||
this.address = null;
|
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();
|
this.timestamp = Date.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -431,41 +442,54 @@ WifiGeoPositionProvider.prototype = {
|
||||||
let xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
let xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||||
.createInstance(Ci.nsIXMLHttpRequest);
|
.createInstance(Ci.nsIXMLHttpRequest);
|
||||||
|
|
||||||
this.notifyListener("locationUpdatePending");
|
// XXX: Dead code?
|
||||||
|
// this.notifyListener("locationUpdatePending");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
xhr.open("POST", url, true);
|
xhr.open("GET", url, true);
|
||||||
xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
|
xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.notifyListener("notifyError",
|
this.notifyListener("notifyError",
|
||||||
[POSITION_UNAVAILABLE]);
|
[POSITION_UNAVAILABLE]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
|
|
||||||
xhr.responseType = "json";
|
xhr.responseType = "json";
|
||||||
xhr.mozBackgroundRequest = true;
|
xhr.mozBackgroundRequest = true;
|
||||||
xhr.timeout = Services.prefs.getIntPref("geo.wifi.xhr.timeout");
|
xhr.timeout = Services.prefs.getIntPref("geo.wifi.xhr.timeout");
|
||||||
|
|
||||||
xhr.ontimeout = (function() {
|
xhr.ontimeout = (function() {
|
||||||
LOG("Location request XHR timed out.")
|
LOG("Location request XHR timed out.")
|
||||||
this.notifyListener("notifyError",
|
this.notifyListener("notifyError",
|
||||||
[POSITION_UNAVAILABLE]);
|
[POSITION_UNAVAILABLE]);
|
||||||
}).bind(this);
|
}).bind(this);
|
||||||
|
|
||||||
xhr.onerror = (function() {
|
xhr.onerror = (function() {
|
||||||
this.notifyListener("notifyError",
|
this.notifyListener("notifyError",
|
||||||
[POSITION_UNAVAILABLE]);
|
[POSITION_UNAVAILABLE]);
|
||||||
}).bind(this);
|
}).bind(this);
|
||||||
|
|
||||||
xhr.onload = (function() {
|
xhr.onload = (function() {
|
||||||
LOG("server returned status: " + xhr.status + " --> " + JSON.stringify(xhr.response));
|
LOG("server returned status: " + xhr.status + " --> " + JSON.stringify(xhr.response));
|
||||||
if ((xhr.channel instanceof Ci.nsIHttpChannel && xhr.status != 200) ||
|
if ((xhr.channel instanceof Ci.nsIHttpChannel && xhr.status != 200) ||
|
||||||
!xhr.response || !xhr.response.location) {
|
!xhr.response || xhr.response.status == 'fail') {
|
||||||
this.notifyListener("notifyError",
|
this.notifyListener("notifyError",
|
||||||
[POSITION_UNAVAILABLE]);
|
[POSITION_UNAVAILABLE]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newLocation = new WifiGeoPositionObject(xhr.response.location.lat,
|
let newLocation = new WifiGeoPositionObject(xhr.response.lat,
|
||||||
xhr.response.location.lng,
|
xhr.response.lon,
|
||||||
xhr.response.accuracy);
|
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]);
|
this.notifyListener("update", [newLocation]);
|
||||||
gCachedRequest = new CachedRequest(newLocation, data.cellTowers, data.wifiAccessPoints);
|
gCachedRequest = new CachedRequest(newLocation, data.cellTowers, data.wifiAccessPoints);
|
||||||
|
|
@ -478,6 +502,7 @@ WifiGeoPositionProvider.prototype = {
|
||||||
|
|
||||||
notifyListener: function(listenerFunc, args) {
|
notifyListener: function(listenerFunc, args) {
|
||||||
args = args || [];
|
args = args || [];
|
||||||
|
LOG("Notify listener " + listenerFunc);
|
||||||
try {
|
try {
|
||||||
this.listener[listenerFunc].apply(this.listener, args);
|
this.listener[listenerFunc].apply(this.listener, args);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue