Bug 1494333 - index crons just like artifacts r=Callek
[gecko.git] / dom / geolocation / PositionError.cpp
blob19892232a3c7447850cf7fc8225e10e31d0c0dd0
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/PositionError.h"
8 #include "mozilla/dom/PositionErrorBinding.h"
9 #include "mozilla/CycleCollectedJSContext.h" // for nsAutoMicroTask
10 #include "nsGeolocation.h"
12 namespace mozilla {
13 namespace dom {
16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PositionError, mParent)
17 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(PositionError, AddRef)
18 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(PositionError, Release)
20 PositionError::PositionError(Geolocation* aParent, int16_t aCode)
21 : mCode(aCode)
22 , mParent(aParent)
26 PositionError::~PositionError() = default;
28 void
29 PositionError::GetMessage(nsAString& aMessage) const
31 switch (mCode)
33 case PositionError_Binding::PERMISSION_DENIED:
34 aMessage = NS_LITERAL_STRING("User denied geolocation prompt");
35 break;
36 case PositionError_Binding::POSITION_UNAVAILABLE:
37 aMessage = NS_LITERAL_STRING("Unknown error acquiring position");
38 break;
39 case PositionError_Binding::TIMEOUT:
40 aMessage = NS_LITERAL_STRING("Position acquisition timed out");
41 break;
42 default:
43 break;
47 nsWrapperCache*
48 PositionError::GetParentObject() const
50 return mParent;
53 JSObject*
54 PositionError::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
56 return PositionError_Binding::Wrap(aCx, this, aGivenProto);
59 void
60 PositionError::NotifyCallback(const GeoPositionErrorCallback& aCallback)
62 nsAutoMicroTask mt;
63 if (aCallback.HasWebIDLCallback()) {
64 PositionErrorCallback* callback = aCallback.GetWebIDLCallback();
66 if (callback) {
67 callback->Call(*this);
69 } else {
70 nsIDOMGeoPositionErrorCallback* callback = aCallback.GetXPCOMCallback();
71 if (callback) {
72 callback->HandleEvent(this);
77 } // namespace mozilla
78 } // namespace dom