From 9a97aef5ec3463dccfe7e5faa5408c95d3fbaa96 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Mon, 19 Dec 2011 12:04:53 +0100 Subject: [PATCH] Bug 674725 - Part AN - Handling no messages in created message list. r=smaug,cjones --- dom/sms/src/SmsRequest.cpp | 41 +++++++++++++++++++++---------- dom/sms/src/SmsRequest.h | 13 ++++++++++ dom/sms/src/SmsRequestManager.cpp | 11 ++++++++- dom/sms/src/SmsRequestManager.h | 1 + dom/sms/src/ipc/PSms.ipdl | 2 ++ dom/sms/src/ipc/SmsChild.cpp | 12 +++++++++ dom/sms/src/ipc/SmsChild.h | 1 + widget/android/AndroidJNI.cpp | 37 ++++++++++++++++++++++++++-- 8 files changed, 102 insertions(+), 16 deletions(-) diff --git a/dom/sms/src/SmsRequest.cpp b/dom/sms/src/SmsRequest.cpp index cb7cb8b43396..88100a31311f 100644 --- a/dom/sms/src/SmsRequest.cpp +++ b/dom/sms/src/SmsRequest.cpp @@ -40,6 +40,7 @@ #include "nsDOMString.h" #include "nsContentUtils.h" #include "nsIDOMSmsMessage.h" +#include "nsIDOMSmsCursor.h" DOMCI_DATA(MozSmsRequest, mozilla::dom::sms::SmsRequest) @@ -122,6 +123,29 @@ SmsRequest::UnrootResult() void SmsRequest::SetSuccess(nsIDOMMozSmsMessage* aMessage) +{ + SetSuccessInternal(aMessage); +} + +void +SmsRequest::SetSuccess(bool aResult) +{ + NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!"); + NS_PRECONDITION(mError == eNoError, "mError shouldn't have been set!"); + NS_PRECONDITION(mResult == JSVAL_NULL, "mResult shouldn't have been set!"); + + mResult.setBoolean(aResult); + mDone = true; +} + +void +SmsRequest::SetSuccess(nsIDOMMozSmsCursor* aCursor) +{ + SetSuccessInternal(aCursor); +} + +bool +SmsRequest::SetSuccessInternal(nsISupports* aObject) { NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!"); NS_PRECONDITION(mError == eNoError, "mError shouldn't have been set!"); @@ -137,29 +161,20 @@ SmsRequest::SetSuccess(nsIDOMMozSmsMessage* aMessage) JSAutoEnterCompartment ac; if (!ac.enter(cx, global)) { SetError(eInternalError); - return; + return false; } RootResult(); - if (NS_FAILED(nsContentUtils::WrapNative(cx, global, aMessage, &mResult))) { + if (NS_FAILED(nsContentUtils::WrapNative(cx, global, aObject, &mResult))) { UnrootResult(); mResult = JSVAL_VOID; SetError(eInternalError); + return false; } mDone = true; -} - -void -SmsRequest::SetSuccess(bool aResult) -{ - NS_PRECONDITION(!mDone, "mDone shouldn't have been set to true already!"); - NS_PRECONDITION(mError == eNoError, "mError shouldn't have been set!"); - NS_PRECONDITION(mResult == JSVAL_NULL, "mResult shouldn't have been set!"); - - mResult.setBoolean(aResult); - mDone = true; + return true; } void diff --git a/dom/sms/src/SmsRequest.h b/dom/sms/src/SmsRequest.h index 48455f0a350f..e8813fe4abc7 100644 --- a/dom/sms/src/SmsRequest.h +++ b/dom/sms/src/SmsRequest.h @@ -42,6 +42,7 @@ #include "nsDOMEventTargetWrapperCache.h" class nsIDOMMozSmsMessage; +class nsIDOMMozSmsCursor; namespace mozilla { namespace dom { @@ -100,11 +101,23 @@ private: */ void SetSuccess(bool aResult); + /** + * Set the object in a success state with the result being a SmsCursor. + */ + void SetSuccess(nsIDOMMozSmsCursor* aCursor); + /** * Set the object in an error state with the error type being aError. */ void SetError(ErrorType aError); + /** + * Set the object in a success state with the result being the nsISupports + * object in parameter. + * @return whether setting the object was a success + */ + bool SetSuccessInternal(nsISupports* aObject); + jsval mResult; bool mResultRooted; ErrorType mError; diff --git a/dom/sms/src/SmsRequestManager.cpp b/dom/sms/src/SmsRequestManager.cpp index fdc0e56fe6aa..3bfa32bac870 100644 --- a/dom/sms/src/SmsRequestManager.cpp +++ b/dom/sms/src/SmsRequestManager.cpp @@ -38,6 +38,7 @@ #include "SmsRequestManager.h" #include "nsIDOMSmsMessage.h" #include "nsDOMEvent.h" +#include "SmsCursor.h" /** * We have to use macros here because our leak analysis tool things we are @@ -96,7 +97,6 @@ SmsRequestManager::CreateRequest(nsPIDOMWindow* aWindow, return i; } - mRequests.AppendObject(request); NS_ADDREF(*aRequest = request); return size; @@ -187,6 +187,15 @@ SmsRequestManager::NotifySmsDeleteFailed(PRInt32 aRequestId, SmsRequest::ErrorTy NotifyError(aRequestId, aError); } +void +SmsRequestManager::NotifyNoMessageInList(PRInt32 aRequestId) +{ + // TODO: use Filter! + nsCOMPtr cursor = new SmsCursor(nsnull); + + NotifySuccess(aRequestId, cursor); +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/SmsRequestManager.h b/dom/sms/src/SmsRequestManager.h index 586f2aea25af..ec538cd6df36 100644 --- a/dom/sms/src/SmsRequestManager.h +++ b/dom/sms/src/SmsRequestManager.h @@ -68,6 +68,7 @@ public: void NotifyGetSmsFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError); void NotifySmsDeleted(PRInt32 aRequestId, bool aDeleted); void NotifySmsDeleteFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError); + void NotifyNoMessageInList(PRInt32 aRequestId); private: static SmsRequestManager* sInstance; diff --git a/dom/sms/src/ipc/PSms.ipdl b/dom/sms/src/ipc/PSms.ipdl index aff21c90e380..f88348ef46df 100644 --- a/dom/sms/src/ipc/PSms.ipdl +++ b/dom/sms/src/ipc/PSms.ipdl @@ -90,6 +90,8 @@ child: NotifyRequestSmsDeleteFailed(PRInt32 aError, PRInt32 aRequestId, PRUint64 aProcessId); + NotifyRequestNoMessageInList(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 40533f1691d3..4c25ba74efaf 100644 --- a/dom/sms/src/ipc/SmsChild.cpp +++ b/dom/sms/src/ipc/SmsChild.cpp @@ -179,6 +179,18 @@ SmsChild::RecvNotifyRequestSmsDeleteFailed(const PRInt32& aError, return true; } +bool +SmsChild::RecvNotifyRequestNoMessageInList(const PRInt32& aRequestId, + const PRUint64& aProcessId) +{ + if (ContentChild::GetSingleton()->GetID() != aProcessId) { + return true; + } + + SmsRequestManager::GetInstance()->NotifyNoMessageInList(aRequestId); + 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 ab3917367383..f1606b12ad78 100644 --- a/dom/sms/src/ipc/SmsChild.h +++ b/dom/sms/src/ipc/SmsChild.h @@ -56,6 +56,7 @@ public: NS_OVERRIDE virtual bool RecvNotifyRequestGetSmsFailed(const PRInt32& aError, const PRInt32& aRequestId, const PRUint64& aProcessId); 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); }; } // namespace sms diff --git a/widget/android/AndroidJNI.cpp b/widget/android/AndroidJNI.cpp index 9f79b2eec394..09e54e1cb805 100644 --- a/widget/android/AndroidJNI.cpp +++ b/widget/android/AndroidJNI.cpp @@ -639,9 +639,42 @@ Java_org_mozilla_gecko_GeckoAppShell_notifySmsDeleteFailed(JNIEnv* jenv, jclass, } NS_EXPORT void JNICALL -Java_org_mozilla_gecko_GeckoAppShell_notifyNoMessageInList(JNIEnv* jenv, jclass, jint, jlong) +Java_org_mozilla_gecko_GeckoAppShell_notifyNoMessageInList(JNIEnv* jenv, jclass, + jint aRequestId, + jlong aProcessId) { - // TODO: implement + class NotifyNoMessageInListRunnable : public nsRunnable { + public: + NotifyNoMessageInListRunnable(PRInt32 aRequestId, PRUint64 aProcessId) + : mRequestId(aRequestId) + , mProcessId(aProcessId) + {} + + NS_IMETHODIMP Run() { + if (mProcessId == 0) { // Parent process. + SmsRequestManager::GetInstance()->NotifyNoMessageInList(mRequestId); + } else { // Content process. + nsTArray spList; + SmsParent::GetAll(spList); + + for (PRUint32 i=0; iSendNotifyRequestNoMessageInList(mRequestId, + mProcessId); + } + } + + return NS_OK; + } + + private: + PRInt32 mRequestId; + PRUint64 mProcessId; + }; + + + nsCOMPtr runnable = + new NotifyNoMessageInListRunnable(aRequestId, aProcessId); + NS_DispatchToMainThread(runnable); } NS_EXPORT void JNICALL