2015-05-03 22:32:37 +03: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 13:40:12 +04: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 11:53:05 +04:00
|
|
|
#include "mozilla/dom/Icc.h"
|
2013-10-09 13:40:12 +04:00
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
#include "IccCallback.h"
|
2015-06-16 12:38:27 +03:00
|
|
|
#include "IccContact.h"
|
|
|
|
#include "mozilla/dom/ContactsBinding.h"
|
2014-09-19 11:53:05 +04:00
|
|
|
#include "mozilla/dom/DOMRequest.h"
|
|
|
|
#include "mozilla/dom/IccInfo.h"
|
2013-10-09 13:40:12 +04:00
|
|
|
#include "mozilla/dom/MozStkCommandEvent.h"
|
2014-12-26 05:11:20 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2014-06-11 20:40:38 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-09-19 11:53:05 +04:00
|
|
|
#include "nsIIccInfo.h"
|
2015-01-13 13:03:44 +03:00
|
|
|
#include "nsIIccService.h"
|
2015-04-27 11:01:56 +03:00
|
|
|
#include "nsIStkCmdFactory.h"
|
|
|
|
#include "nsIStkProactiveCmd.h"
|
2013-10-09 13:40:12 +04:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2016-03-10 03:02:25 +03:00
|
|
|
#include "nsContentUtils.h"
|
2013-10-09 13:40:12 +04:00
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
using mozilla::dom::icc::IccCallback;
|
2015-06-16 12:38:27 +03:00
|
|
|
using mozilla::dom::icc::IccContact;
|
2015-01-13 13:03:44 +03:00
|
|
|
|
2014-11-11 13:16:57 +03: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 12:24:11 +03:00
|
|
|
case IccLockType::NsckPuk:
|
|
|
|
case IccLockType::PckPuk:
|
2014-11-11 13:16:57 +03:00
|
|
|
return true;
|
2014-12-23 11:11:17 +03:00
|
|
|
default:
|
|
|
|
return false;
|
2014-11-11 13:16:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2013-10-09 13:40:12 +04:00
|
|
|
|
2014-09-19 11:53:05 +04: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)
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
Icc::Icc(nsPIDOMWindowInner* aWindow, nsIIcc* aHandler, nsIIccInfo* aIccInfo)
|
2013-10-09 13:40:12 +04:00
|
|
|
: mLive(true)
|
2015-01-13 13:03:44 +03:00
|
|
|
, mHandler(aHandler)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
|
|
|
|
2014-09-19 11:53:05 +04:00
|
|
|
if (aIccInfo) {
|
|
|
|
aIccInfo->GetIccid(mIccId);
|
|
|
|
UpdateIccInfo(aIccInfo);
|
|
|
|
}
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2015-03-12 18:55:50 +03:00
|
|
|
Icc::~Icc()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-10-09 13:40:12 +04:00
|
|
|
void
|
|
|
|
Icc::Shutdown()
|
|
|
|
{
|
2014-09-19 11:53:05 +04:00
|
|
|
mIccInfo.SetNull();
|
2015-01-13 13:03:44 +03:00
|
|
|
mHandler = nullptr;
|
2013-10-09 13:40:12 +04:00
|
|
|
mLive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Icc::NotifyEvent(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2015-04-27 11:01:56 +03:00
|
|
|
Icc::NotifyStkEvent(const nsAString& aName, nsIStkProactiveCmd* aStkProactiveCmd)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2016-08-11 15:39:23 +03:00
|
|
|
JS::RootingContext* cx = RootingCx();
|
2013-10-09 13:40:12 +04:00
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
|
2015-04-27 11:01:56 +03: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 13:40:12 +04:00
|
|
|
|
2016-03-11 02:07:28 +03:00
|
|
|
RootedDictionary<MozStkCommandEventInit> init(cx);
|
2013-10-09 13:40:12 +04:00
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mCommand = value;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MozStkCommandEvent> event =
|
2013-10-09 13:40:12 +04:00
|
|
|
MozStkCommandEvent::Constructor(this, aName, init);
|
|
|
|
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-09-19 11:53:05 +04: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 13:40:12 +04: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 17:13:33 +03:00
|
|
|
Icc::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-10-09 13:40:12 +04: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 17:13:33 +03:00
|
|
|
return MozIccBinding::Wrap(aCx, this, aGivenProto);
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// MozIcc WebIDL
|
|
|
|
|
2014-09-19 11:53:05 +04:00
|
|
|
void
|
|
|
|
Icc::GetIccInfo(Nullable<OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo>& aIccInfo) const
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2014-09-19 11:53:05 +04:00
|
|
|
aIccInfo = mIccInfo;
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 15:31:00 +04:00
|
|
|
Nullable<IccCardState>
|
|
|
|
Icc::GetCardState() const
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2014-09-03 15:31:00 +04:00
|
|
|
Nullable<IccCardState> result;
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
uint32_t cardState = nsIIcc::CARD_STATE_UNDETECTED;
|
|
|
|
if (mHandler &&
|
|
|
|
NS_SUCCEEDED(mHandler->GetCardState(&cardState)) &&
|
|
|
|
cardState != nsIIcc::CARD_STATE_UNDETECTED) {
|
2014-09-03 15:31:00 +04:00
|
|
|
MOZ_ASSERT(cardState < static_cast<uint32_t>(IccCardState::EndGuard_));
|
|
|
|
result.SetValue(static_cast<IccCardState>(cardState));
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 15:31:00 +04:00
|
|
|
return result;
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-09 21:39:36 +04:00
|
|
|
Icc::SendStkResponse(const JSContext* aCx, JS::Handle<JS::Value> aCommand,
|
|
|
|
JS::Handle<JS::Value> aResponse, ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2015-04-29 05:42:35 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 05:42:35 +03: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 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Icc::SendStkMenuSelection(uint16_t aItemIdentifier, bool aHelpRequested,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-04-29 05:42:35 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 05:42:35 +03:00
|
|
|
nsresult rv = mHandler->SendStkMenuSelection(aItemIdentifier, aHelpRequested);
|
2013-10-09 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-09 21:39:36 +04:00
|
|
|
Icc::SendStkTimerExpiration(const JSContext* aCx, JS::Handle<JS::Value> aTimer,
|
2013-10-09 13:40:12 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-04-29 05:42:35 +03:00
|
|
|
if (!mHandler) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStkCmdFactory> cmdFactory =
|
|
|
|
do_GetService(ICC_STK_CMD_FACTORY_CONTRACTID);
|
|
|
|
if (!cmdFactory) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 05:42:35 +03: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 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-09 21:39:36 +04:00
|
|
|
Icc::SendStkEventDownload(const JSContext* aCx, JS::Handle<JS::Value> aEvent,
|
2013-10-09 13:40:12 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-04-29 05:42:35 +03: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 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-29 05:42:35 +03:00
|
|
|
nsresult rv = mHandler->SendStkEventDownload(event);
|
2013-10-09 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 13:16:57 +03:00
|
|
|
Icc::GetCardLock(IccLockType aLockType, ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
2015-01-13 13:03:44 +03:00
|
|
|
// TODO: Bug 1125018 - Simplify The Result of GetCardLock and
|
|
|
|
// getCardLockRetryCount in MozIcc.webidl without a wrapper object.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-01-13 13:03:44 +03:00
|
|
|
new IccCallback(GetOwner(), request, true);
|
|
|
|
nsresult rv = mHandler->GetCardLockEnabled(static_cast<uint32_t>(aLockType),
|
|
|
|
requestCallback);
|
2013-10-09 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
return request.forget();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 13:16:57 +03:00
|
|
|
Icc::UnlockCardLock(const IccUnlockCardLockOptions& aOptions, ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-01-13 13:03:44 +03:00
|
|
|
new IccCallback(GetOwner(), request);
|
2014-11-11 13:16:57 +03:00
|
|
|
const nsString& password = IsPukCardLockType(aOptions.mLockType)
|
|
|
|
? aOptions.mPuk : aOptions.mPin;
|
2015-01-13 13:03:44 +03:00
|
|
|
nsresult rv =
|
|
|
|
mHandler->UnlockCardLock(static_cast<uint32_t>(aOptions.mLockType),
|
|
|
|
password, aOptions.mNewPin, requestCallback);
|
2013-10-09 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
return request.forget();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 13:16:57 +03:00
|
|
|
Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:16:57 +03:00
|
|
|
nsresult rv;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-01-13 13:03:44 +03:00
|
|
|
new IccCallback(GetOwner(), request);
|
2014-11-11 13:16:57 +03:00
|
|
|
|
|
|
|
if (aOptions.mEnabled.WasPassed()) {
|
|
|
|
// Enable card lock.
|
|
|
|
const nsString& password = (aOptions.mLockType == IccLockType::Fdn) ?
|
|
|
|
aOptions.mPin2 : aOptions.mPin;
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
rv =
|
|
|
|
mHandler->SetCardLockEnabled(static_cast<uint32_t>(aOptions.mLockType),
|
|
|
|
password, aOptions.mEnabled.Value(),
|
|
|
|
requestCallback);
|
2014-11-11 13:16:57 +03:00
|
|
|
} else {
|
|
|
|
// Change card lock password.
|
2015-01-13 13:03:44 +03:00
|
|
|
rv =
|
|
|
|
mHandler->ChangeCardLockPassword(static_cast<uint32_t>(aOptions.mLockType),
|
|
|
|
aOptions.mPin, aOptions.mNewPin,
|
|
|
|
requestCallback);
|
2014-11-11 13:16:57 +03:00
|
|
|
}
|
|
|
|
|
2013-10-09 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
return request.forget();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-11-11 13:16:57 +03:00
|
|
|
Icc::GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-01-13 13:03:44 +03:00
|
|
|
new IccCallback(GetOwner(), request);
|
|
|
|
nsresult rv = mHandler->GetCardLockRetryCount(static_cast<uint32_t>(aLockType),
|
|
|
|
requestCallback);
|
2013-10-09 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
return request.forget();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-12-12 06:08:27 +03:00
|
|
|
Icc::ReadContacts(IccContactType aContactType, ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2015-06-16 12:38:27 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-06-16 12:38:27 +03:00
|
|
|
new IccCallback(GetOwner(), request);
|
|
|
|
|
|
|
|
nsresult rv = mHandler->ReadContacts(static_cast<uint32_t>(aContactType),
|
|
|
|
requestCallback);
|
2013-10-09 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-16 12:38:27 +03:00
|
|
|
return request.forget();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2015-06-16 12:38:27 +03:00
|
|
|
Icc::UpdateContact(IccContactType aContactType, mozContact& aContact,
|
|
|
|
const nsAString& aPin2, ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
2015-06-16 12:38:27 +03:00
|
|
|
if (!mHandler) {
|
2013-10-09 13:40:12 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-06-16 12:38:27 +03:00
|
|
|
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 13:40:12 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-16 12:38:27 +03:00
|
|
|
return request.forget();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-12-12 14:04:00 +03:00
|
|
|
Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData,
|
2014-01-28 14:58:00 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
if (!mHandler) {
|
2014-01-28 14:58:00 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-01-13 13:03:44 +03:00
|
|
|
new IccCallback(GetOwner(), request);
|
|
|
|
nsresult rv = mHandler->MatchMvno(static_cast<uint32_t>(aMvnoType),
|
|
|
|
aMvnoData, requestCallback);
|
2014-01-28 14:58:00 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
return request.forget();
|
2014-01-28 14:58:00 +04:00
|
|
|
}
|
2014-11-11 13:16:57 +03:00
|
|
|
|
2014-12-26 05:11:20 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Icc::GetServiceState(IccService aService, ErrorResult& aRv)
|
|
|
|
{
|
2015-01-13 13:03:44 +03:00
|
|
|
if (!mHandler) {
|
2014-12-26 05:11:20 +03:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-13 13:03:44 +03:00
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
if (!global) {
|
2015-03-18 21:48:52 +03:00
|
|
|
return nullptr;
|
2015-01-13 13:03:44 +03:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
2015-01-13 13:03:44 +03:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IccCallback> requestCallback =
|
2015-01-13 13:03:44 +03:00
|
|
|
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 05:11:20 +03:00
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
2014-11-11 13:16:57 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|