Bumping manifests a=b2g-bump
[gecko.git] / dom / icc / IccInfo.cpp
blobcbe4493c8df1fa702f8b07246bd3f24206a1b932
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/dom/IccInfo.h"
7 #include "nsPIDOMWindow.h"
9 #define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \
10 { \
11 uint32_t i = 0; \
12 for (const EnumEntry* entry = _enumType##Values::strings; \
13 entry->value; \
14 ++entry, ++i) { \
15 if (_string.EqualsASCII(entry->value)) { \
16 _enum.SetValue(static_cast<_enumType>(i)); \
17 } \
18 } \
21 using namespace mozilla::dom;
23 // IccInfo
25 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IccInfo, mWindow, mIccInfo)
27 NS_IMPL_CYCLE_COLLECTING_ADDREF(IccInfo)
28 NS_IMPL_CYCLE_COLLECTING_RELEASE(IccInfo)
30 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IccInfo)
31 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
32 NS_INTERFACE_MAP_ENTRY(nsISupports)
33 NS_INTERFACE_MAP_END
35 IccInfo::IccInfo(nsPIDOMWindow* aWindow)
36 : mWindow(aWindow)
40 void
41 IccInfo::Update(nsIIccInfo* aInfo)
43 mIccInfo = aInfo;
46 JSObject*
47 IccInfo::WrapObject(JSContext* aCx)
49 return MozIccInfoBinding::Wrap(aCx, this);
52 Nullable<IccType>
53 IccInfo::GetIccType() const
55 if (!mIccInfo) {
56 return Nullable<IccType>();
59 nsAutoString type;
60 Nullable<IccType> iccType;
62 mIccInfo->GetIccType(type);
63 CONVERT_STRING_TO_NULLABLE_ENUM(type, IccType, iccType);
65 return iccType;
68 void
69 IccInfo::GetIccid(nsAString& aIccId) const
71 if (!mIccInfo) {
72 aIccId.SetIsVoid(true);
73 return;
76 mIccInfo->GetIccid(aIccId);
79 void
80 IccInfo::GetMcc(nsAString& aMcc) const
82 if (!mIccInfo) {
83 aMcc.SetIsVoid(true);
84 return;
87 mIccInfo->GetMcc(aMcc);
90 void
91 IccInfo::GetMnc(nsAString& aMnc) const
93 if (!mIccInfo) {
94 aMnc.SetIsVoid(true);
95 return;
98 mIccInfo->GetMnc(aMnc);
101 void
102 IccInfo::GetSpn(nsAString& aSpn) const
104 if (!mIccInfo) {
105 aSpn.SetIsVoid(true);
106 return;
109 mIccInfo->GetSpn(aSpn);
112 bool
113 IccInfo::IsDisplayNetworkNameRequired() const
115 if (!mIccInfo) {
116 return false;
119 bool isDisplayNetworkNameRequired;
120 mIccInfo->GetIsDisplayNetworkNameRequired(&isDisplayNetworkNameRequired);
122 return isDisplayNetworkNameRequired;
125 bool
126 IccInfo::IsDisplaySpnRequired() const
128 if (!mIccInfo) {
129 return false;
132 bool isDisplaySpnRequired;
133 mIccInfo->GetIsDisplaySpnRequired(&isDisplaySpnRequired);
135 return isDisplaySpnRequired;
138 // GsmIccInfo
140 NS_IMPL_CYCLE_COLLECTION_INHERITED(GsmIccInfo, IccInfo, mGsmIccInfo)
142 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(GsmIccInfo)
143 NS_INTERFACE_MAP_END_INHERITING(IccInfo)
145 NS_IMPL_ADDREF_INHERITED(GsmIccInfo, IccInfo)
146 NS_IMPL_RELEASE_INHERITED(GsmIccInfo, IccInfo)
148 GsmIccInfo::GsmIccInfo(nsPIDOMWindow* aWindow)
149 : IccInfo(aWindow)
153 void
154 GsmIccInfo::Update(nsIGsmIccInfo* aInfo)
156 nsCOMPtr<nsIIccInfo> iccInfo = do_QueryInterface(aInfo);
157 MOZ_ASSERT(iccInfo);
159 IccInfo::Update(iccInfo);
160 mGsmIccInfo = aInfo;
163 JSObject*
164 GsmIccInfo::WrapObject(JSContext* aCx)
166 return MozGsmIccInfoBinding::Wrap(aCx, this);
169 void
170 GsmIccInfo::GetMsisdn(nsAString& aMsisdn) const
172 if (!mGsmIccInfo) {
173 aMsisdn.SetIsVoid(true);
174 return;
177 mGsmIccInfo->GetMsisdn(aMsisdn);
180 // CdmaIccInfo
182 NS_IMPL_CYCLE_COLLECTION_INHERITED(CdmaIccInfo, IccInfo, mCdmaIccInfo)
184 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CdmaIccInfo)
185 NS_INTERFACE_MAP_END_INHERITING(IccInfo)
187 NS_IMPL_ADDREF_INHERITED(CdmaIccInfo, IccInfo)
188 NS_IMPL_RELEASE_INHERITED(CdmaIccInfo, IccInfo)
190 CdmaIccInfo::CdmaIccInfo(nsPIDOMWindow* aWindow)
191 : IccInfo(aWindow)
195 void
196 CdmaIccInfo::Update(nsICdmaIccInfo* aInfo)
198 nsCOMPtr<nsIIccInfo> iccInfo = do_QueryInterface(aInfo);
199 MOZ_ASSERT(iccInfo);
201 IccInfo::Update(iccInfo);
202 mCdmaIccInfo = aInfo;
205 JSObject*
206 CdmaIccInfo::WrapObject(JSContext* aCx)
208 return MozCdmaIccInfoBinding::Wrap(aCx, this);
211 void
212 CdmaIccInfo::GetMdn(nsAString& aMdn) const
214 if (!mCdmaIccInfo) {
215 aMdn.SetIsVoid(true);
216 return;
219 mCdmaIccInfo->GetMdn(aMdn);
222 int32_t
223 CdmaIccInfo::PrlVersion() const
225 if (!mCdmaIccInfo) {
226 return 0;
229 int32_t prlVersion;
230 mCdmaIccInfo->GetPrlVersion(&prlVersion);
232 return prlVersion;