Bug 1114937 - Part 3: Web API change to adopt IccService for IccContacts. r=echen, r=hsinyi
authorBevis Tseng <btseng@mozilla.com>
Tue, 16 Jun 2015 17:38:27 +0800
changeset 254753 244594f4817cb29cccc971b85f6d4a8701755fdb
parent 254752 0c3aa04443397e9baa8e30128aa302051f100fbd
child 254754 95df4f99f500f1cfab2b5e4eca7dee559871987d
push id14250
push userryanvm@gmail.com
push dateMon, 27 Jul 2015 19:44:33 +0000
treeherderfx-team@7d5d2d96f19b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersechen, hsinyi
bugs1114937
milestone42.0a1
Bug 1114937 - Part 3: Web API change to adopt IccService for IccContacts. r=echen, r=hsinyi
dom/icc/Icc.cpp
dom/icc/Icc.h
dom/icc/IccListener.cpp
dom/webidl/MozIcc.webidl
--- a/dom/icc/Icc.cpp
+++ b/dom/icc/Icc.cpp
@@ -2,30 +2,33 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/Icc.h"
 
 #include "IccCallback.h"
+#include "IccContact.h"
+#include "mozilla/dom/ContactsBinding.h"
 #include "mozilla/dom/DOMRequest.h"
 #include "mozilla/dom/IccInfo.h"
 #include "mozilla/dom/MozStkCommandEvent.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ScriptSettings.h"
 #include "nsIIccInfo.h"
 #include "nsIIccProvider.h"
 #include "nsIIccService.h"
 #include "nsIStkCmdFactory.h"
 #include "nsIStkProactiveCmd.h"
 #include "nsRadioInterfaceLayer.h"
 #include "nsServiceManagerUtils.h"
 
 using mozilla::dom::icc::IccCallback;
+using mozilla::dom::icc::IccContact;
 
 namespace mozilla {
 namespace dom {
 
 namespace {
 
 bool
 IsPukCardLockType(IccLockType aLockType)
@@ -54,46 +57,36 @@ IsPukCardLockType(IccLockType aLockType)
 NS_IMPL_CYCLE_COLLECTION_INHERITED(Icc, DOMEventTargetHelper, mIccInfo)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(Icc)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 NS_IMPL_ADDREF_INHERITED(Icc, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(Icc, DOMEventTargetHelper)
 
-Icc::Icc(nsPIDOMWindow* aWindow, long aClientId, nsIIcc* aHandler, nsIIccInfo* aIccInfo)
+Icc::Icc(nsPIDOMWindow* aWindow, nsIIcc* aHandler, nsIIccInfo* aIccInfo)
   : mLive(true)
-  , mClientId(aClientId)
   , mHandler(aHandler)
 {
   BindToOwner(aWindow);
 
-  mProvider = do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
-
   if (aIccInfo) {
     aIccInfo->GetIccid(mIccId);
     UpdateIccInfo(aIccInfo);
   }
-
-  // Not being able to acquire the provider isn't fatal since we check
-  // for it explicitly below.
-  if (!mProvider) {
-    NS_WARNING("Could not acquire nsIIccProvider!");
-  }
 }
 
 Icc::~Icc()
 {
 }
 
 void
 Icc::Shutdown()
 {
   mIccInfo.SetNull();
-  mProvider = nullptr;
   mHandler = nullptr;
   mLive = false;
 }
 
 nsresult
 Icc::NotifyEvent(const nsAString& aName)
 {
   return DispatchTrustedEvent(aName);
@@ -416,54 +409,65 @@ Icc::GetCardLockRetryCount(IccLockType a
   }
 
   return request.forget();
 }
 
 already_AddRefed<DOMRequest>
 Icc::ReadContacts(IccContactType aContactType, ErrorResult& aRv)
 {
-  if (!mProvider) {
+  if (!mHandler) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsRefPtr<nsIDOMDOMRequest> request;
-  nsresult rv = mProvider->ReadContacts(mClientId, GetOwner(),
-                                        static_cast<uint32_t>(aContactType),
-                                        getter_AddRefs(request));
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsRefPtr<IccCallback> requestCallback =
+    new IccCallback(GetOwner(), request);
+
+  nsresult rv = mHandler->ReadContacts(static_cast<uint32_t>(aContactType),
+                                       requestCallback);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
-  return request.forget().downcast<DOMRequest>();
+  return request.forget();
 }
 
 already_AddRefed<DOMRequest>
-Icc::UpdateContact(const JSContext* aCx, IccContactType aContactType,
-                   JS::Handle<JS::Value> aContact, const nsAString& aPin2,
-                   ErrorResult& aRv)
+Icc::UpdateContact(IccContactType aContactType, mozContact& aContact,
+                   const nsAString& aPin2, ErrorResult& aRv)
 {
-  if (!mProvider) {
+  if (!mHandler) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsRefPtr<nsIDOMDOMRequest> request;
-  nsresult rv = mProvider->UpdateContact(mClientId, GetOwner(),
-                                         static_cast<uint32_t>(aContactType),
-                                         aContact, aPin2,
-                                         getter_AddRefs(request));
+  nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
+  nsRefPtr<IccCallback> requestCallback =
+    new IccCallback(GetOwner(), request);
+
+  nsCOMPtr<nsIIccContact> iccContact;
+  nsresult rv = IccContact::Create(aContact, getter_AddRefs(iccContact));
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
 
-  return request.forget().downcast<DOMRequest>();
+  rv = mHandler->UpdateContact(static_cast<uint32_t>(aContactType),
+                               iccContact,
+                               aPin2,
+                               requestCallback);
+  if (NS_FAILED(rv)) {
+    aRv.Throw(rv);
+    return nullptr;
+  }
+
+  return request.forget();
 }
 
 already_AddRefed<DOMRequest>
 Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData,
                ErrorResult& aRv)
 {
   if (!mHandler) {
     aRv.Throw(NS_ERROR_FAILURE);
--- a/dom/icc/Icc.h
+++ b/dom/icc/Icc.h
@@ -15,27 +15,27 @@ class nsIIccInfo;
 class nsIIccProvider;
 class nsIStkProactiveCmd;
 
 namespace mozilla {
 namespace dom {
 
 class DOMRequest;
 class OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo;
+class mozContact;
 class Promise;
 
 class Icc final : public DOMEventTargetHelper
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Icc, DOMEventTargetHelper)
   NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
 
-  Icc(nsPIDOMWindow* aWindow, long aClientId,
-      nsIIcc* aHandler, nsIIccInfo* aIccInfo);
+  Icc(nsPIDOMWindow* aWindow, nsIIcc* aHandler, nsIIccInfo* aIccInfo);
 
   void
   Shutdown();
 
   nsresult
   NotifyEvent(const nsAString& aName);
 
   nsresult
@@ -94,19 +94,18 @@ public:
 
   already_AddRefed<DOMRequest>
   GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv);
 
   already_AddRefed<DOMRequest>
   ReadContacts(IccContactType aContactType, ErrorResult& aRv);
 
   already_AddRefed<DOMRequest>
-  UpdateContact(const JSContext* aCx, IccContactType aContactType,
-                JS::Handle<JS::Value> aContact, const nsAString& aPin2,
-                ErrorResult& aRv);
+  UpdateContact(IccContactType aContactType, mozContact& aContact,
+                const nsAString& aPin2, ErrorResult& aRv);
 
   already_AddRefed<DOMRequest>
   MatchMvno(IccMvnoType aMvnoType, const nsAString& aMatchData,
             ErrorResult& aRv);
 
   already_AddRefed<Promise>
   GetServiceState(IccService aService, ErrorResult& aRv);
 
@@ -117,21 +116,17 @@ public:
 
 private:
   // Put definition of the destructor in Icc.cpp to ensure forward declaration
   // of nsIIccProvider, nsIIcc for the auto-generated .cpp file (i.e.,
   // MozIccManagerBinding.cpp) that includes this header.
   ~Icc();
 
   bool mLive;
-  uint32_t mClientId;
   nsString mIccId;
-  // mProvider is a xpcom service and will be released at Shutdown(), so it
-  // doesn't need to be cycle collected.
-  nsCOMPtr<nsIIccProvider> mProvider;
   // mHandler will be released at Shutdown(), so there is no need to join cycle
   // collection.
   nsCOMPtr<nsIIcc> mHandler;
   Nullable<OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo> mIccInfo;
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/icc/IccListener.cpp
+++ b/dom/icc/IccListener.cpp
@@ -36,17 +36,17 @@ IccListener::IccListener(IccManager* aIc
   }
 
   nsCOMPtr<nsIIccInfo> iccInfo;
   mHandler->GetIccInfo(getter_AddRefs(iccInfo));
   if (iccInfo) {
     nsString iccId;
     iccInfo->GetIccid(iccId);
     if (!iccId.IsEmpty()) {
-      mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
+      mIcc = new Icc(mIccManager->GetOwner(), mHandler, iccInfo);
     }
   }
 
   DebugOnly<nsresult> rv = mHandler->RegisterListener(this);
   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
                    "Failed registering icc listener with Icc Handler");
 }
 
@@ -118,17 +118,17 @@ IccListener::NotifyIccInfoChanged()
   //    notify mIccManager a new icc is added.
   // 2. If the mIcc is not nullptr and iccInfo becomes to null, delete existed
   //    icc object and notify mIccManager the icc is removed.
   if (!mIcc) {
     if (iccInfo) {
       nsString iccId;
       iccInfo->GetIccid(iccId);
       if (!iccId.IsEmpty()) {
-        mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
+        mIcc = new Icc(mIccManager->GetOwner(), mHandler, iccInfo);
         mIccManager->NotifyIccAdd(iccId);
         mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
       }
     }
   } else {
     mIcc->UpdateIccInfo(iccInfo);
     mIcc->NotifyEvent(NS_LITERAL_STRING("iccinfochange"));
     if (!iccInfo) {
--- a/dom/webidl/MozIcc.webidl
+++ b/dom/webidl/MozIcc.webidl
@@ -328,17 +328,17 @@ interface MozIcc : EventTarget
    *        The contact will be updated in ICC.
    * @param pin2 [optional]
    *        PIN2 is only required for "fdn".
    *
    * @return a DOMRequest.
    */
   [Throws]
   DOMRequest updateContact(IccContactType contactType,
-                           any contact,
+                           mozContact contact,
                            optional DOMString? pin2 = null);
 
   // Integrated Circuit Card Helpers.
 
   /**
    * Verify whether the passed data (matchData) matches with some ICC's field
    * according to the mvno type (mvnoType).
    *