Bug 1114935 - Part 5.1: Bind new nsIccService into MozIcc. r=echen, r=hsinyi

--HG--
extra : histedit_source : c4f30cabe18e4a2ef4f6a34745e95d46c5baaff7
This commit is contained in:
Bevis Tseng 2015-01-13 18:03:44 +08:00
parent 1cba772979
commit e511c87731
13 changed files with 385 additions and 61 deletions

View File

@ -4,6 +4,7 @@
#include "mozilla/dom/Icc.h" #include "mozilla/dom/Icc.h"
#include "IccCallback.h"
#include "mozilla/dom/DOMRequest.h" #include "mozilla/dom/DOMRequest.h"
#include "mozilla/dom/IccInfo.h" #include "mozilla/dom/IccInfo.h"
#include "mozilla/dom/MozStkCommandEvent.h" #include "mozilla/dom/MozStkCommandEvent.h"
@ -11,10 +12,13 @@
#include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/ScriptSettings.h"
#include "nsIIccInfo.h" #include "nsIIccInfo.h"
#include "nsIIccProvider.h" #include "nsIIccProvider.h"
#include "nsIIccService.h"
#include "nsJSON.h" #include "nsJSON.h"
#include "nsRadioInterfaceLayer.h" #include "nsRadioInterfaceLayer.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
using mozilla::dom::icc::IccCallback;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -50,9 +54,10 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(Icc, DOMEventTargetHelper) NS_IMPL_ADDREF_INHERITED(Icc, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(Icc, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(Icc, DOMEventTargetHelper)
Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo) Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIcc* aHandler, nsIIccInfo* aIccInfo)
: mLive(true) : mLive(true)
, mClientId(aClientId) , mClientId(aClientId)
, mHandler(aHandler)
{ {
BindToOwner(aWindow); BindToOwner(aWindow);
@ -79,6 +84,7 @@ Icc::Shutdown()
{ {
mIccInfo.SetNull(); mIccInfo.SetNull();
mProvider = nullptr; mProvider = nullptr;
mHandler = nullptr;
mLive = false; mLive = false;
} }
@ -170,10 +176,10 @@ Icc::GetCardState() const
{ {
Nullable<IccCardState> result; Nullable<IccCardState> result;
uint32_t cardState = nsIIccProvider::CARD_STATE_UNDETECTED; uint32_t cardState = nsIIcc::CARD_STATE_UNDETECTED;
if (mProvider && if (mHandler &&
NS_SUCCEEDED(mProvider->GetCardState(mClientId, &cardState)) && NS_SUCCEEDED(mHandler->GetCardState(&cardState)) &&
cardState != nsIIccProvider::CARD_STATE_UNDETECTED) { cardState != nsIIcc::CARD_STATE_UNDETECTED) {
MOZ_ASSERT(cardState < static_cast<uint32_t>(IccCardState::EndGuard_)); MOZ_ASSERT(cardState < static_cast<uint32_t>(IccCardState::EndGuard_));
result.SetValue(static_cast<IccCardState>(cardState)); result.SetValue(static_cast<IccCardState>(cardState));
} }
@ -249,72 +255,78 @@ Icc::SendStkEventDownload(const JSContext* aCx, JS::Handle<JS::Value> aEvent,
already_AddRefed<DOMRequest> already_AddRefed<DOMRequest>
Icc::GetCardLock(IccLockType aLockType, ErrorResult& aRv) Icc::GetCardLock(IccLockType aLockType, ErrorResult& aRv)
{ {
if (!mProvider) { if (!mHandler) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
nsRefPtr<nsIDOMDOMRequest> request; nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsresult rv = mProvider->GetCardLockEnabled(mClientId, GetOwner(), // TODO: Bug 1125018 - Simplify The Result of GetCardLock and
static_cast<uint32_t>(aLockType), // getCardLockRetryCount in MozIcc.webidl without a wrapper object.
getter_AddRefs(request)); nsRefPtr<IccCallback> requestCallback =
new IccCallback(GetOwner(), request, true);
nsresult rv = mHandler->GetCardLockEnabled(static_cast<uint32_t>(aLockType),
requestCallback);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
aRv.Throw(rv); aRv.Throw(rv);
return nullptr; return nullptr;
} }
return request.forget().downcast<DOMRequest>(); return request.forget();
} }
already_AddRefed<DOMRequest> already_AddRefed<DOMRequest>
Icc::UnlockCardLock(const IccUnlockCardLockOptions& aOptions, ErrorResult& aRv) Icc::UnlockCardLock(const IccUnlockCardLockOptions& aOptions, ErrorResult& aRv)
{ {
if (!mProvider) { if (!mHandler) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
nsRefPtr<nsIDOMDOMRequest> request; nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsRefPtr<IccCallback> requestCallback =
new IccCallback(GetOwner(), request);
const nsString& password = IsPukCardLockType(aOptions.mLockType) const nsString& password = IsPukCardLockType(aOptions.mLockType)
? aOptions.mPuk : aOptions.mPin; ? aOptions.mPuk : aOptions.mPin;
nsresult rv = mProvider->UnlockCardLock(mClientId, GetOwner(), nsresult rv =
static_cast<uint32_t>(aOptions.mLockType), mHandler->UnlockCardLock(static_cast<uint32_t>(aOptions.mLockType),
password, aOptions.mNewPin, password, aOptions.mNewPin, requestCallback);
getter_AddRefs(request));
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
aRv.Throw(rv); aRv.Throw(rv);
return nullptr; return nullptr;
} }
return request.forget().downcast<DOMRequest>(); return request.forget();
} }
already_AddRefed<DOMRequest> already_AddRefed<DOMRequest>
Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv) Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv)
{ {
if (!mProvider) { if (!mHandler) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
nsresult rv; nsresult rv;
nsRefPtr<nsIDOMDOMRequest> request; nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsRefPtr<IccCallback> requestCallback =
new IccCallback(GetOwner(), request);
if (aOptions.mEnabled.WasPassed()) { if (aOptions.mEnabled.WasPassed()) {
// Enable card lock. // Enable card lock.
const nsString& password = (aOptions.mLockType == IccLockType::Fdn) ? const nsString& password = (aOptions.mLockType == IccLockType::Fdn) ?
aOptions.mPin2 : aOptions.mPin; aOptions.mPin2 : aOptions.mPin;
rv = mProvider->SetCardLockEnabled(mClientId, GetOwner(), rv =
static_cast<uint32_t>(aOptions.mLockType), mHandler->SetCardLockEnabled(static_cast<uint32_t>(aOptions.mLockType),
password, aOptions.mEnabled.Value(), password, aOptions.mEnabled.Value(),
getter_AddRefs(request)); requestCallback);
} else { } else {
// Change card lock password. // Change card lock password.
rv = mProvider->ChangeCardLockPassword(mClientId, GetOwner(), rv =
static_cast<uint32_t>(aOptions.mLockType), mHandler->ChangeCardLockPassword(static_cast<uint32_t>(aOptions.mLockType),
aOptions.mPin, aOptions.mNewPin, aOptions.mPin, aOptions.mNewPin,
getter_AddRefs(request)); requestCallback);
} }
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -322,27 +334,28 @@ Icc::SetCardLock(const IccSetCardLockOptions& aOptions, ErrorResult& aRv)
return nullptr; return nullptr;
} }
return request.forget().downcast<DOMRequest>(); return request.forget();
} }
already_AddRefed<DOMRequest> already_AddRefed<DOMRequest>
Icc::GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv) Icc::GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv)
{ {
if (!mProvider) { if (!mHandler) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
nsRefPtr<nsIDOMDOMRequest> request; nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsresult rv = mProvider->GetCardLockRetryCount(mClientId, GetOwner(), nsRefPtr<IccCallback> requestCallback =
static_cast<uint32_t>(aLockType), new IccCallback(GetOwner(), request);
getter_AddRefs(request)); nsresult rv = mHandler->GetCardLockRetryCount(static_cast<uint32_t>(aLockType),
requestCallback);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
aRv.Throw(rv); aRv.Throw(rv);
return nullptr; return nullptr;
} }
return request.forget().downcast<DOMRequest>(); return request.forget();
} }
already_AddRefed<DOMRequest> already_AddRefed<DOMRequest>
@ -392,41 +405,54 @@ already_AddRefed<DOMRequest>
Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData, Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData,
ErrorResult& aRv) ErrorResult& aRv)
{ {
if (!mProvider) { if (!mHandler) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
nsRefPtr<nsIDOMDOMRequest> request; nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsresult rv = mProvider->MatchMvno(mClientId, GetOwner(), nsRefPtr<IccCallback> requestCallback =
static_cast<uint32_t>(aMvnoType), new IccCallback(GetOwner(), request);
aMvnoData, getter_AddRefs(request)); nsresult rv = mHandler->MatchMvno(static_cast<uint32_t>(aMvnoType),
aMvnoData, requestCallback);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
aRv.Throw(rv); aRv.Throw(rv);
return nullptr; return nullptr;
} }
return request.forget().downcast<DOMRequest>(); return request.forget();
} }
already_AddRefed<Promise> already_AddRefed<Promise>
Icc::GetServiceState(IccService aService, ErrorResult& aRv) Icc::GetServiceState(IccService aService, ErrorResult& aRv)
{ {
if (!mProvider) { if (!mHandler) {
aRv.Throw(NS_ERROR_FAILURE); aRv.Throw(NS_ERROR_FAILURE);
return nullptr; return nullptr;
} }
nsCOMPtr<nsISupports> supports; nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
nsresult rv = mProvider->GetServiceState(mClientId, GetOwner(), if (!global) {
static_cast<uint32_t>(aService),
getter_AddRefs(supports));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr; return nullptr;
} }
nsCOMPtr<Promise> promise = do_QueryInterface(supports); 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.
}
return promise.forget(); return promise.forget();
} }

View File

@ -8,6 +8,7 @@
#include "mozilla/dom/MozIccBinding.h" #include "mozilla/dom/MozIccBinding.h"
#include "mozilla/DOMEventTargetHelper.h" #include "mozilla/DOMEventTargetHelper.h"
class nsIIcc;
class nsIIccInfo; class nsIIccInfo;
class nsIIccProvider; class nsIIccProvider;
@ -25,7 +26,8 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Icc, DOMEventTargetHelper) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Icc, DOMEventTargetHelper)
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIccInfo* aIccInfo); Icc(nsPIDOMWindow* aWindow, long aClientId,
nsIIcc* aHandler, nsIIccInfo* aIccInfo);
void void
Shutdown(); Shutdown();
@ -111,14 +113,20 @@ public:
IMPL_EVENT_HANDLER(stksessionend) IMPL_EVENT_HANDLER(stksessionend)
private: private:
// Put definition of the destructor in Icc.cpp to ensure forward declaration
// of nsIIccProvider, nsIIcc for the auto-generated .cpp file (i.e.,
// MozIccManagerBinding.cpp) that includes this header.
~Icc(); ~Icc();
bool mLive; bool mLive;
uint32_t mClientId; uint32_t mClientId;
nsString mIccId; nsString mIccId;
// mProvider is a xpcom service and will be released at shutdown, so it // mProvider is a xpcom service and will be released at Shutdown(), so it
// doesn't need to be cycle collected. // doesn't need to be cycle collected.
nsCOMPtr<nsIIccProvider> mProvider; nsCOMPtr<nsIIccProvider> mProvider;
// mHandler will be released at Shutdown(), so there is no need to join cycle
// collection.
nsCOMPtr<nsIIcc> mHandler;
Nullable<OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo> mIccInfo; Nullable<OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo> mIccInfo;
}; };

135
dom/icc/IccCallback.cpp Normal file
View File

@ -0,0 +1,135 @@
/* 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/. */
#include "IccCallback.h"
#include "mozilla/dom/IccCardLockError.h"
#include "mozilla/dom/MozIccBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsJSUtils.h"
#include "nsServiceManagerUtils.h"
namespace mozilla {
namespace dom {
namespace icc {
NS_IMPL_ISUPPORTS(IccCallback, nsIIccCallback)
IccCallback::IccCallback(nsPIDOMWindow* aWindow, DOMRequest* aRequest,
bool aIsCardLockEnabled)
: mWindow(aWindow)
, mRequest(aRequest)
, mIsCardLockEnabled(aIsCardLockEnabled)
{
}
IccCallback::IccCallback(nsPIDOMWindow* aWindow, Promise* aPromise)
: mWindow(aWindow)
, mPromise(aPromise)
{
}
nsresult
IccCallback::NotifySuccess(JS::Handle<JS::Value> aResult)
{
nsCOMPtr<nsIDOMRequestService> rs =
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
return rs->FireSuccessAsync(mRequest, aResult);
}
nsresult
IccCallback::NotifyGetCardLockEnabled(bool aResult)
{
IccCardLockStatus result;
result.mEnabled.Construct(aResult);
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
return NS_ERROR_FAILURE;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JS::Value> jsResult(cx);
if (!ToJSValue(cx, result, &jsResult)) {
JS_ClearPendingException(cx);
return NS_ERROR_TYPE_ERR;
}
return NotifySuccess(jsResult);
}
NS_IMETHODIMP
IccCallback::NotifySuccess()
{
return NotifySuccess(JS::UndefinedHandleValue);
}
NS_IMETHODIMP
IccCallback::NotifySuccessWithBoolean(bool aResult)
{
if (mPromise) {
mPromise->MaybeResolve(aResult ? JS::TrueHandleValue : JS::FalseHandleValue);
return NS_OK;
}
return mIsCardLockEnabled
? NotifyGetCardLockEnabled(aResult)
: NotifySuccess(aResult ? JS::TrueHandleValue : JS::FalseHandleValue);
}
NS_IMETHODIMP
IccCallback::NotifyGetCardLockRetryCount(int32_t aCount)
{
// TODO: Bug 1125018 - Simplify The Result of GetCardLock and
// getCardLockRetryCount in MozIcc.webidl without a wrapper object.
IccCardLockRetryCount result;
result.mRetryCount.Construct(aCount);
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(mWindow))) {
return NS_ERROR_FAILURE;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JS::Value> jsResult(cx);
if (!ToJSValue(cx, result, &jsResult)) {
JS_ClearPendingException(cx);
return NS_ERROR_TYPE_ERR;
}
return NotifySuccess(jsResult);
}
NS_IMETHODIMP
IccCallback::NotifyError(const nsAString & aErrorMsg)
{
if (mPromise) {
mPromise->MaybeRejectBrokenly(aErrorMsg);
return NS_OK;
}
nsCOMPtr<nsIDOMRequestService> rs =
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
return rs->FireErrorAsync(mRequest, aErrorMsg);
}
NS_IMETHODIMP
IccCallback::NotifyCardLockError(const nsAString & aErrorMsg,
int32_t aRetryCount)
{
nsRefPtr<IccCardLockError> error =
new IccCardLockError(mWindow, aErrorMsg, aRetryCount);
mRequest->FireDetailedError(error);
return NS_OK;
}
} // namespace icc
} // namespace dom
} // namespace mozilla

64
dom/icc/IccCallback.h Normal file
View File

@ -0,0 +1,64 @@
/* 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/. */
#ifndef mozilla_dom_icc_IccCallback_h
#define mozilla_dom_icc_IccCallback_h
#include "nsCOMPtr.h"
#include "nsIIccService.h"
namespace mozilla {
namespace dom {
class DOMRequest;
class Promise;
namespace icc {
/**
* A callback object for handling asynchronous request/response. This object is
* created when an asynchronous request is made and should be destroyed after
* Notify*Success/Error is called.
* The modules hold the reference of IccCallback in OOP mode and non-OOP mode
* are different.
* - OOP mode: IccRequestChild
* - non-OOP mode: IccService
* The reference should be released after Notify*Success/Error is called.
*/
class IccCallback final : public nsIIccCallback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIICCCALLBACK
// TODO: Bug 1125018 - Simplify The Result of GetCardLock and
// getCardLockRetryCount in MozIcc.webidl without a wrapper object.
IccCallback(nsPIDOMWindow* aWindow, DOMRequest* aRequest,
bool aIsCardLockEnabled = false);
IccCallback(nsPIDOMWindow* aWindow, Promise* aPromise);
private:
~IccCallback() {}
nsresult
NotifySuccess(JS::Handle<JS::Value> aResult);
// TODO: Bug 1125018 - Simplify The Result of GetCardLock and
// getCardLockRetryCount in MozIcc.webidl without a wrapper object.
nsresult
NotifyGetCardLockEnabled(bool aResult);
nsCOMPtr<nsPIDOMWindow> mWindow;
nsRefPtr<DOMRequest> mRequest;
nsRefPtr<Promise> mPromise;
// TODO: Bug 1125018 - Simplify The Result of GetCardLock and
// getCardLockRetryCount in MozIcc.webidl without a wrapper object.
bool mIsCardLockEnabled;
};
} // namespace icc
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_icc_IccCallback_h

View File

@ -20,6 +20,8 @@ IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
{ {
MOZ_ASSERT(mIccManager); MOZ_ASSERT(mIccManager);
// TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL.
// Remove the registration to IccProvider.
mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID); mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
if (!mProvider) { if (!mProvider) {
@ -27,17 +29,34 @@ IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
return; return;
} }
nsCOMPtr<nsIIccService> iccService = do_GetService(ICC_SERVICE_CONTRACTID);
if (!iccService) {
NS_WARNING("Could not acquire nsIIccService!");
return;
}
iccService->GetIccByServiceId(mClientId, getter_AddRefs(mHandler));
if (!mHandler) {
NS_WARNING("Could not acquire nsIIcc!");
return;
}
nsCOMPtr<nsIIccInfo> iccInfo; nsCOMPtr<nsIIccInfo> iccInfo;
mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo)); mHandler->GetIccInfo(getter_AddRefs(iccInfo));
if (iccInfo) { if (iccInfo) {
nsString iccId; nsString iccId;
iccInfo->GetIccid(iccId); iccInfo->GetIccid(iccId);
if (!iccId.IsEmpty()) { if (!iccId.IsEmpty()) {
mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccInfo); mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
} }
} }
DebugOnly<nsresult> rv = mProvider->RegisterIccMsg(mClientId, this); DebugOnly<nsresult> rv = mHandler->RegisterListener(this);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Failed registering icc listener with Icc Handler");
rv = mProvider->RegisterIccMsg(mClientId, this);
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Failed registering icc messages with provider"); "Failed registering icc messages with provider");
} }
@ -50,11 +69,18 @@ IccListener::~IccListener()
void void
IccListener::Shutdown() IccListener::Shutdown()
{ {
// TODO: Bug 1114938, Refactor STK in MozIcc.webidl with IPDL.
// Remove the unregistration to IccProvider.
if (mProvider) { if (mProvider) {
mProvider->UnregisterIccMsg(mClientId, this); mProvider->UnregisterIccMsg(mClientId, this);
mProvider = nullptr; mProvider = nullptr;
} }
if (mHandler) {
mHandler->UnregisterListener(this);
mHandler = nullptr;
}
if (mIcc) { if (mIcc) {
mIcc->Shutdown(); mIcc->Shutdown();
mIcc = nullptr; mIcc = nullptr;
@ -98,8 +124,12 @@ IccListener::NotifyCardStateChanged()
NS_IMETHODIMP NS_IMETHODIMP
IccListener::NotifyIccInfoChanged() IccListener::NotifyIccInfoChanged()
{ {
if (!mHandler) {
return NS_OK;
}
nsCOMPtr<nsIIccInfo> iccInfo; nsCOMPtr<nsIIccInfo> iccInfo;
mProvider->GetIccInfo(mClientId, getter_AddRefs(iccInfo)); mHandler->GetIccInfo(getter_AddRefs(iccInfo));
// Create/delete icc object based on current iccInfo. // Create/delete icc object based on current iccInfo.
// 1. If the mIcc is nullptr and iccInfo has valid data, create icc object and // 1. If the mIcc is nullptr and iccInfo has valid data, create icc object and
@ -111,7 +141,7 @@ IccListener::NotifyIccInfoChanged()
nsString iccId; nsString iccId;
iccInfo->GetIccid(iccId); iccInfo->GetIccid(iccId);
if (!iccId.IsEmpty()) { if (!iccId.IsEmpty()) {
mIcc = new Icc(mIccManager->GetOwner(), mClientId, iccInfo); mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
mIccManager->NotifyIccAdd(iccId); mIccManager->NotifyIccAdd(iccId);
mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange")); mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
} }

View File

@ -7,6 +7,7 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsIIccProvider.h" #include "nsIIccProvider.h"
#include "nsIIccService.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -42,9 +43,12 @@ private:
// IccListener, this will release the reference and break the cycle. // IccListener, this will release the reference and break the cycle.
nsRefPtr<Icc> mIcc; nsRefPtr<Icc> mIcc;
nsRefPtr<IccManager> mIccManager; nsRefPtr<IccManager> mIccManager;
// mProvider is a xpcom service and will be released at shutdown, so it // mProvider is a xpcom service and will be released at Shutdown(), so it
// doesn't need to be cycle collected. // doesn't need to be cycle collected.
nsCOMPtr<nsIIccProvider> mProvider; nsCOMPtr<nsIIccProvider> mProvider;
// mHandler will be released at Shutdown(), there is no need to join cycle
// collection.
nsCOMPtr<nsIIcc> mHandler;
}; };
} // namespace dom } // namespace dom

View File

@ -10,6 +10,12 @@
#include "mozilla/dom/IccChangeEvent.h" #include "mozilla/dom/IccChangeEvent.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "nsIIccInfo.h" #include "nsIIccInfo.h"
// Service instantiation
#include "ipc/IccIPCService.h"
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
#include "nsIGonkIccService.h"
#endif
#include "nsXULAppAPI.h" // For XRE_GetProcessType()
using namespace mozilla::dom; using namespace mozilla::dom;
@ -129,3 +135,19 @@ IccManager::GetIccById(const nsAString& aIccId) const
} }
return nullptr; return nullptr;
} }
already_AddRefed<nsIIccService>
NS_CreateIccService()
{
nsCOMPtr<nsIIccService> service;
if (XRE_GetProcessType() == GeckoProcessType_Content) {
service = new mozilla::dom::icc::IccIPCService();
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
} else {
service = do_GetService(GONK_ICC_SERVICE_CONTRACTID);
#endif
}
return service.forget();
}

View File

@ -7,7 +7,6 @@
#include "mozilla/DOMEventTargetHelper.h" #include "mozilla/DOMEventTargetHelper.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsIIccProvider.h"
#include "nsTArrayHelpers.h" #include "nsTArrayHelpers.h"
namespace mozilla { namespace mozilla {
@ -25,7 +24,7 @@ public:
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IccManager, DOMEventTargetHelper) NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IccManager, DOMEventTargetHelper)
IccManager(nsPIDOMWindow* aWindow); explicit IccManager(nsPIDOMWindow* aWindow);
void void
Shutdown(); Shutdown();

View File

@ -4,6 +4,11 @@
#include "nsIIccService.idl" #include "nsIIccService.idl"
%{C++
#define GONK_ICC_SERVICE_CONTRACTID \
"@mozilla.org/icc/gonkiccservice;1"
%}
[scriptable, uuid(a037b8a2-b027-11e4-9496-c3b7af59a512)] [scriptable, uuid(a037b8a2-b027-11e4-9496-c3b7af59a512)]
interface nsIGonkIccService : nsIIccService interface nsIGonkIccService : nsIIccService
{ {

View File

@ -63,6 +63,15 @@ interface nsIIccCallback : nsISupports
void notifyCardLockError(in DOMString aErrorMsg, in long aRetryCount); void notifyCardLockError(in DOMString aErrorMsg, in long aRetryCount);
}; };
%{C++
#define ICC_SERVICE_CID \
{ 0xbab0277a, 0x900e, 0x11e4, { 0x80, 0xc7, 0xdb, 0xd7, 0xad, 0x05, 0x24, 0x01 } }
#define ICC_SERVICE_CONTRACTID \
"@mozilla.org/icc/iccservice;1"
template<typename T> struct already_AddRefed;
%}
/** /**
* XPCOM Service for the selection of the ICC to be accessed. * XPCOM Service for the selection of the ICC to be accessed.
*/ */
@ -80,6 +89,11 @@ interface nsIIccService : nsISupports
nsIIcc getIccByServiceId(in unsigned long aServiceId); nsIIcc getIccByServiceId(in unsigned long aServiceId);
}; };
%{C++
already_AddRefed<nsIIccService>
NS_CreateIccService();
%}
/** /**
* XPCOM component that provides the access to the selected ICC. * XPCOM component that provides the access to the selected ICC.
*/ */

View File

@ -21,6 +21,7 @@ EXPORTS.mozilla.dom.icc += [
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
'Assertions.cpp', 'Assertions.cpp',
'Icc.cpp', 'Icc.cpp',
'IccCallback.cpp',
'IccCardLockError.cpp', 'IccCardLockError.cpp',
"IccInfo.cpp", "IccInfo.cpp",
'IccListener.cpp', 'IccListener.cpp',

View File

@ -129,6 +129,16 @@ dictionary IccSetCardLockOptions
// Necessary for lock types: "pin", "fdn" // Necessary for lock types: "pin", "fdn"
}; };
dictionary IccCardLockStatus
{
boolean enabled; // True when CardLock is enabled.
};
dictionary IccCardLockRetryCount
{
long retryCount; // The number of remaining retries. -1 if unkown.
};
[Pref="dom.icc.enabled", [Pref="dom.icc.enabled",
CheckPermissions="mobileconnection", CheckPermissions="mobileconnection",
AvailableIn="CertifiedApps"] AvailableIn="CertifiedApps"]
@ -247,6 +257,7 @@ interface MozIcc : EventTarget
* The request's result will be an object containing * The request's result will be an object containing
* information about the specified lock's status. * information about the specified lock's status.
* e.g. {enabled: true}. * e.g. {enabled: true}.
* @see IccCardLockStatus.
*/ */
[Throws] [Throws]
DOMRequest getCardLock(IccLockType lockType); DOMRequest getCardLock(IccLockType lockType);
@ -289,8 +300,8 @@ interface MozIcc : EventTarget
* *
* @return a DOMRequest. * @return a DOMRequest.
* The request's result will be an object containing the number of * The request's result will be an object containing the number of
* remaining retries. * remaining retries. e.g. {retryCount: 3}.
* e.g. {retryCount: 3}. * @see IccCardLockRetryCount.
*/ */
[Throws] [Throws]
DOMRequest getCardLockRetryCount(IccLockType lockType); DOMRequest getCardLockRetryCount(IccLockType lockType);

View File

@ -213,6 +213,7 @@ static void Shutdown();
#include "mozilla/dom/nsCSPService.h" #include "mozilla/dom/nsCSPService.h"
#include "mozilla/dom/nsCSPContext.h" #include "mozilla/dom/nsCSPContext.h"
#include "nsICellBroadcastService.h" #include "nsICellBroadcastService.h"
#include "nsIIccService.h"
#include "nsISmsService.h" #include "nsISmsService.h"
#include "nsIMmsService.h" #include "nsIMmsService.h"
#include "nsIMobileConnectionService.h" #include "nsIMobileConnectionService.h"
@ -338,6 +339,7 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsICellBroadcastService,
NS_CreateCellBroadcastService) NS_CreateCellBroadcastService)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsISmsService, NS_CreateSmsService) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsISmsService, NS_CreateSmsService)
#endif #endif
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIIccService, NS_CreateIccService)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMmsService, NS_CreateMmsService) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMmsService, NS_CreateMmsService)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMobileMessageService, NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMobileMessageService,
NS_CreateMobileMessageService) NS_CreateMobileMessageService)
@ -798,6 +800,7 @@ NS_DEFINE_NAMED_CID(NS_VOICEMAIL_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_MOBILE_CONNECTION_SERVICE_CID); NS_DEFINE_NAMED_CID(NS_MOBILE_CONNECTION_SERVICE_CID);
NS_DEFINE_NAMED_CID(SMS_SERVICE_CID); NS_DEFINE_NAMED_CID(SMS_SERVICE_CID);
#endif #endif
NS_DEFINE_NAMED_CID(ICC_SERVICE_CID);
NS_DEFINE_NAMED_CID(MMS_SERVICE_CID); NS_DEFINE_NAMED_CID(MMS_SERVICE_CID);
NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_SERVICE_CID); NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_SERVICE_CID);
NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_DATABASE_SERVICE_CID); NS_DEFINE_NAMED_CID(MOBILE_MESSAGE_DATABASE_SERVICE_CID);
@ -1092,6 +1095,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &kCELLBROADCAST_SERVICE_CID, false, nullptr, nsICellBroadcastServiceConstructor }, { &kCELLBROADCAST_SERVICE_CID, false, nullptr, nsICellBroadcastServiceConstructor },
{ &kSMS_SERVICE_CID, false, nullptr, nsISmsServiceConstructor }, { &kSMS_SERVICE_CID, false, nullptr, nsISmsServiceConstructor },
#endif #endif
{ &kICC_SERVICE_CID, false, nullptr, nsIIccServiceConstructor },
{ &kMMS_SERVICE_CID, false, nullptr, nsIMmsServiceConstructor }, { &kMMS_SERVICE_CID, false, nullptr, nsIMmsServiceConstructor },
{ &kMOBILE_MESSAGE_SERVICE_CID, false, nullptr, nsIMobileMessageServiceConstructor }, { &kMOBILE_MESSAGE_SERVICE_CID, false, nullptr, nsIMobileMessageServiceConstructor },
{ &kMOBILE_MESSAGE_DATABASE_SERVICE_CID, false, nullptr, nsIMobileMessageDatabaseServiceConstructor }, { &kMOBILE_MESSAGE_DATABASE_SERVICE_CID, false, nullptr, nsIMobileMessageDatabaseServiceConstructor },
@ -1255,6 +1259,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
{ CELLBROADCAST_SERVICE_CONTRACTID, &kCELLBROADCAST_SERVICE_CID }, { CELLBROADCAST_SERVICE_CONTRACTID, &kCELLBROADCAST_SERVICE_CID },
{ SMS_SERVICE_CONTRACTID, &kSMS_SERVICE_CID }, { SMS_SERVICE_CONTRACTID, &kSMS_SERVICE_CID },
#endif #endif
{ ICC_SERVICE_CONTRACTID, &kICC_SERVICE_CID },
{ MMS_SERVICE_CONTRACTID, &kMMS_SERVICE_CID }, { MMS_SERVICE_CONTRACTID, &kMMS_SERVICE_CID },
{ MOBILE_MESSAGE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_SERVICE_CID }, { MOBILE_MESSAGE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_SERVICE_CID },
{ MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_DATABASE_SERVICE_CID }, { MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID, &kMOBILE_MESSAGE_DATABASE_SERVICE_CID },