Bug 674725 - Part T - WebSMS delivered event: DOM and IPC boilerplate. r=smaug

This commit is contained in:
Mounir Lamouri 2012-01-10 20:36:25 +01:00
Родитель 16935841ef
Коммит 39148cb631
9 изменённых файлов: 58 добавлений и 7 удалений

Просмотреть файл

@ -38,7 +38,7 @@
interface nsIDOMEventListener;
[scriptable, function, uuid(e5da0085-2113-4f17-9d29-ed6fe98780a8)]
[scriptable, function, uuid(09a74bd3-466d-4612-926e-672b021fd08f)]
interface nsIDOMMozSmsManager : nsIDOMEventTarget
{
unsigned short getNumberOfMessagesForText(in DOMString text);
@ -46,4 +46,5 @@ interface nsIDOMMozSmsManager : nsIDOMEventTarget
attribute nsIDOMEventListener onreceived;
attribute nsIDOMEventListener onsent;
attribute nsIDOMEventListener ondelivered;
};

Просмотреть файл

@ -39,8 +39,9 @@ namespace mozilla {
namespace dom {
namespace sms {
const char* kSmsReceivedObserverTopic = "sms-received";
const char* kSmsSentObserverTopic = "sms-sent";
const char* kSmsReceivedObserverTopic = "sms-received";
const char* kSmsSentObserverTopic = "sms-sent";
const char* kSmsDeliveredObserverTopic = "sms-delivered";
} // namespace sms
} // namespace dom

Просмотреть файл

@ -42,8 +42,9 @@ namespace mozilla {
namespace dom {
namespace sms {
extern const char* kSmsReceivedObserverTopic; // Defined in the .cpp.
extern const char* kSmsSentObserverTopic; // Defined in the .cpp.
extern const char* kSmsReceivedObserverTopic; // Defined in the .cpp.
extern const char* kSmsSentObserverTopic; // Defined in the .cpp.
extern const char* kSmsDeliveredObserverTopic; // Defined in the .cpp.
#define DELIVERY_RECEIVED NS_LITERAL_STRING("received")
#define DELIVERY_SENT NS_LITERAL_STRING("sent")

Просмотреть файл

@ -48,8 +48,9 @@
* We have to use macros here because our leak analysis tool things we are
* 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")
#define RECEIVED_EVENT_NAME NS_LITERAL_STRING("received")
#define SENT_EVENT_NAME NS_LITERAL_STRING("sent")
#define DELIVERED_EVENT_NAME NS_LITERAL_STRING("delivered")
DOMCI_DATA(MozSmsManager, mozilla::dom::sms::SmsManager)
@ -63,12 +64,14 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(SmsManager,
nsDOMEventTargetWrapperCache)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(received)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(sent)
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(delivered)
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_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(delivered)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SmsManager)
@ -95,6 +98,7 @@ SmsManager::Init(nsPIDOMWindow *aWindow, nsIScriptContext* aScriptContext)
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
obs->AddObserver(this, kSmsSentObserverTopic, false);
obs->AddObserver(this, kSmsDeliveredObserverTopic, false);
}
void
@ -108,6 +112,7 @@ SmsManager::Shutdown()
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
obs->RemoveObserver(this, kSmsSentObserverTopic);
obs->RemoveObserver(this, kSmsDeliveredObserverTopic);
}
NS_IMETHODIMP
@ -134,6 +139,7 @@ SmsManager::Send(const nsAString& aNumber, const nsAString& aMessage)
NS_IMPL_EVENT_HANDLER(SmsManager, received)
NS_IMPL_EVENT_HANDLER(SmsManager, sent)
NS_IMPL_EVENT_HANDLER(SmsManager, delivered)
nsresult
SmsManager::DispatchTrustedSmsEventToSelf(const nsAString& aEventName, nsIDOMMozSmsMessage* aMessage)
@ -179,6 +185,17 @@ SmsManager::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
if (!strcmp(aTopic, kSmsDeliveredObserverTopic)) {
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'sms-delivered' topic without a valid message!");
return NS_OK;
}
DispatchTrustedSmsEventToSelf(DELIVERED_EVENT_NAME, message);
return NS_OK;
}
return NS_OK;
}

Просмотреть файл

@ -70,6 +70,7 @@ private:
nsIDOMMozSmsMessage* aMessage);
NS_DECL_EVENT_HANDLER(received)
NS_DECL_EVENT_HANDLER(sent)
NS_DECL_EVENT_HANDLER(delivered)
};
} // namespace sms

Просмотреть файл

@ -63,6 +63,8 @@ child:
NotifySentMessage(SmsMessageData aMessageData);
NotifyDeliveredMessage(SmsMessageData aMessageData);
parent:
sync HasSupport()
returns (bool aHasSupport);

Просмотреть файл

@ -73,6 +73,20 @@ SmsChild::RecvNotifySentMessage(const SmsMessageData& aMessageData)
return true;
}
bool
SmsChild::RecvNotifyDeliveredMessage(const SmsMessageData& aMessageData)
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return true;
}
nsCOMPtr<SmsMessage> message = new SmsMessage(aMessageData);
obs->NotifyObservers(message, kSmsDeliveredObserverTopic, nsnull);
return true;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -49,6 +49,7 @@ class SmsChild : public PSmsChild
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);
};
} // namespace sms

Просмотреть файл

@ -60,6 +60,7 @@ SmsParent::SmsParent()
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
obs->AddObserver(this, kSmsSentObserverTopic, false);
obs->AddObserver(this, kSmsDeliveredObserverTopic, false);
}
void
@ -72,6 +73,7 @@ SmsParent::ActorDestroy(ActorDestroyReason why)
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
obs->RemoveObserver(this, kSmsSentObserverTopic);
obs->RemoveObserver(this, kSmsDeliveredObserverTopic);
}
NS_IMETHODIMP
@ -100,6 +102,17 @@ SmsParent::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
if (!strcmp(aTopic, kSmsDeliveredObserverTopic)) {
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'sms-delivered' topic without a valid message!");
return NS_OK;
}
unused << SendNotifyDeliveredMessage(static_cast<SmsMessage*>(message.get())->GetData());
return NS_OK;
}
return NS_OK;
}