mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
bug 1034301 - Guard against bad listener behavior. r=kanru
This commit is contained in:
parent
a673af86e3
commit
87e597b7d1
@ -453,6 +453,7 @@ WifiGeoPositionProvider.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
let l = this.listener;
|
||||
let useCached = isCachedRequestMoreAccurateThanServerRequest(data.cellTowers,
|
||||
data.wifiAccessPoints);
|
||||
|
||||
@ -460,38 +461,40 @@ WifiGeoPositionProvider.prototype = {
|
||||
|
||||
if (useCached) {
|
||||
gCachedRequest.location.timestamp = Date.now();
|
||||
this.listener.update(gCachedRequest.location);
|
||||
this.notifyListener(l.update, [gCachedRequest.location]);
|
||||
return;
|
||||
}
|
||||
|
||||
// From here on, do a network geolocation request //
|
||||
let url = Services.urlFormatter.formatURLPref("geo.wifi.uri");
|
||||
let listener = this.listener;
|
||||
LOG("Sending request: " + url + "\n");
|
||||
|
||||
let xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
||||
.createInstance(Ci.nsIXMLHttpRequest);
|
||||
|
||||
listener.locationUpdatePending();
|
||||
this.notifyListener(l.locationUpdatePending);
|
||||
|
||||
try {
|
||||
xhr.open("POST", url, true);
|
||||
} catch (e) {
|
||||
listener.notifyError(POSITION_UNAVAILABLE);
|
||||
this.notifyListener(l.notifyError,
|
||||
[POSITION_UNAVAILABLE]);
|
||||
return;
|
||||
}
|
||||
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
xhr.responseType = "json";
|
||||
xhr.mozBackgroundRequest = true;
|
||||
xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
|
||||
xhr.onerror = function() {
|
||||
listener.notifyError(POSITION_UNAVAILABLE);
|
||||
};
|
||||
xhr.onload = function() {
|
||||
xhr.onerror = (function() {
|
||||
this.notifyListener(l.notifyError,
|
||||
[POSITION_UNAVAILABLE]);
|
||||
}).bind(this);
|
||||
xhr.onload = (function() {
|
||||
LOG("gls returned status: " + xhr.status + " --> " + JSON.stringify(xhr.response));
|
||||
if ((xhr.channel instanceof Ci.nsIHttpChannel && xhr.status != 200) ||
|
||||
!xhr.response || !xhr.response.location) {
|
||||
listener.notifyError(POSITION_UNAVAILABLE);
|
||||
this.notifyListener(l.notifyError,
|
||||
[POSITION_UNAVAILABLE]);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -499,14 +502,23 @@ WifiGeoPositionProvider.prototype = {
|
||||
xhr.response.location.lng,
|
||||
xhr.response.accuracy);
|
||||
|
||||
listener.update(newLocation);
|
||||
this.notifyListener(l.update, [newLocation]);
|
||||
gCachedRequest = new CachedRequest(newLocation, data.cellTowers, data.wifiAccessPoints);
|
||||
};
|
||||
}).bind(this);
|
||||
|
||||
var requestData = JSON.stringify(data);
|
||||
LOG("sending " + requestData);
|
||||
xhr.send(requestData);
|
||||
},
|
||||
|
||||
notifyListener: function(listenerFunc, args) {
|
||||
args = args || [];
|
||||
try {
|
||||
this.listener[listenerFunc].apply(this.listener, args);
|
||||
} catch(e) {
|
||||
Cu.reportError(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WifiGeoPositionProvider]);
|
||||
|
Loading…
Reference in New Issue
Block a user