2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-10-09 09:40:12 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
#include "mozilla/dom/Icc.h"
|
2013-10-09 09:40:12 +00:00
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
#include "IccCallback.h"
|
2015-06-16 09:38:27 +00:00
|
|
|
#include "IccContact.h"
|
|
|
|
#include "mozilla/dom/ContactsBinding.h"
|
2014-09-19 07:53:05 +00:00
|
|
|
#include "mozilla/dom/DOMRequest.h"
|
|
|
|
#include "mozilla/dom/IccInfo.h"
|
2013-10-09 09:40:12 +00:00
|
|
|
#include "mozilla/dom/MozStkCommandEvent.h"
|
2014-12-26 02:11:20 +00:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2014-06-11 16:40:38 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-09-19 07:53:05 +00:00
|
|
|
#include "nsIIccInfo.h"
|
2015-01-13 10:03:44 +00:00
|
|
|
#include "nsIIccService.h"
|
2015-04-27 08:01:56 +00:00
|
|
|
#include "nsIStkCmdFactory.h"
|
|
|
|
#include "nsIStkProactiveCmd.h"
|
2013-10-09 09:40:12 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
using mozilla::dom::icc::IccCallback;
|
2015-06-16 09:38:27 +00:00
|
|
|
using mozilla::dom::icc::IccContact;
|
2015-01-13 10:03:44 +00:00
|
|
|
|
2014-11-11 10:16:57 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsPukCardLockType(IccLockType aLockType)
|
|
|
|
{
|
|
|
|
switch(aLockType) {
|
|
|
|
case IccLockType::Puk:
|
|
|
|
case IccLockType::Puk2:
|
|
|
|
case IccLockType::NckPuk:
|
|
|
|
case IccLockType::Nck1Puk:
|
|
|
|
case IccLockType::Nck2Puk:
|
|
|
|
case IccLockType::HnckPuk:
|
|
|
|
case IccLockType::CckPuk:
|
|
|
|
case IccLockType::SpckPuk:
|
|
|
|
case IccLockType::RcckPuk:
|
|
|
|
case IccLockType::RspckPuk:
|
2015-04-22 09:24:11 +00:00
|
|
|
case IccLockType::NsckPuk:
|
|
|
|
case IccLockType::PckPuk:
|
2014-11-11 10:16:57 +00:00
|
|
|
return true;
|
2014-12-23 08:11:17 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2014-11-11 10:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace
|
2013-10-09 09:40:12 +00:00
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(Icc, DOMEventTargetHelper, mIccInfo)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Icc)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(Icc, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(Icc, DOMEventTargetHelper)
|
|
|
|
|
2015-06-16 09:38:27 +00:00
|
|
|
Icc::Icc(nsPIDOMWindow* aWindow, nsIIcc* aHandler, nsIIccInfo* aIccInfo)
|
2013-10-09 09:40:12 +00:00
|
|
|
: mLive(true)
|
2015-01-13 10:03:44 +00:00
|
|
|
, mHandler(aHandler)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
if (aIccInfo) {
|
|
|
|
aIccInfo->GetIccid(mIccId);
|
|
|
|
UpdateIccInfo(aIccInfo);
|
|
|
|
}
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 15:55:50 +00:00
|
|
|
Icc::~Icc()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-09 09:40:12 +00:00
|
|
|
void
|
|
|
|
Icc::Shutdown()
|
|
|
|
{
|
2014-09-19 07:53:05 +00:00
|
|
|
mIccInfo.SetNull();
|
2015-01-13 10:03:44 +00:00
|
|
|
mHandler = nullptr;
|
2013-10-09 09:40:12 +00:00
|
|
|
mLive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Icc::NotifyEvent(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-04-27 08:01:56 +00:00
|
|
|
Icc::NotifyStkEvent(const nsAString& aName, nsIStkProactiveCmd* aStkProactiveCmd)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2014-06-19 07:21:14 +00:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 10:17:17 +00:00
|
|
|
if (NS_WARN_IF(!jsapi.InitWithLegacyErrorReporting(GetOwner()))) {
|
2014-06-19 07:21:14 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2014-06-11 16:40:38 +00:00
|
|
|
JSContext* cx = jsapi.cx();
|
2013-10-09 09:40:12 +00:00
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
|
2015-04-27 08:01:56 +00:00
|
|
|
nsCOMPtr<nsIStkCmdFactory> cmdFactory =
|
|
|
|
do_GetService(ICC_STK_CMD_FACTORY_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(cmdFactory, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
cmdFactory->CreateCommandMessage(aStkProactiveCmd, &value);
|
|
|
|
NS_ENSURE_TRUE(value.isObject(), NS_ERROR_UNEXPECTED);
|
2013-10-09 09:40:12 +00:00
|
|
|
|
|
|
|
MozStkCommandEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mCommand = value;
|
|
|
|
|
|
|
|
nsRefPtr<MozStkCommandEvent> event =
|
|
|
|
MozStkCommandEvent::Constructor(this, aName, init);
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
void
|
|
|
|
Icc::UpdateIccInfo(nsIIccInfo* aIccInfo)
|
|
|
|
{
|
|
|
|
if (!aIccInfo) {
|
|
|
|
mIccInfo.SetNull();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIGsmIccInfo> gsmIccInfo(do_QueryInterface(aIccInfo));
|
|
|
|
if (gsmIccInfo) {
|
|
|
|
if (mIccInfo.IsNull() || !mIccInfo.Value().IsMozGsmIccInfo()) {
|
|
|
|
mIccInfo.SetValue().SetAsMozGsmIccInfo() = new GsmIccInfo(GetOwner());
|
|
|
|
}
|
|
|
|
mIccInfo.Value().GetAsMozGsmIccInfo().get()->Update(gsmIccInfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsICdmaIccInfo> cdmaIccInfo(do_QueryInterface(aIccInfo));
|
|
|
|
if (cdmaIccInfo) {
|
|
|
|
if (mIccInfo.IsNull() || !mIccInfo.Value().IsMozCdmaIccInfo()) {
|
|
|
|
mIccInfo.SetValue().SetAsMozCdmaIccInfo() = new CdmaIccInfo(GetOwner());
|
|
|
|
}
|
|
|
|
mIccInfo.Value().GetAsMozCdmaIccInfo().get()->Update(cdmaIccInfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIccInfo.IsNull() || !mIccInfo.Value().IsMozIccInfo()) {
|
|
|
|
mIccInfo.SetValue().SetAsMozIccInfo() = new IccInfo(GetOwner());
|
|
|
|
}
|
|
|
|
mIccInfo.Value().GetAsMozIccInfo().get()->Update(aIccInfo);
|
|
|
|
}
|
|
|
|
|
2013-10-09 09:40:12 +00:00
|
|
|
// WrapperCache
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
Icc::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return MozIccBinding::Wrap(aCx, this, aGivenProto);
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MozIcc WebIDL
|
|
|
|
|
2014-09-19 07:53:05 +00:00
|
|
|
void
|
|
|
|
Icc::GetIccInfo(Nullable<OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo>& aIccInfo) const
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2014-09-19 07:53:05 +00:00
|
|
|
aIccInfo = mIccInfo;
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-03 11:31:00 +00:00
|
|
|
Nullable<IccCardState>
|
|
|
|
Icc::GetCardState() const
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2014-09-03 11:31:00 +00:00
|
|
|
Nullable<IccCardState> result;
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
uint32_t cardState = nsIIcc::CARD_STATE_UNDETECTED;
|
|
|
|
if (mHandler &&
|
|
|
|
NS_SUCCEEDED(mHandler->GetCardState(&cardState)) &&
|
|
|
|
cardState != nsIIcc::CARD_STATE_UNDETECTED) {
|
2014-09-03 11:31:00 +00:00
|
|
|
MOZ_ASSERT(cardState < static_cast<uint32_t>(IccCardState::EndGuard_));
|
|
|
|
result.SetValue(static_cast<IccCardState>(cardState));
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-09-03 11:31:00 +00:00
|
|
|
return result;
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-09 17:39:36 +00:00
|
|
|
Icc::SendStkResponse(const JSContext* aCx, JS::Handle<JS::Value> aCommand,
|
|
|
|
JS::Handle<JS::Value> aResponse, ErrorResult& aRv)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2015-04-29 02:42:35 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 02:42:35 +00:00
|
|
|
nsCOMPtr<nsIStkCmdFactory> cmdFactory =
|
|
|
|
do_GetService(ICC_STK_CMD_FACTORY_CONTRACTID);
|
|
|
|
if (!cmdFactory) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStkProactiveCmd> command;
|
|
|
|
cmdFactory->CreateCommand(aCommand, getter_AddRefs(command));
|
|
|
|
if (!command) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStkTerminalResponse> response;
|
|
|
|
cmdFactory->CreateResponse(aResponse, getter_AddRefs(response));
|
|
|
|
if (!response) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mHandler->SendStkResponse(command, response);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Icc::SendStkMenuSelection(uint16_t aItemIdentifier, bool aHelpRequested,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-04-29 02:42:35 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 02:42:35 +00:00
|
|
|
nsresult rv = mHandler->SendStkMenuSelection(aItemIdentifier, aHelpRequested);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-09 17:39:36 +00:00
|
|
|
Icc::SendStkTimerExpiration(const JSContext* aCx, JS::Handle<JS::Value> aTimer,
|
2013-10-09 09:40:12 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-04-29 02:42:35 +00:00
|
|
|
if (!mHandler) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStkCmdFactory> cmdFactory =
|
|
|
|
do_GetService(ICC_STK_CMD_FACTORY_CONTRACTID);
|
|
|
|
if (!cmdFactory) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 02:42:35 +00:00
|
|
|
nsCOMPtr<nsIStkTimer> timer;
|
|
|
|
cmdFactory->CreateTimer(aTimer, getter_AddRefs(timer));
|
|
|
|
if (!timer) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t timerId;
|
|
|
|
nsresult rv = timer->GetTimerId(&timerId);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t timerValue;
|
|
|
|
rv = timer->GetTimerValue(&timerValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mHandler->SendStkTimerExpiration(timerId, timerValue);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-09 17:39:36 +00:00
|
|
|
Icc::SendStkEventDownload(const JSContext* aCx, JS::Handle<JS::Value> aEvent,
|
2013-10-09 09:40:12 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-04-29 02:42:35 +00:00
|
|
|
if (!mHandler) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStkCmdFactory> cmdFactory =
|
|
|
|
do_GetService(ICC_STK_CMD_FACTORY_CONTRACTID);
|
|
|
|
if (!cmdFactory) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStkDownloadEvent> event;
|
|
|
|
cmdFactory->CreateEvent(aEvent, getter_AddRefs(event));
|
|
|
|
if (!event) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 02:42:35 +00:00
|
|
|
nsresult rv = mHandler->SendStkEventDownload(event);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-19 20:37:58 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 10:16:57 +00:00
|
|
|
Icc::GetCardLock(IccLockType aLockType, ErrorResult& aRv)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2015-01-13 10:03:44 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
// TODO: Bug 1125018 - Simplify The Result of GetCardLock and
|
|
|
|
// getCardLockRetryCount in MozIcc.webidl without a wrapper object.
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), request, true);
|
|
|
|
nsresult rv = mHandler->GetCardLockEnabled(static_cast<uint32_t>(aLockType),
|
|
|
|
requestCallback);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
return request.forget();
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 20:37:58 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 10:16:57 +00:00
|
|
|
Icc::UnlockCardLock(const IccUnlockCardLockOptions& aOptions, ErrorResult& aRv)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2015-01-13 10:03:44 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), request);
|
2014-11-11 10:16:57 +00:00
|
|
|
const nsString& password = IsPukCardLockType(aOptions.mLockType)
|
|
|
|
? aOptions.mPuk : aOptions.mPin;
|
2015-01-13 10:03:44 +00:00
|
|
|
nsresult rv =
|
|
|
|
mHandler->UnlockCardLock(static_cast<uint32_t>(aOptions.mLockType),
|
|
|
|
password, aOptions.mNewPin, requestCallback);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
return request.forget();
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 20:37:58 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 10:16:57 +00:00
|
|
|
Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2015-01-13 10:03:44 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-11 10:16:57 +00:00
|
|
|
nsresult rv;
|
2015-01-13 10:03:44 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), request);
|
2014-11-11 10:16:57 +00:00
|
|
|
|
|
|
|
if (aOptions.mEnabled.WasPassed()) {
|
|
|
|
// Enable card lock.
|
|
|
|
const nsString& password = (aOptions.mLockType == IccLockType::Fdn) ?
|
|
|
|
aOptions.mPin2 : aOptions.mPin;
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
rv =
|
|
|
|
mHandler->SetCardLockEnabled(static_cast<uint32_t>(aOptions.mLockType),
|
|
|
|
password, aOptions.mEnabled.Value(),
|
|
|
|
requestCallback);
|
2014-11-11 10:16:57 +00:00
|
|
|
} else {
|
|
|
|
// Change card lock password.
|
2015-01-13 10:03:44 +00:00
|
|
|
rv =
|
|
|
|
mHandler->ChangeCardLockPassword(static_cast<uint32_t>(aOptions.mLockType),
|
|
|
|
aOptions.mPin, aOptions.mNewPin,
|
|
|
|
requestCallback);
|
2014-11-11 10:16:57 +00:00
|
|
|
}
|
|
|
|
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
return request.forget();
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 20:37:58 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 10:16:57 +00:00
|
|
|
Icc::GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2015-01-13 10:03:44 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), request);
|
|
|
|
nsresult rv = mHandler->GetCardLockRetryCount(static_cast<uint32_t>(aLockType),
|
|
|
|
requestCallback);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
return request.forget();
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 20:37:58 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-12-12 03:08:27 +00:00
|
|
|
Icc::ReadContacts(IccContactType aContactType, ErrorResult& aRv)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2015-06-16 09:38:27 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-16 09:38:27 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), request);
|
|
|
|
|
|
|
|
nsresult rv = mHandler->ReadContacts(static_cast<uint32_t>(aContactType),
|
|
|
|
requestCallback);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-16 09:38:27 +00:00
|
|
|
return request.forget();
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 20:37:58 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2015-06-16 09:38:27 +00:00
|
|
|
Icc::UpdateContact(IccContactType aContactType, mozContact& aContact,
|
|
|
|
const nsAString& aPin2, ErrorResult& aRv)
|
2013-10-09 09:40:12 +00:00
|
|
|
{
|
2015-06-16 09:38:27 +00:00
|
|
|
if (!mHandler) {
|
2013-10-09 09:40:12 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-16 09:38:27 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), request);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIccContact> iccContact;
|
|
|
|
nsresult rv = IccContact::Create(aContact, getter_AddRefs(iccContact));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mHandler->UpdateContact(static_cast<uint32_t>(aContactType),
|
|
|
|
iccContact,
|
|
|
|
aPin2,
|
|
|
|
requestCallback);
|
2013-10-09 09:40:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-16 09:38:27 +00:00
|
|
|
return request.forget();
|
2013-10-09 09:40:12 +00:00
|
|
|
}
|
|
|
|
|
2014-05-19 20:37:58 +00:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-12-12 11:04:00 +00:00
|
|
|
Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData,
|
2014-01-28 10:58:00 +00:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-01-13 10:03:44 +00:00
|
|
|
if (!mHandler) {
|
2014-01-28 10:58:00 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), request);
|
|
|
|
nsresult rv = mHandler->MatchMvno(static_cast<uint32_t>(aMvnoType),
|
|
|
|
aMvnoData, requestCallback);
|
2014-01-28 10:58:00 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
return request.forget();
|
2014-01-28 10:58:00 +00:00
|
|
|
}
|
2014-11-11 10:16:57 +00:00
|
|
|
|
2014-12-26 02:11:20 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Icc::GetServiceState(IccService aService, ErrorResult& aRv)
|
|
|
|
{
|
2015-01-13 10:03:44 +00:00
|
|
|
if (!mHandler) {
|
2014-12-26 02:11:20 +00:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (!global) {
|
2015-03-18 18:48:52 +00:00
|
|
|
return nullptr;
|
2015-01-13 10:03:44 +00:00
|
|
|
}
|
|
|
|
|
2015-01-13 10:03:44 +00:00
|
|
|
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IccCallback> requestCallback =
|
|
|
|
new IccCallback(GetOwner(), promise);
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
mHandler->GetServiceStateEnabled(static_cast<uint32_t>(aService),
|
|
|
|
requestCallback);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
// fall-through to return promise.
|
|
|
|
}
|
|
|
|
|
2014-12-26 02:11:20 +00:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2014-11-11 10:16:57 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|