1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/GeolocationPositionError.h"
8 #include "mozilla/dom/GeolocationPositionErrorBinding.h"
9 #include "mozilla/CycleCollectedJSContext.h" // for nsAutoMicroTask
10 #include "Geolocation.h"
12 namespace mozilla::dom
{
14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GeolocationPositionError
, mParent
)
16 GeolocationPositionError::GeolocationPositionError(Geolocation
* aParent
,
18 : mCode(aCode
), mParent(aParent
) {}
20 GeolocationPositionError::~GeolocationPositionError() = default;
22 void GeolocationPositionError::GetMessage(nsAString
& aMessage
) const {
24 case GeolocationPositionError_Binding::PERMISSION_DENIED
:
25 aMessage
= u
"User denied geolocation prompt"_ns
;
27 case GeolocationPositionError_Binding::POSITION_UNAVAILABLE
:
28 aMessage
= u
"Unknown error acquiring position"_ns
;
30 case GeolocationPositionError_Binding::TIMEOUT
:
31 aMessage
= u
"Position acquisition timed out"_ns
;
38 nsWrapperCache
* GeolocationPositionError::GetParentObject() const {
42 JSObject
* GeolocationPositionError::WrapObject(
43 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
44 return GeolocationPositionError_Binding::Wrap(aCx
, this, aGivenProto
);
47 void GeolocationPositionError::NotifyCallback(
48 const GeoPositionErrorCallback
& aCallback
) {
50 if (aCallback
.HasWebIDLCallback()) {
51 RefPtr
<PositionErrorCallback
> callback
= aCallback
.GetWebIDLCallback();
54 callback
->Call(*this);
57 nsIDOMGeoPositionErrorCallback
* callback
= aCallback
.GetXPCOMCallback();
59 callback
->HandleEvent(this);
64 } // namespace mozilla::dom