GeolocationPositionError.cpp (2277B)
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/. */ 6 7 #include "mozilla/dom/GeolocationPositionError.h" 8 9 #include "Geolocation.h" 10 #include "mozilla/CycleCollectedJSContext.h" // for nsAutoMicroTask 11 #include "mozilla/dom/GeolocationPositionErrorBinding.h" 12 13 extern mozilla::LazyLogModule gGeolocationLog; 14 15 namespace mozilla::dom { 16 17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GeolocationPositionError, mParent) 18 19 GeolocationPositionError::GeolocationPositionError(Geolocation* aParent, 20 int16_t aCode) 21 : mCode(aCode), mParent(aParent) {} 22 23 GeolocationPositionError::~GeolocationPositionError() = default; 24 25 void GeolocationPositionError::GetMessage(nsAString& aMessage) const { 26 switch (mCode) { 27 case GeolocationPositionError_Binding::PERMISSION_DENIED: 28 aMessage = u"User denied geolocation prompt"_ns; 29 break; 30 case GeolocationPositionError_Binding::POSITION_UNAVAILABLE: 31 aMessage = u"Unknown error acquiring position"_ns; 32 break; 33 case GeolocationPositionError_Binding::TIMEOUT: 34 aMessage = u"Position acquisition timed out"_ns; 35 break; 36 default: 37 break; 38 } 39 } 40 41 nsWrapperCache* GeolocationPositionError::GetParentObject() const { 42 return mParent; 43 } 44 45 JSObject* GeolocationPositionError::WrapObject( 46 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 47 return GeolocationPositionError_Binding::Wrap(aCx, this, aGivenProto); 48 } 49 50 void GeolocationPositionError::NotifyCallback( 51 const GeoPositionErrorCallback& aCallback) { 52 MOZ_LOG(gGeolocationLog, LogLevel::Debug, 53 ("GeolocationPositionError::NotifyCallback")); 54 nsAutoMicroTask mt; 55 if (aCallback.HasWebIDLCallback()) { 56 RefPtr<PositionErrorCallback> callback = aCallback.GetWebIDLCallback(); 57 58 if (callback) { 59 callback->Call(*this); 60 } 61 } else { 62 nsIDOMGeoPositionErrorCallback* callback = aCallback.GetXPCOMCallback(); 63 if (callback) { 64 callback->HandleEvent(this); 65 } 66 } 67 } 68 69 } // namespace mozilla::dom