Bug 783525 - part 1 - idl and DOM impl for ICCCardLockErrorEvent. r=smaug, sr=sicking
authorHsin-Yi Tsai <htsai@mozilla.com>
Wed, 03 Oct 2012 14:29:07 +0800
changeset 109633 7eee61226313d6ad1c8aae11653c126307c9ec32
parent 109632 b8b44407bfe65c38f5eca80a4c3780bbd3337505
child 109634 5072dbac12384ca619d7284112271a02b013a939
push id16112
push userhtsai@mozilla.com
push dateMon, 08 Oct 2012 07:57:12 +0000
treeherdermozilla-inbound@5072dbac1238 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, sicking
bugs783525
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 783525 - part 1 - idl and DOM impl for ICCCardLockErrorEvent. r=smaug, sr=sicking
content/base/src/nsGkAtomList.h
dom/icc/interfaces/Makefile.in
dom/icc/interfaces/nsIDOMICCCardLockErrorEvent.idl
dom/network/interfaces/nsIDOMMobileConnection.idl
dom/network/src/MobileConnection.cpp
js/xpconnect/src/event_impl_gen.conf.in
--- a/content/base/src/nsGkAtomList.h
+++ b/content/base/src/nsGkAtomList.h
@@ -694,16 +694,17 @@ GK_ATOM(ondrop, "ondrop")
 GK_ATOM(onenabled, "onenabled")
 GK_ATOM(onerror, "onerror")
 GK_ATOM(onfocus, "onfocus")
 GK_ATOM(onget, "onget")
 GK_ATOM(onhashchange, "onhashchange")
 GK_ATOM(onheld, "onheld")
 GK_ATOM(onholding, "onholding")
 GK_ATOM(oniccinfochange, "oniccinfochange")
+GK_ATOM(onicccardlockerror, "onicccardlockerror")
 GK_ATOM(onincoming, "onincoming")
 GK_ATOM(oninput, "oninput")
 GK_ATOM(oninvalid, "oninvalid")
 GK_ATOM(onkeydown, "onkeydown")
 GK_ATOM(onkeypress, "onkeypress")
 GK_ATOM(onkeyup, "onkeyup")
 GK_ATOM(onlevelchange, "onlevelchange")
 GK_ATOM(onLoad, "onLoad")
--- a/dom/icc/interfaces/Makefile.in
+++ b/dom/icc/interfaces/Makefile.in
@@ -11,15 +11,16 @@ include $(DEPTH)/config/autoconf.mk
 
 XPIDL_MODULE = dom_icc
 
 include $(topsrcdir)/dom/dom-config.mk
 
 XPIDLSRCS = \
   nsIDOMIccManager.idl \
   SimToolKit.idl \
+  nsIDOMICCCardLockErrorEvent.idl \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 XPIDL_FLAGS += \
   -I$(topsrcdir)/dom/interfaces/base \
   -I$(topsrcdir)/dom/interfaces/events \
   $(NULL)
new file mode 100644
--- /dev/null
+++ b/dom/icc/interfaces/nsIDOMICCCardLockErrorEvent.idl
@@ -0,0 +1,24 @@
+/* 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 "nsIDOMEvent.idl"
+
+[scriptable, builtinclass, uuid(109c1117-1199-47aa-aad2-ea9f456220fa)]
+interface nsIDOMICCCardLockErrorEvent : nsIDOMEvent
+{
+  readonly attribute DOMString lockType;
+  readonly attribute long retryCount;
+
+  [noscript] void initICCCardLockErrorEvent(in DOMString aType,
+                                            in boolean aCanBubble,
+                                            in boolean aCancelable,
+                                            in DOMString aLockType,
+                                            in int32_t aRetryCount);
+};
+
+dictionary ICCCardLockErrorEventInit : EventInit
+{
+  DOMString  lockType;
+  long       retryCount;
+};
--- a/dom/network/interfaces/nsIDOMMobileConnection.idl
+++ b/dom/network/interfaces/nsIDOMMobileConnection.idl
@@ -7,17 +7,17 @@
 interface nsIDOMEventListener;
 interface nsIDOMDOMRequest;
 interface nsIDOMMozMobileICCInfo;
 interface nsIDOMMozMobileConnectionInfo;
 interface nsIDOMMozMobileNetworkInfo;
 interface nsIDOMMozMobileCellInfo;
 interface nsIDOMMozIccManager;
 
-[scriptable, builtinclass, uuid(f7bddd87-e967-4f97-9481-2042beb86a92)]
+[scriptable, builtinclass, uuid(5362762c-7091-4da9-aecd-ba878bc51b3d)]
 interface nsIDOMMozMobileConnection : nsIDOMEventTarget
 {
   /**
    * Indicates the state of the device's ICC card.
    *
    * Possible values: null, 'absent', 'pinRequired', 'pukRequired',
    * 'networkLocked', 'ready'.
    */
@@ -255,16 +255,22 @@ interface nsIDOMMozMobileConnection : ns
    */
   [implicit_jscontext] attribute jsval onussdreceived;
 
   /**
    * The 'dataerror' event is notified whenever the data connection object
    * receives an error from the RIL
    */
   [implicit_jscontext] attribute jsval ondataerror;
+
+  /**
+   * The 'icccardlockerror' event is notified whenever 'unlockCardLock' or
+   * 'setCardLock' fails.
+   */
+  [implicit_jscontext] attribute jsval onicccardlockerror;
 };
 
 [scriptable, uuid(5ea0e4a9-4684-40da-9930-8ebb61d187f3)]
 interface nsIDOMMozMobileConnectionInfo : nsISupports
 {
   /**
    * State of the connection.
    *
--- a/dom/network/src/MobileConnection.cpp
+++ b/dom/network/src/MobileConnection.cpp
@@ -6,38 +6,47 @@
 #include "nsIDOMDOMRequest.h"
 #include "nsIDOMClassInfo.h"
 #include "nsDOMEvent.h"
 #include "nsIObserverService.h"
 #include "USSDReceivedEvent.h"
 #include "DataErrorEvent.h"
 #include "mozilla/Services.h"
 #include "IccManager.h"
+#include "GeneratedEvents.h"
+#include "nsIDOMICCCardLockErrorEvent.h"
+
+#include "nsContentUtils.h"
+#include "nsJSUtils.h"
+#include "nsJSON.h"
+#include "jsapi.h"
 
 #define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
 
 #define VOICECHANGE_EVENTNAME      NS_LITERAL_STRING("voicechange")
 #define DATACHANGE_EVENTNAME       NS_LITERAL_STRING("datachange")
 #define CARDSTATECHANGE_EVENTNAME  NS_LITERAL_STRING("cardstatechange")
 #define ICCINFOCHANGE_EVENTNAME    NS_LITERAL_STRING("iccinfochange")
 #define USSDRECEIVED_EVENTNAME     NS_LITERAL_STRING("ussdreceived")
 #define DATAERROR_EVENTNAME        NS_LITERAL_STRING("dataerror")
+#define ICCCARDLOCKERROR_EVENTNAME NS_LITERAL_STRING("icccardlockerror")
 
 DOMCI_DATA(MozMobileConnection, mozilla::dom::network::MobileConnection)
 
 namespace mozilla {
 namespace dom {
 namespace network {
 
 const char* kVoiceChangedTopic     = "mobile-connection-voice-changed";
 const char* kDataChangedTopic      = "mobile-connection-data-changed";
 const char* kCardStateChangedTopic = "mobile-connection-cardstate-changed";
 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";
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(MobileConnection)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MobileConnection,
                                                   nsDOMEventTargetHelper)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MobileConnection,
@@ -56,16 +65,17 @@ NS_IMPL_ADDREF_INHERITED(MobileConnectio
 NS_IMPL_RELEASE_INHERITED(MobileConnection, nsDOMEventTargetHelper)
 
 NS_IMPL_EVENT_HANDLER(MobileConnection, cardstatechange)
 NS_IMPL_EVENT_HANDLER(MobileConnection, iccinfochange)
 NS_IMPL_EVENT_HANDLER(MobileConnection, voicechange)
 NS_IMPL_EVENT_HANDLER(MobileConnection, datachange)
 NS_IMPL_EVENT_HANDLER(MobileConnection, ussdreceived)
 NS_IMPL_EVENT_HANDLER(MobileConnection, dataerror)
+NS_IMPL_EVENT_HANDLER(MobileConnection, icccardlockerror)
 
 MobileConnection::MobileConnection()
 {
   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) {
@@ -85,16 +95,17 @@ MobileConnection::Init(nsPIDOMWindow* aW
   }
 
   obs->AddObserver(this, kVoiceChangedTopic, false);
   obs->AddObserver(this, kDataChangedTopic, false);
   obs->AddObserver(this, kCardStateChangedTopic, false);
   obs->AddObserver(this, kIccInfoChangedTopic, false);
   obs->AddObserver(this, kUssdReceivedTopic, false);
   obs->AddObserver(this, kDataErrorTopic, false);
+  obs->AddObserver(this, kIccCardLockErrorTopic, false);
 
   mIccManager = new icc::IccManager();
   mIccManager->Init(aWindow);
 }
 
 void
 MobileConnection::Shutdown()
 {
@@ -105,16 +116,17 @@ MobileConnection::Shutdown()
   }
 
   obs->RemoveObserver(this, kVoiceChangedTopic);
   obs->RemoveObserver(this, kDataChangedTopic);
   obs->RemoveObserver(this, kCardStateChangedTopic);
   obs->RemoveObserver(this, kIccInfoChangedTopic);
   obs->RemoveObserver(this, kUssdReceivedTopic);
   obs->RemoveObserver(this, kDataErrorTopic);
+  obs->RemoveObserver(this, kIccCardLockErrorTopic);
 
   if (mIccManager) {
     mIccManager->Shutdown();
     mIccManager = nullptr;
   }
 }
 
 // nsIObserver
@@ -163,16 +175,70 @@ MobileConnection::Observe(nsISupports* a
     NS_ASSERTION(event, "This should never fail!");
 
     nsresult rv =
       event->Dispatch(ToIDOMEventTarget(), DATAERROR_EVENTNAME);
     NS_ENSURE_SUCCESS(rv, rv);
     return NS_OK;
   }
 
+  if (!strcmp(aTopic, kIccCardLockErrorTopic)) {
+    nsString errorMsg;
+    errorMsg.Assign(aData);
+
+    if (errorMsg.IsEmpty()) {
+      NS_ERROR("Got a 'icc-cardlock-error' topic without a valid message!");
+      return NS_OK;
+    }
+
+    nsString lockType;
+    int32_t retryCount = -1;
+
+    // Decode the json string "errorMsg" and retrieve its properties:
+    // "lockType" and "retryCount".
+    nsresult rv;
+    nsIScriptContext* sc = GetContextForEventHandlers(&rv);
+    NS_ENSURE_STATE(sc);
+    JSContext* cx = sc->GetNativeContext();
+    NS_ASSERTION(cx, "Failed to get a context!");
+
+    nsCOMPtr<nsIJSON> json(new nsJSON());
+    jsval error;
+    rv = json->DecodeToJSVal(errorMsg, cx, &error);
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    jsval type;
+    if (JS_GetProperty(cx, JSVAL_TO_OBJECT(error), "lockType", &type)) {
+      if (JSVAL_IS_STRING(type)) {
+        nsDependentJSString str;
+        str.init(cx, type.toString());
+        lockType.Assign(str);
+      }
+    }
+
+    jsval count;
+    if (JS_GetProperty(cx, JSVAL_TO_OBJECT(error), "retryCount", &count)) {
+      if (JSVAL_IS_NUMBER(count)) {
+        retryCount = count.toNumber();
+      }
+    }
+
+    nsCOMPtr<nsIDOMEvent> event;
+    NS_NewDOMICCCardLockErrorEvent(getter_AddRefs(event), nullptr, nullptr);
+
+    nsCOMPtr<nsIDOMICCCardLockErrorEvent> e = do_QueryInterface(event);
+    e->InitICCCardLockErrorEvent(NS_LITERAL_STRING("icccardlockerror"),
+                                 false, false, lockType, retryCount);
+    e->SetTrusted(true);
+    bool dummy;
+    DispatchEvent(event, &dummy);
+
+    return NS_OK;
+  }
+
   MOZ_NOT_REACHED("Unknown observer topic!");
   return NS_OK;
 }
 
 // nsIDOMMozMobileConnection
 
 NS_IMETHODIMP
 MobileConnection::GetCardState(nsAString& cardState)
--- a/js/xpconnect/src/event_impl_gen.conf.in
+++ b/js/xpconnect/src/event_impl_gen.conf.in
@@ -21,16 +21,19 @@ simple_events = [
     'MozContactChangeEvent',
     'DeviceOrientationEvent',
     'DeviceLightEvent',
     'MozApplicationEvent',
 #ifdef MOZ_B2G_BT
     'BluetoothDeviceEvent',
     'BluetoothDeviceAddressEvent',
 #endif
+#ifdef MOZ_B2G_RIL
+    'ICCCardLockErrorEvent',
+#endif
     'DeviceStorageChangeEvent',
     'PopupBlockedEvent'
   ]
 
 """ include file names """
 special_includes = [
     'DictionaryHelpers.h',
     'nsContentUtils.h',