Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "Icc.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "mozilla/dom/MozIccBinding.h" |
michael@0 | 8 | #include "mozilla/dom/MozStkCommandEvent.h" |
michael@0 | 9 | #include "nsIDOMDOMRequest.h" |
michael@0 | 10 | #include "nsIDOMIccInfo.h" |
michael@0 | 11 | #include "nsJSON.h" |
michael@0 | 12 | #include "nsRadioInterfaceLayer.h" |
michael@0 | 13 | #include "nsServiceManagerUtils.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla::dom; |
michael@0 | 16 | |
michael@0 | 17 | Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, const nsAString& aIccId) |
michael@0 | 18 | : mLive(true) |
michael@0 | 19 | , mClientId(aClientId) |
michael@0 | 20 | , mIccId(aIccId) |
michael@0 | 21 | { |
michael@0 | 22 | SetIsDOMBinding(); |
michael@0 | 23 | BindToOwner(aWindow); |
michael@0 | 24 | |
michael@0 | 25 | mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID); |
michael@0 | 26 | |
michael@0 | 27 | // Not being able to acquire the provider isn't fatal since we check |
michael@0 | 28 | // for it explicitly below. |
michael@0 | 29 | if (!mProvider) { |
michael@0 | 30 | NS_WARNING("Could not acquire nsIIccProvider!"); |
michael@0 | 31 | } |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | void |
michael@0 | 35 | Icc::Shutdown() |
michael@0 | 36 | { |
michael@0 | 37 | mProvider = nullptr; |
michael@0 | 38 | mLive = false; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | nsresult |
michael@0 | 42 | Icc::NotifyEvent(const nsAString& aName) |
michael@0 | 43 | { |
michael@0 | 44 | return DispatchTrustedEvent(aName); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | nsresult |
michael@0 | 48 | Icc::NotifyStkEvent(const nsAString& aName, const nsAString& aMessage) |
michael@0 | 49 | { |
michael@0 | 50 | nsresult rv; |
michael@0 | 51 | nsIScriptContext* sc = GetContextForEventHandlers(&rv); |
michael@0 | 52 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 53 | |
michael@0 | 54 | AutoPushJSContext cx(sc->GetNativeContext()); |
michael@0 | 55 | JS::Rooted<JS::Value> value(cx); |
michael@0 | 56 | |
michael@0 | 57 | if (!aMessage.IsEmpty()) { |
michael@0 | 58 | nsCOMPtr<nsIJSON> json(new nsJSON()); |
michael@0 | 59 | nsresult rv = json->DecodeToJSVal(aMessage, cx, &value); |
michael@0 | 60 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 61 | } else { |
michael@0 | 62 | value = JS::NullValue(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | MozStkCommandEventInit init; |
michael@0 | 66 | init.mBubbles = false; |
michael@0 | 67 | init.mCancelable = false; |
michael@0 | 68 | init.mCommand = value; |
michael@0 | 69 | |
michael@0 | 70 | nsRefPtr<MozStkCommandEvent> event = |
michael@0 | 71 | MozStkCommandEvent::Constructor(this, aName, init); |
michael@0 | 72 | |
michael@0 | 73 | return DispatchTrustedEvent(event); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | // WrapperCache |
michael@0 | 77 | |
michael@0 | 78 | JSObject* |
michael@0 | 79 | Icc::WrapObject(JSContext* aCx) |
michael@0 | 80 | { |
michael@0 | 81 | return MozIccBinding::Wrap(aCx, this); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | // MozIcc WebIDL |
michael@0 | 85 | |
michael@0 | 86 | already_AddRefed<nsIDOMMozIccInfo> |
michael@0 | 87 | Icc::GetIccInfo() const |
michael@0 | 88 | { |
michael@0 | 89 | if (!mProvider) { |
michael@0 | 90 | return nullptr; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | nsCOMPtr<nsIDOMMozIccInfo> iccInfo; |
michael@0 | 94 | nsresult rv = mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo)); |
michael@0 | 95 | if (NS_FAILED(rv)) { |
michael@0 | 96 | return nullptr; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | return iccInfo.forget(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | void |
michael@0 | 103 | Icc::GetCardState(nsString& aCardState) const |
michael@0 | 104 | { |
michael@0 | 105 | aCardState.SetIsVoid(true); |
michael@0 | 106 | |
michael@0 | 107 | if (!mProvider) { |
michael@0 | 108 | return; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | nsresult rv = mProvider->GetCardState(mClientId, aCardState); |
michael@0 | 112 | if (NS_FAILED(rv)) { |
michael@0 | 113 | aCardState.SetIsVoid(true); |
michael@0 | 114 | } |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | void |
michael@0 | 118 | Icc::SendStkResponse(const JSContext* aCx, JS::Handle<JS::Value> aCommand, |
michael@0 | 119 | JS::Handle<JS::Value> aResponse, ErrorResult& aRv) |
michael@0 | 120 | { |
michael@0 | 121 | if (!mProvider) { |
michael@0 | 122 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 123 | return; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | nsresult rv = mProvider->SendStkResponse(mClientId, GetOwner(), aCommand, |
michael@0 | 127 | aResponse); |
michael@0 | 128 | if (NS_FAILED(rv)) { |
michael@0 | 129 | aRv.Throw(rv); |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | void |
michael@0 | 134 | Icc::SendStkMenuSelection(uint16_t aItemIdentifier, bool aHelpRequested, |
michael@0 | 135 | ErrorResult& aRv) |
michael@0 | 136 | { |
michael@0 | 137 | if (!mProvider) { |
michael@0 | 138 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 139 | return; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | nsresult rv = mProvider->SendStkMenuSelection(mClientId, |
michael@0 | 143 | GetOwner(), |
michael@0 | 144 | aItemIdentifier, |
michael@0 | 145 | aHelpRequested); |
michael@0 | 146 | if (NS_FAILED(rv)) { |
michael@0 | 147 | aRv.Throw(rv); |
michael@0 | 148 | } |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | void |
michael@0 | 152 | Icc::SendStkTimerExpiration(const JSContext* aCx, JS::Handle<JS::Value> aTimer, |
michael@0 | 153 | ErrorResult& aRv) |
michael@0 | 154 | { |
michael@0 | 155 | if (!mProvider) { |
michael@0 | 156 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 157 | return; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | nsresult rv = mProvider->SendStkTimerExpiration(mClientId, GetOwner(), |
michael@0 | 161 | aTimer); |
michael@0 | 162 | if (NS_FAILED(rv)) { |
michael@0 | 163 | aRv.Throw(rv); |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | void |
michael@0 | 168 | Icc::SendStkEventDownload(const JSContext* aCx, JS::Handle<JS::Value> aEvent, |
michael@0 | 169 | ErrorResult& aRv) |
michael@0 | 170 | { |
michael@0 | 171 | if (!mProvider) { |
michael@0 | 172 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 173 | return; |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | nsresult rv = mProvider->SendStkEventDownload(mClientId, GetOwner(), aEvent); |
michael@0 | 177 | if (NS_FAILED(rv)) { |
michael@0 | 178 | aRv.Throw(rv); |
michael@0 | 179 | } |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | already_AddRefed<nsISupports> |
michael@0 | 183 | Icc::GetCardLock(const nsAString& aLockType, ErrorResult& aRv) |
michael@0 | 184 | { |
michael@0 | 185 | if (!mProvider) { |
michael@0 | 186 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 187 | return nullptr; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 191 | nsresult rv = mProvider->GetCardLockState(mClientId, GetOwner(), aLockType, |
michael@0 | 192 | getter_AddRefs(request)); |
michael@0 | 193 | if (NS_FAILED(rv)) { |
michael@0 | 194 | aRv.Throw(rv); |
michael@0 | 195 | return nullptr; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | return request.forget(); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | already_AddRefed<nsISupports> |
michael@0 | 202 | Icc::UnlockCardLock(const JSContext* aCx, JS::Handle<JS::Value> aInfo, |
michael@0 | 203 | ErrorResult& aRv) |
michael@0 | 204 | { |
michael@0 | 205 | if (!mProvider) { |
michael@0 | 206 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 207 | return nullptr; |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 211 | nsresult rv = mProvider->UnlockCardLock(mClientId, GetOwner(), aInfo, |
michael@0 | 212 | getter_AddRefs(request)); |
michael@0 | 213 | if (NS_FAILED(rv)) { |
michael@0 | 214 | aRv.Throw(rv); |
michael@0 | 215 | return nullptr; |
michael@0 | 216 | } |
michael@0 | 217 | |
michael@0 | 218 | return request.forget(); |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | already_AddRefed<nsISupports> |
michael@0 | 222 | Icc::SetCardLock(const JSContext* aCx, JS::Handle<JS::Value> aInfo, |
michael@0 | 223 | ErrorResult& aRv) |
michael@0 | 224 | { |
michael@0 | 225 | if (!mProvider) { |
michael@0 | 226 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 227 | return nullptr; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 231 | nsresult rv = mProvider->SetCardLock(mClientId, GetOwner(), aInfo, |
michael@0 | 232 | getter_AddRefs(request)); |
michael@0 | 233 | if (NS_FAILED(rv)) { |
michael@0 | 234 | aRv.Throw(rv); |
michael@0 | 235 | return nullptr; |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | return request.forget(); |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | already_AddRefed<nsISupports> |
michael@0 | 242 | Icc::GetCardLockRetryCount(const nsAString& aLockType, ErrorResult& aRv) |
michael@0 | 243 | { |
michael@0 | 244 | if (!mProvider) { |
michael@0 | 245 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 246 | return nullptr; |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 250 | nsresult rv = mProvider->GetCardLockRetryCount(mClientId, |
michael@0 | 251 | GetOwner(), |
michael@0 | 252 | aLockType, |
michael@0 | 253 | getter_AddRefs(request)); |
michael@0 | 254 | if (NS_FAILED(rv)) { |
michael@0 | 255 | aRv.Throw(rv); |
michael@0 | 256 | return nullptr; |
michael@0 | 257 | } |
michael@0 | 258 | |
michael@0 | 259 | return request.forget(); |
michael@0 | 260 | } |
michael@0 | 261 | |
michael@0 | 262 | already_AddRefed<nsISupports> |
michael@0 | 263 | Icc::ReadContacts(const nsAString& aContactType, ErrorResult& aRv) |
michael@0 | 264 | { |
michael@0 | 265 | if (!mProvider) { |
michael@0 | 266 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 267 | return nullptr; |
michael@0 | 268 | } |
michael@0 | 269 | |
michael@0 | 270 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 271 | nsresult rv = mProvider->ReadContacts(mClientId, GetOwner(), aContactType, |
michael@0 | 272 | getter_AddRefs(request)); |
michael@0 | 273 | if (NS_FAILED(rv)) { |
michael@0 | 274 | aRv.Throw(rv); |
michael@0 | 275 | return nullptr; |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | return request.forget(); |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | already_AddRefed<nsISupports> |
michael@0 | 282 | Icc::UpdateContact(const JSContext* aCx, const nsAString& aContactType, |
michael@0 | 283 | JS::Handle<JS::Value> aContact, const nsAString& aPin2, |
michael@0 | 284 | ErrorResult& aRv) |
michael@0 | 285 | { |
michael@0 | 286 | if (!mProvider) { |
michael@0 | 287 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 288 | return nullptr; |
michael@0 | 289 | } |
michael@0 | 290 | |
michael@0 | 291 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 292 | nsresult rv = mProvider->UpdateContact(mClientId, GetOwner(), aContactType, |
michael@0 | 293 | aContact, aPin2, |
michael@0 | 294 | getter_AddRefs(request)); |
michael@0 | 295 | if (NS_FAILED(rv)) { |
michael@0 | 296 | aRv.Throw(rv); |
michael@0 | 297 | return nullptr; |
michael@0 | 298 | } |
michael@0 | 299 | |
michael@0 | 300 | return request.forget(); |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | already_AddRefed<nsISupports> |
michael@0 | 304 | Icc::IccOpenChannel(const nsAString& aAid, ErrorResult& aRv) |
michael@0 | 305 | { |
michael@0 | 306 | if (!mProvider) { |
michael@0 | 307 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 308 | return nullptr; |
michael@0 | 309 | } |
michael@0 | 310 | |
michael@0 | 311 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 312 | nsresult rv = mProvider->IccOpenChannel(mClientId, GetOwner(), aAid, |
michael@0 | 313 | getter_AddRefs(request)); |
michael@0 | 314 | if (NS_FAILED(rv)) { |
michael@0 | 315 | aRv.Throw(rv); |
michael@0 | 316 | return nullptr; |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | return request.forget(); |
michael@0 | 320 | } |
michael@0 | 321 | |
michael@0 | 322 | already_AddRefed<nsISupports> |
michael@0 | 323 | Icc::IccExchangeAPDU(const JSContext* aCx, int32_t aChannel, |
michael@0 | 324 | JS::Handle<JS::Value> aApdu, ErrorResult& aRv) |
michael@0 | 325 | { |
michael@0 | 326 | if (!mProvider) { |
michael@0 | 327 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 328 | return nullptr; |
michael@0 | 329 | } |
michael@0 | 330 | |
michael@0 | 331 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 332 | nsresult rv = mProvider->IccExchangeAPDU(mClientId, GetOwner(), aChannel, |
michael@0 | 333 | aApdu, getter_AddRefs(request)); |
michael@0 | 334 | if (NS_FAILED(rv)) { |
michael@0 | 335 | aRv.Throw(rv); |
michael@0 | 336 | return nullptr; |
michael@0 | 337 | } |
michael@0 | 338 | |
michael@0 | 339 | return request.forget(); |
michael@0 | 340 | } |
michael@0 | 341 | |
michael@0 | 342 | already_AddRefed<nsISupports> |
michael@0 | 343 | Icc::IccCloseChannel(int32_t aChannel, ErrorResult& aRv) |
michael@0 | 344 | { |
michael@0 | 345 | if (!mProvider) { |
michael@0 | 346 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 347 | return nullptr; |
michael@0 | 348 | } |
michael@0 | 349 | |
michael@0 | 350 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 351 | nsresult rv = mProvider->IccCloseChannel(mClientId, GetOwner(), aChannel, |
michael@0 | 352 | getter_AddRefs(request)); |
michael@0 | 353 | if (NS_FAILED(rv)) { |
michael@0 | 354 | aRv.Throw(rv); |
michael@0 | 355 | return nullptr; |
michael@0 | 356 | } |
michael@0 | 357 | |
michael@0 | 358 | return request.forget(); |
michael@0 | 359 | } |
michael@0 | 360 | |
michael@0 | 361 | already_AddRefed<nsISupports> |
michael@0 | 362 | Icc::MatchMvno(const nsAString& aMvnoType, |
michael@0 | 363 | const nsAString& aMvnoData, |
michael@0 | 364 | ErrorResult& aRv) |
michael@0 | 365 | { |
michael@0 | 366 | if (!mProvider) { |
michael@0 | 367 | aRv.Throw(NS_ERROR_FAILURE); |
michael@0 | 368 | return nullptr; |
michael@0 | 369 | } |
michael@0 | 370 | |
michael@0 | 371 | nsRefPtr<nsIDOMDOMRequest> request; |
michael@0 | 372 | nsresult rv = mProvider->MatchMvno(mClientId, GetOwner(), |
michael@0 | 373 | aMvnoType, aMvnoData, |
michael@0 | 374 | getter_AddRefs(request)); |
michael@0 | 375 | if (NS_FAILED(rv)) { |
michael@0 | 376 | aRv.Throw(rv); |
michael@0 | 377 | return nullptr; |
michael@0 | 378 | } |
michael@0 | 379 | |
michael@0 | 380 | return request.forget(); |
michael@0 | 381 | } |