mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 466493 Implement PositionOptions::maximumAge. r/sr=jst
Bug 466494 Make geolocation mochitest use PositionError named values. r/sr=jst
This commit is contained in:
parent
b3cbee5843
commit
f91cee129b
@ -41,11 +41,9 @@ interface nsIDOMGeoPositionOptions;
|
||||
interface nsIDOMGeoPositionCallback;
|
||||
interface nsIDOMGeoPositionErrorCallback;
|
||||
|
||||
[scriptable, function, uuid(0EC70F3F-7E15-45E0-84E9-CDE078CB150A)]
|
||||
[scriptable, function, uuid(37687DAF-B85F-4E4D-8881-85A0AD24CF78)]
|
||||
interface nsIDOMGeoGeolocation : nsISupports
|
||||
{
|
||||
readonly attribute nsIDOMGeoPosition lastPosition;
|
||||
|
||||
void getCurrentPosition(in nsIDOMGeoPositionCallback successCallback,
|
||||
[optional] in nsIDOMGeoPositionErrorCallback errorCallback,
|
||||
[optional] in nsIDOMGeoPositionOptions options);
|
||||
|
@ -37,9 +37,10 @@
|
||||
|
||||
#include "domstubs.idl"
|
||||
|
||||
[scriptable, uuid(74FA3BE6-4CBF-47C7-9BE1-FB9F17DD0D5D)]
|
||||
[scriptable, uuid(19C44AAA-64E4-4D25-8C59-EEE7ADCEB709)]
|
||||
interface nsIDOMGeoPositionOptions : nsISupports
|
||||
{
|
||||
attribute boolean enableHighAccuracy;
|
||||
attribute unsigned long timeout;
|
||||
attribute unsigned long maximumAge;
|
||||
};
|
||||
|
@ -236,8 +236,30 @@ nsGeolocationRequest::Cancel()
|
||||
NS_IMETHODIMP
|
||||
nsGeolocationRequest::Allow()
|
||||
{
|
||||
// Kick off the geo device, if it isn't already running
|
||||
nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance();
|
||||
|
||||
// check to see if we can use a cached value
|
||||
PRUint32 maximumAge;
|
||||
if (mOptions && NS_SUCCEEDED(mOptions->GetMaximumAge(&maximumAge)) && maximumAge != 0) {
|
||||
nsCOMPtr<nsIDOMGeoPosition> lastPosition = geoService->GetCachedPosition();
|
||||
DOMTimeStamp cachedPositionTime;
|
||||
lastPosition->GetTimestamp(&cachedPositionTime);
|
||||
|
||||
if ( PR_Now() - (maximumAge * PR_MSEC_PER_SEC) >= cachedPositionTime )
|
||||
{
|
||||
// okay, we can return a cached position
|
||||
mAllowed = PR_TRUE;
|
||||
|
||||
// send the cached location
|
||||
SendLocation(lastPosition);
|
||||
|
||||
// remove ourselves from the locators callback lists.
|
||||
mLocator->RemoveRequest(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Kick off the geo device, if it isn't already running
|
||||
nsresult rv = geoService->StartDevice();
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
@ -252,6 +274,7 @@ nsGeolocationRequest::Allow()
|
||||
mTimeoutTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
|
||||
}
|
||||
|
||||
|
||||
mAllowed = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
@ -379,6 +402,19 @@ nsGeolocationService::Update(nsIDOMGeoPosition *aSomewhere)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsGeolocationService::SetCachedPosition(nsIDOMGeoPosition* aPosition)
|
||||
{
|
||||
mLastPosition = aPosition;
|
||||
}
|
||||
|
||||
nsIDOMGeoPosition*
|
||||
nsGeolocationService::GetCachedPosition()
|
||||
{
|
||||
return mLastPosition;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsGeolocationService::HasGeolocationProvider()
|
||||
{
|
||||
@ -563,6 +599,14 @@ nsGeolocation::Update(nsIDOMGeoPosition *aSomewhere)
|
||||
return;
|
||||
|
||||
mUpdateInProgress = PR_TRUE;
|
||||
|
||||
if (!aSomewhere)
|
||||
{
|
||||
nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance();
|
||||
geoService->SetCachedPosition(aSomewhere);
|
||||
}
|
||||
|
||||
|
||||
if (!OwnerStillExists())
|
||||
{
|
||||
Shutdown();
|
||||
@ -581,15 +625,6 @@ nsGeolocation::Update(nsIDOMGeoPosition *aSomewhere)
|
||||
mUpdateInProgress = PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocation::GetLastPosition(nsIDOMGeoPosition * *aLastPosition)
|
||||
{
|
||||
// we are advocating that this method be removed.
|
||||
NS_ENSURE_ARG_POINTER(aLastPosition);
|
||||
*aLastPosition = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGeolocation::GetCurrentPosition(nsIDOMGeoPositionCallback *callback,
|
||||
nsIDOMGeoPositionErrorCallback *errorCallback,
|
||||
|
@ -114,6 +114,9 @@ public:
|
||||
void AddLocator(nsGeolocation* locator);
|
||||
void RemoveLocator(nsGeolocation* locator);
|
||||
|
||||
void SetCachedPosition(nsIDOMGeoPosition* aPosition);
|
||||
nsIDOMGeoPosition* GetCachedPosition();
|
||||
|
||||
// Returns true if there is a geolocation provider registered.
|
||||
PRBool HasGeolocationProvider();
|
||||
|
||||
@ -148,6 +151,9 @@ private:
|
||||
// addes them to this list, and their destructor removes
|
||||
// them from this list.
|
||||
nsTArray<nsGeolocation*> mGeolocators;
|
||||
|
||||
// This is the last geo position that we have seen.
|
||||
nsCOMPtr<nsIDOMGeoPosition> mLastPosition;
|
||||
};
|
||||
|
||||
|
||||
|
@ -45,7 +45,6 @@ include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = \
|
||||
test_lastPosition.html \
|
||||
test_manyWindows.html \
|
||||
test_allowCurrent.html \
|
||||
test_allowWatch.html \
|
||||
|
@ -27,7 +27,7 @@ var watchID = new Array(numCallbacks);
|
||||
|
||||
function failureCallback(error)
|
||||
{
|
||||
ok(error.code == 2, "Failure was something other than position unavailable");
|
||||
ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
|
||||
removePrompt();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ var callbackCounter = new Array(numCallbacks);
|
||||
|
||||
function failureCallback(error)
|
||||
{
|
||||
ok(error.code == 2, "Failure was something other than position unavailable");
|
||||
ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
|
||||
removePrompt();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var watchID = new Array(numCallbacks);
|
||||
|
||||
function failureCallback(error)
|
||||
{
|
||||
ok(error.code == 2, "Failure was something other than position unavailable");
|
||||
ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
|
||||
removePrompt();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ var watchID = new Array(numCallbacks);
|
||||
|
||||
function failureCallback(error)
|
||||
{
|
||||
ok(error.code == 2, "Failure was something other than position unavailable");
|
||||
ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
|
||||
removePrompt();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
@ -38,13 +38,13 @@ function successCallback(pos){
|
||||
function errorCallback(err) {
|
||||
removePrompt();
|
||||
|
||||
if (err.code == 2) {
|
||||
if (err.code == err.POSITION_UNAVAILABLE) {
|
||||
// nothing is hooked up to test against.
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
ok(err.code == 4, "ensure error is a timeout.");
|
||||
ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
|
||||
removePrompt();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user