Bug 674725 - Part AN - Handling no messages in created message list. r=smaug,cjones

This commit is contained in:
Mounir Lamouri 2011-12-19 12:04:53 +01:00
parent 3b8b1cdf6a
commit c6598ac290
8 changed files with 102 additions and 16 deletions

View File

@ -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

View File

@ -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;

View File

@ -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<nsIDOMMozSmsCursor> cursor = new SmsCursor(nsnull);
NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@ -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;

View File

@ -90,6 +90,8 @@ child:
NotifyRequestSmsDeleteFailed(PRInt32 aError, PRInt32 aRequestId,
PRUint64 aProcessId);
NotifyRequestNoMessageInList(PRInt32 aRequestId, PRUint64 aProcessId);
parent:
sync HasSupport()
returns (bool aHasSupport);

View File

@ -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

View File

@ -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

View File

@ -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<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