2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2010-09-13 12:49:27 -07:00
|
|
|
#include "nsContentPermissionHelper.h"
|
2010-05-13 10:44:51 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
#include "mozilla/dom/PBrowserChild.h"
|
|
|
|
#include "mozilla/dom/PBrowserParent.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2010-05-13 10:44:51 -07:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsFrameLoader.h"
|
|
|
|
#include "nsIFrameLoader.h"
|
|
|
|
|
|
|
|
#include "nsIDocShellTreeOwner.h"
|
|
|
|
#include "nsIDocShellTreeItem.h"
|
|
|
|
#include "nsIWebProgressListener2.h"
|
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
#include "nsISettingsService.h"
|
|
|
|
|
2010-05-13 10:44:51 -07:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
|
|
|
#include "TabChild.h"
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
#include "nsGeolocation.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
2011-10-03 12:11:31 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2008-07-15 16:37:48 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2009-07-10 17:04:39 -07:00
|
|
|
#include "nsICategoryManager.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2008-07-15 16:37:48 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "nsIObserverService.h"
|
2008-09-10 08:52:46 -07:00
|
|
|
#include "nsIJSContextStack.h"
|
2010-08-31 09:15:52 -07:00
|
|
|
#include "nsThreadUtils.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
#include "mozilla/Services.h"
|
2010-07-19 11:33:33 -07:00
|
|
|
#include "mozilla/unused.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-06-14 19:31:55 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-11-08 15:36:50 -08:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2008-08-14 09:35:49 -07:00
|
|
|
|
|
|
|
#include <math.h>
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2010-04-14 02:42:43 -07:00
|
|
|
#ifdef MOZ_MAEMO_LIBLOCATION
|
2010-04-02 00:56:22 -07:00
|
|
|
#include "MaemoLocationProvider.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-15 17:25:43 -07:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
#include "QTMLocationProvider.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2010-06-04 14:14:43 -07:00
|
|
|
#include "AndroidLocationProvider.h"
|
|
|
|
#endif
|
|
|
|
|
2012-01-19 06:53:51 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "GonkGPSGeolocationProvider.h"
|
|
|
|
#endif
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
2008-08-14 09:35:49 -07:00
|
|
|
|
2008-11-12 08:00:37 -08:00
|
|
|
// Some limit to the number of get or watch geolocation requests
|
|
|
|
// that a window can make.
|
|
|
|
#define MAX_GEO_REQUESTS_PER_WINDOW 1500
|
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
// The settings key.
|
|
|
|
#define GEO_SETINGS_ENABLED "geolocation.enabled"
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
using mozilla::unused; // <snicker>
|
2011-05-24 23:31:59 -07:00
|
|
|
using namespace mozilla;
|
2010-08-05 15:11:23 -07:00
|
|
|
using namespace mozilla::dom;
|
2010-07-19 11:33:33 -07:00
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
class GeolocationSettingsCallback : public nsISettingsServiceCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
GeolocationSettingsCallback() {
|
|
|
|
MOZ_COUNT_CTOR(GeolocationSettingsCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GeolocationSettingsCallback() {
|
|
|
|
MOZ_COUNT_DTOR(GeolocationSettingsCallback);
|
|
|
|
}
|
|
|
|
|
2012-11-14 13:46:38 -08:00
|
|
|
NS_IMETHOD Handle(const nsAString& aName, const jsval& aResult)
|
2012-10-31 17:19:34 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// The geolocation is enabled by default:
|
|
|
|
bool value = true;
|
|
|
|
if (aResult.isBoolean()) {
|
|
|
|
value = aResult.toBoolean();
|
|
|
|
}
|
|
|
|
|
|
|
|
MozSettingValue(value);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-14 13:46:38 -08:00
|
|
|
NS_IMETHOD HandleError(const nsAString& aName)
|
2012-10-31 17:19:34 -07:00
|
|
|
{
|
|
|
|
NS_WARNING("Unable to get value for '" GEO_SETINGS_ENABLED "'");
|
|
|
|
|
|
|
|
// Default it's enabled:
|
|
|
|
MozSettingValue(true);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MozSettingValue(const bool aValue)
|
|
|
|
{
|
2012-11-08 15:36:50 -08:00
|
|
|
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
|
|
|
if (gs) {
|
|
|
|
gs->HandleMozsettingValue(aValue);
|
2012-10-31 17:19:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(GeolocationSettingsCallback, nsISettingsServiceCallback);
|
|
|
|
|
2010-08-31 09:15:52 -07:00
|
|
|
class RequestPromptEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RequestPromptEvent(nsGeolocationRequest* request)
|
|
|
|
: mRequest(request)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2012-10-31 10:06:42 -07:00
|
|
|
nsCOMPtr<nsIContentPermissionPrompt> prompt = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
|
2010-09-09 21:59:51 -07:00
|
|
|
if (prompt) {
|
2010-08-31 09:15:52 -07:00
|
|
|
prompt->Prompt(mRequest);
|
2010-09-09 21:59:51 -07:00
|
|
|
}
|
2010-08-31 09:15:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<nsGeolocationRequest> mRequest;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RequestAllowEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RequestAllowEvent(int allow, nsGeolocationRequest* request)
|
|
|
|
: mAllow(allow),
|
|
|
|
mRequest(request)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mAllow) {
|
2010-08-31 09:15:52 -07:00
|
|
|
mRequest->Allow();
|
2012-07-26 20:33:04 -07:00
|
|
|
} else {
|
2010-08-31 09:15:52 -07:00
|
|
|
mRequest->Cancel();
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-08-31 09:15:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mAllow;
|
2010-08-31 09:15:52 -07:00
|
|
|
nsRefPtr<nsGeolocationRequest> mRequest;
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
2010-09-09 21:59:51 -07:00
|
|
|
RequestSendLocationEvent(nsIDOMGeoPosition* aPosition,
|
|
|
|
nsGeolocationRequest* aRequest,
|
2011-08-25 12:13:25 -07:00
|
|
|
nsGeolocation* aLocator)
|
2010-08-31 09:15:52 -07:00
|
|
|
: mPosition(aPosition),
|
|
|
|
mRequest(aRequest),
|
|
|
|
mLocator(aLocator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
mRequest->SendLocation(mPosition);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mLocator) {
|
2010-08-31 09:15:52 -07:00
|
|
|
mLocator->RemoveRequest(mRequest);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-08-31 09:15:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDOMGeoPosition> mPosition;
|
|
|
|
nsRefPtr<nsGeolocationRequest> mRequest;
|
|
|
|
|
|
|
|
nsRefPtr<nsGeolocation> mLocator;
|
|
|
|
};
|
|
|
|
|
2012-12-23 19:05:37 -08:00
|
|
|
class RequestRestartTimerEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RequestRestartTimerEvent(nsGeolocationRequest* aRequest)
|
|
|
|
: mRequest(aRequest)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
mRequest->SetTimeoutTimer();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<nsGeolocationRequest> mRequest;
|
|
|
|
};
|
|
|
|
|
2008-08-14 09:35:49 -07:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
// nsDOMGeoPositionError
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
2012-06-14 19:31:55 -07:00
|
|
|
class nsDOMGeoPositionError MOZ_FINAL : public nsIDOMGeoPositionError
|
2008-08-14 09:35:49 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMGEOPOSITIONERROR
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMGeoPositionError(int16_t aCode);
|
2008-10-20 12:37:10 -07:00
|
|
|
void NotifyCallback(nsIDOMGeoPositionErrorCallback* callback);
|
2008-08-14 09:35:49 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
~nsDOMGeoPositionError();
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t mCode;
|
2008-08-14 09:35:49 -07:00
|
|
|
};
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(GeoPositionError, nsDOMGeoPositionError)
|
|
|
|
|
2008-08-14 09:35:49 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDOMGeoPositionError)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionError)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionError)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoPositionError)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsDOMGeoPositionError)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsDOMGeoPositionError)
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMGeoPositionError::nsDOMGeoPositionError(int16_t aCode)
|
2008-10-20 12:37:10 -07:00
|
|
|
: mCode(aCode)
|
2008-08-14 09:35:49 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMGeoPositionError::~nsDOMGeoPositionError(){}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDOMGeoPositionError::GetCode(int16_t *aCode)
|
2008-08-14 09:35:49 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCode);
|
|
|
|
*aCode = mCode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
void
|
|
|
|
nsDOMGeoPositionError::NotifyCallback(nsIDOMGeoPositionErrorCallback* aCallback)
|
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!aCallback) {
|
2008-10-20 12:37:10 -07:00
|
|
|
return;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
// Ensure that the proper context is on the stack (bug 452762)
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!stack || NS_FAILED(stack->Push(nullptr))) {
|
2008-10-20 12:37:10 -07:00
|
|
|
return;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-03-31 09:30:13 -07:00
|
|
|
|
|
|
|
nsAutoMicroTask mt;
|
2008-10-20 12:37:10 -07:00
|
|
|
aCallback->HandleEvent(this);
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
// remove the stack
|
|
|
|
JSContext* cx;
|
|
|
|
stack->Pop(&cx);
|
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
// nsGeolocationRequest
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
nsGeolocationRequest::nsGeolocationRequest(nsGeolocation* aLocator,
|
|
|
|
nsIDOMGeoPositionCallback* aCallback,
|
|
|
|
nsIDOMGeoPositionErrorCallback* aErrorCallback,
|
2012-10-31 17:19:34 -07:00
|
|
|
bool aWatchPositionRequest,
|
|
|
|
int32_t aWatchId)
|
2011-10-17 07:59:28 -07:00
|
|
|
: mAllowed(false),
|
|
|
|
mCleared(false),
|
2012-11-06 12:34:03 -08:00
|
|
|
mIsFirstUpdate(true),
|
2011-01-31 14:11:45 -08:00
|
|
|
mIsWatchPositionRequest(aWatchPositionRequest),
|
2008-10-20 12:37:10 -07:00
|
|
|
mCallback(aCallback),
|
|
|
|
mErrorCallback(aErrorCallback),
|
2012-10-31 17:19:34 -07:00
|
|
|
mLocator(aLocator),
|
|
|
|
mWatchId(aWatchId)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGeolocationRequest::~nsGeolocationRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-12 07:59:38 -08:00
|
|
|
nsresult
|
2012-04-16 12:08:48 -07:00
|
|
|
nsGeolocationRequest::Init(JSContext* aCx, const jsval& aOptions)
|
2008-11-12 07:59:38 -08:00
|
|
|
{
|
2012-04-16 12:08:48 -07:00
|
|
|
if (aCx && !JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
|
|
|
|
mOptions = new mozilla::dom::GeoPositionOptions();
|
|
|
|
nsresult rv = mOptions->Init(aCx, &aOptions);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-11-12 07:59:38 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-14 17:10:46 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGeolocationRequest)
|
2010-09-09 21:59:51 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentPermissionRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentPermissionRequest)
|
2008-10-20 12:37:10 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
2008-07-15 16:37:48 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2009-01-14 17:10:46 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGeolocationRequest)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsGeolocationRequest)
|
|
|
|
|
2012-04-16 12:08:48 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_3(nsGeolocationRequest, mCallback, mErrorCallback, mLocator)
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGeolocationRequest::NotifyError(int16_t errorCode)
|
2008-10-20 12:37:10 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<nsDOMGeoPositionError> positionError = new nsDOMGeoPositionError(errorCode);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!positionError) {
|
2008-10-20 12:37:10 -07:00
|
|
|
return;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
positionError->NotifyCallback(mErrorCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGeolocationRequest::Notify(nsITimer* aTimer)
|
|
|
|
{
|
2012-12-27 22:46:57 -08:00
|
|
|
if (mCleared) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
// If we haven't gotten an answer from the geolocation
|
2012-12-27 22:46:57 -08:00
|
|
|
// provider yet, fire a TIMEOUT error and reset the timer.
|
|
|
|
if (!mIsWatchPositionRequest) {
|
|
|
|
mLocator->RemoveRequest(this);
|
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2010-08-23 21:52:17 -07:00
|
|
|
NotifyError(nsIDOMGeoPositionError::TIMEOUT);
|
2008-10-20 12:37:10 -07:00
|
|
|
|
2012-12-27 22:46:57 -08:00
|
|
|
if (mIsWatchPositionRequest) {
|
|
|
|
SetTimeoutTimer();
|
|
|
|
}
|
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
NS_IMETHODIMP
|
2012-07-30 07:58:26 -07:00
|
|
|
nsGeolocationRequest::GetPrincipal(nsIPrincipal * *aRequestingPrincipal)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-07-30 07:58:26 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingPrincipal);
|
2009-07-10 17:02:32 -07:00
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = mLocator->GetPrincipal();
|
|
|
|
principal.forget(aRequestingPrincipal);
|
2009-07-10 17:02:32 -07:00
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-09-09 21:59:51 -07:00
|
|
|
nsGeolocationRequest::GetType(nsACString & aType)
|
|
|
|
{
|
|
|
|
aType = "geolocation";
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-13 16:06:42 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGeolocationRequest::GetAccess(nsACString & aAccess)
|
|
|
|
{
|
|
|
|
aAccess = "unused";
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-09 21:59:51 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGeolocationRequest::GetWindow(nsIDOMWindow * *aRequestingWindow)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingWindow);
|
2009-07-10 17:02:32 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(mLocator->GetOwner());
|
|
|
|
window.forget(aRequestingWindow);
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-13 10:44:51 -07:00
|
|
|
NS_IMETHODIMP
|
2010-09-09 21:59:51 -07:00
|
|
|
nsGeolocationRequest::GetElement(nsIDOMElement * *aRequestingElement)
|
2010-05-13 10:44:51 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRequestingElement);
|
2012-07-30 07:20:58 -07:00
|
|
|
*aRequestingElement = nullptr;
|
2010-05-13 10:44:51 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGeolocationRequest::Cancel()
|
|
|
|
{
|
|
|
|
// remove ourselves from the locators callback lists.
|
|
|
|
mLocator->RemoveRequest(this);
|
2010-08-23 21:52:17 -07:00
|
|
|
|
|
|
|
NotifyError(nsIDOMGeoPositionError::PERMISSION_DENIED);
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsGeolocationRequest::Allow()
|
|
|
|
{
|
2012-12-06 18:13:15 -08:00
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
GetWindow(getter_AddRefs(window));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(window);
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
|
|
|
|
bool isPrivate = loadContext && loadContext->UsePrivateBrowsing();
|
2008-12-05 08:29:43 -08:00
|
|
|
|
|
|
|
// Kick off the geo device, if it isn't already running
|
2012-12-06 18:13:15 -08:00
|
|
|
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
|
|
|
nsresult rv = gs->StartDevice(isPrivate);
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2008-08-14 09:35:49 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2008-10-20 12:37:10 -07:00
|
|
|
// Location provider error
|
2008-11-12 08:31:25 -08:00
|
|
|
NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE);
|
2008-10-20 12:37:10 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2012-11-08 15:36:50 -08:00
|
|
|
nsCOMPtr<nsIDOMGeoPosition> lastPosition = gs->GetCachedPosition();
|
2009-01-07 09:41:57 -08:00
|
|
|
DOMTimeStamp cachedPositionTime;
|
2012-07-26 20:33:04 -07:00
|
|
|
if (lastPosition) {
|
2009-01-07 09:41:57 -08:00
|
|
|
lastPosition->GetTimestamp(&cachedPositionTime);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-01-07 09:41:57 -08:00
|
|
|
|
|
|
|
// check to see if we can use a cached value
|
|
|
|
//
|
|
|
|
// either:
|
|
|
|
// a) the user has specified a maximumAge which allows us to return a cached value,
|
|
|
|
// -or-
|
|
|
|
// b) the cached position time is some reasonable value to return to the user (<30s)
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t maximumAge = 30 * PR_MSEC_PER_SEC;
|
2009-01-07 09:41:57 -08:00
|
|
|
if (mOptions) {
|
2012-04-16 12:08:48 -07:00
|
|
|
if (mOptions->maximumAge >= 0) {
|
|
|
|
maximumAge = mOptions->maximumAge;
|
2009-01-07 09:43:56 -08:00
|
|
|
}
|
2012-04-16 12:08:48 -07:00
|
|
|
if (mOptions->enableHighAccuracy) {
|
2012-11-08 15:36:50 -08:00
|
|
|
gs->SetHigherAccuracy(true);
|
2012-03-21 10:52:35 -07:00
|
|
|
}
|
2009-01-07 09:41:57 -08:00
|
|
|
}
|
|
|
|
|
2010-04-02 14:49:38 -07:00
|
|
|
if (lastPosition && maximumAge > 0 &&
|
2010-04-28 13:54:00 -07:00
|
|
|
( PRTime(PR_Now() / PR_USEC_PER_MSEC) - maximumAge <=
|
2010-04-02 14:49:38 -07:00
|
|
|
PRTime(cachedPositionTime) )) {
|
2009-01-07 09:41:57 -08:00
|
|
|
// okay, we can return a cached position
|
2011-10-17 07:59:28 -07:00
|
|
|
mAllowed = true;
|
2012-07-26 20:33:04 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> ev = new RequestSendLocationEvent(lastPosition,
|
|
|
|
this,
|
2012-07-30 07:20:58 -07:00
|
|
|
mIsWatchPositionRequest ? nullptr : mLocator);
|
2010-08-31 09:15:52 -07:00
|
|
|
NS_DispatchToMainThread(ev);
|
2009-01-07 09:41:57 -08:00
|
|
|
}
|
2008-08-14 09:35:49 -07:00
|
|
|
|
2010-08-31 09:15:52 -07:00
|
|
|
SetTimeoutTimer();
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mAllowed = true;
|
2010-08-31 09:15:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGeolocationRequest::SetTimeoutTimer()
|
|
|
|
{
|
|
|
|
if (mTimeoutTimer) {
|
|
|
|
mTimeoutTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mTimeoutTimer = nullptr;
|
2010-08-31 09:15:52 -07:00
|
|
|
}
|
2012-07-26 20:33:04 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t timeout;
|
2012-04-16 12:08:48 -07:00
|
|
|
if (mOptions && (timeout = mOptions->timeout) != 0) {
|
2012-04-13 00:28:00 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (timeout < 0) {
|
2012-04-13 00:28:00 -07:00
|
|
|
timeout = 0;
|
2012-07-26 20:33:04 -07:00
|
|
|
} else if (timeout < 10) {
|
2009-01-07 09:41:57 -08:00
|
|
|
timeout = 10;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2009-01-07 09:41:57 -08:00
|
|
|
mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
mTimeoutTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGeolocationRequest::MarkCleared()
|
|
|
|
{
|
2011-01-04 13:25:04 -08:00
|
|
|
if (mTimeoutTimer) {
|
|
|
|
mTimeoutTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mTimeoutTimer = nullptr;
|
2011-01-04 13:25:04 -08:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mCleared = true;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-20 12:37:10 -07:00
|
|
|
nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mCleared || !mAllowed) {
|
2008-07-15 16:37:48 -07:00
|
|
|
return;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2010-08-31 09:15:52 -07:00
|
|
|
if (mTimeoutTimer) {
|
|
|
|
mTimeoutTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mTimeoutTimer = nullptr;
|
2010-08-31 09:15:52 -07:00
|
|
|
}
|
|
|
|
|
2008-11-12 08:05:32 -08:00
|
|
|
// we should not pass null back to the DOM.
|
|
|
|
if (!aPosition) {
|
|
|
|
NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-09-10 08:52:46 -07:00
|
|
|
// Ensure that the proper context is on the stack (bug 452762)
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
2012-07-30 07:20:58 -07:00
|
|
|
if (!stack || NS_FAILED(stack->Push(nullptr))) {
|
2008-09-10 08:52:46 -07:00
|
|
|
return; // silently fail
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-03-31 09:30:13 -07:00
|
|
|
|
|
|
|
nsAutoMicroTask mt;
|
2008-11-12 08:04:18 -08:00
|
|
|
mCallback->HandleEvent(aPosition);
|
2008-09-10 08:52:46 -07:00
|
|
|
|
|
|
|
// remove the stack
|
|
|
|
JSContext* cx;
|
|
|
|
stack->Pop(&cx);
|
2008-10-20 12:37:10 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mIsWatchPositionRequest) {
|
2011-01-31 14:11:45 -08:00
|
|
|
SetTimeoutTimer();
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2011-10-03 08:44:00 -07:00
|
|
|
bool
|
2012-11-06 12:34:03 -08:00
|
|
|
nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition, bool aIsBetter)
|
2011-01-04 13:25:04 -08:00
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!mAllowed) {
|
2011-10-03 08:44:00 -07:00
|
|
|
return false;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-11-06 12:34:03 -08:00
|
|
|
// 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
|
2012-12-23 19:05:37 -08:00
|
|
|
nsCOMPtr<nsIRunnable> ev;
|
2012-11-06 12:34:03 -08:00
|
|
|
if (mIsFirstUpdate || aIsBetter) {
|
|
|
|
mIsFirstUpdate = false;
|
2012-12-23 19:05:37 -08:00
|
|
|
ev = new RequestSendLocationEvent(aPosition,
|
|
|
|
this,
|
|
|
|
mIsWatchPositionRequest ? nullptr : mLocator);
|
|
|
|
} else {
|
|
|
|
ev = new RequestRestartTimerEvent(this);
|
2012-11-06 12:34:03 -08:00
|
|
|
}
|
2012-12-23 19:05:37 -08:00
|
|
|
NS_DispatchToMainThread(ev);
|
2011-10-03 08:44:00 -07:00
|
|
|
return true;
|
2011-01-04 13:25:04 -08:00
|
|
|
}
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
void
|
|
|
|
nsGeolocationRequest::Shutdown()
|
|
|
|
{
|
2012-04-16 12:08:48 -07:00
|
|
|
if (mOptions && mOptions->enableHighAccuracy) {
|
2012-11-08 15:36:50 -08:00
|
|
|
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
|
|
|
if (gs) {
|
|
|
|
gs->SetHigherAccuracy(false);
|
2012-04-16 12:08:48 -07:00
|
|
|
}
|
2012-03-21 10:52:35 -07:00
|
|
|
}
|
|
|
|
|
2010-08-23 19:09:00 -07:00
|
|
|
if (mTimeoutTimer) {
|
|
|
|
mTimeoutTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mTimeoutTimer = nullptr;
|
2010-08-23 19:09:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mCleared = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCallback = nullptr;
|
|
|
|
mErrorCallback = nullptr;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2010-05-13 10:44:51 -07:00
|
|
|
bool nsGeolocationRequest::Recv__delete__(const bool& allow)
|
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (allow) {
|
2010-05-13 10:44:51 -07:00
|
|
|
(void) Allow();
|
2012-07-26 20:33:04 -07:00
|
|
|
} else {
|
2010-05-13 10:44:51 -07:00
|
|
|
(void) Cancel();
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-05-13 10:44:51 -07:00
|
|
|
return true;
|
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
////////////////////////////////////////////////////
|
2008-08-14 09:35:49 -07:00
|
|
|
// nsGeolocationService
|
2008-07-15 16:37:48 -07:00
|
|
|
////////////////////////////////////////////////////
|
2008-08-14 09:35:49 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGeolocationService)
|
2008-07-15 16:37:48 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGeolocationUpdate)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGeolocationUpdate)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2008-08-14 09:35:49 -07:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsGeolocationService)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsGeolocationService)
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2009-05-06 18:25:44 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sGeoEnabled = true;
|
2012-10-31 17:19:34 -07:00
|
|
|
static bool sGeoInitPending = true;
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sGeoIgnoreLocationFilter = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t sProviderTimeout = 6000; // Time, in milliseconds, to wait for the location provider to spin up.
|
2010-08-31 09:15:52 -07:00
|
|
|
|
2009-08-28 10:40:27 -07:00
|
|
|
nsresult nsGeolocationService::Init()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-01-09 12:27:43 -08:00
|
|
|
Preferences::AddIntVarCache(&sProviderTimeout, "geo.timeout", sProviderTimeout);
|
|
|
|
Preferences::AddBoolVarCache(&sGeoEnabled, "geo.enabled", sGeoEnabled);
|
|
|
|
Preferences::AddBoolVarCache(&sGeoIgnoreLocationFilter, "geo.ignore.location_filter", sGeoIgnoreLocationFilter);
|
2009-05-06 18:25:44 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!sGeoEnabled) {
|
2009-08-28 10:40:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-04-14 09:10:20 -07:00
|
|
|
|
2012-11-06 10:42:27 -08:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
sGeoInitPending = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-10 17:04:39 -07:00
|
|
|
nsCOMPtr<nsIGeolocationProvider> provider = do_GetService(NS_GEOLOCATION_PROVIDER_CONTRACTID);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (provider) {
|
2009-07-10 17:04:39 -07:00
|
|
|
mProviders.AppendObject(provider);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-07-10 17:04:39 -07:00
|
|
|
|
|
|
|
// look up any providers that were registered via the category manager
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan(do_GetService("@mozilla.org/categorymanager;1"));
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!catMan) {
|
2009-08-28 10:40:27 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-07-10 17:04:39 -07:00
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
// check if the geolocation service is enable from settings
|
|
|
|
nsCOMPtr<nsISettingsService> settings =
|
|
|
|
do_GetService("@mozilla.org/settingsService;1");
|
|
|
|
|
|
|
|
if (settings) {
|
|
|
|
nsCOMPtr<nsISettingsServiceLock> settingsLock;
|
|
|
|
nsresult rv = settings->CreateLock(getter_AddRefs(settingsLock));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsRefPtr<GeolocationSettingsCallback> callback = new GeolocationSettingsCallback();
|
|
|
|
rv = settingsLock->Get(GEO_SETINGS_ENABLED, callback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// If we cannot obtain the settings service, we continue
|
|
|
|
// assuming that the geolocation is enabled:
|
|
|
|
sGeoInitPending = false;
|
|
|
|
}
|
|
|
|
|
2009-10-25 22:50:16 -07:00
|
|
|
// geolocation service can be enabled -> now register observer
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!obs) {
|
2009-10-25 22:50:16 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-10-25 22:50:16 -07:00
|
|
|
|
|
|
|
obs->AddObserver(this, "quit-application", false);
|
2012-07-26 20:19:01 -07:00
|
|
|
obs->AddObserver(this, "mozsettings-changed", false);
|
2009-10-25 22:50:16 -07:00
|
|
|
|
2009-07-10 17:04:39 -07:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> geoproviders;
|
|
|
|
catMan->EnumerateCategory("geolocation-provider", getter_AddRefs(geoproviders));
|
|
|
|
if (geoproviders) {
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasMore;
|
2009-07-10 17:04:39 -07:00
|
|
|
while (NS_SUCCEEDED(geoproviders->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> elem;
|
|
|
|
geoproviders->GetNext(getter_AddRefs(elem));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsCString> elemString = do_QueryInterface(elem);
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString name;
|
2009-07-10 17:04:39 -07:00
|
|
|
elemString->GetData(name);
|
|
|
|
|
|
|
|
nsXPIDLCString spec;
|
|
|
|
catMan->GetCategoryEntry("geolocation-provider", name.get(), getter_Copies(spec));
|
|
|
|
|
|
|
|
provider = do_GetService(spec);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (provider) {
|
2009-07-10 17:04:39 -07:00
|
|
|
mProviders.AppendObject(provider);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-07-10 17:04:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we should move these providers outside of this file! dft
|
|
|
|
|
2010-04-14 02:42:43 -07:00
|
|
|
#ifdef MOZ_MAEMO_LIBLOCATION
|
2010-04-02 00:56:22 -07:00
|
|
|
provider = new MaemoLocationProvider();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (provider) {
|
2010-04-02 00:56:22 -07:00
|
|
|
mProviders.AppendObject(provider);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-04-02 00:56:22 -07:00
|
|
|
#endif
|
2010-06-04 14:14:43 -07:00
|
|
|
|
2011-08-15 17:25:43 -07:00
|
|
|
#ifdef MOZ_ENABLE_QTMOBILITY
|
|
|
|
provider = new QTMLocationProvider();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (provider) {
|
2011-08-15 17:25:43 -07:00
|
|
|
mProviders.AppendObject(provider);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2011-08-15 17:25:43 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2010-06-04 14:14:43 -07:00
|
|
|
provider = new AndroidLocationProvider();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (provider) {
|
2010-06-04 14:14:43 -07:00
|
|
|
mProviders.AppendObject(provider);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-06-04 14:14:43 -07:00
|
|
|
#endif
|
2012-01-19 06:53:51 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2012-10-14 23:40:51 -07:00
|
|
|
provider = do_GetService(GONK_GPS_GEOLOCATION_PROVIDER_CONTRACTID);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (provider) {
|
2012-01-19 06:53:51 -08:00
|
|
|
mProviders.AppendObject(provider);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-01-19 06:53:51 -08:00
|
|
|
#endif
|
|
|
|
|
2009-08-28 10:40:27 -07:00
|
|
|
return NS_OK;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2008-08-14 09:35:49 -07:00
|
|
|
nsGeolocationService::~nsGeolocationService()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-07-26 20:19:01 -07:00
|
|
|
void
|
|
|
|
nsGeolocationService::HandleMozsettingChanged(const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
// The string that we're interested in will be a JSON string that looks like:
|
|
|
|
// {"key":"gelocation.enabled","value":true}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThreadJSContextStack> stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
|
|
|
if (!stack) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSContext *cx = stack->GetSafeJSContext();
|
|
|
|
if (!cx) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentString dataStr(aData);
|
|
|
|
JS::Value val;
|
|
|
|
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), &val) || !val.isObject()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject &obj(val.toObject());
|
|
|
|
JS::Value key;
|
|
|
|
if (!JS_GetProperty(cx, &obj, "key", &key) || !key.isString()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSBool match;
|
2012-10-31 17:19:34 -07:00
|
|
|
if (!JS_StringEqualsAscii(cx, key.toString(), GEO_SETINGS_ENABLED, &match) || (match != JS_TRUE)) {
|
2012-07-26 20:19:01 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
JS::Value value;
|
|
|
|
if (!JS_GetProperty(cx, &obj, "value", &value) || !value.isBoolean()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
HandleMozsettingValue(value.toBoolean());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGeolocationService::HandleMozsettingValue(const bool aValue)
|
|
|
|
{
|
|
|
|
if (!aValue) {
|
2012-12-03 02:25:55 -08:00
|
|
|
// turn things off
|
2012-07-26 20:19:01 -07:00
|
|
|
StopDevice();
|
2012-07-30 07:20:58 -07:00
|
|
|
Update(nullptr);
|
|
|
|
mLastPosition = nullptr;
|
2012-07-26 20:19:01 -07:00
|
|
|
sGeoEnabled = false;
|
2012-07-26 20:33:04 -07:00
|
|
|
} else {
|
2012-07-26 20:19:01 -07:00
|
|
|
sGeoEnabled = true;
|
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
|
|
|
if (sGeoInitPending) {
|
2012-11-13 15:03:06 -08:00
|
|
|
sGeoInitPending = false;
|
2012-10-31 17:19:34 -07:00
|
|
|
for (uint32_t i = 0, length = mGeolocators.Length(); i < length; ++i) {
|
|
|
|
mGeolocators[i]->ServiceReady();
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 20:19:01 -07:00
|
|
|
}
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
NS_IMETHODIMP
|
2008-10-20 12:37:10 -07:00
|
|
|
nsGeolocationService::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!strcmp("quit-application", aTopic)) {
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2008-07-15 16:37:48 -07:00
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, "quit-application");
|
2012-07-26 20:19:01 -07:00
|
|
|
obs->RemoveObserver(this, "mozsettings-changed");
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i< mGeolocators.Length(); i++) {
|
2008-07-15 16:37:48 -07:00
|
|
|
mGeolocators[i]->Shutdown();
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
StopDevice();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-07-26 20:19:01 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!strcmp("mozsettings-changed", aTopic)) {
|
2012-07-26 20:19:01 -07:00
|
|
|
HandleMozsettingChanged(aData);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!strcmp("timer-callback", aTopic)) {
|
2008-07-15 16:37:48 -07:00
|
|
|
// decide if we can close down the service.
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i< mGeolocators.Length(); i++)
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mGeolocators[i]->HasActiveCallbacks()) {
|
2008-07-15 16:37:48 -07:00
|
|
|
SetDisconnectTimer();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
// okay to close up.
|
|
|
|
StopDevice();
|
2012-07-30 07:20:58 -07:00
|
|
|
Update(nullptr);
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-10-20 12:37:10 -07:00
|
|
|
nsGeolocationService::Update(nsIDOMGeoPosition *aSomewhere)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-11-06 12:34:03 -08:00
|
|
|
// here we have to determine this aSomewhere is a "better"
|
|
|
|
// position than any previously recv'ed.
|
|
|
|
|
|
|
|
bool isBetter = IsBetterPosition(aSomewhere);
|
|
|
|
|
|
|
|
if (isBetter) {
|
|
|
|
SetCachedPosition(aSomewhere);
|
|
|
|
}
|
2009-07-10 17:04:39 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i< mGeolocators.Length(); i++) {
|
2012-11-06 12:34:03 -08:00
|
|
|
mGeolocators[i]->Update(aSomewhere, isBetter);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-06 12:34:03 -08:00
|
|
|
PRBool
|
|
|
|
nsGeolocationService::IsBetterPosition(nsIDOMGeoPosition *aSomewhere)
|
|
|
|
{
|
|
|
|
if (!aSomewhere) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-23 19:05:37 -08:00
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-06 12:34:03 -08:00
|
|
|
if (mProviders.Count() == 1 || !mLastPosition) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMGeoPositionCoords> coords;
|
|
|
|
mLastPosition->GetCoords(getter_AddRefs(coords));
|
|
|
|
if (!coords) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double oldAccuracy;
|
|
|
|
nsresult rv = coords->GetAccuracy(&oldAccuracy);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
double oldLat, oldLon;
|
|
|
|
rv = coords->GetLongitude(&oldLon);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
rv = coords->GetLatitude(&oldLat);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
aSomewhere->GetCoords(getter_AddRefs(coords));
|
|
|
|
if (!coords) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
double newAccuracy;
|
|
|
|
rv = coords->GetAccuracy(&newAccuracy);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
double newLat, newLon;
|
|
|
|
rv = coords->GetLongitude(&newLon);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
rv = coords->GetLatitude(&newLat);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
// Latitude and longitude is reported in degrees.
|
|
|
|
// However, it is easier to work in radian:
|
|
|
|
// see: http://en.wikipedia.org/wiki/Radian
|
|
|
|
double radsInDeg = M_PI / 180.0;
|
|
|
|
|
|
|
|
newLat *= radsInDeg;
|
|
|
|
newLon *= radsInDeg;
|
|
|
|
oldLat *= radsInDeg;
|
|
|
|
oldLon *= radsInDeg;
|
|
|
|
|
|
|
|
// WGS84 equatorial radius of earth = 6378137m
|
|
|
|
// http://en.wikipedia.org/wiki/WGS84
|
|
|
|
double radius = 6378137;
|
|
|
|
|
|
|
|
// We want to calculate the "Great Circle distance"
|
|
|
|
// between the point (lat1, lon1) and (lat2, lon2). We
|
|
|
|
// will use the spherical law of cosines to the triangle
|
|
|
|
// formed by our two points and the north pole.
|
|
|
|
//
|
|
|
|
// a = sin ( lat1 ) * sin ( lat2 ) + cos ( lat1 ) * cos (lat2) * cos (lon1 - lon2)
|
|
|
|
// R = radius of circle
|
|
|
|
// distance = arccos ( a ) * R
|
|
|
|
//
|
|
|
|
// http://en.wikipedia.org/wiki/Great-circle_distance
|
|
|
|
|
|
|
|
double delta = acos( (sin(newLat) * sin(oldLat)) +
|
|
|
|
(cos(newLat) * cos(oldLat) * cos(oldLon - newLon)) ) * radius;
|
|
|
|
|
|
|
|
// The threshold is when the distance between the two
|
|
|
|
// positions exceeds the worse (larger value) of the two
|
|
|
|
// accuracies.
|
|
|
|
double max_accuracy = NS_MAX(oldAccuracy, newAccuracy);
|
|
|
|
if (delta > max_accuracy)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// check to see if the aSomewhere position is more accurate
|
|
|
|
if (oldAccuracy >= newAccuracy)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-05 08:29:43 -08:00
|
|
|
void
|
|
|
|
nsGeolocationService::SetCachedPosition(nsIDOMGeoPosition* aPosition)
|
|
|
|
{
|
|
|
|
mLastPosition = aPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMGeoPosition*
|
|
|
|
nsGeolocationService::GetCachedPosition()
|
|
|
|
{
|
|
|
|
return mLastPosition;
|
|
|
|
}
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
nsresult
|
2012-12-06 18:13:15 -08:00
|
|
|
nsGeolocationService::StartDevice(bool aRequestPrivate)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-10-31 17:19:34 -07:00
|
|
|
if (!sGeoEnabled || sGeoInitPending) {
|
2009-05-06 18:25:44 -07:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-05-06 18:25:44 -07:00
|
|
|
|
2010-09-27 14:23:35 -07:00
|
|
|
// we do not want to keep the geolocation devices online
|
|
|
|
// indefinitely. Close them down after a reasonable period of
|
|
|
|
// inactivivity
|
|
|
|
SetDisconnectTimer();
|
|
|
|
|
2010-09-20 21:16:37 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
ContentChild* cpc = ContentChild::GetSingleton();
|
2010-11-05 10:43:13 -07:00
|
|
|
cpc->SendAddGeolocationListener();
|
2010-09-20 21:16:37 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-07-10 17:04:39 -07:00
|
|
|
// Start them up!
|
2010-09-27 14:23:35 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!obs) {
|
2010-09-27 14:23:35 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-09-27 14:23:35 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < mProviders.Count(); i++) {
|
2010-09-27 14:23:35 -07:00
|
|
|
mProviders[i]->Startup();
|
2012-12-06 18:13:15 -08:00
|
|
|
mProviders[i]->Watch(this, aRequestPrivate);
|
2010-09-27 14:23:35 -07:00
|
|
|
obs->NotifyObservers(mProviders[i],
|
|
|
|
"geolocation-device-events",
|
|
|
|
NS_LITERAL_STRING("starting").get());
|
2009-07-10 17:04:39 -07:00
|
|
|
}
|
2010-10-14 09:12:57 -07:00
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-08-14 09:35:49 -07:00
|
|
|
nsGeolocationService::SetDisconnectTimer()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!mDisconnectTimer) {
|
2008-07-15 16:37:48 -07:00
|
|
|
mDisconnectTimer = do_CreateInstance("@mozilla.org/timer;1");
|
2012-07-26 20:33:04 -07:00
|
|
|
} else {
|
2008-07-15 16:37:48 -07:00
|
|
|
mDisconnectTimer->Cancel();
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
|
|
|
mDisconnectTimer->Init(this,
|
2012-01-09 12:27:43 -08:00
|
|
|
sProviderTimeout,
|
2008-07-15 16:37:48 -07:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
2012-03-21 10:52:35 -07:00
|
|
|
void
|
|
|
|
nsGeolocationService::SetHigherAccuracy(bool aEnable)
|
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!mHigherAccuracy && aEnable) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < mProviders.Count(); i++) {
|
2012-07-26 20:33:04 -07:00
|
|
|
mProviders[i]->SetHighAccuracy(true);
|
2012-03-21 10:52:35 -07:00
|
|
|
}
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mHigherAccuracy && !aEnable) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < mProviders.Count(); i++) {
|
2012-07-26 20:33:04 -07:00
|
|
|
mProviders[i]->SetHighAccuracy(false);
|
2012-03-21 10:52:35 -07:00
|
|
|
}
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-03-21 10:52:35 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
mHigherAccuracy = aEnable;
|
2012-03-21 10:52:35 -07:00
|
|
|
}
|
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
void
|
2008-08-14 09:35:49 -07:00
|
|
|
nsGeolocationService::StopDevice()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
|
|
|
if(mDisconnectTimer) {
|
|
|
|
mDisconnectTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mDisconnectTimer = nullptr;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
2010-09-20 21:16:37 -07:00
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
ContentChild* cpc = ContentChild::GetSingleton();
|
2010-11-05 10:43:13 -07:00
|
|
|
cpc->SendRemoveGeolocationListener();
|
2010-09-20 21:16:37 -07:00
|
|
|
return; // bail early
|
|
|
|
}
|
|
|
|
|
2010-09-27 14:23:35 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!obs) {
|
2010-09-27 14:23:35 -07:00
|
|
|
return;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-09-27 14:23:35 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < mProviders.Count(); i++) {
|
2010-09-20 21:16:37 -07:00
|
|
|
mProviders[i]->Shutdown();
|
2010-09-27 14:23:35 -07:00
|
|
|
obs->NotifyObservers(mProviders[i],
|
|
|
|
"geolocation-device-events",
|
|
|
|
NS_LITERAL_STRING("shutdown").get());
|
2010-09-20 21:16:37 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2012-11-08 15:36:50 -08:00
|
|
|
nsRefPtr<nsGeolocationService> nsGeolocationService::sService;
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2012-11-08 15:36:50 -08:00
|
|
|
already_AddRefed<nsGeolocationService>
|
|
|
|
nsGeolocationService::GetGeolocationService()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-11-08 15:36:50 -08:00
|
|
|
nsRefPtr<nsGeolocationService> result;
|
|
|
|
if (nsGeolocationService::sService) {
|
|
|
|
result = nsGeolocationService::sService;
|
|
|
|
return result.forget();
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2012-11-08 15:36:50 -08:00
|
|
|
result = new nsGeolocationService();
|
|
|
|
if (NS_FAILED(result->Init())) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
ClearOnShutdown(&nsGeolocationService::sService);
|
|
|
|
nsGeolocationService::sService = result;
|
|
|
|
return result.forget();
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-20 12:37:10 -07:00
|
|
|
nsGeolocationService::AddLocator(nsGeolocation* aLocator)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2008-10-20 12:37:10 -07:00
|
|
|
mGeolocators.AppendElement(aLocator);
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-20 12:37:10 -07:00
|
|
|
nsGeolocationService::RemoveLocator(nsGeolocation* aLocator)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2008-10-20 12:37:10 -07:00
|
|
|
mGeolocators.RemoveElement(aLocator);
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
2008-08-14 09:35:49 -07:00
|
|
|
// nsGeolocation
|
2008-07-15 16:37:48 -07:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(GeoGeolocation, nsGeolocation)
|
|
|
|
|
2009-01-14 17:10:46 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGeolocation)
|
2008-08-14 09:35:49 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoGeolocation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoGeolocation)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(GeoGeolocation)
|
2008-07-15 16:37:48 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2009-01-14 17:10:46 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGeolocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsGeolocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGeolocation)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGeolocation)
|
2012-10-31 17:19:34 -07:00
|
|
|
tmp->mPendingRequests.Clear();
|
2009-01-14 17:10:46 -08:00
|
|
|
tmp->mPendingCallbacks.Clear();
|
|
|
|
tmp->mWatchingCallbacks.Clear();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGeolocation)
|
2012-10-31 17:19:34 -07:00
|
|
|
uint32_t i;
|
|
|
|
for (i = 0; i < tmp->mPendingRequests.Length(); ++i)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingRequests[i].request)
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2009-01-14 17:10:46 -08:00
|
|
|
for (i = 0; i < tmp->mPendingCallbacks.Length(); ++i)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingCallbacks[i])
|
2009-01-14 17:10:46 -08:00
|
|
|
|
|
|
|
for (i = 0; i < tmp->mWatchingCallbacks.Length(); ++i)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWatchingCallbacks[i])
|
2009-01-14 17:10:46 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
nsGeolocation::nsGeolocation()
|
|
|
|
: mLastWatchId(0)
|
2009-11-12 07:14:45 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGeolocation::~nsGeolocation()
|
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mService) {
|
2009-11-12 07:14:45 -08:00
|
|
|
Shutdown();
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-11-12 07:14:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGeolocation::Init(nsIDOMWindow* aContentDom)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
|
|
|
// Remember the window
|
2009-11-12 07:14:45 -08:00
|
|
|
if (aContentDom) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aContentDom);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!window) {
|
2009-11-12 07:14:45 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-11-12 07:14:45 -08:00
|
|
|
|
2009-07-10 17:02:32 -07:00
|
|
|
mOwner = do_GetWeakReference(window->GetCurrentInnerWindow());
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!mOwner) {
|
2009-11-12 07:14:45 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-11-12 07:14:45 -08:00
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
// Grab the principal of the document
|
2009-11-12 07:14:45 -08:00
|
|
|
nsCOMPtr<nsIDOMDocument> domdoc;
|
|
|
|
aContentDom->GetDocument(getter_AddRefs(domdoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!doc) {
|
2009-11-12 07:14:45 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2012-07-30 07:58:26 -07:00
|
|
|
mPrincipal = doc->NodePrincipal();
|
2009-11-12 07:14:45 -08:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2009-11-12 07:14:45 -08:00
|
|
|
// If no aContentDom was passed into us, we are being used
|
2012-07-30 07:58:26 -07:00
|
|
|
// by chrome/c++ and have no mOwner, no mPrincipal, and no need
|
2009-11-12 07:14:45 -08:00
|
|
|
// to prompt.
|
2012-11-08 15:36:50 -08:00
|
|
|
mService = nsGeolocationService::GetGeolocationService();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mService) {
|
2008-07-15 16:37:48 -07:00
|
|
|
mService->AddLocator(this);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-11-12 09:17:21 -08:00
|
|
|
return NS_OK;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-08-14 09:35:49 -07:00
|
|
|
nsGeolocation::Shutdown()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
|
|
|
// Shutdown and release all callbacks
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i< mPendingCallbacks.Length(); i++)
|
2008-07-15 16:37:48 -07:00
|
|
|
mPendingCallbacks[i]->Shutdown();
|
|
|
|
mPendingCallbacks.Clear();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i< mWatchingCallbacks.Length(); i++)
|
2008-07-15 16:37:48 -07:00
|
|
|
mWatchingCallbacks[i]->Shutdown();
|
|
|
|
mWatchingCallbacks.Clear();
|
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mService) {
|
2008-07-15 16:37:48 -07:00
|
|
|
mService->RemoveLocator(this);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mService = nullptr;
|
2012-07-30 07:58:26 -07:00
|
|
|
mPrincipal = nullptr;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-08-14 09:35:49 -07:00
|
|
|
nsGeolocation::HasActiveCallbacks()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mWatchingCallbacks.Length(); i++) {
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mWatchingCallbacks[i]->IsActive()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
|
|
|
}
|
2010-09-27 14:23:35 -07:00
|
|
|
|
2012-01-09 12:27:06 -08:00
|
|
|
return mPendingCallbacks.Length() != 0;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-10-20 12:37:10 -07:00
|
|
|
nsGeolocation::RemoveRequest(nsGeolocationRequest* aRequest)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2008-10-20 12:37:10 -07:00
|
|
|
mPendingCallbacks.RemoveElement(aRequest);
|
2008-07-15 16:37:48 -07:00
|
|
|
|
|
|
|
// if it is in the mWatchingCallbacks, we can't do much
|
|
|
|
// since we passed back the position in the array to who
|
|
|
|
// ever called WatchPosition() and we do not want to mess
|
|
|
|
// around with the ordering of the array. Instead, just
|
|
|
|
// mark the request as "cleared".
|
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
aRequest->MarkCleared();
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-06 12:34:03 -08:00
|
|
|
nsGeolocation::Update(nsIDOMGeoPosition *aSomewhere, bool aIsBetter)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!WindowOwnerStillExists()) {
|
2010-08-31 09:15:52 -07:00
|
|
|
return Shutdown();
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-08-04 17:36:54 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = mPendingCallbacks.Length(); i> 0; i--) {
|
2012-11-06 12:34:03 -08:00
|
|
|
if (mPendingCallbacks[i-1]->Update(aSomewhere, aIsBetter)) {
|
2011-10-03 08:44:00 -07:00
|
|
|
mPendingCallbacks.RemoveElementAt(i-1);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-08-31 09:15:52 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
|
|
|
// notify everyone that is watching
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i< mWatchingCallbacks.Length(); i++) {
|
2012-11-06 12:34:03 -08:00
|
|
|
mWatchingCallbacks[i]->Update(aSomewhere, aIsBetter);
|
2010-08-31 09:15:52 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-08-14 09:35:49 -07:00
|
|
|
nsGeolocation::GetCurrentPosition(nsIDOMGeoPositionCallback *callback,
|
|
|
|
nsIDOMGeoPositionErrorCallback *errorCallback,
|
2012-04-16 12:08:48 -07:00
|
|
|
const jsval& options,
|
|
|
|
JSContext* cx)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2009-07-16 10:03:49 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(callback);
|
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mPendingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW) {
|
2008-11-12 08:00:37 -08:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-11-12 08:00:37 -08:00
|
|
|
|
2011-01-31 14:11:45 -08:00
|
|
|
nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
|
2012-07-26 20:33:04 -07:00
|
|
|
callback,
|
|
|
|
errorCallback,
|
|
|
|
false);
|
|
|
|
if (!request) {
|
2008-10-20 12:37:10 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-10-20 12:37:10 -07:00
|
|
|
|
2012-04-16 12:08:48 -07:00
|
|
|
nsresult rv = request->Init(cx, options);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-12 07:14:45 -08:00
|
|
|
|
2012-07-26 20:19:01 -07:00
|
|
|
if (!sGeoEnabled) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev = new RequestAllowEvent(false, request);
|
|
|
|
NS_DispatchToMainThread(ev);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
if (!mOwner && !nsContentUtils::IsCallerChrome()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingCallbacks.AppendElement(request);
|
|
|
|
|
|
|
|
if (sGeoInitPending) {
|
|
|
|
PendingRequest req = { request, PendingRequest::GetCurrentPosition };
|
|
|
|
mPendingRequests.AppendElement(req);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetCurrentPositionReady(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGeolocation::GetCurrentPositionReady(nsGeolocationRequest* aRequest)
|
|
|
|
{
|
2009-11-12 07:14:45 -08:00
|
|
|
if (mOwner) {
|
2012-10-31 17:19:34 -07:00
|
|
|
if (!RegisterRequestWithPrompt(aRequest)) {
|
2011-01-06 09:50:10 -08:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2008-11-12 07:59:38 -08:00
|
|
|
return NS_OK;
|
2009-11-12 07:14:45 -08:00
|
|
|
}
|
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2009-11-12 07:14:45 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-11-12 07:59:38 -08:00
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
nsCOMPtr<nsIRunnable> ev = new RequestAllowEvent(true, aRequest);
|
2010-08-31 09:15:52 -07:00
|
|
|
NS_DispatchToMainThread(ev);
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-11-12 07:14:45 -08:00
|
|
|
nsGeolocation::WatchPosition(nsIDOMGeoPositionCallback *callback,
|
|
|
|
nsIDOMGeoPositionErrorCallback *errorCallback,
|
2012-04-16 12:08:48 -07:00
|
|
|
const jsval& options,
|
|
|
|
JSContext* cx,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t *_retval)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2009-11-12 07:14:45 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(callback);
|
2009-05-06 18:25:44 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mPendingCallbacks.Length() > MAX_GEO_REQUESTS_PER_WINDOW) {
|
2008-11-12 08:00:37 -08:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-11-12 08:00:37 -08:00
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
// The watch ID:
|
|
|
|
*_retval = mLastWatchId++;
|
|
|
|
|
2011-01-31 14:11:45 -08:00
|
|
|
nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
|
2012-07-26 20:33:04 -07:00
|
|
|
callback,
|
|
|
|
errorCallback,
|
2012-10-31 17:19:34 -07:00
|
|
|
true,
|
|
|
|
*_retval);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!request) {
|
2008-10-20 12:37:10 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-10-20 12:37:10 -07:00
|
|
|
|
2012-04-16 12:08:48 -07:00
|
|
|
nsresult rv = request->Init(cx, options);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-12 07:14:45 -08:00
|
|
|
|
2012-07-26 20:19:01 -07:00
|
|
|
if (!sGeoEnabled) {
|
|
|
|
nsCOMPtr<nsIRunnable> ev = new RequestAllowEvent(false, request);
|
|
|
|
|
|
|
|
// need to hand back an index/reference.
|
|
|
|
mWatchingCallbacks.AppendElement(request);
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(ev);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
if (!mOwner && !nsContentUtils::IsCallerChrome()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWatchingCallbacks.AppendElement(request);
|
|
|
|
|
|
|
|
if (sGeoInitPending) {
|
|
|
|
PendingRequest req = { request, PendingRequest::WatchPosition };
|
|
|
|
mPendingRequests.AppendElement(req);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WatchPositionReady(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGeolocation::WatchPositionReady(nsGeolocationRequest* aRequest)
|
|
|
|
{
|
2012-07-26 20:33:04 -07:00
|
|
|
if (mOwner) {
|
2012-10-31 17:19:34 -07:00
|
|
|
if (!RegisterRequestWithPrompt(aRequest))
|
2011-01-06 09:50:10 -08:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2009-11-12 07:14:45 -08:00
|
|
|
|
2008-11-12 07:59:38 -08:00
|
|
|
return NS_OK;
|
2009-11-12 07:14:45 -08:00
|
|
|
}
|
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!nsContentUtils::IsCallerChrome()) {
|
2009-11-12 07:14:45 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-11-12 07:59:38 -08:00
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
aRequest->Allow();
|
2009-11-12 07:14:45 -08:00
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGeolocation::ClearWatch(int32_t aWatchId)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2012-10-31 17:19:34 -07:00
|
|
|
if (aWatchId < 0) {
|
2009-11-13 09:19:45 -08:00
|
|
|
return NS_OK;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-11-12 08:01:40 -08:00
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
for (uint32_t i = 0, length = mWatchingCallbacks.Length(); i < length; ++i) {
|
|
|
|
if (mWatchingCallbacks[i]->WatchId() == aWatchId) {
|
2012-11-20 17:26:28 -08:00
|
|
|
mWatchingCallbacks[i]->MarkCleared();
|
2012-10-31 17:19:34 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-31 17:19:34 -07:00
|
|
|
void
|
|
|
|
nsGeolocation::ServiceReady()
|
|
|
|
{
|
|
|
|
for (uint32_t length = mPendingRequests.Length(); length > 0; --length) {
|
|
|
|
switch (mPendingRequests[0].type) {
|
|
|
|
case PendingRequest::GetCurrentPosition:
|
|
|
|
GetCurrentPositionReady(mPendingRequests[0].request);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PendingRequest::WatchPosition:
|
|
|
|
WatchPositionReady(mPendingRequests[0].request);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingRequests.RemoveElementAt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-11-12 07:14:45 -08:00
|
|
|
nsGeolocation::WindowOwnerStillExists()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2009-11-12 07:14:45 -08:00
|
|
|
// an owner was never set when nsGeolocation
|
|
|
|
// was created, which means that this object
|
|
|
|
// is being used without a window.
|
2012-07-30 07:20:58 -07:00
|
|
|
if (mOwner == nullptr) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-07-10 17:02:32 -07:00
|
|
|
|
2009-11-12 07:14:45 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mOwner);
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2012-07-26 20:33:04 -07:00
|
|
|
if (window) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool closed = false;
|
2009-07-10 17:02:32 -07:00
|
|
|
window->GetClosed(&closed);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (closed) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2009-11-12 07:14:45 -08:00
|
|
|
nsPIDOMWindow* outer = window->GetOuterWindow();
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!outer || outer->GetCurrentInnerWindow() != window) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2009-11-12 07:14:45 -08:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2011-01-06 09:50:10 -08:00
|
|
|
bool
|
2010-05-13 10:44:51 -07:00
|
|
|
nsGeolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("geo.prompt.testing", false)) {
|
2012-07-26 20:33:04 -07:00
|
|
|
bool allow = Preferences::GetBool("geo.prompt.testing.allow", false);
|
|
|
|
nsCOMPtr<nsIRunnable> ev = new RequestAllowEvent(allow,
|
|
|
|
request);
|
2011-08-30 12:57:04 -07:00
|
|
|
NS_DispatchToMainThread(ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-13 10:44:51 -07:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mOwner);
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!window) {
|
2011-01-06 09:50:10 -08:00
|
|
|
return true;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2010-05-13 10:44:51 -07:00
|
|
|
|
|
|
|
// because owner implements nsITabChild, we can assume that it is
|
|
|
|
// the one and only TabChild.
|
2010-08-05 15:11:23 -07:00
|
|
|
TabChild* child = GetTabChildFrom(window->GetDocShell());
|
2012-07-26 20:33:04 -07:00
|
|
|
if (!child) {
|
2011-01-06 09:50:10 -08:00
|
|
|
return false;
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
|
|
|
|
2010-08-23 11:31:51 -07:00
|
|
|
// Retain a reference so the object isn't deleted without IPDL's knowledge.
|
2010-09-09 22:00:08 -07:00
|
|
|
// Corresponding release occurs in DeallocPContentPermissionRequest.
|
2010-08-23 11:31:51 -07:00
|
|
|
request->AddRef();
|
2012-11-13 16:06:42 -08:00
|
|
|
child->SendPContentPermissionRequestConstructor(request,
|
|
|
|
NS_LITERAL_CSTRING("geolocation"),
|
|
|
|
NS_LITERAL_CSTRING("unused"),
|
|
|
|
IPC::Principal(mPrincipal));
|
2012-07-30 07:58:26 -07:00
|
|
|
|
2010-09-09 22:00:08 -07:00
|
|
|
request->Sendprompt();
|
2011-01-06 09:50:10 -08:00
|
|
|
return true;
|
2010-05-13 10:44:51 -07:00
|
|
|
}
|
|
|
|
|
2010-08-31 09:15:52 -07:00
|
|
|
nsCOMPtr<nsIRunnable> ev = new RequestPromptEvent(request);
|
|
|
|
NS_DispatchToMainThread(ev);
|
2011-01-06 09:50:10 -08:00
|
|
|
return true;
|
2010-05-13 10:44:51 -07:00
|
|
|
}
|