mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 674725 - Part AO - Show the first message of message list in SmsCursor. r=smaug,cjones
This commit is contained in:
parent
9a97aef5ec
commit
06dc950ebe
@ -40,6 +40,7 @@
|
||||
#include "nsDOMError.h"
|
||||
#include "nsIDOMSmsFilter.h"
|
||||
#include "nsIDOMSmsMessage.h"
|
||||
#include "nsIDOMSmsRequest.h"
|
||||
|
||||
DOMCI_DATA(MozSmsCursor, mozilla::dom::sms::SmsCursor)
|
||||
|
||||
@ -53,7 +54,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SmsCursor)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsCursor)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_2(SmsCursor, mFilter, mMessage)
|
||||
NS_IMPL_CYCLE_COLLECTION_3(SmsCursor, mFilter, mRequest, mMessage)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(SmsCursor)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(SmsCursor)
|
||||
@ -63,6 +64,12 @@ SmsCursor::SmsCursor(nsIDOMMozSmsFilter* aFilter)
|
||||
{
|
||||
}
|
||||
|
||||
SmsCursor::SmsCursor(nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest)
|
||||
: mFilter(aFilter)
|
||||
, mRequest(aRequest)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsCursor::GetFilter(nsIDOMMozSmsFilter** aFilter)
|
||||
{
|
||||
@ -73,8 +80,7 @@ SmsCursor::GetFilter(nsIDOMMozSmsFilter** aFilter)
|
||||
NS_IMETHODIMP
|
||||
SmsCursor::GetMessage(nsIDOMMozSmsMessage** aMessage)
|
||||
{
|
||||
// TODO: implement
|
||||
*aMessage = nsnull;
|
||||
NS_IF_ADDREF(*aMessage = mMessage);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
|
||||
class nsIDOMMozSmsFilter;
|
||||
class nsIDOMMozSmsMessage;
|
||||
class nsIDOMMozSmsRequest;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -58,12 +59,22 @@ public:
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(SmsCursor)
|
||||
|
||||
SmsCursor(nsIDOMMozSmsFilter* aFilter);
|
||||
SmsCursor(nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest);
|
||||
|
||||
void SetMessage(nsIDOMMozSmsMessage* aMessage);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIDOMMozSmsFilter> mFilter;
|
||||
nsCOMPtr<nsIDOMMozSmsRequest> mRequest;
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> mMessage;
|
||||
};
|
||||
|
||||
inline void
|
||||
SmsCursor::SetMessage(nsIDOMMozSmsMessage* aMessage)
|
||||
{
|
||||
mMessage = aMessage;
|
||||
}
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -117,16 +117,22 @@ SmsRequestManager::DispatchTrustedEventToRequest(const nsAString& aEventName,
|
||||
return aRequest->DispatchEvent(event, &dummy);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void
|
||||
SmsRequestManager::NotifySuccess(PRInt32 aRequestId, T aParam)
|
||||
SmsRequest*
|
||||
SmsRequestManager::GetRequest(PRInt32 aRequestId)
|
||||
{
|
||||
NS_ASSERTION(mRequests.Count() > aRequestId && mRequests[aRequestId],
|
||||
"Got an invalid request id or it has been already deleted!");
|
||||
|
||||
// It's safe to use the static_cast here given that we did call
|
||||
// |new SmsRequest()|.
|
||||
SmsRequest* request = static_cast<SmsRequest*>(mRequests[aRequestId]);
|
||||
return static_cast<SmsRequest*>(mRequests[aRequestId]);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void
|
||||
SmsRequestManager::NotifySuccess(PRInt32 aRequestId, T aParam)
|
||||
{
|
||||
SmsRequest* request = GetRequest(aRequestId);
|
||||
request->SetSuccess(aParam);
|
||||
|
||||
DispatchTrustedEventToRequest(SUCCESS_EVENT_NAME, request);
|
||||
@ -137,12 +143,7 @@ SmsRequestManager::NotifySuccess(PRInt32 aRequestId, T aParam)
|
||||
void
|
||||
SmsRequestManager::NotifyError(PRInt32 aRequestId, SmsRequest::ErrorType aError)
|
||||
{
|
||||
NS_ASSERTION(mRequests.Count() > aRequestId && mRequests[aRequestId],
|
||||
"Got an invalid request id or it has been already deleted!");
|
||||
|
||||
// It's safe to use the static_cast here given that we did call
|
||||
// |new SmsRequest()|.
|
||||
SmsRequest* request = static_cast<SmsRequest*>(mRequests[aRequestId]);
|
||||
SmsRequest* request = GetRequest(aRequestId);
|
||||
request->SetError(aError);
|
||||
|
||||
DispatchTrustedEventToRequest(ERROR_EVENT_NAME, request);
|
||||
@ -196,6 +197,19 @@ SmsRequestManager::NotifyNoMessageInList(PRInt32 aRequestId)
|
||||
NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
|
||||
}
|
||||
|
||||
void
|
||||
SmsRequestManager::NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId,
|
||||
nsIDOMMozSmsMessage* aMessage)
|
||||
{
|
||||
// TODO: use Filter!
|
||||
SmsRequest* request = GetRequest(aRequestId);
|
||||
|
||||
nsCOMPtr<SmsCursor> cursor = new SmsCursor(nsnull, request);
|
||||
cursor->SetMessage(aMessage);
|
||||
|
||||
NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
|
||||
}
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -69,12 +69,15 @@ public:
|
||||
void NotifySmsDeleted(PRInt32 aRequestId, bool aDeleted);
|
||||
void NotifySmsDeleteFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError);
|
||||
void NotifyNoMessageInList(PRInt32 aRequestId);
|
||||
void NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId, nsIDOMMozSmsMessage* aMessage);
|
||||
|
||||
private:
|
||||
static SmsRequestManager* sInstance;
|
||||
|
||||
nsresult DispatchTrustedEventToRequest(const nsAString& aEventName,
|
||||
nsIDOMMozSmsRequest* aRequest);
|
||||
SmsRequest* GetRequest(PRInt32 aRequestId);
|
||||
|
||||
template <class T>
|
||||
void NotifySuccess(PRInt32 aRequestId, T aParam);
|
||||
void NotifyError(PRInt32 aRequestId, SmsRequest::ErrorType aError);
|
||||
|
@ -92,6 +92,8 @@ child:
|
||||
|
||||
NotifyRequestNoMessageInList(PRInt32 aRequestId, PRUint64 aProcessId);
|
||||
|
||||
NotifyRequestCreateMessageList(PRInt32 aListId, SmsMessageData aMessageData, PRInt32 aRequestId, PRUint64 aProcessId);
|
||||
|
||||
parent:
|
||||
sync HasSupport()
|
||||
returns (bool aHasSupport);
|
||||
|
@ -191,6 +191,21 @@ SmsChild::RecvNotifyRequestNoMessageInList(const PRInt32& aRequestId,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyRequestCreateMessageList(const PRInt32& aListId,
|
||||
const SmsMessageData& aMessageData,
|
||||
const PRInt32& aRequestId,
|
||||
const PRUint64& aProcessId)
|
||||
{
|
||||
if (ContentChild::GetSingleton()->GetID() != aProcessId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(aMessageData);
|
||||
SmsRequestManager::GetInstance()->NotifyCreateMessageList(aRequestId, aListId, message);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
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);
|
||||
NS_OVERRIDE virtual bool RecvNotifyRequestCreateMessageList(const PRInt32& aListId, const SmsMessageData& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
@ -678,9 +678,66 @@ Java_org_mozilla_gecko_GeckoAppShell_notifyNoMessageInList(JNIEnv* jenv, jclass,
|
||||
}
|
||||
|
||||
NS_EXPORT void JNICALL
|
||||
Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass, jint, jint, jstring, jstring, jstring, jlong, jint, jlong)
|
||||
Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass,
|
||||
jint aListId,
|
||||
jint aMessageId,
|
||||
jstring aReceiver,
|
||||
jstring aSender,
|
||||
jstring aBody,
|
||||
jlong aTimestamp,
|
||||
jint aRequestId,
|
||||
jlong aProcessId)
|
||||
{
|
||||
// TODO: implement
|
||||
class NotifyCreateMessageListRunnable : public nsRunnable {
|
||||
public:
|
||||
NotifyCreateMessageListRunnable(PRInt32 aListId,
|
||||
const SmsMessageData& aMessage,
|
||||
PRInt32 aRequestId, PRUint64 aProcessId)
|
||||
: mListId(aListId)
|
||||
, mMessage(aMessage)
|
||||
, mRequestId(aRequestId)
|
||||
, mProcessId(aProcessId)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP Run() {
|
||||
if (mProcessId == 0) { // Parent process.
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessage);
|
||||
SmsRequestManager::GetInstance()->NotifyCreateMessageList(mRequestId,
|
||||
mListId,
|
||||
message);
|
||||
} else { // Content process.
|
||||
nsTArray<SmsParent*> spList;
|
||||
SmsParent::GetAll(spList);
|
||||
|
||||
for (PRUint32 i=0; i<spList.Length(); ++i) {
|
||||
unused << spList[i]->SendNotifyRequestCreateMessageList(mListId,
|
||||
mMessage,
|
||||
mRequestId,
|
||||
mProcessId);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
PRInt32 mListId;
|
||||
SmsMessageData mMessage;
|
||||
PRInt32 mRequestId;
|
||||
PRUint64 mProcessId;
|
||||
};
|
||||
|
||||
|
||||
nsJNIString receiver = nsJNIString(aReceiver, jenv);
|
||||
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
||||
: eDeliveryState_Sent;
|
||||
|
||||
SmsMessageData message(aMessageId, state, nsJNIString(aSender, jenv),
|
||||
receiver, nsJNIString(aBody, jenv), aTimestamp);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable =
|
||||
new NotifyCreateMessageListRunnable(aListId, message, aRequestId, aProcessId);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
#ifdef MOZ_JAVA_COMPOSITOR
|
||||
|
Loading…
Reference in New Issue
Block a user