From f57e9631930d9ba7d2b2d46ef3235d745a1abd91 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Mon, 19 Dec 2011 12:07:03 +0100 Subject: [PATCH] Bug 674725 - Part AO - Show the first message of message list in SmsCursor. r=smaug,cjones --- dom/sms/src/SmsCursor.cpp | 12 ++++-- dom/sms/src/SmsCursor.h | 11 ++++++ dom/sms/src/SmsRequestManager.cpp | 34 ++++++++++++----- dom/sms/src/SmsRequestManager.h | 3 ++ dom/sms/src/ipc/PSms.ipdl | 2 + dom/sms/src/ipc/SmsChild.cpp | 15 ++++++++ dom/sms/src/ipc/SmsChild.h | 1 + widget/android/AndroidJNI.cpp | 61 ++++++++++++++++++++++++++++++- 8 files changed, 124 insertions(+), 15 deletions(-) diff --git a/dom/sms/src/SmsCursor.cpp b/dom/sms/src/SmsCursor.cpp index b048a9928c4..11f2221a7bc 100644 --- a/dom/sms/src/SmsCursor.cpp +++ b/dom/sms/src/SmsCursor.cpp @@ -40,6 +40,7 @@ #include "nsDOMError.h" #include "nsIDOMSmsFilter.h" #include "nsIDOMSmsMessage.h" +#include "nsIDOMSmsRequest.h" DOMCI_DATA(MozSmsCursor, mozilla::dom::sms::SmsCursor) @@ -53,7 +54,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SmsCursor) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsCursor) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION_2(SmsCursor, mFilter, mMessage) +NS_IMPL_CYCLE_COLLECTION_3(SmsCursor, mFilter, mRequest, mMessage) NS_IMPL_CYCLE_COLLECTING_ADDREF(SmsCursor) NS_IMPL_CYCLE_COLLECTING_RELEASE(SmsCursor) @@ -63,6 +64,12 @@ SmsCursor::SmsCursor(nsIDOMMozSmsFilter* aFilter) { } +SmsCursor::SmsCursor(nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest) + : mFilter(aFilter) + , mRequest(aRequest) +{ +} + NS_IMETHODIMP SmsCursor::GetFilter(nsIDOMMozSmsFilter** aFilter) { @@ -73,8 +80,7 @@ SmsCursor::GetFilter(nsIDOMMozSmsFilter** aFilter) NS_IMETHODIMP SmsCursor::GetMessage(nsIDOMMozSmsMessage** aMessage) { - // TODO: implement - *aMessage = nsnull; + NS_IF_ADDREF(*aMessage = mMessage); return NS_OK; } diff --git a/dom/sms/src/SmsCursor.h b/dom/sms/src/SmsCursor.h index cb6b27990cd..ee79c860feb 100644 --- a/dom/sms/src/SmsCursor.h +++ b/dom/sms/src/SmsCursor.h @@ -44,6 +44,7 @@ class nsIDOMMozSmsFilter; class nsIDOMMozSmsMessage; +class nsIDOMMozSmsRequest; namespace mozilla { namespace dom { @@ -58,12 +59,22 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS(SmsCursor) SmsCursor(nsIDOMMozSmsFilter* aFilter); + SmsCursor(nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest); + + void SetMessage(nsIDOMMozSmsMessage* aMessage); private: nsCOMPtr mFilter; + nsCOMPtr mRequest; nsCOMPtr mMessage; }; +inline void +SmsCursor::SetMessage(nsIDOMMozSmsMessage* aMessage) +{ + mMessage = aMessage; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/SmsRequestManager.cpp b/dom/sms/src/SmsRequestManager.cpp index 3bfa32bac87..2cb3aa296e3 100644 --- a/dom/sms/src/SmsRequestManager.cpp +++ b/dom/sms/src/SmsRequestManager.cpp @@ -117,16 +117,22 @@ SmsRequestManager::DispatchTrustedEventToRequest(const nsAString& aEventName, return aRequest->DispatchEvent(event, &dummy); } -template -void -SmsRequestManager::NotifySuccess(PRInt32 aRequestId, T aParam) +SmsRequest* +SmsRequestManager::GetRequest(PRInt32 aRequestId) { NS_ASSERTION(mRequests.Count() > aRequestId && mRequests[aRequestId], "Got an invalid request id or it has been already deleted!"); // It's safe to use the static_cast here given that we did call // |new SmsRequest()|. - SmsRequest* request = static_cast(mRequests[aRequestId]); + return static_cast(mRequests[aRequestId]); +} + +template +void +SmsRequestManager::NotifySuccess(PRInt32 aRequestId, T aParam) +{ + SmsRequest* request = GetRequest(aRequestId); request->SetSuccess(aParam); DispatchTrustedEventToRequest(SUCCESS_EVENT_NAME, request); @@ -137,12 +143,7 @@ SmsRequestManager::NotifySuccess(PRInt32 aRequestId, T aParam) void SmsRequestManager::NotifyError(PRInt32 aRequestId, SmsRequest::ErrorType aError) { - NS_ASSERTION(mRequests.Count() > aRequestId && mRequests[aRequestId], - "Got an invalid request id or it has been already deleted!"); - - // It's safe to use the static_cast here given that we did call - // |new SmsRequest()|. - SmsRequest* request = static_cast(mRequests[aRequestId]); + SmsRequest* request = GetRequest(aRequestId); request->SetError(aError); DispatchTrustedEventToRequest(ERROR_EVENT_NAME, request); @@ -196,6 +197,19 @@ SmsRequestManager::NotifyNoMessageInList(PRInt32 aRequestId) NotifySuccess(aRequestId, cursor); } +void +SmsRequestManager::NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId, + nsIDOMMozSmsMessage* aMessage) +{ + // TODO: use Filter! + SmsRequest* request = GetRequest(aRequestId); + + nsCOMPtr cursor = new SmsCursor(nsnull, request); + cursor->SetMessage(aMessage); + + NotifySuccess(aRequestId, cursor); +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/SmsRequestManager.h b/dom/sms/src/SmsRequestManager.h index ec538cd6df3..50c3572e62d 100644 --- a/dom/sms/src/SmsRequestManager.h +++ b/dom/sms/src/SmsRequestManager.h @@ -69,12 +69,15 @@ public: void NotifySmsDeleted(PRInt32 aRequestId, bool aDeleted); void NotifySmsDeleteFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError); void NotifyNoMessageInList(PRInt32 aRequestId); + void NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId, nsIDOMMozSmsMessage* aMessage); private: static SmsRequestManager* sInstance; nsresult DispatchTrustedEventToRequest(const nsAString& aEventName, nsIDOMMozSmsRequest* aRequest); + SmsRequest* GetRequest(PRInt32 aRequestId); + template void NotifySuccess(PRInt32 aRequestId, T aParam); void NotifyError(PRInt32 aRequestId, SmsRequest::ErrorType aError); diff --git a/dom/sms/src/ipc/PSms.ipdl b/dom/sms/src/ipc/PSms.ipdl index f88348ef46d..5f3f8fb8370 100644 --- a/dom/sms/src/ipc/PSms.ipdl +++ b/dom/sms/src/ipc/PSms.ipdl @@ -92,6 +92,8 @@ child: NotifyRequestNoMessageInList(PRInt32 aRequestId, PRUint64 aProcessId); + NotifyRequestCreateMessageList(PRInt32 aListId, SmsMessageData aMessageData, PRInt32 aRequestId, PRUint64 aProcessId); + parent: sync HasSupport() returns (bool aHasSupport); diff --git a/dom/sms/src/ipc/SmsChild.cpp b/dom/sms/src/ipc/SmsChild.cpp index 4c25ba74efa..3cb18f1630f 100644 --- a/dom/sms/src/ipc/SmsChild.cpp +++ b/dom/sms/src/ipc/SmsChild.cpp @@ -191,6 +191,21 @@ SmsChild::RecvNotifyRequestNoMessageInList(const PRInt32& aRequestId, return true; } +bool +SmsChild::RecvNotifyRequestCreateMessageList(const PRInt32& aListId, + const SmsMessageData& aMessageData, + const PRInt32& aRequestId, + const PRUint64& aProcessId) +{ + if (ContentChild::GetSingleton()->GetID() != aProcessId) { + return true; + } + + nsCOMPtr message = new SmsMessage(aMessageData); + SmsRequestManager::GetInstance()->NotifyCreateMessageList(aRequestId, aListId, message); + return true; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/ipc/SmsChild.h b/dom/sms/src/ipc/SmsChild.h index f1606b12ad7..03cef9a44ae 100644 --- a/dom/sms/src/ipc/SmsChild.h +++ b/dom/sms/src/ipc/SmsChild.h @@ -57,6 +57,7 @@ public: NS_OVERRIDE virtual bool RecvNotifyRequestSmsDeleted(const bool& aDeleted, const PRInt32& aRequestId, const PRUint64& aProcessId); NS_OVERRIDE virtual bool RecvNotifyRequestSmsDeleteFailed(const PRInt32& aError, const PRInt32& aRequestId, const PRUint64& aProcessId); NS_OVERRIDE virtual bool RecvNotifyRequestNoMessageInList(const PRInt32& aRequestId, const PRUint64& aProcessId); + NS_OVERRIDE virtual bool RecvNotifyRequestCreateMessageList(const PRInt32& aListId, const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId); }; } // namespace sms diff --git a/widget/android/AndroidJNI.cpp b/widget/android/AndroidJNI.cpp index 09e54e1cb80..385c5c454dd 100644 --- a/widget/android/AndroidJNI.cpp +++ b/widget/android/AndroidJNI.cpp @@ -678,9 +678,66 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyNoMessageInList(JNIEnv* jenv, jclass, } NS_EXPORT void JNICALL -Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass, jint, jint, jstring, jstring, jstring, jlong, jint, jlong) +Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass, + jint aListId, + jint aMessageId, + jstring aReceiver, + jstring aSender, + jstring aBody, + jlong aTimestamp, + jint aRequestId, + jlong aProcessId) { - // TODO: implement + class NotifyCreateMessageListRunnable : public nsRunnable { + public: + NotifyCreateMessageListRunnable(PRInt32 aListId, + const SmsMessageData& aMessage, + PRInt32 aRequestId, PRUint64 aProcessId) + : mListId(aListId) + , mMessage(aMessage) + , mRequestId(aRequestId) + , mProcessId(aProcessId) + {} + + NS_IMETHODIMP Run() { + if (mProcessId == 0) { // Parent process. + nsCOMPtr message = new SmsMessage(mMessage); + SmsRequestManager::GetInstance()->NotifyCreateMessageList(mRequestId, + mListId, + message); + } else { // Content process. + nsTArray spList; + SmsParent::GetAll(spList); + + for (PRUint32 i=0; iSendNotifyRequestCreateMessageList(mListId, + mMessage, + mRequestId, + mProcessId); + } + } + + return NS_OK; + } + + private: + PRInt32 mListId; + SmsMessageData mMessage; + PRInt32 mRequestId; + PRUint64 mProcessId; + }; + + + nsJNIString receiver = nsJNIString(aReceiver, jenv); + DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received + : eDeliveryState_Sent; + + SmsMessageData message(aMessageId, state, nsJNIString(aSender, jenv), + receiver, nsJNIString(aBody, jenv), aTimestamp); + + nsCOMPtr runnable = + new NotifyCreateMessageListRunnable(aListId, message, aRequestId, aProcessId); + NS_DispatchToMainThread(runnable); } #ifdef MOZ_JAVA_COMPOSITOR