no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / dom / geolocation / GeolocationPositionError.cpp
blob0be1657e0272561ffbda3f641820564c909738e2
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,
19 int16_t aCode)
20 : mCode(aCode), mParent(aParent) {}
22 GeolocationPositionError::~GeolocationPositionError() = default;
24 void GeolocationPositionError::GetMessage(nsAString& aMessage) const {
25 switch (mCode) {
26 case GeolocationPositionError_Binding::PERMISSION_DENIED:
27 aMessage = u"User denied geolocation prompt"_ns;
28 break;
29 case GeolocationPositionError_Binding::POSITION_UNAVAILABLE:
30 aMessage = u"Unknown error acquiring position"_ns;
31 break;
32 case GeolocationPositionError_Binding::TIMEOUT:
33 aMessage = u"Position acquisition timed out"_ns;
34 break;
35 default:
36 break;
40 nsWrapperCache* GeolocationPositionError::GetParentObject() const {
41 return mParent;
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"));
53 nsAutoMicroTask mt;
54 if (aCallback.HasWebIDLCallback()) {
55 RefPtr<PositionErrorCallback> callback = aCallback.GetWebIDLCallback();
57 if (callback) {
58 callback->Call(*this);
60 } else {
61 nsIDOMGeoPositionErrorCallback* callback = aCallback.GetXPCOMCallback();
62 if (callback) {
63 callback->HandleEvent(this);
68 } // namespace mozilla::dom