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"
|
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>
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2013-04-12 11:46:36 -07:00
|
|
|
#include <limits>
|
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
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
static mozilla::idl::GeoPositionOptions*
|
|
|
|
GeoPositionOptionsFromPositionOptions(const PositionOptions& aOptions)
|
|
|
|
{
|
|
|
|
nsAutoPtr<mozilla::idl::GeoPositionOptions> geoOptions(
|
|
|
|
new mozilla::idl::GeoPositionOptions());
|
|
|
|
|
|
|
|
geoOptions->enableHighAccuracy = aOptions.mEnableHighAccuracy;
|
|
|
|
geoOptions->maximumAge = aOptions.mMaximumAge;
|
|
|
|
geoOptions->timeout = aOptions.mTimeout;
|
|
|
|
|
|
|
|
return geoOptions.forget();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-04-02 16:05:37 -07:00
|
|
|
NS_IMETHOD Handle(const nsAString& aName, const JS::Value& 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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-11 02:14:04 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(GeolocationSettingsCallback, nsISettingsServiceCallback)
|
2012-10-31 17:19:34 -07:00
|
|
|
|
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,
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation* aLocator)
|
2010-08-31 09:15:52 -07:00
|
|
|
: mPosition(aPosition),
|
|
|
|
mRequest(aRequest),
|
|
|
|
mLocator(aLocator)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2013-05-02 23:04:58 -07:00
|
|
|
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:
|
2013-04-12 11:46:36 -07:00
|
|
|
nsCOMPtr<nsIDOMGeoPosition> mPosition;
|
2010-08-31 09:15:52 -07:00
|
|
|
nsRefPtr<nsGeolocationRequest> mRequest;
|
2013-05-02 23:04:58 -07:00
|
|
|
nsRefPtr<Geolocation> mLocator;
|
2010-08-31 09:15:52 -07:00
|
|
|
};
|
|
|
|
|
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
|
|
|
////////////////////////////////////////////////////
|
2013-04-12 11:46:32 -07:00
|
|
|
// PositionError
|
2008-08-14 09:35:49 -07:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
2013-04-12 11:46:32 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PositionError)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2008-08-14 09:35:49 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoPositionError)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionError)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-04-12 11:46:32 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(PositionError, mParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(PositionError)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(PositionError)
|
2008-08-14 09:35:49 -07:00
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
PositionError::PositionError(Geolocation* aParent, int16_t aCode)
|
2008-10-20 12:37:10 -07:00
|
|
|
: mCode(aCode)
|
2013-04-12 11:46:32 -07:00
|
|
|
, mParent(aParent)
|
2008-08-14 09:35:49 -07:00
|
|
|
{
|
2013-04-12 11:46:32 -07:00
|
|
|
SetIsDOMBinding();
|
2008-08-14 09:35:49 -07:00
|
|
|
}
|
|
|
|
|
2013-04-12 11:46:32 -07:00
|
|
|
PositionError::~PositionError(){}
|
2008-08-14 09:35:49 -07:00
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-12 11:46:32 -07:00
|
|
|
PositionError::GetCode(int16_t *aCode)
|
2008-08-14 09:35:49 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCode);
|
2013-04-12 11:46:32 -07:00
|
|
|
*aCode = Code();
|
2008-08-14 09:35:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation*
|
2013-04-12 11:46:32 -07:00
|
|
|
PositionError::GetParentObject() const
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2013-04-25 09:29:54 -07:00
|
|
|
PositionError::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
2013-04-12 11:46:32 -07:00
|
|
|
{
|
|
|
|
return PositionErrorBinding::Wrap(aCx, aScope, this);
|
|
|
|
}
|
|
|
|
|
2008-10-20 12:37:10 -07:00
|
|
|
void
|
2013-04-12 11:46:36 -07:00
|
|
|
PositionError::NotifyCallback(const GeoPositionErrorCallback& aCallback)
|
2008-10-20 12:37:10 -07:00
|
|
|
{
|
|
|
|
// Ensure that the proper context is on the stack (bug 452762)
|
2013-04-18 08:36:03 -07:00
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
2012-03-31 09:30:13 -07:00
|
|
|
|
|
|
|
nsAutoMicroTask mt;
|
2013-04-12 11:46:36 -07:00
|
|
|
if (aCallback.HasWebIDLCallback()) {
|
|
|
|
PositionErrorCallback* callback = aCallback.GetWebIDLCallback();
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
ErrorResult err;
|
|
|
|
callback->Call(*this, err);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsIDOMGeoPositionErrorCallback* callback = aCallback.GetXPCOMCallback();
|
|
|
|
if (callback) {
|
|
|
|
callback->HandleEvent(this);
|
|
|
|
}
|
|
|
|
}
|
2008-10-20 12:37:10 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
// nsGeolocationRequest
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
nsGeolocationRequest::nsGeolocationRequest(Geolocation* aLocator,
|
2013-04-12 11:46:36 -07:00
|
|
|
const GeoPositionCallback& aCallback,
|
|
|
|
const GeoPositionErrorCallback& aErrorCallback,
|
2013-02-11 11:37:50 -08:00
|
|
|
mozilla::idl::GeoPositionOptions* aOptions,
|
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),
|
2011-01-31 14:11:45 -08:00
|
|
|
mIsWatchPositionRequest(aWatchPositionRequest),
|
2008-10-20 12:37:10 -07:00
|
|
|
mCallback(aCallback),
|
|
|
|
mErrorCallback(aErrorCallback),
|
2013-01-06 21:57:00 -08:00
|
|
|
mOptions(aOptions),
|
2012-10-31 17:19:34 -07:00
|
|
|
mLocator(aLocator),
|
|
|
|
mWatchId(aWatchId)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsGeolocationRequest::~nsGeolocationRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-04-12 11:46:32 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsRefPtr<PositionError> positionError = new PositionError(mLocator, 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();
|
2013-01-02 13:21:37 -08:00
|
|
|
nsresult rv = gs->StartDevice(GetPrincipal(), 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
|
|
|
}
|
2009-01-07 09:41:57 -08:00
|
|
|
}
|
2013-02-26 09:27:31 -08:00
|
|
|
gs->SetHigherAccuracy(mOptions && mOptions->enableHighAccuracy);
|
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
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
|
|
|
new RequestSendLocationEvent(
|
2013-05-02 23:04:58 -07:00
|
|
|
lastPosition, this, mIsWatchPositionRequest ? nullptr : mLocator);
|
2013-04-12 11:46:36 -07:00
|
|
|
|
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
|
2013-05-02 23:04:58 -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
|
|
|
}
|
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
nsRefPtr<Position> wrapped, cachedWrapper = mLocator->GetCachedPosition();
|
|
|
|
if (cachedWrapper && aPosition == cachedWrapper->GetWrappedGeoPosition()) {
|
|
|
|
wrapped = cachedWrapper;
|
|
|
|
} else if (aPosition) {
|
|
|
|
nsCOMPtr<nsIDOMGeoPositionCoords> coords;
|
|
|
|
aPosition->GetCoords(getter_AddRefs(coords));
|
|
|
|
if (coords) {
|
|
|
|
wrapped = new Position(mLocator, aPosition);
|
|
|
|
}
|
2013-04-12 11:46:27 -07:00
|
|
|
}
|
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
if (!wrapped) {
|
2013-04-12 11:46:27 -07:00
|
|
|
NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE);
|
2008-11-12 08:05:32 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:04:58 -07:00
|
|
|
mLocator->SetCachedPosition(wrapped);
|
2013-04-12 11:46:36 -07:00
|
|
|
|
2008-09-10 08:52:46 -07:00
|
|
|
// Ensure that the proper context is on the stack (bug 452762)
|
2013-04-18 08:36:03 -07:00
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
2012-03-31 09:30:13 -07:00
|
|
|
nsAutoMicroTask mt;
|
2013-04-12 11:46:36 -07:00
|
|
|
if (mCallback.HasWebIDLCallback()) {
|
|
|
|
ErrorResult err;
|
|
|
|
PositionCallback* callback = mCallback.GetWebIDLCallback();
|
|
|
|
|
|
|
|
MOZ_ASSERT(callback);
|
|
|
|
callback->Call(*wrapped, err);
|
|
|
|
} else {
|
|
|
|
nsIDOMGeoPositionCallback* callback = mCallback.GetXPCOMCallback();
|
|
|
|
|
|
|
|
MOZ_ASSERT(callback);
|
|
|
|
callback->HandleEvent(aPosition);
|
|
|
|
}
|
2008-09-10 08:52:46 -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
|
|
|
}
|
|
|
|
|
2013-01-02 13:21:37 -08:00
|
|
|
nsIPrincipal*
|
|
|
|
nsGeolocationRequest::GetPrincipal()
|
|
|
|
{
|
|
|
|
if (!mLocator) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mLocator->GetPrincipal();
|
|
|
|
}
|
|
|
|
|
2011-10-03 08:44:00 -07:00
|
|
|
bool
|
2013-04-29 20:22:27 -07:00
|
|
|
nsGeolocationRequest::Update(nsIDOMGeoPosition* aPosition)
|
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
|
|
|
}
|
2013-05-02 23:04:58 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> ev = new RequestSendLocationEvent(aPosition,
|
|
|
|
this,
|
|
|
|
mIsWatchPositionRequest ? nullptr : mLocator);
|
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()
|
|
|
|
{
|
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;
|
2013-02-26 09:27:31 -08:00
|
|
|
|
|
|
|
// This should happen last, to ensure that this request isn't taken into consideration
|
|
|
|
// when deciding whether existing requests still require high accuracy.
|
|
|
|
if (mOptions && mOptions->enableHighAccuracy) {
|
|
|
|
nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
|
|
|
|
if (gs) {
|
|
|
|
gs->SetHigherAccuracy(false);
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-04-14 02:42:43 -07:00
|
|
|
#ifdef MOZ_MAEMO_LIBLOCATION
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider = new MaemoLocationProvider();
|
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
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider = new QTMLocationProvider();
|
2011-08-15 17:25:43 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider = new AndroidLocationProvider();
|
2010-06-04 14:14:43 -07:00
|
|
|
#endif
|
2012-01-19 06:53:51 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider = do_GetService(GONK_GPS_GEOLOCATION_PROVIDER_CONTRACTID);
|
2012-01-19 06:53:51 -08:00
|
|
|
#endif
|
|
|
|
|
2013-04-29 20:22:27 -07:00
|
|
|
nsCOMPtr<nsIGeolocationProvider> providerOveride = do_GetService(NS_GEOLOCATION_PROVIDER_CONTRACTID);
|
|
|
|
if (providerOveride) {
|
|
|
|
mProvider = providerOveride;
|
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
|
2013-04-18 08:36:03 -07:00
|
|
|
SafeAutoJSContext cx;
|
2012-07-26 20:19:01 -07:00
|
|
|
|
|
|
|
nsDependentString dataStr(aData);
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JS::Value> val(cx);
|
|
|
|
if (!JS_ParseJSON(cx, dataStr.get(), dataStr.Length(), val.address()) || !val.isObject()) {
|
2012-07-26 20:19:01 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JSObject*> obj(cx, &val.toObject());
|
|
|
|
JS::Rooted<JS::Value> key(cx);
|
|
|
|
if (!JS_GetProperty(cx, obj, "key", key.address()) || !key.isString()) {
|
2012-07-26 20:19:01 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-04 00:52:57 -07:00
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
if (!JS_GetProperty(cx, obj, "value", value.address()) || !value.isBoolean()) {
|
2012-07-26 20:19:01 -07:00
|
|
|
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
|
|
|
{
|
2013-04-29 20:22:27 -07:00
|
|
|
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++) {
|
2013-04-29 20:22:27 -07:00
|
|
|
mGeolocators[i]->Update(aSomewhere);
|
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
|
|
|
|
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
|
2013-01-02 13:21:37 -08:00
|
|
|
nsGeolocationService::StartDevice(nsIPrincipal *aPrincipal, 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();
|
2013-02-26 09:27:31 -08:00
|
|
|
cpc->SendAddGeolocationListener(IPC::Principal(aPrincipal),
|
|
|
|
HighAccuracyRequested());
|
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
|
|
|
|
2013-04-29 20:22:27 -07:00
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-07-10 17:04:39 -07:00
|
|
|
}
|
2010-10-14 09:12:57 -07:00
|
|
|
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider->Startup();
|
|
|
|
mProvider->Watch(this, aRequestPrivate);
|
|
|
|
obs->NotifyObservers(mProvider,
|
|
|
|
"geolocation-device-events",
|
|
|
|
NS_LITERAL_STRING("starting").get());
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
bool
|
|
|
|
nsGeolocationService::HighAccuracyRequested()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mGeolocators.Length(); i++) {
|
|
|
|
if (mGeolocators[i]->HighAccuracyRequested()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-21 10:52:35 -07:00
|
|
|
void
|
|
|
|
nsGeolocationService::SetHigherAccuracy(bool aEnable)
|
|
|
|
{
|
2013-02-26 09:27:31 -08:00
|
|
|
bool highRequired = aEnable || HighAccuracyRequested();
|
|
|
|
|
2012-12-31 08:36:46 -08:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
ContentChild* cpc = ContentChild::GetSingleton();
|
2013-02-26 09:27:31 -08:00
|
|
|
cpc->SendSetGeolocationHigherAccuracy(highRequired);
|
2012-12-31 08:36:46 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
if (!mHigherAccuracy && highRequired) {
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider->SetHighAccuracy(true);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
if (mHigherAccuracy && !highRequired) {
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider->SetHighAccuracy(false);
|
2012-07-26 20:33:04 -07:00
|
|
|
}
|
2012-03-21 10:52:35 -07:00
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
mHigherAccuracy = highRequired;
|
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
|
|
|
|
2013-04-29 20:22:27 -07:00
|
|
|
if (!mProvider) {
|
|
|
|
return;
|
2010-09-20 21:16:37 -07:00
|
|
|
}
|
2013-04-29 20:22:27 -07:00
|
|
|
|
2013-04-29 20:22:30 -07:00
|
|
|
mHigherAccuracy = false;
|
|
|
|
|
2013-04-29 20:22:27 -07:00
|
|
|
mProvider->Shutdown();
|
|
|
|
obs->NotifyObservers(mProvider,
|
|
|
|
"geolocation-device-events",
|
|
|
|
NS_LITERAL_STRING("shutdown").get());
|
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
|
2013-04-12 11:47:47 -07:00
|
|
|
nsGeolocationService::AddLocator(Geolocation* 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
|
2013-04-12 11:47:47 -07:00
|
|
|
nsGeolocationService::RemoveLocator(Geolocation* 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
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
2013-04-12 11:47:47 -07:00
|
|
|
// Geolocation
|
2008-07-15 16:37:48 -07:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Geolocation)
|
2013-04-12 11:46:36 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2008-08-14 09:35:49 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMGeoGeolocation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoGeolocation)
|
2008-07-15 16:37:48 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(Geolocation)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(Geolocation)
|
2009-01-14 17:10:46 -08:00
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Geolocation)
|
2013-04-12 11:46:36 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCachedPosition)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2012-10-31 17:19:34 -07:00
|
|
|
tmp->mPendingRequests.Clear();
|
2013-04-02 09:48:59 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingCallbacks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWatchingCallbacks)
|
2009-01-14 17:10:46 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Geolocation)
|
2013-04-12 11:46:36 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCachedPosition)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2013-04-02 09:48:59 -07:00
|
|
|
for (uint32_t 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
|
|
|
|
2013-04-02 09:48:59 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingCallbacks)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWatchingCallbacks)
|
2009-01-14 17:10:46 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2013-04-12 11:47:47 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Geolocation)
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::Geolocation()
|
2012-10-31 17:19:34 -07:00
|
|
|
: mLastWatchId(0)
|
2009-11-12 07:14:45 -08:00
|
|
|
{
|
2013-04-12 11:46:36 -07:00
|
|
|
SetIsDOMBinding();
|
2009-11-12 07:14:45 -08:00
|
|
|
}
|
|
|
|
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::~Geolocation()
|
2009-11-12 07:14:45 -08:00
|
|
|
{
|
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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::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
|
|
|
}
|
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
nsIDOMWindow*
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::GetParentObject() const {
|
2013-04-12 11:46:36 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mOwner);
|
|
|
|
return window.get();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::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
|
|
|
}
|
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
bool
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::HighAccuracyRequested()
|
2013-02-26 09:27:31 -08:00
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mWatchingCallbacks.Length(); i++) {
|
|
|
|
if (mWatchingCallbacks[i]->IsActive() &&
|
|
|
|
mWatchingCallbacks[i]->WantsHighAccuracy()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mPendingCallbacks.Length(); i++) {
|
|
|
|
if (mPendingCallbacks[i]->IsActive() &&
|
|
|
|
mPendingCallbacks[i]->WantsHighAccuracy()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
void
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::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
|
2013-04-29 20:22:27 -07:00
|
|
|
Geolocation::Update(nsIDOMGeoPosition *aSomewhere)
|
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--) {
|
2013-04-29 20:22:27 -07:00
|
|
|
if (mPendingCallbacks[i-1]->Update(aSomewhere)) {
|
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++) {
|
2013-04-29 20:22:27 -07:00
|
|
|
mWatchingCallbacks[i]->Update(aSomewhere);
|
2010-08-31 09:15:52 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
}
|
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
void
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::SetCachedPosition(Position* aPosition)
|
2013-01-06 21:57:00 -08:00
|
|
|
{
|
2013-04-12 11:46:36 -07:00
|
|
|
mCachedPosition = aPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
Position*
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::GetCachedPosition()
|
2013-04-12 11:46:36 -07:00
|
|
|
{
|
|
|
|
return mCachedPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::GetCurrentPosition(PositionCallback& aCallback,
|
|
|
|
PositionErrorCallback* aErrorCallback,
|
|
|
|
const PositionOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2013-04-12 11:46:36 -07:00
|
|
|
{
|
|
|
|
GeoPositionCallback successCallback(&aCallback);
|
|
|
|
GeoPositionErrorCallback errorCallback(aErrorCallback);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
GetCurrentPosition(successCallback, errorCallback,
|
|
|
|
GeoPositionOptionsFromPositionOptions(aOptions));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2013-01-06 21:57:00 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
NS_IMETHODIMP
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::GetCurrentPosition(nsIDOMGeoPositionCallback* aCallback,
|
|
|
|
nsIDOMGeoPositionErrorCallback* aErrorCallback,
|
|
|
|
mozilla::idl::GeoPositionOptions* aOptions)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2013-04-12 11:46:36 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aCallback);
|
|
|
|
|
|
|
|
GeoPositionCallback successCallback(aCallback);
|
|
|
|
GeoPositionErrorCallback errorCallback(aErrorCallback);
|
2009-07-16 10:03:49 -07:00
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
return GetCurrentPosition(successCallback, errorCallback, aOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::GetCurrentPosition(GeoPositionCallback& callback,
|
|
|
|
GeoPositionErrorCallback& errorCallback,
|
|
|
|
mozilla::idl::GeoPositionOptions *options)
|
2013-04-12 11:46:36 -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
|
|
|
|
2011-01-31 14:11:45 -08:00
|
|
|
nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
|
2012-07-26 20:33:04 -07:00
|
|
|
callback,
|
|
|
|
errorCallback,
|
2013-01-06 21:57:00 -08:00
|
|
|
options,
|
2012-07-26 20:33:04 -07:00
|
|
|
false);
|
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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::GetCurrentPositionReady(nsGeolocationRequest* aRequest)
|
2012-10-31 17:19:34 -07:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
int32_t
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::WatchPosition(PositionCallback& aCallback,
|
|
|
|
PositionErrorCallback* aErrorCallback,
|
|
|
|
const PositionOptions& aOptions,
|
|
|
|
ErrorResult& aRv)
|
2013-01-06 21:57:00 -08:00
|
|
|
{
|
2013-04-12 11:46:36 -07:00
|
|
|
int32_t ret;
|
|
|
|
GeoPositionCallback successCallback(&aCallback);
|
|
|
|
GeoPositionErrorCallback errorCallback(aErrorCallback);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
WatchPosition(successCallback, errorCallback,
|
|
|
|
GeoPositionOptionsFromPositionOptions(aOptions), &ret);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-01-06 21:57:00 -08:00
|
|
|
}
|
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
NS_IMETHODIMP
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::WatchPosition(nsIDOMGeoPositionCallback *aCallback,
|
|
|
|
nsIDOMGeoPositionErrorCallback *aErrorCallback,
|
|
|
|
mozilla::idl::GeoPositionOptions *aOptions,
|
|
|
|
int32_t* aRv)
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2013-04-12 11:46:36 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aCallback);
|
|
|
|
|
|
|
|
GeoPositionCallback successCallback(aCallback);
|
|
|
|
GeoPositionErrorCallback errorCallback(aErrorCallback);
|
|
|
|
|
|
|
|
return WatchPosition(successCallback, errorCallback, aOptions, aRv);
|
|
|
|
}
|
2009-05-06 18:25:44 -07:00
|
|
|
|
2013-04-12 11:46:36 -07:00
|
|
|
nsresult
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::WatchPosition(GeoPositionCallback& aCallback,
|
|
|
|
GeoPositionErrorCallback& aErrorCallback,
|
|
|
|
mozilla::idl::GeoPositionOptions* aOptions,
|
|
|
|
int32_t* aRv)
|
2013-04-12 11:46:36 -07:00
|
|
|
{
|
2013-02-03 05:39:00 -08:00
|
|
|
if (mWatchingCallbacks.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:
|
2013-04-12 11:46:36 -07:00
|
|
|
*aRv = mLastWatchId++;
|
2012-10-31 17:19:34 -07:00
|
|
|
|
2011-01-31 14:11:45 -08:00
|
|
|
nsRefPtr<nsGeolocationRequest> request = new nsGeolocationRequest(this,
|
2013-04-12 11:46:36 -07:00
|
|
|
aCallback,
|
|
|
|
aErrorCallback,
|
|
|
|
aOptions,
|
2012-10-31 17:19:34 -07:00
|
|
|
true,
|
2013-04-12 11:46:36 -07:00
|
|
|
*aRv);
|
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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::WatchPositionReady(nsGeolocationRequest* aRequest)
|
2012-10-31 17:19:34 -07:00
|
|
|
{
|
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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::ServiceReady()
|
2012-10-31 17:19:34 -07:00
|
|
|
{
|
|
|
|
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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::WindowOwnerStillExists()
|
2008-07-15 16:37:48 -07:00
|
|
|
{
|
2013-04-12 11:47:47 -07:00
|
|
|
// an owner was never set when Geolocation
|
2009-11-12 07:14:45 -08:00
|
|
|
// 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
|
2013-04-12 11:47:47 -07:00
|
|
|
Geolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request)
|
2010-05-13 10:44:51 -07:00
|
|
|
{
|
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
|
|
|
}
|
2013-04-12 11:46:36 -07:00
|
|
|
|
|
|
|
JSObject*
|
2013-04-25 09:29:54 -07:00
|
|
|
Geolocation::WrapObject(JSContext *aCtx, JS::Handle<JSObject*> aScope)
|
2013-04-12 11:46:36 -07:00
|
|
|
{
|
|
|
|
return mozilla::dom::GeolocationBinding::Wrap(aCtx, aScope, this);
|
|
|
|
}
|