Bug 1114937 - Part 3: Web API change to adopt IccService for IccContacts. r=echen, r=hsinyi

This commit is contained in:
Bevis Tseng 2015-06-16 17:38:27 +08:00
parent aac7631208
commit 75c7fcbaa3
4 changed files with 38 additions and 39 deletions

View File

@ -7,6 +7,8 @@
#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"
@ -21,6 +23,7 @@
#include "nsServiceManagerUtils.h"
using mozilla::dom::icc::IccCallback;
using mozilla::dom::icc::IccContact;
namespace mozilla {
namespace dom {
@ -59,25 +62,16 @@ 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()
@ -88,7 +82,6 @@ void
Icc::Shutdown()
{
mIccInfo.SetNull();
mProvider = nullptr;
mHandler = nullptr;
mLive = false;
}
@ -421,44 +414,55 @@ Icc::GetCardLockRetryCount(IccLockType aLockType, ErrorResult& aRv)
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>

View File

@ -20,6 +20,7 @@ namespace dom {
class DOMRequest;
class OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo;
class mozContact;
class Promise;
class Icc final : public DOMEventTargetHelper
@ -29,8 +30,7 @@ public:
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();
@ -99,9 +99,8 @@ public:
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,
@ -122,11 +121,7 @@ private:
~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;

View File

@ -41,7 +41,7 @@ IccListener::IccListener(IccManager* aIccManager, uint32_t aClientId)
nsString iccId;
iccInfo->GetIccid(iccId);
if (!iccId.IsEmpty()) {
mIcc = new Icc(mIccManager->GetOwner(), mClientId, mHandler, iccInfo);
mIcc = new Icc(mIccManager->GetOwner(), mHandler, iccInfo);
}
}
@ -123,7 +123,7 @@ IccListener::NotifyIccInfoChanged()
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"));
}

View File

@ -333,7 +333,7 @@ interface MozIcc : EventTarget
*/
[Throws]
DOMRequest updateContact(IccContactType contactType,
any contact,
mozContact contact,
optional DOMString? pin2 = null);
// Integrated Circuit Card Helpers.