diff --git a/dom/mobilemessage/src/ipc/SmsChild.cpp b/dom/mobilemessage/src/ipc/SmsChild.cpp index 5d3e92563bed..254422d53c29 100644 --- a/dom/mobilemessage/src/ipc/SmsChild.cpp +++ b/dom/mobilemessage/src/ipc/SmsChild.cpp @@ -9,6 +9,7 @@ #include "mozilla/Services.h" #include "mozilla/dom/ContentChild.h" #include "SmsRequest.h" +#include "MobileMessageThread.h" using namespace mozilla; using namespace mozilla::dom; @@ -97,7 +98,7 @@ SmsChild::DeallocPSmsRequest(PSmsRequestChild* aActor) } PMobileMessageCursorChild* -SmsChild::AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) +SmsChild::AllocPMobileMessageCursor(const IPCMobileMessageCursor& aCursor) { MOZ_NOT_REACHED("Caller is supposed to manually construct a cursor!"); return nullptr; @@ -162,14 +163,6 @@ SmsRequestChild::Recv__delete__(const MessageReply& aReply) case MessageReply::TReplyMarkeMessageReadFail: mReplyRequest->NotifyMarkMessageReadFailed(aReply.get_ReplyMarkeMessageReadFail().error()); break; - case MessageReply::TReplyThreadList: { - SmsRequestForwarder* forwarder = static_cast(mReplyRequest.get()); - SmsRequest* request = static_cast(forwarder->GetRealRequest()); - request->NotifyThreadList(aReply.get_ReplyThreadList().items()); - } break; - case MessageReply::TReplyThreadListFail: - mReplyRequest->NotifyThreadListFailed(aReply.get_ReplyThreadListFail().error()); - break; default: MOZ_NOT_REACHED("Received invalid response parameters!"); return false; @@ -198,11 +191,23 @@ MobileMessageCursorChild::ActorDestroy(ActorDestroyReason aWhy) } bool -MobileMessageCursorChild::RecvNotifyResult(const SmsMessageData& aMessageData) +MobileMessageCursorChild::RecvNotifyResult(const MobileMessageCursorData& aData) { MOZ_ASSERT(mCursorCallback); - nsCOMPtr result = new SmsMessage(aMessageData); + nsCOMPtr result; + switch(aData.type()) { + case MobileMessageCursorData::TSmsMessageData: + result = new SmsMessage(aData.get_SmsMessageData()); + break; + case MobileMessageCursorData::TThreadData: + result = new MobileMessageThread(aData.get_ThreadData()); + break; + default: + MOZ_NOT_REACHED("Received invalid response parameters!"); + return false; + } + mCursorCallback->NotifyCursorResult(result); return true; } diff --git a/dom/mobilemessage/src/ipc/SmsChild.h b/dom/mobilemessage/src/ipc/SmsChild.h index af9cc4312887..75f14b231024 100644 --- a/dom/mobilemessage/src/ipc/SmsChild.h +++ b/dom/mobilemessage/src/ipc/SmsChild.h @@ -59,7 +59,7 @@ protected: DeallocPSmsRequest(PSmsRequestChild* aActor) MOZ_OVERRIDE; virtual PMobileMessageCursorChild* - AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE; + AllocPMobileMessageCursor(const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE; virtual bool DeallocPMobileMessageCursor(PMobileMessageCursorChild* aActor) MOZ_OVERRIDE; @@ -110,7 +110,7 @@ protected: ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; virtual bool - RecvNotifyResult(const SmsMessageData& aMessageData) MOZ_OVERRIDE; + RecvNotifyResult(const MobileMessageCursorData& aData) MOZ_OVERRIDE; virtual bool Recv__delete__(const int32_t& aError) MOZ_OVERRIDE; diff --git a/dom/mobilemessage/src/ipc/SmsIPCService.cpp b/dom/mobilemessage/src/ipc/SmsIPCService.cpp index 27c126576aeb..066deae86d4a 100644 --- a/dom/mobilemessage/src/ipc/SmsIPCService.cpp +++ b/dom/mobilemessage/src/ipc/SmsIPCService.cpp @@ -50,7 +50,7 @@ SendRequest(const IPCSmsRequest& aRequest, } nsresult -SendCursorRequest(const CreateMessageCursorRequest& aRequest, +SendCursorRequest(const IPCMobileMessageCursor& aRequest, nsIMobileMessageCursorCallback* aRequestReply, nsICursorContinueCallback** aResult) { @@ -154,7 +154,9 @@ SmsIPCService::MarkMessageRead(int32_t aMessageId, } NS_IMETHODIMP -SmsIPCService::GetThreadList(nsIMobileMessageCallback* aRequest) +SmsIPCService::CreateThreadCursor(nsIMobileMessageCursorCallback* aCursorCallback, + nsICursorContinueCallback** aResult) { - return SendRequest(GetThreadListRequest(), aRequest); + return SendCursorRequest(CreateThreadCursorRequest(), aCursorCallback, + aResult); } diff --git a/dom/mobilemessage/src/ipc/SmsParent.cpp b/dom/mobilemessage/src/ipc/SmsParent.cpp index 1c128895a890..f798a44586d6 100644 --- a/dom/mobilemessage/src/ipc/SmsParent.cpp +++ b/dom/mobilemessage/src/ipc/SmsParent.cpp @@ -15,6 +15,7 @@ #include "SmsFilter.h" #include "SmsRequest.h" #include "SmsSegmentInfo.h" +#include "MobileMessageThread.h" namespace mozilla { namespace dom { @@ -183,14 +184,11 @@ SmsParent::RecvPSmsRequestConstructor(PSmsRequestParent* aActor, return actor->DoRequest(aRequest.get_DeleteMessageRequest()); case IPCSmsRequest::TMarkMessageReadRequest: return actor->DoRequest(aRequest.get_MarkMessageReadRequest()); - case IPCSmsRequest::TGetThreadListRequest: - return actor->DoRequest(aRequest.get_GetThreadListRequest()); default: MOZ_NOT_REACHED("Unknown type!"); - return false; + break; } - MOZ_NOT_REACHED("Should never get here!"); return false; } @@ -209,16 +207,26 @@ SmsParent::DeallocPSmsRequest(PSmsRequestParent* aActor) bool SmsParent::RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor, - const CreateMessageCursorRequest& aRequest) + const IPCMobileMessageCursor& aRequest) { MobileMessageCursorParent* actor = static_cast(aActor); - return actor->DoRequest(aRequest); + switch (aRequest.type()) { + case IPCMobileMessageCursor::TCreateMessageCursorRequest: + return actor->DoRequest(aRequest.get_CreateMessageCursorRequest()); + case IPCMobileMessageCursor::TCreateThreadCursorRequest: + return actor->DoRequest(aRequest.get_CreateThreadCursorRequest()); + default: + MOZ_NOT_REACHED("Unknown type!"); + break; + } + + return false; } PMobileMessageCursorParent* -SmsParent::AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) +SmsParent::AllocPMobileMessageCursor(const IPCMobileMessageCursor& aRequest) { MobileMessageCursorParent* actor = new MobileMessageCursorParent(); // Add an extra ref for IPDL. Will be released in @@ -327,21 +335,6 @@ SmsRequestParent::DoRequest(const MarkMessageReadRequest& aRequest) return true; } -bool -SmsRequestParent::DoRequest(const GetThreadListRequest& aRequest) -{ - nsCOMPtr mobileMessageDBService = - do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID); - - NS_ENSURE_TRUE(mobileMessageDBService, true); - mSmsRequest = SmsRequest::Create(this); - nsCOMPtr forwarder = new SmsRequestForwarder(mSmsRequest); - nsresult rv = mobileMessageDBService->GetThreadList(forwarder); - NS_ENSURE_SUCCESS(rv, false); - - return true; -} - /******************************************************************************* * MobileMessageCursorParent ******************************************************************************/ @@ -393,6 +386,25 @@ MobileMessageCursorParent::DoRequest(const CreateMessageCursorRequest& aRequest) return true; } +bool +MobileMessageCursorParent::DoRequest(const CreateThreadCursorRequest& aRequest) +{ + nsresult rv = NS_ERROR_FAILURE; + + nsCOMPtr dbService = + do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID); + if (dbService) { + rv = dbService->CreateThreadCursor(this, + getter_AddRefs(mContinueCallback)); + } + + if (NS_FAILED(rv)) { + return NS_SUCCEEDED(NotifyCursorError(nsIMobileMessageCallback::INTERNAL_ERROR)); + } + + return true; +} + // nsIMobileMessageCursorCallback NS_IMETHODIMP @@ -416,8 +428,22 @@ MobileMessageCursorParent::NotifyCursorResult(nsISupports* aResult) // error here to avoid sending a message to the dead process. NS_ENSURE_TRUE(mContinueCallback, NS_ERROR_FAILURE); - SmsMessage* message = static_cast(aResult); - return SendNotifyResult(message->GetData()) ? NS_OK : NS_ERROR_FAILURE; + nsCOMPtr iMessage = do_QueryInterface(aResult); + if (iMessage) { + SmsMessage* message = static_cast(aResult); + return SendNotifyResult(MobileMessageCursorData(message->GetData())) + ? NS_OK : NS_ERROR_FAILURE; + } + + nsCOMPtr iThread = do_QueryInterface(aResult); + if (iThread) { + MobileMessageThread* thread = static_cast(aResult); + return SendNotifyResult(MobileMessageCursorData(thread->GetData())) + ? NS_OK : NS_ERROR_FAILURE; + } + + MOZ_NOT_REACHED("Received invalid response parameters!"); + return NS_ERROR_FAILURE; } NS_IMETHODIMP diff --git a/dom/mobilemessage/src/ipc/SmsParent.h b/dom/mobilemessage/src/ipc/SmsParent.h index b206a4ddbfd3..2c635ac7271a 100644 --- a/dom/mobilemessage/src/ipc/SmsParent.h +++ b/dom/mobilemessage/src/ipc/SmsParent.h @@ -58,10 +58,10 @@ protected: virtual bool RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor, - const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE; + const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE; virtual PMobileMessageCursorParent* - AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE; + AllocPMobileMessageCursor(const IPCMobileMessageCursor& aCursor) MOZ_OVERRIDE; virtual bool DeallocPMobileMessageCursor(PMobileMessageCursorParent* aActor) MOZ_OVERRIDE; @@ -95,9 +95,6 @@ protected: bool DoRequest(const MarkMessageReadRequest& aRequest); - - bool - DoRequest(const GetThreadListRequest& aRequest); }; class MobileMessageCursorParent : public PMobileMessageCursorParent @@ -130,6 +127,9 @@ protected: bool DoRequest(const CreateMessageCursorRequest& aRequest); + + bool + DoRequest(const CreateThreadCursorRequest& aRequest); }; } // namespace mobilemessage