From da62cf5ddc95b5760b462bedcd6672ae0a460155 Mon Sep 17 00:00:00 2001 From: Vicamo Yang Date: Sat, 7 Sep 2013 14:19:53 +0800 Subject: [PATCH] Bug 864485 - 2/3: DOM & IPC. r=khuey --- b2g/installer/package-manifest.in | 2 +- browser/installer/package-manifest.in | 2 +- dom/base/Navigator.cpp | 2 +- dom/bindings/Bindings.conf | 10 +- dom/bluetooth/BluetoothHfpManager.cpp | 2 +- dom/bluetooth/BluetoothTelephonyListener.cpp | 12 +- dom/dom-config.mk | 1 - dom/ipc/ContentChild.cpp | 15 + dom/ipc/ContentChild.h | 3 + dom/ipc/ContentParent.cpp | 21 + dom/ipc/ContentParent.h | 3 + dom/mobilemessage/src/Makefile.in | 1 - dom/moz.build | 4 +- dom/system/gonk/Makefile.in | 1 - dom/telephony/CallEvent.cpp | 1 + dom/telephony/Makefile.in | 2 + dom/telephony/Telephony.cpp | 23 +- dom/telephony/TelephonyCall.cpp | 1 + dom/telephony/TelephonyCallGroup.cpp | 1 + dom/telephony/TelephonyFactory.cpp | 23 + dom/telephony/TelephonyFactory.h | 24 + dom/telephony/ipc/TelephonyChild.cpp | 130 +++++ dom/telephony/ipc/TelephonyChild.h | 77 +++ dom/telephony/ipc/TelephonyIPCProvider.cpp | 258 ++++++++++ dom/telephony/ipc/TelephonyIPCProvider.h | 37 ++ dom/telephony/ipc/TelephonyParent.cpp | 448 ++++++++++++++++++ dom/telephony/ipc/TelephonyParent.h | 128 +++++ dom/telephony/moz.build | 23 +- .../mochitest/general/test_interfaces.html | 8 +- dom/webidl/WebIDL.mk | 10 +- layout/build/Makefile.in | 2 +- layout/build/nsLayoutModule.cpp | 9 + 32 files changed, 1237 insertions(+), 47 deletions(-) create mode 100644 dom/telephony/TelephonyFactory.cpp create mode 100644 dom/telephony/TelephonyFactory.h create mode 100644 dom/telephony/ipc/TelephonyChild.cpp create mode 100644 dom/telephony/ipc/TelephonyChild.h create mode 100644 dom/telephony/ipc/TelephonyIPCProvider.cpp create mode 100644 dom/telephony/ipc/TelephonyIPCProvider.h create mode 100644 dom/telephony/ipc/TelephonyParent.cpp create mode 100644 dom/telephony/ipc/TelephonyParent.h diff --git a/b2g/installer/package-manifest.in b/b2g/installer/package-manifest.in index 2553cf7659ae..adf1200a495a 100644 --- a/b2g/installer/package-manifest.in +++ b/b2g/installer/package-manifest.in @@ -164,7 +164,6 @@ @BINPATH@/components/dom_base.xpt @BINPATH@/components/dom_system.xpt #ifdef MOZ_B2G_RIL -@BINPATH@/components/dom_telephony.xpt @BINPATH@/components/dom_voicemail.xpt @BINPATH@/components/dom_wifi.xpt @BINPATH@/components/dom_system_gonk.xpt @@ -203,6 +202,7 @@ @BINPATH@/components/dom_mobilemessage.xpt @BINPATH@/components/dom_storage.xpt @BINPATH@/components/dom_stylesheets.xpt +@BINPATH@/components/dom_telephony.xpt @BINPATH@/components/dom_threads.xpt @BINPATH@/components/dom_traversal.xpt @BINPATH@/components/dom_views.xpt diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 7842047d3bc9..387a7915c873 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -176,7 +176,6 @@ @BINPATH@/components/dom_base.xpt @BINPATH@/components/dom_system.xpt #ifdef MOZ_B2G_RIL -@BINPATH@/components/dom_telephony.xpt @BINPATH@/components/dom_voicemail.xpt @BINPATH@/components/dom_wifi.xpt @BINPATH@/components/dom_system_gonk.xpt @@ -212,6 +211,7 @@ @BINPATH@/components/dom_mobilemessage.xpt @BINPATH@/components/dom_storage.xpt @BINPATH@/components/dom_stylesheets.xpt +@BINPATH@/components/dom_telephony.xpt @BINPATH@/components/dom_traversal.xpt #ifdef MOZ_WEBSPEECH @BINPATH@/components/dom_webspeechrecognition.xpt diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 45ba553271be..afca9c5111ee 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -54,7 +54,7 @@ #include "MediaManager.h" #endif #ifdef MOZ_B2G_RIL -#include "Telephony.h" +#include "mozilla/dom/telephony/Telephony.h" #endif #ifdef MOZ_B2G_BT #include "BluetoothManager.h" diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 221886370eae..d1e75c49fba1 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -168,12 +168,12 @@ DOMInterfaces = { 'CallEvent': { 'nativeType': 'mozilla::dom::telephony::CallEvent', - 'headerFile': 'CallEvent.h', + 'headerFile': 'mozilla/dom/telephony/CallEvent.h', }, 'CallsList': { 'nativeType': 'mozilla::dom::telephony::CallsList', - 'headerFile': 'CallsList.h', + 'headerFile': 'mozilla/dom/telephony/CallsList.h', }, 'CameraControl': { @@ -1162,17 +1162,17 @@ DOMInterfaces = { 'Telephony' : { 'nativeType': 'mozilla::dom::telephony::Telephony', - 'headerFile': 'Telephony.h', + 'headerFile': 'mozilla/dom/telephony/Telephony.h', }, 'TelephonyCall' : { 'nativeType': 'mozilla::dom::telephony::TelephonyCall', - 'headerFile': 'TelephonyCall.h', + 'headerFile': 'mozilla/dom/telephony/TelephonyCall.h', }, 'TelephonyCallGroup' : { 'nativeType': 'mozilla::dom::telephony::TelephonyCallGroup', - 'headerFile': 'TelephonyCallGroup.h', + 'headerFile': 'mozilla/dom/telephony/TelephonyCallGroup.h', }, 'Text': { diff --git a/dom/bluetooth/BluetoothHfpManager.cpp b/dom/bluetooth/BluetoothHfpManager.cpp index 5ec83c2074d3..c077d82be160 100644 --- a/dom/bluetooth/BluetoothHfpManager.cpp +++ b/dom/bluetooth/BluetoothHfpManager.cpp @@ -1483,7 +1483,7 @@ BluetoothHfpManager::OnSocketConnectSuccess(BluetoothSocket* aSocket) } nsCOMPtr provider = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); NS_ENSURE_TRUE_VOID(provider); provider->EnumerateCalls(mListener->GetListener()); diff --git a/dom/bluetooth/BluetoothTelephonyListener.cpp b/dom/bluetooth/BluetoothTelephonyListener.cpp index eac3a431ba06..93bfc84e676f 100644 --- a/dom/bluetooth/BluetoothTelephonyListener.cpp +++ b/dom/bluetooth/BluetoothTelephonyListener.cpp @@ -61,13 +61,11 @@ TelephonyListener::EnumerateCallState(uint32_t aCallIndex, bool aIsActive, bool aIsOutgoing, bool aIsEmergency, - bool aIsConference, - bool* aResult) + bool aIsConference) { BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); hfp->HandleCallStateChanged(aCallIndex, aCallState, EmptyString(), aNumber, aIsOutgoing, false); - *aResult = true; return NS_OK; } @@ -117,10 +115,10 @@ bool BluetoothTelephonyListener::StartListening() { nsCOMPtr provider = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); NS_ENSURE_TRUE(provider, false); - nsresult rv = provider->RegisterTelephonyMsg(mTelephonyListener); + nsresult rv = provider->RegisterListener(mTelephonyListener); NS_ENSURE_SUCCESS(rv, false); return true; @@ -130,10 +128,10 @@ bool BluetoothTelephonyListener::StopListening() { nsCOMPtr provider = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); NS_ENSURE_TRUE(provider, false); - nsresult rv = provider->UnregisterTelephonyMsg(mTelephonyListener); + nsresult rv = provider->UnregisterListener(mTelephonyListener); return NS_FAILED(rv) ? false : true; } diff --git a/dom/dom-config.mk b/dom/dom-config.mk index b001fc9d3789..6450d3c92a03 100644 --- a/dom/dom-config.mk +++ b/dom/dom-config.mk @@ -40,7 +40,6 @@ DOM_SRCDIRS = \ ifdef MOZ_B2G_RIL DOM_SRCDIRS += \ dom/system/gonk \ - dom/telephony \ dom/wifi \ dom/icc/src \ $(NULL) diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index fa5d8ccde545..7ebea456bd85 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -96,6 +96,7 @@ #include "mozilla/dom/indexedDB/PIndexedDBChild.h" #include "mozilla/dom/mobilemessage/SmsChild.h" +#include "mozilla/dom/telephony/TelephonyChild.h" #include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h" #include "mozilla/dom/bluetooth/PBluetoothChild.h" #include "mozilla/dom/PFMRadioChild.h" @@ -126,6 +127,7 @@ using namespace mozilla::dom::devicestorage; using namespace mozilla::dom::ipc; using namespace mozilla::dom::mobilemessage; using namespace mozilla::dom::indexedDB; +using namespace mozilla::dom::telephony; using namespace mozilla::hal_sandbox; using namespace mozilla::ipc; using namespace mozilla::layers; @@ -919,6 +921,19 @@ ContentChild::DeallocPSmsChild(PSmsChild* aSms) return true; } +PTelephonyChild* +ContentChild::AllocPTelephonyChild() +{ + MOZ_CRASH("No one should be allocating PTelephonyChild actors"); +} + +bool +ContentChild::DeallocPTelephonyChild(PTelephonyChild* aActor) +{ + delete aActor; + return true; +} + PStorageChild* ContentChild::AllocPStorageChild() { diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 279af64fb619..4dd4d77e20b0 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -152,6 +152,9 @@ public: virtual PSmsChild* AllocPSmsChild(); virtual bool DeallocPSmsChild(PSmsChild*); + virtual PTelephonyChild* AllocPTelephonyChild(); + virtual bool DeallocPTelephonyChild(PTelephonyChild*); + virtual PStorageChild* AllocPStorageChild(); virtual bool DeallocPStorageChild(PStorageChild* aActor); diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 8a305d4e9eb9..8f7555931e5d 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -35,6 +35,7 @@ #include "mozilla/dom/PFMRadioParent.h" #include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h" #include "mozilla/dom/GeolocationBinding.h" +#include "mozilla/dom/telephony/TelephonyParent.h" #include "SmsParent.h" #include "mozilla/Hal.h" #include "mozilla/hal_sandbox/PHalParent.h" @@ -148,6 +149,7 @@ using namespace mozilla::dom::devicestorage; using namespace mozilla::dom::indexedDB; using namespace mozilla::dom::power; using namespace mozilla::dom::mobilemessage; +using namespace mozilla::dom::telephony; using namespace mozilla::hal; using namespace mozilla::ipc; using namespace mozilla::layers; @@ -2244,6 +2246,25 @@ ContentParent::DeallocPSmsParent(PSmsParent* aSms) return true; } +PTelephonyParent* +ContentParent::AllocPTelephonyParent() +{ + if (!AssertAppProcessPermission(this, "telephony")) { + return nullptr; + } + + TelephonyParent* actor = new TelephonyParent(); + NS_ADDREF(actor); + return actor; +} + +bool +ContentParent::DeallocPTelephonyParent(PTelephonyParent* aActor) +{ + static_cast(aActor)->Release(); + return true; +} + PStorageParent* ContentParent::AllocPStorageParent() { diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 5bfa77b18d1a..252e0235c90c 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -321,6 +321,9 @@ private: virtual PSmsParent* AllocPSmsParent(); virtual bool DeallocPSmsParent(PSmsParent*); + virtual PTelephonyParent* AllocPTelephonyParent(); + virtual bool DeallocPTelephonyParent(PTelephonyParent*); + virtual PStorageParent* AllocPStorageParent(); virtual bool DeallocPStorageParent(PStorageParent* aActor); diff --git a/dom/mobilemessage/src/Makefile.in b/dom/mobilemessage/src/Makefile.in index f64158868302..edebdeebbfd5 100644 --- a/dom/mobilemessage/src/Makefile.in +++ b/dom/mobilemessage/src/Makefile.in @@ -28,7 +28,6 @@ LOCAL_INCLUDES += $(VPATH:%=-I%) ifdef MOZ_B2G_RIL LOCAL_INCLUDES += \ - -I$(topsrcdir)/dom/telephony \ -I$(topsrcdir)/dom/system/gonk \ $(NULL) endif diff --git a/dom/moz.build b/dom/moz.build index 5aeb1ba6a7a5..4c87f43ef34c 100644 --- a/dom/moz.build +++ b/dom/moz.build @@ -72,7 +72,8 @@ PARALLEL_DIRS += [ 'camera', 'audiochannel', 'promise', - 'wappush' + 'wappush', + 'telephony', ] if CONFIG['OS_ARCH'] == 'WINNT': @@ -80,7 +81,6 @@ if CONFIG['OS_ARCH'] == 'WINNT': if CONFIG['MOZ_B2G_RIL']: PARALLEL_DIRS += [ - 'telephony', 'wifi', 'icc', 'cellbroadcast', diff --git a/dom/system/gonk/Makefile.in b/dom/system/gonk/Makefile.in index 56710dccf091..01378e2f9357 100644 --- a/dom/system/gonk/Makefile.in +++ b/dom/system/gonk/Makefile.in @@ -17,7 +17,6 @@ include $(topsrcdir)/dom/dom-config.mk LOCAL_INCLUDES = \ -I$(topsrcdir)/dom/base \ -I$(topsrcdir)/dom/src/geolocation \ - -I$(topsrcdir)/dom/telephony \ -I$(topsrcdir)/dom/wifi \ -I$(topsrcdir)/dom/bluetooth \ -I$(topsrcdir)/content/events/src \ diff --git a/dom/telephony/CallEvent.cpp b/dom/telephony/CallEvent.cpp index 30ab81aee468..580750f06089 100644 --- a/dom/telephony/CallEvent.cpp +++ b/dom/telephony/CallEvent.cpp @@ -11,6 +11,7 @@ USING_TELEPHONY_NAMESPACE using namespace mozilla::dom; +using mozilla::ErrorResult; /* static */ already_AddRefed diff --git a/dom/telephony/Makefile.in b/dom/telephony/Makefile.in index e2f1f0e33732..ba0eb3e44d09 100644 --- a/dom/telephony/Makefile.in +++ b/dom/telephony/Makefile.in @@ -3,3 +3,5 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. include $(topsrcdir)/dom/dom-config.mk +include $(topsrcdir)/config/rules.mk +include $(topsrcdir)/ipc/chromium/chromium-config.mk diff --git a/dom/telephony/Telephony.cpp b/dom/telephony/Telephony.cpp index 430242e65c6a..95749b0fb6f5 100644 --- a/dom/telephony/Telephony.cpp +++ b/dom/telephony/Telephony.cpp @@ -24,10 +24,9 @@ #include "TelephonyCall.h" #include "TelephonyCallGroup.h" -#define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1" - USING_TELEPHONY_NAMESPACE using namespace mozilla::dom; +using mozilla::ErrorResult; namespace { @@ -51,6 +50,8 @@ public: MOZ_ASSERT(mTelephony); } + virtual ~Listener() {} + void Disconnect() { @@ -111,7 +112,7 @@ Telephony::Shutdown() mListener->Disconnect(); if (mProvider) { - mProvider->UnregisterTelephonyMsg(mListener); + mProvider->UnregisterListener(mListener); mProvider = nullptr; } @@ -132,7 +133,7 @@ Telephony::Create(nsPIDOMWindow* aOwner, ErrorResult& aRv) NS_ASSERTION(aOwner, "Null owner!"); nsCOMPtr ril = - do_GetService(NS_RILCONTENTHELPER_CONTRACTID); + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); if (!ril) { aRv.Throw(NS_ERROR_UNEXPECTED); return nullptr; @@ -165,7 +166,7 @@ Telephony::Create(nsPIDOMWindow* aOwner, ErrorResult& aRv) return nullptr; } - rv = ril->RegisterTelephonyMsg(telephony->mListener); + rv = ril->RegisterListener(telephony->mListener); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; @@ -222,12 +223,7 @@ Telephony::DialInternal(bool isEmergency, } } - nsresult rv; - if (isEmergency) { - rv = mProvider->DialEmergency(aNumber); - } else { - rv = mProvider->Dial(aNumber); - } + nsresult rv = mProvider->Dial(aNumber, isEmergency); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; @@ -591,7 +587,7 @@ NS_IMETHODIMP Telephony::EnumerateCallState(uint32_t aCallIndex, uint16_t aCallState, const nsAString& aNumber, bool aIsActive, bool aIsOutgoing, bool aIsEmergency, - bool aIsConference, bool* aContinue) + bool aIsConference) { nsRefPtr call; @@ -603,12 +599,10 @@ Telephony::EnumerateCallState(uint32_t aCallIndex, uint16_t aCallState, call = aIsConference ? mGroup->GetCall(aCallIndex) : GetCall(aCallIndex); if (call) { // We have the call either in mCalls or in mGroup. Skip it. - *aContinue = true; return NS_OK; } if (MoveCall(aCallIndex, aIsConference)) { - *aContinue = true; return NS_OK; } @@ -622,7 +616,6 @@ Telephony::EnumerateCallState(uint32_t aCallIndex, uint16_t aCallState, mCalls.Contains(call), "Should have auto-added new call!"); - *aContinue = true; return NS_OK; } diff --git a/dom/telephony/TelephonyCall.cpp b/dom/telephony/TelephonyCall.cpp index f90389da17a9..23868f829641 100644 --- a/dom/telephony/TelephonyCall.cpp +++ b/dom/telephony/TelephonyCall.cpp @@ -15,6 +15,7 @@ USING_TELEPHONY_NAMESPACE using namespace mozilla::dom; +using mozilla::ErrorResult; // static already_AddRefed diff --git a/dom/telephony/TelephonyCallGroup.cpp b/dom/telephony/TelephonyCallGroup.cpp index 0e71643afba1..d5571a657ac3 100644 --- a/dom/telephony/TelephonyCallGroup.cpp +++ b/dom/telephony/TelephonyCallGroup.cpp @@ -13,6 +13,7 @@ USING_TELEPHONY_NAMESPACE using namespace mozilla::dom; +using mozilla::ErrorResult; TelephonyCallGroup::TelephonyCallGroup() : mCallState(nsITelephonyProvider::CALL_STATE_UNKNOWN) diff --git a/dom/telephony/TelephonyFactory.cpp b/dom/telephony/TelephonyFactory.cpp new file mode 100644 index 000000000000..3ac863c34fc9 --- /dev/null +++ b/dom/telephony/TelephonyFactory.cpp @@ -0,0 +1,23 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/telephony/TelephonyFactory.h" +#include "nsServiceManagerUtils.h" +#include "nsXULAppAPI.h" +#include "ipc/TelephonyIPCProvider.h" + +USING_TELEPHONY_NAMESPACE + +/* static */ already_AddRefed +TelephonyFactory::CreateTelephonyProvider() +{ + nsCOMPtr provider; + + if (XRE_GetProcessType() == GeckoProcessType_Content) { + provider = new TelephonyIPCProvider(); + } + + return provider.forget(); +} diff --git a/dom/telephony/TelephonyFactory.h b/dom/telephony/TelephonyFactory.h new file mode 100644 index 000000000000..07e3f779304e --- /dev/null +++ b/dom/telephony/TelephonyFactory.h @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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_telephony_TelephonyFactory_h +#define mozilla_dom_telephony_TelephonyFactory_h + +#include "nsCOMPtr.h" +#include "mozilla/dom/telephony/TelephonyCommon.h" + +class nsITelephonyProvider; + +BEGIN_TELEPHONY_NAMESPACE + +class TelephonyFactory +{ +public: + static already_AddRefed CreateTelephonyProvider(); +}; + +END_TELEPHONY_NAMESPACE + +#endif // mozilla_dom_telephony_TelephonyFactory_h diff --git a/dom/telephony/ipc/TelephonyChild.cpp b/dom/telephony/ipc/TelephonyChild.cpp new file mode 100644 index 000000000000..411e3b35f0a7 --- /dev/null +++ b/dom/telephony/ipc/TelephonyChild.cpp @@ -0,0 +1,130 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/telephony/TelephonyChild.h" + +USING_TELEPHONY_NAMESPACE + +/******************************************************************************* + * TelephonyChild + ******************************************************************************/ + +TelephonyChild::TelephonyChild(nsITelephonyListener* aListener) + : mListener(aListener) +{ + MOZ_ASSERT(aListener); +} + +void +TelephonyChild::ActorDestroy(ActorDestroyReason aWhy) +{ + mListener = nullptr; +} + +PTelephonyRequestChild* +TelephonyChild::AllocPTelephonyRequestChild() +{ + MOZ_CRASH("Caller is supposed to manually construct a request!"); +} + +bool +TelephonyChild::DeallocPTelephonyRequestChild(PTelephonyRequestChild* aActor) +{ + delete aActor; + return true; +} + +bool +TelephonyChild::RecvNotifyCallError(const int32_t& aCallIndex, + const nsString& aError) +{ + MOZ_ASSERT(mListener); + + mListener->NotifyError(aCallIndex, aError); + return true; +} + +bool +TelephonyChild::RecvNotifyCallStateChanged(const IPCCallStateData& aData) +{ + MOZ_ASSERT(mListener); + + mListener->CallStateChanged(aData.callIndex(), + aData.callState(), + aData.number(), + aData.isActive(), + aData.isOutGoing(), + aData.isEmergency(), + aData.isConference()); + return true; +} + +bool +TelephonyChild::RecvNotifyCdmaCallWaiting(const nsString& aNumber) +{ + MOZ_ASSERT(mListener); + + mListener->NotifyCdmaCallWaiting(aNumber); + return true; +} + +bool +TelephonyChild::RecvNotifyConferenceCallStateChanged(const uint16_t& aCallState) +{ + MOZ_ASSERT(mListener); + + mListener->ConferenceCallStateChanged(aCallState); + return true; +} + +bool +TelephonyChild::RecvNotifySupplementaryService(const int32_t& aCallIndex, + const uint16_t& aNotification) +{ + MOZ_ASSERT(mListener); + + mListener->SupplementaryServiceNotification(aCallIndex, aNotification); + return true; +} + +/******************************************************************************* + * TelephonyRequestChild + ******************************************************************************/ + +TelephonyRequestChild::TelephonyRequestChild(nsITelephonyListener* aListener) + : mListener(aListener) +{ + MOZ_ASSERT(aListener); +} + +void +TelephonyRequestChild::ActorDestroy(ActorDestroyReason aWhy) +{ + mListener = nullptr; +} + +bool +TelephonyRequestChild::Recv__delete__() +{ + MOZ_ASSERT(mListener); + + mListener->EnumerateCallStateComplete(); + return true; +} + +bool +TelephonyRequestChild::RecvNotifyEnumerateCallState(const IPCCallStateData& aData) +{ + MOZ_ASSERT(mListener); + + mListener->EnumerateCallState(aData.callIndex(), + aData.callState(), + aData.number(), + aData.isActive(), + aData.isOutGoing(), + aData.isEmergency(), + aData.isConference()); + return true; +} diff --git a/dom/telephony/ipc/TelephonyChild.h b/dom/telephony/ipc/TelephonyChild.h new file mode 100644 index 000000000000..91eb1f8d2a54 --- /dev/null +++ b/dom/telephony/ipc/TelephonyChild.h @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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_telephony_TelephonyChild_h +#define mozilla_dom_telephony_TelephonyChild_h + +#include "mozilla/dom/telephony/TelephonyCommon.h" +#include "mozilla/dom/telephony/PTelephonyChild.h" +#include "mozilla/dom/telephony/PTelephonyRequestChild.h" +#include "nsITelephonyProvider.h" + +BEGIN_TELEPHONY_NAMESPACE + +class TelephonyChild : public PTelephonyChild +{ +public: + TelephonyChild(nsITelephonyListener* aListener); + +protected: + virtual ~TelephonyChild() {} + + virtual void + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; + + virtual PTelephonyRequestChild* + AllocPTelephonyRequestChild() MOZ_OVERRIDE; + + virtual bool + DeallocPTelephonyRequestChild(PTelephonyRequestChild* aActor) MOZ_OVERRIDE; + + virtual bool + RecvNotifyCallError(const int32_t& aCallIndex, + const nsString& aError) MOZ_OVERRIDE; + + virtual bool + RecvNotifyCallStateChanged(const IPCCallStateData& aData) MOZ_OVERRIDE; + + virtual bool + RecvNotifyCdmaCallWaiting(const nsString& aNumber) MOZ_OVERRIDE; + + virtual bool + RecvNotifyConferenceCallStateChanged(const uint16_t& aCallState) MOZ_OVERRIDE; + + virtual bool + RecvNotifySupplementaryService(const int32_t& aCallIndex, + const uint16_t& aNotification) MOZ_OVERRIDE; + +private: + nsCOMPtr mListener; +}; + +class TelephonyRequestChild : public PTelephonyRequestChild +{ +public: + TelephonyRequestChild(nsITelephonyListener* aListener); + +protected: + virtual ~TelephonyRequestChild() {} + + virtual void + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; + + virtual bool + Recv__delete__() MOZ_OVERRIDE; + + virtual bool + RecvNotifyEnumerateCallState(const IPCCallStateData& aData) MOZ_OVERRIDE; + +private: + nsCOMPtr mListener; +}; + +END_TELEPHONY_NAMESPACE + +#endif // mozilla_dom_telephony_TelephonyChild_h diff --git a/dom/telephony/ipc/TelephonyIPCProvider.cpp b/dom/telephony/ipc/TelephonyIPCProvider.cpp new file mode 100644 index 000000000000..3b40a31271c3 --- /dev/null +++ b/dom/telephony/ipc/TelephonyIPCProvider.cpp @@ -0,0 +1,258 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/ContentChild.h" +#include "mozilla/dom/telephony/TelephonyChild.h" +#include "ipc/TelephonyIPCProvider.h" + +USING_TELEPHONY_NAMESPACE +using namespace mozilla::dom; + +NS_IMPL_ISUPPORTS2(TelephonyIPCProvider, + nsITelephonyProvider, + nsITelephonyListener) + +TelephonyIPCProvider::TelephonyIPCProvider() +{ + // Deallocated in ContentChild::DeallocPTelephonyChild(). + mPTelephonyChild = new TelephonyChild(this); + ContentChild::GetSingleton()->SendPTelephonyConstructor(mPTelephonyChild); +} + +TelephonyIPCProvider::~TelephonyIPCProvider() +{ + mPTelephonyChild->Send__delete__(mPTelephonyChild); + mPTelephonyChild = nullptr; +} + +/* + * Implementation of nsITelephonyProvider. + */ + +NS_IMETHODIMP +TelephonyIPCProvider::RegisterListener(nsITelephonyListener *aListener) +{ + MOZ_ASSERT(!mListeners.Contains(aListener)); + + // nsTArray doesn't fail. + mListeners.AppendElement(aListener); + + if (mListeners.Length() == 1) { + mPTelephonyChild->SendRegisterListener(); + } + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::UnregisterListener(nsITelephonyListener *aListener) +{ + MOZ_ASSERT(mListeners.Contains(aListener)); + + // We always have the element here, so it can't fail. + mListeners.RemoveElement(aListener); + + if (!mListeners.Length()) { + mPTelephonyChild->SendUnregisterListener(); + } + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::EnumerateCalls(nsITelephonyListener *aListener) +{ + // Life time of newly allocated TelephonyRequestChild instance is managed by + // IPDL itself. + TelephonyRequestChild* actor = new TelephonyRequestChild(aListener); + mPTelephonyChild->SendPTelephonyRequestConstructor(actor); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::Dial(const nsAString& aNumber, + bool aIsEmergency) +{ + mPTelephonyChild->SendDialCall(nsString(aNumber), aIsEmergency); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::HangUp(uint32_t aCallIndex) +{ + mPTelephonyChild->SendHangUpCall(aCallIndex); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::AnswerCall(uint32_t aCallIndex) +{ + mPTelephonyChild->SendAnswerCall(aCallIndex); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::RejectCall(uint32_t aCallIndex) +{ + mPTelephonyChild->SendRejectCall(aCallIndex); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::HoldCall(uint32_t aCallIndex) +{ + mPTelephonyChild->SendHoldCall(aCallIndex); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::ResumeCall(uint32_t aCallIndex) +{ + mPTelephonyChild->SendResumeCall(aCallIndex); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::ConferenceCall() +{ + mPTelephonyChild->SendConferenceCall(); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::SeparateCall(uint32_t aCallIndex) +{ + mPTelephonyChild->SendSeparateCall(aCallIndex); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::HoldConference() +{ + mPTelephonyChild->SendHoldConference(); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::ResumeConference() +{ + mPTelephonyChild->SendResumeConference(); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::StartTone(const nsAString& aDtmfChar) +{ + mPTelephonyChild->SendStartTone(nsString(aDtmfChar)); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::StopTone() +{ + mPTelephonyChild->SendStopTone(); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::GetMicrophoneMuted(bool* aMuted) +{ + mPTelephonyChild->SendGetMicrophoneMuted(aMuted); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::SetMicrophoneMuted(bool aMuted) +{ + mPTelephonyChild->SendSetMicrophoneMuted(aMuted); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::GetSpeakerEnabled(bool* aEnabled) +{ + mPTelephonyChild->SendGetSpeakerEnabled(aEnabled); + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::SetSpeakerEnabled(bool aEnabled) +{ + mPTelephonyChild->SendSetSpeakerEnabled(aEnabled); + return NS_OK; +} + +// nsITelephonyListener + +NS_IMETHODIMP +TelephonyIPCProvider::CallStateChanged(uint32_t aCallIndex, + uint16_t aCallState, + const nsAString& aNumber, + bool aIsActive, + bool aIsOutgoing, + bool aIsEmergency, + bool aIsConference) +{ + for (uint32_t i = 0; i < mListeners.Length(); i++) { + mListeners[i]->CallStateChanged(aCallIndex, aCallState, aNumber, + aIsActive, aIsOutgoing, aIsEmergency, + aIsConference); + } + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::ConferenceCallStateChanged(uint16_t aCallState) +{ + for (uint32_t i = 0; i < mListeners.Length(); i++) { + mListeners[i]->ConferenceCallStateChanged(aCallState); + } + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::EnumerateCallStateComplete() +{ + MOZ_CRASH("Not a EnumerateCalls request!"); +} + +NS_IMETHODIMP +TelephonyIPCProvider::EnumerateCallState(uint32_t aCallIndex, + uint16_t aCallState, + const nsAString& aNumber, + bool aIsActive, + bool aIsOutgoing, + bool aIsEmergency, + bool aIsConference) +{ + MOZ_CRASH("Not a EnumerateCalls request!"); +} + +NS_IMETHODIMP +TelephonyIPCProvider::NotifyCdmaCallWaiting(const nsAString& aNumber) +{ + for (uint32_t i = 0; i < mListeners.Length(); i++) { + mListeners[i]->NotifyCdmaCallWaiting(aNumber); + } + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::NotifyError(int32_t aCallIndex, + const nsAString& aError) +{ + for (uint32_t i = 0; i < mListeners.Length(); i++) { + mListeners[i]->NotifyError(aCallIndex, aError); + } + return NS_OK; +} + +NS_IMETHODIMP +TelephonyIPCProvider::SupplementaryServiceNotification(int32_t aCallIndex, + uint16_t aNotification) +{ + for (uint32_t i = 0; i < mListeners.Length(); i++) { + mListeners[i]->SupplementaryServiceNotification(aCallIndex, aNotification); + } + return NS_OK; +} diff --git a/dom/telephony/ipc/TelephonyIPCProvider.h b/dom/telephony/ipc/TelephonyIPCProvider.h new file mode 100644 index 000000000000..928fd1d6567c --- /dev/null +++ b/dom/telephony/ipc/TelephonyIPCProvider.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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_telephony_TelephonyIPCProvider_h +#define mozilla_dom_telephony_TelephonyIPCProvider_h + +#include "mozilla/dom/telephony/TelephonyCommon.h" +#include "mozilla/Attributes.h" +#include "nsITelephonyProvider.h" + +BEGIN_TELEPHONY_NAMESPACE + +class PTelephonyChild; + +class TelephonyIPCProvider MOZ_FINAL : public nsITelephonyProvider + , public nsITelephonyListener +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSITELEPHONYPROVIDER + NS_DECL_NSITELEPHONYLISTENER + + TelephonyIPCProvider(); + +protected: + virtual ~TelephonyIPCProvider(); + +private: + nsTArray > mListeners; + PTelephonyChild* mPTelephonyChild; +}; + +END_TELEPHONY_NAMESPACE + +#endif // mozilla_dom_telephony_TelephonyIPCProvider_h diff --git a/dom/telephony/ipc/TelephonyParent.cpp b/dom/telephony/ipc/TelephonyParent.cpp new file mode 100644 index 000000000000..c55a90b8553d --- /dev/null +++ b/dom/telephony/ipc/TelephonyParent.cpp @@ -0,0 +1,448 @@ +/* -*- Mode: C++ tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/telephony/TelephonyParent.h" + +USING_TELEPHONY_NAMESPACE + +/******************************************************************************* + * TelephonyParent + ******************************************************************************/ + +NS_IMPL_ISUPPORTS1(TelephonyParent, nsITelephonyListener) + +TelephonyParent::TelephonyParent() + : mActorDestroyed(false) + , mRegistered(false) +{ +} + +void +TelephonyParent::ActorDestroy(ActorDestroyReason why) +{ + // The child process could die before this asynchronous notification, in which + // case ActorDestroy() was called and mActorDestroyed is set to true. Return + // an error here to avoid sending a message to the dead process. + mActorDestroyed = true; + + // Try to unregister listener if we're still registered. + RecvUnregisterListener(); +} + +bool +TelephonyParent::RecvPTelephonyRequestConstructor(PTelephonyRequestParent* aActor) +{ + TelephonyRequestParent* actor = static_cast(aActor); + + return actor->DoRequest(); +} + +PTelephonyRequestParent* +TelephonyParent::AllocPTelephonyRequestParent() +{ + TelephonyRequestParent* actor = new TelephonyRequestParent(); + // Add an extra ref for IPDL. Will be released in + // TelephonyParent::DeallocPTelephonyRequestParent(). + NS_ADDREF(actor); + + return actor; +} + +bool +TelephonyParent::DeallocPTelephonyRequestParent(PTelephonyRequestParent* aActor) +{ + // TelephonyRequestParent is refcounted, must not be freed manually. + static_cast(aActor)->Release(); + return true; +} + +bool +TelephonyParent::Recv__delete__() +{ + return true; // Unregister listener in TelephonyParent::ActorDestroy(). +} + +bool +TelephonyParent::RecvRegisterListener() +{ + NS_ENSURE_TRUE(!mRegistered, true); + + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + mRegistered = NS_SUCCEEDED(provider->RegisterListener(this)); + return true; +} + +bool +TelephonyParent::RecvUnregisterListener() +{ + NS_ENSURE_TRUE(mRegistered, true); + + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + mRegistered = !NS_SUCCEEDED(provider->UnregisterListener(this)); + return true; +} + +bool +TelephonyParent::RecvDialCall(const nsString& aNumber, + const bool& aIsEmergency) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->Dial(aNumber, aIsEmergency); + return true; +} + +bool +TelephonyParent::RecvHangUpCall(const uint32_t& aCallIndex) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->HangUp(aCallIndex); + return true; +} + +bool +TelephonyParent::RecvAnswerCall(const uint32_t& aCallIndex) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->AnswerCall(aCallIndex); + return true; +} + +bool +TelephonyParent::RecvRejectCall(const uint32_t& aCallIndex) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->RejectCall(aCallIndex); + return true; +} + +bool +TelephonyParent::RecvHoldCall(const uint32_t& aCallIndex) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->HoldCall(aCallIndex); + return true; +} + +bool +TelephonyParent::RecvResumeCall(const uint32_t& aCallIndex) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->ResumeCall(aCallIndex); + return true; +} + +bool +TelephonyParent::RecvConferenceCall() +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->ConferenceCall(); + return true; +} + +bool +TelephonyParent::RecvSeparateCall(const uint32_t& aCallState) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->SeparateCall(aCallState); + return true; +} + +bool +TelephonyParent::RecvHoldConference() +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->HoldConference(); + return true; +} + +bool +TelephonyParent::RecvResumeConference() +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->ResumeConference(); + return true; +} + +bool +TelephonyParent::RecvStartTone(const nsString& aTone) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->StartTone(aTone); + return true; +} + +bool +TelephonyParent::RecvStopTone() +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->StopTone(); + return true; +} + +bool +TelephonyParent::RecvGetMicrophoneMuted(bool* aMuted) +{ + *aMuted = false; + + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->GetMicrophoneMuted(aMuted); + return true; +} + +bool +TelephonyParent::RecvSetMicrophoneMuted(const bool& aMuted) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->SetMicrophoneMuted(aMuted); + return true; +} + +bool +TelephonyParent::RecvGetSpeakerEnabled(bool* aEnabled) +{ + *aEnabled = false; + + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->GetSpeakerEnabled(aEnabled); + return true; +} + +bool +TelephonyParent::RecvSetSpeakerEnabled(const bool& aEnabled) +{ + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + NS_ENSURE_TRUE(provider, true); + + provider->SetSpeakerEnabled(aEnabled); + return true; +} + +// nsITelephonyListener + +NS_IMETHODIMP +TelephonyParent::CallStateChanged(uint32_t aCallIndex, + uint16_t aCallState, + const nsAString& aNumber, + bool aIsActive, + bool aIsOutgoing, + bool aIsEmergency, + bool aIsConference) +{ + NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE); + + IPCCallStateData data(aCallIndex, aCallState, nsString(aNumber), aIsActive, + aIsOutgoing, aIsEmergency, aIsConference); + return SendNotifyCallStateChanged(data) ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +TelephonyParent::ConferenceCallStateChanged(uint16_t aCallState) +{ + NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE); + + return SendNotifyConferenceCallStateChanged(aCallState) ? NS_OK + : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +TelephonyParent::EnumerateCallStateComplete() +{ + MOZ_CRASH("Not a EnumerateCalls request!"); +} + +NS_IMETHODIMP +TelephonyParent::EnumerateCallState(uint32_t aCallIndex, + uint16_t aCallState, + const nsAString& aNumber, + bool aIsActive, + bool aIsOutgoing, + bool aIsEmergency, + bool aIsConference) +{ + MOZ_CRASH("Not a EnumerateCalls request!"); +} + +NS_IMETHODIMP +TelephonyParent::NotifyCdmaCallWaiting(const nsAString& aNumber) +{ + NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE); + + return SendNotifyCdmaCallWaiting(nsString(aNumber)) ? NS_OK + : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +TelephonyParent::NotifyError(int32_t aCallIndex, + const nsAString& aError) +{ + NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE); + + return SendNotifyCallError(aCallIndex, nsString(aError)) ? NS_OK + : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +TelephonyParent::SupplementaryServiceNotification(int32_t aCallIndex, + uint16_t aNotification) +{ + NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE); + + return SendNotifySupplementaryService(aCallIndex, aNotification) + ? NS_OK : NS_ERROR_FAILURE; +} + +/******************************************************************************* + * TelephonyRequestParent + ******************************************************************************/ + +NS_IMPL_ISUPPORTS1(TelephonyRequestParent, nsITelephonyListener) + +TelephonyRequestParent::TelephonyRequestParent() + : mActorDestroyed(false) +{ +} + +void +TelephonyRequestParent::ActorDestroy(ActorDestroyReason why) +{ + // The child process could die before this asynchronous notification, in which + // case ActorDestroy() was called and mActorDestroyed is set to true. Return + // an error here to avoid sending a message to the dead process. + mActorDestroyed = true; +} + +bool +TelephonyRequestParent::DoRequest() +{ + nsresult rv = NS_ERROR_FAILURE; + + nsCOMPtr provider = + do_GetService(TELEPHONY_PROVIDER_CONTRACTID); + if (provider) { + rv = provider->EnumerateCalls(this); + } + + if (NS_FAILED(rv)) { + return NS_SUCCEEDED(EnumerateCallStateComplete()); + } + + return true; +} + +// nsITelephonyListener + +NS_IMETHODIMP +TelephonyRequestParent::CallStateChanged(uint32_t aCallIndex, + uint16_t aCallState, + const nsAString& aNumber, + bool aIsActive, + bool aIsOutgoing, + bool aIsEmergency, + bool aIsConference) +{ + MOZ_CRASH("Not a TelephonyParent!"); +} + +NS_IMETHODIMP +TelephonyRequestParent::ConferenceCallStateChanged(uint16_t aCallState) +{ + MOZ_CRASH("Not a TelephonyParent!"); +} + +NS_IMETHODIMP +TelephonyRequestParent::EnumerateCallStateComplete() +{ + NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE); + + return Send__delete__(this) ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +TelephonyRequestParent::EnumerateCallState(uint32_t aCallIndex, + uint16_t aCallState, + const nsAString& aNumber, + bool aIsActive, + bool aIsOutgoing, + bool aIsEmergency, + bool aIsConference) +{ + NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE); + + IPCCallStateData data(aCallIndex, aCallState, nsString(aNumber), aIsActive, + aIsOutgoing, aIsEmergency, aIsConference); + return SendNotifyEnumerateCallState(data) ? NS_OK : NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +TelephonyRequestParent::NotifyCdmaCallWaiting(const nsAString& aNumber) +{ + MOZ_CRASH("Not a TelephonyParent!"); +} + +NS_IMETHODIMP +TelephonyRequestParent::NotifyError(int32_t aCallIndex, + const nsAString& aError) +{ + MOZ_CRASH("Not a TelephonyParent!"); +} + +NS_IMETHODIMP +TelephonyRequestParent::SupplementaryServiceNotification(int32_t aCallIndex, + uint16_t aNotification) +{ + MOZ_CRASH("Not a TelephonyParent!"); +} diff --git a/dom/telephony/ipc/TelephonyParent.h b/dom/telephony/ipc/TelephonyParent.h new file mode 100644 index 000000000000..ac508c264bea --- /dev/null +++ b/dom/telephony/ipc/TelephonyParent.h @@ -0,0 +1,128 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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_telephony_TelephonyParent_h +#define mozilla_dom_telephony_TelephonyParent_h + +#include "mozilla/dom/telephony/TelephonyCommon.h" +#include "mozilla/dom/telephony/PTelephonyParent.h" +#include "mozilla/dom/telephony/PTelephonyRequestParent.h" +#include "nsITelephonyProvider.h" + +BEGIN_TELEPHONY_NAMESPACE + +class TelephonyParent : public PTelephonyParent + , public nsITelephonyListener +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSITELEPHONYLISTENER + + TelephonyParent(); + +protected: + virtual ~TelephonyParent() {} + + virtual void + ActorDestroy(ActorDestroyReason why); + + virtual bool + RecvPTelephonyRequestConstructor(PTelephonyRequestParent* aActor) MOZ_OVERRIDE; + + virtual PTelephonyRequestParent* + AllocPTelephonyRequestParent() MOZ_OVERRIDE; + + virtual bool + DeallocPTelephonyRequestParent(PTelephonyRequestParent* aActor) MOZ_OVERRIDE; + + virtual bool + Recv__delete__() MOZ_OVERRIDE; + + virtual bool + RecvRegisterListener() MOZ_OVERRIDE; + + virtual bool + RecvUnregisterListener() MOZ_OVERRIDE; + + virtual bool + RecvDialCall(const nsString& aNumber, + const bool& aIsEmergency) MOZ_OVERRIDE; + + virtual bool + RecvHangUpCall(const uint32_t& aCallIndex) MOZ_OVERRIDE; + + virtual bool + RecvAnswerCall(const uint32_t& aCallIndex) MOZ_OVERRIDE; + + virtual bool + RecvRejectCall(const uint32_t& aCallIndex) MOZ_OVERRIDE; + + virtual bool + RecvHoldCall(const uint32_t& aCallIndex) MOZ_OVERRIDE; + + virtual bool + RecvResumeCall(const uint32_t& aCallIndex) MOZ_OVERRIDE; + + virtual bool + RecvConferenceCall() MOZ_OVERRIDE; + + virtual bool + RecvSeparateCall(const uint32_t& callIndex) MOZ_OVERRIDE; + + virtual bool + RecvHoldConference() MOZ_OVERRIDE; + + virtual bool + RecvResumeConference() MOZ_OVERRIDE; + + virtual bool + RecvStartTone(const nsString& aTone) MOZ_OVERRIDE; + + virtual bool + RecvStopTone() MOZ_OVERRIDE; + + virtual bool + RecvGetMicrophoneMuted(bool* aMuted) MOZ_OVERRIDE; + + virtual bool + RecvSetMicrophoneMuted(const bool& aMuted) MOZ_OVERRIDE; + + virtual bool + RecvGetSpeakerEnabled(bool* aEnabled) MOZ_OVERRIDE; + + virtual bool + RecvSetSpeakerEnabled(const bool& aEnabled) MOZ_OVERRIDE; + +private: + bool mActorDestroyed; + bool mRegistered; +}; + +class TelephonyRequestParent : public PTelephonyRequestParent + , public nsITelephonyListener +{ + friend class TelephonyParent; + +public: + NS_DECL_ISUPPORTS + NS_DECL_NSITELEPHONYLISTENER + +protected: + TelephonyRequestParent(); + virtual ~TelephonyRequestParent() {} + + virtual void + ActorDestroy(ActorDestroyReason why); + +private: + bool mActorDestroyed; + + bool + DoRequest(); +}; + +END_TELEPHONY_NAMESPACE + +#endif /* mozilla_dom_telephony_TelephonyParent_h */ diff --git a/dom/telephony/moz.build b/dom/telephony/moz.build index 8910a24c887f..b142cec41883 100644 --- a/dom/telephony/moz.build +++ b/dom/telephony/moz.build @@ -12,12 +12,34 @@ XPIDL_MODULE = 'dom_telephony' MODULE = 'dom' +EXPORTS.mozilla.dom.telephony += [ + 'CallEvent.h', + 'CallsList.h', + 'Telephony.h', + 'TelephonyCall.h', + 'TelephonyCallGroup.h', + 'TelephonyCommon.h', + 'TelephonyFactory.h', + 'ipc/TelephonyChild.h', + 'ipc/TelephonyParent.h', +] + CPP_SOURCES += [ 'CallEvent.cpp', 'CallsList.cpp', 'Telephony.cpp', 'TelephonyCall.cpp', 'TelephonyCallGroup.cpp', + 'TelephonyFactory.cpp', + 'ipc/TelephonyChild.cpp', + 'ipc/TelephonyIPCProvider.cpp', + 'ipc/TelephonyParent.cpp', +] + +IPDL_SOURCES += [ + 'ipc/PTelephony.ipdl', + 'ipc/PTelephonyRequest.ipdl', + 'ipc/TelephonyTypes.ipdlh' ] FAIL_ON_WARNINGS = True @@ -25,4 +47,3 @@ FAIL_ON_WARNINGS = True LIBXUL_LIBRARY = True LIBRARY_NAME = 'domtelephony_s' - diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index eaeda570150b..ca570fa076be 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -102,7 +102,7 @@ var interfaceNamesInGlobalScope = {name: "BluetoothStatusChangedEvent", b2g: true}, {name: "BoxObject", xbl: true}, {name: "BrowserFeedWriter", desktop: true}, - {name: "CallEvent", b2g: true}, + "CallEvent", "CameraCapabilities", "CameraControl", "CameraManager", @@ -531,9 +531,9 @@ var interfaceNamesInGlobalScope = "SVGViewElement", "SVGZoomAndPan", "SVGZoomEvent", - {name: "Telephony", b2g: true}, - {name: "TelephonyCall", b2g: true}, - {name: "TelephonyCallGroup", b2g: true}, + "Telephony", + "TelephonyCall", + "TelephonyCallGroup", "Text", "TextDecoder", "TextEncoder", diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index f18ce2bddd4b..b5d7dafa9360 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -34,6 +34,8 @@ webidl_files = \ BiquadFilterNode.webidl \ Blob.webidl \ BrowserElementDictionaries.webidl \ + CallEvent.webidl \ + CallsList.webidl \ CameraControl.webidl \ CameraManager.webidl \ CanvasRenderingContext2D.webidl \ @@ -359,6 +361,9 @@ webidl_files = \ SVGViewElement.webidl \ SVGZoomAndPan.webidl \ SVGZoomEvent.webidl \ + Telephony.webidl \ + TelephonyCall.webidl \ + TelephonyCallGroup.webidl \ Text.webidl \ TextDecoder.webidl \ TextEncoder.webidl \ @@ -445,12 +450,8 @@ endif ifdef MOZ_B2G_RIL webidl_files += \ - CallsList.webidl \ MozStkCommandEvent.webidl \ MozVoicemail.webidl \ - Telephony.webidl \ - TelephonyCall.webidl \ - TelephonyCallGroup.webidl \ $(NULL) endif @@ -495,7 +496,6 @@ endif ifdef MOZ_B2G_RIL webidl_files += \ - CallEvent.webidl \ CFStateChangeEvent.webidl \ DataErrorEvent.webidl \ IccCardLockErrorEvent.webidl \ diff --git a/layout/build/Makefile.in b/layout/build/Makefile.in index 6cfafbacf958..51b8f933f90d 100644 --- a/layout/build/Makefile.in +++ b/layout/build/Makefile.in @@ -59,6 +59,7 @@ SHARED_LIBRARY_LIBS = \ $(DEPTH)/dom/promise/$(LIB_PREFIX)dompromise_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/src/notification/$(LIB_PREFIX)jsdomnotification_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/system/$(LIB_PREFIX)domsystem_s.$(LIB_SUFFIX) \ + $(DEPTH)/dom/telephony/$(LIB_PREFIX)domtelephony_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/workers/$(LIB_PREFIX)domworkers_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/indexedDB/$(LIB_PREFIX)dom_indexeddb_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/indexedDB/ipc/$(LIB_PREFIX)dom_indexeddb_ipc_s.$(LIB_SUFFIX) \ @@ -129,7 +130,6 @@ SHARED_LIBRARY_LIBS += $(DEPTH)/dom/camera/$(LIB_PREFIX)domcamera_s.$(LIB_SUFFIX ifdef MOZ_B2G_RIL #{ SHARED_LIBRARY_LIBS += \ $(DEPTH)/dom/system/gonk/$(LIB_PREFIX)domsystemgonk_s.$(LIB_SUFFIX) \ - $(DEPTH)/dom/telephony/$(LIB_PREFIX)domtelephony_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/icc/src/$(LIB_PREFIX)dom_icc_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/cellbroadcast/src/$(LIB_PREFIX)dom_cellbroadcast_s.$(LIB_SUFFIX) \ $(DEPTH)/dom/voicemail/$(LIB_PREFIX)domvoicemail_s.$(LIB_SUFFIX) \ diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 1d55dd374466..6278d4b8352c 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -230,6 +230,9 @@ static void Shutdown(); #include "mozilla/dom/alarm/AlarmHalService.h" #include "mozilla/dom/time/TimeService.h" +#include "mozilla/dom/telephony/TelephonyFactory.h" +#include "nsITelephonyProvider.h" + #ifdef MOZ_WIDGET_GONK #include "GonkGPSGeolocationProvider.h" #endif @@ -238,6 +241,7 @@ static void Shutdown(); using namespace mozilla; using namespace mozilla::dom; using namespace mozilla::dom::mobilemessage; +using namespace mozilla::dom::telephony; using mozilla::dom::alarm::AlarmHalService; using mozilla::dom::indexedDB::IndexedDatabaseManager; using mozilla::dom::power::PowerManagerService; @@ -338,6 +342,8 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsVolumeService, #endif NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIMediaManagerService, MediaManager::GetInstance) +NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelephonyProvider, + TelephonyFactory::CreateTelephonyProvider) //----------------------------------------------------------------------------- @@ -811,6 +817,7 @@ NS_DEFINE_NAMED_CID(NS_SYNTHVOICEREGISTRY_CID); #ifdef ACCESSIBILITY NS_DEFINE_NAMED_CID(NS_ACCESSIBILITY_SERVICE_CID); #endif +NS_DEFINE_NAMED_CID(TELEPHONY_PROVIDER_CID); static nsresult CreateWindowCommandTableConstructor(nsISupports *aOuter, @@ -1093,6 +1100,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { #ifdef ACCESSIBILITY { &kNS_ACCESSIBILITY_SERVICE_CID, false, NULL, CreateA11yService }, #endif + { &kTELEPHONY_PROVIDER_CID, false, NULL, nsITelephonyProviderConstructor }, { NULL } }; @@ -1248,6 +1256,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { "@mozilla.org/accessibilityService;1", &kNS_ACCESSIBILITY_SERVICE_CID }, { "@mozilla.org/accessibleRetrieval;1", &kNS_ACCESSIBILITY_SERVICE_CID }, #endif + { TELEPHONY_PROVIDER_CONTRACTID, &kTELEPHONY_PROVIDER_CID }, { NULL } };