/src/mozilla-central/dom/geolocation/PositionError.cpp
Line | Count | Source (jump to first uncovered line) |
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/PositionError.h" |
8 | | #include "mozilla/dom/PositionErrorBinding.h" |
9 | | #include "mozilla/CycleCollectedJSContext.h" // for nsAutoMicroTask |
10 | | #include "nsGeolocation.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | |
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) |
19 | | |
20 | | PositionError::PositionError(Geolocation* aParent, int16_t aCode) |
21 | | : mCode(aCode) |
22 | | , mParent(aParent) |
23 | 0 | { |
24 | 0 | } |
25 | | |
26 | 0 | PositionError::~PositionError() = default; |
27 | | |
28 | | void |
29 | | PositionError::GetMessage(nsAString& aMessage) const |
30 | 0 | { |
31 | 0 | switch (mCode) |
32 | 0 | { |
33 | 0 | case PositionError_Binding::PERMISSION_DENIED: |
34 | 0 | aMessage = NS_LITERAL_STRING("User denied geolocation prompt"); |
35 | 0 | break; |
36 | 0 | case PositionError_Binding::POSITION_UNAVAILABLE: |
37 | 0 | aMessage = NS_LITERAL_STRING("Unknown error acquiring position"); |
38 | 0 | break; |
39 | 0 | case PositionError_Binding::TIMEOUT: |
40 | 0 | aMessage = NS_LITERAL_STRING("Position acquisition timed out"); |
41 | 0 | break; |
42 | 0 | default: |
43 | 0 | break; |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | | nsWrapperCache* |
48 | | PositionError::GetParentObject() const |
49 | 0 | { |
50 | 0 | return mParent; |
51 | 0 | } |
52 | | |
53 | | JSObject* |
54 | | PositionError::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
55 | 0 | { |
56 | 0 | return PositionError_Binding::Wrap(aCx, this, aGivenProto); |
57 | 0 | } |
58 | | |
59 | | void |
60 | | PositionError::NotifyCallback(const GeoPositionErrorCallback& aCallback) |
61 | 0 | { |
62 | 0 | nsAutoMicroTask mt; |
63 | 0 | if (aCallback.HasWebIDLCallback()) { |
64 | 0 | PositionErrorCallback* callback = aCallback.GetWebIDLCallback(); |
65 | 0 |
|
66 | 0 | if (callback) { |
67 | 0 | callback->Call(*this); |
68 | 0 | } |
69 | 0 | } else { |
70 | 0 | nsIDOMGeoPositionErrorCallback* callback = aCallback.GetXPCOMCallback(); |
71 | 0 | if (callback) { |
72 | 0 | callback->HandleEvent(this); |
73 | 0 | } |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | | } // namespace mozilla |
78 | | } // namespace dom |
79 | | |