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"
|
2012-06-11 04:28:16 -07:00
|
|
|
#include "nsIObserverService.h"
|
2012-06-28 07:21:48 -07:00
|
|
|
#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"
|
|
|
|
|
2012-06-11 04:28:16 -07:00
|
|
|
#define STKCOMMAND_EVENTNAME NS_LITERAL_STRING("stkcommand")
|
|
|
|
#define STKSESSIONEND_EVENTNAME NS_LITERAL_STRING("stksessionend")
|
|
|
|
|
2012-06-28 07:21:48 -07:00
|
|
|
DOMCI_DATA(MozIccManager, mozilla::dom::icc::IccManager)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace icc {
|
|
|
|
|
2012-06-11 04:28:16 -07:00
|
|
|
const char* kStkCommandTopic = "icc-manager-stk-command";
|
|
|
|
const char* kStkSessionEndTopic = "icc-manager-stk-session-end";
|
|
|
|
|
2012-06-28 07:21:48 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IccManager,
|
|
|
|
nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IccManager,
|
|
|
|
nsDOMEventTargetHelper)
|
2012-04-10 05:04:27 -07:00
|
|
|
tmp->mProvider = nullptr;
|
2012-06-28 07:21:48 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IccManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozIccManager)
|
2012-10-25 11:16:05 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
2012-06-28 07:21:48 -07:00
|
|
|
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) {
|
|
|
|
NS_WARNING("Could not acquire nsIMobileConnectionProvider!");
|
|
|
|
}
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IccManager::Init(nsPIDOMWindow* aWindow)
|
|
|
|
{
|
|
|
|
BindToOwner(aWindow);
|
2012-06-11 04:28:16 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs) {
|
|
|
|
NS_WARNING("Could not acquire nsIObserverService!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs->AddObserver(this, kStkCommandTopic, false);
|
|
|
|
obs->AddObserver(this, kStkSessionEndTopic, false);
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IccManager::Shutdown()
|
|
|
|
{
|
2012-06-11 04:28:16 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs) {
|
|
|
|
NS_WARNING("Could not acquire nsIObserverService!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs->RemoveObserver(this, kStkCommandTopic);
|
|
|
|
obs->RemoveObserver(this, kStkSessionEndTopic);
|
2012-06-28 07:21:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
2012-06-11 04:28:16 -07:00
|
|
|
if (!strcmp(aTopic, kStkCommandTopic)) {
|
|
|
|
nsString stkMsg;
|
|
|
|
stkMsg.Assign(aData);
|
|
|
|
nsRefPtr<StkCommandEvent> event = StkCommandEvent::Create(stkMsg);
|
|
|
|
|
|
|
|
NS_ASSERTION(event, "This should never fail!");
|
|
|
|
|
|
|
|
nsresult rv = event->Dispatch(ToIDOMEventTarget(), STKCOMMAND_EVENTNAME);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kStkSessionEndTopic)) {
|
2012-09-27 13:11:31 -07:00
|
|
|
DispatchTrustedEvent(STKSESSIONEND_EVENTNAME);
|
2012-06-11 04:28:16 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_NOT_REACHED("Unknown observer topic!");
|
|
|
|
|
2012-06-28 07:21:48 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
*aRequest = nullptr;
|
|
|
|
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mProvider->IccOpenChannel(GetOwner(), aAid, aRequest);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::IccExchangeAPDU(PRInt32 aChannel, const jsval& aApdu, nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
*aRequest = nullptr;
|
|
|
|
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mProvider->IccExchangeAPDU(GetOwner(), aChannel, aApdu, aRequest);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IccManager::IccCloseChannel(PRInt32 aChannel, nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
|
|
|
*aRequest = nullptr;
|
|
|
|
|
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mProvider->IccCloseChannel(GetOwner(), aChannel, aRequest);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-28 07:21:48 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, stkcommand)
|
|
|
|
NS_IMPL_EVENT_HANDLER(IccManager, stksessionend)
|
|
|
|
|
|
|
|
} // namespace icc
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|