Bug 674725 - Part AH - Allow to pass a SmsMessage or an id to delete(). r=mrbkap

This commit is contained in:
Mounir Lamouri 2011-12-20 17:16:20 +01:00
parent b9b285610f
commit cf192649bb
3 changed files with 32 additions and 2 deletions

View File

@ -51,7 +51,9 @@ interface nsIDOMMozSmsManager : nsIDOMEventTarget
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;

View File

@ -48,6 +48,7 @@
#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
@ -227,7 +228,7 @@ SmsManager::GetMessageMoz(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)
return NS_OK;
}
NS_IMETHODIMP
nsresult
SmsManager::Delete(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)
{
int requestId =
@ -243,6 +244,28 @@ SmsManager::Delete(PRInt32 aId, nsIDOMMozSmsRequest** aRequest)
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)

View File

@ -72,6 +72,11 @@ private:
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)