Bug 1081810 - Part 1: Implement IccCardLockError in C++. r=smaug
authorEdgar Chen <echen@mozilla.com>
Mon, 13 Oct 2014 12:35:53 +0800
changeset 210394 547119c5331081590958889b49c666bcccf466be
parent 210393 eb76ff14dd6169977e22ee8a5e3011fce8c23128
child 210395 511be093541f41786062b10a884f65729b35a4c6
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug
bugs1081810
milestone36.0a1
Bug 1081810 - Part 1: Implement IccCardLockError in C++. r=smaug
dom/icc/IccCardLockError.cpp
dom/icc/IccCardLockError.h
dom/icc/moz.build
dom/system/gonk/RILContentHelper.js
dom/system/gonk/RadioInterfaceLayer.manifest
dom/webidl/IccCardLockError.webidl
new file mode 100644
--- /dev/null
+++ b/dom/icc/IccCardLockError.cpp
@@ -0,0 +1,48 @@
+/* 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 "mozilla/dom/IccCardLockError.h"
+#include "mozilla/dom/IccCardLockErrorBinding.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_IMPL_ISUPPORTS_INHERITED0(IccCardLockError, DOMError)
+
+/* static */ already_AddRefed<IccCardLockError>
+IccCardLockError::Constructor(const GlobalObject& aGlobal,
+                              const nsAString& aLockType,
+                              const nsAString& aName,
+                              int16_t aRetryCount,
+                              ErrorResult& aRv)
+{
+  nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
+  if (!window) {
+    aRv.Throw(NS_ERROR_FAILURE);
+    return nullptr;
+  }
+
+  nsRefPtr<IccCardLockError> result =
+    new IccCardLockError(window, aName, aLockType, aRetryCount);
+  return result.forget();
+}
+
+IccCardLockError::IccCardLockError(nsPIDOMWindow* aWindow,
+                                   const nsAString& aName,
+                                   const nsAString& aLockType,
+                                   int16_t aRetryCount)
+  : DOMError(aWindow, aName)
+  , mLockType(aLockType)
+  , mRetryCount(aRetryCount)
+{
+}
+
+JSObject*
+IccCardLockError::WrapObject(JSContext* aCx)
+{
+  return IccCardLockErrorBinding::Wrap(aCx, this);
+}
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/icc/IccCardLockError.h
@@ -0,0 +1,54 @@
+/* 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_IccCardLockError_h
+#define mozilla_dom_IccCardLockError_h
+
+#include "mozilla/dom/DOMError.h"
+
+namespace mozilla {
+namespace dom {
+
+class IccCardLockError MOZ_FINAL : public DOMError
+{
+public:
+  NS_DECL_ISUPPORTS_INHERITED
+
+  IccCardLockError(nsPIDOMWindow* aWindow, const nsAString& aName,
+                   const nsAString& aLockType, int16_t aRetryCount);
+
+  static already_AddRefed<IccCardLockError>
+  Constructor(const GlobalObject& aGlobal, const nsAString& aLockType,
+              const nsAString& aName, int16_t aRetryCount,
+              ErrorResult& aRv);
+
+  virtual JSObject*
+  WrapObject(JSContext* aCx) MOZ_OVERRIDE;
+
+  // WebIDL interface
+
+  void
+  GetLockType(nsString& aLockType) const
+  {
+    aLockType = mLockType;
+  }
+
+  int16_t
+  RetryCount() const
+  {
+    return mRetryCount;
+  }
+
+private:
+  ~IccCardLockError() {}
+
+private:
+  nsString mLockType;
+  int16_t mRetryCount;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_IccCardLockError_h
--- a/dom/icc/moz.build
+++ b/dom/icc/moz.build
@@ -3,23 +3,25 @@
 # 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/.
 
 DIRS += ['interfaces']
 
 EXPORTS.mozilla.dom += [
     'Icc.h',
+    'IccCardLockError.h',
     'IccInfo.h',
     'IccManager.h',
 ]
 
 UNIFIED_SOURCES += [
     'Assertions.cpp',
     'Icc.cpp',
+    'IccCardLockError.cpp',
     "IccInfo.cpp",
     'IccListener.cpp',
     'IccManager.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
--- a/dom/system/gonk/RILContentHelper.js
+++ b/dom/system/gonk/RILContentHelper.js
@@ -36,18 +36,16 @@ const kPrefRilDebuggingEnabled = "ril.de
 
 let DEBUG;
 function debug(s) {
   dump("-*- RILContentHelper: " + s + "\n");
 }
 
 const RILCONTENTHELPER_CID =
   Components.ID("{472816e1-1fd6-4405-996c-806f9ea68174}");
-const ICCCARDLOCKERROR_CID =
-  Components.ID("{08a71987-408c-44ff-93fd-177c0a85c3dd}");
 
 const RIL_IPC_MSG_NAMES = [
   "RIL:CardStateChanged",
   "RIL:IccInfoChanged",
   "RIL:CardLockResult",
   "RIL:CardLockRetryCount",
   "RIL:StkCommand",
   "RIL:StkSessionEnd",
@@ -131,30 +129,16 @@ CdmaIccInfo.prototype = {
                                          Ci.nsIIccInfo]),
 
   // nsICdmaIccInfo
 
   mdn: null,
   prlVersion: 0
 };
 
-function IccCardLockError() {
-}
-IccCardLockError.prototype = {
-  classDescription: "IccCardLockError",
-  classID:          ICCCARDLOCKERROR_CID,
-  contractID:       "@mozilla.org/dom/icccardlock-error;1",
-  QueryInterface:   XPCOMUtils.generateQI([Ci.nsISupports]),
-  __init: function(lockType, errorMsg, retryCount) {
-    this.__DOM_IMPL__.init(errorMsg);
-    this.lockType = lockType;
-    this.retryCount = retryCount;
-  },
-};
-
 function RILContentHelper() {
   this.updateDebugFlag();
 
   this.numClients = gNumRadioInterfaces;
   if (DEBUG) debug("Number of clients: " + this.numClients);
 
   this.rilContexts = [];
   for (let clientId = 0; clientId < this.numClients; clientId++) {
@@ -842,10 +826,9 @@ RILContentHelper.prototype = {
         handler.apply(listener, args);
       } catch (e) {
         if (DEBUG) debug("listener for " + name + " threw an exception: " + e);
       }
     }
   }
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RILContentHelper,
-                                                     IccCardLockError]);
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RILContentHelper]);
--- a/dom/system/gonk/RadioInterfaceLayer.manifest
+++ b/dom/system/gonk/RadioInterfaceLayer.manifest
@@ -14,12 +14,10 @@
 
 # RadioInterfaceLayer.js
 component {2d831c8d-6017-435b-a80c-e5d422810cea} RadioInterfaceLayer.js
 contract @mozilla.org/ril;1 {2d831c8d-6017-435b-a80c-e5d422810cea}
 category profile-after-change RadioInterfaceLayer @mozilla.org/ril;1
 
 # RILContentHelper.js
 component {472816e1-1fd6-4405-996c-806f9ea68174} RILContentHelper.js
-component {08a71987-408c-44ff-93fd-177c0a85c3dd} RILContentHelper.js
 contract @mozilla.org/ril/content-helper;1 {472816e1-1fd6-4405-996c-806f9ea68174}
-contract @mozilla.org/dom/icccardlock-error;1 {08a71987-408c-44ff-93fd-177c0a85c3dd}
 category profile-after-change RILContentHelper @mozilla.org/ril/content-helper;1
--- a/dom/webidl/IccCardLockError.webidl
+++ b/dom/webidl/IccCardLockError.webidl
@@ -1,12 +1,11 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/.
-*/
+ * 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/.
+ */
 
-[JSImplementation="@mozilla.org/dom/icccardlock-error;1",
- Constructor(DOMString lockType, DOMString errorName, short retryCount)]
+[Constructor(DOMString lockType, DOMString errorName, short retryCount),
+ Pref="dom.icc.enabled"]
 interface IccCardLockError : DOMError {
   readonly attribute DOMString lockType;
   readonly attribute short retryCount;
 };