Bug 681941 - Ensure that we always clear geolocation requests that are not long-lived, and never clear ones that are. r=dougt
authorJosh Matthews <josh@joshmatthews.net>
Thu, 25 Aug 2011 15:13:25 -0400
changeset 75970 0938cf5252cd5ea0b79c4c165385bbf170418a76
parent 75969 4dc1e45afdd7282835ea2081ce334176ee30d51a
child 75971 7d3f4aafd9ea7f783c962b14d454f45c0360b7f6
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersdougt
bugs681941
milestone9.0a1
Bug 681941 - Ensure that we always clear geolocation requests that are not long-lived, and never clear ones that are. r=dougt
dom/src/geolocation/nsGeolocation.cpp
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -144,17 +144,17 @@ private:
 class RequestSendLocationEvent : public nsRunnable
 {
 public:
   // a bit funky.  if locator is passed, that means this
   // event should remove the request from it.  If we ever
   // have to do more, then we can change this around.
   RequestSendLocationEvent(nsIDOMGeoPosition* aPosition,
                            nsGeolocationRequest* aRequest,
-                           nsGeolocation* aLocator = nsnull)
+                           nsGeolocation* aLocator)
     : mPosition(aPosition),
       mRequest(aRequest),
       mLocator(aLocator)
   {
   }
 
   NS_IMETHOD Run() {
     mRequest->SendLocation(mPosition);
@@ -384,17 +384,19 @@ nsGeolocationRequest::Allow()
   }
 
   if (lastPosition && maximumAge > 0 &&
       ( PRTime(PR_Now() / PR_USEC_PER_MSEC) - maximumAge <=
         PRTime(cachedPositionTime) )) {
     // okay, we can return a cached position
     mAllowed = PR_TRUE;
     
-    nsCOMPtr<nsIRunnable> ev = new RequestSendLocationEvent(lastPosition, this, mLocator);
+     nsCOMPtr<nsIRunnable> ev =
+         new RequestSendLocationEvent(lastPosition, this,
+                                      mIsWatchPositionRequest ? nsnull : mLocator);
     NS_DispatchToMainThread(ev);
   }
 
   SetTimeoutTimer();
 
   mAllowed = PR_TRUE;
   return NS_OK;
 }
@@ -457,17 +459,19 @@ nsGeolocationRequest::SendLocation(nsIDO
 
   if (mIsWatchPositionRequest)
     SetTimeoutTimer();
 }
 
 void
 nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition)
 {
-  nsCOMPtr<nsIRunnable> ev  = new RequestSendLocationEvent(aPosition, this);
+  nsCOMPtr<nsIRunnable> ev  =
+      new RequestSendLocationEvent(aPosition, this,
+                                   mIsWatchPositionRequest ? nsnull : mLocator);
   NS_DispatchToMainThread(ev);
 }
 
 void
 nsGeolocationRequest::Shutdown()
 {
   if (mTimeoutTimer) {
     mTimeoutTimer->Cancel();