Bug 674725 - Part AN - Handling no messages in created message list. r=smaug,cjones
authorMounir Lamouri <mounir.lamouri@gmail.com>
Mon, 19 Dec 2011 12:04:53 +0100
changeset 85950 358b9db3d4868e03cc11ae39f04a2d89388416ef
parent 85949 3b95e40950156f9fa9298272bd5d65225975dd43
child 85951 731e1914b5985fdc912c36a0771a3f5ac3056e68
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, cjones
bugs674725
milestone12.0a1
Bug 674725 - Part AN - Handling no messages in created message list. r=smaug,cjones
dom/sms/src/SmsRequest.cpp
dom/sms/src/SmsRequest.h
dom/sms/src/SmsRequestManager.cpp
dom/sms/src/SmsRequestManager.h
dom/sms/src/ipc/PSms.ipdl
dom/sms/src/ipc/SmsChild.cpp
dom/sms/src/ipc/SmsChild.h
widget/android/AndroidJNI.cpp
--- a/dom/sms/src/SmsRequest.cpp
+++ b/dom/sms/src/SmsRequest.cpp
@@ -35,16 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "SmsRequest.h"
 #include "nsIDOMClassInfo.h"
 #include "nsDOMString.h"
 #include "nsContentUtils.h"
 #include "nsIDOMSmsMessage.h"
+#include "nsIDOMSmsCursor.h"
 
 DOMCI_DATA(MozSmsRequest, mozilla::dom::sms::SmsRequest)
 
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(SmsRequest)
@@ -118,53 +119,67 @@ SmsRequest::UnrootResult()
   NS_ASSERTION(mResultRooted, "Don't call UnrotResult() if not rooted!");
   NS_DROP_JS_OBJECTS(this, SmsRequest);
   mResultRooted = false;
 }
 
 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!");
   NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");
 
   JSContext* cx = mScriptContext->GetNativeContext();
   NS_ASSERTION(cx, "Failed to get a context!");
 
   JSObject* global = mScriptContext->GetNativeGlobal();
   NS_ASSERTION(global, "Failed to get global object!");
 
   JSAutoRequest ar(cx);
   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
 SmsRequest::SetError(ErrorType aError)
 {
   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_VOID, "mResult shouldn't have been set!");
--- a/dom/sms/src/SmsRequest.h
+++ b/dom/sms/src/SmsRequest.h
@@ -37,16 +37,17 @@
 
 #ifndef mozilla_dom_sms_SmsRequest_h
 #define mozilla_dom_sms_SmsRequest_h
 
 #include "nsIDOMSmsRequest.h"
 #include "nsDOMEventTargetWrapperCache.h"
 
 class nsIDOMMozSmsMessage;
+class nsIDOMMozSmsCursor;
 
 namespace mozilla {
 namespace dom {
 namespace sms {
 
 class SmsRequest : public nsIDOMMozSmsRequest
                  , public nsDOMEventTargetWrapperCache
 {
@@ -96,20 +97,32 @@ private:
   void SetSuccess(nsIDOMMozSmsMessage* aMessage);
 
   /**
    * Set the object in a success state with the result being a boolean.
    */
   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;
   bool      mDone;
 
   NS_DECL_EVENT_HANDLER(success)
   NS_DECL_EVENT_HANDLER(error)
 };
--- a/dom/sms/src/SmsRequestManager.cpp
+++ b/dom/sms/src/SmsRequestManager.cpp
@@ -33,16 +33,17 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #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
  * leaking strings when we have |static const nsString|. Sad :(
  */
 #define SUCCESS_EVENT_NAME NS_LITERAL_STRING("success")
 #define ERROR_EVENT_NAME   NS_LITERAL_STRING("error")
 
@@ -91,17 +92,16 @@ SmsRequestManager::CreateRequest(nsPIDOM
       continue;
     }
 
     mRequests.ReplaceObjectAt(request, i);
     NS_ADDREF(*aRequest = request);
     return i;
   }
 
-
   mRequests.AppendObject(request);
   NS_ADDREF(*aRequest = request);
   return size;
 }
 
 nsresult
 SmsRequestManager::DispatchTrustedEventToRequest(const nsAString& aEventName,
                                                  nsIDOMMozSmsRequest* aRequest)
@@ -182,11 +182,20 @@ SmsRequestManager::NotifySmsDeleted(PRIn
 }
 
 void
 SmsRequestManager::NotifySmsDeleteFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError)
 {
   NotifyError(aRequestId, aError);
 }
 
+void
+SmsRequestManager::NotifyNoMessageInList(PRInt32 aRequestId)
+{
+  // TODO: use Filter!
+  nsCOMPtr<nsIDOMMozSmsCursor> cursor = new SmsCursor(nsnull);
+
+  NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
+}
+
 } // namespace sms
 } // namespace dom
 } // namespace mozilla
--- a/dom/sms/src/SmsRequestManager.h
+++ b/dom/sms/src/SmsRequestManager.h
@@ -63,16 +63,17 @@ public:
                         nsIDOMMozSmsRequest** aRequest);
 
   void NotifySmsSent(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage);
   void NotifySmsSendFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError);
   void NotifyGotSms(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage);
   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;
 
   nsresult DispatchTrustedEventToRequest(const nsAString& aEventName,
                                          nsIDOMMozSmsRequest* aRequest);
   template <class T>
   void NotifySuccess(PRInt32 aRequestId, T aParam);
--- a/dom/sms/src/ipc/PSms.ipdl
+++ b/dom/sms/src/ipc/PSms.ipdl
@@ -85,16 +85,18 @@ child:
                               PRUint64 aProcessId);
 
     NotifyRequestSmsDeleted(bool aDeleted, PRInt32 aRequestId,
                             PRUint64 aProcessId);
 
     NotifyRequestSmsDeleteFailed(PRInt32 aError, PRInt32 aRequestId,
                                  PRUint64 aProcessId);
 
+    NotifyRequestNoMessageInList(PRInt32 aRequestId, PRUint64 aProcessId);
+
 parent:
     sync HasSupport()
         returns (bool aHasSupport);
 
     sync GetNumberOfMessagesForText(nsString aText)
         returns (PRUint16 aNumber);
 
     SendMessage(nsString aNumber, nsString aMessage, PRInt32 aRequestId,
--- a/dom/sms/src/ipc/SmsChild.cpp
+++ b/dom/sms/src/ipc/SmsChild.cpp
@@ -174,11 +174,23 @@ SmsChild::RecvNotifyRequestSmsDeleteFail
   }
 
   SmsRequestManager::GetInstance()->NotifySmsDeleteFailed(aRequestId,
                                                           SmsRequest::ErrorType(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
--- a/dom/sms/src/ipc/SmsChild.h
+++ b/dom/sms/src/ipc/SmsChild.h
@@ -51,15 +51,16 @@ public:
   NS_OVERRIDE virtual bool RecvNotifySentMessage(const SmsMessageData& aMessage);
   NS_OVERRIDE virtual bool RecvNotifyDeliveredMessage(const SmsMessageData& aMessage);
   NS_OVERRIDE virtual bool RecvNotifyRequestSmsSent(const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
   NS_OVERRIDE virtual bool RecvNotifyRequestSmsSendFailed(const PRInt32& aError, const PRInt32& aRequestId, const PRUint64& aProcessId);
   NS_OVERRIDE virtual bool RecvNotifyRequestGotSms(const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
   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
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_sms_SmsChild_h
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -634,19 +634,52 @@ Java_org_mozilla_gecko_GeckoAppShell_not
 
 
     nsCOMPtr<nsIRunnable> runnable =
       new NotifySmsDeleteFailedRunnable(SmsRequest::ErrorType(aError), aRequestId, aProcessId);
     NS_DispatchToMainThread(runnable);
 }
 
 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<SmsParent*> spList;
+          SmsParent::GetAll(spList);
+
+          for (PRUint32 i=0; i<spList.Length(); ++i) {
+            unused << spList[i]->SendNotifyRequestNoMessageInList(mRequestId,
+                                                                  mProcessId);
+          }
+        }
+
+        return NS_OK;
+      }
+
+    private:
+      PRInt32               mRequestId;
+      PRUint64              mProcessId;
+    };
+
+
+    nsCOMPtr<nsIRunnable> runnable =
+      new NotifyNoMessageInListRunnable(aRequestId, aProcessId);
+    NS_DispatchToMainThread(runnable);
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass, jint, jint, jstring, jstring, jstring, jlong, jint, jlong)
 {
   // TODO: implement
 }