Bug 1112471 - Part 2: DOM Changes for getting icc service state API. r=smaug

This commit is contained in:
Edgar Chen 2014-12-26 10:11:20 +08:00
parent 57a7e84adb
commit 8954e6d67e
5 changed files with 44 additions and 0 deletions

View File

@ -106,6 +106,16 @@ ASSERT_ICC_MVNO_TYPE_EQUALITY(Gid, CARD_MVNO_TYPE_GID);
#undef ASSERT_ICC_MVNO_TYPE_EQUALITY
/**
* Enum IccService
*/
#define ASSERT_ICC_SERVICE_EQUALITY(webidlState, xpidlState) \
ASSERT_EQUALITY(IccService, webidlState, xpidlState)
ASSERT_ICC_SERVICE_EQUALITY(Fdn, CARD_SERVICE_FDN);
#undef ASSERT_ICC_SERVICE_EQUALITY
#undef ASSERT_EQUALITY
} // namespace icc

View File

@ -7,6 +7,7 @@
#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"
@ -404,5 +405,26 @@ Icc::MatchMvno(IccMvnoType aMvnoType, const nsAString& aMvnoData,
return request.forget().downcast<DOMRequest>();
}
already_AddRefed<Promise>
Icc::GetServiceState(IccService aService, ErrorResult& aRv)
{
if (!mProvider) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsISupports> supports;
nsresult rv = mProvider->GetServiceState(mClientId, GetOwner(),
static_cast<uint32_t>(aService),
getter_AddRefs(supports));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
nsCOMPtr<Promise> promise = do_QueryInterface(supports);
return promise.forget();
}
} // namespace dom
} // namespace mozilla

View File

@ -16,6 +16,7 @@ namespace dom {
class DOMRequest;
class OwningMozIccInfoOrMozGsmIccInfoOrMozCdmaIccInfo;
class Promise;
class Icc MOZ_FINAL : public DOMEventTargetHelper
{
@ -101,6 +102,9 @@ public:
MatchMvno(IccMvnoType aMvnoType, const nsAString& aMatchData,
ErrorResult& aRv);
already_AddRefed<Promise>
GetServiceState(IccService aService, ErrorResult& aRv);
IMPL_EVENT_HANDLER(iccinfochange)
IMPL_EVENT_HANDLER(cardstatechange)
IMPL_EVENT_HANDLER(stkcommand)

View File

@ -273,6 +273,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(Promise)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Promise)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(Promise)
NS_INTERFACE_MAP_END
Promise::Promise(nsIGlobalObject* aGlobal)

View File

@ -52,6 +52,10 @@ public:
Notify(JSContext* aCx, workers::Status aStatus) MOZ_OVERRIDE;
};
#define NS_PROMISE_IID \
{ 0x1b8d6215, 0x3e67, 0x43ba, \
{ 0x8a, 0xf9, 0x31, 0x5e, 0x8f, 0xce, 0x75, 0x65 } }
class Promise : public nsISupports,
public nsWrapperCache,
public SupportsWeakPtr<Promise>
@ -68,6 +72,7 @@ class Promise : public nsISupports,
friend class WrapperPromiseCallback;
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_PROMISE_IID)
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Promise)
MOZ_DECLARE_REFCOUNTED_TYPENAME(Promise)
@ -332,6 +337,8 @@ private:
TimeStamp mSettlementTimestamp;
};
NS_DEFINE_STATIC_IID_ACCESSOR(Promise, NS_PROMISE_IID)
} // namespace dom
} // namespace mozilla