Bug 452762 - Make sure Geolocation callbacks run in the right JS context r/sr=jst

This commit is contained in:
Doug Turner 2008-09-10 08:52:46 -07:00
parent dda5d0de06
commit 3291d97489

View File

@ -48,6 +48,7 @@
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsIProxyObjectManager.h"
#include "nsIJSContextStack.h"
#include <math.h>
@ -180,7 +181,18 @@ nsGeolocationRequest::Allow()
NS_PROXY_ASYNC | NS_PROXY_ALWAYS,
getter_AddRefs(callbackProxy));
// Ensure that the proper context is on the stack (bug 452762)
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
if (!stack || NS_FAILED(stack->Push(nsnull)))
return NS_OK; // silently fail
callbackProxy->HandleEvent(positionError);
// remove the stack
JSContext* cx;
stack->Pop(&cx);
return rv;
}
@ -207,6 +219,11 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* position)
if (mCleared || !mAllowed)
return;
// Ensure that the proper context is on the stack (bug 452762)
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
if (!stack || NS_FAILED(stack->Push(nsnull)))
return; // silently fail
//TODO mFuzzLocation. Needs to be defined what we do here.
if (mFuzzLocation)
{
@ -246,10 +263,15 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* position)
velocity,
time);
mCallback->HandleEvent(somewhere);
return;
}
mCallback->HandleEvent(position);
else
{
mCallback->HandleEvent(position);
}
// remove the stack
JSContext* cx;
stack->Pop(&cx);
}
void