Bug 981519 - number and name presentation - part 3 - DOM & IPC code. r=smaug

This commit is contained in:
Hsin-Yi Tsai 2014-04-10 14:25:42 +08:00
Родитель 9405057330
Коммит 279886c354
13 изменённых файлов: 289 добавлений и 46 удалений

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

@ -25,6 +25,7 @@
#include "CallsList.h"
#include "TelephonyCall.h"
#include "TelephonyCallGroup.h"
#include "TelephonyCallId.h"
using namespace mozilla::dom;
using mozilla::ErrorResult;
@ -282,6 +283,9 @@ Telephony::CreateNewDialingCall(uint32_t aServiceId, const nsAString& aNumber,
{
nsRefPtr<TelephonyCall> call =
TelephonyCall::Create(this, aServiceId, aNumber,
nsITelephonyService::CALL_PRESENTATION_ALLOWED,
EmptyString(),
nsITelephonyService::CALL_PRESENTATION_ALLOWED,
nsITelephonyService::CALL_STATE_DIALING, aCallIndex);
NS_ASSERTION(call, "This should never fail!");
@ -486,8 +490,10 @@ Telephony::EventListenerAdded(nsIAtom* aType)
NS_IMETHODIMP
Telephony::CallStateChanged(uint32_t aServiceId, uint32_t aCallIndex,
uint16_t aCallState, const nsAString& aNumber,
bool aIsOutgoing, bool aIsEmergency,
bool aIsConference, bool aIsSwitchable, bool aIsMergeable)
uint16_t aNumberPresentation, const nsAString& aName,
uint16_t aNamePresentation, bool aIsOutgoing,
bool aIsEmergency, bool aIsConference,
bool aIsSwitchable, bool aIsMergeable)
{
nsRefPtr<TelephonyCall> modifiedCall
= GetCallFromEverywhere(aServiceId, aCallIndex);
@ -536,9 +542,10 @@ Telephony::CallStateChanged(uint32_t aServiceId, uint32_t aCallIndex,
// Didn't find this call in mCalls or mGroup. Create a new call.
nsRefPtr<TelephonyCall> call =
TelephonyCall::Create(this, aServiceId, aNumber, aCallState, aCallIndex,
aIsEmergency, aIsConference, aIsSwitchable,
aIsMergeable);
TelephonyCall::Create(this, aServiceId, aNumber, aNumberPresentation,
aName, aNamePresentation, aCallState, aCallIndex,
aIsEmergency, aIsConference, aIsSwitchable,
aIsMergeable);
NS_ASSERTION(call, "This should never fail!");
NS_ASSERTION(aIsConference ? mGroup->CallsArray().Contains(call) :
@ -580,8 +587,10 @@ Telephony::EnumerateCallStateComplete()
NS_IMETHODIMP
Telephony::EnumerateCallState(uint32_t aServiceId, uint32_t aCallIndex,
uint16_t aCallState, const nsAString& aNumber,
bool aIsOutgoing, bool aIsEmergency,
bool aIsConference, bool aIsSwitchable, bool aIsMergeable)
uint16_t aNumberPresentation, const nsAString& aName,
uint16_t aNamePresentation, bool aIsOutgoing,
bool aIsEmergency, bool aIsConference,
bool aIsSwitchable, bool aIsMergeable)
{
nsRefPtr<TelephonyCall> call;
@ -596,7 +605,8 @@ Telephony::EnumerateCallState(uint32_t aServiceId, uint32_t aCallIndex,
}
// Didn't know anything about this call before now.
call = TelephonyCall::Create(this, aServiceId, aNumber, aCallState,
call = TelephonyCall::Create(this, aServiceId, aNumber, aNumberPresentation,
aName, aNamePresentation, aCallState,
aCallIndex, aIsEmergency, aIsConference,
aIsSwitchable, aIsMergeable);
NS_ASSERTION(call, "This should never fail!");
@ -660,14 +670,20 @@ Telephony::NotifyError(uint32_t aServiceId,
}
NS_IMETHODIMP
Telephony::NotifyCdmaCallWaiting(uint32_t aServiceId, const nsAString& aNumber)
Telephony::NotifyCdmaCallWaiting(uint32_t aServiceId, const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation)
{
MOZ_ASSERT(mCalls.Length() == 1);
nsRefPtr<TelephonyCall> callToNotify = mCalls[0];
MOZ_ASSERT(callToNotify && callToNotify->ServiceId() == aServiceId);
callToNotify->UpdateSecondNumber(aNumber);
nsRefPtr<TelephonyCallId> id =
new TelephonyCallId(GetOwner(), aNumber, aNumberPresentation, aName,
aNamePresentation);
callToNotify->UpdateSecondId(id);
DispatchCallEvent(NS_LITERAL_STRING("callschanged"), callToNotify);
return NS_OK;
}

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

@ -19,25 +19,29 @@ using mozilla::ErrorResult;
// static
already_AddRefed<TelephonyCall>
TelephonyCall::Create(Telephony* aTelephony, uint32_t aServiceId,
const nsAString& aNumber, uint16_t aCallState,
uint32_t aCallIndex, bool aEmergency, bool aIsConference,
bool aSwitchable, bool aMergeable)
const nsAString& aNumber, uint16_t aNumberPresentation,
const nsAString& aName, uint16_t aNamePresentation,
uint16_t aCallState, uint32_t aCallIndex, bool aEmergency,
bool aIsConference, bool aSwitchable, bool aMergeable)
{
NS_ASSERTION(aTelephony, "Null pointer!");
NS_ASSERTION(!aNumber.IsEmpty(), "Empty number!");
NS_ASSERTION(aCallIndex >= 1, "Invalid call index!");
nsRefPtr<TelephonyCall> call = new TelephonyCall(aTelephony->GetOwner());
nsRefPtr<TelephonyCallId> id = new TelephonyCallId(aTelephony->GetOwner(),
aNumber, aNumberPresentation,
aName, aNamePresentation);
call->mTelephony = aTelephony;
call->mServiceId = aServiceId;
call->mNumber = aNumber;
call->mCallIndex = aCallIndex;
call->mError = nullptr;
call->mEmergency = aEmergency;
call->mGroup = aIsConference ? aTelephony->ConferenceGroup() : nullptr;
call->mSwitchable = aSwitchable;
call->mMergeable = aMergeable;
call->mId = id;
call->ChangeStateInternal(aCallState, false);
@ -187,7 +191,9 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED(TelephonyCall,
DOMEventTargetHelper,
mTelephony,
mError,
mGroup);
mGroup,
mId,
mSecondId);
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TelephonyCall)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
@ -197,6 +203,20 @@ NS_IMPL_RELEASE_INHERITED(TelephonyCall, DOMEventTargetHelper)
// TelephonyCall WebIDL
already_AddRefed<TelephonyCallId>
TelephonyCall::Id() const
{
nsRefPtr<TelephonyCallId> id = mId;
return id.forget();
}
already_AddRefed<TelephonyCallId>
TelephonyCall::GetSecondId() const
{
nsRefPtr<TelephonyCallId> id = mSecondId;
return id.forget();
}
already_AddRefed<DOMError>
TelephonyCall::GetError() const
{
@ -272,7 +292,7 @@ TelephonyCall::Hold(ErrorResult& aRv)
return;
}
if (!mSecondNumber.IsEmpty()) {
if (mSecondId) {
// No state transition when we switch two numbers within one TelephonyCall
// object. Otherwise, the state here will be inconsistent with the backend
// RIL and will never be right.

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

@ -11,6 +11,8 @@
#include "mozilla/dom/DOMError.h"
#include "TelephonyCallId.h"
class nsPIDOMWindow;
namespace mozilla {
@ -21,9 +23,10 @@ class TelephonyCall MOZ_FINAL : public DOMEventTargetHelper
nsRefPtr<Telephony> mTelephony;
nsRefPtr<TelephonyCallGroup> mGroup;
nsRefPtr<TelephonyCallId> mId;
nsRefPtr<TelephonyCallId> mSecondId;
uint32_t mServiceId;
nsString mNumber;
nsString mSecondNumber;
nsString mState;
bool mEmergency;
nsRefPtr<DOMError> mError;
@ -39,7 +42,6 @@ public:
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TelephonyCall,
DOMEventTargetHelper)
friend class Telephony;
nsPIDOMWindow*
@ -53,17 +55,11 @@ public:
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
// WebIDL
void
GetNumber(nsString& aNumber) const
{
aNumber.Assign(mNumber);
}
already_AddRefed<TelephonyCallId>
Id() const;
void
GetSecondNumber(nsString& aSecondNumber) const
{
aSecondNumber.Assign(mSecondNumber);
}
already_AddRefed<TelephonyCallId>
GetSecondId() const;
void
GetState(nsString& aState) const
@ -122,7 +118,9 @@ public:
static already_AddRefed<TelephonyCall>
Create(Telephony* aTelephony, uint32_t aServiceId,
const nsAString& aNumber, uint16_t aCallState, uint32_t aCallIndex,
const nsAString& aNumber, uint16_t aNumberPresentation,
const nsAString& aName, uint16_t aNamePresentation,
uint16_t aCallState, uint32_t aCallIndex,
bool aEmergency = false, bool aIsConference = false,
bool aSwitchable = true, bool aMergeable = true);
@ -156,12 +154,6 @@ public:
mEmergency = aEmergency;
}
void
UpdateSecondNumber(const nsAString& aNumber)
{
mSecondNumber = aNumber;
}
void
UpdateSwitchable(bool aSwitchable) {
mSwitchable = aSwitchable;
@ -172,6 +164,11 @@ public:
mMergeable = aMergeable;
}
void
UpdateSecondId(TelephonyCallId* aId) {
mSecondId = aId;
}
void
NotifyError(const nsAString& aError);

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

@ -0,0 +1,77 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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 "TelephonyCallId.h"
#include "nsITelephonyService.h"
namespace mozilla {
namespace dom {
TelephonyCallId::TelephonyCallId(nsPIDOMWindow* aWindow,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation)
: mWindow(aWindow), mNumber(aNumber), mNumberPresentation(aNumberPresentation),
mName(aName), mNamePresentation(aNamePresentation)
{
SetIsDOMBinding();
}
TelephonyCallId::~TelephonyCallId()
{
}
JSObject*
TelephonyCallId::WrapObject(JSContext* aCx)
{
return TelephonyCallIdBinding::Wrap(aCx, this);
}
CallIdPresentation
TelephonyCallId::GetPresentationStr(uint16_t aPresentation) const
{
switch (aPresentation) {
case nsITelephonyService::CALL_PRESENTATION_ALLOWED:
return CallIdPresentation::Allowed;
case nsITelephonyService::CALL_PRESENTATION_RESTRICTED:
return CallIdPresentation::Restricted;
case nsITelephonyService::CALL_PRESENTATION_UNKNOWN:
return CallIdPresentation::Unknown;
case nsITelephonyService::CALL_PRESENTATION_PAYPHONE:
return CallIdPresentation::Payphone;
default:
MOZ_ASSUME_UNREACHABLE("Bad presentation!");
}
}
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TelephonyCallId, mWindow)
NS_IMPL_CYCLE_COLLECTING_ADDREF(TelephonyCallId)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TelephonyCallId)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TelephonyCallId)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
// WebIDL
CallIdPresentation
TelephonyCallId::NumberPresentation() const
{
return GetPresentationStr(mNumberPresentation);
}
CallIdPresentation
TelephonyCallId::NamePresentation() const
{
return GetPresentationStr(mNamePresentation);
}
} // namespace dom
} // namespace mozilla

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

@ -0,0 +1,76 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_TelephonyCallId_h
#define mozilla_dom_TelephonyCallId_h
#include "mozilla/dom/TelephonyCallIdBinding.h"
#include "mozilla/dom/telephony/TelephonyCommon.h"
#include "nsWrapperCache.h"
class nsPIDOMWindow;
namespace mozilla {
namespace dom {
class TelephonyCallId MOZ_FINAL : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TelephonyCallId)
TelephonyCallId(nsPIDOMWindow* aWindow, const nsAString& aNumber,
uint16_t aNumberPresentation, const nsAString& aName,
uint16_t aNamePresentation);
nsPIDOMWindow*
GetParentObject() const
{
return mWindow;
}
virtual JSObject*
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
// WebIDL
void
GetNumber(nsString& aNumber) const
{
aNumber.Assign(mNumber);
}
CallIdPresentation
NumberPresentation() const;
void
GetName(nsString& aName) const
{
aName.Assign(mName);
}
CallIdPresentation
NamePresentation() const;
private:
~TelephonyCallId();
nsCOMPtr<nsPIDOMWindow> mWindow;
nsString mNumber;
uint16_t mNumberPresentation;
nsString mName;
uint16_t mNamePresentation;
CallIdPresentation
GetPresentationStr(uint16_t aPresentation) const;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TelephonyCallId_h

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

@ -39,7 +39,7 @@ child:
NotifyCallStateChanged(uint32_t aClientId, IPCCallStateData aData);
NotifyCdmaCallWaiting(uint32_t aClientId, nsString aNumber);
NotifyCdmaCallWaiting(uint32_t aClientId, IPCCdmaWaitingCallData aData);
NotifyConferenceCallStateChanged(uint16_t aCallState);

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

@ -65,6 +65,9 @@ TelephonyChild::RecvNotifyCallStateChanged(const uint32_t& aClientId,
aData.callIndex(),
aData.callState(),
aData.number(),
aData.numberPresentation(),
aData.name(),
aData.namePresentation(),
aData.isOutGoing(),
aData.isEmergency(),
aData.isConference(),
@ -75,11 +78,15 @@ TelephonyChild::RecvNotifyCallStateChanged(const uint32_t& aClientId,
bool
TelephonyChild::RecvNotifyCdmaCallWaiting(const uint32_t& aClientId,
const nsString& aNumber)
const IPCCdmaWaitingCallData& aData)
{
MOZ_ASSERT(mService);
mService->NotifyCdmaCallWaiting(aClientId, aNumber);
mService->NotifyCdmaCallWaiting(aClientId,
aData.number(),
aData.numberPresentation(),
aData.name(),
aData.namePresentation());
return true;
}
@ -158,6 +165,9 @@ TelephonyRequestChild::RecvNotifyEnumerateCallState(const uint32_t& aClientId,
aData.callIndex(),
aData.callState(),
aData.number(),
aData.numberPresentation(),
aData.name(),
aData.namePresentation(),
aData.isOutGoing(),
aData.isEmergency(),
aData.isConference(),

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

@ -42,7 +42,7 @@ protected:
virtual bool
RecvNotifyCdmaCallWaiting(const uint32_t& aClientId,
const nsString& aNumber) MOZ_OVERRIDE;
const IPCCdmaWaitingCallData& aData) MOZ_OVERRIDE;
virtual bool
RecvNotifyConferenceCallStateChanged(const uint16_t& aCallState) MOZ_OVERRIDE;

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

@ -355,6 +355,9 @@ TelephonyIPCService::CallStateChanged(uint32_t aClientId,
uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference,
@ -363,6 +366,7 @@ TelephonyIPCService::CallStateChanged(uint32_t aClientId,
{
for (uint32_t i = 0; i < mListeners.Length(); i++) {
mListeners[i]->CallStateChanged(aClientId, aCallIndex, aCallState, aNumber,
aNumberPresentation, aName, aNamePresentation,
aIsOutgoing, aIsEmergency, aIsConference,
aIsSwitchable, aIsMergeable);
}
@ -389,6 +393,9 @@ TelephonyIPCService::EnumerateCallState(uint32_t aClientId,
uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference,
@ -400,10 +407,14 @@ TelephonyIPCService::EnumerateCallState(uint32_t aClientId,
NS_IMETHODIMP
TelephonyIPCService::NotifyCdmaCallWaiting(uint32_t aClientId,
const nsAString& aNumber)
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation)
{
for (uint32_t i = 0; i < mListeners.Length(); i++) {
mListeners[i]->NotifyCdmaCallWaiting(aClientId, aNumber);
mListeners[i]->NotifyCdmaCallWaiting(aClientId, aNumber, aNumberPresentation,
aName, aNamePresentation);
}
return NS_OK;
}

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

@ -283,6 +283,9 @@ TelephonyParent::CallStateChanged(uint32_t aClientId,
uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference,
@ -292,6 +295,7 @@ TelephonyParent::CallStateChanged(uint32_t aClientId,
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
IPCCallStateData data(aCallIndex, aCallState, nsString(aNumber),
aNumberPresentation, nsString(aName), aNamePresentation,
aIsOutgoing, aIsEmergency, aIsConference,
aIsSwitchable, aIsMergeable);
return SendNotifyCallStateChanged(aClientId, data) ? NS_OK : NS_ERROR_FAILURE;
@ -317,6 +321,9 @@ TelephonyParent::EnumerateCallState(uint32_t aClientId,
uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference,
@ -328,12 +335,16 @@ TelephonyParent::EnumerateCallState(uint32_t aClientId,
NS_IMETHODIMP
TelephonyParent::NotifyCdmaCallWaiting(uint32_t aClientId,
const nsAString& aNumber)
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation)
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
return SendNotifyCdmaCallWaiting(aClientId, nsString(aNumber))
? NS_OK : NS_ERROR_FAILURE;
IPCCdmaWaitingCallData data(nsString(aNumber), aNumberPresentation,
nsString(aName), aNamePresentation);
return SendNotifyCdmaCallWaiting(aClientId, data) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -430,6 +441,9 @@ TelephonyRequestParent::CallStateChanged(uint32_t aClientId,
uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference,
@ -458,6 +472,9 @@ TelephonyRequestParent::EnumerateCallState(uint32_t aClientId,
uint32_t aCallIndex,
uint16_t aCallState,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation,
bool aIsOutgoing,
bool aIsEmergency,
bool aIsConference,
@ -467,6 +484,7 @@ TelephonyRequestParent::EnumerateCallState(uint32_t aClientId,
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
IPCCallStateData data(aCallIndex, aCallState, nsString(aNumber),
aNumberPresentation, nsString(aName), aNamePresentation,
aIsOutgoing, aIsEmergency, aIsConference,
aIsSwitchable, aIsMergeable);
return SendNotifyEnumerateCallState(aClientId, data) ? NS_OK
@ -475,7 +493,10 @@ TelephonyRequestParent::EnumerateCallState(uint32_t aClientId,
NS_IMETHODIMP
TelephonyRequestParent::NotifyCdmaCallWaiting(uint32_t aClientId,
const nsAString& aNumber)
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation)
{
MOZ_CRASH("Not a TelephonyParent!");
}

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

@ -13,6 +13,9 @@ struct IPCCallStateData
uint32_t callIndex;
uint16_t callState;
nsString number;
uint16_t numberPresentation;
nsString name;
uint16_t namePresentation;
bool isOutGoing;
bool isEmergency;
bool isConference;
@ -20,6 +23,14 @@ struct IPCCallStateData
bool isMergeable;
};
struct IPCCdmaWaitingCallData
{
nsString number;
uint16_t numberPresentation;
nsString name;
uint16_t namePresentation;
};
} /* namespace telephony */
} /* namespace dom */
} /* namespace mozilla */

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

@ -15,6 +15,7 @@ EXPORTS.mozilla.dom += [
'Telephony.h',
'TelephonyCall.h',
'TelephonyCallGroup.h',
'TelephonyCallId.h',
]
EXPORTS.mozilla.dom.telephony += [
@ -32,6 +33,7 @@ UNIFIED_SOURCES += [
'Telephony.cpp',
'TelephonyCall.cpp',
'TelephonyCallGroup.cpp',
'TelephonyCallId.cpp',
'TelephonyFactory.cpp',
]

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

@ -1110,6 +1110,8 @@ var interfaceNamesInGlobalScope =
{name: "TelephonyCall", b2g: true, pref: "dom.telephony.enabled"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TelephonyCallGroup", b2g: true, pref: "dom.telephony.enabled"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TelephonyCallId", b2g: true, pref: "dom.telephony.enabled"},
// IMPORTANT: Do not change this list without review from a DOM peer!
"Text",
// IMPORTANT: Do not change this list without review from a DOM peer!