Bug 674725 - Part AH - Allow to pass a SmsMessage or an id to delete(). r=mrbkap
authorMounir Lamouri <mounir.lamouri@gmail.com>
Tue, 20 Dec 2011 17:16:20 +0100
changeset 84719 3eb67a0b91f1230c68bd2f644774b86baaeee2cd
parent 84718 31e83a9f249bdb0a6b510ee115dc62169370d3b5
child 84720 48725e4f215ac788f704f6c64ecbc3be034d3efc
push id21873
push usermlamouri@mozilla.com
push dateWed, 18 Jan 2012 10:29:07 +0000
treeherdermozilla-central@7538f4d4697c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs674725
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 674725 - Part AH - Allow to pass a SmsMessage or an id to delete(). r=mrbkap
dom/sms/interfaces/nsIDOMSmsManager.idl
dom/sms/src/SmsManager.cpp
dom/sms/src/SmsManager.h
--- a/dom/sms/interfaces/nsIDOMSmsManager.idl
+++ b/dom/sms/interfaces/nsIDOMSmsManager.idl
@@ -46,14 +46,16 @@ interface nsIDOMMozSmsManager : nsIDOMEv
 
   // The first parameter can be either a DOMString (only one number) or an array
   // of DOMStrings.
   // The method returns a SmsRequest object if one number has been passed.
   // An array of SmsRequest objects otherwise.
   jsval send(in jsval number, in DOMString message);
 
   [binaryname(GetMessageMoz)] nsIDOMMozSmsRequest getMessage(in long id);
-  nsIDOMMozSmsRequest delete(in long id);
+
+  // The parameter can be either a message id or a SmsMessage.
+  nsIDOMMozSmsRequest delete(in jsval param);
 
   attribute nsIDOMEventListener onreceived;
   attribute nsIDOMEventListener onsent;
   attribute nsIDOMEventListener ondelivered;
 };
--- a/dom/sms/src/SmsManager.cpp
+++ b/dom/sms/src/SmsManager.cpp
@@ -43,16 +43,17 @@
 #include "Constants.h"
 #include "SmsEvent.h"
 #include "nsIDOMSmsMessage.h"
 #include "nsIDOMSmsRequest.h"
 #include "SmsRequestManager.h"
 #include "nsJSUtils.h"
 #include "nsContentUtils.h"
 #include "nsISmsDatabaseService.h"
+#include "nsIXPConnect.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 RECEIVED_EVENT_NAME  NS_LITERAL_STRING("received")
 #define SENT_EVENT_NAME      NS_LITERAL_STRING("sent")
 #define DELIVERED_EVENT_NAME NS_LITERAL_STRING("delivered")
@@ -222,32 +223,54 @@ SmsManager::GetMessageMoz(PRInt32 aId, n
     do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE);
 
   smsDBService->GetMessageMoz(aId, requestId, 0);
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
+nsresult
 SmsManager::Delete(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)
 {
   int requestId =
     SmsRequestManager::GetInstance()->CreateRequest(mOwner, mScriptContext, aRequest);
   NS_ASSERTION(*aRequest, "The request object must have been created!");
 
   nsCOMPtr<nsISmsDatabaseService> smsDBService =
     do_GetService(SMS_DATABASE_SERVICE_CONTRACTID);
   NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE);
 
   smsDBService->DeleteMessage(aId, requestId, 0);
 
   return NS_OK;
 }
 
+NS_IMETHODIMP
+SmsManager::Delete(const jsval& aParam, nsIDOMMozSmsRequest** aRequest)
+{
+  if (aParam.isInt32()) {
+    return Delete(aParam.toInt32(), aRequest);
+  }
+
+  if (!aParam.isObject()) {
+    return NS_ERROR_INVALID_ARG;
+  }
+
+  nsCOMPtr<nsIDOMMozSmsMessage> message =
+    do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(
+          mScriptContext->GetNativeContext(), &aParam.toObject()));
+  NS_ENSURE_TRUE(message, NS_ERROR_INVALID_ARG);
+
+  PRInt32 id;
+  message->GetId(&id);
+
+  return Delete(id, aRequest);
+}
+
 NS_IMPL_EVENT_HANDLER(SmsManager, received)
 NS_IMPL_EVENT_HANDLER(SmsManager, sent)
 NS_IMPL_EVENT_HANDLER(SmsManager, delivered)
 
 nsresult
 SmsManager::DispatchTrustedSmsEventToSelf(const nsAString& aEventName, nsIDOMMozSmsMessage* aMessage)
 {
   nsRefPtr<nsDOMEvent> event = new SmsEvent(nsnull, nsnull);
--- a/dom/sms/src/SmsManager.h
+++ b/dom/sms/src/SmsManager.h
@@ -67,16 +67,21 @@ public:
 
 private:
   /**
    * Internal Send() method used to send one message.
    */
   nsresult Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
                 const nsAString& aMessage, jsval* aRequest);
 
+  /**
+   * Internal Delete() method used to delete a message.
+   */
+  nsresult Delete(PRInt32 aId, nsIDOMMozSmsRequest** aRequest);
+
   nsresult DispatchTrustedSmsEventToSelf(const nsAString& aEventName,
                                          nsIDOMMozSmsMessage* aMessage);
   NS_DECL_EVENT_HANDLER(received)
   NS_DECL_EVENT_HANDLER(sent)
   NS_DECL_EVENT_HANDLER(delivered)
 };
 
 } // namespace sms