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 extern mozilla::LazyLogModule gGeolocationLog
;
14 namespace mozilla::dom
{
16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GeolocationPositionError
, mParent
)
18 GeolocationPositionError::GeolocationPositionError(Geolocation
* aParent
,
20 : mCode(aCode
), mParent(aParent
) {}
22 GeolocationPositionError::~GeolocationPositionError() = default;
24 void GeolocationPositionError::GetMessage(nsAString
& aMessage
) const {
26 case GeolocationPositionError_Binding::PERMISSION_DENIED
:
27 aMessage
= u
"User denied geolocation prompt"_ns
;
29 case GeolocationPositionError_Binding::POSITION_UNAVAILABLE
:
30 aMessage
= u
"Unknown error acquiring position"_ns
;
32 case GeolocationPositionError_Binding::TIMEOUT
:
33 aMessage
= u
"Position acquisition timed out"_ns
;
40 nsWrapperCache
* GeolocationPositionError::GetParentObject() const {
44 JSObject
* GeolocationPositionError::WrapObject(
45 JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
46 return GeolocationPositionError_Binding::Wrap(aCx
, this, aGivenProto
);
49 void GeolocationPositionError::NotifyCallback(
50 const GeoPositionErrorCallback
& aCallback
) {
51 MOZ_LOG(gGeolocationLog
, LogLevel::Debug
,
52 ("GeolocationPositionError::NotifyCallback"));
54 if (aCallback
.HasWebIDLCallback()) {
55 RefPtr
<PositionErrorCallback
> callback
= aCallback
.GetWebIDLCallback();
58 callback
->Call(*this);
61 nsIDOMGeoPositionErrorCallback
* callback
= aCallback
.GetXPCOMCallback();
63 callback
->HandleEvent(this);
68 } // namespace mozilla::dom