Bug 844431 - B2G MMS: provide nsIDOMMobileMessageManager interface (with sendMMS() first) (part 1, nsIDOMMobileMessageManager). r=vicamo sr=sicking a=leo+

--HG--
rename : dom/mobilemessage/interfaces/nsIDOMSmsManager.idl => dom/mobilemessage/interfaces/nsIDOMMobileMessageManager.idl
rename : dom/mobilemessage/interfaces/nsIDOMNavigatorSms.idl => dom/mobilemessage/interfaces/nsIDOMNavigatorMobileMessage.idl
rename : dom/mobilemessage/src/SmsManager.cpp => dom/mobilemessage/src/MobileMessageManager.cpp
rename : dom/mobilemessage/src/SmsManager.h => dom/mobilemessage/src/MobileMessageManager.h
This commit is contained in:
Gene Lian 2013-03-09 15:21:47 +08:00
parent c2e58bd3d3
commit bf05bdc64c
13 changed files with 556 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "nsIDOMWakeLock.h"
#include "nsIPowerManagerService.h"
#include "mozilla/dom/SmsManager.h"
#include "mozilla/dom/MobileMessageManager.h"
#include "nsISmsService.h"
#include "mozilla/Hal.h"
#include "nsIWebNavigation.h"
@ -123,6 +124,7 @@ NS_INTERFACE_MAP_BEGIN(Navigator)
NS_INTERFACE_MAP_ENTRY(nsINavigatorBattery)
NS_INTERFACE_MAP_ENTRY(nsIDOMNavigatorDesktopNotification)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorSms)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozNavigatorMobileMessage)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
#ifdef MOZ_MEDIA_NAVIGATOR
NS_INTERFACE_MAP_ENTRY(nsINavigatorUserMedia)
@ -196,6 +198,11 @@ Navigator::Invalidate()
mSmsManager = nullptr;
}
if (mMobileMessageManager) {
mMobileMessageManager->Shutdown();
mMobileMessageManager = nullptr;
}
#ifdef MOZ_B2G_RIL
if (mTelephony) {
mTelephony = nullptr;
@ -1196,6 +1203,41 @@ Navigator::GetMozSms(nsIDOMMozSmsManager** aSmsManager)
return NS_OK;
}
//*****************************************************************************
// Navigator::nsIDOMNavigatorMobileMessage
//*****************************************************************************
NS_IMETHODIMP
Navigator::GetMozMobileMessage(nsIDOMMozMobileMessageManager** aMobileMessageManager)
{
*aMobileMessageManager = nullptr;
#ifndef MOZ_WEBSMS_BACKEND
return NS_OK;
#endif
// First of all, the general pref has to be turned on.
bool enabled = false;
Preferences::GetBool("dom.sms.enabled", &enabled);
NS_ENSURE_TRUE(enabled, NS_OK);
if (!mMobileMessageManager) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window && window->GetDocShell(), NS_OK);
if (!CheckPermission("sms")) {
return NS_OK;
}
mMobileMessageManager = new MobileMessageManager();
mMobileMessageManager->Init(window);
}
NS_ADDREF(*aMobileMessageManager = mMobileMessageManager);
return NS_OK;
}
#ifdef MOZ_B2G_RIL
//*****************************************************************************

View File

@ -14,6 +14,7 @@
#include "nsIDOMClientInformation.h"
#include "nsINavigatorBattery.h"
#include "nsIDOMNavigatorSms.h"
#include "nsIDOMNavigatorMobileMessage.h"
#include "nsIDOMNavigatorNetwork.h"
#include "nsIObserver.h"
#ifdef MOZ_AUDIO_CHANNEL_MANAGER
@ -66,6 +67,7 @@ class BatteryManager;
} // namespace battery
class SmsManager;
class MobileMessageManager;
namespace network {
class Connection;
@ -95,6 +97,7 @@ class Navigator : public nsIDOMNavigator
, public nsIDOMNavigatorDesktopNotification
, public nsINavigatorBattery
, public nsIDOMMozNavigatorSms
, public nsIDOMMozNavigatorMobileMessage
, public nsIObserver
#ifdef MOZ_MEDIA_NAVIGATOR
, public nsINavigatorUserMedia
@ -133,6 +136,7 @@ public:
NS_DECL_NSIDOMNAVIGATORDESKTOPNOTIFICATION
NS_DECL_NSINAVIGATORBATTERY
NS_DECL_NSIDOMMOZNAVIGATORSMS
NS_DECL_NSIDOMMOZNAVIGATORMOBILEMESSAGE
NS_DECL_NSIOBSERVER
#ifdef MOZ_MEDIA_NAVIGATOR
NS_DECL_NSINAVIGATORUSERMEDIA
@ -196,6 +200,7 @@ private:
nsRefPtr<battery::BatteryManager> mBatteryManager;
nsRefPtr<power::PowerManager> mPowerManager;
nsRefPtr<SmsManager> mSmsManager;
nsRefPtr<MobileMessageManager> mMobileMessageManager;
#ifdef MOZ_B2G_RIL
nsCOMPtr<nsIDOMTelephony> mTelephony;
nsCOMPtr<nsIDOMMozVoicemail> mVoicemail;

View File

@ -336,6 +336,7 @@ using mozilla::dom::workers::ResolveWorkerClasses;
#include "nsIDOMPowerManager.h"
#include "nsIDOMWakeLock.h"
#include "nsIDOMSmsManager.h"
#include "nsIDOMMobileMessageManager.h"
#include "nsIDOMMozSmsMessage.h"
#include "nsIDOMSmsRequest.h"
#include "nsIDOMSmsFilter.h"
@ -966,6 +967,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(MozSmsManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozMobileMessageManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozSmsMessage, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -1859,6 +1863,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(nsINavigatorBattery,
battery::BatteryManager::HasSupport())
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozNavigatorSms)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozNavigatorMobileMessage)
#ifdef MOZ_MEDIA_NAVIGATOR
DOM_CLASSINFO_MAP_ENTRY(nsINavigatorUserMedia)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNavigatorUserMedia)
@ -2519,6 +2524,10 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsManager)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozMobileMessageManager, nsIDOMMozMobileMessageManager)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozMobileMessageManager)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozSmsMessage, nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_END

View File

@ -205,6 +205,7 @@ DOMCI_CLASS(MozPowerManager)
DOMCI_CLASS(MozWakeLock)
DOMCI_CLASS(MozSmsManager)
DOMCI_CLASS(MozMobileMessageManager)
DOMCI_CLASS(MozSmsMessage)
DOMCI_CLASS(MozSmsRequest)
DOMCI_CLASS(MozSmsFilter)

View File

@ -4,8 +4,10 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
XPIDL_SOURCES += [
'nsIDOMMobileMessageManager.idl',
'nsIDOMMozSmsEvent.idl',
'nsIDOMMozSmsMessage.idl',
'nsIDOMNavigatorMobileMessage.idl',
'nsIDOMNavigatorSms.idl',
'nsIDOMSmsCursor.idl',
'nsIDOMSmsFilter.idl',

View File

@ -0,0 +1,41 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIDOMEventTarget.idl"
interface nsIDOMEventListener;
interface nsIDOMMozSmsRequest;
interface nsIDOMMozSmsFilter;
interface nsIDOMMozSmsSegmentInfo;
[scriptable, builtinclass, uuid(228508d0-7fe4-11e2-a028-83810f98f20b)]
interface nsIDOMMozMobileMessageManager : nsIDOMEventTarget
{
nsIDOMMozSmsSegmentInfo getSegmentInfoForText(in DOMString text);
// The first parameter can be either a DOMString (only one number) or an array
// of DOMStrings.
// The method returns a SmsRequest object if one number has been passed.
// An array of SmsRequest objects otherwise.
jsval send(in jsval number, in DOMString message);
[binaryname(GetMessageMoz)]
nsIDOMMozSmsRequest getMessage(in long id);
// The parameter can be either a message id or a SmsMessage.
nsIDOMMozSmsRequest delete(in jsval param);
nsIDOMMozSmsRequest getMessages(in nsIDOMMozSmsFilter filter, in boolean reverse);
nsIDOMMozSmsRequest markMessageRead(in long id, in boolean aValue);
nsIDOMMozSmsRequest getThreadList();
[implicit_jscontext] attribute jsval onreceived;
[implicit_jscontext] attribute jsval onsending;
[implicit_jscontext] attribute jsval onsent;
[implicit_jscontext] attribute jsval onfailed;
[implicit_jscontext] attribute jsval ondeliverysuccess;
[implicit_jscontext] attribute jsval ondeliveryerror;
};

View File

@ -0,0 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsIDOMMozMobileMessageManager;
[scriptable, uuid(baefbb1a-7fe4-11e2-abff-cf1a90f9139f)]
interface nsIDOMMozNavigatorMobileMessage : nsISupports
{
readonly attribute nsIDOMMozMobileMessageManager mozMobileMessage;
};

View File

@ -36,6 +36,7 @@ EXPORTS_NAMESPACES = \
EXPORTS_mozilla/dom = \
SmsManager.h \
MobileMessageManager.h \
SmsMessage.h \
SmsRequest.h \
SmsSegmentInfo.h \
@ -52,6 +53,7 @@ EXPORTS_mozilla/dom/mobilemessage = \
CPPSRCS = \
SmsManager.cpp \
MobileMessageManager.cpp \
SmsService.cpp \
SmsIPCService.cpp \
SmsServicesFactory.cpp \

View File

@ -0,0 +1,367 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SmsFilter.h"
#include "MobileMessageManager.h"
#include "nsIDOMClassInfo.h"
#include "nsISmsService.h"
#include "nsIObserverService.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "Constants.h"
#include "nsIDOMMozSmsEvent.h"
#include "nsIDOMMozSmsMessage.h"
#include "SmsRequest.h"
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsIMobileMessageDatabaseService.h"
#include "nsIXPConnect.h"
#include "nsIPermissionManager.h"
#include "GeneratedEvents.h"
#define RECEIVED_EVENT_NAME NS_LITERAL_STRING("received")
#define SENDING_EVENT_NAME NS_LITERAL_STRING("sending")
#define SENT_EVENT_NAME NS_LITERAL_STRING("sent")
#define FAILED_EVENT_NAME NS_LITERAL_STRING("failed")
#define DELIVERY_SUCCESS_EVENT_NAME NS_LITERAL_STRING("deliverysuccess")
#define DELIVERY_ERROR_EVENT_NAME NS_LITERAL_STRING("deliveryerror")
using namespace mozilla::dom::mobilemessage;
DOMCI_DATA(MozMobileMessageManager, mozilla::dom::MobileMessageManager)
namespace mozilla {
namespace dom {
NS_INTERFACE_MAP_BEGIN(MobileMessageManager)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozMobileMessageManager)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozMobileMessageManager)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(MobileMessageManager, nsDOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(MobileMessageManager, nsDOMEventTargetHelper)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, received)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, sending)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, sent)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, failed)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, deliverysuccess)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, deliveryerror)
void
MobileMessageManager::Init(nsPIDOMWindow *aWindow)
{
BindToOwner(aWindow);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
// GetObserverService() can return null is some situations like shutdown.
if (!obs) {
return;
}
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
obs->AddObserver(this, kSmsSendingObserverTopic, false);
obs->AddObserver(this, kSmsSentObserverTopic, false);
obs->AddObserver(this, kSmsFailedObserverTopic, false);
obs->AddObserver(this, kSmsDeliverySuccessObserverTopic, false);
obs->AddObserver(this, kSmsDeliveryErrorObserverTopic, false);
}
void
MobileMessageManager::Shutdown()
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
// GetObserverService() can return null is some situations like shutdown.
if (!obs) {
return;
}
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
obs->RemoveObserver(this, kSmsSendingObserverTopic);
obs->RemoveObserver(this, kSmsSentObserverTopic);
obs->RemoveObserver(this, kSmsFailedObserverTopic);
obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic);
obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic);
}
NS_IMETHODIMP
MobileMessageManager::GetSegmentInfoForText(const nsAString& aText,
nsIDOMMozSmsSegmentInfo** aResult)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
return smsService->GetSegmentInfoForText(aText, aResult);
}
nsresult
MobileMessageManager::Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
const nsAString& aMessage, jsval* aRequest)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
if (!smsService) {
NS_ERROR("No SMS Service!");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMMozSmsRequest> request = SmsRequest::Create(this);
nsDependentJSString number;
number.init(aCx, aNumber);
nsCOMPtr<nsISmsRequest> forwarder =
new SmsRequestForwarder(static_cast<SmsRequest*>(request.get()));
smsService->Send(number, aMessage, forwarder);
nsresult rv = nsContentUtils::WrapNative(aCx, aGlobal, request, aRequest);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create the js value!");
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
MobileMessageManager::Send(const jsval& aNumber, const nsAString& aMessage, jsval* aReturn)
{
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_STATE(sc);
AutoPushJSContext cx(sc->GetNativeContext());
NS_ASSERTION(cx, "Failed to get a context!");
if (!aNumber.isString() &&
!(aNumber.isObject() && JS_IsArrayObject(cx, &aNumber.toObject()))) {
return NS_ERROR_INVALID_ARG;
}
JSObject* global = sc->GetNativeGlobal();
NS_ASSERTION(global, "Failed to get global object!");
JSAutoRequest ar(cx);
JSAutoCompartment ac(cx, global);
if (aNumber.isString()) {
return Send(cx, global, aNumber.toString(), aMessage, aReturn);
}
// Must be an array then.
JSObject& numbers = aNumber.toObject();
uint32_t size;
JS_ALWAYS_TRUE(JS_GetArrayLength(cx, &numbers, &size));
jsval* requests = new jsval[size];
for (uint32_t i=0; i<size; ++i) {
jsval number;
if (!JS_GetElement(cx, &numbers, i, &number)) {
return NS_ERROR_INVALID_ARG;
}
nsresult rv = Send(cx, global, number.toString(), aMessage, &requests[i]);
NS_ENSURE_SUCCESS(rv, rv);
}
aReturn->setObjectOrNull(JS_NewArrayObject(cx, size, requests));
NS_ENSURE_TRUE(aReturn->isObject(), NS_ERROR_FAILURE);
return NS_OK;
}
NS_IMETHODIMP
MobileMessageManager::GetMessageMoz(int32_t aId, nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
nsCOMPtr<nsISmsRequest> forwarder = new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
mobileMessageDBService->GetMessageMoz(aId, forwarder);
req.forget(aRequest);
return NS_OK;
}
nsresult
MobileMessageManager::Delete(int32_t aId, nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
nsCOMPtr<nsISmsRequest> forwarder = new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
mobileMessageDBService->DeleteMessage(aId, forwarder);
req.forget(aRequest);
return NS_OK;
}
NS_IMETHODIMP
MobileMessageManager::Delete(const jsval& aParam, nsIDOMMozSmsRequest** aRequest)
{
if (aParam.isInt32()) {
return Delete(aParam.toInt32(), aRequest);
}
if (!aParam.isObject()) {
return NS_ERROR_INVALID_ARG;
}
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
AutoPushJSContext cx(sc->GetNativeContext());
NS_ENSURE_STATE(sc);
nsCOMPtr<nsIDOMMozSmsMessage> message =
do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(cx, &aParam.toObject()));
NS_ENSURE_TRUE(message, NS_ERROR_INVALID_ARG);
int32_t id;
message->GetId(&id);
return Delete(id, aRequest);
}
NS_IMETHODIMP
MobileMessageManager::GetMessages(nsIDOMMozSmsFilter* aFilter, bool aReverse,
nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsIDOMMozSmsFilter> filter = aFilter;
if (!filter) {
filter = new SmsFilter();
}
nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
nsCOMPtr<nsISmsRequest> forwarder = new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
mobileMessageDBService->CreateMessageList(filter, aReverse, forwarder);
req.forget(aRequest);
return NS_OK;
}
NS_IMETHODIMP
MobileMessageManager::MarkMessageRead(int32_t aId, bool aValue,
nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
nsCOMPtr<nsISmsRequest> forwarder =
new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
mobileMessageDBService->MarkMessageRead(aId, aValue, forwarder);
req.forget(aRequest);
return NS_OK;
}
NS_IMETHODIMP
MobileMessageManager::GetThreadList(nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsIDOMMozSmsRequest> req = SmsRequest::Create(this);
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
nsCOMPtr<nsISmsRequest> forwarder =
new SmsRequestForwarder(static_cast<SmsRequest*>(req.get()));
mobileMessageDBService->GetThreadList(forwarder);
req.forget(aRequest);
return NS_OK;
}
nsresult
MobileMessageManager::DispatchTrustedSmsEventToSelf(const nsAString& aEventName,
nsIDOMMozSmsMessage* aMessage)
{
nsCOMPtr<nsIDOMEvent> event;
NS_NewDOMMozSmsEvent(getter_AddRefs(event), this, nullptr, nullptr);
NS_ASSERTION(event, "This should never fail!");
nsCOMPtr<nsIDOMMozSmsEvent> se = do_QueryInterface(event);
MOZ_ASSERT(se);
nsresult rv = se->InitMozSmsEvent(aEventName, false, false, aMessage);
NS_ENSURE_SUCCESS(rv, rv);
return DispatchTrustedEvent(event);
}
NS_IMETHODIMP
MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData)
{
if (!strcmp(aTopic, kSmsReceivedObserverTopic)) {
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'sms-received' topic without a valid message!");
return NS_OK;
}
DispatchTrustedSmsEventToSelf(RECEIVED_EVENT_NAME, message);
return NS_OK;
}
if (!strcmp(aTopic, kSmsSendingObserverTopic)) {
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'sms-sending' topic without a valid message!");
return NS_OK;
}
DispatchTrustedSmsEventToSelf(SENDING_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;
}
if (!strcmp(aTopic, kSmsFailedObserverTopic)) {
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'sms-failed' topic without a valid message!");
return NS_OK;
}
DispatchTrustedSmsEventToSelf(FAILED_EVENT_NAME, message);
return NS_OK;
}
if (!strcmp(aTopic, kSmsDeliverySuccessObserverTopic)) {
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'sms-delivery-success' topic without a valid message!");
return NS_OK;
}
DispatchTrustedSmsEventToSelf(DELIVERY_SUCCESS_EVENT_NAME, message);
return NS_OK;
}
if (!strcmp(aTopic, kSmsDeliveryErrorObserverTopic)) {
nsCOMPtr<nsIDOMMozSmsMessage> message = do_QueryInterface(aSubject);
if (!message) {
NS_ERROR("Got a 'sms-delivery-error' topic without a valid message!");
return NS_OK;
}
DispatchTrustedSmsEventToSelf(DELIVERY_ERROR_EVENT_NAME, message);
return NS_OK;
}
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_mobilemessage_MobileMessageManager_h
#define mozilla_dom_mobilemessage_MobileMessageManager_h
#include "nsIDOMMobileMessageManager.h"
#include "nsIObserver.h"
#include "nsDOMEventTargetHelper.h"
class nsIDOMMozSmsMessage;
namespace mozilla {
namespace dom {
class MobileMessageManager : public nsDOMEventTargetHelper
, public nsIDOMMozMobileMessageManager
, public nsIObserver
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMMOZMOBILEMESSAGEMANAGER
NS_FORWARD_NSIDOMEVENTTARGET(nsDOMEventTargetHelper::)
void Init(nsPIDOMWindow *aWindow);
void Shutdown();
private:
/**
* Internal Send() method used to send one message.
*/
nsresult Send(JSContext* aCx, JSObject* aGlobal, JSString* aNumber,
const nsAString& aMessage, jsval* aRequest);
/**
* Internal Delete() method used to delete a message.
*/
nsresult Delete(int32_t aId, nsIDOMMozSmsRequest** aRequest);
nsresult DispatchTrustedSmsEventToSelf(const nsAString& aEventName,
nsIDOMMozSmsMessage* aMessage);
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_mobilemessage_MobileMessageManager_h

View File

@ -14,6 +14,7 @@
#include "SmsCursor.h"
#include "SmsMessage.h"
#include "SmsManager.h"
#include "MobileMessageManager.h"
#include "mozilla/dom/DOMError.h"
#include "SmsParent.h"
#include "jsapi.h"
@ -73,6 +74,13 @@ SmsRequest::Create(SmsManager* aManager)
return request.forget();
}
already_AddRefed<nsIDOMMozSmsRequest>
SmsRequest::Create(MobileMessageManager* aManager)
{
nsCOMPtr<nsIDOMMozSmsRequest> request = new SmsRequest(aManager);
return request.forget();
}
already_AddRefed<SmsRequest>
SmsRequest::Create(SmsRequestParent* aRequestParent)
{
@ -90,6 +98,16 @@ SmsRequest::SmsRequest(SmsManager* aManager)
BindToOwner(aManager);
}
SmsRequest::SmsRequest(MobileMessageManager* aManager)
: mResult(JSVAL_VOID)
, mResultRooted(false)
, mDone(false)
, mParentAlive(false)
, mParent(nullptr)
{
BindToOwner(aManager);
}
SmsRequest::SmsRequest(SmsRequestParent* aRequestParent)
: mResult(JSVAL_VOID)
, mResultRooted(false)

View File

@ -49,6 +49,7 @@ private:
};
class SmsManager;
class MobileMessageManager;
class SmsRequest : public nsDOMEventTargetHelper
, public nsIDOMMozSmsRequest
@ -68,6 +69,7 @@ public:
nsDOMEventTargetHelper)
static already_AddRefed<nsIDOMMozSmsRequest> Create(SmsManager* aManager);
static already_AddRefed<nsIDOMMozSmsRequest> Create(MobileMessageManager* aManager);
static already_AddRefed<SmsRequest> Create(mobilemessage::SmsRequestParent* requestParent);
void Reset();
@ -83,6 +85,7 @@ private:
SmsRequest() MOZ_DELETE;
SmsRequest(SmsManager* aManager);
SmsRequest(MobileMessageManager* aManager);
SmsRequest(mobilemessage::SmsRequestParent* aParent);
~SmsRequest();

View File

@ -334,6 +334,7 @@ var interfaceNamesInGlobalScope =
"SVGAnimatedNumber",
"HTMLHtmlElement",
"MozSmsManager",
"MozMobileMessageManager",
"MozSmsFilter",
"SVGFETileElement",
"MozMobileConnectionInfo",
@ -426,6 +427,7 @@ var interfaceNamesInGlobalScope =
"MozSmsCursor",
"EventSource",
"MozNavigatorSms",
"MozNavigatorMobileMessage",
"SVGSetElement",
"GlobalObjectConstructor",
"SVGAnimatedBoolean",