2013-03-08 23:21:47 -08:00
|
|
|
/* -*- 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"
|
2013-03-08 23:22:32 -08:00
|
|
|
#include "nsIMmsService.h"
|
2013-03-08 23:21:47 -08:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "Constants.h"
|
|
|
|
#include "nsIDOMMozSmsEvent.h"
|
2013-03-08 23:22:42 -08:00
|
|
|
#include "nsIDOMMozMmsEvent.h"
|
2013-03-08 23:21:47 -08:00
|
|
|
#include "nsIDOMMozSmsMessage.h"
|
2013-03-08 23:22:42 -08:00
|
|
|
#include "nsIDOMMozMmsMessage.h"
|
2013-03-08 23:21:47 -08:00
|
|
|
#include "nsJSUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
2013-05-22 09:05:26 -07:00
|
|
|
#include "nsCxPusher.h"
|
2013-03-08 23:21:47 -08:00
|
|
|
#include "nsIMobileMessageDatabaseService.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsIPermissionManager.h"
|
|
|
|
#include "GeneratedEvents.h"
|
2013-03-08 23:22:32 -08:00
|
|
|
#include "DOMRequest.h"
|
|
|
|
#include "nsIMobileMessageCallback.h"
|
|
|
|
#include "MobileMessageCallback.h"
|
2013-04-09 09:35:59 -07:00
|
|
|
#include "MobileMessageCursorCallback.h"
|
|
|
|
#include "DOMCursor.h"
|
2013-03-08 23:21:47 -08:00
|
|
|
|
|
|
|
#define RECEIVED_EVENT_NAME NS_LITERAL_STRING("received")
|
2013-05-10 13:39:22 -07:00
|
|
|
#define RETRIEVING_EVENT_NAME NS_LITERAL_STRING("retrieving")
|
2013-03-08 23:21:47 -08:00
|
|
|
#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)
|
2013-05-10 13:39:22 -07:00
|
|
|
NS_IMPL_EVENT_HANDLER(MobileMessageManager, retrieving)
|
2013-03-08 23:21:47 -08:00
|
|
|
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);
|
2013-05-10 13:39:22 -07:00
|
|
|
obs->AddObserver(this, kSmsRetrievingObserverTopic, false);
|
2013-03-08 23:21:47 -08:00
|
|
|
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);
|
2013-05-10 13:39:22 -07:00
|
|
|
obs->RemoveObserver(this, kSmsRetrievingObserverTopic);
|
2013-03-08 23:21:47 -08:00
|
|
|
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
|
2013-05-11 22:17:42 -07:00
|
|
|
MobileMessageManager::Send(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
|
|
|
|
JS::Handle<JSString*> aNumber,
|
2013-04-02 15:42:37 -07:00
|
|
|
const nsAString& aMessage, JS::Value* aRequest)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
2013-04-09 09:41:27 -07:00
|
|
|
NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
|
2013-03-08 23:21:47 -08:00
|
|
|
|
|
|
|
nsDependentJSString number;
|
|
|
|
number.init(aCx, aNumber);
|
|
|
|
|
2013-04-09 09:41:27 -07:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
|
|
|
new MobileMessageCallback(request);
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-07-29 15:50:21 -07:00
|
|
|
// By default, we don't send silent messages via MobileMessageManager.
|
|
|
|
nsresult rv = smsService->Send(number, aMessage, false, msgCallback);
|
2013-04-09 09:41:27 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-05-02 02:12:46 -07:00
|
|
|
JS::Rooted<JSObject*> global(aCx, aGlobal);
|
|
|
|
rv = nsContentUtils::WrapNative(aCx, global,
|
2013-04-09 09:41:27 -07:00
|
|
|
static_cast<nsIDOMDOMRequest*>(request.get()),
|
|
|
|
aRequest);
|
2013-03-08 23:21:47 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("Failed to create the js value!");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-05-11 22:17:42 -07:00
|
|
|
MobileMessageManager::Send(const JS::Value& aNumber_, const nsAString& aMessage, JS::Value* aReturn)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
|
|
|
NS_ENSURE_STATE(sc);
|
|
|
|
AutoPushJSContext cx(sc->GetNativeContext());
|
|
|
|
NS_ASSERTION(cx, "Failed to get a context!");
|
|
|
|
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JS::Value> aNumber(cx, aNumber_);
|
2013-03-08 23:21:47 -08:00
|
|
|
if (!aNumber.isString() &&
|
|
|
|
!(aNumber.isObject() && JS_IsArrayObject(cx, &aNumber.toObject()))) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JSObject*> global(cx, sc->GetNativeGlobal());
|
2013-03-08 23:21:47 -08:00
|
|
|
NS_ASSERTION(global, "Failed to get global object!");
|
|
|
|
|
|
|
|
JSAutoCompartment ac(cx, global);
|
|
|
|
|
|
|
|
if (aNumber.isString()) {
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JSString*> str(cx, aNumber.toString());
|
|
|
|
return Send(cx, global, str, aMessage, aReturn);
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Must be an array then.
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JSObject*> numbers(cx, &aNumber.toObject());
|
2013-03-08 23:21:47 -08:00
|
|
|
|
|
|
|
uint32_t size;
|
2013-05-11 22:17:42 -07:00
|
|
|
JS_ALWAYS_TRUE(JS_GetArrayLength(cx, numbers, &size));
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-04-02 15:42:37 -07:00
|
|
|
JS::Value* requests = new JS::Value[size];
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JS::Value> number(cx);
|
2013-03-08 23:21:47 -08:00
|
|
|
for (uint32_t i=0; i<size; ++i) {
|
2013-08-05 06:02:47 -07:00
|
|
|
if (!JS_GetElement(cx, numbers, i, &number)) {
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JSString*> str(cx, number.toString());
|
|
|
|
nsresult rv = Send(cx, global, str, aMessage, &requests[i]);
|
2013-03-08 23:21:47 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
aReturn->setObjectOrNull(JS_NewArrayObject(cx, size, requests));
|
|
|
|
NS_ENSURE_TRUE(aReturn->isObject(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-08 23:22:32 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileMessageManager::SendMMS(const JS::Value& aParams, nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
2013-04-10 05:18:32 -07:00
|
|
|
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
|
2013-03-08 23:22:32 -08:00
|
|
|
NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
|
|
|
nsresult rv = mmsService->Send(aParams, msgCallback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
request.forget(aRequest);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
NS_IMETHODIMP
|
2013-03-07 19:46:16 -08:00
|
|
|
MobileMessageManager::GetMessageMoz(int32_t aId, nsIDOMDOMRequest** aRequest)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
|
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
|
2013-03-07 19:46:16 -08:00
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
|
|
|
nsresult rv = mobileMessageDBService->GetMessageMoz(aId, msgCallback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
request.forget(aRequest);
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-05-10 01:45:05 -07:00
|
|
|
MobileMessageManager::GetMessageId(AutoPushJSContext &aCx,
|
|
|
|
const JS::Value &aMessage, int32_t &aId)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
2013-05-10 01:45:05 -07:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> smsMessage =
|
|
|
|
do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, &aMessage.toObject()));
|
|
|
|
if (smsMessage) {
|
|
|
|
return smsMessage->GetId(&aId);
|
|
|
|
}
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-05-10 01:45:05 -07:00
|
|
|
nsCOMPtr<nsIDOMMozMmsMessage> mmsMessage =
|
|
|
|
do_QueryInterface(nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, &aMessage.toObject()));
|
|
|
|
if (mmsMessage) {
|
|
|
|
return mmsMessage->GetId(&aId);
|
|
|
|
}
|
2013-03-07 20:06:06 -08:00
|
|
|
|
2013-05-10 01:45:05 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-02 15:42:37 -07:00
|
|
|
MobileMessageManager::Delete(const JS::Value& aParam, nsIDOMDOMRequest** aRequest)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
2013-05-10 01:45:05 -07:00
|
|
|
// We expect Int32, SmsMessage, MmsMessage, Int32[], SmsMessage[], MmsMessage[]
|
|
|
|
if (!aParam.isObject() && !aParam.isInt32()) {
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
|
|
|
|
AutoPushJSContext cx(sc->GetNativeContext());
|
|
|
|
NS_ENSURE_STATE(sc);
|
|
|
|
|
2013-05-10 01:45:05 -07:00
|
|
|
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(cx, &aParam.toObject())) {
|
|
|
|
// Single SmsMessage/MmsMessage object
|
|
|
|
rv = GetMessageId(cx, aParam, id);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
size = 1;
|
|
|
|
idArray = &id;
|
2013-03-07 20:06:06 -08:00
|
|
|
} else {
|
2013-05-10 01:45:05 -07:00
|
|
|
// Int32[], SmsMessage[], or MmsMessage[]
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JSObject*> ids(cx, &aParam.toObject());
|
2013-05-10 01:45:05 -07:00
|
|
|
|
2013-05-11 22:17:42 -07:00
|
|
|
JS_ALWAYS_TRUE(JS_GetArrayLength(cx, ids, &size));
|
2013-05-10 01:45:05 -07:00
|
|
|
nsAutoArrayPtr<int32_t> idAutoArray(new int32_t[size]);
|
|
|
|
|
2013-05-11 22:17:42 -07:00
|
|
|
JS::Rooted<JS::Value> idJsValue(cx);
|
2013-05-10 01:45:05 -07:00
|
|
|
for (uint32_t i = 0; i < size; i++) {
|
2013-08-05 06:02:47 -07:00
|
|
|
if (!JS_GetElement(cx, ids, i, &idJsValue)) {
|
2013-05-10 01:45:05 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (idJsValue.isInt32()) {
|
|
|
|
idAutoArray[i] = idJsValue.toInt32();
|
|
|
|
} else if (idJsValue.isObject()) {
|
|
|
|
rv = GetMessageId(cx, idJsValue, id);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
idAutoArray[i] = id;
|
|
|
|
}
|
2013-03-07 20:06:06 -08:00
|
|
|
}
|
2013-05-10 01:45:05 -07:00
|
|
|
|
|
|
|
idArray = idAutoArray.forget();
|
2013-03-07 20:06:06 -08:00
|
|
|
}
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-05-10 01:45:05 -07:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
|
|
|
new MobileMessageCallback(request);
|
|
|
|
|
|
|
|
rv = dbService->DeleteMessage(idArray, size, msgCallback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
request.forget(aRequest);
|
|
|
|
return NS_OK;
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-09 09:35:59 -07:00
|
|
|
MobileMessageManager::GetMessages(nsIDOMMozSmsFilter* aFilter,
|
|
|
|
bool aReverse,
|
|
|
|
nsIDOMDOMCursor** aCursor)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
2013-04-09 09:35:59 -07:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
nsCOMPtr<nsIDOMMozSmsFilter> filter = aFilter;
|
|
|
|
if (!filter) {
|
|
|
|
filter = new SmsFilter();
|
|
|
|
}
|
|
|
|
|
2013-04-09 09:35:59 -07:00
|
|
|
nsRefPtr<MobileMessageCursorCallback> cursorCallback =
|
|
|
|
new MobileMessageCursorCallback();
|
|
|
|
|
|
|
|
nsCOMPtr<nsICursorContinueCallback> continueCallback;
|
|
|
|
nsresult rv = dbService->CreateMessageCursor(filter, aReverse, cursorCallback,
|
|
|
|
getter_AddRefs(continueCallback));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
cursorCallback->mDOMCursor = new DOMCursor(GetOwner(), continueCallback);
|
|
|
|
NS_ADDREF(*aCursor = cursorCallback->mDOMCursor);
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileMessageManager::MarkMessageRead(int32_t aId, bool aValue,
|
2013-03-10 21:14:15 -07:00
|
|
|
nsIDOMDOMRequest** aRequest)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
|
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(mobileMessageDBService, NS_ERROR_FAILURE);
|
2013-03-10 21:14:15 -07:00
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
|
|
|
nsresult rv = mobileMessageDBService->MarkMessageRead(aId, aValue, msgCallback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
request.forget(aRequest);
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-04-09 09:37:54 -07:00
|
|
|
MobileMessageManager::GetThreads(nsIDOMDOMCursor** aCursor)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
2013-04-09 09:37:54 -07:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
2013-03-08 23:21:47 -08:00
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
2013-04-09 09:37:54 -07:00
|
|
|
NS_ENSURE_TRUE(dbService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsRefPtr<MobileMessageCursorCallback> cursorCallback =
|
|
|
|
new MobileMessageCursorCallback();
|
|
|
|
|
|
|
|
nsCOMPtr<nsICursorContinueCallback> continueCallback;
|
|
|
|
nsresult rv = dbService->CreateThreadCursor(cursorCallback,
|
|
|
|
getter_AddRefs(continueCallback));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
cursorCallback->mDOMCursor = new DOMCursor(GetOwner(), continueCallback);
|
|
|
|
NS_ADDREF(*aCursor = cursorCallback->mDOMCursor);
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-21 02:57:41 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileMessageManager::RetrieveMMS(int32_t id,
|
|
|
|
nsIDOMDOMRequest** aRequest)
|
|
|
|
{
|
2013-04-10 05:18:43 -07:00
|
|
|
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
|
2013-03-21 02:57:41 -07:00
|
|
|
NS_ENSURE_TRUE(mmsService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
|
|
|
|
|
|
|
nsresult rv = mmsService->Retrieve(id, msgCallback);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
request.forget(aRequest);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
nsresult
|
2013-04-10 05:18:35 -07:00
|
|
|
MobileMessageManager::DispatchTrustedSmsEventToSelf(const char* aTopic,
|
|
|
|
const nsAString& aEventName,
|
|
|
|
nsISupports* aMsg)
|
2013-03-08 23:21:47 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
|
2013-04-10 05:18:35 -07:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> sms = do_QueryInterface(aMsg);
|
|
|
|
if (sms) {
|
|
|
|
NS_NewDOMMozSmsEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
|
|
|
NS_ASSERTION(event, "This should never fail!");
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-04-10 05:18:35 -07:00
|
|
|
nsCOMPtr<nsIDOMMozSmsEvent> se = do_QueryInterface(event);
|
|
|
|
nsresult rv = se->InitMozSmsEvent(aEventName, false, false, sms);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
2013-03-08 23:21:47 -08:00
|
|
|
|
2013-04-10 05:18:35 -07:00
|
|
|
nsCOMPtr<nsIDOMMozMmsMessage> mms = do_QueryInterface(aMsg);
|
|
|
|
if (mms) {
|
|
|
|
NS_NewDOMMozMmsEvent(getter_AddRefs(event), this, nullptr, nullptr);
|
|
|
|
NS_ASSERTION(event, "This should never fail!");
|
2013-03-08 23:22:42 -08:00
|
|
|
|
2013-04-10 05:18:35 -07:00
|
|
|
nsCOMPtr<nsIDOMMozMmsEvent> se = do_QueryInterface(event);
|
|
|
|
nsresult rv = se->InitMozMmsEvent(aEventName, false, false, mms);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
2013-03-08 23:22:42 -08:00
|
|
|
|
2013-04-10 05:18:35 -07:00
|
|
|
nsAutoCString errorMsg;
|
|
|
|
errorMsg.AssignLiteral("Got a '");
|
|
|
|
errorMsg.Append(aTopic);
|
|
|
|
errorMsg.AppendLiteral("' topic without a valid message!");
|
|
|
|
NS_ERROR(errorMsg.get());
|
|
|
|
return NS_OK;
|
2013-03-08 23:22:42 -08:00
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, kSmsReceivedObserverTopic)) {
|
2013-04-10 05:18:35 -07:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, RECEIVED_EVENT_NAME, aSubject);
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
2013-05-10 13:39:22 -07:00
|
|
|
if (!strcmp(aTopic, kSmsRetrievingObserverTopic)) {
|
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, RETRIEVING_EVENT_NAME, aSubject);
|
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
if (!strcmp(aTopic, kSmsSendingObserverTopic)) {
|
2013-04-10 05:18:35 -07:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, SENDING_EVENT_NAME, aSubject);
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsSentObserverTopic)) {
|
2013-04-10 05:18:35 -07:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, SENT_EVENT_NAME, aSubject);
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsFailedObserverTopic)) {
|
2013-04-10 05:18:35 -07:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, FAILED_EVENT_NAME, aSubject);
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsDeliverySuccessObserverTopic)) {
|
2013-04-10 05:18:35 -07:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, DELIVERY_SUCCESS_EVENT_NAME, aSubject);
|
2013-03-08 23:21:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsDeliveryErrorObserverTopic)) {
|
2013-04-10 05:18:35 -07:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, DELIVERY_ERROR_EVENT_NAME, aSubject);
|
2013-03-18 03:47:41 -07:00
|
|
|
}
|
|
|
|
|
2013-03-08 23:21:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|