Bug 1114935 - Part 4.1: Add Support of nsIIccInfo to IccInfo. r=echen

--HG--
extra : rebase_source : b4f0c29a016a4cd78b1ec6b1c99d6616b9be3b85
This commit is contained in:
Bevis Tseng 2015-01-07 19:25:22 +08:00
Родитель ad571c7972
Коммит 2d01d315a1
2 изменённых файлов: 177 добавлений и 94 удалений

Просмотреть файл

@ -4,6 +4,7 @@
#include "mozilla/dom/IccInfo.h"
#include "mozilla/dom/icc/PIccTypes.h"
#include "nsPIDOMWindow.h"
#define CONVERT_STRING_TO_NULLABLE_ENUM(_string, _enumType, _enum) \
@ -20,29 +21,110 @@
using namespace mozilla::dom;
using mozilla::dom::icc::IccInfoData;
// IccInfo
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IccInfo, mWindow, mIccInfo)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(IccInfo, mWindow)
NS_IMPL_CYCLE_COLLECTING_ADDREF(IccInfo)
NS_IMPL_CYCLE_COLLECTING_RELEASE(IccInfo)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IccInfo)
NS_INTERFACE_MAP_ENTRY(nsIIccInfo)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
IccInfo::IccInfo(nsPIDOMWindow* aWindow)
: mWindow(aWindow)
{
mIccType.SetIsVoid(true);
mIccid.SetIsVoid(true);
mMcc.SetIsVoid(true);
mMnc.SetIsVoid(true);
mSpn.SetIsVoid(true);
}
IccInfo::IccInfo(const IccInfoData& aData)
{
mIccType = aData.iccType();
mIccid = aData.iccid();
mMcc = aData.mcc();
mMnc = aData.mnc();
mSpn = aData.spn();
mIsDisplayNetworkNameRequired = aData.isDisplayNetworkNameRequired();
mIsDisplaySpnRequired = aData.isDisplaySpnRequired();
}
// nsIIccInfo
NS_IMETHODIMP
IccInfo::GetIccType(nsAString & aIccType)
{
aIccType = mIccType;
return NS_OK;
}
NS_IMETHODIMP
IccInfo::GetIccid(nsAString & aIccid)
{
aIccid = mIccid;
return NS_OK;
}
NS_IMETHODIMP
IccInfo::GetMcc(nsAString & aMcc)
{
aMcc = mMcc;
return NS_OK;
}
NS_IMETHODIMP
IccInfo::GetMnc(nsAString & aMnc)
{
aMnc = mMnc;
return NS_OK;
}
NS_IMETHODIMP
IccInfo::GetSpn(nsAString & aSpn)
{
aSpn = mSpn;
return NS_OK;
}
NS_IMETHODIMP
IccInfo::GetIsDisplayNetworkNameRequired(bool *aIsDisplayNetworkNameRequired)
{
*aIsDisplayNetworkNameRequired = mIsDisplayNetworkNameRequired;
return NS_OK;
}
NS_IMETHODIMP
IccInfo::GetIsDisplaySpnRequired(bool *aIsDisplaySpnRequired)
{
*aIsDisplaySpnRequired = mIsDisplaySpnRequired;
return NS_OK;
}
void
IccInfo::Update(nsIIccInfo* aInfo)
{
mIccInfo = aInfo;
NS_ASSERTION(aInfo, "aInfo is null");
aInfo->GetIccType(mIccType);
aInfo->GetIccid(mIccid);
aInfo->GetMcc(mMcc);
aInfo->GetMnc(mMnc);
aInfo->GetSpn(mSpn);
aInfo->GetIsDisplayNetworkNameRequired(
&mIsDisplayNetworkNameRequired);
aInfo->GetIsDisplaySpnRequired(
&mIsDisplaySpnRequired);
}
// WebIDL implementation
JSObject*
IccInfo::WrapObject(JSContext* aCx)
{
@ -52,15 +134,9 @@ IccInfo::WrapObject(JSContext* aCx)
Nullable<IccType>
IccInfo::GetIccType() const
{
if (!mIccInfo) {
return Nullable<IccType>();
}
nsAutoString type;
Nullable<IccType> iccType;
mIccInfo->GetIccType(type);
CONVERT_STRING_TO_NULLABLE_ENUM(type, IccType, iccType);
CONVERT_STRING_TO_NULLABLE_ENUM(mIccType, IccType, iccType);
return iccType;
}
@ -68,96 +144,77 @@ IccInfo::GetIccType() const
void
IccInfo::GetIccid(nsAString& aIccId) const
{
if (!mIccInfo) {
aIccId.SetIsVoid(true);
return;
}
mIccInfo->GetIccid(aIccId);
aIccId = mIccid;
}
void
IccInfo::GetMcc(nsAString& aMcc) const
{
if (!mIccInfo) {
aMcc.SetIsVoid(true);
return;
}
mIccInfo->GetMcc(aMcc);
aMcc = mMcc;
}
void
IccInfo::GetMnc(nsAString& aMnc) const
{
if (!mIccInfo) {
aMnc.SetIsVoid(true);
return;
}
mIccInfo->GetMnc(aMnc);
aMnc = mMnc;
}
void
IccInfo::GetSpn(nsAString& aSpn) const
{
if (!mIccInfo) {
aSpn.SetIsVoid(true);
return;
}
mIccInfo->GetSpn(aSpn);
aSpn = mSpn;
}
bool
IccInfo::IsDisplayNetworkNameRequired() const
{
if (!mIccInfo) {
return false;
}
bool isDisplayNetworkNameRequired;
mIccInfo->GetIsDisplayNetworkNameRequired(&isDisplayNetworkNameRequired);
return isDisplayNetworkNameRequired;
return mIsDisplayNetworkNameRequired;
}
bool
IccInfo::IsDisplaySpnRequired() const
{
if (!mIccInfo) {
return false;
}
bool isDisplaySpnRequired;
mIccInfo->GetIsDisplaySpnRequired(&isDisplaySpnRequired);
return isDisplaySpnRequired;
return mIsDisplaySpnRequired;
}
// GsmIccInfo
NS_IMPL_CYCLE_COLLECTION_INHERITED(GsmIccInfo, IccInfo, mGsmIccInfo)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(GsmIccInfo)
NS_INTERFACE_MAP_END_INHERITING(IccInfo)
NS_IMPL_ADDREF_INHERITED(GsmIccInfo, IccInfo)
NS_IMPL_RELEASE_INHERITED(GsmIccInfo, IccInfo)
NS_IMPL_ISUPPORTS_INHERITED(GsmIccInfo, IccInfo, nsIGsmIccInfo)
GsmIccInfo::GsmIccInfo(nsPIDOMWindow* aWindow)
: IccInfo(aWindow)
{
mPhoneNumber.SetIsVoid(true);
}
GsmIccInfo::GsmIccInfo(const IccInfoData& aData)
: IccInfo(aData)
{
mPhoneNumber = aData.phoneNumber();
}
// nsIGsmIccInfo
NS_IMETHODIMP
GsmIccInfo::GetMsisdn(nsAString & aMsisdn)
{
aMsisdn = mPhoneNumber;
return NS_OK;
}
// WebIDL implementation
void
GsmIccInfo::Update(nsIGsmIccInfo* aInfo)
{
MOZ_ASSERT(aInfo);
nsCOMPtr<nsIIccInfo> iccInfo = do_QueryInterface(aInfo);
MOZ_ASSERT(iccInfo);
IccInfo::Update(iccInfo);
mGsmIccInfo = aInfo;
aInfo->GetMsisdn(mPhoneNumber);
}
JSObject*
@ -169,39 +226,57 @@ GsmIccInfo::WrapObject(JSContext* aCx)
void
GsmIccInfo::GetMsisdn(nsAString& aMsisdn) const
{
if (!mGsmIccInfo) {
aMsisdn.SetIsVoid(true);
return;
}
mGsmIccInfo->GetMsisdn(aMsisdn);
aMsisdn = mPhoneNumber;
}
// CdmaIccInfo
NS_IMPL_CYCLE_COLLECTION_INHERITED(CdmaIccInfo, IccInfo, mCdmaIccInfo)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CdmaIccInfo)
NS_INTERFACE_MAP_END_INHERITING(IccInfo)
NS_IMPL_ADDREF_INHERITED(CdmaIccInfo, IccInfo)
NS_IMPL_RELEASE_INHERITED(CdmaIccInfo, IccInfo)
NS_IMPL_ISUPPORTS_INHERITED(CdmaIccInfo, IccInfo, nsICdmaIccInfo)
CdmaIccInfo::CdmaIccInfo(nsPIDOMWindow* aWindow)
: IccInfo(aWindow)
{
mPhoneNumber.SetIsVoid(true);
}
CdmaIccInfo::CdmaIccInfo(const IccInfoData& aData)
: IccInfo(aData)
{
mPhoneNumber = aData.phoneNumber();
mPrlVersion = aData.prlVersion();
}
// nsICdmaIccInfo
NS_IMETHODIMP
CdmaIccInfo::GetMdn(nsAString & aMdn)
{
aMdn = mPhoneNumber;
return NS_OK;
}
NS_IMETHODIMP
CdmaIccInfo::GetPrlVersion(int32_t *aPrlVersion)
{
*aPrlVersion = mPrlVersion;
return NS_OK;
}
void
CdmaIccInfo::Update(nsICdmaIccInfo* aInfo)
{
MOZ_ASSERT(aInfo);
nsCOMPtr<nsIIccInfo> iccInfo = do_QueryInterface(aInfo);
MOZ_ASSERT(iccInfo);
IccInfo::Update(iccInfo);
mCdmaIccInfo = aInfo;
aInfo->GetMdn(mPhoneNumber);
aInfo->GetPrlVersion(&mPrlVersion);
}
// WebIDL implementation
JSObject*
CdmaIccInfo::WrapObject(JSContext* aCx)
{
@ -211,23 +286,11 @@ CdmaIccInfo::WrapObject(JSContext* aCx)
void
CdmaIccInfo::GetMdn(nsAString& aMdn) const
{
if (!mCdmaIccInfo) {
aMdn.SetIsVoid(true);
return;
}
mCdmaIccInfo->GetMdn(aMdn);
aMdn = mPhoneNumber;
}
int32_t
CdmaIccInfo::PrlVersion() const
{
if (!mCdmaIccInfo) {
return 0;
}
int32_t prlVersion;
mCdmaIccInfo->GetPrlVersion(&prlVersion);
return prlVersion;
return mPrlVersion;
}

Просмотреть файл

@ -14,14 +14,20 @@ class nsPIDOMWindow;
namespace mozilla {
namespace dom {
class IccInfo : public nsISupports
namespace icc {
class IccInfoData;
} // namespace icc
class IccInfo : public nsIIccInfo
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IccInfo)
NS_DECL_NSIICCINFO
explicit IccInfo(nsPIDOMWindow* aWindow);
explicit IccInfo(const icc::IccInfoData& aData);
void
Update(nsIIccInfo* aInfo);
@ -61,18 +67,30 @@ public:
protected:
virtual ~IccInfo() {}
protected:
nsCOMPtr<nsPIDOMWindow> mWindow;
nsCOMPtr<nsIIccInfo> mIccInfo;
// To prevent compiling error in OS_WIN in auto-generated UnifiedBindingsXX.cpp,
// we have all data fields expended here instead of having a data member of
// |IccInfoData| defined in PIccTypes.h which indirectly includes "windows.h"
// See 925382 for the restriction of including "windows.h" in UnifiedBindings.cpp.
nsString mIccType;
nsString mIccid;
nsString mMcc;
nsString mMnc;
nsString mSpn;
bool mIsDisplayNetworkNameRequired;
bool mIsDisplaySpnRequired;
};
class GsmIccInfo MOZ_FINAL : public IccInfo
, public nsIGsmIccInfo
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GsmIccInfo, IccInfo)
NS_FORWARD_NSIICCINFO(IccInfo::)
NS_DECL_NSIGSMICCINFO
explicit GsmIccInfo(nsPIDOMWindow* aWindow);
explicit GsmIccInfo(const icc::IccInfoData& aData);
void
Update(nsIGsmIccInfo* aInfo);
@ -88,17 +106,19 @@ public:
private:
~GsmIccInfo() {}
private:
nsCOMPtr<nsIGsmIccInfo> mGsmIccInfo;
nsString mPhoneNumber;
};
class CdmaIccInfo MOZ_FINAL : public IccInfo
, public nsICdmaIccInfo
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CdmaIccInfo, IccInfo)
NS_FORWARD_NSIICCINFO(IccInfo::)
NS_DECL_NSICDMAICCINFO
explicit CdmaIccInfo(nsPIDOMWindow* aWindow);
explicit CdmaIccInfo(const icc::IccInfoData& aData);
void
Update(nsICdmaIccInfo* aInfo);
@ -117,8 +137,8 @@ public:
private:
~CdmaIccInfo() {}
private:
nsCOMPtr<nsICdmaIccInfo> mCdmaIccInfo;
nsString mPhoneNumber;
int32_t mPrlVersion;
};
} // namespace dom