From d8190dbc3770db3baaaee7fc9a4615900db715d0 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Tue, 17 Jan 2012 19:42:05 +0100 Subject: [PATCH] Bug 674725 - Part AJ - Create a message list when getMessages() is called. r=smaug --- dom/sms/interfaces/nsIDOMSmsManager.idl | 5 +++- dom/sms/interfaces/nsISmsDatabaseService.idl | 10 +++++--- dom/sms/src/SmsManager.cpp | 24 ++++++++++++++++++++ dom/sms/src/SmsMessage.cpp | 3 ++- dom/sms/src/Types.h | 5 ++-- dom/sms/src/android/SmsDatabaseService.cpp | 9 ++++++++ dom/sms/src/fallback/SmsDatabaseService.cpp | 9 ++++++++ dom/sms/src/ipc/PSms.ipdl | 2 ++ dom/sms/src/ipc/SmsIPCService.cpp | 12 ++++++++++ dom/sms/src/ipc/SmsParent.cpp | 17 ++++++++++++++ dom/sms/src/ipc/SmsParent.h | 1 + 11 files changed, 90 insertions(+), 7 deletions(-) diff --git a/dom/sms/interfaces/nsIDOMSmsManager.idl b/dom/sms/interfaces/nsIDOMSmsManager.idl index 8bd2baf33fc..a2afd86d8cf 100644 --- a/dom/sms/interfaces/nsIDOMSmsManager.idl +++ b/dom/sms/interfaces/nsIDOMSmsManager.idl @@ -38,8 +38,9 @@ interface nsIDOMEventListener; interface nsIDOMMozSmsRequest; +interface nsIDOMMozSmsFilter; -[scriptable, function, uuid(4e628d96-abc9-45e1-b158-8970885a2552)] +[scriptable, function, uuid(c9916dce-2947-41bb-95c2-818f792a020c)] interface nsIDOMMozSmsManager : nsIDOMEventTarget { unsigned short getNumberOfMessagesForText(in DOMString text); @@ -55,6 +56,8 @@ interface nsIDOMMozSmsManager : nsIDOMEventTarget // The parameter can be either a message id or a SmsMessage. nsIDOMMozSmsRequest delete(in jsval param); + nsIDOMMozSmsRequest getMessages(in nsIDOMMozSmsFilter filter, in boolean reverse); + attribute nsIDOMEventListener onreceived; attribute nsIDOMEventListener onsent; attribute nsIDOMEventListener ondelivered; diff --git a/dom/sms/interfaces/nsISmsDatabaseService.idl b/dom/sms/interfaces/nsISmsDatabaseService.idl index 807322dfa55..db306bae56a 100644 --- a/dom/sms/interfaces/nsISmsDatabaseService.idl +++ b/dom/sms/interfaces/nsISmsDatabaseService.idl @@ -38,12 +38,14 @@ %{C++ #define SMS_DATABASE_SERVICE_CID \ -{ 0xcc939280, 0x36ba, 0x4a03, \ -{ 0xbe, 0x20, 0xd1, 0xfa, 0x7e, 0xb0, 0x44, 0x1e } } +{ 0xcb971459, 0xe85a, 0x49b3, \ +{ 0xbc, 0x1c, 0x10, 0x40, 0x27, 0x1e, 0x04, 0x6c } } #define SMS_DATABASE_SERVICE_CONTRACTID "@mozilla.org/sms/smsdatabaseservice;1" %} -[scriptable, function, uuid(8f217fbf-88d9-4e72-8399-8c4d5e5cf7d0)] +interface nsIDOMMozSmsFilter; + +[scriptable, function, uuid(33358749-d1b3-4bd6-835c-ef3869f0e966)] interface nsISmsDatabaseService : nsISupports { // Takes some information required to save the message and returns its id. @@ -51,4 +53,6 @@ interface nsISmsDatabaseService : nsISupports [binaryname(GetMessageMoz)] void getMessage(in long messageId, in long requestId, [optional] in unsigned long long processId); void deleteMessage(in long messageId, in long requestId, [optional] in unsigned long long processId); + + void createMessageList(in nsIDOMMozSmsFilter filter, in boolean reverse, in long requestId, [optional] in unsigned long long processId); }; diff --git a/dom/sms/src/SmsManager.cpp b/dom/sms/src/SmsManager.cpp index 7a748df88c5..77d2b2646af 100644 --- a/dom/sms/src/SmsManager.cpp +++ b/dom/sms/src/SmsManager.cpp @@ -35,6 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include "SmsFilter.h" #include "SmsManager.h" #include "nsIDOMClassInfo.h" #include "nsISmsService.h" @@ -266,6 +267,29 @@ SmsManager::Delete(const jsval& aParam, nsIDOMMozSmsRequest** aRequest) return Delete(id, aRequest); } +NS_IMETHODIMP +SmsManager::GetMessages(nsIDOMMozSmsFilter* aFilter, bool aReverse, + nsIDOMMozSmsRequest** aRequest) +{ + nsCOMPtr filter = aFilter; + + if (!filter) { + filter = new SmsFilter(); + } + + int requestId = + SmsRequestManager::GetInstance()->CreateRequest(mOwner, mScriptContext, aRequest); + NS_ASSERTION(*aRequest, "The request object must have been created!"); + + nsCOMPtr smsDBService = + do_GetService(SMS_DATABASE_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE); + + smsDBService->CreateMessageList(filter, aReverse, requestId, 0); + + return NS_OK; +} + NS_IMPL_EVENT_HANDLER(SmsManager, received) NS_IMPL_EVENT_HANDLER(SmsManager, sent) NS_IMPL_EVENT_HANDLER(SmsManager, delivered) diff --git a/dom/sms/src/SmsMessage.cpp b/dom/sms/src/SmsMessage.cpp index 5d7902a3289..190fbf97aee 100644 --- a/dom/sms/src/SmsMessage.cpp +++ b/dom/sms/src/SmsMessage.cpp @@ -144,8 +144,9 @@ SmsMessage::GetDelivery(nsAString& aDelivery) aDelivery = DELIVERY_SENT; break; case eDeliveryState_Unknown: + case eDeliveryState_EndGuard: default: - NS_ASSERTION(true, "We shouldn't get an unknown delivery state!"); + NS_ASSERTION(true, "We shouldn't get any other delivery state!"); return NS_ERROR_UNEXPECTED; } diff --git a/dom/sms/src/Types.h b/dom/sms/src/Types.h index bf90b56173c..c1d20fd520e 100644 --- a/dom/sms/src/Types.h +++ b/dom/sms/src/Types.h @@ -48,8 +48,9 @@ namespace sms { enum DeliveryState { eDeliveryState_Sent, eDeliveryState_Received, + eDeliveryState_Unknown, // This state should stay at the end. - eDeliveryState_Unknown + eDeliveryState_EndGuard }; } // namespace sms @@ -65,7 +66,7 @@ template <> struct ParamTraits : public EnumSerializer + mozilla::dom::sms::eDeliveryState_EndGuard> {}; } // namespace IPC diff --git a/dom/sms/src/android/SmsDatabaseService.cpp b/dom/sms/src/android/SmsDatabaseService.cpp index 25a15e313bb..29df141e4e5 100644 --- a/dom/sms/src/android/SmsDatabaseService.cpp +++ b/dom/sms/src/android/SmsDatabaseService.cpp @@ -83,6 +83,15 @@ SmsDatabaseService::DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, return NS_OK; } +NS_IMETHODIMP +SmsDatabaseService::CreateMessageList(nsIDOMMozSmsFilter* aFilter, + bool aReverse, PRInt32 aRequestId, + PRUint64 aProcessId) +{ + // TODO: implement + return NS_OK; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/fallback/SmsDatabaseService.cpp b/dom/sms/src/fallback/SmsDatabaseService.cpp index 27a5864d24b..0f246deb5de 100644 --- a/dom/sms/src/fallback/SmsDatabaseService.cpp +++ b/dom/sms/src/fallback/SmsDatabaseService.cpp @@ -69,6 +69,15 @@ SmsDatabaseService::DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, return NS_OK; } +NS_IMETHODIMP +SmsDatabaseService::CreateMessageList(nsIDOMMozSmsFilter* aFilter, + bool aReverse, PRInt32 aRequestId, + PRUint64 aProcessId) +{ + NS_ERROR("We should not be here!"); + return NS_OK; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/ipc/PSms.ipdl b/dom/sms/src/ipc/PSms.ipdl index be05a1ef1fd..aff21c90e38 100644 --- a/dom/sms/src/ipc/PSms.ipdl +++ b/dom/sms/src/ipc/PSms.ipdl @@ -107,6 +107,8 @@ parent: DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId); + CreateMessageList(SmsFilterData aFilter, bool aReverse, PRInt32 aRequestId, PRUint64 aProcessId); + __delete__(); }; diff --git a/dom/sms/src/ipc/SmsIPCService.cpp b/dom/sms/src/ipc/SmsIPCService.cpp index f2ba09b4ff8..1faebc80bc9 100644 --- a/dom/sms/src/ipc/SmsIPCService.cpp +++ b/dom/sms/src/ipc/SmsIPCService.cpp @@ -41,6 +41,7 @@ #include "jsapi.h" #include "mozilla/dom/sms/SmsChild.h" #include "mozilla/dom/sms/SmsMessage.h" +#include "SmsFilter.h" namespace mozilla { namespace dom { @@ -135,6 +136,17 @@ SmsIPCService::DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, return NS_OK; } +NS_IMETHODIMP +SmsIPCService::CreateMessageList(nsIDOMMozSmsFilter* aFilter, bool aReverse, + PRInt32 aRequestId, PRUint64 aProcessId) +{ + SmsFilter* filter = static_cast(aFilter); + GetSmsChild()->SendCreateMessageList(filter->GetData(), aReverse, aRequestId, + ContentChild::GetSingleton()->GetID()); + + return NS_OK; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/ipc/SmsParent.cpp b/dom/sms/src/ipc/SmsParent.cpp index 9c7238633c4..1d6de2eb15a 100644 --- a/dom/sms/src/ipc/SmsParent.cpp +++ b/dom/sms/src/ipc/SmsParent.cpp @@ -44,6 +44,7 @@ #include "mozilla/unused.h" #include "SmsMessage.h" #include "nsISmsDatabaseService.h" +#include "SmsFilter.h" namespace mozilla { namespace dom { @@ -216,6 +217,22 @@ SmsParent::RecvDeleteMessage(const PRInt32& aMessageId, const PRInt32& aRequestI return true; } +bool +SmsParent::RecvCreateMessageList(const SmsFilterData& aFilter, + const bool& aReverse, + const PRInt32& aRequestId, + const PRUint64& aProcessId) +{ + nsCOMPtr smsDBService = + do_GetService(SMS_DATABASE_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(smsDBService, true); + + nsCOMPtr filter = new SmsFilter(aFilter); + smsDBService->CreateMessageList(filter, aReverse, aRequestId, aProcessId); + + return true; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/ipc/SmsParent.h b/dom/sms/src/ipc/SmsParent.h index 4f0440804b1..ae0ab92436a 100644 --- a/dom/sms/src/ipc/SmsParent.h +++ b/dom/sms/src/ipc/SmsParent.h @@ -62,6 +62,7 @@ public: NS_OVERRIDE virtual bool RecvSaveSentMessage(const nsString& aRecipient, const nsString& aBody, const PRUint64& aDate, PRInt32* aId); NS_OVERRIDE virtual bool RecvGetMessage(const PRInt32& aMessageId, const PRInt32& aRequestId, const PRUint64& aProcessId); NS_OVERRIDE virtual bool RecvDeleteMessage(const PRInt32& aMessageId, const PRInt32& aRequestId, const PRUint64& aProcessId); + NS_OVERRIDE virtual bool RecvCreateMessageList(const SmsFilterData& aFilter, const bool& aReverse, const PRInt32& aRequestId, const PRUint64& aProcessId); protected: virtual void ActorDestroy(ActorDestroyReason why);