gecko/dom/mobilemessage/ipc/SmsChild.cpp
Birunthan Mohanathas 6d90091662 Bug 1058101 - Flatten dom/mobilemessage/src/ into parent directory. r=mccr8
--HG--
rename : dom/mobilemessage/src/Constants.cpp => dom/mobilemessage/Constants.cpp
rename : dom/mobilemessage/src/Constants.h => dom/mobilemessage/Constants.h
rename : dom/mobilemessage/src/DOMMobileMessageError.cpp => dom/mobilemessage/DOMMobileMessageError.cpp
rename : dom/mobilemessage/src/DOMMobileMessageError.h => dom/mobilemessage/DOMMobileMessageError.h
rename : dom/mobilemessage/src/DeletedMessageInfo.cpp => dom/mobilemessage/DeletedMessageInfo.cpp
rename : dom/mobilemessage/src/DeletedMessageInfo.h => dom/mobilemessage/DeletedMessageInfo.h
rename : dom/mobilemessage/src/MmsMessage.cpp => dom/mobilemessage/MmsMessage.cpp
rename : dom/mobilemessage/src/MmsMessage.h => dom/mobilemessage/MmsMessage.h
rename : dom/mobilemessage/src/MobileMessageCallback.cpp => dom/mobilemessage/MobileMessageCallback.cpp
rename : dom/mobilemessage/src/MobileMessageCallback.h => dom/mobilemessage/MobileMessageCallback.h
rename : dom/mobilemessage/src/MobileMessageCursorCallback.cpp => dom/mobilemessage/MobileMessageCursorCallback.cpp
rename : dom/mobilemessage/src/MobileMessageCursorCallback.h => dom/mobilemessage/MobileMessageCursorCallback.h
rename : dom/mobilemessage/src/MobileMessageManager.cpp => dom/mobilemessage/MobileMessageManager.cpp
rename : dom/mobilemessage/src/MobileMessageManager.h => dom/mobilemessage/MobileMessageManager.h
rename : dom/mobilemessage/src/MobileMessageService.cpp => dom/mobilemessage/MobileMessageService.cpp
rename : dom/mobilemessage/src/MobileMessageService.h => dom/mobilemessage/MobileMessageService.h
rename : dom/mobilemessage/src/MobileMessageThread.cpp => dom/mobilemessage/MobileMessageThread.cpp
rename : dom/mobilemessage/src/MobileMessageThread.h => dom/mobilemessage/MobileMessageThread.h
rename : dom/mobilemessage/src/SmsMessage.cpp => dom/mobilemessage/SmsMessage.cpp
rename : dom/mobilemessage/src/SmsMessage.h => dom/mobilemessage/SmsMessage.h
rename : dom/mobilemessage/src/SmsServicesFactory.cpp => dom/mobilemessage/SmsServicesFactory.cpp
rename : dom/mobilemessage/src/SmsServicesFactory.h => dom/mobilemessage/SmsServicesFactory.h
rename : dom/mobilemessage/src/Types.h => dom/mobilemessage/Types.h
rename : dom/mobilemessage/src/android/MobileMessageDatabaseService.cpp => dom/mobilemessage/android/MobileMessageDatabaseService.cpp
rename : dom/mobilemessage/src/android/MobileMessageDatabaseService.h => dom/mobilemessage/android/MobileMessageDatabaseService.h
rename : dom/mobilemessage/src/android/SmsService.cpp => dom/mobilemessage/android/SmsService.cpp
rename : dom/mobilemessage/src/android/SmsService.h => dom/mobilemessage/android/SmsService.h
rename : dom/mobilemessage/src/gonk/MmsPduHelper.jsm => dom/mobilemessage/gonk/MmsPduHelper.jsm
rename : dom/mobilemessage/src/gonk/MmsService.js => dom/mobilemessage/gonk/MmsService.js
rename : dom/mobilemessage/src/gonk/MmsService.manifest => dom/mobilemessage/gonk/MmsService.manifest
rename : dom/mobilemessage/src/gonk/MobileMessageDB.jsm => dom/mobilemessage/gonk/MobileMessageDB.jsm
rename : dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js => dom/mobilemessage/gonk/MobileMessageDatabaseService.js
rename : dom/mobilemessage/src/gonk/MobileMessageDatabaseService.manifest => dom/mobilemessage/gonk/MobileMessageDatabaseService.manifest
rename : dom/mobilemessage/src/gonk/SmsService.cpp => dom/mobilemessage/gonk/SmsService.cpp
rename : dom/mobilemessage/src/gonk/SmsService.h => dom/mobilemessage/gonk/SmsService.h
rename : dom/mobilemessage/src/gonk/WspPduHelper.jsm => dom/mobilemessage/gonk/WspPduHelper.jsm
rename : dom/mobilemessage/src/gonk/mms_consts.js => dom/mobilemessage/gonk/mms_consts.js
rename : dom/mobilemessage/src/gonk/wap_consts.js => dom/mobilemessage/gonk/wap_consts.js
rename : dom/mobilemessage/src/ipc/PMobileMessageCursor.ipdl => dom/mobilemessage/ipc/PMobileMessageCursor.ipdl
rename : dom/mobilemessage/src/ipc/PSms.ipdl => dom/mobilemessage/ipc/PSms.ipdl
rename : dom/mobilemessage/src/ipc/PSmsRequest.ipdl => dom/mobilemessage/ipc/PSmsRequest.ipdl
rename : dom/mobilemessage/src/ipc/SmsChild.cpp => dom/mobilemessage/ipc/SmsChild.cpp
rename : dom/mobilemessage/src/ipc/SmsChild.h => dom/mobilemessage/ipc/SmsChild.h
rename : dom/mobilemessage/src/ipc/SmsIPCService.cpp => dom/mobilemessage/ipc/SmsIPCService.cpp
rename : dom/mobilemessage/src/ipc/SmsIPCService.h => dom/mobilemessage/ipc/SmsIPCService.h
rename : dom/mobilemessage/src/ipc/SmsParent.cpp => dom/mobilemessage/ipc/SmsParent.cpp
rename : dom/mobilemessage/src/ipc/SmsParent.h => dom/mobilemessage/ipc/SmsParent.h
rename : dom/mobilemessage/src/ipc/SmsTypes.ipdlh => dom/mobilemessage/ipc/SmsTypes.ipdlh
2014-08-27 10:13:36 -07:00

344 lines
9.6 KiB
C++

/* 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 "SmsChild.h"
#include "SmsMessage.h"
#include "MmsMessage.h"
#include "DeletedMessageInfo.h"
#include "nsIObserverService.h"
#include "mozilla/Services.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
#include "MobileMessageThread.h"
#include "MainThreadUtils.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::dom::mobilemessage;
namespace {
already_AddRefed<nsISupports>
CreateMessageFromMessageData(const MobileMessageData& aData)
{
nsCOMPtr<nsISupports> message;
switch(aData.type()) {
case MobileMessageData::TMmsMessageData:
message = new MmsMessage(aData.get_MmsMessageData());
break;
case MobileMessageData::TSmsMessageData:
message = new SmsMessage(aData.get_SmsMessageData());
break;
default:
MOZ_CRASH("Unexpected type of MobileMessageData");
}
return message.forget();
}
void
NotifyObserversWithMobileMessage(const char* aEventName,
const MobileMessageData& aData)
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
nsCOMPtr<nsISupports> msg = CreateMessageFromMessageData(aData);
obs->NotifyObservers(msg, aEventName, nullptr);
}
} // anonymous namespace
namespace mozilla {
namespace dom {
namespace mobilemessage {
void
SmsChild::ActorDestroy(ActorDestroyReason aWhy)
{
}
bool
SmsChild::RecvNotifyReceivedMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsReceivedObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyRetrievingMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsRetrievingObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifySendingMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsSendingObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifySentMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsSentObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyFailedMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsFailedObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyDeliverySuccessMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsDeliverySuccessObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyDeliveryErrorMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsDeliveryErrorObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyReceivedSilentMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSilentSmsReceivedObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyReadSuccessMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsReadSuccessObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyReadErrorMessage(const MobileMessageData& aData)
{
NotifyObserversWithMobileMessage(kSmsReadErrorObserverTopic, aData);
return true;
}
bool
SmsChild::RecvNotifyDeletedMessageInfo(const DeletedMessageInfoData& aDeletedInfo)
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
NS_ERROR("Failed to get nsIObserverService!");
return false;
}
nsCOMPtr<nsISupports> info = new DeletedMessageInfo(aDeletedInfo);
obs->NotifyObservers(info, kSmsDeletedObserverTopic, nullptr);
return true;
}
PSmsRequestChild*
SmsChild::AllocPSmsRequestChild(const IPCSmsRequest& aRequest)
{
MOZ_CRASH("Caller is supposed to manually construct a request!");
}
bool
SmsChild::DeallocPSmsRequestChild(PSmsRequestChild* aActor)
{
delete aActor;
return true;
}
PMobileMessageCursorChild*
SmsChild::AllocPMobileMessageCursorChild(const IPCMobileMessageCursor& aCursor)
{
MOZ_CRASH("Caller is supposed to manually construct a cursor!");
}
bool
SmsChild::DeallocPMobileMessageCursorChild(PMobileMessageCursorChild* aActor)
{
// MobileMessageCursorChild is refcounted, must not be freed manually.
// Originally AddRefed in SendCursorRequest() in SmsIPCService.cpp.
static_cast<MobileMessageCursorChild*>(aActor)->Release();
return true;
}
/*******************************************************************************
* SmsRequestChild
******************************************************************************/
SmsRequestChild::SmsRequestChild(nsIMobileMessageCallback* aReplyRequest)
: mReplyRequest(aReplyRequest)
{
MOZ_COUNT_CTOR(SmsRequestChild);
MOZ_ASSERT(aReplyRequest);
}
void
SmsRequestChild::ActorDestroy(ActorDestroyReason aWhy)
{
// Nothing needed here.
}
bool
SmsRequestChild::Recv__delete__(const MessageReply& aReply)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mReplyRequest);
nsCOMPtr<SmsMessage> message;
switch(aReply.type()) {
case MessageReply::TReplyMessageSend: {
const MobileMessageData& data =
aReply.get_ReplyMessageSend().messageData();
nsCOMPtr<nsISupports> msg = CreateMessageFromMessageData(data);
mReplyRequest->NotifyMessageSent(msg);
}
break;
case MessageReply::TReplyMessageSendFail: {
const ReplyMessageSendFail &replyFail = aReply.get_ReplyMessageSendFail();
nsCOMPtr<nsISupports> msg;
if (replyFail.messageData().type() ==
OptionalMobileMessageData::TMobileMessageData) {
msg = CreateMessageFromMessageData(
replyFail.messageData().get_MobileMessageData());
}
mReplyRequest->NotifySendMessageFailed(replyFail.error(), msg);
}
break;
case MessageReply::TReplyGetMessage: {
const MobileMessageData& data =
aReply.get_ReplyGetMessage().messageData();
nsCOMPtr<nsISupports> msg = CreateMessageFromMessageData(data);
mReplyRequest->NotifyMessageGot(msg);
}
break;
case MessageReply::TReplyGetMessageFail:
mReplyRequest->NotifyGetMessageFailed(aReply.get_ReplyGetMessageFail().error());
break;
case MessageReply::TReplyMessageDelete: {
const InfallibleTArray<bool>& deletedResult = aReply.get_ReplyMessageDelete().deleted();
mReplyRequest->NotifyMessageDeleted(const_cast<bool *>(deletedResult.Elements()),
deletedResult.Length());
}
break;
case MessageReply::TReplyMessageDeleteFail:
mReplyRequest->NotifyDeleteMessageFailed(aReply.get_ReplyMessageDeleteFail().error());
break;
case MessageReply::TReplyMarkeMessageRead:
mReplyRequest->NotifyMessageMarkedRead(aReply.get_ReplyMarkeMessageRead().read());
break;
case MessageReply::TReplyMarkeMessageReadFail:
mReplyRequest->NotifyMarkMessageReadFailed(aReply.get_ReplyMarkeMessageReadFail().error());
break;
case MessageReply::TReplyGetSegmentInfoForText: {
const ReplyGetSegmentInfoForText& reply =
aReply.get_ReplyGetSegmentInfoForText();
mReplyRequest->NotifySegmentInfoForTextGot(reply.segments(),
reply.charsPerSegment(),
reply.charsAvailableInLastSegment());
}
break;
case MessageReply::TReplyGetSegmentInfoForTextFail:
mReplyRequest->NotifyGetSegmentInfoForTextFailed(
aReply.get_ReplyGetSegmentInfoForTextFail().error());
break;
case MessageReply::TReplyGetSmscAddress:
mReplyRequest->NotifyGetSmscAddress(aReply.get_ReplyGetSmscAddress().smscAddress());
break;
case MessageReply::TReplyGetSmscAddressFail:
mReplyRequest->NotifyGetSmscAddressFailed(aReply.get_ReplyGetSmscAddressFail().error());
break;
default:
MOZ_CRASH("Received invalid response parameters!");
}
return true;
}
/*******************************************************************************
* MobileMessageCursorChild
******************************************************************************/
NS_IMPL_ISUPPORTS(MobileMessageCursorChild, nsICursorContinueCallback)
MobileMessageCursorChild::MobileMessageCursorChild(nsIMobileMessageCursorCallback* aCallback)
: mCursorCallback(aCallback)
{
MOZ_COUNT_CTOR(MobileMessageCursorChild);
MOZ_ASSERT(aCallback);
}
void
MobileMessageCursorChild::ActorDestroy(ActorDestroyReason aWhy)
{
// Nothing needed here.
}
bool
MobileMessageCursorChild::RecvNotifyResult(const MobileMessageCursorData& aData)
{
MOZ_ASSERT(mCursorCallback);
nsCOMPtr<nsISupports> result;
switch(aData.type()) {
case MobileMessageCursorData::TMmsMessageData:
result = new MmsMessage(aData.get_MmsMessageData());
break;
case MobileMessageCursorData::TSmsMessageData:
result = new SmsMessage(aData.get_SmsMessageData());
break;
case MobileMessageCursorData::TThreadData:
result = new MobileMessageThread(aData.get_ThreadData());
break;
default:
MOZ_CRASH("Received invalid response parameters!");
}
mCursorCallback->NotifyCursorResult(result);
return true;
}
bool
MobileMessageCursorChild::Recv__delete__(const int32_t& aError)
{
MOZ_ASSERT(mCursorCallback);
if (aError != nsIMobileMessageCallback::SUCCESS_NO_ERROR) {
mCursorCallback->NotifyCursorError(aError);
} else {
mCursorCallback->NotifyCursorDone();
}
mCursorCallback = nullptr;
return true;
}
// nsICursorContinueCallback
NS_IMETHODIMP
MobileMessageCursorChild::HandleContinue()
{
MOZ_ASSERT(mCursorCallback);
SendContinue();
return NS_OK;
}
} // namespace mobilemessage
} // namespace dom
} // namespace mozilla