Files
palemoon27/dom/telephony/ipc/TelephonyParent.cpp
T
roytam1 444160f7b2 import changes from `dev' branch of rmottola/Arctic-Fox:
- align permissions to gecko (2b5293932d)
- Bug 1214759 - backport SkDashPathEffect::asPoints fix from upstream Skia. r=jmuizelaar (4f58a0ef9a)
- Bug 1216020 - Comment all ALLOW_COMPILER_WARNINGS lines. r=glandium. (30a485d631)
- bug 1174747 - Fix sqlite3 build on iOS. r=glandium (ad59695677)
- Bug 1229615 - Conditionalize mp4parse.h export. r=kinetik (f7e95a1afa)
- Bug 1211741 - Remove libstagefright ID3 files. r=k17e (016da13fed)
- Bug 1202266 - Suppress '-Wformat-security' in libstagefright CXXFLAGS. r=kentuckyfriedtakahe Bug 1143336 - Fix and suppress -Wunreachable-code-return warnings in media code. r=cajbir (f8f58de405)
- Bug 1225923 - part 1 - convert all needs-to-copy instances of AppendElement(nsDependentString(...)); r=erahm (e061f9cb53)
- Bug 1225923 - part 2 - fix AppendElement(nsDependentString(...)) call in HTMLInputElement.cpp; r=baku (69d4b4c288)
- Bug 1179089 - Let TelephonyRequestParent hold the callback objects. r=hsinyi (05a6d68415)
- Bug 1225923 - part 3 - fix AppendElement(nsDependentString(...)) calls in dom/telephony/; r=btseng (31cb1e8cb0)
- Bug 1225923 - part 4 - fix AppendElement(nsDependentCString(...)) call in nsClipboardProxy.cpp; r=roc (978e7bfe19)
- Bug 1225923 - part 5 - fix AppendElement(nsDependentAtomString(...)) calls; r=bz (82c93922bb)
- fix (761e252105)
- Bug 1187114 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xul/ with iterators. r=mccr8. (12b2947f5b)
- Bug 1187114 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xul/ with iterators. r=mccr8. (db1ad0cd0f)
- Bug 1187114 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xul/ with iterators. r=mccr8. (0b46fdbb38)
- Bug 1137009 - Do not persist xul window attributes when in fullscreen. r=enndeakin (6bef2373dc)
- Bug 1206958 - Use channel->asyncOpen2() in dom/xul/XULDocument.cpp (r=sicking) (21b1a90678)
- Bug 1216945 - Uninitialised value use in nsXULWindow::SizeShellTo. r=bzbarsky. (989ce9ff88)
- Bug 1189132 - Skip unmap during window destruction on GTK, working around talos hang with GL layers. r=karlt (34f29cb72b)
- Bug 1206964 - Use channel->AsyncOpen2() in netwerk/base/nsNetUtil.cpp (r=sicking) (fbb5158a68)
- Bug 1225682 - Don't use nsAuto{,C}String as class member variables in xpfe/. r=neil (bd453fc5f5)
- Bug 1221992 - Prevent ServiceWorkerClients.OpenWindow from opening tabs in private mode windows. r=smaug (f7da0cf34c)
- Bug 1034922 - Make nsSiteWindow's destructor private, and expose it to nsContentTreeOwner via friend class. r=Enn (87d8dfa052)
- Bug 1214174 - Windowless WebBrowserChrome2Stub should implement nsIEmbeddingSiteWindow GetDimensions. r=billm (4f4b44532d)
- Bug 1214174 - Add windowless browser test case. r=billm (2ece018afd)
- Bug 1160770 - Unnecessary return in tabScrolling property in XPFE autocomplete.xml NPOTB r=Neil DONTBUILD (7fe5f13994)
- Bug 1192943 - Use channel->asycnOpen2 in xpfe/components/directory/nsDirectoryViewer.cpp (r=sicking) (79c2f93134)
- Bug 1186790 - Replace nsBaseHashtable::EnumerateRead() calls in xpfe/with iterators. r=neil. (ee73ea015d)
- Bug 1232450 - use UniquePtr<T[]> instead of nsAutoArrayPtr<T> in xulrunner/; r=Yoric (ffa7a84864)
- Bug 1174011, fix xulrunner-stub compile, r=gladium DONTBUILD (bb9381a707)
- Bug 1216723 - Add a new -forbid- Safe Browsing list type. r=gcp,r=smaug (9f164a56d8)
- cleanup, do not run PP (0d7c0cd4c0)
- Bug 1204338 Followup to Bug 403800 Refactor netError.dtd/netErrorApp.dtd to simplify per-application overrides r=Pike (5e1bbcb45c)
- Bug 1154347 - Don't set -fomit-frame-pointer on all of skia. r=glandium, r=gw280 (af8db2b7b9)
- Bug 1136958 - Remove duplicate SkDiscardableMemory_none.cpp from gfx/skia/moz.build. r=gps (9bbebeecc4)
- bits of  Bug 1188462 - Rename gfx/skia/trun (d839e73b23)
- Bug 1215899 - Suppress clang and gcc warnings in gfx/skia. r=gw280 (e7859525d0)
- Bug 1222166 - use gcc/clang warning flags for clang-cl in moz.build files; r=glandium (b885ca1dff)
- Bug 1082598 - Part 1: Update Skia to master revision 53c5d5fb795fe04bec050c0583223027c25b839b. r=jrmuizel (4baf696313)
- Bug 1082598 - Part 2: Fix Moz2D Skia usage for Skia update. r=jrmuizel (d6192e1b0d)
- Bug 1082598 - Part 3: Fix thebes gfxPlatform shutdown for Skia. r=jrmuizel (ecaf498adf)
- Bug 1082598 - Part 6: Fix layers for Skia update. r=jrmuizel (e80b4e204c)
- Bug 1082598 - Part 7: Update moz.build for Skia update. r=jrmuizel (121c4c6e21)
- Bug 1082598 - Part 8: Fix OpenGL interface glue for Skia update. r=jrmuizel (327cebb260)
- Bug 1082598 - Part 9: Fix test failures for Skia update. r=jrmuizel (1d0a6a6a9a)
- missing bit of Bug 1082598 - Part 1: Update Skia (559cb5a38a)
- cleanup strange misspatch (5d759aadaf)
2023-06-14 15:12:12 +08:00

524 lines
17 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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"
#include "nsServiceManagerUtils.h"
USING_TELEPHONY_NAMESPACE
/*******************************************************************************
* TelephonyParent
******************************************************************************/
NS_IMPL_ISUPPORTS(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,
const IPCTelephonyRequest& aRequest)
{
TelephonyRequestParent* actor = static_cast<TelephonyRequestParent*>(aActor);
nsCOMPtr<nsITelephonyService> service = do_GetService(TELEPHONY_SERVICE_CONTRACTID);
if (!service) {
return NS_SUCCEEDED(actor->GetCallback()->NotifyError(NS_LITERAL_STRING("InvalidStateError")));
}
switch (aRequest.type()) {
case IPCTelephonyRequest::TEnumerateCallsRequest: {
nsresult rv = service->EnumerateCalls(actor);
if (NS_FAILED(rv)) {
return NS_SUCCEEDED(EnumerateCallStateComplete());
} else {
return true;
}
}
case IPCTelephonyRequest::TDialRequest: {
const DialRequest& request = aRequest.get_DialRequest();
service->Dial(request.clientId(), request.number(),
request.isEmergency(), actor->GetDialCallback());
return true;
}
case IPCTelephonyRequest::TSendUSSDRequest: {
const SendUSSDRequest& request = aRequest.get_SendUSSDRequest();
service->SendUSSD(request.clientId(), request.ussd(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TCancelUSSDRequest: {
const CancelUSSDRequest& request = aRequest.get_CancelUSSDRequest();
service->CancelUSSD(request.clientId(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TConferenceCallRequest: {
const ConferenceCallRequest& request = aRequest.get_ConferenceCallRequest();
service->ConferenceCall(request.clientId(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TSeparateCallRequest: {
const SeparateCallRequest& request = aRequest.get_SeparateCallRequest();
service->SeparateCall(request.clientId(), request.callIndex(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::THangUpConferenceRequest: {
const HangUpConferenceRequest& request = aRequest.get_HangUpConferenceRequest();
service->HangUpConference(request.clientId(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::THoldConferenceRequest: {
const HoldConferenceRequest& request = aRequest.get_HoldConferenceRequest();
service->HoldConference(request.clientId(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TResumeConferenceRequest: {
const ResumeConferenceRequest& request = aRequest.get_ResumeConferenceRequest();
service->ResumeConference(request.clientId(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TAnswerCallRequest: {
const AnswerCallRequest& request = aRequest.get_AnswerCallRequest();
service->AnswerCall(request.clientId(), request.callIndex(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::THangUpCallRequest: {
const HangUpCallRequest& request = aRequest.get_HangUpCallRequest();
service->HangUpCall(request.clientId(), request.callIndex(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TRejectCallRequest: {
const RejectCallRequest& request = aRequest.get_RejectCallRequest();
service->RejectCall(request.clientId(), request.callIndex(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::THoldCallRequest: {
const HoldCallRequest& request = aRequest.get_HoldCallRequest();
service->HoldCall(request.clientId(), request.callIndex(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TResumeCallRequest: {
const ResumeCallRequest& request = aRequest.get_ResumeCallRequest();
service->ResumeCall(request.clientId(), request.callIndex(), actor->GetCallback());
return true;
}
case IPCTelephonyRequest::TSendTonesRequest: {
const SendTonesRequest& request = aRequest.get_SendTonesRequest();
service->SendTones(request.clientId(),
request.dtmfChars(),
request.pauseDuration(),
request.toneDuration(),
actor->GetCallback());
return true;
}
default:
MOZ_CRASH("Unknown type!");
}
return false;
}
PTelephonyRequestParent*
TelephonyParent::AllocPTelephonyRequestParent(const IPCTelephonyRequest& aRequest)
{
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<TelephonyRequestParent*>(aActor)->Release();
return true;
}
bool
TelephonyParent::Recv__delete__()
{
return true; // Unregister listener in TelephonyParent::ActorDestroy().
}
bool
TelephonyParent::RecvRegisterListener()
{
NS_ENSURE_TRUE(!mRegistered, true);
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
mRegistered = NS_SUCCEEDED(service->RegisterListener(this));
return true;
}
bool
TelephonyParent::RecvUnregisterListener()
{
NS_ENSURE_TRUE(mRegistered, true);
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
mRegistered = !NS_SUCCEEDED(service->UnregisterListener(this));
return true;
}
bool
TelephonyParent::RecvStartTone(const uint32_t& aClientId, const nsString& aTone)
{
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
service->StartTone(aClientId, aTone);
return true;
}
bool
TelephonyParent::RecvStopTone(const uint32_t& aClientId)
{
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
service->StopTone(aClientId);
return true;
}
bool
TelephonyParent::RecvGetMicrophoneMuted(bool* aMuted)
{
*aMuted = false;
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
service->GetMicrophoneMuted(aMuted);
return true;
}
bool
TelephonyParent::RecvSetMicrophoneMuted(const bool& aMuted)
{
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
service->SetMicrophoneMuted(aMuted);
return true;
}
bool
TelephonyParent::RecvGetSpeakerEnabled(bool* aEnabled)
{
*aEnabled = false;
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
service->GetSpeakerEnabled(aEnabled);
return true;
}
bool
TelephonyParent::RecvSetSpeakerEnabled(const bool& aEnabled)
{
nsCOMPtr<nsITelephonyService> service =
do_GetService(TELEPHONY_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(service, true);
service->SetSpeakerEnabled(aEnabled);
return true;
}
// nsITelephonyListener
NS_IMETHODIMP
TelephonyParent::CallStateChanged(uint32_t aLength, nsITelephonyCallInfo** aAllInfo)
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
nsTArray<nsITelephonyCallInfo*> allInfo;
for (uint32_t i = 0; i < aLength; i++) {
allInfo.AppendElement(aAllInfo[i]);
}
return SendNotifyCallStateChanged(allInfo) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TelephonyParent::EnumerateCallStateComplete()
{
MOZ_CRASH("Not a EnumerateCalls request!");
}
NS_IMETHODIMP
TelephonyParent::EnumerateCallState(nsITelephonyCallInfo* aInfo)
{
MOZ_CRASH("Not a EnumerateCalls request!");
}
NS_IMETHODIMP
TelephonyParent::NotifyCdmaCallWaiting(uint32_t aClientId,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation)
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
IPCCdmaWaitingCallData data(nsString(aNumber), aNumberPresentation,
nsString(aName), aNamePresentation);
return SendNotifyCdmaCallWaiting(aClientId, data) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TelephonyParent::NotifyConferenceError(const nsAString& aName,
const nsAString& aMessage)
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
return SendNotifyConferenceError(nsString(aName), nsString(aMessage)) ? NS_OK
: NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TelephonyParent::SupplementaryServiceNotification(uint32_t aClientId,
int32_t aCallIndex,
uint16_t aNotification)
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
return SendNotifySupplementaryService(aClientId, aCallIndex, aNotification)
? NS_OK : NS_ERROR_FAILURE;
}
/*******************************************************************************
* TelephonyRequestParent
******************************************************************************/
NS_IMPL_ISUPPORTS(TelephonyRequestParent,
nsITelephonyListener)
TelephonyRequestParent::TelephonyRequestParent()
: mActorDestroyed(false),
mCallback(new Callback(*this)),
mDialCallback(new DialCallback(*this))
{
}
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;
}
nsresult
TelephonyRequestParent::SendResponse(const IPCTelephonyResponse& aResponse)
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
return Send__delete__(this, aResponse) ? NS_OK : NS_ERROR_FAILURE;
}
// nsITelephonyListener
NS_IMETHODIMP
TelephonyRequestParent::CallStateChanged(uint32_t aLength, nsITelephonyCallInfo** aAllInfo)
{
MOZ_CRASH("Not a TelephonyParent!");
}
NS_IMETHODIMP
TelephonyRequestParent::EnumerateCallStateComplete()
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
return Send__delete__(this, EnumerateCallsResponse()) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TelephonyRequestParent::EnumerateCallState(nsITelephonyCallInfo* aInfo)
{
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
return SendNotifyEnumerateCallState(aInfo) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TelephonyRequestParent::NotifyCdmaCallWaiting(uint32_t aClientId,
const nsAString& aNumber,
uint16_t aNumberPresentation,
const nsAString& aName,
uint16_t aNamePresentation)
{
MOZ_CRASH("Not a TelephonyParent!");
}
NS_IMETHODIMP
TelephonyRequestParent::NotifyConferenceError(const nsAString& aName,
const nsAString& aMessage)
{
MOZ_CRASH("Not a TelephonyParent!");
}
NS_IMETHODIMP
TelephonyRequestParent::SupplementaryServiceNotification(uint32_t aClientId,
int32_t aCallIndex,
uint16_t aNotification)
{
MOZ_CRASH("Not a TelephonyParent!");
}
/*******************************************************************************
* TelephonyRequestParent::Callback
******************************************************************************/
NS_IMPL_ISUPPORTS(TelephonyRequestParent::Callback,
nsITelephonyCallback)
nsresult TelephonyRequestParent::Callback::SendResponse(const IPCTelephonyResponse& aResponse)
{
return mParent.SendResponse(aResponse);
}
NS_IMETHODIMP
TelephonyRequestParent::Callback::NotifySuccess()
{
return SendResponse(SuccessResponse());
}
NS_IMETHODIMP
TelephonyRequestParent::Callback::NotifyError(const nsAString& aError)
{
return SendResponse(ErrorResponse(nsAutoString(aError)));
}
/*******************************************************************************
* TelephonyRequestParent::DialCallback
******************************************************************************/
NS_IMPL_ISUPPORTS_INHERITED(TelephonyRequestParent::DialCallback,
TelephonyRequestParent::Callback,
nsITelephonyDialCallback)
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMI(const nsAString& aServiceCode)
{
NS_ENSURE_TRUE(!mParent.mActorDestroyed, NS_ERROR_FAILURE);
return mParent.SendNotifyDialMMI(nsAutoString(aServiceCode)) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialCallSuccess(uint32_t aClientId,
uint32_t aCallIndex,
const nsAString& aNumber)
{
return SendResponse(DialResponseCallSuccess(aClientId, aCallIndex,
nsAutoString(aNumber)));
}
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMISuccess(const nsAString& aStatusMessage)
{
return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
AdditionalInformation(mozilla::void_t())));
}
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithInteger(const nsAString& aStatusMessage,
uint16_t aAdditionalInformation)
{
return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
AdditionalInformation(aAdditionalInformation)));
}
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithStrings(const nsAString& aStatusMessage,
uint32_t aCount,
const char16_t** aAdditionalInformation)
{
nsTArray<nsString> additionalInformation;
nsString* infos = additionalInformation.AppendElements(aCount);
for (uint32_t i = 0; i < aCount; i++) {
infos[i].Rebind(aAdditionalInformation[i],
nsCharTraits<char16_t>::length(aAdditionalInformation[i]));
}
return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
AdditionalInformation(additionalInformation)));
}
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMISuccessWithCallForwardingOptions(const nsAString& aStatusMessage,
uint32_t aCount,
nsIMobileCallForwardingOptions** aAdditionalInformation)
{
nsTArray<nsIMobileCallForwardingOptions*> additionalInformation;
for (uint32_t i = 0; i < aCount; i++) {
additionalInformation.AppendElement(aAdditionalInformation[i]);
}
return SendResponse(DialResponseMMISuccess(nsAutoString(aStatusMessage),
AdditionalInformation(additionalInformation)));
}
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMIError(const nsAString& aError)
{
return SendResponse(DialResponseMMIError(nsAutoString(aError),
AdditionalInformation(mozilla::void_t())));
}
NS_IMETHODIMP
TelephonyRequestParent::DialCallback::NotifyDialMMIErrorWithInfo(const nsAString& aError,
uint16_t aInfo)
{
return SendResponse(DialResponseMMIError(nsAutoString(aError),
AdditionalInformation(aInfo)));
}