mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 674725 - Part X - Use SmsRequest for send() method. r=smaug,cjones
This commit is contained in:
parent
de42946157
commit
fcf1028f48
@ -37,12 +37,13 @@
|
||||
#include "nsIDOMEventTarget.idl"
|
||||
|
||||
interface nsIDOMEventListener;
|
||||
interface nsIDOMMozSmsRequest;
|
||||
|
||||
[scriptable, function, uuid(09a74bd3-466d-4612-926e-672b021fd08f)]
|
||||
[scriptable, function, uuid(1c1f23d7-5f4e-40bf-859b-82e8faa36041)]
|
||||
interface nsIDOMMozSmsManager : nsIDOMEventTarget
|
||||
{
|
||||
unsigned short getNumberOfMessagesForText(in DOMString text);
|
||||
void send(in DOMString number, in DOMString message);
|
||||
unsigned short getNumberOfMessagesForText(in DOMString text);
|
||||
nsIDOMMozSmsRequest send(in DOMString number, in DOMString message);
|
||||
|
||||
attribute nsIDOMEventListener onreceived;
|
||||
attribute nsIDOMEventListener onsent;
|
||||
|
@ -49,7 +49,8 @@ interface nsISmsService : nsISupports
|
||||
{
|
||||
boolean hasSupport();
|
||||
unsigned short getNumberOfMessagesForText(in DOMString text);
|
||||
void send(in DOMString number, in DOMString message);
|
||||
void send(in DOMString number, in DOMString message,
|
||||
in long requestId, [optional] in unsigned long long processId);
|
||||
|
||||
[implicit_jscontext]
|
||||
nsIDOMMozSmsMessage createSmsMessage(in long id,
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include "Constants.h"
|
||||
#include "SmsEvent.h"
|
||||
#include "nsIDOMSmsMessage.h"
|
||||
#include "nsIDOMSmsRequest.h"
|
||||
#include "SmsRequestManager.h"
|
||||
|
||||
/**
|
||||
* We have to use macros here because our leak analysis tool things we are
|
||||
@ -127,12 +129,18 @@ SmsManager::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsManager::Send(const nsAString& aNumber, const nsAString& aMessage)
|
||||
SmsManager::Send(const nsAString& aNumber, const nsAString& aMessage, nsIDOMMozSmsRequest** aRequest)
|
||||
{
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(smsService, NS_OK);
|
||||
|
||||
smsService->Send(aNumber, aMessage);
|
||||
int requestId =
|
||||
SmsRequestManager::GetInstance()->CreateRequest(mOwner, mScriptContext, aRequest);
|
||||
NS_ASSERTION(*aRequest, "The request object must have been created!");
|
||||
|
||||
NS_ADDREF(*aRequest);
|
||||
|
||||
smsService->Send(aNumber, aMessage, requestId, 0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SmsRequest,
|
||||
nsDOMEventTargetWrapperCache)
|
||||
if (tmp->mResultRooted) {
|
||||
tmp->mResult = JSVAL_NULL;
|
||||
tmp->mResult = JSVAL_VOID;
|
||||
tmp->UnrootResult();
|
||||
}
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(success)
|
||||
@ -87,7 +87,7 @@ NS_IMPL_EVENT_HANDLER(SmsRequest, success)
|
||||
NS_IMPL_EVENT_HANDLER(SmsRequest, error)
|
||||
|
||||
SmsRequest::SmsRequest(nsPIDOMWindow* aWindow, nsIScriptContext* aScriptContext)
|
||||
: mResult(JSVAL_NULL)
|
||||
: mResult(JSVAL_VOID)
|
||||
, mResultRooted(false)
|
||||
, mError(eNoError)
|
||||
, mDone(false)
|
||||
@ -125,7 +125,7 @@ SmsRequest::SetSuccess(nsIDOMMozSmsMessage* aMessage)
|
||||
{
|
||||
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!");
|
||||
NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");
|
||||
|
||||
JSContext* cx = mScriptContext->GetNativeContext();
|
||||
NS_ASSERTION(cx, "Failed to get a context!");
|
||||
@ -144,7 +144,7 @@ SmsRequest::SetSuccess(nsIDOMMozSmsMessage* aMessage)
|
||||
|
||||
if (NS_FAILED(nsContentUtils::WrapNative(cx, global, aMessage, &mResult))) {
|
||||
UnrootResult();
|
||||
mResult = JSVAL_NULL;
|
||||
mResult = JSVAL_VOID;
|
||||
SetError(eInternalError);
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ 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_NULL, "mResult shouldn't have been set!");
|
||||
NS_PRECONDITION(mResult == JSVAL_VOID, "mResult shouldn't have been set!");
|
||||
|
||||
mDone = true;
|
||||
mError = aError;
|
||||
@ -185,7 +185,7 @@ SmsRequest::GetError(nsAString& aError)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_ASSERTION(mError == eNoError || mResult == JSVAL_NULL,
|
||||
NS_ASSERTION(mError == eNoError || mResult == JSVAL_VOID,
|
||||
"mResult should be void when there is an error!");
|
||||
|
||||
switch (mError) {
|
||||
@ -204,10 +204,10 @@ NS_IMETHODIMP
|
||||
SmsRequest::GetResult(jsval* aResult)
|
||||
{
|
||||
if (!mDone) {
|
||||
NS_ASSERTION(mResult == JSVAL_NULL,
|
||||
NS_ASSERTION(mResult == JSVAL_VOID,
|
||||
"When not done, result should be null!");
|
||||
|
||||
*aResult = JSVAL_NULL;
|
||||
*aResult = JSVAL_VOID;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,15 @@
|
||||
|
||||
#include "SmsRequestManager.h"
|
||||
#include "SmsRequest.h"
|
||||
#include "nsIDOMSmsMessage.h"
|
||||
#include "nsDOMEvent.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")
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -94,6 +103,37 @@ SmsRequestManager::CreateRequest(nsPIDOMWindow* aWindow,
|
||||
return size;
|
||||
}
|
||||
|
||||
nsresult
|
||||
SmsRequestManager::DispatchTrustedEventToRequest(const nsAString& aEventName,
|
||||
nsIDOMMozSmsRequest* aRequest)
|
||||
{
|
||||
nsRefPtr<nsDOMEvent> event = new nsDOMEvent(nsnull, nsnull);
|
||||
nsresult rv = event->InitEvent(aEventName, false, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = event->SetTrusted(PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
bool dummy;
|
||||
return aRequest->DispatchEvent(event, &dummy);
|
||||
}
|
||||
|
||||
void
|
||||
SmsRequestManager::NotifySmsSent(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage)
|
||||
{
|
||||
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]);
|
||||
request->SetSuccess(aMessage);
|
||||
|
||||
DispatchTrustedEventToRequest(SUCCESS_EVENT_NAME, request);
|
||||
|
||||
mRequests.ReplaceObjectAt(nsnull, aRequestId);
|
||||
}
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -44,6 +44,7 @@
|
||||
class nsIDOMMozSmsRequest;
|
||||
class nsPIDOMWindow;
|
||||
class nsIScriptContext;
|
||||
class nsIDOMMozSmsMessage;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -60,9 +61,14 @@ public:
|
||||
nsIScriptContext* aScriptContext,
|
||||
nsIDOMMozSmsRequest** aRequest);
|
||||
|
||||
void NotifySmsSent(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage);
|
||||
|
||||
private:
|
||||
static SmsRequestManager* sInstance;
|
||||
|
||||
nsresult DispatchTrustedEventToRequest(const nsAString& aEventName,
|
||||
nsIDOMMozSmsRequest* aRequest);
|
||||
|
||||
nsCOMArray<nsIDOMMozSmsRequest> mRequests;
|
||||
};
|
||||
|
||||
|
@ -67,13 +67,15 @@ SmsService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::Send(const nsAString& aNumber, const nsAString& aMessage)
|
||||
SmsService::Send(const nsAString& aNumber, const nsAString& aMessage,
|
||||
PRInt32 aRequestId, PRUint64 aProcessId)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
AndroidBridge::Bridge()->SendMessage(aNumber, aMessage);
|
||||
AndroidBridge::Bridge()->SendMessage(aNumber, aMessage, aRequestId,
|
||||
aProcessId);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,8 @@ SmsService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::Send(const nsAString& aNumber, const nsAString& aMessage)
|
||||
SmsService::Send(const nsAString& aNumber, const nsAString& aMessage,
|
||||
PRInt32 aRequestId, PRUint64 aProcessId)
|
||||
{
|
||||
NS_ERROR("We should not be here!");
|
||||
return NS_OK;
|
||||
|
@ -65,6 +65,9 @@ child:
|
||||
|
||||
NotifyDeliveredMessage(SmsMessageData aMessageData);
|
||||
|
||||
NotifyRequestSmsSent(SmsMessageData aMessageData, PRInt32 aRequestId,
|
||||
PRUint64 aProcessId);
|
||||
|
||||
parent:
|
||||
sync HasSupport()
|
||||
returns (bool aHasSupport);
|
||||
@ -72,7 +75,8 @@ parent:
|
||||
sync GetNumberOfMessagesForText(nsString aText)
|
||||
returns (PRUint16 aNumber);
|
||||
|
||||
SendMessage(nsString aNumber, nsString aMessage);
|
||||
SendMessage(nsString aNumber, nsString aMessage, PRInt32 aRequestId,
|
||||
PRUint64 aProcessId);
|
||||
|
||||
sync SaveSentMessage(nsString aReceiver, nsString aBody, PRUint64 aDate)
|
||||
returns (PRInt32 aId);
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include "Constants.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "SmsRequestManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -87,6 +89,21 @@ SmsChild::RecvNotifyDeliveredMessage(const SmsMessageData& aMessageData)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyRequestSmsSent(const SmsMessageData& aMessage,
|
||||
const PRInt32& aRequestId,
|
||||
const PRUint64& aProcessId)
|
||||
{
|
||||
if (ContentChild::GetSingleton()->GetID() != aProcessId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(aMessage);
|
||||
SmsRequestManager::GetInstance()->NotifySmsSent(aRequestId, message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
NS_OVERRIDE virtual bool RecvNotifyReceivedMessage(const SmsMessageData& aMessage);
|
||||
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);
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
@ -80,9 +80,11 @@ SmsIPCService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aRes
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::Send(const nsAString& aNumber, const nsAString& aMessage)
|
||||
SmsIPCService::Send(const nsAString& aNumber, const nsAString& aMessage,
|
||||
PRInt32 aRequestId, PRUint64 aProcessId)
|
||||
{
|
||||
GetSmsChild()->SendSendMessage(nsString(aNumber), nsString(aMessage));
|
||||
GetSmsChild()->SendSendMessage(nsString(aNumber), nsString(aMessage),
|
||||
aRequestId, ContentChild::GetSingleton()->GetID());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -49,10 +49,29 @@ namespace mozilla {
|
||||
namespace dom {
|
||||
namespace sms {
|
||||
|
||||
nsTArray<SmsParent*>* SmsParent::gSmsParents = nsnull;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(SmsParent, nsIObserver)
|
||||
|
||||
/* static */ void
|
||||
SmsParent::GetAll(nsTArray<SmsParent*>& aArray)
|
||||
{
|
||||
if (!gSmsParents) {
|
||||
aArray.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
aArray = *gSmsParents;
|
||||
}
|
||||
|
||||
SmsParent::SmsParent()
|
||||
{
|
||||
if (!gSmsParents) {
|
||||
gSmsParents = new nsTArray<SmsParent*>();
|
||||
}
|
||||
|
||||
gSmsParents->AppendElement(this);
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
@ -74,6 +93,13 @@ SmsParent::ActorDestroy(ActorDestroyReason why)
|
||||
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsSentObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsDeliveredObserverTopic);
|
||||
|
||||
NS_ASSERTION(gSmsParents, "gSmsParents can't be null at that point!");
|
||||
gSmsParents->RemoveElement(this);
|
||||
if (gSmsParents->Length() == 0) {
|
||||
delete gSmsParents;
|
||||
gSmsParents = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -141,12 +167,13 @@ SmsParent::RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResu
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvSendMessage(const nsString& aNumber, const nsString& aMessage)
|
||||
SmsParent::RecvSendMessage(const nsString& aNumber, const nsString& aMessage,
|
||||
const PRInt32& aRequestId, const PRUint64& aProcessId)
|
||||
{
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(smsService, true);
|
||||
|
||||
smsService->Send(aNumber, aMessage);
|
||||
smsService->Send(aNumber, aMessage, aRequestId, aProcessId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -52,15 +52,20 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
static void GetAll(nsTArray<SmsParent*>& aArray);
|
||||
|
||||
SmsParent();
|
||||
|
||||
NS_OVERRIDE virtual bool RecvHasSupport(bool* aHasSupport);
|
||||
NS_OVERRIDE virtual bool RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResult);
|
||||
NS_OVERRIDE virtual bool RecvSendMessage(const nsString& aNumber, const nsString& aMessage);
|
||||
NS_OVERRIDE virtual bool RecvSendMessage(const nsString& aNumber, const nsString& aMessage, const PRInt32& aRequestId, const PRUint64& aProcessId);
|
||||
NS_OVERRIDE virtual bool RecvSaveSentMessage(const nsString& aRecipient, const nsString& aBody, const PRUint64& aDate, PRInt32* aId);
|
||||
|
||||
protected:
|
||||
virtual void ActorDestroy(ActorDestroyReason why);
|
||||
|
||||
private:
|
||||
static nsTArray<SmsParent*>* gSmsParents;
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
@ -123,7 +123,7 @@ public class GeckoAppShell
|
||||
|
||||
public static native void notifySmsReceived(String aSender, String aBody, long aTimestamp);
|
||||
public static native int saveMessageInSentbox(String aReceiver, String aBody, long aTimestamp);
|
||||
public static native void notifySmsSent(int aId, String aReceiver, String aBody, long aTimestamp);
|
||||
public static native void notifySmsSent(int aId, String aReceiver, String aBody, long aTimestamp, int aRequestId, long aProcessId);
|
||||
public static native void notifySmsDelivered(int aId, String aReceiver, String aBody, long aTimestamp);
|
||||
|
||||
// A looper thread, accessed by GeckoAppShell.getHandler
|
||||
@ -1695,8 +1695,8 @@ public class GeckoAppShell
|
||||
return GeckoSmsManager.getNumberOfMessagesForText(aText);
|
||||
}
|
||||
|
||||
public static void sendMessage(String aNumber, String aMessage) {
|
||||
GeckoSmsManager.send(aNumber, aMessage);
|
||||
public static void sendMessage(String aNumber, String aMessage, int aRequestId, long aProcessId) {
|
||||
GeckoSmsManager.send(aNumber, aMessage, aRequestId, aProcessId);
|
||||
}
|
||||
|
||||
public static int saveSentMessage(String aRecipient, String aBody, long aDate) {
|
||||
|
@ -254,8 +254,9 @@ public class GeckoSmsManager
|
||||
Bundle bundle = intent.getExtras();
|
||||
|
||||
if (bundle == null || !bundle.containsKey("envelopeId") ||
|
||||
!bundle.containsKey("number") || !bundle.containsKey("message")) {
|
||||
Log.e("GeckoSmsManager", "Got an invalid ACTION_SMS_SENT!");
|
||||
!bundle.containsKey("number") || !bundle.containsKey("message") ||
|
||||
!bundle.containsKey("requestId") || !bundle.containsKey("processId")) {
|
||||
Log.e("GeckoSmsManager", "Got an invalid ACTION_SMS_SENT/ACTION_SMS_DELIVERED!");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -301,7 +302,9 @@ public class GeckoSmsManager
|
||||
|
||||
int id = GeckoAppShell.saveMessageInSentbox(number, message, timestamp);
|
||||
|
||||
GeckoAppShell.notifySmsSent(id, number, message, timestamp);
|
||||
GeckoAppShell.notifySmsSent(id, number, message, timestamp,
|
||||
bundle.getInt("requestId"),
|
||||
bundle.getLong("processId"));
|
||||
|
||||
envelope.setMessageId(id);
|
||||
envelope.setMessageTimestamp(timestamp);
|
||||
@ -330,7 +333,7 @@ public class GeckoSmsManager
|
||||
return SmsManager.getDefault().divideMessage(aText).size();
|
||||
}
|
||||
|
||||
public static void send(String aNumber, String aMessage) {
|
||||
public static void send(String aNumber, String aMessage, int aRequestId, long aProcessId) {
|
||||
/*
|
||||
* TODO:
|
||||
* This is a basic send method that doesn't handle errors and doesn't listen to
|
||||
@ -347,6 +350,8 @@ public class GeckoSmsManager
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("number", aNumber);
|
||||
bundle.putString("message", aMessage);
|
||||
bundle.putInt("requestId", aRequestId);
|
||||
bundle.putLong("processId", aProcessId);
|
||||
|
||||
if (aMessage.length() <= kMaxMessageSize) {
|
||||
envelopeId = Postman.getInstance().createEnvelope(1);
|
||||
|
@ -198,6 +198,42 @@ Java_org_mozilla_gecko_GeckoAppShell_ ## name(JNIEnv *jenv, jclass jc, type1 one
|
||||
return f_ ## name(jenv, jc, one, two, three, four); \
|
||||
}
|
||||
|
||||
#define SHELL_WRAPPER5(name,type1,type2,type3,type4,type5) \
|
||||
typedef void (*name ## _t)(JNIEnv *, jclass, type1 one, type2 two, type3 three, type4 four, type5 five); \
|
||||
static name ## _t f_ ## name; \
|
||||
extern "C" NS_EXPORT void JNICALL \
|
||||
Java_org_mozilla_gecko_GeckoAppShell_ ## name(JNIEnv *jenv, jclass jc, type1 one, type2 two, type3 three, type4 four, type5 five) \
|
||||
{ \
|
||||
f_ ## name(jenv, jc, one, two, three, four, five); \
|
||||
}
|
||||
|
||||
#define SHELL_WRAPPER5_WITH_RETURN(name, return_type, type1, type2, type3, type4, type5) \
|
||||
typedef return_type (*name ## _t)(JNIEnv *, jclass, type1 one, type2 two, type3 three, type4 four, type5 five); \
|
||||
static name ## _t f_ ## name; \
|
||||
extern "C" NS_EXPORT return_type JNICALL \
|
||||
Java_org_mozilla_gecko_GeckoAppShell_ ## name(JNIEnv *jenv, jclass jc, type1 one, type2 two, type3 three, type4 four, type5 five) \
|
||||
{ \
|
||||
return f_ ## name(jenv, jc, one, two, three, four, five); \
|
||||
}
|
||||
|
||||
#define SHELL_WRAPPER6(name,type1,type2,type3,type4,type5,type6) \
|
||||
typedef void (*name ## _t)(JNIEnv *, jclass, type1 one, type2 two, type3 three, type4 four, type5 five, type6 six); \
|
||||
static name ## _t f_ ## name; \
|
||||
extern "C" NS_EXPORT void JNICALL \
|
||||
Java_org_mozilla_gecko_GeckoAppShell_ ## name(JNIEnv *jenv, jclass jc, type1 one, type2 two, type3 three, type4 four, type5 five, type6 six) \
|
||||
{ \
|
||||
f_ ## name(jenv, jc, one, two, three, four, five, six); \
|
||||
}
|
||||
|
||||
#define SHELL_WRAPPER6_WITH_RETURN(name, return_type, type1, type2, type3, type4, type5, type6) \
|
||||
typedef return_type (*name ## _t)(JNIEnv *, jclass, type1 one, type2 two, type3 three, type4 four, type5 five, type6 six); \
|
||||
static name ## _t f_ ## name; \
|
||||
extern "C" NS_EXPORT return_type JNICALL \
|
||||
Java_org_mozilla_gecko_GeckoAppShell_ ## name(JNIEnv *jenv, jclass jc, type1 one, type2 two, type3 three, type4 four, type5 five, type6 six) \
|
||||
{ \
|
||||
return f_ ## name(jenv, jc, one, two, three, four, five, six); \
|
||||
}
|
||||
|
||||
SHELL_WRAPPER0(nativeInit)
|
||||
SHELL_WRAPPER1(nativeRun, jstring)
|
||||
SHELL_WRAPPER1(notifyGeckoOfEvent, jobject)
|
||||
@ -217,7 +253,7 @@ SHELL_WRAPPER3(notifySmsReceived, jstring, jstring, jlong);
|
||||
SHELL_WRAPPER0(bindWidgetTexture);
|
||||
SHELL_WRAPPER0_WITH_RETURN(testDirectTexture, bool);
|
||||
SHELL_WRAPPER3_WITH_RETURN(saveMessageInSentbox, jint, jstring, jstring, jlong);
|
||||
SHELL_WRAPPER4(notifySmsSent, jint, jstring, jstring, jlong);
|
||||
SHELL_WRAPPER6(notifySmsSent, jint, jstring, jstring, jlong, jint, jlong);
|
||||
SHELL_WRAPPER4(notifySmsDelivered, jint, jstring, jstring, jlong);
|
||||
|
||||
static void * xul_handle = NULL;
|
||||
|
@ -167,7 +167,7 @@ AndroidBridge::Init(JNIEnv *jEnv,
|
||||
jMarkUriVisited = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "markUriVisited", "(Ljava/lang/String;)V");
|
||||
|
||||
jNumberOfMessages = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getNumberOfMessagesForText", "(Ljava/lang/String;)I");
|
||||
jSendMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "sendMessage", "(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
jSendMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "sendMessage", "(Ljava/lang/String;Ljava/lang/String;IJ)V");
|
||||
jSaveSentMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "saveSentMessage", "(Ljava/lang/String;Ljava/lang/String;J)I");
|
||||
|
||||
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
|
||||
@ -1343,7 +1343,7 @@ AndroidBridge::GetNumberOfMessagesForText(const nsAString& aText)
|
||||
}
|
||||
|
||||
void
|
||||
AndroidBridge::SendMessage(const nsAString& aNumber, const nsAString& aMessage)
|
||||
AndroidBridge::SendMessage(const nsAString& aNumber, const nsAString& aMessage, PRInt32 aRequestId, PRUint64 aProcessId)
|
||||
{
|
||||
ALOG_BRIDGE("AndroidBridge::SendMessage");
|
||||
|
||||
@ -1351,7 +1351,7 @@ AndroidBridge::SendMessage(const nsAString& aNumber, const nsAString& aMessage)
|
||||
jstring jNumber = GetJNIForThread()->NewString(PromiseFlatString(aNumber).get(), aNumber.Length());
|
||||
jstring jMessage = GetJNIForThread()->NewString(PromiseFlatString(aMessage).get(), aMessage.Length());
|
||||
|
||||
GetJNIForThread()->CallStaticVoidMethod(mGeckoAppShellClass, jSendMessage, jNumber, jMessage);
|
||||
GetJNIForThread()->CallStaticVoidMethod(mGeckoAppShellClass, jSendMessage, jNumber, jMessage, aRequestId, aProcessId);
|
||||
}
|
||||
|
||||
PRInt32
|
||||
|
@ -335,7 +335,7 @@ public:
|
||||
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
|
||||
|
||||
PRUint16 GetNumberOfMessagesForText(const nsAString& aText);
|
||||
void SendMessage(const nsAString& aNumber, const nsAString& aText);
|
||||
void SendMessage(const nsAString& aNumber, const nsAString& aText, PRInt32 aRequestId, PRUint64 aProcessId);
|
||||
PRInt32 SaveSentMessage(const nsAString& aRecipient, const nsAString& aBody, PRUint64 aDate);
|
||||
|
||||
bool IsTablet();
|
||||
|
@ -59,10 +59,14 @@
|
||||
#include "nsExceptionHandler.h"
|
||||
#endif
|
||||
|
||||
#include "mozilla/unused.h"
|
||||
|
||||
#include "mozilla/dom/sms/SmsMessage.h"
|
||||
#include "mozilla/dom/sms/Constants.h"
|
||||
#include "mozilla/dom/sms/Types.h"
|
||||
#include "mozilla/dom/sms/PSms.h"
|
||||
#include "mozilla/dom/sms/SmsRequestManager.h"
|
||||
#include "mozilla/dom/sms/SmsParent.h"
|
||||
#include "nsISmsDatabaseService.h"
|
||||
|
||||
using namespace mozilla;
|
||||
@ -87,7 +91,7 @@ extern "C" {
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass, jdouble, jboolean, jdouble);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsReceived(JNIEnv* jenv, jclass, jstring, jstring, jlong);
|
||||
NS_EXPORT PRInt32 JNICALL Java_org_mozilla_gecko_GeckoAppShell_saveMessageInSentbox(JNIEnv* jenv, jclass, jstring, jstring, jlong);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsSent(JNIEnv* jenv, jclass, jint, jstring, jstring, jlong);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsSent(JNIEnv* jenv, jclass, jint, jstring, jstring, jlong, jint, jlong);
|
||||
NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifySmsDelivered(JNIEnv* jenv, jclass, jint, jstring, jstring, jlong);
|
||||
|
||||
#ifdef MOZ_JAVA_COMPOSITOR
|
||||
@ -303,15 +307,24 @@ Java_org_mozilla_gecko_GeckoAppShell_notifySmsSent(JNIEnv* jenv, jclass,
|
||||
jint aId,
|
||||
jstring aReceiver,
|
||||
jstring aBody,
|
||||
jlong aTimestamp)
|
||||
jlong aTimestamp,
|
||||
jint aRequestId,
|
||||
jlong aProcessId)
|
||||
{
|
||||
class NotifySmsSentRunnable : public nsRunnable {
|
||||
public:
|
||||
NotifySmsSentRunnable(const SmsMessageData& aMessageData)
|
||||
NotifySmsSentRunnable(const SmsMessageData& aMessageData,
|
||||
PRInt32 aRequestId, PRUint64 aProcessId)
|
||||
: mMessageData(aMessageData)
|
||||
, mRequestId(aRequestId)
|
||||
, mProcessId(aProcessId)
|
||||
{}
|
||||
|
||||
NS_IMETHODIMP Run() {
|
||||
/*
|
||||
* First, we are going to notify all SmsManager that a message has
|
||||
* been sent. Then, we will notify the SmsRequest object about it.
|
||||
*/
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return NS_OK;
|
||||
@ -320,18 +333,33 @@ Java_org_mozilla_gecko_GeckoAppShell_notifySmsSent(JNIEnv* jenv, jclass,
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
||||
obs->NotifyObservers(message, kSmsSentObserverTopic, nsnull);
|
||||
|
||||
if (mProcessId == 0) { // Parent process.
|
||||
SmsRequestManager::GetInstance()->NotifySmsSent(mRequestId, message);
|
||||
} else { // Content process.
|
||||
nsTArray<SmsParent*> spList;
|
||||
SmsParent::GetAll(spList);
|
||||
|
||||
for (PRUint32 i=0; i<spList.Length(); ++i) {
|
||||
unused << spList[i]->SendNotifyRequestSmsSent(mMessageData,
|
||||
mRequestId,
|
||||
mProcessId);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
SmsMessageData mMessageData;
|
||||
PRInt32 mRequestId;
|
||||
PRUint64 mProcessId;
|
||||
};
|
||||
|
||||
SmsMessageData message(aId, eDeliveryState_Sent, EmptyString(),
|
||||
nsJNIString(aReceiver, jenv),
|
||||
nsJNIString(aBody, jenv), aTimestamp);
|
||||
|
||||
nsCOMPtr<nsIRunnable> runnable = new NotifySmsSentRunnable(message);
|
||||
nsCOMPtr<nsIRunnable> runnable = new NotifySmsSentRunnable(message, aRequestId, aProcessId);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user