2012-06-28 07:21:48 -07: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/. */
|
|
|
|
|
2012-06-11 04:28:16 -07:00
|
|
|
#include "mozilla/Services.h"
|
2012-06-28 07:21:48 -07:00
|
|
|
#include "nsIDOMClassInfo.h"
|
|
|
|
#include "IccManager.h"
|
|
|
|
#include "SimToolKit.h"
|
2012-06-11 04:28:16 -07:00
|
|
|
#include "StkCommandEvent.h"
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2012-04-10 05:04:27 -07:00
|
|
|
#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
|
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
using namespace mozilla::dom::icc;
|
2012-06-11 04:28:16 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
class IccManager::Listener : public nsIIccListener
|
|
|
|
{
|
|
|
|
IccManager* mIccManager;
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSIICCLISTENER(mIccManager)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
Listener(IccManager* aIccManager)
|
|
|
|
: mIccManager(aIccManager)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIccManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Disconnect()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIccManager);
|
|
|
|
mIccManager = nullptr;
|
|
|
|
}
|
|
|
|
};
|
2012-06-11 04:28:16 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_IMPL_ISUPPORTS1(IccManager::Listener, nsIIccListener)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
DOMCI_DATA(MozIccManager, mozilla::dom::icc::IccManager)
|
2012-06-28 07:21:48 -07:00
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN(IccManager)
|
2012-06-28 07:21:48 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozIccManager)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozIccManager)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(IccManager, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IccManager, nsDOMEventTargetHelper)
|
|
|
|
|
|
|
|
IccManager::IccManager()
|
|
|
|
{
|
2012-04-10 05:04:27 -07:00
|
|
|
mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
|
|
|
|
|
|
|
|
// Not being able to acquire the provider isn't fatal since we check
|
|
|
|
// for it explicitly below.
|
|
|
|
if (!mProvider) {
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_WARNING("Could not acquire nsIIccProvider!");
|
|
|
|
return;
|
2012-04-10 05:04:27 -07:00
|
|
|
}
|
2013-03-06 01:53:27 -08:00
|
|
|
|
|
|
|
mListener = new Listener(this);
|
|
|
|
DebugOnly<nsresult> rv = mProvider->RegisterIccMsg(mListener);
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"Failed registering icc messages with provider");
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IccManager::Init(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IccManager::Shutdown()
|
|
|
|
{
|
2013-03-06 01:53:27 -08:00
|
|
|
if (mProvider && mListener) {
|
|
|
|
mListener->Disconnect();
|
|
|
|
mProvider->UnregisterIccMsg(mListener);
|
|
|
|
mProvider = nullptr;
|
|
|
|
mListener = nullptr;
|
2012-06-11 04:28:16 -07:00
|
|
|
}
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMMozIccManager
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-29 14:39:20 -07:00
|
|
|
IccManager::SendStkResponse(const JS::Value& aCommand,
|
|
|
|
const JS::Value& aResponse)
|
2012-06-28 07:21:48 -07:00
|
|
|
{
|
2012-04-10 05:04:27 -07:00
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-29 14:39:20 -07:00
|
|
|
mProvider->SendStkResponse(GetOwner(), aCommand, aResponse);
|
2012-04-10 05:04:27 -07:00
|
|
|
return NS_OK;
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-29 07:56:51 -07:00
|
|
|
IccManager::SendStkMenuSelection(uint16_t aItemIdentifier, bool aHelpRequested)
|
2012-06-28 07:21:48 -07:00
|
|
|
{
|
2012-04-10 05:04:27 -07:00
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider->SendStkMenuSelection(GetOwner(), aItemIdentifier, aHelpRequested);
|
|
|
|
return NS_OK;
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
2012-12-04 03:19:17 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::SendStkTimerExpiration(const JS::Value& aTimer)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider->SendStkTimerExpiration(GetOwner(), aTimer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-12 00:24:58 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::SendStkEventDownload(const JS::Value& aEvent)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProvider->SendStkEventDownload(GetOwner(), aEvent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:27:23 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::IccOpenChannel(const nsAString& aAid, nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:36:05 -08:00
|
|
|
return mProvider->IccOpenChannel(GetOwner(), aAid, aRequest);
|
2013-02-25 01:27:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-25 01:36:05 -08:00
|
|
|
IccManager::IccExchangeAPDU(int32_t aChannel, const jsval& aApdu, nsIDOMDOMRequest** aRequest)
|
2013-02-25 01:27:23 -08:00
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:36:05 -08:00
|
|
|
return mProvider->IccExchangeAPDU(GetOwner(), aChannel, aApdu, aRequest);
|
2013-02-25 01:27:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-25 01:36:05 -08:00
|
|
|
IccManager::IccCloseChannel(int32_t aChannel, nsIDOMDOMRequest** aRequest)
|
2013-02-25 01:27:23 -08:00
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2013-02-25 01:36:05 -08:00
|
|
|
return mProvider->IccCloseChannel(GetOwner(), aChannel, aRequest);
|
2013-02-25 01:27:23 -08:00
|
|
|
}
|
|
|
|
|
2013-03-05 22:09:50 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::ReadContacts(const nsAString& aContactType, nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->ReadContacts(GetOwner(), aContactType, aRequest);
|
|
|
|
}
|
|
|
|
|
2012-12-24 02:38:49 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::UpdateContact(const nsAString& aContactType,
|
|
|
|
nsIDOMContact* aContact,
|
|
|
|
const nsAString& aPin2,
|
|
|
|
nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mProvider->UpdateContact(GetOwner(), aContactType, aContact, aPin2, aRequest);
|
|
|
|
}
|
2013-02-25 01:27:23 -08:00
|
|
|
|
2012-06-28 07:21:48 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, stkcommand)
|
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, stksessionend)
|
|
|
|
|
2013-03-06 01:53:27 -08:00
|
|
|
// nsIIccListener
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::NotifyStkCommand(const nsAString& aMessage)
|
|
|
|
{
|
2013-03-09 03:34:29 -08:00
|
|
|
nsRefPtr<StkCommandEvent> event = StkCommandEvent::Create(this, aMessage);
|
2013-03-06 01:53:27 -08:00
|
|
|
NS_ASSERTION(event, "This should never fail!");
|
|
|
|
|
2013-04-19 15:18:33 -07:00
|
|
|
return event->Dispatch(this, NS_LITERAL_STRING("stkcommand"));
|
2013-03-06 01:53:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::NotifyStkSessionEnd()
|
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(NS_LITERAL_STRING("stksessionend"));
|
|
|
|
}
|