Bug 1828523 [wpt PR 39579] - Only restore dialog focus if focus is in the dialog...
[gecko.git] / dom / geolocation / GeolocationPositionError.cpp
blob1fb6274a6b0a71d32dcf016dada0a6ad68cab227
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,
17 int16_t aCode)
18 : mCode(aCode), mParent(aParent) {}
20 GeolocationPositionError::~GeolocationPositionError() = default;
22 void GeolocationPositionError::GetMessage(nsAString& aMessage) const {
23 switch (mCode) {
24 case GeolocationPositionError_Binding::PERMISSION_DENIED:
25 aMessage = u"User denied geolocation prompt"_ns;
26 break;
27 case GeolocationPositionError_Binding::POSITION_UNAVAILABLE:
28 aMessage = u"Unknown error acquiring position"_ns;
29 break;
30 case GeolocationPositionError_Binding::TIMEOUT:
31 aMessage = u"Position acquisition timed out"_ns;
32 break;
33 default:
34 break;
38 nsWrapperCache* GeolocationPositionError::GetParentObject() const {
39 return mParent;
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) {
49 nsAutoMicroTask mt;
50 if (aCallback.HasWebIDLCallback()) {
51 RefPtr<PositionErrorCallback> callback = aCallback.GetWebIDLCallback();
53 if (callback) {
54 callback->Call(*this);
56 } else {
57 nsIDOMGeoPositionErrorCallback* callback = aCallback.GetXPCOMCallback();
58 if (callback) {
59 callback->HandleEvent(this);
64 } // namespace mozilla::dom