2013-03-09 11:21:47 +04: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 "MobileMessageManager.h"
|
2014-06-25 07:57:18 +04:00
|
|
|
|
2014-06-27 09:25:37 +04:00
|
|
|
#include "DeletedMessageInfo.h"
|
2014-06-25 07:57:18 +04:00
|
|
|
#include "DOMCursor.h"
|
|
|
|
#include "DOMRequest.h"
|
|
|
|
#include "MobileMessageCallback.h"
|
|
|
|
#include "MobileMessageCursorCallback.h"
|
|
|
|
#include "mozilla/dom/mobilemessage/Constants.h" // For kSms*ObserverTopic
|
2014-06-27 09:25:37 +04:00
|
|
|
#include "mozilla/dom/MozMessageDeletedEvent.h"
|
2014-06-11 05:23:34 +04:00
|
|
|
#include "mozilla/dom/MozMmsEvent.h"
|
2014-06-25 07:57:16 +04:00
|
|
|
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
|
2014-06-11 05:23:34 +04:00
|
|
|
#include "mozilla/dom/MozSmsEvent.h"
|
2014-06-25 07:57:16 +04:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2014-06-25 07:57:18 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
2013-03-09 11:22:42 +04:00
|
|
|
#include "nsIDOMMozMmsMessage.h"
|
2014-06-25 07:57:18 +04:00
|
|
|
#include "nsIDOMMozSmsMessage.h"
|
|
|
|
#include "nsIMmsService.h"
|
2013-03-09 11:22:32 +04:00
|
|
|
#include "nsIMobileMessageCallback.h"
|
2014-06-25 07:57:18 +04:00
|
|
|
#include "nsIMobileMessageDatabaseService.h"
|
2014-09-21 11:24:44 +04:00
|
|
|
#include "nsIMobileMessageService.h"
|
2014-06-25 07:57:18 +04:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsISmsService.h"
|
|
|
|
#include "nsServiceManagerUtils.h" // For do_GetService()
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-09-21 11:24:44 +04:00
|
|
|
// Service instantiation
|
|
|
|
#include "ipc/SmsIPCService.h"
|
|
|
|
#include "MobileMessageService.h"
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "android/MobileMessageDatabaseService.h"
|
|
|
|
#include "android/SmsService.h"
|
|
|
|
#elif defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
2014-12-10 10:30:59 +03:00
|
|
|
#include "nsIGonkMobileMessageDatabaseService.h"
|
2014-11-24 13:43:54 +03:00
|
|
|
#include "nsIGonkSmsService.h"
|
2014-09-21 11:24:44 +04:00
|
|
|
#endif
|
|
|
|
#include "nsXULAppAPI.h" // For XRE_GetProcessType()
|
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
#define RECEIVED_EVENT_NAME NS_LITERAL_STRING("received")
|
2013-05-11 00:39:22 +04:00
|
|
|
#define RETRIEVING_EVENT_NAME NS_LITERAL_STRING("retrieving")
|
2013-03-09 11:21:47 +04: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")
|
2013-11-25 14:54:59 +04:00
|
|
|
#define READ_SUCCESS_EVENT_NAME NS_LITERAL_STRING("readsuccess")
|
|
|
|
#define READ_ERROR_EVENT_NAME NS_LITERAL_STRING("readerror")
|
2014-06-27 09:25:37 +04:00
|
|
|
#define DELETED_EVENT_NAME NS_LITERAL_STRING("deleted")
|
2013-03-09 11:21:47 +04:00
|
|
|
|
|
|
|
using namespace mozilla::dom::mobilemessage;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(MobileMessageManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(MobileMessageManager, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MobileMessageManager, DOMEventTargetHelper)
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
MobileMessageManager::MobileMessageManager(nsPIDOMWindow *aWindow)
|
|
|
|
: DOMEventTargetHelper(aWindow)
|
|
|
|
{
|
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
|
|
|
void
|
2014-06-25 07:57:16 +04:00
|
|
|
MobileMessageManager::Init()
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
// GetObserverService() can return null is some situations like shutdown.
|
|
|
|
if (!obs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
|
2013-05-11 00:39:22 +04:00
|
|
|
obs->AddObserver(this, kSmsRetrievingObserverTopic, false);
|
2013-03-09 11:21:47 +04: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);
|
2013-11-25 14:54:59 +04:00
|
|
|
obs->AddObserver(this, kSmsReadSuccessObserverTopic, false);
|
|
|
|
obs->AddObserver(this, kSmsReadErrorObserverTopic, false);
|
2014-06-27 09:25:37 +04:00
|
|
|
obs->AddObserver(this, kSmsDeletedObserverTopic, false);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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-11 00:39:22 +04:00
|
|
|
obs->RemoveObserver(this, kSmsRetrievingObserverTopic);
|
2013-03-09 11:21:47 +04:00
|
|
|
obs->RemoveObserver(this, kSmsSendingObserverTopic);
|
|
|
|
obs->RemoveObserver(this, kSmsSentObserverTopic);
|
|
|
|
obs->RemoveObserver(this, kSmsFailedObserverTopic);
|
|
|
|
obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic);
|
|
|
|
obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic);
|
2013-11-25 14:54:59 +04:00
|
|
|
obs->RemoveObserver(this, kSmsReadSuccessObserverTopic);
|
|
|
|
obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
|
2014-06-27 09:25:37 +04:00
|
|
|
obs->RemoveObserver(this, kSmsDeletedObserverTopic);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
JSObject*
|
|
|
|
MobileMessageManager::WrapObject(JSContext* aCx)
|
|
|
|
{
|
|
|
|
return MozMobileMessageManagerBinding::Wrap(aCx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DOMRequest>
|
2013-03-09 11:21:47 +04:00
|
|
|
MobileMessageManager::GetSegmentInfoForText(const nsAString& aText,
|
2014-06-25 07:57:16 +04:00
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!smsService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2013-08-09 17:25:53 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
|
|
|
new MobileMessageCallback(request);
|
|
|
|
nsresult rv = smsService->GetSegmentInfoForText(aText, msgCallback);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-08-09 17:25:53 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return request.forget();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::Send(nsISmsService* aSmsService,
|
2013-11-02 14:17:16 +04:00
|
|
|
uint32_t aServiceId,
|
2014-06-25 07:57:16 +04:00
|
|
|
const nsAString& aNumber,
|
2014-06-25 07:57:15 +04:00
|
|
|
const nsAString& aText,
|
2014-06-25 07:57:16 +04:00
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2013-04-09 20:41:27 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
|
|
|
new MobileMessageCallback(request);
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2013-07-30 02:50:21 +04:00
|
|
|
// By default, we don't send silent messages via MobileMessageManager.
|
2014-06-25 07:57:16 +04:00
|
|
|
nsresult rv = aSmsService->Send(aServiceId, aNumber, aText,
|
2014-06-25 07:57:15 +04:00
|
|
|
false, msgCallback);
|
2013-03-09 11:21:47 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-06-25 07:57:16 +04:00
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return request.forget();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::Send(const nsAString& aNumber,
|
2014-06-25 07:57:15 +04:00
|
|
|
const nsAString& aText,
|
2014-06-25 07:57:16 +04:00
|
|
|
const SmsSendParameters& aSendParams,
|
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2013-11-02 14:17:16 +04:00
|
|
|
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!smsService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-11-02 14:17:16 +04:00
|
|
|
|
|
|
|
// Use the default one unless |aSendParams.serviceId| is available.
|
|
|
|
uint32_t serviceId;
|
2014-06-25 07:57:16 +04:00
|
|
|
if (aSendParams.mServiceId.WasPassed()) {
|
|
|
|
serviceId = aSendParams.mServiceId.Value();
|
2014-06-25 07:57:15 +04:00
|
|
|
} else {
|
2014-06-25 07:57:16 +04:00
|
|
|
nsresult rv = smsService->GetSmsDefaultServiceId(&serviceId);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return Send(smsService, serviceId, aNumber, aText, aRv);
|
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
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;
|
2013-11-06 04:09:33 +04:00
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
// 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;
|
|
|
|
}
|
2013-11-06 04:09:33 +04:00
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
const uint32_t size = aNumbers.Length();
|
2013-11-02 14:17:16 +04:00
|
|
|
for (uint32_t i = 0; i < size; ++i) {
|
2014-06-25 07:57:16 +04:00
|
|
|
nsRefPtr<DOMRequest> request = Send(smsService, serviceId, aNumbers[i], aText, aRv);
|
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
2013-11-06 04:09:33 +04:00
|
|
|
}
|
2014-06-25 07:57:16 +04:00
|
|
|
aReturn.AppendElement(request);
|
2013-11-06 04:09:33 +04:00
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::SendMMS(const MmsParameters& aParams,
|
|
|
|
const MmsSendParameters& aSendParams,
|
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:22:32 +04:00
|
|
|
{
|
2013-04-10 16:18:32 +04:00
|
|
|
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!mmsService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-09 11:22:32 +04:00
|
|
|
|
2013-11-02 14:17:16 +04:00
|
|
|
// Use the default one unless |aSendParams.serviceId| is available.
|
|
|
|
uint32_t serviceId;
|
2014-06-25 07:57:15 +04:00
|
|
|
nsresult rv;
|
2014-06-25 07:57:16 +04:00
|
|
|
if (aSendParams.mServiceId.WasPassed()) {
|
|
|
|
serviceId = aSendParams.mServiceId.Value();
|
|
|
|
} else {
|
|
|
|
rv = mmsService->GetMmsDefaultServiceId(&serviceId);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-11-02 14:17:16 +04:00
|
|
|
}
|
2014-06-25 07:57:15 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
AutoJSAPI jsapi;
|
2014-11-07 07:56:00 +03:00
|
|
|
if (NS_WARN_IF(!jsapi.Init(GetOwner()))) {
|
2014-06-25 07:57:16 +04:00
|
|
|
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;
|
2013-11-02 14:17:16 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 11:22:32 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
2014-06-25 07:57:16 +04:00
|
|
|
rv = mmsService->Send(serviceId, val, msgCallback);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-09 11:22:32 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return request.forget();
|
2013-03-09 11:22:32 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::GetMessage(int32_t aId,
|
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2014-06-25 07:57:15 +04:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
2013-03-09 11:21:47 +04:00
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!dbService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-08 07:46:16 +04:00
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
2014-06-25 07:57:15 +04:00
|
|
|
nsresult rv = dbService->GetMessageMoz(aId, msgCallback);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-08 07:46:16 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return request.forget();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::Delete(int32_t* aIdArray,
|
|
|
|
uint32_t aSize,
|
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2014-06-25 07:57:16 +04:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
|
|
|
if (!dbService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
2013-05-10 12:45:05 +04:00
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
|
|
|
new MobileMessageCallback(request);
|
|
|
|
|
|
|
|
nsresult rv = dbService->DeleteMessage(aIdArray, aSize, msgCallback);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
2013-05-10 12:45:05 +04:00
|
|
|
}
|
2013-03-08 08:06:06 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return request.forget();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::Delete(int32_t aId,
|
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2014-06-25 07:57:16 +04:00
|
|
|
return Delete(&aId, 1, aRv);
|
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::Delete(nsIDOMMozSmsMessage* aMessage,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
int32_t id;
|
2013-05-10 12:45:05 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
DebugOnly<nsresult> rv = aMessage->GetId(&id);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2013-05-10 12:45:05 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return Delete(id, aRv);
|
|
|
|
}
|
2013-05-10 12:45:05 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::Delete(nsIDOMMozMmsMessage* aMessage,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
int32_t id;
|
2013-05-10 12:45:05 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
DebugOnly<nsresult> rv = aMessage->GetId(&id);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return Delete(id, aRv);
|
|
|
|
}
|
2013-05-10 12:45:05 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
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;
|
|
|
|
}
|
2013-05-10 12:45:05 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2013-05-10 12:45:05 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return Delete(idArray.Elements(), size, aRv);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMCursor>
|
2014-08-28 07:00:03 +04:00
|
|
|
MobileMessageManager::GetMessages(const MobileMessageFilter& aFilter,
|
2013-04-09 20:35:59 +04:00
|
|
|
bool aReverse,
|
2014-06-25 07:57:16 +04:00
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2013-04-09 20:35:59 +04:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!dbService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-04-09 20:35:59 +04:00
|
|
|
|
2014-08-28 07:00:03 +04:00
|
|
|
bool hasStartDate = !aFilter.mStartDate.IsNull();
|
|
|
|
uint64_t startDate = 0;
|
|
|
|
if (hasStartDate) {
|
|
|
|
startDate = aFilter.mStartDate.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasEndDate = !aFilter.mEndDate.IsNull();
|
|
|
|
uint64_t endDate = 0;
|
|
|
|
if (hasEndDate) {
|
|
|
|
endDate = aFilter.mEndDate.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoArrayPtr<const char16_t*> ptrNumbers;
|
|
|
|
uint32_t numbersCount = 0;
|
|
|
|
if (!aFilter.mNumbers.IsNull() &&
|
|
|
|
aFilter.mNumbers.Value().Length()) {
|
|
|
|
const FallibleTArray<nsString>& numbers = aFilter.mNumbers.Value();
|
|
|
|
uint32_t index;
|
|
|
|
|
|
|
|
numbersCount = numbers.Length();
|
|
|
|
ptrNumbers = new const char16_t* [numbersCount];
|
|
|
|
for (index = 0; index < numbersCount; index++) {
|
|
|
|
ptrNumbers[index] = numbers[index].get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString delivery;
|
|
|
|
delivery.SetIsVoid(true);
|
|
|
|
if (!aFilter.mDelivery.IsNull()) {
|
|
|
|
const uint32_t index = static_cast<uint32_t>(aFilter.mDelivery.Value());
|
|
|
|
const EnumEntry& entry =
|
|
|
|
MobileMessageFilterDeliveryValues::strings[index];
|
|
|
|
delivery.AssignASCII(entry.value, entry.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasRead = !aFilter.mRead.IsNull();
|
|
|
|
bool read = false;
|
|
|
|
if (hasRead) {
|
|
|
|
read = aFilter.mRead.Value();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t threadId = 0;
|
|
|
|
if (!aFilter.mThreadId.IsNull()) {
|
|
|
|
threadId = aFilter.mThreadId.Value();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2013-04-09 20:35:59 +04:00
|
|
|
nsRefPtr<MobileMessageCursorCallback> cursorCallback =
|
|
|
|
new MobileMessageCursorCallback();
|
|
|
|
nsCOMPtr<nsICursorContinueCallback> continueCallback;
|
2014-08-28 07:00:03 +04:00
|
|
|
nsresult rv = dbService->CreateMessageCursor(hasStartDate, startDate,
|
|
|
|
hasEndDate, endDate,
|
|
|
|
ptrNumbers, numbersCount,
|
|
|
|
delivery,
|
|
|
|
hasRead, read,
|
|
|
|
threadId,
|
|
|
|
aReverse, cursorCallback,
|
2013-04-09 20:35:59 +04:00
|
|
|
getter_AddRefs(continueCallback));
|
2014-06-25 07:57:16 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-04-09 20:35:59 +04:00
|
|
|
|
2014-09-04 07:15:41 +04:00
|
|
|
cursorCallback->mDOMCursor =
|
|
|
|
new MobileMessageCursor(GetOwner(), continueCallback);
|
2013-04-09 20:35:59 +04:00
|
|
|
|
2014-09-04 07:15:41 +04:00
|
|
|
nsRefPtr<DOMCursor> cursor(cursorCallback->mDOMCursor);
|
2014-06-25 07:57:16 +04:00
|
|
|
return cursor.forget();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-06-25 07:57:15 +04:00
|
|
|
MobileMessageManager::MarkMessageRead(int32_t aId,
|
|
|
|
bool aValue,
|
2013-11-04 07:36:00 +04:00
|
|
|
bool aSendReadReport,
|
2014-06-25 07:57:16 +04:00
|
|
|
ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2014-06-25 07:57:15 +04:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
2013-03-09 11:21:47 +04:00
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!dbService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-11 08:14:15 +04:00
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
2014-06-25 07:57:15 +04:00
|
|
|
nsresult rv = dbService->MarkMessageRead(aId, aValue, aSendReadReport,
|
|
|
|
msgCallback);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-11 08:14:15 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return request.forget();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMCursor>
|
|
|
|
MobileMessageManager::GetThreads(ErrorResult& aRv)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2013-04-09 20:37:54 +04:00
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
2013-03-09 11:21:47 +04:00
|
|
|
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!dbService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-04-09 20:37:54 +04:00
|
|
|
|
|
|
|
nsRefPtr<MobileMessageCursorCallback> cursorCallback =
|
|
|
|
new MobileMessageCursorCallback();
|
|
|
|
|
|
|
|
nsCOMPtr<nsICursorContinueCallback> continueCallback;
|
|
|
|
nsresult rv = dbService->CreateThreadCursor(cursorCallback,
|
|
|
|
getter_AddRefs(continueCallback));
|
2014-06-25 07:57:16 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-04-09 20:37:54 +04:00
|
|
|
|
2014-09-04 07:15:41 +04:00
|
|
|
cursorCallback->mDOMCursor =
|
|
|
|
new MobileMessageCursor(GetOwner(), continueCallback);
|
2013-04-09 20:37:54 +04:00
|
|
|
|
2014-09-04 07:15:41 +04:00
|
|
|
nsRefPtr<DOMCursor> cursor(cursorCallback->mDOMCursor);
|
2014-06-25 07:57:16 +04:00
|
|
|
return cursor.forget();
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
2014-06-25 07:57:15 +04:00
|
|
|
MobileMessageManager::RetrieveMMS(int32_t aId,
|
2014-06-25 07:57:16 +04:00
|
|
|
ErrorResult& aRv)
|
2013-03-21 13:57:41 +04:00
|
|
|
{
|
2014-06-25 07:57:15 +04:00
|
|
|
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!mmsService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-21 13:57:41 +04:00
|
|
|
|
2014-06-25 07:57:15 +04:00
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
2013-03-21 13:57:41 +04:00
|
|
|
|
2014-06-25 07:57:15 +04:00
|
|
|
nsresult rv = mmsService->Retrieve(aId, msgCallback);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-03-21 13:57:41 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
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);
|
2013-03-21 13:57:41 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
nsresult
|
2013-04-10 16:18:35 +04:00
|
|
|
MobileMessageManager::DispatchTrustedSmsEventToSelf(const char* aTopic,
|
|
|
|
const nsAString& aEventName,
|
|
|
|
nsISupports* aMsg)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
2013-04-10 16:18:35 +04:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> sms = do_QueryInterface(aMsg);
|
|
|
|
if (sms) {
|
2014-06-11 05:23:34 +04:00
|
|
|
MozSmsEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mMessage = sms;
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2014-06-11 05:23:34 +04:00
|
|
|
nsRefPtr<MozSmsEvent> event =
|
|
|
|
MozSmsEvent::Constructor(this, aEventName, init);
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
2013-03-09 11:21:47 +04:00
|
|
|
|
2013-04-10 16:18:35 +04:00
|
|
|
nsCOMPtr<nsIDOMMozMmsMessage> mms = do_QueryInterface(aMsg);
|
|
|
|
if (mms) {
|
2014-06-11 05:23:34 +04:00
|
|
|
MozMmsEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
init.mMessage = mms;
|
2013-03-09 11:22:42 +04:00
|
|
|
|
2014-06-11 05:23:34 +04:00
|
|
|
nsRefPtr<MozMmsEvent> event =
|
|
|
|
MozMmsEvent::Constructor(this, aEventName, init);
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
2013-03-09 11:22:42 +04:00
|
|
|
|
2013-04-10 16:18:35 +04: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-09 11:22:42 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 09:25:37 +04:00
|
|
|
nsresult
|
|
|
|
MobileMessageManager::DispatchTrustedDeletedEventToSelf(nsISupports* aDeletedInfo)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDeletedMessageInfo> deletedInfo = do_QueryInterface(aDeletedInfo);
|
|
|
|
if (deletedInfo) {
|
|
|
|
MozMessageDeletedEventInit init;
|
|
|
|
init.mBubbles = false;
|
|
|
|
init.mCancelable = false;
|
|
|
|
DeletedMessageInfo* info =
|
|
|
|
static_cast<DeletedMessageInfo*>(deletedInfo.get());
|
|
|
|
|
|
|
|
uint32_t msgIdLength = info->GetData().deletedMessageIds().Length();
|
|
|
|
if (msgIdLength) {
|
|
|
|
Sequence<int32_t>& deletedMsgIds = init.mDeletedMessageIds.SetValue();
|
|
|
|
deletedMsgIds.AppendElements(info->GetData().deletedMessageIds());
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t threadIdLength = info->GetData().deletedThreadIds().Length();
|
|
|
|
if (threadIdLength) {
|
|
|
|
Sequence<uint64_t>& deletedThreadIds = init.mDeletedThreadIds.SetValue();
|
|
|
|
deletedThreadIds.AppendElements(info->GetData().deletedThreadIds());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<MozMessageDeletedEvent> event =
|
|
|
|
MozMessageDeletedEvent::Constructor(this, DELETED_EVENT_NAME, init);
|
|
|
|
return DispatchTrustedEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ERROR("Got a 'deleted' topic without a valid message!");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData)
|
2013-03-09 11:21:47 +04:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, kSmsReceivedObserverTopic)) {
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, RECEIVED_EVENT_NAME, aSubject);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
2013-05-11 00:39:22 +04:00
|
|
|
if (!strcmp(aTopic, kSmsRetrievingObserverTopic)) {
|
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, RETRIEVING_EVENT_NAME, aSubject);
|
|
|
|
}
|
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
if (!strcmp(aTopic, kSmsSendingObserverTopic)) {
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, SENDING_EVENT_NAME, aSubject);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsSentObserverTopic)) {
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, SENT_EVENT_NAME, aSubject);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsFailedObserverTopic)) {
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, FAILED_EVENT_NAME, aSubject);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsDeliverySuccessObserverTopic)) {
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, DELIVERY_SUCCESS_EVENT_NAME, aSubject);
|
2013-03-09 11:21:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsDeliveryErrorObserverTopic)) {
|
2013-04-10 16:18:35 +04:00
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, DELIVERY_ERROR_EVENT_NAME, aSubject);
|
2013-03-18 14:47:41 +04:00
|
|
|
}
|
|
|
|
|
2013-11-25 14:54:59 +04:00
|
|
|
if (!strcmp(aTopic, kSmsReadSuccessObserverTopic)) {
|
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, READ_SUCCESS_EVENT_NAME, aSubject);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kSmsReadErrorObserverTopic)) {
|
|
|
|
return DispatchTrustedSmsEventToSelf(aTopic, READ_ERROR_EVENT_NAME, aSubject);
|
|
|
|
}
|
|
|
|
|
2014-06-27 09:25:37 +04:00
|
|
|
if (!strcmp(aTopic, kSmsDeletedObserverTopic)) {
|
|
|
|
return DispatchTrustedDeletedEventToSelf(aSubject);
|
|
|
|
}
|
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
MobileMessageManager::GetSmscAddress(const Optional<uint32_t>& aServiceId,
|
|
|
|
ErrorResult& aRv)
|
2013-09-16 06:12:43 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
2014-06-25 07:57:16 +04:00
|
|
|
if (!smsService) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-16 06:12:43 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
// Use the default one unless |aSendParams.serviceId| is available.
|
|
|
|
uint32_t serviceId;
|
2013-09-16 06:12:43 +04:00
|
|
|
nsresult rv;
|
2014-06-25 07:57:16 +04:00
|
|
|
if (aServiceId.WasPassed()) {
|
|
|
|
serviceId = aServiceId.Value();
|
|
|
|
} else {
|
|
|
|
rv = smsService->GetSmsDefaultServiceId(&serviceId);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-16 06:12:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<DOMRequest> request = new DOMRequest(GetOwner());
|
|
|
|
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
2014-06-25 07:57:16 +04:00
|
|
|
rv = smsService->GetSmscAddress(serviceId, msgCallback);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-09-16 06:12:43 +04:00
|
|
|
|
2014-06-25 07:57:16 +04:00
|
|
|
return request.forget();
|
2013-09-16 06:12:43 +04:00
|
|
|
}
|
|
|
|
|
2013-03-09 11:21:47 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-09-21 11:24:44 +04:00
|
|
|
|
|
|
|
already_AddRefed<nsISmsService>
|
|
|
|
NS_CreateSmsService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISmsService> smsService;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
smsService = SmsIPCService::GetSingleton();
|
|
|
|
} else {
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
smsService = new SmsService();
|
|
|
|
#elif defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
2014-11-24 13:43:54 +03:00
|
|
|
smsService = do_GetService(GONK_SMSSERVICE_CONTRACTID);
|
2014-09-21 11:24:44 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return smsService.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIMobileMessageDatabaseService>
|
|
|
|
NS_CreateMobileMessageDatabaseService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService;
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
mobileMessageDBService = SmsIPCService::GetSingleton();
|
|
|
|
} else {
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
mobileMessageDBService = new MobileMessageDatabaseService();
|
|
|
|
#elif defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
|
|
|
mobileMessageDBService =
|
2014-12-10 10:30:59 +03:00
|
|
|
do_CreateInstance(GONK_MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
2014-09-21 11:24:44 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return mobileMessageDBService.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIMmsService>
|
|
|
|
NS_CreateMmsService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMmsService> mmsService;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
mmsService = SmsIPCService::GetSingleton();
|
|
|
|
} else {
|
|
|
|
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
2014-12-10 11:14:19 +03:00
|
|
|
mmsService = do_CreateInstance("@mozilla.org/mms/gonkmmsservice;1");
|
2014-09-21 11:24:44 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return mmsService.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIMobileMessageService>
|
|
|
|
NS_CreateMobileMessageService()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMobileMessageService> service = new MobileMessageService();
|
|
|
|
return service.forget();
|
|
|
|
}
|