Bug 625415 - Position is lost after a few seconds r=jdm, a=approval-2.0
authorDoug Turner <dougt@dougt.org>
Mon, 31 Jan 2011 14:11:45 -0800
changeset 61680 f169d30d28a5983047b749c73cad5dfacb21b6a0
parent 61679 163c0ed43150ea2a571797a38e8ae050a37c6efb
child 61681 ae887246ba3400e8861e7c5620eeecdc3f81d7b9
push id18447
push userdougt@mozilla.com
push dateTue, 01 Feb 2011 02:44:39 +0000
treeherdermozilla-central@f169d30d28a5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm, approval-2.0
bugs625415
milestone2.0b11pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 625415 - Position is lost after a few seconds r=jdm, a=approval-2.0
dom/src/geolocation/nsGeolocation.cpp
dom/src/geolocation/nsGeolocation.h
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -234,20 +234,22 @@ nsDOMGeoPositionError::NotifyCallback(ns
 }
 ////////////////////////////////////////////////////
 // nsGeolocationRequest
 ////////////////////////////////////////////////////
 
 nsGeolocationRequest::nsGeolocationRequest(nsGeolocation* aLocator,
                                            nsIDOMGeoPositionCallback* aCallback,
                                            nsIDOMGeoPositionErrorCallback* aErrorCallback,
-                                           nsIDOMGeoPositionOptions* aOptions)
+                                           nsIDOMGeoPositionOptions* aOptions,
+                                           PRBool aWatchPositionRequest)
   : mAllowed(PR_FALSE),
     mCleared(PR_FALSE),
     mIsFirstUpdate(PR_TRUE),
+    mIsWatchPositionRequest(aWatchPositionRequest),
     mCallback(aCallback),
     mErrorCallback(aErrorCallback),
     mOptions(aOptions),
     mLocator(aLocator)
 {
 }
 
 nsGeolocationRequest::~nsGeolocationRequest()
@@ -449,17 +451,18 @@ nsGeolocationRequest::SendLocation(nsIDO
     return; // silently fail
   
   mCallback->HandleEvent(aPosition);
 
   // remove the stack
   JSContext* cx;
   stack->Pop(&cx);
 
-  SetTimeoutTimer();
+  if (mIsWatchPositionRequest)
+    SetTimeoutTimer();
 }
 
 void
 nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition, PRBool isBetter)
 {
   // Only dispatch callbacks if this is the first position for this request, or
   // if the accuracy is as good or improving.
   //
@@ -1020,17 +1023,21 @@ nsGeolocation::GetCurrentPosition(nsIDOM
   NS_ENSURE_ARG_POINTER(callback);
 
   if (!sGeoEnabled)
     return NS_ERROR_NOT_AVAILABLE;
 
   if (mPendingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW)
     return NS_ERROR_NOT_AVAILABLE;
 
-  nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this, callback, errorCallback, options);
+  nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
+								    callback,
+								    errorCallback,
+								    options,
+								    PR_FALSE);
   if (!request)
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (NS_FAILED(request->Init()))
     return NS_ERROR_FAILURE; // this as OKAY.  not sure why we wouldn't throw. xxx dft
 
   if (mOwner) {
     RegisterRequestWithPrompt(request);
@@ -1059,17 +1066,21 @@ nsGeolocation::WatchPosition(nsIDOMGeoPo
   NS_ENSURE_ARG_POINTER(callback);
 
   if (!sGeoEnabled)
     return NS_ERROR_NOT_AVAILABLE;
 
   if (mPendingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW)
     return NS_ERROR_NOT_AVAILABLE;
 
-  nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this, callback, errorCallback, options);
+  nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
+								    callback,
+								    errorCallback,
+								    options,
+								    PR_TRUE);
   if (!request)
     return NS_ERROR_OUT_OF_MEMORY;
 
   if (NS_FAILED(request->Init()))
     return NS_ERROR_FAILURE; // this as OKAY.  not sure why we wouldn't throw. xxx dft
 
   if (mOwner) {
     RegisterRequestWithPrompt(request);
--- a/dom/src/geolocation/nsGeolocation.h
+++ b/dom/src/geolocation/nsGeolocation.h
@@ -86,17 +86,18 @@ class nsGeolocationRequest
   NS_DECL_NSICONTENTPERMISSIONREQUEST
   NS_DECL_NSITIMERCALLBACK
 
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGeolocationRequest, nsIContentPermissionRequest)
 
   nsGeolocationRequest(nsGeolocation* locator,
                        nsIDOMGeoPositionCallback* callback,
                        nsIDOMGeoPositionErrorCallback* errorCallback,
-                       nsIDOMGeoPositionOptions* options);
+                       nsIDOMGeoPositionOptions* options,
+                       PRBool watchPositionRequest = PR_FALSE);
   nsresult Init();
   void Shutdown();
 
   // Called by the geolocation device to notify that a location has changed.
   // isBetter: the accuracy is as good or better than the previous position. 
   void Update(nsIDOMGeoPosition* aPosition, PRBool isBetter);
 
   void SendLocation(nsIDOMGeoPosition* location);
@@ -113,16 +114,17 @@ class nsGeolocationRequest
 #endif
 
  private:
 
   void NotifyError(PRInt16 errorCode);
   PRPackedBool mAllowed;
   PRPackedBool mCleared;
   PRPackedBool mIsFirstUpdate;
+  PRPackedBool mIsWatchPositionRequest;
 
   nsCOMPtr<nsITimer> mTimeoutTimer;
   nsCOMPtr<nsIDOMGeoPositionCallback> mCallback;
   nsCOMPtr<nsIDOMGeoPositionErrorCallback> mErrorCallback;
   nsCOMPtr<nsIDOMGeoPositionOptions> mOptions;
 
   nsRefPtr<nsGeolocation> mLocator;
 };