Bug 868257 - watchPosition only sends one location r=stuart

This commit is contained in:
Doug Turner 2013-05-02 23:04:58 -07:00
parent 65de50fed4
commit 887ca3dc76
2 changed files with 10 additions and 31 deletions

View File

@ -187,18 +187,16 @@ public:
// event should remove the request from it. If we ever
// have to do more, then we can change this around.
RequestSendLocationEvent(nsIDOMGeoPosition* aPosition,
bool aCachePosition,
nsGeolocationRequest* aRequest,
Geolocation* aLocator)
: mPosition(aPosition),
mCachePosition(aCachePosition),
mRequest(aRequest),
mLocator(aLocator)
{
}
NS_IMETHOD Run() {
mRequest->SendLocation(mPosition, mCachePosition);
mRequest->SendLocation(mPosition);
if (mLocator) {
mLocator->RemoveRequest(mRequest);
}
@ -207,10 +205,8 @@ public:
private:
nsCOMPtr<nsIDOMGeoPosition> mPosition;
bool mCachePosition;
nsRefPtr<nsGeolocationRequest> mRequest;
nsRefPtr<Geolocation> mLocator;
nsRefPtr<Geolocation> mLocator;
};
class RequestRestartTimerEvent : public nsRunnable
@ -308,7 +304,6 @@ nsGeolocationRequest::nsGeolocationRequest(Geolocation* aLocator,
int32_t aWatchId)
: mAllowed(false),
mCleared(false),
mIsFirstUpdate(true),
mIsWatchPositionRequest(aWatchPositionRequest),
mCallback(aCallback),
mErrorCallback(aErrorCallback),
@ -472,7 +467,7 @@ nsGeolocationRequest::Allow()
nsCOMPtr<nsIRunnable> ev =
new RequestSendLocationEvent(
lastPosition, true, this, mIsWatchPositionRequest ? nullptr : mLocator);
lastPosition, this, mIsWatchPositionRequest ? nullptr : mLocator);
NS_DispatchToMainThread(ev);
}
@ -516,7 +511,7 @@ nsGeolocationRequest::MarkCleared()
}
void
nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition, bool aCachePosition)
nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition)
{
if (mCleared || !mAllowed) {
return;
@ -543,9 +538,7 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition, bool aCachePosi
return;
}
if (aCachePosition) {
mLocator->SetCachedPosition(wrapped);
}
mLocator->SetCachedPosition(wrapped);
// Ensure that the proper context is on the stack (bug 452762)
nsCxPusher pusher;
@ -584,23 +577,10 @@ nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition)
if (!mAllowed) {
return false;
}
// Only dispatch callbacks if this is the first position for this request, or
// if the accuracy is as good or improving.
//
// This ensures that all listeners get at least one position callback, particularly
// in the case when newly detected positions are all less accurate than the cached one.
//
// Fixes bug 596481
nsCOMPtr<nsIRunnable> ev;
if (mIsFirstUpdate) {
mIsFirstUpdate = false;
ev = new RequestSendLocationEvent(aPosition,
true,
this,
mIsWatchPositionRequest ? nullptr : mLocator);
} else {
ev = new RequestRestartTimerEvent(this);
}
nsCOMPtr<nsIRunnable> ev = new RequestSendLocationEvent(aPosition,
this,
mIsWatchPositionRequest ? nullptr : mLocator);
NS_DispatchToMainThread(ev);
return true;
}

View File

@ -73,7 +73,7 @@ class nsGeolocationRequest
// Called by the geolocation device to notify that a location has changed.
bool Update(nsIDOMGeoPosition* aPosition);
void SendLocation(nsIDOMGeoPosition* location, bool aCachePosition);
void SendLocation(nsIDOMGeoPosition* location);
void MarkCleared();
bool WantsHighAccuracy() {return mOptions && mOptions->enableHighAccuracy;}
bool IsActive() {return !mCleared;}
@ -92,7 +92,6 @@ class nsGeolocationRequest
void NotifyError(int16_t errorCode);
bool mAllowed;
bool mCleared;
bool mIsFirstUpdate;
bool mIsWatchPositionRequest;
nsCOMPtr<nsITimer> mTimeoutTimer;