Bug 958782 - 2.b/3: WebIDL implementation. f=Ms2ger,bzbarsky,bz,r=khuey

This commit is contained in:
Vicamo Yang 2014-06-23 20:55:58 +08:00
parent 30ad92dd6c
commit 19503c8125
9 changed files with 425 additions and 293 deletions

View File

@ -1558,7 +1558,7 @@ Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
return pmService->NewWakeLock(aTopic, mWindow, aRv);
}
nsIDOMMozMobileMessageManager*
MobileMessageManager*
Navigator::GetMozMobileMessage()
{
if (!mMobileMessageManager) {
@ -1566,8 +1566,8 @@ Navigator::GetMozMobileMessage()
NS_ENSURE_TRUE(mWindow, nullptr);
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
mMobileMessageManager = new MobileMessageManager();
mMobileMessageManager->Init(mWindow);
mMobileMessageManager = new MobileMessageManager(mWindow);
mMobileMessageManager->Init();
}
return mMobileMessageManager;

View File

@ -22,7 +22,6 @@
class nsPluginArray;
class nsMimeTypeArray;
class nsPIDOMWindow;
class nsIDOMMozMobileMessageManager;
class nsIDOMNavigatorSystemMessages;
class nsDOMCameraManager;
class nsDOMDeviceStorage;
@ -207,7 +206,7 @@ public:
DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
bool MozIsLocallyAvailable(const nsAString& aURI, bool aWhenOffline,
ErrorResult& aRv);
nsIDOMMozMobileMessageManager* GetMozMobileMessage();
MobileMessageManager* GetMozMobileMessage();
Telephony* GetMozTelephony(ErrorResult& aRv);
network::Connection* GetConnection(ErrorResult& aRv);
nsDOMCameraManager* GetMozCameras(ErrorResult& aRv);

View File

@ -132,7 +132,6 @@
#include "nsWrapperCacheInlines.h"
#include "mozilla/dom/HTMLCollectionBinding.h"
#include "nsIDOMMobileMessageManager.h"
#include "nsIDOMMozSmsMessage.h"
#include "nsIDOMMozMmsMessage.h"
#include "nsIDOMSmsFilter.h"
@ -377,9 +376,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DEFAULT_SCRIPTABLE_FLAGS |
WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozMobileMessageManager, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozSmsMessage, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -983,10 +979,6 @@ nsDOMClassInfo::Init()
#endif
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

@ -59,7 +59,6 @@ DOMCI_CLASS(File)
// DOM modal content window class, almost identical to Window
DOMCI_CLASS(ModalContentWindow)
DOMCI_CLASS(MozMobileMessageManager)
DOMCI_CLASS(MozSmsMessage)
DOMCI_CLASS(MozMmsMessage)
DOMCI_CLASS(MozSmsFilter)

View File

@ -604,7 +604,13 @@ MobileConnection::SetCallForwardingOption(const MozCallForwardingOptions& aOptio
return nullptr;
}
AutoSafeJSContext cx;
AutoJSAPI jsapi;
if (!NS_WARN_IF(jsapi.InitUsingWin(GetOwner()))) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSContext *cx = jsapi.cx();
JS::Rooted<JS::Value> options(cx);
if (!ToJSValue(cx, aOptions, &options)) {
aRv.Throw(NS_ERROR_TYPE_ERR);
@ -635,7 +641,13 @@ MobileConnection::GetCallBarringOption(const MozCallBarringOptions& aOptions,
return nullptr;
}
AutoSafeJSContext cx;
AutoJSAPI jsapi;
if (!NS_WARN_IF(jsapi.InitUsingWin(GetOwner()))) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSContext *cx = jsapi.cx();
JS::Rooted<JS::Value> options(cx);
if (!ToJSValue(cx, aOptions, &options)) {
aRv.Throw(NS_ERROR_TYPE_ERR);
@ -666,7 +678,13 @@ MobileConnection::SetCallBarringOption(const MozCallBarringOptions& aOptions,
return nullptr;
}
AutoSafeJSContext cx;
AutoJSAPI jsapi;
if (!NS_WARN_IF(jsapi.InitUsingWin(GetOwner()))) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSContext *cx = jsapi.cx();
JS::Rooted<JS::Value> options(cx);
if (!ToJSValue(cx, aOptions, &options)) {
aRv.Throw(NS_ERROR_TYPE_ERR);
@ -697,7 +715,13 @@ MobileConnection::ChangeCallBarringPassword(const MozCallBarringOptions& aOption
return nullptr;
}
AutoSafeJSContext cx;
AutoJSAPI jsapi;
if (!NS_WARN_IF(jsapi.InitUsingWin(GetOwner()))) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSContext *cx = jsapi.cx();
JS::Rooted<JS::Value> options(cx);
if (!ToJSValue(cx, aOptions, &options)) {
aRv.Throw(NS_ERROR_TYPE_ERR);

View File

@ -10,6 +10,7 @@
#include "nsString.h"
#include "mozilla/dom/mobilemessage/Types.h"
#include "mozilla/dom/MozMmsMessageBinding.h"
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
#include "mozilla/Attributes.h"
namespace mozilla {

View File

@ -12,10 +12,11 @@
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
#include "mozilla/dom/MobileMessageManagerBinding.h"
#include "mozilla/dom/MozMmsEvent.h"
#include "mozilla/dom/MozMmsMessageBinding.h"
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
#include "mozilla/dom/MozSmsEvent.h"
#include "mozilla/dom/ToJSValue.h"
#include "nsIDOMMozSmsMessage.h"
#include "nsIDOMMozMmsMessage.h"
#include "nsJSUtils.h"
@ -43,35 +44,24 @@
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(DOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(MobileMessageManager, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(MobileMessageManager, DOMEventTargetHelper)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, received)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, retrieving)
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)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, readsuccess)
NS_IMPL_EVENT_HANDLER(MobileMessageManager, readerror)
MobileMessageManager::MobileMessageManager(nsPIDOMWindow *aWindow)
: DOMEventTargetHelper(aWindow)
{
}
void
MobileMessageManager::Init(nsPIDOMWindow *aWindow)
MobileMessageManager::Init()
{
BindToOwner(aWindow);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
// GetObserverService() can return null is some situations like shutdown.
if (!obs) {
@ -109,296 +99,285 @@ MobileMessageManager::Shutdown()
obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
}
NS_IMETHODIMP
JSObject*
MobileMessageManager::WrapObject(JSContext* aCx)
{
return MozMobileMessageManagerBinding::Wrap(aCx, this);
}
already_AddRefed<DOMRequest>
MobileMessageManager::GetSegmentInfoForText(const nsAString& aText,
nsIDOMDOMRequest** aRequest)
ErrorResult& aRv)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
if (!smsService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
new MobileMessageCallback(request);
nsresult rv = smsService->GetSegmentInfoForText(aText, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
request.forget(aRequest);
return NS_OK;
return request.forget();
}
nsresult
MobileMessageManager::Send(JSContext* aCx,
JS::Handle<JSObject*> aGlobal,
nsISmsService* aSmsService,
already_AddRefed<DOMRequest>
MobileMessageManager::Send(nsISmsService* aSmsService,
uint32_t aServiceId,
JS::Handle<JSString*> aNumber,
const nsAString& aNumber,
const nsAString& aText,
JS::MutableHandle<JS::Value> aRequest)
ErrorResult& aRv)
{
nsDependentJSString number;
number.init(aCx, aNumber);
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
new MobileMessageCallback(request);
// By default, we don't send silent messages via MobileMessageManager.
nsresult rv = aSmsService->Send(aServiceId, number, aText,
nsresult rv = aSmsService->Send(aServiceId, aNumber, aText,
false, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
js::AssertSameCompartment(aCx, aGlobal);
rv = nsContentUtils::WrapNative(aCx,
static_cast<nsIDOMDOMRequest*>(request.get()),
aRequest);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create the js value!");
return rv;
aRv.Throw(rv);
return nullptr;
}
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
MobileMessageManager::Send(JS::Handle<JS::Value> aNumber,
already_AddRefed<DOMRequest>
MobileMessageManager::Send(const nsAString& aNumber,
const nsAString& aText,
JS::Handle<JS::Value> aSendParams,
JSContext* aCx,
uint8_t aArgc,
JS::MutableHandle<JS::Value> aReturn)
const SmsSendParameters& aSendParams,
ErrorResult& aRv)
{
if (!aNumber.isString() && !JS_IsArrayObject(aCx, aNumber)) {
return NS_ERROR_INVALID_ARG;
}
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_STATE(sc);
JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
mozilla::Maybe<JSAutoCompartment> ac;
if (!global) {
global = sc->GetWindowProxy();
ac.construct(aCx, global);
}
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
if (!smsService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// Use the default one unless |aSendParams.serviceId| is available.
uint32_t serviceId;
RootedDictionary<SmsSendParameters> sendParams(aCx);
if (aArgc >= 1) {
JS::Rooted<JS::Value> param(aCx, aSendParams);
if (!sendParams.Init(aCx, param)) {
return NS_ERROR_TYPE_ERR;
}
}
if (sendParams.mServiceId.WasPassed()) {
serviceId = sendParams.mServiceId.Value();
if (aSendParams.mServiceId.WasPassed()) {
serviceId = aSendParams.mServiceId.Value();
} else {
rv = smsService->GetSmsDefaultServiceId(&serviceId);
NS_ENSURE_SUCCESS(rv, rv);
}
if (aNumber.isString()) {
JS::Rooted<JSString*> str(aCx, aNumber.toString());
return Send(aCx, global, smsService, serviceId, str, aText, aReturn);
}
// Must be an array then.
JS::Rooted<JSObject*> numbers(aCx, &aNumber.toObject());
uint32_t size;
if (!JS_GetArrayLength(aCx, numbers, &size)) {
return NS_ERROR_FAILURE;
}
JS::AutoValueVector requests(aCx);
if (!requests.resize(size)) {
return NS_ERROR_FAILURE;
}
JS::Rooted<JS::Value> number(aCx);
JS::Rooted<JSString*> str(aCx);
for (uint32_t i = 0; i < size; ++i) {
if (!JS_GetElement(aCx, numbers, i, &number)) {
return NS_ERROR_INVALID_ARG;
nsresult rv = smsService->GetSmsDefaultServiceId(&serviceId);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
str = JS::ToString(aCx, number);
if (!str) {
return NS_ERROR_FAILURE;
}
nsresult rv = Send(aCx, global, smsService, serviceId, str, aText, requests[i]);
NS_ENSURE_SUCCESS(rv, rv);
}
JS::Rooted<JSObject*> obj(aCx);
obj = JS_NewArrayObject(aCx, requests);
if (!obj) {
return NS_ERROR_FAILURE;
}
aReturn.setObject(*obj);
return NS_OK;
return Send(smsService, serviceId, aNumber, aText, aRv);
}
NS_IMETHODIMP
MobileMessageManager::SendMMS(JS::Handle<JS::Value> aParams,
JS::Handle<JS::Value> aSendParams,
JSContext* aCx,
uint8_t aArgc,
nsIDOMDOMRequest** aRequest)
void
MobileMessageManager::Send(const Sequence<nsString>& aNumbers,
const nsAString& aText,
const SmsSendParameters& aSendParams,
nsTArray<nsRefPtr<DOMRequest>>& aReturn,
ErrorResult& aRv)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
if (!smsService) {
aRv.Throw(NS_ERROR_FAILURE);
return;
}
// Use the default one unless |aSendParams.serviceId| is available.
uint32_t serviceId;
if (aSendParams.mServiceId.WasPassed()) {
serviceId = aSendParams.mServiceId.Value();
} else {
nsresult rv = smsService->GetSmsDefaultServiceId(&serviceId);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
}
const uint32_t size = aNumbers.Length();
for (uint32_t i = 0; i < size; ++i) {
nsRefPtr<DOMRequest> request = Send(smsService, serviceId, aNumbers[i], aText, aRv);
if (aRv.Failed()) {
return;
}
aReturn.AppendElement(request);
}
}
already_AddRefed<DOMRequest>
MobileMessageManager::SendMMS(const MmsParameters& aParams,
const MmsSendParameters& aSendParams,
ErrorResult& aRv)
{
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
if (!mmsService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// Use the default one unless |aSendParams.serviceId| is available.
uint32_t serviceId;
RootedDictionary<MmsSendParameters> sendParams(aCx);
nsresult rv;
if (aArgc >= 1) {
JS::Rooted<JS::Value> param(aCx, aSendParams);
if (!sendParams.Init(aCx, param)) {
return NS_ERROR_TYPE_ERR;
if (aSendParams.mServiceId.WasPassed()) {
serviceId = aSendParams.mServiceId.Value();
} else {
rv = mmsService->GetMmsDefaultServiceId(&serviceId);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
}
if (sendParams.mServiceId.WasPassed()) {
serviceId = sendParams.mServiceId.Value();
} else {
rv = mmsService->GetMmsDefaultServiceId(&serviceId);
NS_ENSURE_SUCCESS(rv, rv);
AutoJSAPI jsapi;
if (!NS_WARN_IF(jsapi.InitUsingWin(GetOwner()))) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
JSContext *cx = jsapi.cx();
JS::Rooted<JS::Value> val(cx);
if (!ToJSValue(cx, aParams, &val)) {
aRv.Throw(NS_ERROR_TYPE_ERR);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
rv = mmsService->Send(serviceId, aParams, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
rv = mmsService->Send(serviceId, val, msgCallback);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
request.forget(aRequest);
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
MobileMessageManager::GetMessageMoz(int32_t aId,
nsIDOMDOMRequest** aRequest)
already_AddRefed<DOMRequest>
MobileMessageManager::GetMessage(int32_t aId,
ErrorResult& aRv)
{
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
if (!dbService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
nsresult rv = dbService->GetMessageMoz(aId, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
request.forget(aRequest);
return NS_OK;
return request.forget();
}
nsresult
MobileMessageManager::GetMessageId(JSContext* aCx,
const JS::Value& aMessage, int32_t* aId)
already_AddRefed<DOMRequest>
MobileMessageManager::Delete(int32_t* aIdArray,
uint32_t aSize,
ErrorResult& aRv)
{
nsCOMPtr<nsIDOMMozSmsMessage> smsMessage =
do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, &aMessage.toObject()));
if (smsMessage) {
return smsMessage->GetId(aId);
}
nsCOMPtr<nsIDOMMozMmsMessage> mmsMessage =
do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, &aMessage.toObject()));
if (mmsMessage) {
return mmsMessage->GetId(aId);
}
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
MobileMessageManager::Delete(JS::Handle<JS::Value> aParam,
JSContext* aCx,
nsIDOMDOMRequest** aRequest)
{
// We expect Int32, SmsMessage, MmsMessage, Int32[], SmsMessage[], MmsMessage[]
if (!aParam.isObject() && !aParam.isInt32()) {
return NS_ERROR_INVALID_ARG;
}
nsresult rv = NS_OK;
int32_t id, *idArray;
uint32_t size;
if (aParam.isInt32()) {
// Single Integer Message ID
id = aParam.toInt32();
size = 1;
idArray = &id;
} else if (!JS_IsArrayObject(aCx, aParam)) {
// Single SmsMessage/MmsMessage object
rv = GetMessageId(aCx, aParam, &id);
NS_ENSURE_SUCCESS(rv, rv);
size = 1;
idArray = &id;
} else {
// Int32[], SmsMessage[], or MmsMessage[]
JS::Rooted<JSObject*> ids(aCx, &aParam.toObject());
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, ids, &size));
nsAutoArrayPtr<int32_t> idAutoArray(new int32_t[size]);
JS::Rooted<JS::Value> idJsValue(aCx);
for (uint32_t i = 0; i < size; i++) {
if (!JS_GetElement(aCx, ids, i, &idJsValue)) {
return NS_ERROR_INVALID_ARG;
}
if (idJsValue.isInt32()) {
idAutoArray[i] = idJsValue.toInt32();
} else if (idJsValue.isObject()) {
rv = GetMessageId(aCx, idJsValue, &id);
NS_ENSURE_SUCCESS(rv, rv);
idAutoArray[i] = id;
}
}
idArray = idAutoArray.forget();
}
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
if (!dbService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
new MobileMessageCallback(request);
rv = dbService->DeleteMessage(idArray, size, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv = dbService->DeleteMessage(aIdArray, aSize, msgCallback);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
request.forget(aRequest);
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
already_AddRefed<DOMRequest>
MobileMessageManager::Delete(int32_t aId,
ErrorResult& aRv)
{
return Delete(&aId, 1, aRv);
}
already_AddRefed<DOMRequest>
MobileMessageManager::Delete(nsIDOMMozSmsMessage* aMessage,
ErrorResult& aRv)
{
int32_t id;
DebugOnly<nsresult> rv = aMessage->GetId(&id);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return Delete(id, aRv);
}
already_AddRefed<DOMRequest>
MobileMessageManager::Delete(nsIDOMMozMmsMessage* aMessage,
ErrorResult& aRv)
{
int32_t id;
DebugOnly<nsresult> rv = aMessage->GetId(&id);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return Delete(id, aRv);
}
already_AddRefed<DOMRequest>
MobileMessageManager::Delete(const Sequence<OwningLongOrMozSmsMessageOrMozMmsMessage>& aParams,
ErrorResult& aRv)
{
const uint32_t size = aParams.Length();
FallibleTArray<int32_t> idArray;
if (!idArray.SetLength(size)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
DebugOnly<nsresult> rv;
for (uint32_t i = 0; i < size; i++) {
const OwningLongOrMozSmsMessageOrMozMmsMessage& element = aParams[i];
int32_t &id = idArray[i];
if (element.IsLong()) {
id = element.GetAsLong();
} else if (element.IsMozMmsMessage()) {
rv = element.GetAsMozMmsMessage()->GetId(&id);
MOZ_ASSERT(NS_SUCCEEDED(rv));
} else /*if (element.IsMozSmsMessage())*/ {
rv = element.GetAsMozSmsMessage()->GetId(&id);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
}
return Delete(idArray.Elements(), size, aRv);
}
already_AddRefed<DOMCursor>
MobileMessageManager::GetMessages(nsIDOMMozSmsFilter* aFilter,
bool aReverse,
nsIDOMDOMCursor** aCursor)
ErrorResult& aRv)
{
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
if (!dbService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIDOMMozSmsFilter> filter = aFilter;
if (!filter) {
@ -411,40 +390,51 @@ MobileMessageManager::GetMessages(nsIDOMMozSmsFilter* aFilter,
nsCOMPtr<nsICursorContinueCallback> continueCallback;
nsresult rv = dbService->CreateMessageCursor(filter, aReverse, cursorCallback,
getter_AddRefs(continueCallback));
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
cursorCallback->mDOMCursor = new DOMCursor(GetOwner(), continueCallback);
NS_ADDREF(*aCursor = cursorCallback->mDOMCursor);
return NS_OK;
nsRefPtr<DOMCursor> cursor = cursorCallback->mDOMCursor;
return cursor.forget();
}
NS_IMETHODIMP
already_AddRefed<DOMRequest>
MobileMessageManager::MarkMessageRead(int32_t aId,
bool aValue,
bool aSendReadReport,
nsIDOMDOMRequest** aRequest)
ErrorResult& aRv)
{
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
if (!dbService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
nsresult rv = dbService->MarkMessageRead(aId, aValue, aSendReadReport,
msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
request.forget(aRequest);
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
MobileMessageManager::GetThreads(nsIDOMDOMCursor** aCursor)
already_AddRefed<DOMCursor>
MobileMessageManager::GetThreads(ErrorResult& aRv)
{
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
if (!dbService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<MobileMessageCursorCallback> cursorCallback =
new MobileMessageCursorCallback();
@ -452,29 +442,49 @@ MobileMessageManager::GetThreads(nsIDOMDOMCursor** aCursor)
nsCOMPtr<nsICursorContinueCallback> continueCallback;
nsresult rv = dbService->CreateThreadCursor(cursorCallback,
getter_AddRefs(continueCallback));
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
cursorCallback->mDOMCursor = new DOMCursor(GetOwner(), continueCallback);
NS_ADDREF(*aCursor = cursorCallback->mDOMCursor);
return NS_OK;
nsRefPtr<DOMCursor> cursor = cursorCallback->mDOMCursor;
return cursor.forget();
}
NS_IMETHODIMP
already_AddRefed<DOMRequest>
MobileMessageManager::RetrieveMMS(int32_t aId,
nsIDOMDOMRequest** aRequest)
ErrorResult& aRv)
{
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
if (!mmsService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
nsresult rv = mmsService->Retrieve(aId, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
request.forget(aRequest);
return NS_OK;
return request.forget();
}
already_AddRefed<DOMRequest>
MobileMessageManager::RetrieveMMS(nsIDOMMozMmsMessage* aMessage,
ErrorResult& aRv)
{
int32_t id;
DebugOnly<nsresult> rv = aMessage->GetId(&id);
MOZ_ASSERT(NS_SUCCEEDED(rv));
return RetrieveMMS(id, aRv);
}
nsresult
@ -557,27 +567,38 @@ MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
return NS_OK;
}
NS_IMETHODIMP
MobileMessageManager::GetSmscAddress(uint32_t aServiceId,
uint8_t aArgc,
nsIDOMDOMRequest** aRequest)
already_AddRefed<DOMRequest>
MobileMessageManager::GetSmscAddress(const Optional<uint32_t>& aServiceId,
ErrorResult& aRv)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
if (!smsService) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// Use the default one unless |aSendParams.serviceId| is available.
uint32_t serviceId;
nsresult rv;
if (aArgc == 0) {
rv = smsService->GetSmsDefaultServiceId(&aServiceId);
NS_ENSURE_SUCCESS(rv, rv);
if (aServiceId.WasPassed()) {
serviceId = aServiceId.Value();
} else {
rv = smsService->GetSmsDefaultServiceId(&serviceId);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
}
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
rv = smsService->GetSmscAddress(aServiceId, msgCallback);
NS_ENSURE_SUCCESS(rv, rv);
rv = smsService->GetSmscAddress(serviceId, msgCallback);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
request.forget(aRequest);
return NS_OK;
return request.forget();
}
} // namespace dom

View File

@ -6,43 +6,140 @@
#ifndef mozilla_dom_mobilemessage_MobileMessageManager_h
#define mozilla_dom_mobilemessage_MobileMessageManager_h
#include "mozilla/Attributes.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "nsIDOMMobileMessageManager.h"
#include "nsIObserver.h"
class nsISmsService;
class nsIDOMMozSmsMessage;
class nsIDOMMozMmsMessage;
class nsIDOMMozSmsFilter;
namespace mozilla {
namespace dom {
class MobileMessageManager : public DOMEventTargetHelper
, public nsIDOMMozMobileMessageManager
, public nsIObserver
class DOMRequest;
class DOMCursor;
class MmsParameters;
class MmsSendParameters;
class SmsSendParameters;
class MobileMessageManager MOZ_FINAL : public DOMEventTargetHelper
, public nsIObserver
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMMOZMOBILEMESSAGEMANAGER
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
void Init(nsPIDOMWindow *aWindow);
MobileMessageManager(nsPIDOMWindow* aWindow);
void Init();
void Shutdown();
nsPIDOMWindow*
GetParentObject() const { return GetOwner(); }
// WrapperCache
virtual JSObject*
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
// WebIDL Interface
already_AddRefed<DOMRequest>
GetSegmentInfoForText(const nsAString& aText,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
Send(const nsAString& aNumber,
const nsAString& aText,
const SmsSendParameters& aSendParams,
ErrorResult& aRv);
void
Send(const Sequence<nsString>& aNumbers,
const nsAString& aText,
const SmsSendParameters& aSendParams,
nsTArray<nsRefPtr<DOMRequest>>& aReturn,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
SendMMS(const MmsParameters& aParameters,
const MmsSendParameters& aSendParams,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
GetMessage(int32_t aId,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
Delete(int32_t aId,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
Delete(nsIDOMMozSmsMessage* aMessage,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
Delete(nsIDOMMozMmsMessage* aMessage,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
Delete(const Sequence<OwningLongOrMozSmsMessageOrMozMmsMessage>& aParams,
ErrorResult& aRv);
already_AddRefed<DOMCursor>
GetMessages(nsIDOMMozSmsFilter* aFilter,
bool aReverse,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
MarkMessageRead(int32_t aId,
bool aRead,
bool aSendReadReport,
ErrorResult& aRv);
already_AddRefed<DOMCursor>
GetThreads(ErrorResult& aRv);
already_AddRefed<DOMRequest>
RetrieveMMS(int32_t aId,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
RetrieveMMS(nsIDOMMozMmsMessage* aMessage,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
GetSmscAddress(const Optional<uint32_t>& aServiceId,
ErrorResult& aRv);
IMPL_EVENT_HANDLER(received)
IMPL_EVENT_HANDLER(retrieving)
IMPL_EVENT_HANDLER(sending)
IMPL_EVENT_HANDLER(sent)
IMPL_EVENT_HANDLER(failed)
IMPL_EVENT_HANDLER(deliverysuccess)
IMPL_EVENT_HANDLER(deliveryerror)
IMPL_EVENT_HANDLER(readsuccess)
IMPL_EVENT_HANDLER(readerror)
private:
/**
* Internal Send() method used to send one message.
*/
nsresult
Send(JSContext* aCx,
JS::Handle<JSObject*> aGlobal,
nsISmsService* aSmsService,
already_AddRefed<DOMRequest>
Send(nsISmsService* aSmsService,
uint32_t aServiceId,
JS::Handle<JSString*> aNumber,
const nsAString& aNumber,
const nsAString& aText,
JS::MutableHandle<JS::Value> aRequest);
ErrorResult& aRv);
already_AddRefed<DOMRequest>
Delete(int32_t* aIdArray,
uint32_t aSize,
ErrorResult& aRv);
nsresult
DispatchTrustedSmsEventToSelf(const char* aTopic,

View File

@ -12,8 +12,7 @@
#include "SmsSegmentInfo.h"
#include "nsJSUtils.h"
#include "nsCxPusher.h"
#include "mozilla/dom/MobileMessageManagerBinding.h"
#include "mozilla/dom/MozMmsMessageBinding.h"
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/Preferences.h"
#include "nsString.h"