Bug 827280 - Part 3: MobileConnection. r=philikon a=tef+

This commit is contained in:
Jose Antonio Olivera Ortega 2013-01-25 19:45:19 +01:00
parent b821688dc3
commit 82a2e87de4

View File

@ -13,6 +13,7 @@
#include "IccManager.h"
#include "GeneratedEvents.h"
#include "nsIDOMICCCardLockErrorEvent.h"
#include "CFStateChangeEvent.h"
#include "nsContentUtils.h"
#include "nsJSUtils.h"
@ -20,6 +21,7 @@
#include "jsapi.h"
#include "mozilla/dom/USSDReceivedEventBinding.h"
#include "mozilla/dom/CFStateChangeEventBinding.h"
#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
@ -30,6 +32,7 @@
#define USSDRECEIVED_EVENTNAME NS_LITERAL_STRING("ussdreceived")
#define DATAERROR_EVENTNAME NS_LITERAL_STRING("dataerror")
#define ICCCARDLOCKERROR_EVENTNAME NS_LITERAL_STRING("icccardlockerror")
#define CFSTATECHANGE_EVENTNAME NS_LITERAL_STRING("cfstatechange")
DOMCI_DATA(MozMobileConnection, mozilla::dom::network::MobileConnection)
@ -44,6 +47,7 @@ const char* kIccInfoChangedTopic = "mobile-connection-iccinfo-changed";
const char* kUssdReceivedTopic = "mobile-connection-ussd-received";
const char* kDataErrorTopic = "mobile-connection-data-error";
const char* kIccCardLockErrorTopic = "mobile-connection-icccardlock-error";
const char* kCfStateChangedTopic = "mobile-connection-cfstate-change";
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MobileConnection,
nsDOMEventTargetHelper)
@ -71,6 +75,7 @@ NS_IMPL_EVENT_HANDLER(MobileConnection, datachange)
NS_IMPL_EVENT_HANDLER(MobileConnection, ussdreceived)
NS_IMPL_EVENT_HANDLER(MobileConnection, dataerror)
NS_IMPL_EVENT_HANDLER(MobileConnection, icccardlockerror)
NS_IMPL_EVENT_HANDLER(MobileConnection, cfstatechange)
MobileConnection::MobileConnection()
{
@ -103,6 +108,7 @@ MobileConnection::Init(nsPIDOMWindow* aWindow)
obs->AddObserver(this, kUssdReceivedTopic, false);
obs->AddObserver(this, kDataErrorTopic, false);
obs->AddObserver(this, kIccCardLockErrorTopic, false);
obs->AddObserver(this, kCfStateChangedTopic, false);
mIccManager = new icc::IccManager();
mIccManager->Init(aWindow);
@ -124,6 +130,7 @@ MobileConnection::Shutdown()
obs->RemoveObserver(this, kUssdReceivedTopic);
obs->RemoveObserver(this, kDataErrorTopic);
obs->RemoveObserver(this, kIccCardLockErrorTopic);
obs->RemoveObserver(this, kCfStateChangedTopic);
if (mIccManager) {
mIccManager->Shutdown();
@ -238,6 +245,25 @@ MobileConnection::Observe(nsISupports* aSubject,
return NS_OK;
}
if (!strcmp(aTopic, kCfStateChangedTopic)) {
mozilla::dom::CFStateChangeEventDict dict;
bool ok = dict.Init(nsDependentString(aData));
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
nsRefPtr<CFStateChangeEvent> event =
CFStateChangeEvent::Create(dict.mSuccess,
dict.mAction,
dict.mReason,
dict.mNumber,
dict.mTimeSeconds,
dict.mServiceClass);
NS_ASSERTION(event, "This should never fail!");
nsresult rv = event->Dispatch(ToIDOMEventTarget(), CFSTATECHANGE_EVENTNAME);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
MOZ_NOT_REACHED("Unknown observer topic!");
return NS_OK;
}