зеркало из https://github.com/mozilla/pjs.git
Bug 674725 - Part S - Implement WebSMS sent event. r=cjones,smaug
This commit is contained in:
Родитель
90b3769112
Коммит
16935841ef
|
@ -38,11 +38,12 @@
|
|||
|
||||
interface nsIDOMEventListener;
|
||||
|
||||
[scriptable, function, uuid(807d593c-09cb-4aa3-afa5-aa0a671bd0d3)]
|
||||
[scriptable, function, uuid(e5da0085-2113-4f17-9d29-ed6fe98780a8)]
|
||||
interface nsIDOMMozSmsManager : nsIDOMEventTarget
|
||||
{
|
||||
unsigned short getNumberOfMessagesForText(in DOMString text);
|
||||
void send(in DOMString number, in DOMString message);
|
||||
|
||||
attribute nsIDOMEventListener onreceived;
|
||||
attribute nsIDOMEventListener onsent;
|
||||
};
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace dom {
|
|||
namespace sms {
|
||||
|
||||
const char* kSmsReceivedObserverTopic = "sms-received";
|
||||
const char* kSmsSentObserverTopic = "sms-sent";
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace dom {
|
|||
namespace sms {
|
||||
|
||||
extern const char* kSmsReceivedObserverTopic; // Defined in the .cpp.
|
||||
extern const char* kSmsSentObserverTopic; // Defined in the .cpp.
|
||||
|
||||
#define DELIVERY_RECEIVED NS_LITERAL_STRING("received")
|
||||
#define DELIVERY_SENT NS_LITERAL_STRING("sent")
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
* 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")
|
||||
|
||||
DOMCI_DATA(MozSmsManager, mozilla::dom::sms::SmsManager)
|
||||
|
||||
|
@ -61,11 +62,13 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(SmsManager)
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SmsManager,
|
||||
nsDOMEventTargetWrapperCache)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(received)
|
||||
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(sent)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(SmsManager,
|
||||
nsDOMEventTargetWrapperCache)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(received)
|
||||
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(sent)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SmsManager)
|
||||
|
@ -91,6 +94,7 @@ SmsManager::Init(nsPIDOMWindow *aWindow, nsIScriptContext* aScriptContext)
|
|||
}
|
||||
|
||||
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsSentObserverTopic, false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -103,6 +107,7 @@ SmsManager::Shutdown()
|
|||
}
|
||||
|
||||
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsSentObserverTopic);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -128,6 +133,7 @@ SmsManager::Send(const nsAString& aNumber, const nsAString& aMessage)
|
|||
}
|
||||
|
||||
NS_IMPL_EVENT_HANDLER(SmsManager, received)
|
||||
NS_IMPL_EVENT_HANDLER(SmsManager, sent)
|
||||
|
||||
nsresult
|
||||
SmsManager::DispatchTrustedSmsEventToSelf(const nsAString& aEventName, nsIDOMMozSmsMessage* aMessage)
|
||||
|
@ -159,6 +165,18 @@ SmsManager::Observe(nsISupports* aSubject, const char* aTopic,
|
|||
}
|
||||
|
||||
DispatchTrustedSmsEventToSelf(RECEIVED_EVENT_NAME, message);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsSentObserverTopic)) {
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
|
||||
if (!message) {
|
||||
NS_ERROR("Got a 'sms-sent' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
DispatchTrustedSmsEventToSelf(SENT_EVENT_NAME, message);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -69,6 +69,7 @@ private:
|
|||
nsresult DispatchTrustedSmsEventToSelf(const nsAString& aEventName,
|
||||
nsIDOMMozSmsMessage* aMessage);
|
||||
NS_DECL_EVENT_HANDLER(received)
|
||||
NS_DECL_EVENT_HANDLER(sent)
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
|
|
@ -57,6 +57,13 @@ NS_INTERFACE_MAP_END
|
|||
NS_IMPL_ADDREF(SmsMessage)
|
||||
NS_IMPL_RELEASE(SmsMessage)
|
||||
|
||||
SmsMessage::SmsMessage(PRInt32 aId, DeliveryState aDelivery,
|
||||
const nsString& aSender, const nsString& aReceiver,
|
||||
const nsString& aBody, PRUint64 aTimestamp)
|
||||
: mData(aId, aDelivery, aSender, aReceiver, aBody, aTimestamp)
|
||||
{
|
||||
}
|
||||
|
||||
SmsMessage::SmsMessage(const SmsMessageData& aData)
|
||||
: mData(aData)
|
||||
{
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "nsIDOMSmsMessage.h"
|
||||
#include "nsString.h"
|
||||
#include "jspubtd.h"
|
||||
#include "Types.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -53,6 +54,9 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMMOZSMSMESSAGE
|
||||
|
||||
SmsMessage(PRInt32 aId, DeliveryState aDelivery, const nsString& aSender,
|
||||
const nsString& aReceiver, const nsString& aBody,
|
||||
PRUint64 aTimestamp);
|
||||
SmsMessage(const SmsMessageData& aData);
|
||||
|
||||
static nsresult Create(PRInt32 aId,
|
||||
|
|
|
@ -61,6 +61,8 @@ sync protocol PSms {
|
|||
child:
|
||||
NotifyReceivedMessage(SmsMessageData aMessageData);
|
||||
|
||||
NotifySentMessage(SmsMessageData aMessageData);
|
||||
|
||||
parent:
|
||||
sync HasSupport()
|
||||
returns (bool aHasSupport);
|
||||
|
|
|
@ -59,6 +59,20 @@ SmsChild::RecvNotifyReceivedMessage(const SmsMessageData& aMessageData)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifySentMessage(const SmsMessageData& aMessageData)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<SmsMessage> message = new SmsMessage(aMessageData);
|
||||
obs->NotifyObservers(message, kSmsSentObserverTopic, nsnull);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace sms
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -48,6 +48,7 @@ class SmsChild : public PSmsChild
|
|||
{
|
||||
public:
|
||||
NS_OVERRIDE virtual bool RecvNotifyReceivedMessage(const SmsMessageData& aMessage);
|
||||
NS_OVERRIDE virtual bool RecvNotifySentMessage(const SmsMessageData& aMessage);
|
||||
};
|
||||
|
||||
} // namespace sms
|
||||
|
|
|
@ -59,6 +59,7 @@ SmsParent::SmsParent()
|
|||
}
|
||||
|
||||
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsSentObserverTopic, false);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -70,6 +71,7 @@ SmsParent::ActorDestroy(ActorDestroyReason why)
|
|||
}
|
||||
|
||||
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsSentObserverTopic);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -87,6 +89,17 @@ SmsParent::Observe(nsISupports* aSubject, const char* aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsSentObserverTopic)) {
|
||||
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
|
||||
if (!message) {
|
||||
NS_ERROR("Got a 'sms-sent' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
unused << SendNotifySentMessage(static_cast<SmsMessage*>(message.get())->GetData());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -301,8 +301,17 @@ Java_org_mozilla_gecko_GeckoAppShell_onSmsSent(JNIEnv* jenv, jclass,
|
|||
int id;
|
||||
smsDBService->SaveSentMessage(mReceiver, mBody, mTimestamp, &id);
|
||||
|
||||
// TODO: use the ID to build a SmsMessage object and notify about the
|
||||
// sent message.
|
||||
nsCOMPtr<SmsMessage> message =
|
||||
new SmsMessage(id, eDeliveryState_Sent, EmptyString(),
|
||||
mReceiver, mBody, mTimestamp);
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
NS_ERROR("Observer Service not available!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
obs->NotifyObservers(message, kSmsSentObserverTopic, nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче