mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 914888 - Reset geolocation provider accuracy when the last high accuracy request is shut down. r=jdm
This commit is contained in:
parent
476e8c2e17
commit
fc54d0b9da
@ -77,7 +77,7 @@ class nsGeolocationRequest
|
||||
void Shutdown();
|
||||
|
||||
void SendLocation(nsIDOMGeoPosition* location);
|
||||
bool WantsHighAccuracy() {return mOptions && mOptions->mEnableHighAccuracy;}
|
||||
bool WantsHighAccuracy() {return !mShutdown && mOptions && mOptions->mEnableHighAccuracy;}
|
||||
void SetTimeoutTimer();
|
||||
nsIPrincipal* GetPrincipal();
|
||||
|
||||
@ -462,7 +462,7 @@ nsGeolocationRequest::Allow()
|
||||
maximumAge = mOptions->mMaximumAge;
|
||||
}
|
||||
}
|
||||
gs->SetHigherAccuracy(mOptions && mOptions->mEnableHighAccuracy);
|
||||
gs->UpdateAccuracy(WantsHighAccuracy());
|
||||
|
||||
bool canUseCache = lastPosition && maximumAge > 0 &&
|
||||
(PRTime(PR_Now() / PR_USEC_PER_MSEC) - maximumAge <=
|
||||
@ -602,12 +602,12 @@ nsGeolocationRequest::Shutdown()
|
||||
mTimeoutTimer = nullptr;
|
||||
}
|
||||
|
||||
// This should happen last, to ensure that this request isn't taken into consideration
|
||||
// when deciding whether existing requests still require high accuracy.
|
||||
// If there are no other high accuracy requests, the geolocation service will
|
||||
// notify the provider to switch to the default accuracy.
|
||||
if (mOptions && mOptions->mEnableHighAccuracy) {
|
||||
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
||||
if (gs) {
|
||||
gs->SetHigherAccuracy(false);
|
||||
gs->UpdateAccuracy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -920,9 +920,9 @@ nsGeolocationService::HighAccuracyRequested()
|
||||
}
|
||||
|
||||
void
|
||||
nsGeolocationService::SetHigherAccuracy(bool aEnable)
|
||||
nsGeolocationService::UpdateAccuracy(bool aForceHigh)
|
||||
{
|
||||
bool highRequired = aEnable || HighAccuracyRequested();
|
||||
bool highRequired = aForceHigh || HighAccuracyRequested();
|
||||
|
||||
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
||||
ContentChild* cpc = ContentChild::GetSingleton();
|
||||
@ -1080,6 +1080,7 @@ Geolocation::Shutdown()
|
||||
|
||||
if (mService) {
|
||||
mService->RemoveLocator(this);
|
||||
mService->UpdateAccuracy();
|
||||
}
|
||||
|
||||
mService = nullptr;
|
||||
|
@ -85,8 +85,8 @@ public:
|
||||
// create, or reinitalize the callback timer
|
||||
void SetDisconnectTimer();
|
||||
|
||||
// request higher accuracy, if possible
|
||||
void SetHigherAccuracy(bool aEnable);
|
||||
// Update the accuracy and notify the provider if changed
|
||||
void UpdateAccuracy(bool aForceHigh = false);
|
||||
bool HighAccuracyRequested();
|
||||
|
||||
private:
|
||||
|
@ -73,6 +73,9 @@ function WifiGeoPositionProvider() {
|
||||
this.timer = null;
|
||||
this.hasSeenWiFi = false;
|
||||
this.started = false;
|
||||
// this is only used when logging is enabled, to debug interactions with the
|
||||
// geolocation service
|
||||
this.highAccuracy = false;
|
||||
}
|
||||
|
||||
WifiGeoPositionProvider.prototype = {
|
||||
@ -132,10 +135,12 @@ WifiGeoPositionProvider.prototype = {
|
||||
},
|
||||
|
||||
setHighAccuracy: function(enable) {
|
||||
this.highAccuracy = enable;
|
||||
LOG("setting highAccuracy to " + (this.highAccuracy?"TRUE":"FALSE"));
|
||||
},
|
||||
|
||||
onChange: function(accessPoints) {
|
||||
LOG("onChange called");
|
||||
LOG("onChange called, highAccuracy = " + (this.highAccuracy?"TRUE":"FALSE"));
|
||||
this.hasSeenWiFi = true;
|
||||
|
||||
let url = Services.urlFormatter.formatURLPref("geo.wifi.uri");
|
||||
|
104
dom/tests/unit/test_geolocation_reset_accuracy.js
Normal file
104
dom/tests/unit/test_geolocation_reset_accuracy.js
Normal file
@ -0,0 +1,104 @@
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
|
||||
const providerContract = "@mozilla.org/geolocation/provider;1";
|
||||
|
||||
const categoryName = "geolocation-provider";
|
||||
|
||||
var provider = {
|
||||
QueryInterface: function eventsink_qi(iid) {
|
||||
if (iid.equals(Components.interfaces.nsISupports) ||
|
||||
iid.equals(Components.interfaces.nsIFactory) ||
|
||||
iid.equals(Components.interfaces.nsIGeolocationProvider))
|
||||
return this;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
createInstance: function eventsink_ci(outer, iid) {
|
||||
if (outer)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return this.QueryInterface(iid);
|
||||
},
|
||||
lockFactory: function eventsink_lockf(lock) {
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
startup: function() {
|
||||
},
|
||||
watch: function() {
|
||||
},
|
||||
shutdown: function() {
|
||||
},
|
||||
setHighAccuracy: function(enable) {
|
||||
this._isHigh = enable;
|
||||
if (enable) {
|
||||
this._seenHigh = true;
|
||||
}
|
||||
},
|
||||
_isHigh: false,
|
||||
_seenHigh: false
|
||||
};
|
||||
|
||||
let runningInParent = true;
|
||||
try {
|
||||
runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
|
||||
getService(Components.interfaces.nsIXULRuntime).processType
|
||||
== Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
|
||||
}
|
||||
catch (e) { }
|
||||
|
||||
function successCallback()
|
||||
{
|
||||
do_check_true(false);
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function errorCallback()
|
||||
{
|
||||
do_check_true(false);
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
function run_test()
|
||||
{
|
||||
if (runningInParent) {
|
||||
// XPCShell does not get a profile by default. The geolocation service
|
||||
// depends on the settings service which uses IndexedDB and IndexedDB
|
||||
// needs a place where it can store databases.
|
||||
do_get_profile();
|
||||
|
||||
Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
|
||||
"Unit test geo provider", providerContract, provider);
|
||||
var catMan = Components.classes["@mozilla.org/categorymanager;1"]
|
||||
.getService(Components.interfaces.nsICategoryManager);
|
||||
catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
|
||||
providerContract, false, true);
|
||||
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
prefs.setBoolPref("geo.testing.ignore_ipc_principal", true);
|
||||
prefs.setBoolPref("geo.wifi.scan", false);
|
||||
}
|
||||
|
||||
let geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
|
||||
|
||||
do_test_pending();
|
||||
|
||||
let watchID1 = geolocation.watchPosition(successCallback, errorCallback);
|
||||
let watchID2 = geolocation.watchPosition(successCallback, errorCallback,
|
||||
{enableHighAccuracy: true});
|
||||
|
||||
do_timeout(1000, function() {
|
||||
geolocation.clearWatch(watchID2);
|
||||
do_timeout(1000, check_results);
|
||||
});
|
||||
}
|
||||
|
||||
function check_results()
|
||||
{
|
||||
if (runningInParent) {
|
||||
// check the provider was set to high accuracy during the test
|
||||
do_check_true(provider._seenHigh);
|
||||
// check the provider is not currently set to high accuracy
|
||||
do_check_false(provider._isHigh);
|
||||
}
|
||||
do_test_finished();
|
||||
}
|
70
dom/tests/unit/test_geolocation_reset_accuracy_wrap.js
Normal file
70
dom/tests/unit/test_geolocation_reset_accuracy_wrap.js
Normal file
@ -0,0 +1,70 @@
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
|
||||
const providerContract = "@mozilla.org/geolocation/provider;1";
|
||||
|
||||
const categoryName = "geolocation-provider";
|
||||
|
||||
var provider = {
|
||||
QueryInterface: function eventsink_qi(iid) {
|
||||
if (iid.equals(Components.interfaces.nsISupports) ||
|
||||
iid.equals(Components.interfaces.nsIFactory) ||
|
||||
iid.equals(Components.interfaces.nsIGeolocationProvider))
|
||||
return this;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
createInstance: function eventsink_ci(outer, iid) {
|
||||
if (outer)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
return this.QueryInterface(iid);
|
||||
},
|
||||
lockFactory: function eventsink_lockf(lock) {
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
startup: function() {
|
||||
},
|
||||
watch: function() {
|
||||
},
|
||||
shutdown: function() {
|
||||
},
|
||||
setHighAccuracy: function(enable) {
|
||||
this._isHigh = enable;
|
||||
if (enable) {
|
||||
this._seenHigh = true;
|
||||
}
|
||||
},
|
||||
_isHigh: false,
|
||||
_seenHigh: false
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
// XPCShell does not get a profile by default. The geolocation service
|
||||
// depends on the settings service which uses IndexedDB and IndexedDB
|
||||
// needs a place where it can store databases.
|
||||
do_get_profile();
|
||||
|
||||
Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
|
||||
"Unit test geo provider", providerContract, provider);
|
||||
var catMan = Components.classes["@mozilla.org/categorymanager;1"]
|
||||
.getService(Components.interfaces.nsICategoryManager);
|
||||
catMan.nsICategoryManager.addCategoryEntry(categoryName, "unit test",
|
||||
providerContract, false, true);
|
||||
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
prefs.setBoolPref("geo.testing.ignore_ipc_principal", true);
|
||||
prefs.setBoolPref("geo.wifi.scan", false);
|
||||
|
||||
run_test_in_child("test_geolocation_reset_accuracy.js", check_results);
|
||||
}
|
||||
|
||||
function check_results()
|
||||
{
|
||||
// check the provider was set to high accuracy during the test
|
||||
do_check_true(provider._seenHigh);
|
||||
// check the provider is not currently set to high accuracy
|
||||
do_check_false(provider._isHigh);
|
||||
|
||||
do_test_finished();
|
||||
}
|
@ -12,3 +12,8 @@ skip-if = os == "android"
|
||||
skip-if = os == "android"
|
||||
[test_geolocation_timeout_wrap.js]
|
||||
skip-if = os == "mac" || os == "android"
|
||||
[test_geolocation_reset_accuracy.js]
|
||||
# Bug 919946: test hangs consistently on Android
|
||||
skip-if = os == "android"
|
||||
[test_geolocation_reset_accuracy_wrap.js]
|
||||
skip-if = os == "mac" || os == "android"
|
||||
|
Loading…
Reference in New Issue
Block a user