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
|
|
|
|
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-06-11 20:40:38 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-09-19 11:53:05 +04:00
|
|
|
#include "nsIIccInfo.h"
|
|
|
|
#include "nsIIccProvider.h"
|
2013-10-09 13:40:12 +04:00
|
|
|
#include "nsJSON.h"
|
|
|
|
#include "nsRadioInterfaceLayer.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo)
|
2013-10-09 13:40:12 +04:00
|
|
|
: mLive(true)
|
|
|
|
, mClientId(aClientId)
|
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
|
|
|
|
|
|
|
mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
|
2014-09-19 11:53:05 +04:00
|
|
|
if (aIccInfo) {
|
|
|
|
aIccInfo->GetIccid(mIccId);
|
|
|
|
UpdateIccInfo(aIccInfo);
|
|
|
|
}
|
|
|
|
|
2013-10-09 13:40:12 +04:00
|
|
|
// Not being able to acquire the provider isn't fatal since we check
|
|
|
|
// for it explicitly below.
|
|
|
|
if (!mProvider) {
|
|
|
|
NS_WARNING("Could not acquire nsIIccProvider!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Icc::Shutdown()
|
|
|
|
{
|
2014-09-19 11:53:05 +04:00
|
|
|
mIccInfo.SetNull();
|
2013-10-09 13:40:12 +04:00
|
|
|
mProvider = nullptr;
|
|
|
|
mLive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Icc::NotifyEvent(const nsAString& aName)
|
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Icc::NotifyStkEvent(const nsAString& aName, const nsAString& aMessage)
|
|
|
|
{
|
2014-06-19 11:21:14 +04:00
|
|
|
AutoJSAPI jsapi;
|
2014-06-25 14:17:17 +04:00
|
|
|
if (NS_WARN_IF(!jsapi.InitWithLegacyErrorReporting(GetOwner()))) {
|
2014-06-19 11:21:14 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2014-06-11 20:40:38 +04:00
|
|
|
JSContext* cx = jsapi.cx();
|
2013-10-09 13:40:12 +04:00
|
|
|
JS::Rooted<JS::Value> value(cx);
|
|
|
|
|
|
|
|
if (!aMessage.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIJSON> json(new nsJSON());
|
2014-01-09 21:39:36 +04:00
|
|
|
nsresult rv = json->DecodeToJSVal(aMessage, cx, &value);
|
2013-10-09 13:40:12 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
value = JS::NullValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 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*
|
2014-04-09 02:27:18 +04:00
|
|
|
Icc::WrapObject(JSContext* aCx)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-09 02:27:17 +04:00
|
|
|
return MozIccBinding::Wrap(aCx, this);
|
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;
|
|
|
|
|
|
|
|
uint32_t cardState = nsIIccProvider::CARD_STATE_UNDETECTED;
|
|
|
|
if (mProvider &&
|
|
|
|
NS_SUCCEEDED(mProvider->GetCardState(mClientId, &cardState)) &&
|
|
|
|
cardState != nsIIccProvider::CARD_STATE_UNDETECTED) {
|
|
|
|
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
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mProvider->SendStkResponse(mClientId, GetOwner(), aCommand,
|
|
|
|
aResponse);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Icc::SendStkMenuSelection(uint16_t aItemIdentifier, bool aHelpRequested,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mProvider->SendStkMenuSelection(mClientId,
|
|
|
|
GetOwner(),
|
|
|
|
aItemIdentifier,
|
|
|
|
aHelpRequested);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mProvider->SendStkTimerExpiration(mClientId, GetOwner(),
|
|
|
|
aTimer);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mProvider->SendStkEventDownload(mClientId, GetOwner(), aEvent);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-10-09 13:40:12 +04:00
|
|
|
Icc::GetCardLock(const nsAString& aLockType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsIDOMDOMRequest> request;
|
|
|
|
nsresult rv = mProvider->GetCardLockState(mClientId, GetOwner(), aLockType,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
return request.forget().downcast<DOMRequest>();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-01-09 21:39:36 +04:00
|
|
|
Icc::UnlockCardLock(const JSContext* aCx, JS::Handle<JS::Value> aInfo,
|
2013-10-09 13:40:12 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsIDOMDOMRequest> request;
|
|
|
|
nsresult rv = mProvider->UnlockCardLock(mClientId, GetOwner(), aInfo,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
return request.forget().downcast<DOMRequest>();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-01-09 21:39:36 +04:00
|
|
|
Icc::SetCardLock(const JSContext* aCx, JS::Handle<JS::Value> aInfo,
|
|
|
|
ErrorResult& aRv)
|
2013-10-09 13:40:12 +04:00
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsIDOMDOMRequest> request;
|
|
|
|
nsresult rv = mProvider->SetCardLock(mClientId, GetOwner(), aInfo,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
return request.forget().downcast<DOMRequest>();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-10-09 13:40:12 +04:00
|
|
|
Icc::GetCardLockRetryCount(const nsAString& aLockType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsIDOMDOMRequest> request;
|
|
|
|
nsresult rv = mProvider->GetCardLockRetryCount(mClientId,
|
|
|
|
GetOwner(),
|
|
|
|
aLockType,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
return request.forget().downcast<DOMRequest>();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-10-09 13:40:12 +04:00
|
|
|
Icc::ReadContacts(const nsAString& aContactType, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsIDOMDOMRequest> request;
|
|
|
|
nsresult rv = mProvider->ReadContacts(mClientId, GetOwner(), aContactType,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
return request.forget().downcast<DOMRequest>();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2013-10-09 13:40:12 +04:00
|
|
|
Icc::UpdateContact(const JSContext* aCx, const nsAString& aContactType,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::Handle<JS::Value> aContact, const nsAString& aPin2,
|
2013-10-09 13:40:12 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsIDOMDOMRequest> request;
|
|
|
|
nsresult rv = mProvider->UpdateContact(mClientId, GetOwner(), aContactType,
|
|
|
|
aContact, aPin2,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
return request.forget().downcast<DOMRequest>();
|
2013-10-09 13:40:12 +04:00
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-01-28 14:58:00 +04:00
|
|
|
Icc::MatchMvno(const nsAString& aMvnoType,
|
|
|
|
const nsAString& aMvnoData,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsIDOMDOMRequest> request;
|
|
|
|
nsresult rv = mProvider->MatchMvno(mClientId, GetOwner(),
|
|
|
|
aMvnoType, aMvnoData,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:37:58 +04:00
|
|
|
return request.forget().downcast<DOMRequest>();
|
2014-01-28 14:58:00 +04:00
|
|
|
}
|