mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 1310027 - Remove DOM/mobilemessage and related code. r=Ehsan
MozReview-Commit-ID: ENmSuOCdTnA --HG-- extra : rebase_source : a178eee07034fb2aa1415b64bec1946230fd1c5e
This commit is contained in:
parent
513e313d64
commit
07411b2cc6
@ -390,9 +390,6 @@ pref("dom.ipc.browser_frames.oop_by_default", false);
|
||||
pref("dom.meta-viewport.enabled", true);
|
||||
#endif
|
||||
|
||||
// SMS/MMS
|
||||
pref("dom.sms.enabled", true);
|
||||
|
||||
//The waiting time in network manager.
|
||||
pref("network.gonk.ms-release-mms-connection", 30000);
|
||||
|
||||
|
@ -208,7 +208,6 @@
|
||||
@RESPATH@/components/dom_settings.xpt
|
||||
@RESPATH@/components/dom_permissionsettings.xpt
|
||||
@RESPATH@/components/dom_sidebar.xpt
|
||||
@RESPATH@/components/dom_mobilemessage.xpt
|
||||
@RESPATH@/components/dom_storage.xpt
|
||||
@RESPATH@/components/dom_stylesheets.xpt
|
||||
@RESPATH@/components/dom_telephony.xpt
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include "mozilla/dom/FlyWebService.h"
|
||||
#include "mozilla/dom/IccManager.h"
|
||||
#include "mozilla/dom/InputPortManager.h"
|
||||
#include "mozilla/dom/MobileMessageManager.h"
|
||||
#include "mozilla/dom/Permissions.h"
|
||||
#include "mozilla/dom/Presentation.h"
|
||||
#include "mozilla/dom/ServiceWorkerContainer.h"
|
||||
@ -216,7 +215,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBatteryPromise)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPowerManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIccManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileMessageManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputPortManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
|
||||
@ -292,11 +290,6 @@ Navigator::Invalidate()
|
||||
mIccManager = nullptr;
|
||||
}
|
||||
|
||||
if (mMobileMessageManager) {
|
||||
mMobileMessageManager->Shutdown();
|
||||
mMobileMessageManager = nullptr;
|
||||
}
|
||||
|
||||
if (mTelephony) {
|
||||
mTelephony = nullptr;
|
||||
}
|
||||
@ -1624,21 +1617,6 @@ Navigator::RequestWakeLock(const nsAString &aTopic, ErrorResult& aRv)
|
||||
return pmService->NewWakeLock(aTopic, mWindow, aRv);
|
||||
}
|
||||
|
||||
MobileMessageManager*
|
||||
Navigator::GetMozMobileMessage()
|
||||
{
|
||||
if (!mMobileMessageManager) {
|
||||
// Check that our window has not gone away
|
||||
NS_ENSURE_TRUE(mWindow, nullptr);
|
||||
NS_ENSURE_TRUE(mWindow->GetDocShell(), nullptr);
|
||||
|
||||
mMobileMessageManager = new MobileMessageManager(mWindow);
|
||||
mMobileMessageManager->Init();
|
||||
}
|
||||
|
||||
return mMobileMessageManager;
|
||||
}
|
||||
|
||||
Telephony*
|
||||
Navigator::GetMozTelephony(ErrorResult& aRv)
|
||||
{
|
||||
|
@ -59,7 +59,6 @@ class BatteryManager;
|
||||
class Promise;
|
||||
|
||||
class DesktopNotificationCenter;
|
||||
class MobileMessageManager;
|
||||
class MozIdleObserver;
|
||||
#ifdef MOZ_GAMEPAD
|
||||
class Gamepad;
|
||||
@ -222,7 +221,6 @@ public:
|
||||
|
||||
DesktopNotificationCenter* GetMozNotification(ErrorResult& aRv);
|
||||
IccManager* GetMozIccManager(ErrorResult& aRv);
|
||||
MobileMessageManager* GetMozMobileMessage();
|
||||
Telephony* GetMozTelephony(ErrorResult& aRv);
|
||||
InputPortManager* GetInputPortManager(ErrorResult& aRv);
|
||||
already_AddRefed<LegacyMozTCPSocket> MozTCPSocket();
|
||||
@ -327,7 +325,6 @@ private:
|
||||
RefPtr<Promise> mBatteryPromise;
|
||||
RefPtr<PowerManager> mPowerManager;
|
||||
RefPtr<IccManager> mIccManager;
|
||||
RefPtr<MobileMessageManager> mMobileMessageManager;
|
||||
RefPtr<Telephony> mTelephony;
|
||||
RefPtr<InputPortManager> mInputPortManager;
|
||||
RefPtr<network::Connection> mConnection;
|
||||
|
@ -686,10 +686,6 @@ DOMInterfaces = {
|
||||
'nativeType': 'mozilla::dom::MobileConnectionInfo',
|
||||
},
|
||||
|
||||
'MozMobileMessageManager': {
|
||||
'nativeType': 'mozilla::dom::MobileMessageManager',
|
||||
},
|
||||
|
||||
'MozMobileNetworkInfo': {
|
||||
'nativeType': 'mozilla::dom::MobileNetworkInfo',
|
||||
},
|
||||
|
@ -172,7 +172,6 @@
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/icc/IccChild.h"
|
||||
#include "mozilla/dom/mobileconnection/MobileConnectionChild.h"
|
||||
#include "mozilla/dom/mobilemessage/SmsChild.h"
|
||||
#include "mozilla/dom/devicestorage/DeviceStorageRequestChild.h"
|
||||
#include "mozilla/dom/bluetooth/PBluetoothChild.h"
|
||||
#include "mozilla/dom/PPresentationChild.h"
|
||||
@ -208,7 +207,6 @@ using namespace mozilla::dom::devicestorage;
|
||||
using namespace mozilla::dom::icc;
|
||||
using namespace mozilla::dom::ipc;
|
||||
using namespace mozilla::dom::mobileconnection;
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
using namespace mozilla::dom::telephony;
|
||||
using namespace mozilla::dom::workers;
|
||||
using namespace mozilla::media;
|
||||
@ -1977,19 +1975,6 @@ bool ContentChild::DeallocPHandlerServiceChild(PHandlerServiceChild* aHandlerSer
|
||||
return true;
|
||||
}
|
||||
|
||||
PSmsChild*
|
||||
ContentChild::AllocPSmsChild()
|
||||
{
|
||||
return new SmsChild();
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::DeallocPSmsChild(PSmsChild* aSms)
|
||||
{
|
||||
delete aSms;
|
||||
return true;
|
||||
}
|
||||
|
||||
PTelephonyChild*
|
||||
ContentChild::AllocPTelephonyChild()
|
||||
{
|
||||
|
@ -335,10 +335,6 @@ public:
|
||||
|
||||
virtual bool DeallocPHandlerServiceChild(PHandlerServiceChild*) override;
|
||||
|
||||
virtual PSmsChild* AllocPSmsChild() override;
|
||||
|
||||
virtual bool DeallocPSmsChild(PSmsChild*) override;
|
||||
|
||||
virtual PTelephonyChild* AllocPTelephonyChild() override;
|
||||
|
||||
virtual bool DeallocPTelephonyChild(PTelephonyChild*) override;
|
||||
|
@ -61,7 +61,6 @@
|
||||
#include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h"
|
||||
#include "mozilla/dom/icc/IccParent.h"
|
||||
#include "mozilla/dom/mobileconnection/MobileConnectionParent.h"
|
||||
#include "mozilla/dom/mobilemessage/SmsParent.h"
|
||||
#include "mozilla/dom/power/PowerManagerService.h"
|
||||
#include "mozilla/dom/Permissions.h"
|
||||
#include "mozilla/dom/PresentationParent.h"
|
||||
@ -292,7 +291,6 @@ using namespace mozilla::dom::devicestorage;
|
||||
using namespace mozilla::dom::icc;
|
||||
using namespace mozilla::dom::power;
|
||||
using namespace mozilla::dom::mobileconnection;
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
using namespace mozilla::dom::telephony;
|
||||
using namespace mozilla::media;
|
||||
using namespace mozilla::embedding;
|
||||
@ -3432,25 +3430,6 @@ ContentParent::DeallocPHandlerServiceParent(PHandlerServiceParent* aHandlerServi
|
||||
return true;
|
||||
}
|
||||
|
||||
PSmsParent*
|
||||
ContentParent::AllocPSmsParent()
|
||||
{
|
||||
if (!AssertAppProcessPermission(this, "sms")) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SmsParent* parent = new SmsParent();
|
||||
parent->AddRef();
|
||||
return parent;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::DeallocPSmsParent(PSmsParent* aSms)
|
||||
{
|
||||
static_cast<SmsParent*>(aSms)->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
PTelephonyParent*
|
||||
ContentParent::AllocPTelephonyParent()
|
||||
{
|
||||
|
@ -843,10 +843,6 @@ private:
|
||||
|
||||
virtual bool DeallocPHandlerServiceParent(PHandlerServiceParent*) override;
|
||||
|
||||
virtual PSmsParent* AllocPSmsParent() override;
|
||||
|
||||
virtual bool DeallocPSmsParent(PSmsParent*) override;
|
||||
|
||||
virtual PTelephonyParent* AllocPTelephonyParent() override;
|
||||
|
||||
virtual bool DeallocPTelephonyParent(PTelephonyParent*) override;
|
||||
|
@ -42,7 +42,6 @@ include protocol POfflineCacheUpdate;
|
||||
include protocol PRenderFrame;
|
||||
include protocol PScreenManager;
|
||||
include protocol PSharedBufferManager;
|
||||
include protocol PSms;
|
||||
include protocol PSpeechSynthesis;
|
||||
include protocol PStorage;
|
||||
include protocol PTelephony;
|
||||
@ -371,7 +370,6 @@ nested(upto inside_cpow) sync protocol PContent
|
||||
manages PPrinting;
|
||||
manages PSendStream;
|
||||
manages PScreenManager;
|
||||
manages PSms;
|
||||
manages PSpeechSynthesis;
|
||||
manages PStorage;
|
||||
manages PTelephony;
|
||||
@ -817,8 +815,6 @@ parent:
|
||||
float systemDefaultScale,
|
||||
bool success);
|
||||
|
||||
async PSms();
|
||||
|
||||
async PSpeechSynthesis();
|
||||
|
||||
nested(inside_cpow) async PStorage();
|
||||
|
@ -132,7 +132,6 @@ LOCAL_INCLUDES += [
|
||||
'/dom/filesystem',
|
||||
'/dom/geolocation',
|
||||
'/dom/media/webspeech/synth/ipc',
|
||||
'/dom/mobilemessage/ipc',
|
||||
'/dom/security',
|
||||
'/dom/storage',
|
||||
'/dom/workers',
|
||||
|
@ -1,47 +0,0 @@
|
||||
/* 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 "mozilla/dom/MozMobileMessageManagerBinding.h"
|
||||
#include "nsISmsService.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
#define ASSERT_SMS_EQUALITY(webidlType, webidlState, xpidlState) \
|
||||
static_assert(static_cast<uint32_t>(webidlType::webidlState) == nsISmsService::xpidlState, \
|
||||
#webidlType "::" #webidlState " should equal to nsISmsService::" #xpidlState)
|
||||
|
||||
/**
|
||||
* Enum TypeOfNumber
|
||||
*/
|
||||
#define ASSERT_SMS_TYPE_OF_NUMBER_EQUALITY(webidlState, xpidlState) \
|
||||
ASSERT_SMS_EQUALITY(TypeOfNumber, webidlState, xpidlState)
|
||||
|
||||
ASSERT_SMS_TYPE_OF_NUMBER_EQUALITY(Unknown, TYPE_OF_NUMBER_UNKNOWN);
|
||||
ASSERT_SMS_TYPE_OF_NUMBER_EQUALITY(International, TYPE_OF_NUMBER_INTERNATIONAL);
|
||||
ASSERT_SMS_TYPE_OF_NUMBER_EQUALITY(National, TYPE_OF_NUMBER_NATIONAL);
|
||||
ASSERT_SMS_TYPE_OF_NUMBER_EQUALITY(Network_specific, TYPE_OF_NUMBER_NETWORK_SPECIFIC);
|
||||
ASSERT_SMS_TYPE_OF_NUMBER_EQUALITY(Dedicated_access_short_code, TYPE_OF_NUMBER_DEDICATED_ACCESS_SHORT_CODE);
|
||||
|
||||
#undef ASSERT_SMS_TYPE_OF_NUMBER_EQUALITY
|
||||
|
||||
/**
|
||||
* Enum NumberPlanIdentification
|
||||
*/
|
||||
#define ASSERT_SMS_NUMBER_PLAN_IDENTIFICATION_EQUALITY(webidlState, xpidlState) \
|
||||
ASSERT_SMS_EQUALITY(NumberPlanIdentification, webidlState, xpidlState)
|
||||
|
||||
ASSERT_SMS_NUMBER_PLAN_IDENTIFICATION_EQUALITY(Unknown, NUMBER_PLAN_IDENTIFICATION_UNKNOWN);
|
||||
ASSERT_SMS_NUMBER_PLAN_IDENTIFICATION_EQUALITY(Isdn, NUMBER_PLAN_IDENTIFICATION_ISDN);
|
||||
ASSERT_SMS_NUMBER_PLAN_IDENTIFICATION_EQUALITY(Data, NUMBER_PLAN_IDENTIFICATION_DATA);
|
||||
ASSERT_SMS_NUMBER_PLAN_IDENTIFICATION_EQUALITY(Telex, NUMBER_PLAN_IDENTIFICATION_TELEX);
|
||||
ASSERT_SMS_NUMBER_PLAN_IDENTIFICATION_EQUALITY(National, NUMBER_PLAN_IDENTIFICATION_NATIONAL);
|
||||
ASSERT_SMS_NUMBER_PLAN_IDENTIFICATION_EQUALITY(Private, NUMBER_PLAN_IDENTIFICATION_PRIVATE);
|
||||
|
||||
#undef ASSERT_SMS_EQUALITY
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,25 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
const char* kSmsReceivedObserverTopic = "sms-received";
|
||||
const char* kSmsRetrievingObserverTopic = "sms-retrieving";
|
||||
const char* kSmsSendingObserverTopic = "sms-sending";
|
||||
const char* kSmsSentObserverTopic = "sms-sent";
|
||||
const char* kSmsFailedObserverTopic = "sms-failed";
|
||||
const char* kSmsDeliverySuccessObserverTopic = "sms-delivery-success";
|
||||
const char* kSmsDeliveryErrorObserverTopic = "sms-delivery-error";
|
||||
const char* kSilentSmsReceivedObserverTopic = "silent-sms-received";
|
||||
const char* kSmsReadSuccessObserverTopic = "sms-read-success";
|
||||
const char* kSmsReadErrorObserverTopic = "sms-read-error";
|
||||
const char* kSmsDeletedObserverTopic = "sms-deleted";
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,58 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_Constants_h
|
||||
#define mozilla_dom_mobilemessage_Constants_h
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
// Defined in the .cpp.
|
||||
extern const char* kSmsReceivedObserverTopic;
|
||||
extern const char* kSmsRetrievingObserverTopic;
|
||||
extern const char* kSmsSendingObserverTopic;
|
||||
extern const char* kSmsSentObserverTopic;
|
||||
extern const char* kSmsFailedObserverTopic;
|
||||
extern const char* kSmsDeliverySuccessObserverTopic;
|
||||
extern const char* kSmsDeliveryErrorObserverTopic;
|
||||
extern const char* kSilentSmsReceivedObserverTopic;
|
||||
extern const char* kSmsReadSuccessObserverTopic;
|
||||
extern const char* kSmsReadErrorObserverTopic;
|
||||
extern const char* kSmsDeletedObserverTopic;
|
||||
|
||||
#define DELIVERY_RECEIVED NS_LITERAL_STRING("received")
|
||||
#define DELIVERY_SENDING NS_LITERAL_STRING("sending")
|
||||
#define DELIVERY_SENT NS_LITERAL_STRING("sent")
|
||||
#define DELIVERY_ERROR NS_LITERAL_STRING("error")
|
||||
#define DELIVERY_NOT_DOWNLOADED NS_LITERAL_STRING("not-downloaded")
|
||||
|
||||
#define DELIVERY_STATUS_NOT_APPLICABLE NS_LITERAL_STRING("not-applicable")
|
||||
#define DELIVERY_STATUS_SUCCESS NS_LITERAL_STRING("success")
|
||||
#define DELIVERY_STATUS_PENDING NS_LITERAL_STRING("pending")
|
||||
#define DELIVERY_STATUS_ERROR NS_LITERAL_STRING("error")
|
||||
#define DELIVERY_STATUS_REJECTED NS_LITERAL_STRING("rejected")
|
||||
#define DELIVERY_STATUS_MANUAL NS_LITERAL_STRING("manual")
|
||||
|
||||
#define READ_STATUS_NOT_APPLICABLE NS_LITERAL_STRING("not-applicable")
|
||||
#define READ_STATUS_SUCCESS NS_LITERAL_STRING("success")
|
||||
#define READ_STATUS_PENDING NS_LITERAL_STRING("pending")
|
||||
#define READ_STATUS_ERROR NS_LITERAL_STRING("error")
|
||||
|
||||
#define MESSAGE_CLASS_NORMAL NS_LITERAL_STRING("normal")
|
||||
#define MESSAGE_CLASS_CLASS_0 NS_LITERAL_STRING("class-0")
|
||||
#define MESSAGE_CLASS_CLASS_1 NS_LITERAL_STRING("class-1")
|
||||
#define MESSAGE_CLASS_CLASS_2 NS_LITERAL_STRING("class-2")
|
||||
#define MESSAGE_CLASS_CLASS_3 NS_LITERAL_STRING("class-3")
|
||||
|
||||
#define MESSAGE_TYPE_SMS NS_LITERAL_STRING("sms")
|
||||
#define MESSAGE_TYPE_MMS NS_LITERAL_STRING("mms")
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_Constants_h
|
@ -1,74 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "DOMMobileMessageError.h"
|
||||
#include "mozilla/dom/DOMMobileMessageErrorBinding.h"
|
||||
#include "MmsMessage.h"
|
||||
#include "SmsMessage.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMMobileMessageError)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMMobileMessageError, DOMError)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSms)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMms)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DOMMobileMessageError, DOMError)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSms)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMms)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMMobileMessageError)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMError)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(DOMMobileMessageError, DOMError)
|
||||
NS_IMPL_RELEASE_INHERITED(DOMMobileMessageError, DOMError)
|
||||
|
||||
DOMMobileMessageError::DOMMobileMessageError(nsPIDOMWindowInner* aWindow,
|
||||
const nsAString& aName,
|
||||
SmsMessage* aSms)
|
||||
: DOMError(aWindow, aName)
|
||||
, mSms(aSms)
|
||||
, mMms(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
DOMMobileMessageError::DOMMobileMessageError(nsPIDOMWindowInner* aWindow,
|
||||
const nsAString& aName,
|
||||
MmsMessage* aMms)
|
||||
: DOMError(aWindow, aName)
|
||||
, mSms(nullptr)
|
||||
, mMms(aMms)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
DOMMobileMessageError::GetData(OwningSmsMessageOrMmsMessage& aRetVal) const
|
||||
{
|
||||
if (mSms) {
|
||||
aRetVal.SetAsSmsMessage() = mSms;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mMms) {
|
||||
aRetVal.SetAsMmsMessage() = mMms;
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_CRASH("Bad object with invalid mSms and mMms.");
|
||||
}
|
||||
|
||||
JSObject*
|
||||
DOMMobileMessageError::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return DOMMobileMessageErrorBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,46 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_MobileMessageError_h
|
||||
#define mozilla_dom_MobileMessageError_h
|
||||
|
||||
#include "mozilla/dom/DOMError.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class MmsMessage;
|
||||
class OwningSmsMessageOrMmsMessage;
|
||||
class SmsMessage;
|
||||
|
||||
class DOMMobileMessageError final : public DOMError
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMMobileMessageError, DOMError)
|
||||
|
||||
DOMMobileMessageError(nsPIDOMWindowInner* aWindow, const nsAString& aName,
|
||||
SmsMessage* aSms);
|
||||
|
||||
DOMMobileMessageError(nsPIDOMWindowInner* aWindow, const nsAString& aName,
|
||||
MmsMessage* aMms);
|
||||
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void GetData(OwningSmsMessageOrMmsMessage& aRetVal) const;
|
||||
|
||||
private:
|
||||
~DOMMobileMessageError() {}
|
||||
|
||||
RefPtr<SmsMessage> mSms;
|
||||
RefPtr<MmsMessage> mMms;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_MobileMessageError_h
|
@ -1,123 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "DeletedMessageInfo.h"
|
||||
#include "nsComponentManagerUtils.h" // for do_CreateInstance
|
||||
#include "nsVariant.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_ISUPPORTS(DeletedMessageInfo, nsIDeletedMessageInfo)
|
||||
|
||||
DeletedMessageInfo::DeletedMessageInfo(const DeletedMessageInfoData& aData)
|
||||
: mData(aData)
|
||||
{
|
||||
}
|
||||
|
||||
DeletedMessageInfo::DeletedMessageInfo(int32_t* aMessageIds,
|
||||
uint32_t aMsgCount,
|
||||
uint64_t* aThreadIds,
|
||||
uint32_t aThreadCount)
|
||||
{
|
||||
mData.deletedMessageIds().AppendElements(aMessageIds, aMsgCount);
|
||||
mData.deletedThreadIds().AppendElements(aThreadIds, aThreadCount);
|
||||
}
|
||||
|
||||
DeletedMessageInfo::~DeletedMessageInfo()
|
||||
{
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
DeletedMessageInfo::Create(int32_t* aMessageIds,
|
||||
uint32_t aMsgCount,
|
||||
uint64_t* aThreadIds,
|
||||
uint32_t aThreadCount,
|
||||
nsIDeletedMessageInfo** aDeletedInfo)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDeletedInfo);
|
||||
NS_ENSURE_TRUE(aMsgCount || aThreadCount, NS_ERROR_INVALID_ARG);
|
||||
|
||||
nsCOMPtr<nsIDeletedMessageInfo> deletedInfo =
|
||||
new DeletedMessageInfo(aMessageIds,
|
||||
aMsgCount,
|
||||
aThreadIds,
|
||||
aThreadCount);
|
||||
deletedInfo.forget(aDeletedInfo);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeletedMessageInfo::GetDeletedMessageIds(nsIVariant** aDeletedMessageIds)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDeletedMessageIds);
|
||||
|
||||
if (mDeletedMessageIds) {
|
||||
NS_ADDREF(*aDeletedMessageIds = mDeletedMessageIds);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t length = mData.deletedMessageIds().Length();
|
||||
|
||||
if (length == 0) {
|
||||
*aDeletedMessageIds = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mDeletedMessageIds = new nsVariant();
|
||||
|
||||
nsresult rv;
|
||||
rv = mDeletedMessageIds->SetAsArray(nsIDataType::VTYPE_INT32,
|
||||
nullptr,
|
||||
length,
|
||||
mData.deletedMessageIds().Elements());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mDeletedMessageIds->SetWritable(false);
|
||||
|
||||
NS_ADDREF(*aDeletedMessageIds = mDeletedMessageIds);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DeletedMessageInfo::GetDeletedThreadIds(nsIVariant** aDeletedThreadIds)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDeletedThreadIds);
|
||||
|
||||
if (mDeletedThreadIds) {
|
||||
NS_ADDREF(*aDeletedThreadIds = mDeletedThreadIds);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t length = mData.deletedThreadIds().Length();
|
||||
|
||||
if (length == 0) {
|
||||
*aDeletedThreadIds = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mDeletedThreadIds = new nsVariant();
|
||||
|
||||
nsresult rv;
|
||||
rv = mDeletedThreadIds->SetAsArray(nsIDataType::VTYPE_UINT64,
|
||||
nullptr,
|
||||
length,
|
||||
mData.deletedThreadIds().Elements());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mDeletedThreadIds->SetWritable(false);
|
||||
|
||||
NS_ADDREF(*aDeletedThreadIds = mDeletedThreadIds);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,59 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_DeletedMessageInfo_h
|
||||
#define mozilla_dom_mobilemessage_DeletedMessageInfo_h
|
||||
|
||||
#include "mozilla/dom/mobilemessage/SmsTypes.h"
|
||||
#include "nsIDeletedMessageInfo.h"
|
||||
|
||||
class nsIWritableVariant;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class DeletedMessageInfo final : public nsIDeletedMessageInfo
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDELETEDMESSAGEINFO
|
||||
|
||||
explicit DeletedMessageInfo(const DeletedMessageInfoData& aData);
|
||||
|
||||
DeletedMessageInfo(int32_t* aMessageIds,
|
||||
uint32_t aMsgCount,
|
||||
uint64_t* aThreadIds,
|
||||
uint32_t aThreadCount);
|
||||
|
||||
static nsresult Create(int32_t* aMessageIds,
|
||||
uint32_t aMsgCount,
|
||||
uint64_t* aThreadIds,
|
||||
uint32_t aThreadCount,
|
||||
nsIDeletedMessageInfo** aDeletedInfo);
|
||||
|
||||
const DeletedMessageInfoData& GetData() const { return mData; }
|
||||
|
||||
private:
|
||||
// Don't try to use the default constructor.
|
||||
DeletedMessageInfo();
|
||||
|
||||
~DeletedMessageInfo();
|
||||
|
||||
DeletedMessageInfoData mData;
|
||||
|
||||
nsCOMPtr<nsIWritableVariant> mDeletedMessageIds;
|
||||
nsCOMPtr<nsIWritableVariant> mDeletedThreadIds;
|
||||
|
||||
protected:
|
||||
/* additional members */
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_DeletedMessageInfo_h
|
@ -1,163 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 "MmsMessage.h"
|
||||
|
||||
#include "MmsMessageInternal.h"
|
||||
#include "mozilla/dom/MmsMessageBinding.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MmsMessage, mWindow, mMessage)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(MmsMessage)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(MmsMessage)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MmsMessage)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
MmsMessage::MmsMessage(nsPIDOMWindowInner* aWindow, MmsMessageInternal* aMessage)
|
||||
: mWindow(aWindow)
|
||||
, mMessage(aMessage)
|
||||
{
|
||||
}
|
||||
|
||||
MmsMessage::~MmsMessage()
|
||||
{
|
||||
}
|
||||
|
||||
JSObject*
|
||||
MmsMessage::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return MmsMessageBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetType(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetType(aRetVal);
|
||||
}
|
||||
|
||||
int32_t
|
||||
MmsMessage::Id() const
|
||||
{
|
||||
int32_t id;
|
||||
mMessage->GetId(&id);
|
||||
return id;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
MmsMessage::ThreadId() const
|
||||
{
|
||||
uint64_t id;
|
||||
mMessage->GetThreadId(&id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetIccId(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetIccId(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetDelivery(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetDelivery(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetDeliveryInfo(nsTArray<MmsDeliveryInfo>& aRetVal) const
|
||||
{
|
||||
aRetVal = mMessage->mDeliveryInfo;
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetSender(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetSender(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetReceivers(nsTArray<nsString>& aRetVal) const
|
||||
{
|
||||
aRetVal = mMessage->mReceivers;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
MmsMessage::Timestamp() const
|
||||
{
|
||||
uint64_t timestamp;
|
||||
mMessage->GetTimestamp(×tamp);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
MmsMessage::SentTimestamp() const
|
||||
{
|
||||
uint64_t timestamp;
|
||||
mMessage->GetSentTimestamp(×tamp);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
bool
|
||||
MmsMessage::Read() const
|
||||
{
|
||||
bool read;
|
||||
mMessage->GetRead(&read);
|
||||
return read;
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetSubject(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetSubject(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetSmil(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetSmil(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
MmsMessage::GetAttachments(nsTArray<MmsAttachment>& aRetVal) const
|
||||
{
|
||||
uint32_t length = mMessage->mAttachments.Length();
|
||||
|
||||
// Duplicating the Blob with the correct parent object.
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
MmsAttachment attachment;
|
||||
const MmsAttachment &element = mMessage->mAttachments[i];
|
||||
attachment.mId = element.mId;
|
||||
attachment.mLocation = element.mLocation;
|
||||
attachment.mContent = Blob::Create(mWindow, element.mContent->Impl());
|
||||
aRetVal.AppendElement(attachment);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t
|
||||
MmsMessage::ExpiryDate() const
|
||||
{
|
||||
uint64_t date;
|
||||
mMessage->GetExpiryDate(&date);
|
||||
return date;
|
||||
}
|
||||
|
||||
bool
|
||||
MmsMessage::ReadReportRequested() const
|
||||
{
|
||||
bool reportRequested;
|
||||
mMessage->GetReadReportRequested(&reportRequested);
|
||||
return reportRequested;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,106 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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_MmsMessage_h
|
||||
#define mozilla_dom_MmsMessage_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsPIDOMWindowInner;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
namespace mobilemessage {
|
||||
class MmsMessageInternal;
|
||||
} // namespace mobilemessage
|
||||
|
||||
struct MmsAttachment;
|
||||
struct MmsDeliveryInfo;
|
||||
|
||||
class MmsMessage final : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MmsMessage)
|
||||
|
||||
MmsMessage(nsPIDOMWindowInner* aWindow,
|
||||
mobilemessage::MmsMessageInternal* aMessage);
|
||||
|
||||
nsPIDOMWindowInner*
|
||||
GetParentObject() const
|
||||
{
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void
|
||||
GetType(nsString& aRetVal) const;
|
||||
|
||||
int32_t
|
||||
Id() const;
|
||||
|
||||
uint64_t
|
||||
ThreadId() const;
|
||||
|
||||
void
|
||||
GetIccId(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetDelivery(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetDeliveryInfo(nsTArray<MmsDeliveryInfo>& aRetVal) const;
|
||||
|
||||
void
|
||||
GetSender(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetReceivers(nsTArray<nsString>& aRetVal) const;
|
||||
|
||||
uint64_t
|
||||
Timestamp() const;
|
||||
|
||||
uint64_t
|
||||
SentTimestamp() const;
|
||||
|
||||
bool
|
||||
Read() const;
|
||||
|
||||
void
|
||||
GetSubject(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetSmil(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetAttachments(nsTArray<MmsAttachment>& aRetVal) const;
|
||||
|
||||
uint64_t
|
||||
ExpiryDate() const;
|
||||
|
||||
bool
|
||||
ReadReportRequested() const;
|
||||
|
||||
private:
|
||||
// Don't try to use the default constructor.
|
||||
MmsMessage() = delete;
|
||||
|
||||
~MmsMessage();
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
||||
RefPtr<mobilemessage::MmsMessageInternal> mMessage;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_MmsMessage_h
|
@ -1,614 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "MmsMessageInternal.h"
|
||||
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "jsapi.h" // For JS_IsArrayObject, JS_GetElement, etc.
|
||||
#include "nsJSUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsTArrayHelpers.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
||||
#include "mozilla/dom/mobilemessage/SmsTypes.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/dom/ipc/BlobChild.h"
|
||||
#include "mozilla/dom/ipc/BlobParent.h"
|
||||
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(MmsMessageInternal)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(MmsMessageInternal)
|
||||
for (uint32_t i = 0; i < tmp->mAttachments.Length(); i++) {
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAttachments[i].mContent)
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MmsMessageInternal)
|
||||
for (uint32_t i = 0; i < tmp->mAttachments.Length(); i++) {
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAttachments[i].mContent)
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MmsMessageInternal)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIMmsMessage)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(MmsMessageInternal)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(MmsMessageInternal)
|
||||
|
||||
MmsMessageInternal::MmsMessageInternal(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
DeliveryState aDelivery,
|
||||
const nsTArray<MmsDeliveryInfo>& aDeliveryInfo,
|
||||
const nsAString& aSender,
|
||||
const nsTArray<nsString>& aReceivers,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
bool aRead,
|
||||
const nsAString& aSubject,
|
||||
const nsAString& aSmil,
|
||||
const nsTArray<MmsAttachment>& aAttachments,
|
||||
uint64_t aExpiryDate,
|
||||
bool aReadReportRequested)
|
||||
: mId(aId),
|
||||
mThreadId(aThreadId),
|
||||
mIccId(aIccId),
|
||||
mDelivery(aDelivery),
|
||||
mDeliveryInfo(aDeliveryInfo),
|
||||
mSender(aSender),
|
||||
mReceivers(aReceivers),
|
||||
mTimestamp(aTimestamp),
|
||||
mSentTimestamp(aSentTimestamp),
|
||||
mRead(aRead),
|
||||
mSubject(aSubject),
|
||||
mSmil(aSmil),
|
||||
mAttachments(aAttachments),
|
||||
mExpiryDate(aExpiryDate),
|
||||
mReadReportRequested(aReadReportRequested)
|
||||
{
|
||||
}
|
||||
|
||||
MmsMessageInternal::MmsMessageInternal(const MmsMessageData& aData)
|
||||
: mId(aData.id())
|
||||
, mThreadId(aData.threadId())
|
||||
, mIccId(aData.iccId())
|
||||
, mDelivery(aData.delivery())
|
||||
, mSender(aData.sender())
|
||||
, mReceivers(aData.receivers())
|
||||
, mTimestamp(aData.timestamp())
|
||||
, mSentTimestamp(aData.sentTimestamp())
|
||||
, mRead(aData.read())
|
||||
, mSubject(aData.subject())
|
||||
, mSmil(aData.smil())
|
||||
, mExpiryDate(aData.expiryDate())
|
||||
, mReadReportRequested(aData.readReportRequested())
|
||||
{
|
||||
uint32_t len = aData.attachments().Length();
|
||||
mAttachments.SetCapacity(len);
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
MmsAttachment att;
|
||||
const MmsAttachmentData &element = aData.attachments()[i];
|
||||
att.mId = element.id();
|
||||
att.mLocation = element.location();
|
||||
|
||||
// mContent is not going to be exposed to JS directly so we can use
|
||||
// nullptr as parent.
|
||||
if (element.contentParent()) {
|
||||
RefPtr<BlobImpl> impl = static_cast<BlobParent*>(element.contentParent())->GetBlobImpl();
|
||||
att.mContent = Blob::Create(nullptr, impl);
|
||||
} else if (element.contentChild()) {
|
||||
RefPtr<BlobImpl> impl = static_cast<BlobChild*>(element.contentChild())->GetBlobImpl();
|
||||
att.mContent = Blob::Create(nullptr, impl);
|
||||
} else {
|
||||
NS_WARNING("MmsMessage: Unable to get attachment content.");
|
||||
}
|
||||
mAttachments.AppendElement(att);
|
||||
}
|
||||
|
||||
len = aData.deliveryInfo().Length();
|
||||
mDeliveryInfo.SetCapacity(len);
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
MmsDeliveryInfo info;
|
||||
const MmsDeliveryInfoData &infoData = aData.deliveryInfo()[i];
|
||||
|
||||
// Prepare |info.mReceiver|.
|
||||
info.mReceiver = infoData.receiver();
|
||||
|
||||
// Prepare |info.mDeliveryStatus|.
|
||||
nsString statusStr;
|
||||
switch (infoData.deliveryStatus()) {
|
||||
case eDeliveryStatus_NotApplicable:
|
||||
statusStr = DELIVERY_STATUS_NOT_APPLICABLE;
|
||||
break;
|
||||
case eDeliveryStatus_Success:
|
||||
statusStr = DELIVERY_STATUS_SUCCESS;
|
||||
break;
|
||||
case eDeliveryStatus_Pending:
|
||||
statusStr = DELIVERY_STATUS_PENDING;
|
||||
break;
|
||||
case eDeliveryStatus_Error:
|
||||
statusStr = DELIVERY_STATUS_ERROR;
|
||||
break;
|
||||
case eDeliveryStatus_Reject:
|
||||
statusStr = DELIVERY_STATUS_REJECTED;
|
||||
break;
|
||||
case eDeliveryStatus_Manual:
|
||||
statusStr = DELIVERY_STATUS_MANUAL;
|
||||
break;
|
||||
case eDeliveryStatus_EndGuard:
|
||||
default:
|
||||
MOZ_CRASH("We shouldn't get any other delivery status!");
|
||||
}
|
||||
info.mDeliveryStatus = statusStr;
|
||||
|
||||
// Prepare |info.mDeliveryTimestamp|.
|
||||
info.mDeliveryTimestamp = infoData.deliveryTimestamp();
|
||||
|
||||
// Prepare |info.mReadStatus|.
|
||||
nsString statusReadString;
|
||||
switch(infoData.readStatus()) {
|
||||
case eReadStatus_NotApplicable:
|
||||
statusReadString = READ_STATUS_NOT_APPLICABLE;
|
||||
break;
|
||||
case eReadStatus_Success:
|
||||
statusReadString = READ_STATUS_SUCCESS;
|
||||
break;
|
||||
case eReadStatus_Pending:
|
||||
statusReadString = READ_STATUS_PENDING;
|
||||
break;
|
||||
case eReadStatus_Error:
|
||||
statusReadString = READ_STATUS_ERROR;
|
||||
break;
|
||||
case eReadStatus_EndGuard:
|
||||
default:
|
||||
MOZ_CRASH("We shouldn't get any other read status!");
|
||||
}
|
||||
info.mReadStatus = statusReadString;
|
||||
|
||||
// Prepare |info.mReadTimestamp|.
|
||||
info.mReadTimestamp = infoData.readTimestamp();
|
||||
|
||||
mDeliveryInfo.AppendElement(info);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
MmsMessageInternal::Create(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
const nsAString& aDelivery,
|
||||
const JS::Value& aDeliveryInfo,
|
||||
const nsAString& aSender,
|
||||
const JS::Value& aReceivers,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
bool aRead,
|
||||
const nsAString& aSubject,
|
||||
const nsAString& aSmil,
|
||||
const JS::Value& aAttachments,
|
||||
uint64_t aExpiryDate,
|
||||
bool aIsReadReportRequested,
|
||||
JSContext* aCx,
|
||||
nsIMmsMessage** aMessage)
|
||||
{
|
||||
*aMessage = nullptr;
|
||||
|
||||
// Set |delivery|.
|
||||
DeliveryState delivery;
|
||||
if (aDelivery.Equals(DELIVERY_SENT)) {
|
||||
delivery = eDeliveryState_Sent;
|
||||
} else if (aDelivery.Equals(DELIVERY_RECEIVED)) {
|
||||
delivery = eDeliveryState_Received;
|
||||
} else if (aDelivery.Equals(DELIVERY_SENDING)) {
|
||||
delivery = eDeliveryState_Sending;
|
||||
} else if (aDelivery.Equals(DELIVERY_NOT_DOWNLOADED)) {
|
||||
delivery = eDeliveryState_NotDownloaded;
|
||||
} else if (aDelivery.Equals(DELIVERY_ERROR)) {
|
||||
delivery = eDeliveryState_Error;
|
||||
} else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Set |deliveryInfo|.
|
||||
if (!aDeliveryInfo.isObject()) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
JS::Rooted<JSObject*> deliveryInfoObj(aCx, &aDeliveryInfo.toObject());
|
||||
bool isArray;
|
||||
if (!JS_IsArrayObject(aCx, deliveryInfoObj, &isArray)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!isArray) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
uint32_t length;
|
||||
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, deliveryInfoObj, &length));
|
||||
|
||||
nsTArray<MmsDeliveryInfo> deliveryInfo;
|
||||
JS::Rooted<JS::Value> infoJsVal(aCx);
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
if (!JS_GetElement(aCx, deliveryInfoObj, i, &infoJsVal) ||
|
||||
!infoJsVal.isObject()) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
MmsDeliveryInfo info;
|
||||
if (!info.Init(aCx, infoJsVal)) {
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
deliveryInfo.AppendElement(info);
|
||||
}
|
||||
|
||||
// Set |receivers|.
|
||||
if (!aReceivers.isObject()) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
JS::Rooted<JSObject*> receiversObj(aCx, &aReceivers.toObject());
|
||||
if (!JS_IsArrayObject(aCx, receiversObj, &isArray)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!isArray) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, receiversObj, &length));
|
||||
|
||||
nsTArray<nsString> receivers;
|
||||
JS::Rooted<JS::Value> receiverJsVal(aCx);
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
if (!JS_GetElement(aCx, receiversObj, i, &receiverJsVal) ||
|
||||
!receiverJsVal.isString()) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoJSString receiverStr;
|
||||
if (!receiverStr.init(aCx, receiverJsVal.toString())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
receivers.AppendElement(receiverStr);
|
||||
}
|
||||
|
||||
// Set |attachments|.
|
||||
if (!aAttachments.isObject()) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
JS::Rooted<JSObject*> attachmentsObj(aCx, &aAttachments.toObject());
|
||||
if (!JS_IsArrayObject(aCx, attachmentsObj, &isArray)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!isArray) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsTArray<MmsAttachment> attachments;
|
||||
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, attachmentsObj, &length));
|
||||
|
||||
JS::Rooted<JS::Value> attachmentJsVal(aCx);
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
if (!JS_GetElement(aCx, attachmentsObj, i, &attachmentJsVal)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
MmsAttachment attachment;
|
||||
if (!attachment.Init(aCx, attachmentJsVal)) {
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(attachment.mContent, NS_ERROR_TYPE_ERR);
|
||||
|
||||
attachments.AppendElement(attachment);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMmsMessage> message =
|
||||
new MmsMessageInternal(aId,
|
||||
aThreadId,
|
||||
aIccId,
|
||||
delivery,
|
||||
deliveryInfo,
|
||||
aSender,
|
||||
receivers,
|
||||
aTimestamp,
|
||||
aSentTimestamp,
|
||||
aRead,
|
||||
aSubject,
|
||||
aSmil,
|
||||
attachments,
|
||||
aExpiryDate,
|
||||
aIsReadReportRequested);
|
||||
message.forget(aMessage);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
MmsMessageInternal::GetData(ContentParent* aParent,
|
||||
MmsMessageData& aData)
|
||||
{
|
||||
NS_ASSERTION(aParent, "aParent is null");
|
||||
|
||||
aData.id() = mId;
|
||||
aData.threadId() = mThreadId;
|
||||
aData.iccId() = mIccId;
|
||||
aData.delivery() = mDelivery;
|
||||
aData.sender().Assign(mSender);
|
||||
aData.receivers() = mReceivers;
|
||||
aData.timestamp() = mTimestamp;
|
||||
aData.sentTimestamp() = mSentTimestamp;
|
||||
aData.read() = mRead;
|
||||
aData.subject() = mSubject;
|
||||
aData.smil() = mSmil;
|
||||
aData.expiryDate() = mExpiryDate;
|
||||
aData.readReportRequested() = mReadReportRequested;
|
||||
|
||||
aData.deliveryInfo().SetCapacity(mDeliveryInfo.Length());
|
||||
for (uint32_t i = 0; i < mDeliveryInfo.Length(); i++) {
|
||||
MmsDeliveryInfoData infoData;
|
||||
const MmsDeliveryInfo &info = mDeliveryInfo[i];
|
||||
|
||||
// Prepare |infoData.mReceiver|.
|
||||
infoData.receiver().Assign(info.mReceiver);
|
||||
|
||||
// Prepare |infoData.mDeliveryStatus|.
|
||||
DeliveryStatus status;
|
||||
if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) {
|
||||
status = eDeliveryStatus_NotApplicable;
|
||||
} else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_SUCCESS)) {
|
||||
status = eDeliveryStatus_Success;
|
||||
} else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_PENDING)) {
|
||||
status = eDeliveryStatus_Pending;
|
||||
} else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_ERROR)) {
|
||||
status = eDeliveryStatus_Error;
|
||||
} else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_REJECTED)) {
|
||||
status = eDeliveryStatus_Reject;
|
||||
} else if (info.mDeliveryStatus.Equals(DELIVERY_STATUS_MANUAL)) {
|
||||
status = eDeliveryStatus_Manual;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
infoData.deliveryStatus() = status;
|
||||
|
||||
// Prepare |infoData.mDeliveryTimestamp|.
|
||||
infoData.deliveryTimestamp() = info.mDeliveryTimestamp;
|
||||
|
||||
// Prepare |infoData.mReadStatus|.
|
||||
ReadStatus readStatus;
|
||||
if (info.mReadStatus.Equals(READ_STATUS_NOT_APPLICABLE)) {
|
||||
readStatus = eReadStatus_NotApplicable;
|
||||
} else if (info.mReadStatus.Equals(READ_STATUS_SUCCESS)) {
|
||||
readStatus = eReadStatus_Success;
|
||||
} else if (info.mReadStatus.Equals(READ_STATUS_PENDING)) {
|
||||
readStatus = eReadStatus_Pending;
|
||||
} else if (info.mReadStatus.Equals(READ_STATUS_ERROR)) {
|
||||
readStatus = eReadStatus_Error;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
infoData.readStatus() = readStatus;
|
||||
|
||||
// Prepare |infoData.mReadTimestamp|.
|
||||
infoData.readTimestamp() = info.mReadTimestamp;
|
||||
|
||||
aData.deliveryInfo().AppendElement(infoData);
|
||||
}
|
||||
|
||||
aData.attachments().SetCapacity(mAttachments.Length());
|
||||
for (uint32_t i = 0; i < mAttachments.Length(); i++) {
|
||||
MmsAttachmentData mma;
|
||||
const MmsAttachment &element = mAttachments[i];
|
||||
mma.id().Assign(element.mId);
|
||||
mma.location().Assign(element.mLocation);
|
||||
|
||||
// This is a workaround. Sometimes the blob we get from the database
|
||||
// doesn't have a valid last modified date, making the ContentParent
|
||||
// send a "Mystery Blob" to the ContentChild. Attempting to get the
|
||||
// last modified date of blob can force that value to be initialized.
|
||||
RefPtr<BlobImpl> impl = element.mContent->Impl();
|
||||
if (impl && impl->IsDateUnknown()) {
|
||||
ErrorResult rv;
|
||||
impl->GetLastModified(rv);
|
||||
if (rv.Failed()) {
|
||||
NS_WARNING("Failed to get last modified date!");
|
||||
rv.SuppressException();
|
||||
}
|
||||
}
|
||||
|
||||
mma.contentParent() = aParent->GetOrCreateActorForBlob(element.mContent);
|
||||
if (!mma.contentParent()) {
|
||||
return false;
|
||||
}
|
||||
aData.attachments().AppendElement(mma);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetType(nsAString& aType)
|
||||
{
|
||||
aType = NS_LITERAL_STRING("mms");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetId(int32_t* aId)
|
||||
{
|
||||
*aId = mId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetThreadId(uint64_t* aThreadId)
|
||||
{
|
||||
*aThreadId = mThreadId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetIccId(nsAString& aIccId)
|
||||
{
|
||||
aIccId = mIccId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetDelivery(nsAString& aDelivery)
|
||||
{
|
||||
switch (mDelivery) {
|
||||
case eDeliveryState_Received:
|
||||
aDelivery = DELIVERY_RECEIVED;
|
||||
break;
|
||||
case eDeliveryState_Sending:
|
||||
aDelivery = DELIVERY_SENDING;
|
||||
break;
|
||||
case eDeliveryState_Sent:
|
||||
aDelivery = DELIVERY_SENT;
|
||||
break;
|
||||
case eDeliveryState_Error:
|
||||
aDelivery = DELIVERY_ERROR;
|
||||
break;
|
||||
case eDeliveryState_NotDownloaded:
|
||||
aDelivery = DELIVERY_NOT_DOWNLOADED;
|
||||
break;
|
||||
case eDeliveryState_Unknown:
|
||||
case eDeliveryState_EndGuard:
|
||||
default:
|
||||
MOZ_CRASH("We shouldn't get any other delivery state!");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetDeliveryInfo(JSContext* aCx, JS::MutableHandle<JS::Value> aDeliveryInfo)
|
||||
{
|
||||
// TODO Bug 850525 It'd be better to depend on the delivery of MmsMessage
|
||||
// to return a more correct value. Ex, if .delivery = 'received', we should
|
||||
// also make .deliveryInfo = null, since the .deliveryInfo is useless.
|
||||
uint32_t length = mDeliveryInfo.Length();
|
||||
if (length == 0) {
|
||||
aDeliveryInfo.setNull();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!ToJSValue(aCx, mDeliveryInfo, aDeliveryInfo)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetSender(nsAString& aSender)
|
||||
{
|
||||
aSender = mSender;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetReceivers(JSContext* aCx, JS::MutableHandle<JS::Value> aReceivers)
|
||||
{
|
||||
JS::Rooted<JSObject*> receiversObj(aCx);
|
||||
nsresult rv = nsTArrayToJSArray(aCx, mReceivers, &receiversObj);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aReceivers.setObject(*receiversObj);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetTimestamp(DOMTimeStamp* aTimestamp)
|
||||
{
|
||||
*aTimestamp = mTimestamp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetSentTimestamp(DOMTimeStamp* aSentTimestamp)
|
||||
{
|
||||
*aSentTimestamp = mSentTimestamp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetRead(bool* aRead)
|
||||
{
|
||||
*aRead = mRead;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetSubject(nsAString& aSubject)
|
||||
{
|
||||
aSubject = mSubject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetSmil(nsAString& aSmil)
|
||||
{
|
||||
aSmil = mSmil;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachments)
|
||||
{
|
||||
uint32_t length = mAttachments.Length();
|
||||
|
||||
if (length == 0) {
|
||||
aAttachments.setNull();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Duplicating the Blob with the correct parent object.
|
||||
nsIGlobalObject* global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
|
||||
MOZ_ASSERT(global);
|
||||
nsTArray<MmsAttachment> result;
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
MmsAttachment attachment;
|
||||
const MmsAttachment &element = mAttachments[i];
|
||||
attachment.mId = element.mId;
|
||||
attachment.mLocation = element.mLocation;
|
||||
attachment.mContent = Blob::Create(global, element.mContent->Impl());
|
||||
result.AppendElement(attachment);
|
||||
}
|
||||
|
||||
if (!ToJSValue(aCx, result, aAttachments)) {
|
||||
JS_ClearPendingException(aCx);
|
||||
return NS_ERROR_TYPE_ERR;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetExpiryDate(DOMTimeStamp* aExpiryDate)
|
||||
{
|
||||
*aExpiryDate = mExpiryDate;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MmsMessageInternal::GetReadReportRequested(bool* aReadReportRequested)
|
||||
{
|
||||
*aReadReportRequested = mReadReportRequested;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,104 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_MmsMessageInternal_h
|
||||
#define mozilla_dom_mobilemessage_MmsMessageInternal_h
|
||||
|
||||
#include "nsIMmsMessage.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/dom/mobilemessage/Types.h"
|
||||
#include "mozilla/dom/MmsMessageBinding.h"
|
||||
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ContentParent;
|
||||
class Blob;
|
||||
struct MmsAttachment;
|
||||
class MmsMessage;
|
||||
|
||||
namespace mobilemessage {
|
||||
|
||||
class MmsMessageData;
|
||||
|
||||
class MmsMessageInternal final : public nsIMmsMessage
|
||||
{
|
||||
// This allows the MmsMessage class to access jsval data members
|
||||
// like |deliveryInfo|, |receivers|, and |attachments| without JS API.
|
||||
friend class mozilla::dom::MmsMessage;
|
||||
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(MmsMessageInternal)
|
||||
NS_DECL_NSIMMSMESSAGE
|
||||
|
||||
MmsMessageInternal(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
mobilemessage::DeliveryState aDelivery,
|
||||
const nsTArray<MmsDeliveryInfo>& aDeliveryInfo,
|
||||
const nsAString& aSender,
|
||||
const nsTArray<nsString>& aReceivers,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
bool aRead,
|
||||
const nsAString& aSubject,
|
||||
const nsAString& aSmil,
|
||||
const nsTArray<MmsAttachment>& aAttachments,
|
||||
uint64_t aExpiryDate,
|
||||
bool aReadReportRequested);
|
||||
|
||||
explicit MmsMessageInternal(const MmsMessageData& aData);
|
||||
|
||||
static nsresult Create(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
const nsAString& aDelivery,
|
||||
const JS::Value& aDeliveryInfo,
|
||||
const nsAString& aSender,
|
||||
const JS::Value& aReceivers,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
bool aRead,
|
||||
const nsAString& aSubject,
|
||||
const nsAString& aSmil,
|
||||
const JS::Value& aAttachments,
|
||||
uint64_t aExpiryDate,
|
||||
bool aReadReportRequested,
|
||||
JSContext* aCx,
|
||||
nsIMmsMessage** aMessage);
|
||||
|
||||
bool GetData(ContentParent* aParent,
|
||||
MmsMessageData& aData);
|
||||
|
||||
private:
|
||||
|
||||
~MmsMessageInternal() {}
|
||||
|
||||
int32_t mId;
|
||||
uint64_t mThreadId;
|
||||
nsString mIccId;
|
||||
mobilemessage::DeliveryState mDelivery;
|
||||
nsTArray<MmsDeliveryInfo> mDeliveryInfo;
|
||||
nsString mSender;
|
||||
nsTArray<nsString> mReceivers;
|
||||
uint64_t mTimestamp;
|
||||
uint64_t mSentTimestamp;
|
||||
bool mRead;
|
||||
nsString mSubject;
|
||||
nsString mSmil;
|
||||
nsTArray<MmsAttachment> mAttachments;
|
||||
uint64_t mExpiryDate;
|
||||
bool mReadReportRequested;
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_MmsMessageInternal_h
|
@ -1,381 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "MobileMessageCallback.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "MmsMessage.h"
|
||||
#include "MmsMessageInternal.h"
|
||||
#include "SmsMessage.h"
|
||||
#include "SmsMessageInternal.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "jsapi.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsTArrayHelpers.h"
|
||||
#include "DOMMobileMessageError.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
static nsAutoString
|
||||
ConvertErrorCodeToErrorString(int32_t aError)
|
||||
{
|
||||
nsAutoString errorStr;
|
||||
switch (aError) {
|
||||
case nsIMobileMessageCallback::NO_SIGNAL_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("NoSignalError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::NOT_FOUND_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("NotFoundError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::UNKNOWN_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("UnknownError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::INTERNAL_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("InternalError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::NO_SIM_CARD_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("NoSimCardError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::RADIO_DISABLED_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("RadioDisabledError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::INVALID_ADDRESS_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("InvalidAddressError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::FDN_CHECK_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("FdnCheckError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::NON_ACTIVE_SIM_CARD_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("NonActiveSimCardError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::STORAGE_FULL_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("StorageFullError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::SIM_NOT_MATCHED_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("SimNotMatchedError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::NETWORK_PROBLEMS_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("NetworkProblemsError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::GENERAL_PROBLEMS_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("GeneralProblemsError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::SERVICE_NOT_AVAILABLE_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("ServiceNotAvailableError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::MESSAGE_TOO_LONG_FOR_NETWORK_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("MessageTooLongForNetworkError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::SERVICE_NOT_SUPPORTED_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("ServiceNotSupportedError");
|
||||
break;
|
||||
case nsIMobileMessageCallback::RETRY_REQUIRED_ERROR:
|
||||
errorStr = NS_LITERAL_STRING("RetryRequiredError");
|
||||
break;
|
||||
default: // SUCCESS_NO_ERROR is handled above.
|
||||
MOZ_CRASH("Should never get here!");
|
||||
}
|
||||
|
||||
return errorStr;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(MobileMessageCallback)
|
||||
NS_IMPL_RELEASE(MobileMessageCallback)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(MobileMessageCallback)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIMobileMessageCallback)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
MobileMessageCallback::MobileMessageCallback(DOMRequest* aDOMRequest)
|
||||
: mDOMRequest(aDOMRequest)
|
||||
{
|
||||
}
|
||||
|
||||
MobileMessageCallback::MobileMessageCallback(Promise* aPromise)
|
||||
: mPromise(aPromise)
|
||||
{
|
||||
}
|
||||
|
||||
MobileMessageCallback::~MobileMessageCallback()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
MobileMessageCallback::NotifySuccess(JS::Handle<JS::Value> aResult, bool aAsync)
|
||||
{
|
||||
if (NS_WARN_IF(!mDOMRequest->GetOwner())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aAsync) {
|
||||
nsCOMPtr<nsIDOMRequestService> rs =
|
||||
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
return rs->FireSuccessAsync(mDOMRequest, aResult);
|
||||
}
|
||||
|
||||
mDOMRequest->FireSuccess(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileMessageCallback::NotifySuccess(nsISupports *aMessage, bool aAsync)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = mDOMRequest->GetOwner();
|
||||
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISupports> result;
|
||||
|
||||
nsCOMPtr<nsISmsMessage> internalSms =
|
||||
do_QueryInterface(aMessage);
|
||||
if (internalSms) {
|
||||
SmsMessageInternal* smsMsg = static_cast<SmsMessageInternal*>(internalSms.get());
|
||||
result = new SmsMessage(window, smsMsg);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
nsCOMPtr<nsIMmsMessage> internalMms =
|
||||
do_QueryInterface(aMessage);
|
||||
if (internalMms) {
|
||||
MmsMessageInternal* mmsMsg = static_cast<MmsMessageInternal*>(internalMms.get());
|
||||
result = new MmsMessage(window, mmsMsg);
|
||||
}
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (NS_WARN_IF(!jsapi.Init(window))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
JS::Rooted<JS::Value> wrappedMessage(cx);
|
||||
nsresult rv =
|
||||
nsContentUtils::WrapNative(cx, result, &wrappedMessage);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NotifySuccess(wrappedMessage, aAsync);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileMessageCallback::NotifyError(int32_t aError, DOMError *aDetailedError, bool aAsync)
|
||||
{
|
||||
if (NS_WARN_IF(!mDOMRequest->GetOwner())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aAsync) {
|
||||
NS_ASSERTION(!aDetailedError,
|
||||
"No Support to FireDetailedErrorAsync() in nsIDOMRequestService!");
|
||||
|
||||
nsCOMPtr<nsIDOMRequestService> rs =
|
||||
do_GetService(DOMREQUEST_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(rs, NS_ERROR_FAILURE);
|
||||
|
||||
return rs->FireErrorAsync(mDOMRequest,
|
||||
ConvertErrorCodeToErrorString(aError));
|
||||
}
|
||||
|
||||
if (aDetailedError) {
|
||||
mDOMRequest->FireDetailedError(aDetailedError);
|
||||
} else {
|
||||
mDOMRequest->FireError(ConvertErrorCodeToErrorString(aError));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyMessageSent(nsISupports *aMessage)
|
||||
{
|
||||
return NotifySuccess(aMessage);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifySendMessageFailed(int32_t aError, nsISupports *aMessage)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = mDOMRequest->GetOwner();
|
||||
if (NS_WARN_IF(!window)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<DOMMobileMessageError> domMobileMessageError;
|
||||
if (aMessage) {
|
||||
nsAutoString errorStr = ConvertErrorCodeToErrorString(aError);
|
||||
nsCOMPtr<nsISmsMessage> internalSms = do_QueryInterface(aMessage);
|
||||
if (internalSms) {
|
||||
domMobileMessageError =
|
||||
new DOMMobileMessageError(window, errorStr,
|
||||
new SmsMessage(window,
|
||||
static_cast<SmsMessageInternal*>(internalSms.get())));
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIMmsMessage> internalMms = do_QueryInterface(aMessage);
|
||||
domMobileMessageError =
|
||||
new DOMMobileMessageError(window, errorStr,
|
||||
new MmsMessage(window,
|
||||
static_cast<MmsMessageInternal*>(internalMms.get())));
|
||||
}
|
||||
NS_ASSERTION(domMobileMessageError, "Invalid DOMMobileMessageError!");
|
||||
}
|
||||
|
||||
return NotifyError(aError, domMobileMessageError);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyMessageGot(nsISupports *aMessage)
|
||||
{
|
||||
return NotifySuccess(aMessage);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyGetMessageFailed(int32_t aError)
|
||||
{
|
||||
return NotifyError(aError);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyMessageDeleted(bool *aDeleted, uint32_t aSize)
|
||||
{
|
||||
if (aSize == 1) {
|
||||
AutoJSContext cx;
|
||||
JS::Rooted<JS::Value> val(cx, JS::BooleanValue(*aDeleted));
|
||||
return NotifySuccess(val);
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (NS_WARN_IF(!jsapi.Init(mDOMRequest->GetOwner()))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
JS::Rooted<JSObject*> deleteArrayObj(cx, JS_NewArrayObject(cx, aSize));
|
||||
if (!deleteArrayObj) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
for (uint32_t i = 0; i < aSize; i++) {
|
||||
if (!JS_DefineElement(cx, deleteArrayObj, i, aDeleted[i],
|
||||
JSPROP_ENUMERATE)) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
}
|
||||
|
||||
JS::Rooted<JS::Value> deleteArrayVal(cx, JS::ObjectValue(*deleteArrayObj));
|
||||
return NotifySuccess(deleteArrayVal);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyDeleteMessageFailed(int32_t aError)
|
||||
{
|
||||
return NotifyError(aError);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyMessageMarkedRead(bool aRead)
|
||||
{
|
||||
AutoJSContext cx;
|
||||
JS::Rooted<JS::Value> val(cx, JS::BooleanValue(aRead));
|
||||
return NotifySuccess(val);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyMarkMessageReadFailed(int32_t aError)
|
||||
{
|
||||
return NotifyError(aError);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifySegmentInfoForTextGot(int32_t aSegments,
|
||||
int32_t aCharsPerSegment,
|
||||
int32_t aCharsAvailableInLastSegment)
|
||||
{
|
||||
AutoJSAPI jsapi;
|
||||
if (NS_WARN_IF(!jsapi.Init(mDOMRequest->GetOwner()))) {
|
||||
return NotifyError(nsIMobileMessageCallback::INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
SmsSegmentInfo info;
|
||||
info.mSegments = aSegments;
|
||||
info.mCharsPerSegment = aCharsPerSegment;
|
||||
info.mCharsAvailableInLastSegment = aCharsAvailableInLastSegment;
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> val(cx);
|
||||
if (!ToJSValue(cx, info, &val)) {
|
||||
jsapi.ClearException();
|
||||
return NotifyError(nsIMobileMessageCallback::INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
return NotifySuccess(val, true);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyGetSegmentInfoForTextFailed(int32_t aError)
|
||||
{
|
||||
return NotifyError(aError, nullptr, true);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyGetSmscAddress(const nsAString& aSmscAddress,
|
||||
uint32_t aTypeOfNumber,
|
||||
uint32_t aNumberPlanIdentification)
|
||||
{
|
||||
TypeOfAddress toa;
|
||||
|
||||
// Check the value is valid and set TON accordingly.
|
||||
bool isTonValid = aTypeOfNumber < uint32_t(TypeOfNumber::EndGuard_);
|
||||
toa.mTypeOfNumber = (isTonValid) ?
|
||||
static_cast<TypeOfNumber>(aTypeOfNumber) : TypeOfNumber::Unknown;
|
||||
|
||||
// Check the value is valid and set NPI accordingly.
|
||||
bool isNpiValid =
|
||||
aNumberPlanIdentification < uint32_t(NumberPlanIdentification::EndGuard_);
|
||||
toa.mNumberPlanIdentification = (isNpiValid) ?
|
||||
static_cast<NumberPlanIdentification>(aNumberPlanIdentification) :
|
||||
NumberPlanIdentification::Unknown;
|
||||
|
||||
SmscAddress smsc;
|
||||
smsc.mTypeOfAddress = toa;
|
||||
smsc.mAddress.Construct(nsString(aSmscAddress));
|
||||
|
||||
mPromise->MaybeResolve(smsc);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifyGetSmscAddressFailed(int32_t aError)
|
||||
{
|
||||
const nsAString& errorStr = ConvertErrorCodeToErrorString(aError);
|
||||
mPromise->MaybeRejectBrokenly(errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifySetSmscAddress()
|
||||
{
|
||||
mPromise->MaybeResolveWithUndefined();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCallback::NotifySetSmscAddressFailed(int32_t aError)
|
||||
{
|
||||
const nsAString& errorStr = ConvertErrorCodeToErrorString(aError);
|
||||
mPromise->MaybeRejectBrokenly(errorStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,44 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_MobileMessageCallback_h
|
||||
#define mozilla_dom_mobilemessage_MobileMessageCallback_h
|
||||
|
||||
#include "nsIMobileMessageCallback.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "DOMRequest.h"
|
||||
|
||||
class Promise;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class MobileMessageCallback final : public nsIMobileMessageCallback
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMOBILEMESSAGECALLBACK
|
||||
|
||||
explicit MobileMessageCallback(DOMRequest* aDOMRequest);
|
||||
explicit MobileMessageCallback(Promise* aPromise);
|
||||
|
||||
private:
|
||||
~MobileMessageCallback();
|
||||
|
||||
RefPtr<DOMRequest> mDOMRequest;
|
||||
RefPtr<Promise> mPromise;
|
||||
|
||||
nsresult NotifySuccess(JS::Handle<JS::Value> aResult, bool aAsync = false);
|
||||
nsresult NotifySuccess(nsISupports *aMessage, bool aAsync = false);
|
||||
nsresult NotifyError(int32_t aError, DOMError *aDetailedError = nullptr, bool aAsync = false);
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_MobileMessageCallback_h
|
@ -1,216 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "MobileMessageCursorCallback.h"
|
||||
#include "MmsMessage.h"
|
||||
#include "MmsMessageInternal.h"
|
||||
#include "MobileMessageThread.h"
|
||||
#include "MobileMessageThreadInternal.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "nsIDOMDOMRequest.h"
|
||||
#include "SmsMessage.h"
|
||||
#include "SmsMessageInternal.h"
|
||||
#include "nsIMobileMessageCallback.h"
|
||||
#include "nsServiceManagerUtils.h" // for do_GetService
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(MobileMessageCursor, DOMCursor,
|
||||
mPendingResults)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MobileMessageCursor)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMCursor)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(MobileMessageCursor, DOMCursor)
|
||||
NS_IMPL_RELEASE_INHERITED(MobileMessageCursor, DOMCursor)
|
||||
|
||||
MobileMessageCursor::MobileMessageCursor(nsPIDOMWindowInner* aWindow,
|
||||
nsICursorContinueCallback* aCallback)
|
||||
: DOMCursor(aWindow, aCallback)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursor::Continue()
|
||||
{
|
||||
// We have originally:
|
||||
//
|
||||
// DOMCursor::Continue()
|
||||
// +-> DOMCursor::Continue(ErrorResult& aRv)
|
||||
//
|
||||
// Now it becomes:
|
||||
//
|
||||
// MobileMessageCursor::Continue()
|
||||
// +-> DOMCursor::Continue()
|
||||
// +-> MobileMessageCursor::Continue(ErrorResult& aRv)
|
||||
// o-> DOMCursor::Continue(ErrorResult& aRv)
|
||||
return DOMCursor::Continue();
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageCursor::Continue(ErrorResult& aRv)
|
||||
{
|
||||
// An ordinary DOMCursor works in following flow:
|
||||
//
|
||||
// DOMCursor::Continue()
|
||||
// +-> DOMCursor::Reset()
|
||||
// +-> nsICursorContinueCallback::HandleContinue()
|
||||
// +-> nsIMobileMessageCursorCallback::NotifyCursorResult()
|
||||
// +-> DOMCursor::FireSuccess()
|
||||
//
|
||||
// With no pending result, we call to |DOMCursor::Continue()| as usual.
|
||||
if (!mPendingResults.Length()) {
|
||||
DOMCursor::Continue(aRv);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, reset current result and fire a success event with the last
|
||||
// pending one.
|
||||
Reset();
|
||||
|
||||
nsresult rv = FireSuccessWithNextPendingResult();
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileMessageCursor::FireSuccessWithNextPendingResult()
|
||||
{
|
||||
// We're going to pop the last element from mPendingResults, so it must not
|
||||
// be empty.
|
||||
MOZ_ASSERT(mPendingResults.Length());
|
||||
|
||||
nsCOMPtr<nsISupports> result;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageThread> internalThread =
|
||||
do_QueryInterface(mPendingResults.LastElement());
|
||||
if (internalThread) {
|
||||
MobileMessageThreadInternal* thread =
|
||||
static_cast<MobileMessageThreadInternal*>(internalThread.get());
|
||||
result = new MobileMessageThread(GetOwner(), thread);
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
nsCOMPtr<nsISmsMessage> internalSms =
|
||||
do_QueryInterface(mPendingResults.LastElement());
|
||||
if (internalSms) {
|
||||
SmsMessageInternal* sms = static_cast<SmsMessageInternal*>(internalSms.get());
|
||||
result = new SmsMessage(GetOwner(), sms);
|
||||
}
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
nsCOMPtr<nsIMmsMessage> internalMms =
|
||||
do_QueryInterface(mPendingResults.LastElement());
|
||||
if (internalMms) {
|
||||
MmsMessageInternal* mms = static_cast<MmsMessageInternal*>(internalMms.get());
|
||||
result = new MmsMessage(GetOwner(), mms);
|
||||
}
|
||||
}
|
||||
|
||||
MOZ_ASSERT(result);
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (NS_WARN_IF(!jsapi.Init(GetOwner()))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
JSContext* cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> val(cx);
|
||||
nsresult rv =
|
||||
nsContentUtils::WrapNative(cx, result, &val);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mPendingResults.RemoveElementAt(mPendingResults.Length() - 1);
|
||||
|
||||
FireSuccess(val);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(MobileMessageCursorCallback, mDOMCursor)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MobileMessageCursorCallback)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIMobileMessageCursorCallback)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(MobileMessageCursorCallback)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(MobileMessageCursorCallback)
|
||||
|
||||
// nsIMobileMessageCursorCallback
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorCallback::NotifyCursorError(int32_t aError)
|
||||
{
|
||||
MOZ_ASSERT(mDOMCursor);
|
||||
|
||||
RefPtr<DOMCursor> cursor = mDOMCursor.forget();
|
||||
|
||||
switch (aError) {
|
||||
case nsIMobileMessageCallback::NO_SIGNAL_ERROR:
|
||||
cursor->FireError(NS_LITERAL_STRING("NoSignalError"));
|
||||
break;
|
||||
case nsIMobileMessageCallback::NOT_FOUND_ERROR:
|
||||
cursor->FireError(NS_LITERAL_STRING("NotFoundError"));
|
||||
break;
|
||||
case nsIMobileMessageCallback::UNKNOWN_ERROR:
|
||||
cursor->FireError(NS_LITERAL_STRING("UnknownError"));
|
||||
break;
|
||||
case nsIMobileMessageCallback::INTERNAL_ERROR:
|
||||
cursor->FireError(NS_LITERAL_STRING("InternalError"));
|
||||
break;
|
||||
default: // SUCCESS_NO_ERROR is handled above.
|
||||
MOZ_CRASH("Should never get here!");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorCallback::NotifyCursorResult(nsISupports** aResults,
|
||||
uint32_t aSize)
|
||||
{
|
||||
MOZ_ASSERT(mDOMCursor);
|
||||
// We should only be notified with valid results. Or, either
|
||||
// |NotifyCursorDone()| or |NotifyCursorError()| should be called instead.
|
||||
MOZ_ASSERT(aResults && *aResults && aSize);
|
||||
// There shouldn't be unexpected notifications before |Continue()| is called.
|
||||
nsTArray<nsCOMPtr<nsISupports>>& pending = mDOMCursor->mPendingResults;
|
||||
MOZ_ASSERT(pending.Length() == 0);
|
||||
|
||||
// Push pending results in reversed order.
|
||||
pending.SetCapacity(pending.Length() + aSize);
|
||||
while (aSize) {
|
||||
--aSize;
|
||||
pending.AppendElement(aResults[aSize]);
|
||||
}
|
||||
|
||||
nsresult rv = mDOMCursor->FireSuccessWithNextPendingResult();
|
||||
if (NS_FAILED(rv)) {
|
||||
NotifyCursorError(nsIMobileMessageCallback::INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorCallback::NotifyCursorDone()
|
||||
{
|
||||
MOZ_ASSERT(mDOMCursor);
|
||||
|
||||
RefPtr<DOMCursor> cursor = mDOMCursor.forget();
|
||||
cursor->FireDone();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,90 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_MobileMessageCursorCallback_h
|
||||
#define mozilla_dom_mobilemessage_MobileMessageCursorCallback_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/DOMCursor.h"
|
||||
#include "nsIMobileMessageCursorCallback.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsICursorContinueCallback;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class MobileMessageManager;
|
||||
|
||||
namespace mobilemessage {
|
||||
class MobileMessageCursorCallback;
|
||||
} // namespace mobilemessage
|
||||
|
||||
class MobileMessageCursor final : public DOMCursor
|
||||
{
|
||||
friend class mobilemessage::MobileMessageCursorCallback;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MobileMessageCursor, DOMCursor)
|
||||
|
||||
MobileMessageCursor(nsPIDOMWindowInner* aWindow,
|
||||
nsICursorContinueCallback* aCallback);
|
||||
|
||||
// Override XPIDL continue function to suppress -Werror,-Woverloaded-virtual.
|
||||
NS_IMETHOD
|
||||
Continue(void) override;
|
||||
|
||||
virtual void
|
||||
Continue(ErrorResult& aRv) override;
|
||||
|
||||
private:
|
||||
// final suppresses -Werror,-Wdelete-non-virtual-dtor
|
||||
~MobileMessageCursor() {}
|
||||
|
||||
private:
|
||||
// List of read-ahead results in reversed order.
|
||||
nsTArray<nsCOMPtr<nsISupports>> mPendingResults;
|
||||
|
||||
nsresult
|
||||
FireSuccessWithNextPendingResult();
|
||||
};
|
||||
|
||||
namespace mobilemessage {
|
||||
|
||||
class MobileMessageCursorCallback final : public nsIMobileMessageCursorCallback
|
||||
{
|
||||
friend class mozilla::dom::MobileMessageManager;
|
||||
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_NSIMOBILEMESSAGECURSORCALLBACK
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS(MobileMessageCursorCallback)
|
||||
|
||||
MobileMessageCursorCallback()
|
||||
{
|
||||
MOZ_COUNT_CTOR(MobileMessageCursorCallback);
|
||||
}
|
||||
|
||||
private:
|
||||
// final suppresses -Werror,-Wdelete-non-virtual-dtor
|
||||
~MobileMessageCursorCallback()
|
||||
{
|
||||
MOZ_COUNT_DTOR(MobileMessageCursorCallback);
|
||||
}
|
||||
|
||||
RefPtr<MobileMessageCursor> mDOMCursor;
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_MobileMessageCursorCallback_h
|
||||
|
@ -1,905 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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"
|
||||
|
||||
#include "DeletedMessageInfo.h"
|
||||
#include "DOMCursor.h"
|
||||
#include "DOMRequest.h"
|
||||
#include "MmsMessage.h"
|
||||
#include "MmsMessageInternal.h"
|
||||
#include "MobileMessageCallback.h"
|
||||
#include "MobileMessageCursorCallback.h"
|
||||
#include "SmsMessage.h"
|
||||
#include "SmsMessageInternal.h"
|
||||
#include "mozilla/dom/mobilemessage/Constants.h" // For kSms*ObserverTopic
|
||||
#include "mozilla/dom/MozMessageDeletedEvent.h"
|
||||
#include "mozilla/dom/MozMmsEvent.h"
|
||||
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
|
||||
#include "mozilla/dom/MozSmsEvent.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsIMmsService.h"
|
||||
#include "nsIMobileMessageCallback.h"
|
||||
#include "nsIMobileMessageDatabaseService.h"
|
||||
#include "nsIMobileMessageService.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsISmsService.h"
|
||||
#include "nsServiceManagerUtils.h" // For do_GetService()
|
||||
|
||||
// Service instantiation
|
||||
#include "ipc/SmsIPCService.h"
|
||||
#include "MobileMessageService.h"
|
||||
#if defined(MOZ_WIDGET_ANDROID) && defined(MOZ_WEBSMS_BACKEND)
|
||||
#include "android/MobileMessageDatabaseService.h"
|
||||
#include "android/SmsService.h"
|
||||
#elif defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
||||
#include "nsIGonkMobileMessageDatabaseService.h"
|
||||
#include "nsIGonkSmsService.h"
|
||||
#endif
|
||||
#include "nsXULAppAPI.h" // For XRE_GetProcessType()
|
||||
|
||||
#define RECEIVED_EVENT_NAME NS_LITERAL_STRING("received")
|
||||
#define RETRIEVING_EVENT_NAME NS_LITERAL_STRING("retrieving")
|
||||
#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")
|
||||
#define READ_SUCCESS_EVENT_NAME NS_LITERAL_STRING("readsuccess")
|
||||
#define READ_ERROR_EVENT_NAME NS_LITERAL_STRING("readerror")
|
||||
#define DELETED_EVENT_NAME NS_LITERAL_STRING("deleted")
|
||||
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(MobileMessageManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(MobileMessageManager, DOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(MobileMessageManager, DOMEventTargetHelper)
|
||||
|
||||
MobileMessageManager::MobileMessageManager(nsPIDOMWindowInner* aWindow)
|
||||
: DOMEventTargetHelper(aWindow)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageManager::Init()
|
||||
{
|
||||
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, kSmsRetrievingObserverTopic, 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);
|
||||
obs->AddObserver(this, kSmsReadSuccessObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsReadErrorObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsDeletedObserverTopic, 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, kSmsRetrievingObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsSendingObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsSentObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsFailedObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsReadSuccessObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsDeletedObserverTopic);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
MobileMessageManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return MozMobileMessageManagerBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::GetSegmentInfoForText(const nsAString& aText,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
if (!smsService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMRequest> request = new DOMRequest(window);
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
||||
new MobileMessageCallback(request);
|
||||
nsresult rv = smsService->GetSegmentInfoForText(aText, msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::Send(nsISmsService* aSmsService,
|
||||
uint32_t aServiceId,
|
||||
const nsAString& aNumber,
|
||||
const nsAString& aText,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMRequest> request = new DOMRequest(window);
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
||||
new MobileMessageCallback(request);
|
||||
|
||||
// By default, we don't send silent messages via MobileMessageManager.
|
||||
nsresult rv = aSmsService->Send(aServiceId, aNumber, aText,
|
||||
false, msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::Send(const nsAString& aNumber,
|
||||
const nsAString& aText,
|
||||
const SmsSendParameters& aSendParams,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
if (!smsService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// 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 nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return Send(smsService, serviceId, aNumber, aText, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageManager::Send(const Sequence<nsString>& aNumbers,
|
||||
const nsAString& aText,
|
||||
const SmsSendParameters& aSendParams,
|
||||
nsTArray<RefPtr<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) {
|
||||
RefPtr<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);
|
||||
if (!mmsService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Use the default one unless |aSendParams.serviceId| is available.
|
||||
uint32_t serviceId;
|
||||
nsresult rv;
|
||||
if (aSendParams.mServiceId.WasPassed()) {
|
||||
serviceId = aSendParams.mServiceId.Value();
|
||||
} else {
|
||||
rv = mmsService->GetMmsDefaultServiceId(&serviceId);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (NS_WARN_IF(!jsapi.Init(window))) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JSContext *cx = jsapi.cx();
|
||||
JS::Rooted<JS::Value> val(cx);
|
||||
aRv.MightThrowJSException();
|
||||
if (!ToJSValue(cx, aParams, &val)) {
|
||||
aRv.StealExceptionFromJSContext(cx);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMRequest> request = new DOMRequest(window);
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
||||
rv = mmsService->Send(serviceId, val, msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::GetMessage(int32_t aId,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (!dbService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMRequest> request = new DOMRequest(window);
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
||||
nsresult rv = dbService->GetMessageMoz(aId, msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::Delete(int32_t* aIdArray,
|
||||
uint32_t aSize,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (!dbService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMRequest> request = new DOMRequest(window);
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
||||
new MobileMessageCallback(request);
|
||||
|
||||
nsresult rv = dbService->DeleteMessage(aIdArray, aSize, msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::Delete(int32_t aId,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
return Delete(&aId, 1, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::Delete(SmsMessage& aMessage,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
return Delete(aMessage.Id(), aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::Delete(MmsMessage& aMessage,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
return Delete(aMessage.Id(), aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::Delete(const Sequence<OwningLongOrSmsMessageOrMmsMessage>& aParams,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
const uint32_t size = aParams.Length();
|
||||
FallibleTArray<int32_t> idArray;
|
||||
if (!idArray.SetLength(size, fallible)) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
DebugOnly<nsresult> rv;
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
const OwningLongOrSmsMessageOrMmsMessage& element = aParams[i];
|
||||
int32_t &id = idArray[i];
|
||||
|
||||
if (element.IsLong()) {
|
||||
id = element.GetAsLong();
|
||||
} else if (element.IsMmsMessage()) {
|
||||
id = element.GetAsMmsMessage()->Id();
|
||||
} else /*if (element.IsSmsMessage())*/ {
|
||||
id = element.GetAsSmsMessage()->Id();
|
||||
}
|
||||
}
|
||||
|
||||
return Delete(idArray.Elements(), size, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<DOMCursor>
|
||||
MobileMessageManager::GetMessages(const MobileMessageFilter& aFilter,
|
||||
bool aReverse,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (!dbService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
UniquePtr<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 = MakeUnique<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();
|
||||
}
|
||||
|
||||
bool hasThreadId = !aFilter.mThreadId.IsNull();
|
||||
uint64_t threadId = 0;
|
||||
if (hasThreadId) {
|
||||
threadId = aFilter.mThreadId.Value();
|
||||
}
|
||||
|
||||
RefPtr<MobileMessageCursorCallback> cursorCallback =
|
||||
new MobileMessageCursorCallback();
|
||||
nsCOMPtr<nsICursorContinueCallback> continueCallback;
|
||||
nsresult rv = dbService->CreateMessageCursor(hasStartDate, startDate,
|
||||
hasEndDate, endDate,
|
||||
ptrNumbers.get(), numbersCount,
|
||||
delivery,
|
||||
hasRead, read,
|
||||
hasThreadId, threadId,
|
||||
aReverse, cursorCallback,
|
||||
getter_AddRefs(continueCallback));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cursorCallback->mDOMCursor =
|
||||
new MobileMessageCursor(window, continueCallback);
|
||||
|
||||
RefPtr<DOMCursor> cursor(cursorCallback->mDOMCursor);
|
||||
return cursor.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::MarkMessageRead(int32_t aId,
|
||||
bool aValue,
|
||||
bool aSendReadReport,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (!dbService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMRequest> request = new DOMRequest(window);
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
||||
nsresult rv = dbService->MarkMessageRead(aId, aValue, aSendReadReport,
|
||||
msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMCursor>
|
||||
MobileMessageManager::GetThreads(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (!dbService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<MobileMessageCursorCallback> cursorCallback =
|
||||
new MobileMessageCursorCallback();
|
||||
|
||||
nsCOMPtr<nsICursorContinueCallback> continueCallback;
|
||||
nsresult rv = dbService->CreateThreadCursor(cursorCallback,
|
||||
getter_AddRefs(continueCallback));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cursorCallback->mDOMCursor =
|
||||
new MobileMessageCursor(window, continueCallback);
|
||||
|
||||
RefPtr<DOMCursor> cursor(cursorCallback->mDOMCursor);
|
||||
return cursor.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::RetrieveMMS(int32_t aId,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
|
||||
if (!mmsService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMRequest> request = new DOMRequest(window);
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback = new MobileMessageCallback(request);
|
||||
|
||||
nsresult rv = mmsService->Retrieve(aId, msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return request.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
MobileMessageManager::RetrieveMMS(MmsMessage& aMessage,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
return RetrieveMMS(aMessage.Id(), aRv);
|
||||
}
|
||||
|
||||
nsresult
|
||||
MobileMessageManager::DispatchTrustedSmsEventToSelf(const char* aTopic,
|
||||
const nsAString& aEventName,
|
||||
nsISupports* aMsg)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISmsMessage> sms = do_QueryInterface(aMsg);
|
||||
if (sms) {
|
||||
MozSmsEventInit init;
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = false;
|
||||
init.mMessage =
|
||||
new SmsMessage(window, static_cast<SmsMessageInternal*>(sms.get()));
|
||||
|
||||
RefPtr<MozSmsEvent> event =
|
||||
MozSmsEvent::Constructor(this, aEventName, init);
|
||||
return DispatchTrustedEvent(event);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMmsMessage> mms = do_QueryInterface(aMsg);
|
||||
if (mms) {
|
||||
MozMmsEventInit init;
|
||||
init.mBubbles = false;
|
||||
init.mCancelable = false;
|
||||
init.mMessage =
|
||||
new MmsMessage(window, static_cast<MmsMessageInternal*>(mms.get()));
|
||||
|
||||
RefPtr<MozMmsEvent> event =
|
||||
MozMmsEvent::Constructor(this, aEventName, init);
|
||||
return DispatchTrustedEvent(event);
|
||||
}
|
||||
|
||||
nsAutoCString errorMsg;
|
||||
errorMsg.AssignLiteral("Got a '");
|
||||
errorMsg.Append(aTopic);
|
||||
errorMsg.AppendLiteral("' topic without a valid message!");
|
||||
NS_ERROR(errorMsg.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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();
|
||||
if (!deletedMsgIds.AppendElements(info->GetData().deletedMessageIds(),
|
||||
fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t threadIdLength = info->GetData().deletedThreadIds().Length();
|
||||
if (threadIdLength) {
|
||||
Sequence<uint64_t>& deletedThreadIds = init.mDeletedThreadIds.SetValue();
|
||||
if (!deletedThreadIds.AppendElements(info->GetData().deletedThreadIds(),
|
||||
fallible)) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageManager::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
if (!strcmp(aTopic, kSmsReceivedObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, RECEIVED_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsRetrievingObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, RETRIEVING_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsSendingObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, SENDING_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsSentObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, SENT_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsFailedObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, FAILED_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsDeliverySuccessObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, DELIVERY_SUCCESS_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsDeliveryErrorObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, DELIVERY_ERROR_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsReadSuccessObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, READ_SUCCESS_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsReadErrorObserverTopic)) {
|
||||
return DispatchTrustedSmsEventToSelf(aTopic, READ_ERROR_EVENT_NAME, aSubject);
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsDeletedObserverTopic)) {
|
||||
return DispatchTrustedDeletedEventToSelf(aSubject);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
MobileMessageManager::GetSmscAddress(const Optional<uint32_t>& aServiceId,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
if (!smsService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Use the default one unless |aSendParams.serviceId| is available.
|
||||
uint32_t serviceId;
|
||||
nsresult rv;
|
||||
if (aServiceId.WasPassed()) {
|
||||
serviceId = aServiceId.Value();
|
||||
} else {
|
||||
rv = smsService->GetSmsDefaultServiceId(&serviceId);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(window);
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
||||
new MobileMessageCallback(promise);
|
||||
|
||||
rv = smsService->GetSmscAddress(serviceId, msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
promise->MaybeReject(rv);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
MobileMessageManager::SetSmscAddress(const SmscAddress& aSmscAddress,
|
||||
const Optional<uint32_t>& aServiceId,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
if (!smsService) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Use the default one unless |serviceId| is available.
|
||||
uint32_t serviceId;
|
||||
nsresult rv;
|
||||
if (aServiceId.WasPassed()) {
|
||||
serviceId = aServiceId.Value();
|
||||
} else {
|
||||
rv = smsService->GetSmsDefaultServiceId(&serviceId);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = GetOwner();
|
||||
if (!window) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(window);
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!aSmscAddress.mAddress.WasPassed()) {
|
||||
NS_WARNING("SmscAddress.address is a mandatory field and can not be omitted.");
|
||||
promise->MaybeReject(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsString address = aSmscAddress.mAddress.Value();
|
||||
TypeOfNumber ton = aSmscAddress.mTypeOfAddress.mTypeOfNumber;
|
||||
NumberPlanIdentification npi =
|
||||
aSmscAddress.mTypeOfAddress.mNumberPlanIdentification;
|
||||
|
||||
// If the address begins with +, set TON to international no matter what has
|
||||
// passed in.
|
||||
if (!address.IsEmpty() && address[0] == '+') {
|
||||
ton = TypeOfNumber::International;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCallback> msgCallback =
|
||||
new MobileMessageCallback(promise);
|
||||
|
||||
rv = smsService->SetSmscAddress(serviceId, address,
|
||||
static_cast<uint32_t>(ton), static_cast<uint32_t>(npi), msgCallback);
|
||||
if (NS_FAILED(rv)) {
|
||||
promise->MaybeReject(rv);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
already_AddRefed<nsISmsService>
|
||||
NS_CreateSmsService()
|
||||
{
|
||||
nsCOMPtr<nsISmsService> smsService;
|
||||
|
||||
if (XRE_IsContentProcess()) {
|
||||
smsService = SmsIPCService::GetSingleton();
|
||||
} else {
|
||||
#if defined(MOZ_WIDGET_ANDROID) && defined(MOZ_WEBSMS_BACKEND)
|
||||
smsService = new SmsService();
|
||||
#elif defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
||||
smsService = do_GetService(GONK_SMSSERVICE_CONTRACTID);
|
||||
#endif
|
||||
}
|
||||
|
||||
return smsService.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMobileMessageDatabaseService>
|
||||
NS_CreateMobileMessageDatabaseService()
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService;
|
||||
if (XRE_IsContentProcess()) {
|
||||
mobileMessageDBService = SmsIPCService::GetSingleton();
|
||||
} else {
|
||||
#if defined(MOZ_WIDGET_ANDROID) && defined(MOZ_WEBSMS_BACKEND)
|
||||
mobileMessageDBService = new MobileMessageDatabaseService();
|
||||
#elif defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
||||
mobileMessageDBService =
|
||||
do_CreateInstance(GONK_MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
#endif
|
||||
}
|
||||
|
||||
return mobileMessageDBService.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMmsService>
|
||||
NS_CreateMmsService()
|
||||
{
|
||||
nsCOMPtr<nsIMmsService> mmsService;
|
||||
|
||||
if (XRE_IsContentProcess()) {
|
||||
mmsService = SmsIPCService::GetSingleton();
|
||||
} else {
|
||||
#if defined(MOZ_WIDGET_GONK) && defined(MOZ_B2G_RIL)
|
||||
mmsService = do_CreateInstance("@mozilla.org/mms/gonkmmsservice;1");
|
||||
#endif
|
||||
}
|
||||
|
||||
return mmsService.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMobileMessageService>
|
||||
NS_CreateMobileMessageService()
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageService> service = new MobileMessageService();
|
||||
return service.forget();
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "mozilla/Attributes.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class nsISmsService;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class Promise;
|
||||
class DOMRequest;
|
||||
class DOMCursor;
|
||||
class MmsMessage;
|
||||
struct MmsParameters;
|
||||
struct MmsSendParameters;
|
||||
struct MobileMessageFilter;
|
||||
class OwningLongOrSmsMessageOrMmsMessage;
|
||||
class SmsMessage;
|
||||
struct SmsSendParameters;
|
||||
struct SmscAddress;
|
||||
|
||||
class MobileMessageManager final : public DOMEventTargetHelper
|
||||
, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
|
||||
|
||||
explicit MobileMessageManager(nsPIDOMWindowInner* aWindow);
|
||||
|
||||
void Init();
|
||||
void Shutdown();
|
||||
|
||||
nsPIDOMWindowInner*
|
||||
GetParentObject() const { return GetOwner(); }
|
||||
|
||||
// WrapperCache
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) 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<RefPtr<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(SmsMessage& aMessage,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
Delete(MmsMessage& aMessage,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
Delete(const Sequence<OwningLongOrSmsMessageOrMmsMessage>& aParams,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMCursor>
|
||||
GetMessages(const MobileMessageFilter& 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(MmsMessage& aMessage,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
GetSmscAddress(const Optional<uint32_t>& aServiceId,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
SetSmscAddress(const SmscAddress& aSmscAddress,
|
||||
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)
|
||||
IMPL_EVENT_HANDLER(deleted)
|
||||
|
||||
private:
|
||||
~MobileMessageManager() {}
|
||||
|
||||
/**
|
||||
* Internal Send() method used to send one message.
|
||||
*/
|
||||
already_AddRefed<DOMRequest>
|
||||
Send(nsISmsService* aSmsService,
|
||||
uint32_t aServiceId,
|
||||
const nsAString& aNumber,
|
||||
const nsAString& aText,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<DOMRequest>
|
||||
Delete(int32_t* aIdArray,
|
||||
uint32_t aSize,
|
||||
ErrorResult& aRv);
|
||||
|
||||
nsresult
|
||||
DispatchTrustedSmsEventToSelf(const char* aTopic,
|
||||
const nsAString& aEventName,
|
||||
nsISupports* aMsg);
|
||||
|
||||
nsresult
|
||||
DispatchTrustedDeletedEventToSelf(nsISupports* aDeletedInfo);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_MobileMessageManager_h
|
@ -1,129 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "SmsMessageInternal.h"
|
||||
#include "MmsMessageInternal.h"
|
||||
#include "MobileMessageThreadInternal.h"
|
||||
#include "MobileMessageService.h"
|
||||
#include "DeletedMessageInfo.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_ISUPPORTS(MobileMessageService, nsIMobileMessageService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageService::CreateSmsMessage(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
const nsAString& aDelivery,
|
||||
const nsAString& aDeliveryStatus,
|
||||
const nsAString& aSender,
|
||||
const nsAString& aReceiver,
|
||||
const nsAString& aBody,
|
||||
const nsAString& aMessageClass,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
uint64_t aDeliveryTimestamp,
|
||||
bool aRead,
|
||||
JSContext* aCx,
|
||||
nsISmsMessage** aMessage)
|
||||
{
|
||||
return SmsMessageInternal::Create(aId,
|
||||
aThreadId,
|
||||
aIccId,
|
||||
aDelivery,
|
||||
aDeliveryStatus,
|
||||
aSender,
|
||||
aReceiver,
|
||||
aBody,
|
||||
aMessageClass,
|
||||
aTimestamp,
|
||||
aSentTimestamp,
|
||||
aDeliveryTimestamp,
|
||||
aRead,
|
||||
aCx,
|
||||
aMessage);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageService::CreateMmsMessage(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
const nsAString& aDelivery,
|
||||
JS::Handle<JS::Value> aDeliveryInfo,
|
||||
const nsAString& aSender,
|
||||
JS::Handle<JS::Value> aReceivers,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
bool aRead,
|
||||
const nsAString& aSubject,
|
||||
const nsAString& aSmil,
|
||||
JS::Handle<JS::Value> aAttachments,
|
||||
uint64_t aExpiryDate,
|
||||
bool aReadReportRequested,
|
||||
JSContext* aCx,
|
||||
nsIMmsMessage** aMessage)
|
||||
{
|
||||
return MmsMessageInternal::Create(aId,
|
||||
aThreadId,
|
||||
aIccId,
|
||||
aDelivery,
|
||||
aDeliveryInfo,
|
||||
aSender,
|
||||
aReceivers,
|
||||
aTimestamp,
|
||||
aSentTimestamp,
|
||||
aRead,
|
||||
aSubject,
|
||||
aSmil,
|
||||
aAttachments,
|
||||
aExpiryDate,
|
||||
aReadReportRequested,
|
||||
aCx,
|
||||
aMessage);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageService::CreateThread(uint64_t aId,
|
||||
JS::Handle<JS::Value> aParticipants,
|
||||
uint64_t aTimestamp,
|
||||
const nsAString& aLastMessageSubject,
|
||||
const nsAString& aBody,
|
||||
uint64_t aUnreadCount,
|
||||
const nsAString& aLastMessageType,
|
||||
JSContext* aCx,
|
||||
nsIMobileMessageThread** aThread)
|
||||
{
|
||||
return MobileMessageThreadInternal::Create(aId,
|
||||
aParticipants,
|
||||
aTimestamp,
|
||||
aLastMessageSubject,
|
||||
aBody,
|
||||
aUnreadCount,
|
||||
aLastMessageType,
|
||||
aCx,
|
||||
aThread);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageService::CreateDeletedMessageInfo(int32_t* aMessageIds,
|
||||
uint32_t aMsgCount,
|
||||
uint64_t* aThreadIds,
|
||||
uint32_t aThreadCount,
|
||||
nsIDeletedMessageInfo** aDeletedInfo)
|
||||
{
|
||||
return DeletedMessageInfo::Create(aMessageIds,
|
||||
aMsgCount,
|
||||
aThreadIds,
|
||||
aThreadCount,
|
||||
aDeletedInfo);
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,34 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_MobileMessageService_h
|
||||
#define mozilla_dom_mobilemessage_MobileMessageService_h
|
||||
|
||||
#include "mozilla/Attributes.h" // For final
|
||||
#include "nsIMobileMessageService.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class MobileMessageService final : public nsIMobileMessageService
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMOBILEMESSAGESERVICE
|
||||
|
||||
MobileMessageService() { MOZ_COUNT_CTOR(MobileMessageService); }
|
||||
|
||||
private:
|
||||
// final suppresses -Werror,-Wdelete-non-virtual-dtor
|
||||
~MobileMessageService() { MOZ_COUNT_DTOR(MobileMessageService); }
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_MobileMessageService_h
|
@ -1,92 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 "MobileMessageThread.h"
|
||||
|
||||
#include "MobileMessageThreadInternal.h"
|
||||
#include "mozilla/dom/MobileMessageThreadBinding.h"
|
||||
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MobileMessageThread, mWindow, mThread)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(MobileMessageThread)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(MobileMessageThread)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MobileMessageThread)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
MobileMessageThread::MobileMessageThread(nsPIDOMWindowInner* aWindow,
|
||||
MobileMessageThreadInternal* aThread)
|
||||
: mWindow(aWindow)
|
||||
, mThread(aThread)
|
||||
{
|
||||
}
|
||||
|
||||
MobileMessageThread::~MobileMessageThread()
|
||||
{
|
||||
}
|
||||
|
||||
JSObject*
|
||||
MobileMessageThread::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return MobileMessageThreadBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
MobileMessageThread::Id() const
|
||||
{
|
||||
uint64_t id;
|
||||
mThread->GetId(&id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageThread::GetLastMessageSubject(nsString& aRetVal) const
|
||||
{
|
||||
mThread->GetLastMessageSubject(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageThread::GetBody(nsString& aRetVal) const
|
||||
{
|
||||
mThread->GetBody(aRetVal);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
MobileMessageThread::UnreadCount() const
|
||||
{
|
||||
uint64_t count;
|
||||
mThread->GetUnreadCount(&count);
|
||||
return count;
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageThread::GetParticipants(nsTArray<nsString>& aRetVal) const
|
||||
{
|
||||
aRetVal = mThread->mData.participants();
|
||||
}
|
||||
|
||||
DOMTimeStamp
|
||||
MobileMessageThread::Timestamp() const
|
||||
{
|
||||
DOMTimeStamp timestamp;
|
||||
mThread->GetTimestamp(×tamp);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageThread::GetLastMessageType(nsString& aRetVal) const
|
||||
{
|
||||
mThread->GetLastMessageType(aRetVal);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,80 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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_MobileMessageThread_h
|
||||
#define mozilla_dom_MobileMessageThread_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsPIDOMWindowInner;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
namespace mobilemessage {
|
||||
class MobileMessageThreadInternal;
|
||||
} // namespace mobilemessage
|
||||
|
||||
/**
|
||||
* Each instance of this class provides the DOM-level representation of
|
||||
* a MobileMessageThread object to bind it to a window being exposed to.
|
||||
*/
|
||||
class MobileMessageThread final : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MobileMessageThread)
|
||||
|
||||
MobileMessageThread(nsPIDOMWindowInner* aWindow,
|
||||
mobilemessage::MobileMessageThreadInternal* aThread);
|
||||
|
||||
nsPIDOMWindowInner*
|
||||
GetParentObject() const
|
||||
{
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
uint64_t
|
||||
Id() const;
|
||||
|
||||
void
|
||||
GetLastMessageSubject(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetBody(nsString& aRetVal) const;
|
||||
|
||||
uint64_t
|
||||
UnreadCount() const;
|
||||
|
||||
void
|
||||
GetParticipants(nsTArray<nsString>& aRetVal) const;
|
||||
|
||||
DOMTimeStamp
|
||||
Timestamp() const;
|
||||
|
||||
void
|
||||
GetLastMessageType(nsString& aRetVal) const;
|
||||
|
||||
private:
|
||||
// Don't try to use the default constructor.
|
||||
MobileMessageThread() = delete;
|
||||
|
||||
~MobileMessageThread();
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
||||
RefPtr<mobilemessage::MobileMessageThreadInternal> mThread;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_MobileMessageThread_h
|
@ -1,185 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "MobileMessageThreadInternal.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
|
||||
#include "nsJSUtils.h" // For nsAutoJSString
|
||||
#include "nsTArrayHelpers.h" // For nsTArrayToJSArray
|
||||
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_ISUPPORTS(MobileMessageThreadInternal, nsIMobileMessageThread)
|
||||
|
||||
/* static */ nsresult
|
||||
MobileMessageThreadInternal::Create(uint64_t aId,
|
||||
const JS::Value& aParticipants,
|
||||
uint64_t aTimestamp,
|
||||
const nsAString& aLastMessageSubject,
|
||||
const nsAString& aBody,
|
||||
uint64_t aUnreadCount,
|
||||
const nsAString& aLastMessageType,
|
||||
JSContext* aCx,
|
||||
nsIMobileMessageThread** aThread)
|
||||
{
|
||||
*aThread = nullptr;
|
||||
|
||||
// ThreadData exposes these as references, so we can simply assign
|
||||
// to them.
|
||||
ThreadData data;
|
||||
data.id() = aId;
|
||||
data.lastMessageSubject().Assign(aLastMessageSubject);
|
||||
data.body().Assign(aBody);
|
||||
data.unreadCount() = aUnreadCount;
|
||||
|
||||
// Participants.
|
||||
{
|
||||
if (!aParticipants.isObject()) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
JS::Rooted<JSObject*> obj(aCx, &aParticipants.toObject());
|
||||
bool isArray;
|
||||
if (!JS_IsArrayObject(aCx, obj, &isArray)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
if (!isArray) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
uint32_t length;
|
||||
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, obj, &length));
|
||||
NS_ENSURE_TRUE(length, NS_ERROR_INVALID_ARG);
|
||||
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
JS::Rooted<JS::Value> val(aCx);
|
||||
|
||||
if (!JS_GetElement(aCx, obj, i, &val) || !val.isString()) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsAutoJSString str;
|
||||
if (!str.init(aCx, val.toString())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
data.participants().AppendElement(str);
|
||||
}
|
||||
}
|
||||
|
||||
// Set |timestamp|;
|
||||
data.timestamp() = aTimestamp;
|
||||
|
||||
// Set |lastMessageType|.
|
||||
{
|
||||
MessageType lastMessageType;
|
||||
if (aLastMessageType.Equals(MESSAGE_TYPE_SMS)) {
|
||||
lastMessageType = eMessageType_SMS;
|
||||
} else if (aLastMessageType.Equals(MESSAGE_TYPE_MMS)) {
|
||||
lastMessageType = eMessageType_MMS;
|
||||
} else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
data.lastMessageType() = lastMessageType;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMobileMessageThread> thread =
|
||||
new MobileMessageThreadInternal(data);
|
||||
thread.forget(aThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MobileMessageThreadInternal::MobileMessageThreadInternal(uint64_t aId,
|
||||
const nsTArray<nsString>& aParticipants,
|
||||
uint64_t aTimestamp,
|
||||
const nsString& aLastMessageSubject,
|
||||
const nsString& aBody,
|
||||
uint64_t aUnreadCount,
|
||||
MessageType aLastMessageType)
|
||||
: mData(aId, aParticipants, aTimestamp, aLastMessageSubject, aBody,
|
||||
aUnreadCount, aLastMessageType)
|
||||
{
|
||||
MOZ_ASSERT(aParticipants.Length());
|
||||
}
|
||||
|
||||
MobileMessageThreadInternal::MobileMessageThreadInternal(const ThreadData& aData)
|
||||
: mData(aData)
|
||||
{
|
||||
MOZ_ASSERT(aData.participants().Length());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageThreadInternal::GetId(uint64_t* aId)
|
||||
{
|
||||
*aId = mData.id();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageThreadInternal::GetLastMessageSubject(nsAString& aLastMessageSubject)
|
||||
{
|
||||
aLastMessageSubject = mData.lastMessageSubject();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageThreadInternal::GetBody(nsAString& aBody)
|
||||
{
|
||||
aBody = mData.body();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageThreadInternal::GetUnreadCount(uint64_t* aUnreadCount)
|
||||
{
|
||||
*aUnreadCount = mData.unreadCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageThreadInternal::GetParticipants(JSContext* aCx,
|
||||
JS::MutableHandle<JS::Value> aParticipants)
|
||||
{
|
||||
JS::Rooted<JSObject*> obj(aCx);
|
||||
|
||||
nsresult rv = nsTArrayToJSArray(aCx, mData.participants(), &obj);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
aParticipants.setObject(*obj);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageThreadInternal::GetTimestamp(DOMTimeStamp* aDate)
|
||||
{
|
||||
*aDate = mData.timestamp();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageThreadInternal::GetLastMessageType(nsAString& aLastMessageType)
|
||||
{
|
||||
switch (mData.lastMessageType()) {
|
||||
case eMessageType_SMS:
|
||||
aLastMessageType = MESSAGE_TYPE_SMS;
|
||||
break;
|
||||
case eMessageType_MMS:
|
||||
aLastMessageType = MESSAGE_TYPE_MMS;
|
||||
break;
|
||||
case eMessageType_EndGuard:
|
||||
default:
|
||||
MOZ_CRASH("We shouldn't get any other message type!");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,69 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_MobileMessageThreadInternal_h
|
||||
#define mozilla_dom_mobilemessage_MobileMessageThreadInternal_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/mobilemessage/SmsTypes.h"
|
||||
#include "nsIMobileMessageThread.h"
|
||||
#include "nsString.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class MobileMessageThread;
|
||||
|
||||
namespace mobilemessage {
|
||||
|
||||
class ThreadData;
|
||||
|
||||
class MobileMessageThreadInternal final : public nsIMobileMessageThread
|
||||
{
|
||||
// This allows the MobileMessageThread class to access data members, i.e. participants
|
||||
// without JS API.
|
||||
friend class mozilla::dom::MobileMessageThread;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMOBILEMESSAGETHREAD
|
||||
|
||||
MobileMessageThreadInternal(uint64_t aId,
|
||||
const nsTArray<nsString>& aParticipants,
|
||||
uint64_t aTimestamp,
|
||||
const nsString& aLastMessageSubject,
|
||||
const nsString& aBody,
|
||||
uint64_t aUnreadCount,
|
||||
mobilemessage::MessageType aLastMessageType);
|
||||
|
||||
explicit MobileMessageThreadInternal(const ThreadData& aData);
|
||||
|
||||
static nsresult Create(uint64_t aId,
|
||||
const JS::Value& aParticipants,
|
||||
uint64_t aTimestamp,
|
||||
const nsAString& aLastMessageSubject,
|
||||
const nsAString& aBody,
|
||||
uint64_t aUnreadCount,
|
||||
const nsAString& aLastMessageType,
|
||||
JSContext* aCx,
|
||||
nsIMobileMessageThread** aThread);
|
||||
|
||||
const ThreadData& GetData() const { return mData; }
|
||||
|
||||
private:
|
||||
~MobileMessageThreadInternal() {}
|
||||
|
||||
// Don't try to use the default constructor.
|
||||
MobileMessageThreadInternal() = delete;
|
||||
|
||||
ThreadData mData;
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_MobileMessageThreadInternal_h
|
@ -1,136 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 "SmsMessage.h"
|
||||
|
||||
#include "SmsMessageInternal.h"
|
||||
#include "mozilla/dom/SmsMessageBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SmsMessage, mWindow, mMessage)
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(SmsMessage)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(SmsMessage)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SmsMessage)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
SmsMessage::SmsMessage(nsPIDOMWindowInner* aWindow, SmsMessageInternal* aMessage)
|
||||
: mWindow(aWindow)
|
||||
, mMessage(aMessage)
|
||||
{
|
||||
}
|
||||
|
||||
SmsMessage::~SmsMessage()
|
||||
{
|
||||
}
|
||||
|
||||
JSObject*
|
||||
SmsMessage::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return SmsMessageBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetType(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetType(aRetVal);
|
||||
}
|
||||
|
||||
int32_t
|
||||
SmsMessage::Id() const
|
||||
{
|
||||
int32_t id;
|
||||
mMessage->GetId(&id);
|
||||
return id;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
SmsMessage::ThreadId() const
|
||||
{
|
||||
uint64_t id;
|
||||
mMessage->GetThreadId(&id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetIccId(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetIccId(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetDelivery(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetDelivery(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetDeliveryStatus(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetDeliveryStatus(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetSender(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetSender(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetReceiver(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetReceiver(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetBody(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetBody(aRetVal);
|
||||
}
|
||||
|
||||
void
|
||||
SmsMessage::GetMessageClass(nsString& aRetVal) const
|
||||
{
|
||||
mMessage->GetMessageClass(aRetVal);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
SmsMessage::Timestamp() const
|
||||
{
|
||||
uint64_t timestamp;
|
||||
mMessage->GetTimestamp(×tamp);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
SmsMessage::SentTimestamp() const
|
||||
{
|
||||
uint64_t timestamp;
|
||||
mMessage->GetSentTimestamp(×tamp);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
SmsMessage::DeliveryTimestamp() const
|
||||
{
|
||||
uint64_t timestamp;
|
||||
mMessage->GetDeliveryTimestamp(×tamp);
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsMessage::Read() const
|
||||
{
|
||||
bool read;
|
||||
mMessage->GetRead(&read);
|
||||
return read;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,102 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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_SmsMessage_h
|
||||
#define mozilla_dom_SmsMessage_h
|
||||
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsPIDOMWindowInner;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
namespace mobilemessage {
|
||||
class SmsMessageInternal;
|
||||
} // namespace mobilemessage
|
||||
|
||||
/**
|
||||
* Each instance of this class provides the DOM-level representation of
|
||||
* a SmsMessage object to bind it to a window being exposed to.
|
||||
*/
|
||||
class SmsMessage final : public nsISupports,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SmsMessage)
|
||||
|
||||
SmsMessage(nsPIDOMWindowInner* aWindow,
|
||||
mobilemessage::SmsMessageInternal* aMessage);
|
||||
|
||||
public:
|
||||
nsPIDOMWindowInner*
|
||||
GetParentObject() const
|
||||
{
|
||||
return mWindow;
|
||||
}
|
||||
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
void
|
||||
GetType(nsString& aRetVal) const;
|
||||
|
||||
int32_t
|
||||
Id() const;
|
||||
|
||||
uint64_t
|
||||
ThreadId() const;
|
||||
|
||||
void
|
||||
GetIccId(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetDelivery(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetDeliveryStatus(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetSender(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetReceiver(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetBody(nsString& aRetVal) const;
|
||||
|
||||
void
|
||||
GetMessageClass(nsString& aRetVal) const;
|
||||
|
||||
uint64_t
|
||||
Timestamp() const;
|
||||
|
||||
uint64_t
|
||||
SentTimestamp() const;
|
||||
|
||||
uint64_t
|
||||
DeliveryTimestamp() const;
|
||||
|
||||
bool
|
||||
Read() const;
|
||||
|
||||
private:
|
||||
// Don't try to use the default constructor.
|
||||
SmsMessage() = delete;
|
||||
|
||||
~SmsMessage();
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
||||
RefPtr<mobilemessage::SmsMessageInternal> mMessage;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_SmsMessage_h
|
@ -1,283 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "SmsMessageInternal.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_ISUPPORTS(SmsMessageInternal, nsISmsMessage)
|
||||
|
||||
SmsMessageInternal::SmsMessageInternal(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsString& aIccId,
|
||||
DeliveryState aDelivery,
|
||||
DeliveryStatus aDeliveryStatus,
|
||||
const nsString& aSender,
|
||||
const nsString& aReceiver,
|
||||
const nsString& aBody,
|
||||
MessageClass aMessageClass,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
uint64_t aDeliveryTimestamp,
|
||||
bool aRead)
|
||||
: mData(aId, aThreadId, aIccId, aDelivery, aDeliveryStatus,
|
||||
aSender, aReceiver, aBody, aMessageClass, aTimestamp, aSentTimestamp,
|
||||
aDeliveryTimestamp, aRead)
|
||||
{
|
||||
}
|
||||
|
||||
SmsMessageInternal::SmsMessageInternal(const SmsMessageData& aData)
|
||||
: mData(aData)
|
||||
{
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
SmsMessageInternal::Create(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
const nsAString& aDelivery,
|
||||
const nsAString& aDeliveryStatus,
|
||||
const nsAString& aSender,
|
||||
const nsAString& aReceiver,
|
||||
const nsAString& aBody,
|
||||
const nsAString& aMessageClass,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
uint64_t aDeliveryTimestamp,
|
||||
bool aRead,
|
||||
JSContext* aCx,
|
||||
nsISmsMessage** aMessage)
|
||||
{
|
||||
*aMessage = nullptr;
|
||||
|
||||
// SmsMessageData exposes these as references, so we can simply assign
|
||||
// to them.
|
||||
SmsMessageData data;
|
||||
data.id() = aId;
|
||||
data.threadId() = aThreadId;
|
||||
data.iccId() = nsString(aIccId);
|
||||
data.sender() = nsString(aSender);
|
||||
data.receiver() = nsString(aReceiver);
|
||||
data.body() = nsString(aBody);
|
||||
data.read() = aRead;
|
||||
|
||||
if (aDelivery.Equals(DELIVERY_RECEIVED)) {
|
||||
data.delivery() = eDeliveryState_Received;
|
||||
} else if (aDelivery.Equals(DELIVERY_SENDING)) {
|
||||
data.delivery() = eDeliveryState_Sending;
|
||||
} else if (aDelivery.Equals(DELIVERY_SENT)) {
|
||||
data.delivery() = eDeliveryState_Sent;
|
||||
} else if (aDelivery.Equals(DELIVERY_ERROR)) {
|
||||
data.delivery() = eDeliveryState_Error;
|
||||
} else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (aDeliveryStatus.Equals(DELIVERY_STATUS_NOT_APPLICABLE)) {
|
||||
data.deliveryStatus() = eDeliveryStatus_NotApplicable;
|
||||
} else if (aDeliveryStatus.Equals(DELIVERY_STATUS_SUCCESS)) {
|
||||
data.deliveryStatus() = eDeliveryStatus_Success;
|
||||
} else if (aDeliveryStatus.Equals(DELIVERY_STATUS_PENDING)) {
|
||||
data.deliveryStatus() = eDeliveryStatus_Pending;
|
||||
} else if (aDeliveryStatus.Equals(DELIVERY_STATUS_ERROR)) {
|
||||
data.deliveryStatus() = eDeliveryStatus_Error;
|
||||
} else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (aMessageClass.Equals(MESSAGE_CLASS_NORMAL)) {
|
||||
data.messageClass() = eMessageClass_Normal;
|
||||
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_0)) {
|
||||
data.messageClass() = eMessageClass_Class0;
|
||||
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_1)) {
|
||||
data.messageClass() = eMessageClass_Class1;
|
||||
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_2)) {
|
||||
data.messageClass() = eMessageClass_Class2;
|
||||
} else if (aMessageClass.Equals(MESSAGE_CLASS_CLASS_3)) {
|
||||
data.messageClass() = eMessageClass_Class3;
|
||||
} else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Set |timestamp|.
|
||||
data.timestamp() = aTimestamp;
|
||||
|
||||
// Set |sentTimestamp|.
|
||||
data.sentTimestamp() = aSentTimestamp;
|
||||
|
||||
// Set |deliveryTimestamp|.
|
||||
data.deliveryTimestamp() = aDeliveryTimestamp;
|
||||
|
||||
nsCOMPtr<nsISmsMessage> message = new SmsMessageInternal(data);
|
||||
message.swap(*aMessage);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const SmsMessageData&
|
||||
SmsMessageInternal::GetData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetType(nsAString& aType)
|
||||
{
|
||||
aType = NS_LITERAL_STRING("sms");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetId(int32_t* aId)
|
||||
{
|
||||
*aId = mData.id();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetThreadId(uint64_t* aThreadId)
|
||||
{
|
||||
*aThreadId = mData.threadId();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetIccId(nsAString& aIccId)
|
||||
{
|
||||
aIccId = mData.iccId();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetDelivery(nsAString& aDelivery)
|
||||
{
|
||||
switch (mData.delivery()) {
|
||||
case eDeliveryState_Received:
|
||||
aDelivery = DELIVERY_RECEIVED;
|
||||
break;
|
||||
case eDeliveryState_Sending:
|
||||
aDelivery = DELIVERY_SENDING;
|
||||
break;
|
||||
case eDeliveryState_Sent:
|
||||
aDelivery = DELIVERY_SENT;
|
||||
break;
|
||||
case eDeliveryState_Error:
|
||||
aDelivery = DELIVERY_ERROR;
|
||||
break;
|
||||
case eDeliveryState_Unknown:
|
||||
case eDeliveryState_EndGuard:
|
||||
default:
|
||||
MOZ_CRASH("We shouldn't get any other delivery state!");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetDeliveryStatus(nsAString& aDeliveryStatus)
|
||||
{
|
||||
switch (mData.deliveryStatus()) {
|
||||
case eDeliveryStatus_NotApplicable:
|
||||
aDeliveryStatus = DELIVERY_STATUS_NOT_APPLICABLE;
|
||||
break;
|
||||
case eDeliveryStatus_Success:
|
||||
aDeliveryStatus = DELIVERY_STATUS_SUCCESS;
|
||||
break;
|
||||
case eDeliveryStatus_Pending:
|
||||
aDeliveryStatus = DELIVERY_STATUS_PENDING;
|
||||
break;
|
||||
case eDeliveryStatus_Error:
|
||||
aDeliveryStatus = DELIVERY_STATUS_ERROR;
|
||||
break;
|
||||
case eDeliveryStatus_EndGuard:
|
||||
default:
|
||||
MOZ_CRASH("We shouldn't get any other delivery status!");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetSender(nsAString& aSender)
|
||||
{
|
||||
aSender = mData.sender();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetReceiver(nsAString& aReceiver)
|
||||
{
|
||||
aReceiver = mData.receiver();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetBody(nsAString& aBody)
|
||||
{
|
||||
aBody = mData.body();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetMessageClass(nsAString& aMessageClass)
|
||||
{
|
||||
switch (mData.messageClass()) {
|
||||
case eMessageClass_Normal:
|
||||
aMessageClass = MESSAGE_CLASS_NORMAL;
|
||||
break;
|
||||
case eMessageClass_Class0:
|
||||
aMessageClass = MESSAGE_CLASS_CLASS_0;
|
||||
break;
|
||||
case eMessageClass_Class1:
|
||||
aMessageClass = MESSAGE_CLASS_CLASS_1;
|
||||
break;
|
||||
case eMessageClass_Class2:
|
||||
aMessageClass = MESSAGE_CLASS_CLASS_2;
|
||||
break;
|
||||
case eMessageClass_Class3:
|
||||
aMessageClass = MESSAGE_CLASS_CLASS_3;
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("We shouldn't get any other message class!");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetTimestamp(DOMTimeStamp* aTimestamp)
|
||||
{
|
||||
*aTimestamp = mData.timestamp();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetSentTimestamp(DOMTimeStamp* aSentTimestamp)
|
||||
{
|
||||
*aSentTimestamp = mData.sentTimestamp();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetDeliveryTimestamp(DOMTimeStamp* aDate)
|
||||
{
|
||||
*aDate = mData.deliveryTimestamp();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsMessageInternal::GetRead(bool* aRead)
|
||||
{
|
||||
*aRead = mData.read();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,74 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_SmsMessageInternal_h
|
||||
#define mozilla_dom_mobilemessage_SmsMessageInternal_h
|
||||
|
||||
#include "mozilla/dom/mobilemessage/SmsTypes.h"
|
||||
#include "nsISmsMessage.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/dom/mobilemessage/Types.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class SmsMessageData;
|
||||
|
||||
class SmsMessageInternal final : public nsISmsMessage
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISMSMESSAGE
|
||||
|
||||
SmsMessageInternal(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsString& aIccId,
|
||||
mobilemessage::DeliveryState aDelivery,
|
||||
mobilemessage::DeliveryStatus aDeliveryStatus,
|
||||
const nsString& aSender,
|
||||
const nsString& aReceiver,
|
||||
const nsString& aBody,
|
||||
mobilemessage::MessageClass aMessageClass,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
uint64_t aDeliveryTimestamp,
|
||||
bool aRead);
|
||||
|
||||
explicit SmsMessageInternal(const SmsMessageData& aData);
|
||||
|
||||
static nsresult Create(int32_t aId,
|
||||
uint64_t aThreadId,
|
||||
const nsAString& aIccId,
|
||||
const nsAString& aDelivery,
|
||||
const nsAString& aDeliveryStatus,
|
||||
const nsAString& aSender,
|
||||
const nsAString& aReceiver,
|
||||
const nsAString& aBody,
|
||||
const nsAString& aMessageClass,
|
||||
uint64_t aTimestamp,
|
||||
uint64_t aSentTimestamp,
|
||||
uint64_t aDeliveryTimestamp,
|
||||
bool aRead,
|
||||
JSContext* aCx,
|
||||
nsISmsMessage** aMessage);
|
||||
const SmsMessageData& GetData() const;
|
||||
|
||||
private:
|
||||
~SmsMessageInternal() {}
|
||||
|
||||
// Don't try to use the default constructor.
|
||||
SmsMessageInternal();
|
||||
|
||||
SmsMessageData mData;
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_SmsMessageInternal_h
|
@ -1,134 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_Types_h
|
||||
#define mozilla_dom_mobilemessage_Types_h
|
||||
|
||||
#include "IPCMessageUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
// For MmsMessageData.state and SmsMessageData.deliveryState
|
||||
// Please keep the following files in sync with enum below:
|
||||
// mobile/android/base/GeckoSmsManager.java
|
||||
enum DeliveryState {
|
||||
eDeliveryState_Sent = 0,
|
||||
eDeliveryState_Received,
|
||||
eDeliveryState_Sending,
|
||||
eDeliveryState_Error,
|
||||
eDeliveryState_Unknown,
|
||||
eDeliveryState_NotDownloaded,
|
||||
// This state should stay at the end.
|
||||
eDeliveryState_EndGuard
|
||||
};
|
||||
|
||||
// For {Mms,Sms}MessageData.deliveryStatus.
|
||||
enum DeliveryStatus {
|
||||
eDeliveryStatus_NotApplicable = 0,
|
||||
eDeliveryStatus_Success,
|
||||
eDeliveryStatus_Pending,
|
||||
eDeliveryStatus_Error,
|
||||
eDeliveryStatus_Reject,
|
||||
eDeliveryStatus_Manual,
|
||||
// This state should stay at the end.
|
||||
eDeliveryStatus_EndGuard
|
||||
};
|
||||
|
||||
// For MmsMessageData.readStatus.
|
||||
enum ReadStatus {
|
||||
eReadStatus_NotApplicable = 0,
|
||||
eReadStatus_Success,
|
||||
eReadStatus_Pending,
|
||||
eReadStatus_Error,
|
||||
// This state should stay at the end.
|
||||
eReadStatus_EndGuard
|
||||
};
|
||||
|
||||
// For {Mms,Sms}MessageData.messageClass.
|
||||
enum MessageClass {
|
||||
eMessageClass_Normal = 0,
|
||||
eMessageClass_Class0,
|
||||
eMessageClass_Class1,
|
||||
eMessageClass_Class2,
|
||||
eMessageClass_Class3,
|
||||
// This state should stay at the end.
|
||||
eMessageClass_EndGuard
|
||||
};
|
||||
|
||||
// For ThreadData.
|
||||
enum MessageType {
|
||||
eMessageType_SMS = 0,
|
||||
eMessageType_MMS,
|
||||
// This state should stay at the end.
|
||||
eMessageType_EndGuard
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
namespace IPC {
|
||||
|
||||
/**
|
||||
* Delivery state serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::mobilemessage::DeliveryState>
|
||||
: public ContiguousEnumSerializer<
|
||||
mozilla::dom::mobilemessage::DeliveryState,
|
||||
mozilla::dom::mobilemessage::eDeliveryState_Sent,
|
||||
mozilla::dom::mobilemessage::eDeliveryState_EndGuard>
|
||||
{};
|
||||
|
||||
/**
|
||||
* Delivery status serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::mobilemessage::DeliveryStatus>
|
||||
: public ContiguousEnumSerializer<
|
||||
mozilla::dom::mobilemessage::DeliveryStatus,
|
||||
mozilla::dom::mobilemessage::eDeliveryStatus_NotApplicable,
|
||||
mozilla::dom::mobilemessage::eDeliveryStatus_EndGuard>
|
||||
{};
|
||||
|
||||
/**
|
||||
* Read status serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::mobilemessage::ReadStatus>
|
||||
: public ContiguousEnumSerializer<
|
||||
mozilla::dom::mobilemessage::ReadStatus,
|
||||
mozilla::dom::mobilemessage::eReadStatus_NotApplicable,
|
||||
mozilla::dom::mobilemessage::eReadStatus_EndGuard>
|
||||
{};
|
||||
|
||||
/**
|
||||
* Message class serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::mobilemessage::MessageClass>
|
||||
: public ContiguousEnumSerializer<
|
||||
mozilla::dom::mobilemessage::MessageClass,
|
||||
mozilla::dom::mobilemessage::eMessageClass_Normal,
|
||||
mozilla::dom::mobilemessage::eMessageClass_EndGuard>
|
||||
{};
|
||||
|
||||
/**
|
||||
* MessageType class serializer.
|
||||
*/
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::mobilemessage::MessageType>
|
||||
: public ContiguousEnumSerializer<
|
||||
mozilla::dom::mobilemessage::MessageType,
|
||||
mozilla::dom::mobilemessage::eMessageType_SMS,
|
||||
mozilla::dom::mobilemessage::eMessageType_EndGuard>
|
||||
{};
|
||||
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_Types_h
|
@ -1,129 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "MobileMessageDatabaseService.h"
|
||||
|
||||
#include "AndroidBridge.h"
|
||||
#include "SmsManager.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_ISUPPORTS(MobileMessageDatabaseService, nsIMobileMessageDatabaseService)
|
||||
|
||||
MobileMessageDatabaseService::MobileMessageDatabaseService()
|
||||
{
|
||||
SmsManager::Init();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageDatabaseService::GetMessageMoz(int32_t aMessageId,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
AndroidBridge::Bridge()->GetMessage(aMessageId, aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageDatabaseService::DeleteMessage(int32_t *aMessageIds,
|
||||
uint32_t aLength,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!aMessageIds) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aLength != 1) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
AndroidBridge::Bridge()->DeleteMessage(aMessageIds[0], aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageDatabaseService::CreateMessageCursor(bool aHasStartDate,
|
||||
uint64_t aStartDate,
|
||||
bool aHasEndDate,
|
||||
uint64_t aEndDate,
|
||||
const char16_t** aNumbers,
|
||||
uint32_t aNumbersCount,
|
||||
const nsAString& aDelivery,
|
||||
bool aHasRead,
|
||||
bool aRead,
|
||||
bool aHasThreadId,
|
||||
uint64_t aThreadId,
|
||||
bool aReverse,
|
||||
nsIMobileMessageCursorCallback* aCallback,
|
||||
nsICursorContinueCallback** aCursor)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
*aCursor = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICursorContinueCallback> cursor =
|
||||
AndroidBridge::Bridge()->CreateMessageCursor(aHasStartDate,
|
||||
aStartDate,
|
||||
aHasEndDate,
|
||||
aEndDate,
|
||||
aNumbers,
|
||||
aNumbersCount,
|
||||
aDelivery,
|
||||
aHasRead,
|
||||
aRead,
|
||||
aHasThreadId,
|
||||
aThreadId,
|
||||
aReverse,
|
||||
aCallback);
|
||||
cursor.forget(aCursor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageDatabaseService::MarkMessageRead(int32_t aMessageId,
|
||||
bool aValue,
|
||||
bool aSendReadReport,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
AndroidBridge::Bridge()->MarkMessageRead(aMessageId,
|
||||
aValue,
|
||||
aSendReadReport,
|
||||
aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageDatabaseService::CreateThreadCursor(nsIMobileMessageCursorCallback* aRequest,
|
||||
nsICursorContinueCallback** aCursor)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
*aCursor = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICursorContinueCallback> cursor =
|
||||
AndroidBridge::Bridge()->CreateThreadCursor(aRequest);
|
||||
cursor.forget(aCursor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,33 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_MobileMessageDatabaseService_h
|
||||
#define mozilla_dom_mobilemessage_MobileMessageDatabaseService_h
|
||||
|
||||
#include "nsIMobileMessageDatabaseService.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class MobileMessageDatabaseService final : public nsIMobileMessageDatabaseService
|
||||
{
|
||||
private:
|
||||
~MobileMessageDatabaseService() {}
|
||||
|
||||
public:
|
||||
MobileMessageDatabaseService();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMOBILEMESSAGEDATABASESERVICE
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_MobileMessageDatabaseService_h
|
@ -1,391 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* 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 "SmsManager.h"
|
||||
|
||||
#include "mozilla/dom/mobilemessage/Constants.h"
|
||||
#include "mozilla/dom/mobilemessage/PSms.h"
|
||||
#include "mozilla/dom/mobilemessage/SmsParent.h"
|
||||
#include "mozilla/dom/mobilemessage/SmsTypes.h"
|
||||
#include "mozilla/dom/mobilemessage/Types.h"
|
||||
#include "MobileMessageThreadInternal.h"
|
||||
#include "SmsMessageInternal.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsIMobileMessageDatabaseService.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "AndroidJavaWrappers.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsReceived(int32_t aId,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int32_t aMessageClass,
|
||||
int64_t aSentTimestamp,
|
||||
int64_t aTimestamp)
|
||||
{
|
||||
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
||||
SmsMessageData message;
|
||||
message.id() = aId;
|
||||
message.threadId() = 0;
|
||||
message.iccId() = EmptyString();
|
||||
message.delivery() = eDeliveryState_Received;
|
||||
message.deliveryStatus() = eDeliveryStatus_Success;
|
||||
message.sender() = aSender ? aSender->ToString() : EmptyString();
|
||||
message.receiver() = EmptyString();
|
||||
message.body() = aBody ? aBody->ToString() : EmptyString();
|
||||
message.messageClass() = static_cast<MessageClass>(aMessageClass);
|
||||
message.timestamp() = aTimestamp;
|
||||
message.sentTimestamp() = aSentTimestamp;
|
||||
message.deliveryTimestamp() = aTimestamp;
|
||||
message.read() = false;
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
|
||||
obs->NotifyObservers(domMessage, kSmsReceivedObserverTopic, nullptr);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsSent(int32_t aId,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp,
|
||||
int32_t aRequestId)
|
||||
{
|
||||
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
||||
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
||||
SmsMessageData message;
|
||||
message.id() = aId;
|
||||
message.threadId() = 0;
|
||||
message.iccId() = EmptyString();
|
||||
message.delivery() = eDeliveryState_Sent;
|
||||
message.deliveryStatus() = eDeliveryStatus_Pending;
|
||||
message.sender() = EmptyString();
|
||||
message.receiver() = aReceiver ? aReceiver->ToString() : EmptyString();
|
||||
message.body() = aBody ? aBody->ToString() : EmptyString();
|
||||
message.messageClass() = eMessageClass_Normal;
|
||||
message.timestamp() = aTimestamp;
|
||||
message.sentTimestamp() = aTimestamp;
|
||||
message.deliveryTimestamp() = aTimestamp;
|
||||
message.read() = true;
|
||||
|
||||
/*
|
||||
* First, we are going to notify all SmsManager that a message has
|
||||
* been sent. Then, we will notify the SmsRequest object about it.
|
||||
*/
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
|
||||
obs->NotifyObservers(domMessage, kSmsSentObserverTopic, nullptr);
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifyMessageSent(domMessage);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsDelivery(int32_t aId,
|
||||
int32_t aDeliveryStatus,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp)
|
||||
{
|
||||
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
||||
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
||||
SmsMessageData message;
|
||||
message.id() = aId;
|
||||
message.threadId() = 0;
|
||||
message.iccId() = EmptyString();
|
||||
message.delivery() = eDeliveryState_Sent;
|
||||
message.deliveryStatus() = static_cast<DeliveryStatus>(aDeliveryStatus);
|
||||
message.sender() = EmptyString();
|
||||
message.receiver() = aReceiver ? aReceiver->ToString() : EmptyString();
|
||||
message.body() = aBody ? aBody->ToString() : EmptyString();
|
||||
message.messageClass() = eMessageClass_Normal;
|
||||
message.timestamp() = aTimestamp;
|
||||
message.sentTimestamp() = aTimestamp;
|
||||
message.deliveryTimestamp() = aTimestamp;
|
||||
message.read() = true;
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
|
||||
const char* topic = (message.deliveryStatus() == eDeliveryStatus_Success)
|
||||
? kSmsDeliverySuccessObserverTopic
|
||||
: kSmsDeliveryErrorObserverTopic;
|
||||
obs->NotifyObservers(domMessage, topic, nullptr);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsSendFailed(int32_t aError, int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if(!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifySendMessageFailed(aError, nullptr);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifyGetSms(int32_t aId,
|
||||
int32_t aDeliveryStatus,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp,
|
||||
bool aRead,
|
||||
int32_t aRequestId)
|
||||
{
|
||||
nsString receiver(aReceiver->ToString());
|
||||
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
||||
: eDeliveryState_Sent;
|
||||
|
||||
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
||||
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
||||
SmsMessageData message;
|
||||
message.id() = aId;
|
||||
message.threadId() = 0;
|
||||
message.iccId() = EmptyString();
|
||||
message.delivery() = state;
|
||||
message.deliveryStatus() = static_cast<DeliveryStatus>(aDeliveryStatus);
|
||||
message.sender() = aSender ? aSender->ToString() : EmptyString();
|
||||
message.receiver() = receiver;
|
||||
message.body() = aBody ? aBody->ToString() : EmptyString();
|
||||
message.messageClass() = eMessageClass_Normal;
|
||||
message.timestamp() = aTimestamp;
|
||||
message.sentTimestamp() = aTimestamp;
|
||||
message.deliveryTimestamp() = aTimestamp;
|
||||
message.read() = aRead;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
|
||||
request->NotifyMessageGot(domMessage);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifyGetSmsFailed(int32_t aError, int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifyGetMessageFailed(aError);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsDeleted(bool aDeleted, int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
// For android, we support only single SMS deletion.
|
||||
bool deleted = aDeleted;
|
||||
request->NotifyMessageDeleted(&deleted, 1);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsDeleteFailed(int32_t aError, int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifyDeleteMessageFailed(aError);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifyCursorError(int32_t aError, int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCursorCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsCursorRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifyCursorError(aError);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifyThreadCursorResult(int64_t aId,
|
||||
jni::String::Param aLastMessageSubject,
|
||||
jni::String::Param aBody,
|
||||
int64_t aUnreadCount,
|
||||
jni::ObjectArray::Param aParticipants,
|
||||
int64_t aTimestamp,
|
||||
jni::String::Param aLastMessageType,
|
||||
int32_t aRequestId)
|
||||
{
|
||||
ThreadData thread;
|
||||
thread.id() = aId;
|
||||
thread.lastMessageSubject() = aLastMessageSubject ?
|
||||
aLastMessageSubject->ToString() :
|
||||
EmptyString();
|
||||
thread.body() = aBody ? aBody->ToString() : EmptyString();
|
||||
thread.unreadCount() = aUnreadCount;
|
||||
thread.timestamp() = aTimestamp;
|
||||
thread.lastMessageType() = eMessageType_SMS;
|
||||
|
||||
JNIEnv* const env = jni::GetGeckoThreadEnv();
|
||||
|
||||
jobjectArray participants = aParticipants.Get();
|
||||
jsize length = env->GetArrayLength(participants);
|
||||
for (jsize i = 0; i < length; ++i) {
|
||||
jstring participant =
|
||||
static_cast<jstring>(env->GetObjectArrayElement(participants, i));
|
||||
if (participant) {
|
||||
thread.participants().AppendElement(nsJNIString(participant, env));
|
||||
env->DeleteLocalRef(participant);
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCursorCallback> request =
|
||||
AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMArray<nsIMobileMessageThread> arr;
|
||||
arr.AppendElement(new MobileMessageThreadInternal(thread));
|
||||
|
||||
nsIMobileMessageThread** elements;
|
||||
int32_t size;
|
||||
size = arr.Forget(&elements);
|
||||
|
||||
request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
|
||||
size);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifyMessageCursorResult(int32_t aMessageId,
|
||||
int32_t aDeliveryStatus,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp,
|
||||
int64_t aThreadId,
|
||||
bool aRead,
|
||||
int32_t aRequestId)
|
||||
{
|
||||
nsString receiver = aReceiver->ToString();
|
||||
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
||||
: eDeliveryState_Sent;
|
||||
|
||||
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
||||
SmsMessageData message;
|
||||
message.id() = aMessageId;
|
||||
message.threadId() = aThreadId;
|
||||
message.iccId() = EmptyString();
|
||||
message.delivery() = state;
|
||||
message.deliveryStatus() = static_cast<DeliveryStatus>(aDeliveryStatus);
|
||||
message.sender() = aSender ? aSender->ToString() : EmptyString();
|
||||
message.receiver() = receiver;
|
||||
message.body() = aBody ? aBody->ToString() : EmptyString();
|
||||
message.messageClass() = eMessageClass_Normal;
|
||||
message.timestamp() = aTimestamp;
|
||||
message.sentTimestamp() = aTimestamp;
|
||||
message.deliveryTimestamp() = aTimestamp;
|
||||
message.read() = aRead;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCursorCallback> request =
|
||||
AndroidBridge::Bridge()->GetSmsCursorRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMArray<nsISmsMessage> arr;
|
||||
arr.AppendElement(new SmsMessageInternal(message));
|
||||
|
||||
nsISmsMessage** elements;
|
||||
int32_t size;
|
||||
size = arr.Forget(&elements);
|
||||
|
||||
request->NotifyCursorResult(reinterpret_cast<nsISupports**>(elements),
|
||||
size);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifyCursorDone(int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCursorCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsCursorRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifyCursorDone();
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsMarkedAsRead(bool aMarkedAsRead, int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifyMessageMarkedRead(aMarkedAsRead);
|
||||
}
|
||||
|
||||
/*static*/
|
||||
void
|
||||
SmsManager::NotifySmsMarkAsReadFailed(int32_t aError, int32_t aRequestId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageCallback> request =
|
||||
AndroidBridge::Bridge()->DequeueSmsRequest(aRequestId);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
|
||||
request->NotifyMarkMessageReadFailed(aError);
|
||||
}
|
||||
|
||||
} // namespace
|
@ -1,77 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* 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 SmsManager_h__
|
||||
#define SmsManager_h__
|
||||
|
||||
#include "GeneratedJNINatives.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class SmsManager : public java::GeckoSmsManager::Natives<SmsManager>
|
||||
{
|
||||
private:
|
||||
SmsManager();
|
||||
|
||||
public:
|
||||
static void NotifySmsReceived(int32_t aId,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int32_t aMessageClass,
|
||||
int64_t aSentTimestamp,
|
||||
int64_t aTimestamp);
|
||||
static void NotifySmsSent(int32_t aId,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp,
|
||||
int32_t aRequestId);
|
||||
static void NotifySmsDelivery(int32_t aId,
|
||||
int32_t aDeliveryStatus,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp);
|
||||
static void NotifySmsSendFailed(int32_t aError,
|
||||
int32_t aRequestId);
|
||||
static void NotifyGetSms(int32_t aId,
|
||||
int32_t aDeliveryStatus,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp,
|
||||
bool aRead,
|
||||
int32_t aRequestId);
|
||||
static void NotifyGetSmsFailed(int32_t aError,
|
||||
int32_t aRequestId);
|
||||
static void NotifySmsDeleted(bool aDeleted,
|
||||
int32_t aRequestId);
|
||||
static void NotifySmsDeleteFailed(int32_t aError,
|
||||
int32_t aRequestId);
|
||||
static void NotifyCursorError(int32_t aError,
|
||||
int32_t aRequestId);
|
||||
static void NotifyThreadCursorResult(int64_t aId,
|
||||
jni::String::Param aLastMessageSubject,
|
||||
jni::String::Param aBody,
|
||||
int64_t aUnreadCount,
|
||||
jni::ObjectArray::Param aParticipants,
|
||||
int64_t aTimestamp,
|
||||
jni::String::Param aLastMessageType,
|
||||
int32_t aRequestId);
|
||||
static void NotifyMessageCursorResult(int32_t aMessageId,
|
||||
int32_t aDeliveryStatus,
|
||||
jni::String::Param aReceiver,
|
||||
jni::String::Param aSender,
|
||||
jni::String::Param aBody,
|
||||
int64_t aTimestamp,
|
||||
int64_t aThreadId,
|
||||
bool aRead,
|
||||
int32_t aRequestId);
|
||||
static void NotifyCursorDone(int32_t aRequestId);
|
||||
static void NotifySmsMarkedAsRead(bool aMarkedAsRead, int32_t aRequestId);
|
||||
static void NotifySmsMarkAsReadFailed(int32_t aError, int32_t aRequestId);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif // SmsManager_h__
|
@ -1,90 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "SmsService.h"
|
||||
#include "AndroidBridge.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
NS_IMPL_ISUPPORTS(SmsService, nsISmsService)
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::GetSmsDefaultServiceId(uint32_t* aServiceId)
|
||||
{
|
||||
// Android has no official DSDS support.
|
||||
*aServiceId = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::GetSegmentInfoForText(const nsAString& aText,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult rv = AndroidBridge::Bridge()->GetSegmentInfoForText(aText, aRequest);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::Send(uint32_t aServiceId,
|
||||
const nsAString& aNumber,
|
||||
const nsAString& aMessage,
|
||||
bool aSilent,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
if (!AndroidBridge::Bridge()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
AndroidBridge::Bridge()->SendMessage(aNumber, aMessage, aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::AddSilentNumber(const nsAString& aNumber)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("Implement me!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::RemoveSilentNumber(const nsAString& aNumber)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("Implement me!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::GetSmscAddress(uint32_t aServiceId,
|
||||
nsIMobileMessageCallback *aRequest)
|
||||
{
|
||||
// TODO: bug 878016 - Android backend: implement getSMSCAddress/setSMSCAddress
|
||||
NS_NOTYETIMPLEMENTED("Implement me!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsService::SetSmscAddress(uint32_t aServiceId,
|
||||
const nsAString& aNumber,
|
||||
uint32_t aTypeOfNumber,
|
||||
uint32_t aNumberPlanIdentification,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
// TODO: bug 878016 - Android backend: implement getSMSCAddress/setSMSCAddress
|
||||
NS_NOTYETIMPLEMENTED("Implement me!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,30 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_SmsService_h
|
||||
#define mozilla_dom_mobilemessage_SmsService_h
|
||||
|
||||
#include "nsISmsService.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class SmsService final : public nsISmsService
|
||||
{
|
||||
private:
|
||||
~SmsService() {}
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISMSSERVICE
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_SmsService_h
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,3 +0,0 @@
|
||||
# MmsService.js
|
||||
component {9b069b8c-8697-11e4-a406-474f5190272b} MmsService.js
|
||||
contract @mozilla.org/mms/gonkmmsservice;1 {9b069b8c-8697-11e4-a406-474f5190272b}
|
File diff suppressed because it is too large
Load Diff
@ -1,130 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var MMDB = {};
|
||||
Cu.import("resource://gre/modules/MobileMessageDB.jsm", MMDB);
|
||||
|
||||
const GONK_MOBILEMESSAGEDATABASESERVICE_CONTRACTID =
|
||||
"@mozilla.org/mobilemessage/gonkmobilemessagedatabaseservice;1";
|
||||
const GONK_MOBILEMESSAGEDATABASESERVICE_CID =
|
||||
Components.ID("{7db05024-8038-11e4-b7fa-a3edb6f1bf0c}");
|
||||
|
||||
const DB_NAME = "sms";
|
||||
|
||||
/**
|
||||
* MobileMessageDatabaseService
|
||||
*/
|
||||
function MobileMessageDatabaseService() {
|
||||
// Prime the directory service's cache to ensure that the ProfD entry exists
|
||||
// by the time IndexedDB queries for it off the main thread. (See bug 743635.)
|
||||
Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
|
||||
let mmdb = new MMDB.MobileMessageDB();
|
||||
mmdb.init(DB_NAME, 0, mmdb.updatePendingTransactionToError.bind(mmdb));
|
||||
this.mmdb = mmdb;
|
||||
}
|
||||
MobileMessageDatabaseService.prototype = {
|
||||
|
||||
classID: GONK_MOBILEMESSAGEDATABASESERVICE_CID,
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIGonkMobileMessageDatabaseService,
|
||||
Ci.nsIMobileMessageDatabaseService,
|
||||
Ci.nsIObserver]),
|
||||
|
||||
/**
|
||||
* MobileMessageDB instance.
|
||||
*/
|
||||
mmdb: null,
|
||||
|
||||
/**
|
||||
* nsIObserver
|
||||
*/
|
||||
observe: function() {},
|
||||
|
||||
/**
|
||||
* nsIGonkMobileMessageDatabaseService API
|
||||
*/
|
||||
|
||||
saveReceivedMessage: function(aMessage, aCallback) {
|
||||
this.mmdb.saveReceivedMessage(aMessage, aCallback);
|
||||
},
|
||||
|
||||
saveSendingMessage: function(aMessage, aCallback) {
|
||||
this.mmdb.saveSendingMessage(aMessage, aCallback);
|
||||
},
|
||||
|
||||
setMessageDeliveryByMessageId: function(aMessageId, aReceiver, aDelivery,
|
||||
aDeliveryStatus, aEnvelopeId,
|
||||
aCallback) {
|
||||
this.mmdb.updateMessageDeliveryById(aMessageId, "messageId", aReceiver,
|
||||
aDelivery, aDeliveryStatus,
|
||||
aEnvelopeId, aCallback);
|
||||
},
|
||||
|
||||
setMessageDeliveryStatusByEnvelopeId: function(aEnvelopeId, aReceiver,
|
||||
aDeliveryStatus, aCallback) {
|
||||
this.mmdb.updateMessageDeliveryById(aEnvelopeId, "envelopeId", aReceiver,
|
||||
null, aDeliveryStatus, null, aCallback);
|
||||
},
|
||||
|
||||
setMessageReadStatusByEnvelopeId: function(aEnvelopeId, aReceiver,
|
||||
aReadStatus, aCallback) {
|
||||
this.mmdb.setMessageReadStatusByEnvelopeId(aEnvelopeId, aReceiver,
|
||||
aReadStatus, aCallback);
|
||||
},
|
||||
|
||||
getMessageRecordByTransactionId: function(aTransactionId, aCallback) {
|
||||
this.mmdb.getMessageRecordByTransactionId(aTransactionId, aCallback);
|
||||
},
|
||||
|
||||
getMessageRecordById: function(aMessageId, aCallback) {
|
||||
this.mmdb.getMessageRecordById(aMessageId, aCallback);
|
||||
},
|
||||
|
||||
translateCrErrorToMessageCallbackError: function(aCrError) {
|
||||
return this.mmdb.translateCrErrorToMessageCallbackError(aCrError);
|
||||
},
|
||||
|
||||
saveSmsSegment: function(aSmsSegment, aCallback) {
|
||||
this.mmdb.saveSmsSegment(aSmsSegment, aCallback);
|
||||
},
|
||||
|
||||
/**
|
||||
* nsIMobileMessageDatabaseService API
|
||||
*/
|
||||
|
||||
getMessage: function(aMessageId, aRequest) {
|
||||
this.mmdb.getMessage(aMessageId, aRequest);
|
||||
},
|
||||
|
||||
deleteMessage: function(aMessageIds, aLength, aRequest) {
|
||||
this.mmdb.deleteMessage(aMessageIds, aLength, aRequest);
|
||||
},
|
||||
|
||||
createMessageCursor: function(aHasStartDate, aStartDate, aHasEndDate,
|
||||
aEndDate, aNumbers, aNumbersCount, aDelivery,
|
||||
aHasRead, aRead, aHasThreadId, aThreadId,
|
||||
aReverse, aCallback) {
|
||||
return this.mmdb.createMessageCursor(aHasStartDate, aStartDate, aHasEndDate,
|
||||
aEndDate, aNumbers, aNumbersCount,
|
||||
aDelivery, aHasRead, aRead, aHasThreadId,
|
||||
aThreadId, aReverse, aCallback);
|
||||
},
|
||||
|
||||
markMessageRead: function(aMessageId, aValue, aSendReadReport, aRequest) {
|
||||
this.mmdb.markMessageRead(aMessageId, aValue, aSendReadReport, aRequest);
|
||||
},
|
||||
|
||||
createThreadCursor: function(aCallback) {
|
||||
return this.mmdb.createThreadCursor(aCallback);
|
||||
}
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MobileMessageDatabaseService]);
|
@ -1,3 +0,0 @@
|
||||
component {7db05024-8038-11e4-b7fa-a3edb6f1bf0c} MobileMessageDatabaseService.js
|
||||
contract @mozilla.org/mobilemessage/gonkmobilemessagedatabaseservice;1 {7db05024-8038-11e4-b7fa-a3edb6f1bf0c}
|
||||
category profile-after-change MobileMessageDatabaseService @mozilla.org/mobilemessage/gonkmobilemessagedatabaseservice;1
|
@ -1,425 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
var RIL = {};
|
||||
Cu.import("resource://gre/modules/ril_consts.js", RIL);
|
||||
|
||||
/**
|
||||
* SmsSegmentHelper
|
||||
*/
|
||||
this.SmsSegmentHelper = {
|
||||
/**
|
||||
* Get valid SMS concatenation reference number.
|
||||
*/
|
||||
_segmentRef: 0,
|
||||
get nextSegmentRef() {
|
||||
let ref = this._segmentRef++;
|
||||
|
||||
this._segmentRef %= (this.segmentRef16Bit ? 65535 : 255);
|
||||
|
||||
// 0 is not a valid SMS concatenation reference number.
|
||||
return ref + 1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate encoded length using specified locking/single shift table
|
||||
*
|
||||
* @param aMessage
|
||||
* message string to be encoded.
|
||||
* @param aLangTable
|
||||
* locking shift table string.
|
||||
* @param aLangShiftTable
|
||||
* single shift table string.
|
||||
* @param aStrict7BitEncoding [Optional]
|
||||
* Enable Latin characters replacement with corresponding
|
||||
* ones in GSM SMS 7-bit default alphabet.
|
||||
*
|
||||
* @return encoded length in septets.
|
||||
*
|
||||
* @note The algorithm used in this function must match exactly with
|
||||
* GsmPDUHelper#writeStringAsSeptets.
|
||||
*/
|
||||
countGsm7BitSeptets: function(aMessage, aLangTable, aLangShiftTable, aStrict7BitEncoding) {
|
||||
let length = 0;
|
||||
for (let msgIndex = 0; msgIndex < aMessage.length; msgIndex++) {
|
||||
let c = aMessage.charAt(msgIndex);
|
||||
if (aStrict7BitEncoding) {
|
||||
c = RIL.GSM_SMS_STRICT_7BIT_CHARMAP[c] || c;
|
||||
}
|
||||
|
||||
let septet = aLangTable.indexOf(c);
|
||||
|
||||
// According to 3GPP TS 23.038, section 6.1.1 General notes, "The
|
||||
// characters marked '1)' are not used but are displayed as a space."
|
||||
if (septet == RIL.PDU_NL_EXTENDED_ESCAPE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (septet >= 0) {
|
||||
length++;
|
||||
continue;
|
||||
}
|
||||
|
||||
septet = aLangShiftTable.indexOf(c);
|
||||
if (septet < 0) {
|
||||
if (!aStrict7BitEncoding) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Bug 816082, when aStrict7BitEncoding is enabled, we should replace
|
||||
// characters that can't be encoded with GSM 7-Bit alphabets with '*'.
|
||||
c = "*";
|
||||
if (aLangTable.indexOf(c) >= 0) {
|
||||
length++;
|
||||
} else if (aLangShiftTable.indexOf(c) >= 0) {
|
||||
length += 2;
|
||||
} else {
|
||||
// We can't even encode a '*' character with current configuration.
|
||||
return -1;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// According to 3GPP TS 23.038 B.2, "This code represents a control
|
||||
// character and therefore must not be used for language specific
|
||||
// characters."
|
||||
if (septet == RIL.PDU_NL_RESERVED_CONTROL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The character is not found in locking shfit table, but could be
|
||||
// encoded as <escape><char> with single shift table. Note that it's
|
||||
// still possible for septet to has the value of PDU_NL_EXTENDED_ESCAPE,
|
||||
// but we can display it as a space in this case as said in previous
|
||||
// comment.
|
||||
length += 2;
|
||||
}
|
||||
|
||||
return length;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate user data length of specified message string encoded in GSM 7Bit
|
||||
* alphabets.
|
||||
*
|
||||
* @param aMessage
|
||||
* a message string to be encoded.
|
||||
* @param aStrict7BitEncoding [Optional]
|
||||
* Enable Latin characters replacement with corresponding
|
||||
* ones in GSM SMS 7-bit default alphabet.
|
||||
*
|
||||
* @return null or an options object with attributes `dcs`,
|
||||
* `userDataHeaderLength`, `encodedFullBodyLength`, `langIndex`,
|
||||
* `langShiftIndex`, `segmentMaxSeq` set.
|
||||
*
|
||||
* @see #calculateUserDataLength().
|
||||
*
|
||||
* |enabledGsmTableTuples|:
|
||||
* List of tuples of national language identifier pairs.
|
||||
* |segmentRef16Bit|:
|
||||
* Use 16-bit reference number for concatenated outgoint messages.
|
||||
* TODO: Support static/runtime settings, see bug 1019443.
|
||||
*/
|
||||
enabledGsmTableTuples: [
|
||||
[RIL.PDU_NL_IDENTIFIER_DEFAULT, RIL.PDU_NL_IDENTIFIER_DEFAULT],
|
||||
],
|
||||
segmentRef16Bit: false,
|
||||
calculateUserDataLength7Bit: function(aMessage, aStrict7BitEncoding) {
|
||||
let options = null;
|
||||
let minUserDataSeptets = Number.MAX_VALUE;
|
||||
for (let i = 0; i < this.enabledGsmTableTuples.length; i++) {
|
||||
let [langIndex, langShiftIndex] = this.enabledGsmTableTuples[i];
|
||||
|
||||
const langTable = RIL.PDU_NL_LOCKING_SHIFT_TABLES[langIndex];
|
||||
const langShiftTable = RIL.PDU_NL_SINGLE_SHIFT_TABLES[langShiftIndex];
|
||||
|
||||
let bodySeptets = this.countGsm7BitSeptets(aMessage,
|
||||
langTable,
|
||||
langShiftTable,
|
||||
aStrict7BitEncoding);
|
||||
if (bodySeptets < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let headerLen = 0;
|
||||
if (langIndex != RIL.PDU_NL_IDENTIFIER_DEFAULT) {
|
||||
headerLen += 3; // IEI + len + langIndex
|
||||
}
|
||||
if (langShiftIndex != RIL.PDU_NL_IDENTIFIER_DEFAULT) {
|
||||
headerLen += 3; // IEI + len + langShiftIndex
|
||||
}
|
||||
|
||||
// Calculate full user data length, note the extra byte is for header len
|
||||
let headerSeptets = Math.ceil((headerLen ? headerLen + 1 : 0) * 8 / 7);
|
||||
let segmentSeptets = RIL.PDU_MAX_USER_DATA_7BIT;
|
||||
if ((bodySeptets + headerSeptets) > segmentSeptets) {
|
||||
headerLen += this.segmentRef16Bit ? 6 : 5;
|
||||
headerSeptets = Math.ceil((headerLen + 1) * 8 / 7);
|
||||
}
|
||||
segmentSeptets -= headerSeptets;
|
||||
|
||||
let segments = Math.ceil(bodySeptets / segmentSeptets);
|
||||
let userDataSeptets = bodySeptets + headerSeptets * segments;
|
||||
if (userDataSeptets >= minUserDataSeptets) {
|
||||
continue;
|
||||
}
|
||||
|
||||
minUserDataSeptets = userDataSeptets;
|
||||
|
||||
options = {
|
||||
dcs: RIL.PDU_DCS_MSG_CODING_7BITS_ALPHABET,
|
||||
encodedFullBodyLength: bodySeptets,
|
||||
userDataHeaderLength: headerLen,
|
||||
langIndex: langIndex,
|
||||
langShiftIndex: langShiftIndex,
|
||||
segmentMaxSeq: segments,
|
||||
segmentChars: segmentSeptets,
|
||||
};
|
||||
}
|
||||
|
||||
return options;
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate user data length of specified message string encoded in UCS2.
|
||||
*
|
||||
* @param aMessage
|
||||
* a message string to be encoded.
|
||||
*
|
||||
* @return an options object with attributes `dcs`, `userDataHeaderLength`,
|
||||
* `encodedFullBodyLength`, `segmentMaxSeq` set.
|
||||
*
|
||||
* @see #calculateUserDataLength().
|
||||
*/
|
||||
calculateUserDataLengthUCS2: function(aMessage) {
|
||||
let bodyChars = aMessage.length;
|
||||
let headerLen = 0;
|
||||
let headerChars = Math.ceil((headerLen ? headerLen + 1 : 0) / 2);
|
||||
let segmentChars = RIL.PDU_MAX_USER_DATA_UCS2;
|
||||
if ((bodyChars + headerChars) > segmentChars) {
|
||||
headerLen += this.segmentRef16Bit ? 6 : 5;
|
||||
headerChars = Math.ceil((headerLen + 1) / 2);
|
||||
segmentChars -= headerChars;
|
||||
}
|
||||
|
||||
let segments = Math.ceil(bodyChars / segmentChars);
|
||||
|
||||
return {
|
||||
dcs: RIL.PDU_DCS_MSG_CODING_16BITS_ALPHABET,
|
||||
encodedFullBodyLength: bodyChars * 2,
|
||||
userDataHeaderLength: headerLen,
|
||||
segmentMaxSeq: segments,
|
||||
segmentChars: segmentChars,
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Calculate user data length and its encoding.
|
||||
*
|
||||
* @param aMessage
|
||||
* a message string to be encoded.
|
||||
* @param aStrict7BitEncoding [Optional]
|
||||
* Enable Latin characters replacement with corresponding
|
||||
* ones in GSM SMS 7-bit default alphabet.
|
||||
*
|
||||
* @return an options object with some or all of following attributes set:
|
||||
*
|
||||
* @param dcs
|
||||
* Data coding scheme. One of the PDU_DCS_MSG_CODING_*BITS_ALPHABET
|
||||
* constants.
|
||||
* @param userDataHeaderLength
|
||||
* Length of embedded user data header, in bytes. The whole header
|
||||
* size will be userDataHeaderLength + 1; 0 for no header.
|
||||
* @param encodedFullBodyLength
|
||||
* Length of the message body when encoded with the given DCS. For
|
||||
* UCS2, in bytes; for 7-bit, in septets.
|
||||
* @param langIndex
|
||||
* Table index used for normal 7-bit encoded character lookup.
|
||||
* @param langShiftIndex
|
||||
* Table index used for escaped 7-bit encoded character lookup.
|
||||
* @param segmentMaxSeq
|
||||
* Max sequence number of a multi-part messages, or 1 for single one.
|
||||
* This number might not be accurate for a multi-part message until
|
||||
* it's processed by #fragmentText() again.
|
||||
*/
|
||||
calculateUserDataLength: function(aMessage, aStrict7BitEncoding) {
|
||||
let options = this.calculateUserDataLength7Bit(aMessage, aStrict7BitEncoding);
|
||||
if (!options) {
|
||||
options = this.calculateUserDataLengthUCS2(aMessage);
|
||||
}
|
||||
|
||||
return options;
|
||||
},
|
||||
|
||||
/**
|
||||
* Fragment GSM 7-Bit encodable string for transmission.
|
||||
*
|
||||
* @param aText
|
||||
* text string to be fragmented.
|
||||
* @param aLangTable
|
||||
* locking shift table string.
|
||||
* @param aLangShiftTable
|
||||
* single shift table string.
|
||||
* @param aSegmentSeptets
|
||||
* Number of available spetets per segment.
|
||||
* @param aStrict7BitEncoding [Optional]
|
||||
* Enable Latin characters replacement with corresponding
|
||||
* ones in GSM SMS 7-bit default alphabet.
|
||||
*
|
||||
* @return an array of objects. See #fragmentText() for detailed definition.
|
||||
*/
|
||||
fragmentText7Bit: function(aText, aLangTable, aLangShiftTable, aSegmentSeptets, aStrict7BitEncoding) {
|
||||
let ret = [];
|
||||
let body = "", len = 0;
|
||||
// If the message is empty, we only push the empty message to ret.
|
||||
if (aText.length === 0) {
|
||||
ret.push({
|
||||
body: aText,
|
||||
encodedBodyLength: aText.length,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (let i = 0, inc = 0; i < aText.length; i++) {
|
||||
let c = aText.charAt(i);
|
||||
if (aStrict7BitEncoding) {
|
||||
c = RIL.GSM_SMS_STRICT_7BIT_CHARMAP[c] || c;
|
||||
}
|
||||
|
||||
let septet = aLangTable.indexOf(c);
|
||||
if (septet == RIL.PDU_NL_EXTENDED_ESCAPE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (septet >= 0) {
|
||||
inc = 1;
|
||||
} else {
|
||||
septet = aLangShiftTable.indexOf(c);
|
||||
if (septet == RIL.PDU_NL_RESERVED_CONTROL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
inc = 2;
|
||||
if (septet < 0) {
|
||||
if (!aStrict7BitEncoding) {
|
||||
throw new Error("Given text cannot be encoded with GSM 7-bit Alphabet!");
|
||||
}
|
||||
|
||||
// Bug 816082, when aStrict7BitEncoding is enabled, we should replace
|
||||
// characters that can't be encoded with GSM 7-Bit alphabets with '*'.
|
||||
c = "*";
|
||||
if (aLangTable.indexOf(c) >= 0) {
|
||||
inc = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((len + inc) > aSegmentSeptets) {
|
||||
ret.push({
|
||||
body: body,
|
||||
encodedBodyLength: len,
|
||||
});
|
||||
body = c;
|
||||
len = inc;
|
||||
} else {
|
||||
body += c;
|
||||
len += inc;
|
||||
}
|
||||
}
|
||||
|
||||
if (len) {
|
||||
ret.push({
|
||||
body: body,
|
||||
encodedBodyLength: len,
|
||||
});
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
/**
|
||||
* Fragment UCS2 encodable string for transmission.
|
||||
*
|
||||
* @param aText
|
||||
* text string to be fragmented.
|
||||
* @param aSegmentChars
|
||||
* Number of available characters per segment.
|
||||
*
|
||||
* @return an array of objects. See #fragmentText() for detailed definition.
|
||||
*/
|
||||
fragmentTextUCS2: function(aText, aSegmentChars) {
|
||||
let ret = [];
|
||||
// If the message is empty, we only push the empty message to ret.
|
||||
if (aText.length === 0) {
|
||||
ret.push({
|
||||
body: aText,
|
||||
encodedBodyLength: aText.length,
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (let offset = 0; offset < aText.length; offset += aSegmentChars) {
|
||||
let str = aText.substr(offset, aSegmentChars);
|
||||
ret.push({
|
||||
body: str,
|
||||
encodedBodyLength: str.length * 2,
|
||||
});
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
/**
|
||||
* Fragment string for transmission.
|
||||
*
|
||||
* Fragment input text string into an array of objects that contains
|
||||
* attributes `body`, substring for this segment, `encodedBodyLength`,
|
||||
* length of the encoded segment body in septets.
|
||||
*
|
||||
* @param aText
|
||||
* Text string to be fragmented.
|
||||
* @param aOptions [Optional]
|
||||
* Optional pre-calculated option object. The output array will be
|
||||
* stored at aOptions.segments if there are multiple segments.
|
||||
* @param aStrict7BitEncoding [Optional]
|
||||
* Enable Latin characters replacement with corresponding
|
||||
* ones in GSM SMS 7-bit default alphabet.
|
||||
*
|
||||
* @return Populated options object.
|
||||
*/
|
||||
fragmentText: function(aText, aOptions, aStrict7BitEncoding) {
|
||||
if (!aOptions) {
|
||||
aOptions = this.calculateUserDataLength(aText, aStrict7BitEncoding);
|
||||
}
|
||||
|
||||
if (aOptions.dcs == RIL.PDU_DCS_MSG_CODING_7BITS_ALPHABET) {
|
||||
const langTable = RIL.PDU_NL_LOCKING_SHIFT_TABLES[aOptions.langIndex];
|
||||
const langShiftTable = RIL.PDU_NL_SINGLE_SHIFT_TABLES[aOptions.langShiftIndex];
|
||||
aOptions.segments = this.fragmentText7Bit(aText,
|
||||
langTable, langShiftTable,
|
||||
aOptions.segmentChars,
|
||||
aStrict7BitEncoding);
|
||||
} else {
|
||||
aOptions.segments = this.fragmentTextUCS2(aText,
|
||||
aOptions.segmentChars);
|
||||
}
|
||||
|
||||
// Re-sync aOptions.segmentMaxSeq with actual length of returning array.
|
||||
aOptions.segmentMaxSeq = aOptions.segments.length;
|
||||
|
||||
if (aOptions.segmentMaxSeq > 1) {
|
||||
aOptions.segmentRef16Bit = this.segmentRef16Bit;
|
||||
aOptions.segmentRef = this.nextSegmentRef;
|
||||
}
|
||||
|
||||
return aOptions;
|
||||
}
|
||||
};
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ 'SmsSegmentHelper' ];
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +0,0 @@
|
||||
# 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/.
|
||||
|
||||
component {f9b9b5e2-73b4-11e4-83ff-a33e27428c86} SmsService.js
|
||||
contract @mozilla.org/sms/gonksmsservice;1 {f9b9b5e2-73b4-11e4-83ff-a33e27428c86}
|
||||
category profile-after-change SmsService @mozilla.org/sms/gonksmsservice;1
|
File diff suppressed because it is too large
Load Diff
@ -1,131 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
// Encoded X-Mms-Message-Type values
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.30
|
||||
this.MMS_PDU_TYPE_SEND_REQ = 128;
|
||||
this.MMS_PDU_TYPE_SEND_CONF = 129;
|
||||
this.MMS_PDU_TYPE_NOTIFICATION_IND = 130;
|
||||
this.MMS_PDU_TYPE_NOTIFYRESP_IND = 131;
|
||||
this.MMS_PDU_TYPE_RETRIEVE_CONF = 132;
|
||||
this.MMS_PDU_TYPE_ACKNOWLEDGE_IND = 133;
|
||||
this.MMS_PDU_TYPE_DELIVERY_IND = 134;
|
||||
this.MMS_PDU_TYPE_READ_REC_IND = 135;
|
||||
this.MMS_PDU_TYPE_READ_ORIG_IND = 136;
|
||||
this.MMS_PDU_TYPE_FORWARD_REQ = 137;
|
||||
this.MMS_PDU_TYPE_FORWARD_CONF = 138;
|
||||
this.MMS_PDU_TYPE_MBOX_STORE_REQ = 139;
|
||||
this.MMS_PDU_TYPE_MBOX_STORE_CONF = 140;
|
||||
this.MMS_PDU_TYPE_MBOX_VIEW_REQ = 141;
|
||||
this.MMS_PDU_TYPE_MBOX_VIEW_CONF = 142;
|
||||
this.MMS_PDU_TYPE_MBOX_UPLOAD_REQ = 143;
|
||||
this.MMS_PDU_TYPE_MBOX_UPLOAD_CONF = 144;
|
||||
this.MMS_PDU_TYPE_MBOX_DELETE_REQ = 145;
|
||||
this.MMS_PDU_TYPE_MBOX_DELETE_CONF = 146;
|
||||
this.MMS_PDU_TYPE_MBOX_DESCR = 147;
|
||||
this.MMS_PDU_TYPE_DELETE_REQ = 148;
|
||||
this.MMS_PDU_TYPE_DELETE_CONF = 149;
|
||||
this.MMS_PDU_TYPE_CANCEL_REQ = 150;
|
||||
this.MMS_PDU_TYPE_CANCEL_CONF = 151;
|
||||
|
||||
// MMS version
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.34
|
||||
this.MMS_VERSION_1_1 = (0x01 << 4) | 0x01;
|
||||
this.MMS_VERSION_1_3 = (0x01 << 4) | 0x03;
|
||||
|
||||
// Common Status Values
|
||||
this.MMS_PDU_ERROR_OK = 128;
|
||||
this.MMS_PDU_ERROR_TRANSIENT_FAILURE = 192;
|
||||
this.MMS_PDU_ERROR_PERMANENT_FAILURE = 224;
|
||||
|
||||
// X-Mms-Response-Status values
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.48
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A Table 28, 29, 30
|
||||
//this.MMS_PDU_RESPONSE_ERROR_UNSPECIFIED = 129; (obsolete)
|
||||
//this.MMS_PDU_RESPONSE_ERROR_SERVICE_DENIED = 130; (obsolete)
|
||||
//this.MMS_PDU_RESPONSE_ERROR_MESSAGE_FORMAT_CORRUPT = 131; (obsolete)
|
||||
//this.MMS_PDU_RESPONSE_ERROR_SENDING_ADDRESS_UNRESOLVED = 132; (obsolete)
|
||||
//this.MMS_PDU_RESPONSE_ERROR_MESSAGE_NOT_FOUND = 133; (obsolete)
|
||||
//this.MMS_PDU_RESPONSE_ERROR_NETWORK_PROBLEM = 134; (obsolete)
|
||||
//this.MMS_PDU_RESPONSE_ERROR_CONTENT_NOT_ACCEPTED = 135; (obsolete)
|
||||
this.MMS_PDU_RESPONSE_ERROR_UNSUPPORTED_MESSAGE = 136;
|
||||
this.MMS_PDU_RESPONSE_ERROR_TRANSIENT_SENDING_ADDRESS_UNRESOLVED = 193;
|
||||
this.MMS_PDU_RESPONSE_ERROR_TRANSIENT_MESSAGE_NOT_FOUND = 194;
|
||||
this.MMS_PDU_RESPONSE_ERROR_TRANSIENT_NETWORK_PROBLEM = 195;
|
||||
this.MMS_PDU_RESPONSE_ERROR_TRANSIENT_PARTIAL_SUCCESS = 196;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_SERVICE_DENIED = 225;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_MESSAGE_FORMAT_CORRUPT = 226;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_SENDING_ADDRESS_UNRESOLVED = 227;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 228;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_CONTENT_NOT_ACCEPTED = 229;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_REPLY_CHARGING_LIMITATIONS_NOT_MET = 230;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_REPLY_CHARGING_REQUEST_NOT_ACCEPTED = 231;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_REPLY_CHARGING_FORWARDING_DENIED = 232;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_REPLY_CHARGING_NOT_SUPPORTED = 233;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_ADDRESS_HIDING_NOT_SUPPORTED = 234;
|
||||
this.MMS_PDU_RESPONSE_ERROR_PERMANENT_LACK_OF_PREPAID = 235;
|
||||
|
||||
// X-Mms-Retrieve-Status values
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.50
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A Table 31
|
||||
this.MMS_PDU_RETRIEVE_ERROR_TRANSIENT_MESSAGE_NOT_FOUND = 193;
|
||||
this.MMS_PDU_RETRIEVE_ERROR_TRANSIENT_NETWORK_PROBLEM = 194;
|
||||
this.MMS_PDU_RETRIEVE_ERROR_PERMANENT_SERVICE_DENIED = 225;
|
||||
this.MMS_PDU_RETRIEVE_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 226;
|
||||
this.MMS_PDU_RETRIEVE_ERROR_PERMANENT_CONTENT_UNSUPPORTED = 227;
|
||||
|
||||
// X-Mms-Store-Status values
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.58
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A Table 35
|
||||
this.MMS_PDU_STORE_ERROR_TRANSIENT_NETWORK_PROBLEM = 193;
|
||||
this.MMS_PDU_STORE_ERROR_PERMANENT_SERVICE_DENIED = 225;
|
||||
this.MMS_PDU_STORE_ERROR_PERMANENT_MESSAGE_FORMAT_CORRUPT = 226;
|
||||
this.MMS_PDU_STORE_ERROR_PERMANENT_MESSAGE_NOT_FOUND = 227;
|
||||
this.MMS_PDU_STORE_ERROR_PERMANENT_MMBOX_FULL = 228;
|
||||
|
||||
// X-Mms-Status values
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.54
|
||||
this.MMS_PDU_STATUS_EXPIRED = 128;
|
||||
this.MMS_PDU_STATUS_RETRIEVED = 129;
|
||||
this.MMS_PDU_STATUS_REJECTED = 130;
|
||||
this.MMS_PDU_STATUS_DEFERRED = 131;
|
||||
this.MMS_PDU_STATUS_UNRECOGNISED = 132;
|
||||
this.MMS_PDU_STATUS_INDETERMINATE = 133;
|
||||
this.MMS_PDU_STATUS_FORWARDED = 134;
|
||||
this.MMS_PDU_STATUS_UNREACHABLE = 135;
|
||||
|
||||
// X-Mms-Cancel-Status values
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.7
|
||||
this.MMS_PDU_CANCEL_STATUS_RECEIVED = 128;
|
||||
this.MMS_PDU_CANCEL_STATUS_CORRUPTED = 129;
|
||||
|
||||
// X-Mms-Sender-Visibility
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.52
|
||||
this.MMS_PDU_SENDER_VISIBILITY_HIDE = 128;
|
||||
this.MMS_PDU_SENDER_VISIBILITY_SHOW = 129;
|
||||
|
||||
// X-Mms-Read-Status
|
||||
// @see OMA-TS-MMS_ENC-V1_3-20110913-A clause 7.3.38
|
||||
this.MMS_PDU_READ_STATUS_READ = 128;
|
||||
this.MMS_PDU_READ_STATUS_DELETED_UNREAD = 129;
|
||||
|
||||
// Maximum Values of MMS Parameters
|
||||
// @see OMA-TS-MMS_CONF-V1_3-20110511-C 10.2.5
|
||||
this.MMS_MAX_LENGTH_SUBJECT = 40;
|
||||
this.MMS_MAX_LENGTH_RECIPIENT = 312;
|
||||
this.MMS_MAX_TOTAL_RECIPIENTS = 20;
|
||||
this.MMS_MAX_LENGTH_NAME_CONTENT_TYPE = 40;
|
||||
this.MMS_MAX_LENGTH_MAILBOX_PORTION = 256;
|
||||
|
||||
this.DOM_READ_STATUS_NOT_APPLICABLE = "not-applicable";
|
||||
this.DOM_READ_STATUS_SUCCESS = "success";
|
||||
this.DOM_READ_STATUS_PENDING = "pending";
|
||||
this.DOM_READ_STATUS_ERROR = "error";
|
||||
|
||||
this.ALL_CONST_SYMBOLS = undefined; // We want ALL_CONST_SYMBOLS to be exported.
|
||||
this.ALL_CONST_SYMBOLS = Object.keys(this);
|
||||
|
||||
// Allow this file to be imported via Components.utils.import().
|
||||
this.EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS;
|
||||
|
@ -1,22 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
// WSP PDU Type Assignments
|
||||
// @see WAP-230-WSP-20010705-a Appendix A. Assigned Numbers.
|
||||
this.WSP_PDU_TYPE_PUSH = 0x06;
|
||||
|
||||
// Registered WDP Port Numbers
|
||||
// @see WAP-259-WDP-20010614-a Appendix B. Port Number Definitions.
|
||||
this.WDP_PORT_PUSH = 2948;
|
||||
|
||||
// Bearer Type Assignments
|
||||
// @see WAP-259-WDP-20010614-a Appendix C. Network Bearer Table.
|
||||
this.WDP_BEARER_GSM_SMS_GSM_MSISDN = 0x03;
|
||||
|
||||
this.ALL_CONST_SYMBOLS = undefined; // We want ALL_CONST_SYMBOLS to be exported.
|
||||
this.ALL_CONST_SYMBOLS = Object.keys(this);
|
||||
|
||||
this.EXPORTED_SYMBOLS = ALL_CONST_SYMBOLS;
|
@ -1,29 +0,0 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
XPIDL_SOURCES += [
|
||||
'nsIDeletedMessageInfo.idl',
|
||||
'nsIMmsMessage.idl',
|
||||
'nsIMmsService.idl',
|
||||
'nsIMobileMessageCallback.idl',
|
||||
'nsIMobileMessageCursorCallback.idl',
|
||||
'nsIMobileMessageDatabaseService.idl',
|
||||
'nsIMobileMessageService.idl',
|
||||
'nsIMobileMessageThread.idl',
|
||||
'nsISmsMessage.idl',
|
||||
'nsISmsService.idl',
|
||||
'nsIWapPushApplication.idl',
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
|
||||
XPIDL_SOURCES += [
|
||||
'nsIGonkMobileMessageDatabaseService.idl',
|
||||
'nsIGonkSmsService.idl',
|
||||
'nsISmsMessenger.idl',
|
||||
]
|
||||
|
||||
XPIDL_MODULE = 'dom_mobilemessage'
|
||||
|
@ -1,17 +0,0 @@
|
||||
/* 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 nsIVariant;
|
||||
|
||||
[scriptable, builtinclass, uuid(174139d8-00e1-11e4-818a-f38357d90920)]
|
||||
interface nsIDeletedMessageInfo : nsISupports
|
||||
{
|
||||
/* Array of messages ids in long if available. */
|
||||
readonly attribute nsIVariant deletedMessageIds;
|
||||
|
||||
/* Array of thread ids in unsigned long long. if available */
|
||||
readonly attribute nsIVariant deletedThreadIds;
|
||||
};
|
@ -1,153 +0,0 @@
|
||||
/* 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 "domstubs.idl"
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIMobileMessageDatabaseService.idl"
|
||||
|
||||
[scriptable, function, uuid(2ae081ac-8038-11e4-a472-1ba11eb89d79)]
|
||||
interface nsIGonkMobileMessageDatabaseCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* |aDomMessage|: the nsI{Mms,Sms}Message
|
||||
*/
|
||||
void notify(in nsresult aRv, in nsISupports aDomMessage);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(2f7a6fde-8038-11e4-9d93-5b9ffba492fb)]
|
||||
interface nsIGonkMobileMessageDatabaseRecordCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* |aMessageRecord| Object: the mobile-message database record
|
||||
* |aDomMessage|: the nsI{Mms,Sms}Message. Noted, this value might be null.
|
||||
*/
|
||||
void notify(in nsresult aRv, in jsval aMessageRecord, in nsISupports aDomMessage);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(36f9732c-8038-11e4-b634-3f7e3df5232a)]
|
||||
interface nsIGonkMobileMessageDatabaseConcatenationCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* |aCompleteMessage|: jsval: the completely concatenated message. Noted, this value might be null.
|
||||
*/
|
||||
void notify(in nsresult aRv, in jsval aCompleteMessage);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define GONK_MOBILE_MESSAGE_DATABASE_SERVICE_CID \
|
||||
{ 0x7db05024, 0x8038, 0x11e4, { 0xb7, 0xfa, 0xa3, 0xed, 0xb6, 0xf1, 0xbf, 0x0c } }
|
||||
#define GONK_MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID \
|
||||
"@mozilla.org/mobilemessage/gonkmobilemessagedatabaseservice;1"
|
||||
%}
|
||||
|
||||
[scriptable, uuid(48a3c28a-8038-11e4-b7b9-0f2df5b53100)]
|
||||
interface nsIGonkMobileMessageDatabaseService : nsIMobileMessageDatabaseService
|
||||
{
|
||||
/**
|
||||
* |aMessage| Object: should contain the following properties for internal use:
|
||||
* - |type| DOMString: "sms" or "mms"
|
||||
* - |timestamp| Number: the timestamp of received message
|
||||
* - |iccId| DOMString: [optional] the ICC ID of the SIM for receiving
|
||||
* message if available.
|
||||
*
|
||||
* - If |type| == "sms", we also need:
|
||||
* - |messageClass| DOMString: the message class of received message
|
||||
* - |receiver| DOMString: the phone number of receiver
|
||||
* - |pid| Number: the TP-PID field of the SMS TPDU, default 0.
|
||||
* - |sender| DOMString: the phone number of sender
|
||||
*
|
||||
* - If |type| == "mms", we also need:
|
||||
* - |delivery| DOMString: the delivery state of received message
|
||||
* - |deliveryStatus| DOMString: the delivery status of received message
|
||||
* - |receivers| DOMString Array: the phone numbers of receivers
|
||||
* - |phoneNumber| DOMString: [optional] my own phone number.
|
||||
*/
|
||||
void saveReceivedMessage(in jsval aMessage,
|
||||
[optional] in nsIGonkMobileMessageDatabaseCallback aCallback);
|
||||
|
||||
/**
|
||||
* |aMessage| Object: should contain the following properties for internal use:
|
||||
* - |type| DOMString: "sms" or "mms"
|
||||
* - |sender| DOMString: the phone number of sender
|
||||
* - |timestamp| Number: the timestamp of sending message
|
||||
* - |deliveryStatusRequested| Bool: true when the delivery report is requested.
|
||||
* - |iccId| DOMString: the ICC ID of the SIM for sending message
|
||||
*
|
||||
* - If |type| == "sms", we also need:
|
||||
* - |receiver| DOMString: the phone number of receiver
|
||||
*
|
||||
* - If |type| == "mms", we also need:
|
||||
* - |receivers| DOMString Array: the phone numbers of receivers
|
||||
*/
|
||||
void saveSendingMessage(in jsval aMessage,
|
||||
[optional] in nsIGonkMobileMessageDatabaseCallback aCallback);
|
||||
|
||||
/**
|
||||
* |aMessageId| Number: the message's DB record ID.
|
||||
* |aReceiver| DOMString: the phone number of receiver (for MMS; can be null).
|
||||
* |aDelivery| DOMString: the new delivery value to update (can be null).
|
||||
* |aDeliveryStatus| DOMString: the new delivery status to update (can be null).
|
||||
* |aEnvelopeId| DOMString: the "message-id" specified in the MMS PDU headers.
|
||||
* |aCallback| nsIGonkMobileMessageDatabaseCallback: an optional callback.
|
||||
*/
|
||||
void setMessageDeliveryByMessageId(in long aMessageId,
|
||||
in DOMString aReceiver,
|
||||
in DOMString aDelivery,
|
||||
in DOMString aDeliveryStatus,
|
||||
in DOMString aEnvelopeId,
|
||||
[optional] in nsIGonkMobileMessageDatabaseCallback aCallback);
|
||||
|
||||
/**
|
||||
* |aEnvelopeId| DOMString: the "message-id" specified in the MMS PDU headers.
|
||||
* |aReceiver| DOMString: the phone number of receiver (for MMS; can be null).
|
||||
* |aDeliveryStatus| DOMString: the new delivery status to be updated (can be null).
|
||||
* |aCallback| nsIGonkMobileMessageDatabaseCallback: an optional callback.
|
||||
*/
|
||||
void setMessageDeliveryStatusByEnvelopeId(in DOMString aEnvelopeId,
|
||||
in DOMString aReceiver,
|
||||
in DOMString aDeliveryStatus,
|
||||
[optional] in nsIGonkMobileMessageDatabaseCallback aCallback);
|
||||
|
||||
/**
|
||||
* |aEnvelopeId| DOMString: the "message-id" specified in the MMS PDU headers.
|
||||
* |aReceiver| DOMString: the phone number of receiver (for MMS; can be null).
|
||||
* |aReadStatus| DOMString: the new read status to be updated.
|
||||
* |aCallback| nsIGonkMobileMessageDatabaseCallback: an optional callback.
|
||||
*/
|
||||
void setMessageReadStatusByEnvelopeId(in DOMString aEnvelopeId,
|
||||
in DOMString aReceiver,
|
||||
in DOMString aReadStatus,
|
||||
[optional] in nsIGonkMobileMessageDatabaseCallback aCallback);
|
||||
|
||||
/**
|
||||
* |aMessageId| Number: the message's DB record ID.
|
||||
* |aCallback| nsIGonkMobileMessageDatabaseRecordCallback: a callback which
|
||||
* takes result flag, message record and domMessage as parameters.
|
||||
*/
|
||||
void getMessageRecordById(in long aMessageId,
|
||||
in nsIGonkMobileMessageDatabaseRecordCallback aCallback);
|
||||
|
||||
/**
|
||||
* |aTransactionId| DOMString: the transaction ID of MMS PDU.
|
||||
* |aCallback| nsIGonkMobileMessageDatabaseRecordCallback: a callback which
|
||||
* takes result flag and message record as parameters.
|
||||
*/
|
||||
void getMessageRecordByTransactionId(in DOMString aTransactionId,
|
||||
in nsIGonkMobileMessageDatabaseRecordCallback aCallback);
|
||||
|
||||
/**
|
||||
* |aCrError| nsresult: the NS_ERROR defined in Components.results.
|
||||
*
|
||||
* @returns the error code defined in nsIMobileMessageCallback
|
||||
*/
|
||||
jsval translateCrErrorToMessageCallbackError(in nsresult aCrError);
|
||||
|
||||
/**
|
||||
* |aSmsSegment| jsval: Decoded Single SMS PDU.
|
||||
* |aCallback| nsIGonkMobileMessageDatabaseConcatenationCallback: a callback which
|
||||
* takes result flag, and complete mesage as parameters.
|
||||
*/
|
||||
void saveSmsSegment(in jsval aSmsSegment,
|
||||
in nsIGonkMobileMessageDatabaseConcatenationCallback aCallback);
|
||||
};
|
@ -1,95 +0,0 @@
|
||||
/* 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 "domstubs.idl"
|
||||
#include "nsISmsService.idl"
|
||||
|
||||
%{C++
|
||||
#define GONK_SMSSERVICE_CONTRACTID \
|
||||
"@mozilla.org/sms/gonksmsservice;1"
|
||||
%}
|
||||
|
||||
[scriptable, uuid(76681431-8261-4540-bab8-24ef3866e8b6)]
|
||||
interface nsIGonkSmsService : nsISmsService
|
||||
{
|
||||
const unsigned short SMS_MESSAGE_ENCODING_7BITS_ALPHABET = 0x00;
|
||||
const unsigned short SMS_MESSAGE_ENCODING_8BITS_ALPHABET = 0x04;
|
||||
const unsigned short SMS_MESSAGE_ENCODING_16BITS_ALPHABET = 0x08;
|
||||
|
||||
const unsigned long SMS_APPLICATION_PORT_INVALID = 0xFFFFFFFF;
|
||||
|
||||
/**
|
||||
* Called when a short message has been received by the network.
|
||||
*
|
||||
* @param aServiceId
|
||||
* The ID of the service where this message is received from.
|
||||
* @param aSMSC
|
||||
* SMS Center address.
|
||||
* @param aSentTimestamp
|
||||
* The time stamp when message is arrived to SMSC.
|
||||
* @param aSender
|
||||
* The sender's address of this message.
|
||||
* @param aPid
|
||||
* Protocol Identifier, See TS 23.040, subcluase 9.2.3.9.
|
||||
* Set to 0 if invalid.
|
||||
* @param aEncoding
|
||||
* The encoding of message body.
|
||||
* SMS_MESSAGE_ENCODING_*.
|
||||
* @param aMessageClass
|
||||
* A predefined constant of nsISmsService.MESSAGE_CLASS_TYPE_*.
|
||||
* @param aLanguage
|
||||
* ISO-639-1 language code for this message. Null if unspecified.
|
||||
* @param aSegmentRef, aSegmentSeq, aSegmentMaxSeq
|
||||
* Concatenation info. See TS 23.040, subclause 9.2.3.24.1.
|
||||
* All set to 1 if no need for concatenatenation.
|
||||
* @param aOriginatorPort, aDestinationPort
|
||||
* Application Port Addressing. See TS 23.040 subclause 9.2.3.24.3~4.
|
||||
* All set to 1 if no need for concatenatenation.
|
||||
* @param aMwiPresent
|
||||
* True if MWI is presented in this message.
|
||||
* @param aMwiDiscard
|
||||
* True if MWI has to be discarded after received.
|
||||
* @param aMwiMsgCount
|
||||
* The number of messages waiting in the voicemail server.
|
||||
* -1 if number is unknown from the decoded MWI.
|
||||
* @param aMwiActive
|
||||
* True if there are messages waiting in the voicemail server.
|
||||
* @param aCdmaMessageType
|
||||
* CDMA SMS Message Type, as defined in 3GPP2 C.S0015-A v2.0, Table 3.4-1
|
||||
* Set to 0 if invalid.
|
||||
* @param aCdmaTeleservice
|
||||
* SMS Teleservice Identitifier, as defined in 3GPP2 N.S0005, Table 175.
|
||||
* Set to 0 if invalid.
|
||||
* @param aCdmaServiceCategory
|
||||
* CDMA Service Category, 3GPP2 C.R1001-D v2.0, 9.3 Service Category.
|
||||
* Set to 0 if invalid.
|
||||
* @param aBody
|
||||
* Text message body.
|
||||
* @param aData
|
||||
* Binary message body.
|
||||
*/
|
||||
void notifyMessageReceived(in unsigned long aServiceId,
|
||||
in DOMString aSMSC,
|
||||
in DOMTimeStamp aSentTimestamp,
|
||||
in DOMString aSender,
|
||||
in unsigned short aPid,
|
||||
in unsigned short aEncoding,
|
||||
in unsigned long aMessageClass,
|
||||
in DOMString aLanguage,
|
||||
in unsigned short aSegmentRef,
|
||||
in unsigned short aSegmentSeq,
|
||||
in unsigned short aSegmentMaxSeq,
|
||||
in unsigned long aOriginatorPort,
|
||||
in unsigned long aDestinationPort,
|
||||
in boolean aMwiPresent,
|
||||
in boolean aMwiDiscard,
|
||||
in short aMwiMsgCount,
|
||||
in boolean aMwiActive,
|
||||
in unsigned short aCdmaMessageType,
|
||||
in unsigned long aCdmaTeleservice,
|
||||
in unsigned long aCdmaServiceCategory,
|
||||
in DOMString aBody,
|
||||
[array, size_is(aDataLength)] in octet aData,
|
||||
in uint32_t aDataLength);
|
||||
};
|
@ -1,60 +0,0 @@
|
||||
/* 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 "domstubs.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMBlob;
|
||||
|
||||
[scriptable, builtinclass, uuid(cd2ff09a-8853-11e5-ac49-0f655992cef6)]
|
||||
interface nsIMmsMessage : nsISupports
|
||||
{
|
||||
/**
|
||||
* |type| is always "mms".
|
||||
*/
|
||||
readonly attribute DOMString type;
|
||||
|
||||
readonly attribute long id;
|
||||
|
||||
readonly attribute unsigned long long threadId;
|
||||
|
||||
/**
|
||||
* Integrated Circuit Card Identifier.
|
||||
*
|
||||
* Will be null if ICC is not available.
|
||||
*/
|
||||
readonly attribute DOMString iccId;
|
||||
|
||||
/**
|
||||
* Should be "not-downloaded", "received", "sending", "sent" or "error".
|
||||
*/
|
||||
readonly attribute DOMString delivery;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval deliveryInfo; // MmsDeliveryInfo[]
|
||||
|
||||
readonly attribute DOMString sender;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval receivers; // DOMString[]
|
||||
|
||||
readonly attribute DOMTimeStamp timestamp;
|
||||
|
||||
readonly attribute DOMTimeStamp sentTimestamp;
|
||||
// 0 if not available (e.g., |delivery| =
|
||||
// "sending").
|
||||
|
||||
readonly attribute boolean read;
|
||||
readonly attribute DOMString subject;
|
||||
readonly attribute DOMString smil;
|
||||
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval attachments; // MmsAttachment[]
|
||||
|
||||
readonly attribute DOMTimeStamp expiryDate; // Expiry date for an MMS to be
|
||||
// manually downloaded.
|
||||
|
||||
// Request read report from sender or not.
|
||||
readonly attribute boolean readReportRequested;
|
||||
};
|
@ -1,38 +0,0 @@
|
||||
/* 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 nsIMobileMessageCallback;
|
||||
interface nsIDOMBlob;
|
||||
|
||||
%{C++
|
||||
#define MMS_SERVICE_CID { 0x06d9124b, 0x80e0, 0x40ed, \
|
||||
{ 0x98, 0x71, 0x4d, 0x23, 0x4a, 0x0f, 0xd4, 0x31 } }
|
||||
#define MMS_SERVICE_CONTRACTID "@mozilla.org/mms/mmsservice;1"
|
||||
%}
|
||||
|
||||
[scriptable, uuid(543278b3-d926-4c65-84b8-b49ad7a17d21)]
|
||||
interface nsIMmsService : nsISupports
|
||||
{
|
||||
readonly attribute unsigned long mmsDefaultServiceId;
|
||||
|
||||
void send(in unsigned long serviceId,
|
||||
in jsval parameters /* MmsParameters */,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
void retrieve(in long id,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
void sendReadReport(in DOMString messageID,
|
||||
in DOMString toAddress,
|
||||
in DOMString iccId);
|
||||
};
|
||||
|
||||
%{C++
|
||||
template<typename T> struct already_AddRefed;
|
||||
|
||||
already_AddRefed<nsIMmsService>
|
||||
NS_CreateMmsService();
|
||||
%}
|
@ -1,67 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
[scriptable, uuid(19b24f93-7c02-4acf-addd-2f53bbb4e3fd)]
|
||||
interface nsIMobileMessageCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* All SMS related errors.
|
||||
* Make sure to keep this list in sync with the list in:
|
||||
* mobile/android/base/GeckoSmsManager.java
|
||||
*/
|
||||
const unsigned short SUCCESS_NO_ERROR = 0;
|
||||
const unsigned short NO_SIGNAL_ERROR = 1;
|
||||
const unsigned short NOT_FOUND_ERROR = 2;
|
||||
const unsigned short UNKNOWN_ERROR = 3;
|
||||
const unsigned short INTERNAL_ERROR = 4;
|
||||
const unsigned short NO_SIM_CARD_ERROR = 5;
|
||||
const unsigned short RADIO_DISABLED_ERROR = 6;
|
||||
const unsigned short INVALID_ADDRESS_ERROR = 7;
|
||||
const unsigned short FDN_CHECK_ERROR = 8;
|
||||
const unsigned short NON_ACTIVE_SIM_CARD_ERROR = 9;
|
||||
const unsigned short STORAGE_FULL_ERROR = 10;
|
||||
const unsigned short SIM_NOT_MATCHED_ERROR = 11;
|
||||
const unsigned short NETWORK_PROBLEMS_ERROR = 12;
|
||||
const unsigned short GENERAL_PROBLEMS_ERROR = 13;
|
||||
const unsigned short SERVICE_NOT_AVAILABLE_ERROR = 14;
|
||||
const unsigned short MESSAGE_TOO_LONG_FOR_NETWORK_ERROR = 15;
|
||||
const unsigned short SERVICE_NOT_SUPPORTED_ERROR = 16;
|
||||
const unsigned short RETRY_REQUIRED_ERROR = 17;
|
||||
|
||||
/**
|
||||
* |message| can be nsI{Mms,Sms}Message.
|
||||
*/
|
||||
void notifyMessageSent(in nsISupports message);
|
||||
void notifySendMessageFailed(in long error, in nsISupports message);
|
||||
|
||||
/**
|
||||
* |message| can be nsI{Mms,Sms}Message.
|
||||
*/
|
||||
void notifyMessageGot(in nsISupports message);
|
||||
void notifyGetMessageFailed(in long error);
|
||||
|
||||
void notifyMessageDeleted([array, size_is(count)] in boolean deleted,
|
||||
in uint32_t count);
|
||||
void notifyDeleteMessageFailed(in long error);
|
||||
|
||||
void notifyMessageMarkedRead(in boolean read);
|
||||
void notifyMarkMessageReadFailed(in long error);
|
||||
|
||||
void notifySegmentInfoForTextGot(in long segments,
|
||||
in long charsPerSegment,
|
||||
in long charsAvailableInLastSegment);
|
||||
void notifyGetSegmentInfoForTextFailed(in long error);
|
||||
|
||||
/**
|
||||
* SMSC Address get/set result
|
||||
*/
|
||||
void notifyGetSmscAddress(in DOMString aSmscAddress,
|
||||
in unsigned long aTypeOfNumber,
|
||||
in unsigned long aNumberPlanIdentification);
|
||||
void notifyGetSmscAddressFailed(in long error);
|
||||
void notifySetSmscAddress();
|
||||
void notifySetSmscAddressFailed(in long error);
|
||||
};
|
@ -1,14 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
[scriptable, builtinclass, uuid(134a6958-543b-46e2-b419-4631a2314164)]
|
||||
interface nsIMobileMessageCursorCallback : nsISupports
|
||||
{
|
||||
void notifyCursorError(in long error);
|
||||
void notifyCursorResult([array, size_is(size)] in nsISupports results,
|
||||
in uint32_t size);
|
||||
void notifyCursorDone();
|
||||
};
|
@ -1,56 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
%{C++
|
||||
#define MOBILE_MESSAGE_DATABASE_SERVICE_CID \
|
||||
{ 0x0d84b9c2, 0x8f76, 0x4ba4, \
|
||||
{ 0xa5, 0xcd, 0xdb, 0xfb, 0x01, 0xdf, 0xda, 0x99 } }
|
||||
#define MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID "@mozilla.org/mobilemessage/mobilemessagedatabaseservice;1"
|
||||
%}
|
||||
|
||||
interface nsICursorContinueCallback;
|
||||
interface nsIMobileMessageCallback;
|
||||
interface nsIMobileMessageCursorCallback;
|
||||
|
||||
[scriptable, uuid(18672be2-c185-4f9c-8af6-2e6ea004de73)]
|
||||
interface nsIMobileMessageDatabaseService : nsISupports
|
||||
{
|
||||
[binaryname(GetMessageMoz)]
|
||||
void getMessage(in long messageId,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
void deleteMessage([array, size_is(count)] in long messageIds,
|
||||
in uint32_t count,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
nsICursorContinueCallback createMessageCursor(in boolean hasStartDate,
|
||||
in unsigned long long startDate,
|
||||
in boolean hasEndDate,
|
||||
in unsigned long long endDate,
|
||||
[array, size_is(numbersCount)] in wstring numbers,
|
||||
in uint32_t numbersCount,
|
||||
[Null(Null), Undefined(Null)] in DOMString delivery,
|
||||
in boolean hasRead,
|
||||
in boolean read,
|
||||
in boolean hasThreadId,
|
||||
in unsigned long long threadId,
|
||||
in boolean reverse,
|
||||
in nsIMobileMessageCursorCallback callback);
|
||||
|
||||
void markMessageRead(in long messageId,
|
||||
in boolean value,
|
||||
in boolean sendReadReport,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
nsICursorContinueCallback createThreadCursor(in nsIMobileMessageCursorCallback callback);
|
||||
};
|
||||
|
||||
%{C++
|
||||
template<typename T> struct already_AddRefed;
|
||||
|
||||
already_AddRefed<nsIMobileMessageDatabaseService>
|
||||
NS_CreateMobileMessageDatabaseService();
|
||||
%}
|
@ -1,73 +0,0 @@
|
||||
/* 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 nsIDeletedMessageInfo;
|
||||
interface nsISmsMessage;
|
||||
interface nsIMmsMessage;
|
||||
interface nsIMobileMessageThread;
|
||||
|
||||
%{C++
|
||||
#define MOBILE_MESSAGE_SERVICE_CID { 0x829c1dd6, 0x0466, 0x4591, { 0x83, 0x6f, 0xb8, 0xf6, 0xfd, 0x1f, 0x7b, 0xa5 } }
|
||||
#define MOBILE_MESSAGE_SERVICE_CONTRACTID "@mozilla.org/mobilemessage/mobilemessageservice;1"
|
||||
%}
|
||||
|
||||
[scriptable, builtinclass, uuid(15267554-8854-11e5-8947-8f2150f4eabc)]
|
||||
interface nsIMobileMessageService : nsISupports
|
||||
{
|
||||
[implicit_jscontext]
|
||||
nsISmsMessage createSmsMessage(in long id,
|
||||
in unsigned long long threadId,
|
||||
in DOMString iccId,
|
||||
in DOMString delivery,
|
||||
in DOMString deliveryStatus,
|
||||
in DOMString sender,
|
||||
in DOMString receiver,
|
||||
in DOMString body,
|
||||
in DOMString messageClass,
|
||||
in unsigned long long timestamp,
|
||||
in unsigned long long sentTimestamp,
|
||||
in unsigned long long deliveryTimestamp,
|
||||
in bool read);
|
||||
|
||||
[implicit_jscontext]
|
||||
nsIMmsMessage createMmsMessage(in long id,
|
||||
in unsigned long long threadId,
|
||||
in DOMString iccId,
|
||||
in DOMString delivery,
|
||||
in jsval deliveryInfo,
|
||||
in DOMString sender,
|
||||
in jsval receivers,
|
||||
in unsigned long long timestamp,
|
||||
in unsigned long long sentTimestamp,
|
||||
in boolean read,
|
||||
in DOMString subject,
|
||||
in DOMString smil,
|
||||
in jsval attachments,
|
||||
in unsigned long long expiryDate,
|
||||
in boolean readReportRequested);
|
||||
|
||||
[implicit_jscontext]
|
||||
nsIMobileMessageThread createThread(in unsigned long long id,
|
||||
in jsval participants,
|
||||
in unsigned long long timestamp,
|
||||
in DOMString lastMessageSubject,
|
||||
in DOMString body,
|
||||
in unsigned long long unreadCount,
|
||||
in DOMString aLastMessageType);
|
||||
|
||||
nsIDeletedMessageInfo createDeletedMessageInfo(
|
||||
[array, size_is(msgCount)] in long messageIds,
|
||||
in uint32_t msgCount,
|
||||
[array, size_is(threadCount)] in unsigned long long threadIds,
|
||||
in uint32_t threadCount);
|
||||
};
|
||||
|
||||
%{C++
|
||||
template<typename T> struct already_AddRefed;
|
||||
|
||||
already_AddRefed<nsIMobileMessageService>
|
||||
NS_CreateMobileMessageService();
|
||||
%}
|
@ -1,32 +0,0 @@
|
||||
/* 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 "domstubs.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, builtinclass, uuid(dd6794cc-8853-11e5-89b4-278852073d45)]
|
||||
interface nsIMobileMessageThread : nsISupports
|
||||
{
|
||||
// Unique identity of the thread.
|
||||
readonly attribute unsigned long long id;
|
||||
|
||||
// Last (MMS) message subject.
|
||||
readonly attribute DOMString lastMessageSubject;
|
||||
|
||||
// Message body of the last message in the thread.
|
||||
readonly attribute DOMString body;
|
||||
|
||||
// Total unread messages in the thread.
|
||||
readonly attribute unsigned long long unreadCount;
|
||||
|
||||
// Participant addresses of the thread.
|
||||
[implicit_jscontext]
|
||||
readonly attribute jsval participants; // DOMString[]
|
||||
|
||||
// Timestamp of the last message in the thread.
|
||||
readonly attribute DOMTimeStamp timestamp;
|
||||
|
||||
// Message type of the last message in the thread.
|
||||
readonly attribute DOMString lastMessageType;
|
||||
};
|
@ -1,64 +0,0 @@
|
||||
/* 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 "domstubs.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, builtinclass, uuid(d7670dfa-8853-11e5-8e3e-43cd171289cc)]
|
||||
interface nsISmsMessage : nsISupports
|
||||
{
|
||||
/**
|
||||
* |type| is always "sms".
|
||||
*/
|
||||
readonly attribute DOMString type;
|
||||
|
||||
readonly attribute long id;
|
||||
|
||||
readonly attribute unsigned long long threadId;
|
||||
|
||||
/**
|
||||
* Integrated Circuit Card Identifier.
|
||||
*
|
||||
* Will be null if ICC is not available.
|
||||
*/
|
||||
readonly attribute DOMString iccId;
|
||||
|
||||
/**
|
||||
* Should be "received", "sending", "sent" or "error".
|
||||
*/
|
||||
readonly attribute DOMString delivery;
|
||||
|
||||
/**
|
||||
* Possible delivery status values for above delivery states are:
|
||||
*
|
||||
* "received": "success"
|
||||
* "sending" : "pending", or "not-applicable" if the message was sent without
|
||||
* status report requisition.
|
||||
* "sent" : "pending", "success", "error", or "not-applicable"
|
||||
* if the message was sent without status report requisition.
|
||||
* "error" : "error"
|
||||
*/
|
||||
readonly attribute DOMString deliveryStatus;
|
||||
|
||||
readonly attribute DOMString sender;
|
||||
readonly attribute DOMString receiver;
|
||||
readonly attribute DOMString body;
|
||||
|
||||
/**
|
||||
* Should be "normal", "class-0", "class-1", "class-2" or "class-3".
|
||||
*/
|
||||
readonly attribute DOMString messageClass;
|
||||
|
||||
readonly attribute DOMTimeStamp timestamp;
|
||||
|
||||
readonly attribute DOMTimeStamp sentTimestamp;
|
||||
// 0 if not available (e.g., |delivery| =
|
||||
// "sending").
|
||||
|
||||
readonly attribute DOMTimeStamp deliveryTimestamp;
|
||||
// 0 if not available (e.g., |delivery| =
|
||||
// "received" or not yet delivered).
|
||||
|
||||
readonly attribute boolean read;
|
||||
};
|
@ -1,74 +0,0 @@
|
||||
/* 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 "domstubs.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(3be7c6ac-e27d-11e4-b6da-7bbe0e4cd4ec)]
|
||||
interface nsISmsMessenger : nsISupports
|
||||
{
|
||||
/* 'sms-received' system message */
|
||||
const unsigned short NOTIFICATION_TYPE_RECEIVED = 0;
|
||||
/* 'sms-sent' system message */
|
||||
const unsigned short NOTIFICATION_TYPE_SENT = 1;
|
||||
/* 'sms-delivery-success' system message */
|
||||
const unsigned short NOTIFICATION_TYPE_DELIVERY_SUCCESS = 2;
|
||||
/* 'sms-failed' system message */
|
||||
const unsigned short NOTIFICATION_TYPE_SENT_FAILED = 3;
|
||||
/* 'sms-delivery-error' system message */
|
||||
const unsigned short NOTIFICATION_TYPE_DELIVERY_ERROR = 4;
|
||||
|
||||
/**
|
||||
* To broadcast system messages of 'sms-received', 'sms-delivery-success',
|
||||
* 'sms-sent', 'sms-failed' and 'sms-delivery-error'.
|
||||
*
|
||||
* Note: Except aNotificationType, all parameters are the attributes of the
|
||||
* nsISmsMessage generated by nsIMobileMessageService.createSmsMessage().
|
||||
*
|
||||
* @param aNotificationType
|
||||
* A predefined constant of nsISmsMessenger.NOTIFICATION_TYPE_*.
|
||||
* @param aId
|
||||
* The unique identity of this message.
|
||||
* @param aThreadId
|
||||
* The unique identity of the thread this message belongs to.
|
||||
* @param aIccId
|
||||
* Integrated Circuit Card Identifier. null if ICC is not available.
|
||||
* @param aDelivery
|
||||
* A predefined constant of nsISmsService.DELIVERY_TYPE_*.
|
||||
* @param aDeliveryStatus
|
||||
* A predefined constant of nsISmsService.DELIVERY_STATUS_TYPE_*.
|
||||
* @param aSender
|
||||
* Sender address. null if not available.
|
||||
* @param aReceiver
|
||||
* Receiver address. null if not available.
|
||||
* @param aBody
|
||||
* Text message body. null if not available.
|
||||
* @param aMessageClass
|
||||
* A predefined constant of nsISmsService.MESSAGE_CLASS_TYPE_*.
|
||||
* @param aTimestamp
|
||||
* The device system time when creating or saving this message.
|
||||
* @param aSentTimestamp
|
||||
* The SMSC timestamp of the incoming message.
|
||||
* 0 if not available.
|
||||
* @param aDeliveryTimestamp
|
||||
* The delivery timestamp to the remote party of the sent message.
|
||||
* 0 if not available.
|
||||
* @param aRead
|
||||
* True if the message was read.
|
||||
*/
|
||||
void notifySms(in unsigned short aNotificationType,
|
||||
in long aId,
|
||||
in unsigned long long aThreadId,
|
||||
in DOMString aIccId,
|
||||
in unsigned long aDelivery,
|
||||
in unsigned long aDeliveryStatus,
|
||||
in DOMString aSender,
|
||||
in DOMString aReceiver,
|
||||
in DOMString aBody,
|
||||
in unsigned long aMessageClass,
|
||||
in DOMTimeStamp aTimestamp,
|
||||
in DOMTimeStamp aSentTimestamp,
|
||||
in DOMTimeStamp aDeliveryTimestamp,
|
||||
in boolean aRead);
|
||||
};
|
@ -1,178 +0,0 @@
|
||||
/* 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 nsIMobileMessageCallback;
|
||||
|
||||
%{C++
|
||||
#define SMS_SERVICE_CID { 0xbada3cb8, 0xa568, 0x4dff, { 0xb5, 0x43, 0x52, 0xbb, 0xb3, 0x14, 0x31, 0x21 } }
|
||||
#define SMS_SERVICE_CONTRACTID "@mozilla.org/sms/smsservice;1"
|
||||
%}
|
||||
|
||||
[scriptable, uuid(c8ca5f06-ad76-44b0-a324-9e2910fd37da)]
|
||||
interface nsISmsService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Constant definitions of predefined GSM Message Class
|
||||
* See 3GPP TS 23.038 clause 4 SMS Data Coding Scheme
|
||||
*/
|
||||
const unsigned short MESSAGE_CLASS_TYPE_CLASS_0 = 0;
|
||||
const unsigned short MESSAGE_CLASS_TYPE_CLASS_1 = 1;
|
||||
const unsigned short MESSAGE_CLASS_TYPE_CLASS_2 = 2;
|
||||
const unsigned short MESSAGE_CLASS_TYPE_CLASS_3 = 3;
|
||||
const unsigned short MESSAGE_CLASS_TYPE_NORMAL = 6;
|
||||
|
||||
/**
|
||||
* Constant definitions of SMS Delivery
|
||||
*/
|
||||
const unsigned short DELIVERY_TYPE_RECEIVED = 0;
|
||||
const unsigned short DELIVERY_TYPE_SENDING = 1;
|
||||
const unsigned short DELIVERY_TYPE_SENT = 2;
|
||||
const unsigned short DELIVERY_TYPE_ERROR = 3;
|
||||
|
||||
/**
|
||||
* Constant definitions of SMS Delivery Status
|
||||
*/
|
||||
const unsigned short DELIVERY_STATUS_TYPE_NOT_APPLICABLE = 0;
|
||||
const unsigned short DELIVERY_STATUS_TYPE_SUCCESS = 1;
|
||||
const unsigned short DELIVERY_STATUS_TYPE_PENDING = 2;
|
||||
const unsigned short DELIVERY_STATUS_TYPE_ERROR = 3;
|
||||
|
||||
/**
|
||||
* Constant definitions of SM-RP type of number as defined in
|
||||
* |Table 10.5.118: Called party BCD number| of 3GPP TS 24.008.
|
||||
*/
|
||||
const unsigned short TYPE_OF_NUMBER_UNKNOWN = 0;
|
||||
const unsigned short TYPE_OF_NUMBER_INTERNATIONAL = 1;
|
||||
const unsigned short TYPE_OF_NUMBER_NATIONAL = 2;
|
||||
const unsigned short TYPE_OF_NUMBER_NETWORK_SPECIFIC = 3;
|
||||
const unsigned short TYPE_OF_NUMBER_DEDICATED_ACCESS_SHORT_CODE = 4;
|
||||
|
||||
/**
|
||||
* Constant definitions of SM-RP number plan identification as defined in
|
||||
* |Table 10.5.118: Called party BCD number| of 3GPP TS 24.008. These values
|
||||
* do not represent the actual protocol values defined in the 3GPP standard,
|
||||
* but rather the corresponding enum values of NumberPlanIdentification in
|
||||
* MozMobileMessageManager.
|
||||
*/
|
||||
const unsigned short NUMBER_PLAN_IDENTIFICATION_UNKNOWN = 0;
|
||||
const unsigned short NUMBER_PLAN_IDENTIFICATION_ISDN = 1;
|
||||
const unsigned short NUMBER_PLAN_IDENTIFICATION_DATA = 2;
|
||||
const unsigned short NUMBER_PLAN_IDENTIFICATION_TELEX = 3;
|
||||
const unsigned short NUMBER_PLAN_IDENTIFICATION_NATIONAL = 4;
|
||||
const unsigned short NUMBER_PLAN_IDENTIFICATION_PRIVATE = 5;
|
||||
|
||||
/**
|
||||
* The default RIL service ID used for SMS.
|
||||
*/
|
||||
readonly attribute unsigned long smsDefaultServiceId;
|
||||
|
||||
/**
|
||||
* Get the information necessary to create a multi-part SMS for a given text.
|
||||
*
|
||||
* @param text
|
||||
* The text message content.
|
||||
* @param request
|
||||
* The callback object to use. It invokes
|
||||
* |notifySegmentInfoForTextGot| on success, or
|
||||
* |notifyGetSegmentInfoForTextFailed| on failure.
|
||||
*/
|
||||
void getSegmentInfoForText(in DOMString text,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
/**
|
||||
* Send a SMS.
|
||||
*
|
||||
* @param serviceId
|
||||
* The ID of RIL service to use.
|
||||
* @param number
|
||||
* Destination number in string.
|
||||
* @param message
|
||||
* The text message content.
|
||||
* @param silent
|
||||
* |true| to send a silent message. It's used to make a SMS based
|
||||
* authentication for some services such as mobile billing.
|
||||
* @param request
|
||||
* The callback object to use. It invokes |notifyMessageSent| on
|
||||
* success, or |notifySendMessageFailed| on failure.
|
||||
* @throws NS_ERROR_INVALID_ARG
|
||||
* If |serviceId| exceeds the max value of available IDs.
|
||||
*/
|
||||
void send(in unsigned long serviceId,
|
||||
in DOMString number,
|
||||
in DOMString message,
|
||||
in boolean silent,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
/**
|
||||
* Add a number to the list of silent message originators. When receiving a
|
||||
* SMS sent from one of the numbers in the list, |SmsService| will notify
|
||||
* observers through the topic "silent-sms-received".
|
||||
*
|
||||
* It's used when a SMS based authentication has been initiated and the client
|
||||
* is waiting for an incoming silent message containing the authentication
|
||||
* result.
|
||||
*
|
||||
* @param number
|
||||
* Originator number in string.
|
||||
* @throw NS_ERROR_UNEXPECTED
|
||||
* If the given number has already been added before.
|
||||
*/
|
||||
void addSilentNumber(in DOMString number);
|
||||
|
||||
/**
|
||||
* Remove a number from the silent message originator list.
|
||||
*
|
||||
* @param number
|
||||
* Originator number in string.
|
||||
* @throws NS_ERROR_INVALID_ARG
|
||||
* If the number doesn't exist in the list.
|
||||
*/
|
||||
void removeSilentNumber(in DOMString number);
|
||||
|
||||
/**
|
||||
* Get the short message service center address of given |serviceId|.
|
||||
*
|
||||
* @param serviceId
|
||||
* The ID of RIL service to use.
|
||||
* @param request
|
||||
* The callback object to use. It invokes |notifyGetSmscAddress| on
|
||||
* success, or |notifyGetSmscAddressFailed| on failure.
|
||||
* @throws NS_ERROR_INVALID_ARG
|
||||
* If |serviceId| exceeds the max value of available IDs.
|
||||
*/
|
||||
void getSmscAddress(in unsigned long serviceId,
|
||||
in nsIMobileMessageCallback request);
|
||||
|
||||
/**
|
||||
* Set the short message service center address of given |serviceId|.
|
||||
*
|
||||
* @param serviceId
|
||||
* The ID of RIL service to use.
|
||||
* @param number
|
||||
* Number part of the SMSC address.
|
||||
* @param typeOfNumber
|
||||
* Type of number of the SMSC address.
|
||||
* @param numberPlanIdentification
|
||||
* Number plan identification of the SMSC address.
|
||||
* @param request
|
||||
* The callback object to use. It invokes |notifySetSmscAddress| on
|
||||
* success, or |notifySetSmscAddressFailed| on failure.
|
||||
* @throws NS_ERROR_INVALID_ARG
|
||||
* If |serviceId| exceeds the max value of available IDs.
|
||||
*/
|
||||
void setSmscAddress(in unsigned long serviceId,
|
||||
in DOMString number,
|
||||
in unsigned long typeOfNumber,
|
||||
in unsigned long numberPlanIdentification,
|
||||
in nsIMobileMessageCallback request);
|
||||
};
|
||||
|
||||
%{C++
|
||||
template<typename T> struct already_AddRefed;
|
||||
|
||||
already_AddRefed<nsISmsService>
|
||||
NS_CreateSmsService();
|
||||
%}
|
@ -1,30 +0,0 @@
|
||||
/* 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"
|
||||
|
||||
/**
|
||||
* Handle WAP Push notifications.
|
||||
*/
|
||||
[scriptable, uuid(fd6f7f6b-a67e-4892-930d-fca864df8fe7)]
|
||||
interface nsIWapPushApplication : nsISupports
|
||||
{
|
||||
/**
|
||||
* Receive WAP Push message.
|
||||
*
|
||||
* @param aData
|
||||
* An array containing raw PDU data.
|
||||
* @param aLength
|
||||
* Length of aData.
|
||||
* @param aOffset
|
||||
* Start offset of aData containing message body of the Push PDU.
|
||||
* @param options
|
||||
* An object containing various attributes from lower transport layer.
|
||||
*/
|
||||
void receiveWapPush([array, size_is(aLength)] in octet aData,
|
||||
in unsigned long aLength,
|
||||
in unsigned long aOffset,
|
||||
in jsval aOptions);
|
||||
};
|
||||
|
@ -1,33 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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 protocol PSms;
|
||||
include protocol PBlob;
|
||||
include SmsTypes;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
protocol PMobileMessageCursor
|
||||
{
|
||||
manager PSms;
|
||||
|
||||
child:
|
||||
async NotifyResult(MobileMessageCursorData aData);
|
||||
|
||||
/**
|
||||
* Sent when the asynchronous cursor request has completed.
|
||||
*/
|
||||
async __delete__(int32_t aError);
|
||||
|
||||
parent:
|
||||
async Continue();
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,158 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et ft=cpp : */
|
||||
/* 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 protocol PContent;
|
||||
include protocol PSmsRequest;
|
||||
include protocol PMobileMessageCursor;
|
||||
include protocol PBlob;
|
||||
include SmsTypes;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
struct SendMmsMessageRequest
|
||||
{
|
||||
uint32_t serviceId;
|
||||
nsString[] receivers;
|
||||
nsString subject;
|
||||
nsString smil;
|
||||
MmsAttachmentData[] attachments;
|
||||
};
|
||||
|
||||
struct SendSmsMessageRequest
|
||||
{
|
||||
uint32_t serviceId;
|
||||
nsString number;
|
||||
nsString message;
|
||||
bool silent;
|
||||
};
|
||||
|
||||
union SendMessageRequest
|
||||
{
|
||||
SendMmsMessageRequest;
|
||||
SendSmsMessageRequest;
|
||||
};
|
||||
|
||||
struct RetrieveMessageRequest
|
||||
{
|
||||
int32_t messageId;
|
||||
};
|
||||
|
||||
struct GetMessageRequest
|
||||
{
|
||||
int32_t messageId;
|
||||
};
|
||||
|
||||
struct DeleteMessageRequest
|
||||
{
|
||||
int32_t[] messageIds;
|
||||
};
|
||||
|
||||
struct CreateMessageCursorRequest
|
||||
{
|
||||
SmsFilterData filter;
|
||||
bool reverse;
|
||||
};
|
||||
|
||||
struct MarkMessageReadRequest
|
||||
{
|
||||
int32_t messageId;
|
||||
bool value;
|
||||
bool sendReadReport;
|
||||
};
|
||||
|
||||
struct GetSegmentInfoForTextRequest
|
||||
{
|
||||
nsString text;
|
||||
};
|
||||
|
||||
struct CreateThreadCursorRequest
|
||||
{
|
||||
};
|
||||
|
||||
struct GetSmscAddressRequest
|
||||
{
|
||||
uint32_t serviceId;
|
||||
};
|
||||
|
||||
struct SetSmscAddressRequest
|
||||
{
|
||||
uint32_t serviceId;
|
||||
nsString number;
|
||||
uint32_t typeOfNumber;
|
||||
uint32_t numberPlanIdentification;
|
||||
};
|
||||
|
||||
union IPCSmsRequest
|
||||
{
|
||||
SendMessageRequest;
|
||||
RetrieveMessageRequest;
|
||||
GetMessageRequest;
|
||||
DeleteMessageRequest;
|
||||
MarkMessageReadRequest;
|
||||
GetSegmentInfoForTextRequest;
|
||||
GetSmscAddressRequest;
|
||||
SetSmscAddressRequest;
|
||||
};
|
||||
|
||||
union IPCMobileMessageCursor
|
||||
{
|
||||
CreateMessageCursorRequest;
|
||||
CreateThreadCursorRequest;
|
||||
};
|
||||
|
||||
sync protocol PSms {
|
||||
manager PContent;
|
||||
manages PSmsRequest;
|
||||
manages PMobileMessageCursor;
|
||||
|
||||
child:
|
||||
async NotifyReceivedMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyRetrievingMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifySendingMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifySentMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyFailedMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyDeliverySuccessMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyDeliveryErrorMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyReceivedSilentMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyReadSuccessMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyReadErrorMessage(MobileMessageData aMessageData);
|
||||
|
||||
async NotifyDeletedMessageInfo(DeletedMessageInfoData aDeletedInfo);
|
||||
|
||||
parent:
|
||||
/**
|
||||
* Sent when the child no longer needs to use sms.
|
||||
*/
|
||||
async __delete__();
|
||||
|
||||
/**
|
||||
* Sent when the child makes an asynchronous request to the parent.
|
||||
*/
|
||||
async PSmsRequest(IPCSmsRequest request);
|
||||
|
||||
/**
|
||||
* Sent when the child makes an asynchronous cursor to the parent.
|
||||
*/
|
||||
async PMobileMessageCursor(IPCMobileMessageCursor request);
|
||||
|
||||
async AddSilentNumber(nsString aNumber);
|
||||
async RemoveSilentNumber(nsString aNumber);
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,128 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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 protocol PSms;
|
||||
include protocol PBlob;
|
||||
include SmsTypes;
|
||||
|
||||
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
protocol PSmsRequest
|
||||
{
|
||||
manager PSms;
|
||||
|
||||
child:
|
||||
/**
|
||||
* Sent when the asynchronous request has completed.
|
||||
*/
|
||||
async __delete__(MessageReply response);
|
||||
};
|
||||
|
||||
struct ReplyMessageSend
|
||||
{
|
||||
MobileMessageData messageData;
|
||||
};
|
||||
|
||||
union OptionalMobileMessageData
|
||||
{
|
||||
void_t;
|
||||
MobileMessageData;
|
||||
};
|
||||
|
||||
struct ReplyMessageSendFail
|
||||
{
|
||||
int32_t error;
|
||||
OptionalMobileMessageData messageData;
|
||||
};
|
||||
|
||||
struct ReplyGetMessage
|
||||
{
|
||||
MobileMessageData messageData;
|
||||
};
|
||||
|
||||
struct ReplyGetMessageFail
|
||||
{
|
||||
int32_t error;
|
||||
};
|
||||
|
||||
struct ReplyMessageDelete
|
||||
{
|
||||
bool[] deleted;
|
||||
};
|
||||
|
||||
struct ReplyMessageDeleteFail
|
||||
{
|
||||
int32_t error;
|
||||
};
|
||||
|
||||
struct ReplyMarkeMessageRead
|
||||
{
|
||||
bool read;
|
||||
};
|
||||
|
||||
struct ReplyMarkeMessageReadFail
|
||||
{
|
||||
int32_t error;
|
||||
};
|
||||
|
||||
struct ReplyGetSegmentInfoForText
|
||||
{
|
||||
int32_t segments;
|
||||
int32_t charsPerSegment;
|
||||
int32_t charsAvailableInLastSegment;
|
||||
};
|
||||
|
||||
struct ReplyGetSegmentInfoForTextFail
|
||||
{
|
||||
int32_t error;
|
||||
};
|
||||
|
||||
struct ReplyGetSmscAddress
|
||||
{
|
||||
nsString smscAddress;
|
||||
uint32_t typeOfNumber;
|
||||
uint32_t numberPlanIdentification;
|
||||
};
|
||||
|
||||
struct ReplyGetSmscAddressFail
|
||||
{
|
||||
int32_t error;
|
||||
};
|
||||
|
||||
struct ReplySetSmscAddress
|
||||
{
|
||||
};
|
||||
|
||||
struct ReplySetSmscAddressFail
|
||||
{
|
||||
int32_t error;
|
||||
};
|
||||
|
||||
union MessageReply
|
||||
{
|
||||
ReplyMessageSend;
|
||||
ReplyMessageSendFail;
|
||||
ReplyGetMessage;
|
||||
ReplyGetMessageFail;
|
||||
ReplyMessageDelete;
|
||||
ReplyMessageDeleteFail;
|
||||
ReplyMarkeMessageRead;
|
||||
ReplyMarkeMessageReadFail;
|
||||
ReplyGetSegmentInfoForText;
|
||||
ReplyGetSegmentInfoForTextFail;
|
||||
ReplyGetSmscAddress;
|
||||
ReplyGetSmscAddressFail;
|
||||
ReplySetSmscAddress;
|
||||
ReplySetSmscAddressFail;
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,391 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "SmsChild.h"
|
||||
|
||||
#include "SmsMessageInternal.h"
|
||||
#include "MmsMessageInternal.h"
|
||||
#include "DeletedMessageInfo.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
||||
#include "MobileMessageThreadInternal.h"
|
||||
#include "MainThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
|
||||
namespace {
|
||||
|
||||
already_AddRefed<nsISupports>
|
||||
CreateMessageFromMessageData(const MobileMessageData& aData)
|
||||
{
|
||||
nsCOMPtr<nsISupports> message;
|
||||
|
||||
switch(aData.type()) {
|
||||
case MobileMessageData::TMmsMessageData:
|
||||
message = new MmsMessageInternal(aData.get_MmsMessageData());
|
||||
break;
|
||||
case MobileMessageData::TSmsMessageData:
|
||||
message = new SmsMessageInternal(aData.get_SmsMessageData());
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Unexpected type of MobileMessageData");
|
||||
}
|
||||
|
||||
return message.forget();
|
||||
}
|
||||
|
||||
void
|
||||
NotifyObserversWithMobileMessage(const char* aEventName,
|
||||
const MobileMessageData& aData)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> msg = CreateMessageFromMessageData(aData);
|
||||
obs->NotifyObservers(msg, aEventName, nullptr);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
void
|
||||
SmsChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyReceivedMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsReceivedObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyRetrievingMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsRetrievingObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifySendingMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsSendingObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifySentMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsSentObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyFailedMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsFailedObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyDeliverySuccessMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsDeliverySuccessObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyDeliveryErrorMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsDeliveryErrorObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyReceivedSilentMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSilentSmsReceivedObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyReadSuccessMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsReadSuccessObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyReadErrorMessage(const MobileMessageData& aData)
|
||||
{
|
||||
NotifyObserversWithMobileMessage(kSmsReadErrorObserverTopic, aData);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::RecvNotifyDeletedMessageInfo(const DeletedMessageInfoData& aDeletedInfo)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
NS_ERROR("Failed to get nsIObserverService!");
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> info = new DeletedMessageInfo(aDeletedInfo);
|
||||
obs->NotifyObservers(info, kSmsDeletedObserverTopic, nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PSmsRequestChild*
|
||||
SmsChild::AllocPSmsRequestChild(const IPCSmsRequest& aRequest)
|
||||
{
|
||||
MOZ_CRASH("Caller is supposed to manually construct a request!");
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::DeallocPSmsRequestChild(PSmsRequestChild* aActor)
|
||||
{
|
||||
delete aActor;
|
||||
return true;
|
||||
}
|
||||
|
||||
PMobileMessageCursorChild*
|
||||
SmsChild::AllocPMobileMessageCursorChild(const IPCMobileMessageCursor& aCursor)
|
||||
{
|
||||
MOZ_CRASH("Caller is supposed to manually construct a cursor!");
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::DeallocPMobileMessageCursorChild(PMobileMessageCursorChild* aActor)
|
||||
{
|
||||
// MobileMessageCursorChild is refcounted, must not be freed manually.
|
||||
// Originally AddRefed in SendCursorRequest() in SmsIPCService.cpp.
|
||||
static_cast<MobileMessageCursorChild*>(aActor)->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* SmsRequestChild
|
||||
******************************************************************************/
|
||||
|
||||
SmsRequestChild::SmsRequestChild(nsIMobileMessageCallback* aReplyRequest)
|
||||
: mReplyRequest(aReplyRequest)
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsRequestChild);
|
||||
MOZ_ASSERT(aReplyRequest);
|
||||
}
|
||||
|
||||
void
|
||||
SmsRequestChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
// Nothing needed here.
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestChild::Recv__delete__(const MessageReply& aReply)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mReplyRequest);
|
||||
switch(aReply.type()) {
|
||||
case MessageReply::TReplyMessageSend: {
|
||||
const MobileMessageData& data =
|
||||
aReply.get_ReplyMessageSend().messageData();
|
||||
nsCOMPtr<nsISupports> msg = CreateMessageFromMessageData(data);
|
||||
mReplyRequest->NotifyMessageSent(msg);
|
||||
}
|
||||
break;
|
||||
case MessageReply::TReplyMessageSendFail: {
|
||||
const ReplyMessageSendFail &replyFail = aReply.get_ReplyMessageSendFail();
|
||||
nsCOMPtr<nsISupports> msg;
|
||||
|
||||
if (replyFail.messageData().type() ==
|
||||
OptionalMobileMessageData::TMobileMessageData) {
|
||||
msg = CreateMessageFromMessageData(
|
||||
replyFail.messageData().get_MobileMessageData());
|
||||
}
|
||||
|
||||
mReplyRequest->NotifySendMessageFailed(replyFail.error(), msg);
|
||||
}
|
||||
break;
|
||||
case MessageReply::TReplyGetMessage: {
|
||||
const MobileMessageData& data =
|
||||
aReply.get_ReplyGetMessage().messageData();
|
||||
nsCOMPtr<nsISupports> msg = CreateMessageFromMessageData(data);
|
||||
mReplyRequest->NotifyMessageGot(msg);
|
||||
}
|
||||
break;
|
||||
case MessageReply::TReplyGetMessageFail:
|
||||
mReplyRequest->NotifyGetMessageFailed(aReply.get_ReplyGetMessageFail().error());
|
||||
break;
|
||||
case MessageReply::TReplyMessageDelete: {
|
||||
const InfallibleTArray<bool>& deletedResult = aReply.get_ReplyMessageDelete().deleted();
|
||||
mReplyRequest->NotifyMessageDeleted(const_cast<bool *>(deletedResult.Elements()),
|
||||
deletedResult.Length());
|
||||
}
|
||||
break;
|
||||
case MessageReply::TReplyMessageDeleteFail:
|
||||
mReplyRequest->NotifyDeleteMessageFailed(aReply.get_ReplyMessageDeleteFail().error());
|
||||
break;
|
||||
case MessageReply::TReplyMarkeMessageRead:
|
||||
mReplyRequest->NotifyMessageMarkedRead(aReply.get_ReplyMarkeMessageRead().read());
|
||||
break;
|
||||
case MessageReply::TReplyMarkeMessageReadFail:
|
||||
mReplyRequest->NotifyMarkMessageReadFailed(aReply.get_ReplyMarkeMessageReadFail().error());
|
||||
break;
|
||||
case MessageReply::TReplyGetSegmentInfoForText: {
|
||||
const ReplyGetSegmentInfoForText& reply =
|
||||
aReply.get_ReplyGetSegmentInfoForText();
|
||||
mReplyRequest->NotifySegmentInfoForTextGot(reply.segments(),
|
||||
reply.charsPerSegment(),
|
||||
reply.charsAvailableInLastSegment());
|
||||
}
|
||||
break;
|
||||
case MessageReply::TReplyGetSegmentInfoForTextFail:
|
||||
mReplyRequest->NotifyGetSegmentInfoForTextFailed(
|
||||
aReply.get_ReplyGetSegmentInfoForTextFail().error());
|
||||
break;
|
||||
case MessageReply::TReplyGetSmscAddress:
|
||||
mReplyRequest->NotifyGetSmscAddress(aReply.get_ReplyGetSmscAddress().smscAddress(),
|
||||
aReply.get_ReplyGetSmscAddress().typeOfNumber(),
|
||||
aReply.get_ReplyGetSmscAddress().numberPlanIdentification());
|
||||
break;
|
||||
case MessageReply::TReplyGetSmscAddressFail:
|
||||
mReplyRequest->NotifyGetSmscAddressFailed(aReply.get_ReplyGetSmscAddressFail().error());
|
||||
break;
|
||||
case MessageReply::TReplySetSmscAddress:
|
||||
mReplyRequest->NotifySetSmscAddress();
|
||||
break;
|
||||
case MessageReply::TReplySetSmscAddressFail:
|
||||
mReplyRequest->NotifySetSmscAddressFailed(aReply.get_ReplySetSmscAddressFail().error());
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Received invalid response parameters!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* MobileMessageCursorChild
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS(MobileMessageCursorChild, nsICursorContinueCallback)
|
||||
|
||||
MobileMessageCursorChild::MobileMessageCursorChild(nsIMobileMessageCursorCallback* aCallback)
|
||||
: mCursorCallback(aCallback)
|
||||
{
|
||||
MOZ_COUNT_CTOR(MobileMessageCursorChild);
|
||||
MOZ_ASSERT(aCallback);
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageCursorChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
// Nothing needed here.
|
||||
}
|
||||
|
||||
bool
|
||||
MobileMessageCursorChild::RecvNotifyResult(const MobileMessageCursorData& aData)
|
||||
{
|
||||
MOZ_ASSERT(mCursorCallback);
|
||||
|
||||
switch(aData.type()) {
|
||||
case MobileMessageCursorData::TMobileMessageArrayData:
|
||||
DoNotifyResult(aData.get_MobileMessageArrayData().messages());
|
||||
break;
|
||||
case MobileMessageCursorData::TThreadArrayData:
|
||||
DoNotifyResult(aData.get_ThreadArrayData().threads());
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Received invalid response parameters!");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileMessageCursorChild::Recv__delete__(const int32_t& aError)
|
||||
{
|
||||
MOZ_ASSERT(mCursorCallback);
|
||||
|
||||
if (aError != nsIMobileMessageCallback::SUCCESS_NO_ERROR) {
|
||||
mCursorCallback->NotifyCursorError(aError);
|
||||
} else {
|
||||
mCursorCallback->NotifyCursorDone();
|
||||
}
|
||||
mCursorCallback = nullptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// nsICursorContinueCallback
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorChild::HandleContinue()
|
||||
{
|
||||
MOZ_ASSERT(mCursorCallback);
|
||||
|
||||
SendContinue();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageCursorChild::DoNotifyResult(const nsTArray<MobileMessageData>& aDataArray)
|
||||
{
|
||||
const uint32_t length = aDataArray.Length();
|
||||
MOZ_ASSERT(length);
|
||||
|
||||
AutoTArray<nsISupports*, 1> autoArray;
|
||||
NS_ENSURE_TRUE_VOID(autoArray.SetCapacity(length, fallible));
|
||||
|
||||
AutoTArray<nsCOMPtr<nsISupports>, 1> messages;
|
||||
NS_ENSURE_TRUE_VOID(messages.SetCapacity(length, fallible));
|
||||
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
nsCOMPtr<nsISupports> message = CreateMessageFromMessageData(aDataArray[i]);
|
||||
NS_ENSURE_TRUE_VOID(messages.AppendElement(message, fallible));
|
||||
NS_ENSURE_TRUE_VOID(autoArray.AppendElement(message.get(), fallible));
|
||||
}
|
||||
|
||||
mCursorCallback->NotifyCursorResult(autoArray.Elements(), length);
|
||||
}
|
||||
|
||||
void
|
||||
MobileMessageCursorChild::DoNotifyResult(const nsTArray<ThreadData>& aDataArray)
|
||||
{
|
||||
const uint32_t length = aDataArray.Length();
|
||||
MOZ_ASSERT(length);
|
||||
|
||||
AutoTArray<nsISupports*, 1> autoArray;
|
||||
NS_ENSURE_TRUE_VOID(autoArray.SetCapacity(length, fallible));
|
||||
|
||||
AutoTArray<nsCOMPtr<nsISupports>, 1> threads;
|
||||
NS_ENSURE_TRUE_VOID(threads.SetCapacity(length, fallible));
|
||||
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
nsCOMPtr<nsISupports> thread =
|
||||
new MobileMessageThreadInternal(aDataArray[i]);
|
||||
NS_ENSURE_TRUE_VOID(threads.AppendElement(thread, fallible));
|
||||
NS_ENSURE_TRUE_VOID(autoArray.AppendElement(thread.get(), fallible));
|
||||
}
|
||||
|
||||
mCursorCallback->NotifyCursorResult(autoArray.Elements(), length);
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,146 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_SmsChild_h
|
||||
#define mozilla_dom_mobilemessage_SmsChild_h
|
||||
|
||||
#include "mozilla/dom/mobilemessage/PSmsChild.h"
|
||||
#include "mozilla/dom/mobilemessage/PSmsRequestChild.h"
|
||||
#include "mozilla/dom/mobilemessage/PMobileMessageCursorChild.h"
|
||||
#include "nsIDOMDOMCursor.h"
|
||||
#include "nsIMobileMessageCallback.h"
|
||||
#include "nsIMobileMessageCursorCallback.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class SmsChild : public PSmsChild
|
||||
{
|
||||
public:
|
||||
SmsChild()
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsChild);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~SmsChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsChild);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyReceivedMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyRetrievingMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifySendingMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifySentMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyFailedMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyDeliverySuccessMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyDeliveryErrorMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyReceivedSilentMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyReadSuccessMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyReadErrorMessage(const MobileMessageData& aMessage) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyDeletedMessageInfo(const DeletedMessageInfoData& aDeletedInfo) override;
|
||||
|
||||
virtual PSmsRequestChild*
|
||||
AllocPSmsRequestChild(const IPCSmsRequest& aRequest) override;
|
||||
|
||||
virtual bool
|
||||
DeallocPSmsRequestChild(PSmsRequestChild* aActor) override;
|
||||
|
||||
virtual PMobileMessageCursorChild*
|
||||
AllocPMobileMessageCursorChild(const IPCMobileMessageCursor& aCursor) override;
|
||||
|
||||
virtual bool
|
||||
DeallocPMobileMessageCursorChild(PMobileMessageCursorChild* aActor) override;
|
||||
};
|
||||
|
||||
class SmsRequestChild : public PSmsRequestChild
|
||||
{
|
||||
friend class SmsChild;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCallback> mReplyRequest;
|
||||
|
||||
public:
|
||||
explicit SmsRequestChild(nsIMobileMessageCallback* aReplyRequest);
|
||||
|
||||
protected:
|
||||
virtual ~SmsRequestChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsRequestChild);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual bool
|
||||
Recv__delete__(const MessageReply& aReply) override;
|
||||
};
|
||||
|
||||
class MobileMessageCursorChild : public PMobileMessageCursorChild
|
||||
, public nsICursorContinueCallback
|
||||
{
|
||||
friend class SmsChild;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCursorCallback> mCursorCallback;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICURSORCONTINUECALLBACK
|
||||
|
||||
explicit MobileMessageCursorChild(nsIMobileMessageCursorCallback* aCallback);
|
||||
|
||||
protected:
|
||||
virtual ~MobileMessageCursorChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(MobileMessageCursorChild);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyResult(const MobileMessageCursorData& aData) override;
|
||||
|
||||
virtual bool
|
||||
Recv__delete__(const int32_t& aError) override;
|
||||
|
||||
private:
|
||||
void
|
||||
DoNotifyResult(const nsTArray<MobileMessageData>& aData);
|
||||
|
||||
void
|
||||
DoNotifyResult(const nsTArray<ThreadData>& aData);
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_SmsChild_h
|
@ -1,396 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "mozilla/dom/ContentChild.h"
|
||||
#include "SmsIPCService.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
#include "mozilla/dom/mobilemessage/SmsChild.h"
|
||||
#include "nsJSUtils.h"
|
||||
#include "mozilla/dom/MozMobileMessageManagerBinding.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsString.h"
|
||||
#include "mozilla/dom/ipc/BlobChild.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
|
||||
namespace {
|
||||
|
||||
#define kPrefMmsDefaultServiceId "dom.mms.defaultServiceId"
|
||||
#define kPrefSmsDefaultServiceId "dom.sms.defaultServiceId"
|
||||
|
||||
// TODO: Bug 767082 - WebSMS: sSmsChild leaks at shutdown
|
||||
PSmsChild* gSmsChild;
|
||||
|
||||
// SmsIPCService is owned by nsLayoutModule.
|
||||
SmsIPCService* sSingleton = nullptr;
|
||||
|
||||
PSmsChild*
|
||||
GetSmsChild()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!gSmsChild) {
|
||||
gSmsChild = ContentChild::GetSingleton()->SendPSmsConstructor();
|
||||
|
||||
NS_WARNING_ASSERTION(gSmsChild,
|
||||
"Calling methods on SmsIPCService during shutdown!");
|
||||
}
|
||||
|
||||
return gSmsChild;
|
||||
}
|
||||
|
||||
nsresult
|
||||
SendRequest(const IPCSmsRequest& aRequest,
|
||||
nsIMobileMessageCallback* aRequestReply)
|
||||
{
|
||||
PSmsChild* smsChild = GetSmsChild();
|
||||
NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
|
||||
|
||||
SmsRequestChild* actor = new SmsRequestChild(aRequestReply);
|
||||
smsChild->SendPSmsRequestConstructor(actor, aRequest);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
SendCursorRequest(const IPCMobileMessageCursor& aRequest,
|
||||
nsIMobileMessageCursorCallback* aRequestReply,
|
||||
nsICursorContinueCallback** aResult)
|
||||
{
|
||||
PSmsChild* smsChild = GetSmsChild();
|
||||
NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
|
||||
|
||||
RefPtr<MobileMessageCursorChild> actor =
|
||||
new MobileMessageCursorChild(aRequestReply);
|
||||
|
||||
// Add an extra ref for IPDL. Will be released in
|
||||
// SmsChild::DeallocPMobileMessageCursor().
|
||||
RefPtr<MobileMessageCursorChild> actorCopy(actor);
|
||||
mozilla::Unused << actorCopy.forget().take();
|
||||
|
||||
smsChild->SendPMobileMessageCursorConstructor(actor, aRequest);
|
||||
|
||||
actor.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
getDefaultServiceId(const char* aPrefKey)
|
||||
{
|
||||
static const char* kPrefRilNumRadioInterfaces = "ril.numRadioInterfaces";
|
||||
int32_t id = mozilla::Preferences::GetInt(aPrefKey, 0);
|
||||
int32_t numRil = mozilla::Preferences::GetInt(kPrefRilNumRadioInterfaces, 1);
|
||||
|
||||
if (id >= numRil || id < 0) {
|
||||
id = 0;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS(SmsIPCService,
|
||||
nsISmsService,
|
||||
nsIMmsService,
|
||||
nsIMobileMessageDatabaseService,
|
||||
nsIObserver)
|
||||
|
||||
/* static */ already_AddRefed<SmsIPCService>
|
||||
SmsIPCService::GetSingleton()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!sSingleton) {
|
||||
sSingleton = new SmsIPCService();
|
||||
}
|
||||
|
||||
RefPtr<SmsIPCService> service = sSingleton;
|
||||
return service.forget();
|
||||
}
|
||||
|
||||
SmsIPCService::SmsIPCService()
|
||||
{
|
||||
static const char* kObservedPrefs[] = {
|
||||
kPrefMmsDefaultServiceId,
|
||||
kPrefSmsDefaultServiceId,
|
||||
nullptr
|
||||
};
|
||||
Preferences::AddStrongObservers(this, kObservedPrefs);
|
||||
mMmsDefaultServiceId = getDefaultServiceId(kPrefMmsDefaultServiceId);
|
||||
mSmsDefaultServiceId = getDefaultServiceId(kPrefSmsDefaultServiceId);
|
||||
}
|
||||
|
||||
SmsIPCService::~SmsIPCService()
|
||||
{
|
||||
sSingleton = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation of nsIObserver.
|
||||
*/
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
||||
nsDependentString data(aData);
|
||||
if (data.EqualsLiteral(kPrefMmsDefaultServiceId)) {
|
||||
mMmsDefaultServiceId = getDefaultServiceId(kPrefMmsDefaultServiceId);
|
||||
} else if (data.EqualsLiteral(kPrefSmsDefaultServiceId)) {
|
||||
mSmsDefaultServiceId = getDefaultServiceId(kPrefSmsDefaultServiceId);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(false, "SmsIPCService got unexpected topic!");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation of nsISmsService.
|
||||
*/
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::GetSmsDefaultServiceId(uint32_t* aServiceId)
|
||||
{
|
||||
*aServiceId = mSmsDefaultServiceId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::GetSegmentInfoForText(const nsAString& aText,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
return SendRequest(GetSegmentInfoForTextRequest(nsString(aText)),
|
||||
aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::GetSmscAddress(uint32_t aServiceId,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
return SendRequest(GetSmscAddressRequest(aServiceId), aRequest);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::SetSmscAddress(uint32_t aServiceId,
|
||||
const nsAString& aNumber,
|
||||
uint32_t aTypeOfNumber,
|
||||
uint32_t aNumberPlanIdentification,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
return SendRequest(SetSmscAddressRequest(aServiceId,
|
||||
nsString(aNumber),
|
||||
aTypeOfNumber,
|
||||
aNumberPlanIdentification),
|
||||
aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::Send(uint32_t aServiceId,
|
||||
const nsAString& aNumber,
|
||||
const nsAString& aMessage,
|
||||
bool aSilent,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
return SendRequest(SendMessageRequest(SendSmsMessageRequest(aServiceId,
|
||||
nsString(aNumber),
|
||||
nsString(aMessage),
|
||||
aSilent)),
|
||||
aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::AddSilentNumber(const nsAString& aNumber)
|
||||
{
|
||||
PSmsChild* smsChild = GetSmsChild();
|
||||
NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
|
||||
|
||||
smsChild->SendAddSilentNumber(nsString(aNumber));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::RemoveSilentNumber(const nsAString& aNumber)
|
||||
{
|
||||
PSmsChild* smsChild = GetSmsChild();
|
||||
NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
|
||||
|
||||
smsChild->SendRemoveSilentNumber(nsString(aNumber));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation of nsIMobileMessageDatabaseService.
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::GetMessageMoz(int32_t aMessageId,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
return SendRequest(GetMessageRequest(aMessageId), aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::DeleteMessage(int32_t *aMessageIds, uint32_t aSize,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
DeleteMessageRequest data;
|
||||
data.messageIds().AppendElements(aMessageIds, aSize);
|
||||
return SendRequest(data, aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::CreateMessageCursor(bool aHasStartDate,
|
||||
uint64_t aStartDate,
|
||||
bool aHasEndDate,
|
||||
uint64_t aEndDate,
|
||||
const char16_t** aNumbers,
|
||||
uint32_t aNumbersCount,
|
||||
const nsAString& aDelivery,
|
||||
bool aHasRead,
|
||||
bool aRead,
|
||||
bool aHasThreadId,
|
||||
uint64_t aThreadId,
|
||||
bool aReverse,
|
||||
nsIMobileMessageCursorCallback* aCursorCallback,
|
||||
nsICursorContinueCallback** aResult)
|
||||
{
|
||||
SmsFilterData data;
|
||||
|
||||
data.hasStartDate() = aHasStartDate;
|
||||
data.startDate() = aStartDate;
|
||||
data.hasEndDate() = aHasEndDate;
|
||||
data.endDate() = aEndDate;
|
||||
|
||||
if (aNumbersCount && aNumbers) {
|
||||
nsTArray<nsString>& numbers = data.numbers();
|
||||
uint32_t index;
|
||||
|
||||
for (index = 0; index < aNumbersCount; index++) {
|
||||
numbers.AppendElement(aNumbers[index]);
|
||||
}
|
||||
}
|
||||
|
||||
data.delivery() = aDelivery;
|
||||
data.hasRead() = aHasRead;
|
||||
data.read() = aRead;
|
||||
data.hasThreadId() = aHasThreadId;
|
||||
data.threadId() = aThreadId;
|
||||
|
||||
return SendCursorRequest(CreateMessageCursorRequest(data, aReverse),
|
||||
aCursorCallback, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::MarkMessageRead(int32_t aMessageId,
|
||||
bool aValue,
|
||||
bool aSendReadReport,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
return SendRequest(MarkMessageReadRequest(aMessageId, aValue, aSendReadReport), aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::CreateThreadCursor(nsIMobileMessageCursorCallback* aCursorCallback,
|
||||
nsICursorContinueCallback** aResult)
|
||||
{
|
||||
return SendCursorRequest(CreateThreadCursorRequest(), aCursorCallback,
|
||||
aResult);
|
||||
}
|
||||
|
||||
bool
|
||||
GetSendMmsMessageRequestFromParams(uint32_t aServiceId,
|
||||
const JS::Value& aParam,
|
||||
SendMmsMessageRequest& request) {
|
||||
if (aParam.isUndefined() || aParam.isNull() || !aParam.isObject()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::AutoJSContext cx;
|
||||
JS::Rooted<JS::Value> param(cx, aParam);
|
||||
RootedDictionary<MmsParameters> params(cx);
|
||||
if (!params.Init(cx, param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// SendMobileMessageRequest.receivers
|
||||
if (!params.mReceivers.WasPassed()) {
|
||||
return false;
|
||||
}
|
||||
request.receivers().AppendElements(params.mReceivers.Value());
|
||||
|
||||
// SendMobileMessageRequest.attachments
|
||||
mozilla::dom::ContentChild* cc = mozilla::dom::ContentChild::GetSingleton();
|
||||
|
||||
if (!params.mAttachments.WasPassed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < params.mAttachments.Value().Length(); i++) {
|
||||
mozilla::dom::MmsAttachment& attachment = params.mAttachments.Value()[i];
|
||||
MmsAttachmentData mmsAttachment;
|
||||
mmsAttachment.id().Assign(attachment.mId);
|
||||
mmsAttachment.location().Assign(attachment.mLocation);
|
||||
mmsAttachment.contentChild() = cc->GetOrCreateActorForBlob(attachment.mContent);
|
||||
if (!mmsAttachment.contentChild()) {
|
||||
return false;
|
||||
}
|
||||
request.attachments().AppendElement(mmsAttachment);
|
||||
}
|
||||
|
||||
request.smil() = params.mSmil;
|
||||
request.subject() = params.mSubject;
|
||||
|
||||
// Set service ID.
|
||||
request.serviceId() = aServiceId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation of nsIMmsService.
|
||||
*/
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::GetMmsDefaultServiceId(uint32_t* aServiceId)
|
||||
{
|
||||
*aServiceId = mMmsDefaultServiceId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::Send(uint32_t aServiceId,
|
||||
JS::Handle<JS::Value> aParameters,
|
||||
nsIMobileMessageCallback *aRequest)
|
||||
{
|
||||
SendMmsMessageRequest req;
|
||||
if (!GetSendMmsMessageRequestFromParams(aServiceId, aParameters, req)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
return SendRequest(SendMessageRequest(req), aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::Retrieve(int32_t aId, nsIMobileMessageCallback *aRequest)
|
||||
{
|
||||
return SendRequest(RetrieveMessageRequest(aId), aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::SendReadReport(const nsAString & messageID,
|
||||
const nsAString & toAddress,
|
||||
const nsAString & iccId)
|
||||
{
|
||||
NS_ERROR("We should not be here!");
|
||||
return NS_OK;
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_SmsIPCService_h
|
||||
#define mozilla_dom_mobilemessage_SmsIPCService_h
|
||||
|
||||
#include "nsISmsService.h"
|
||||
#include "nsIMmsService.h"
|
||||
#include "nsIMobileMessageDatabaseService.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
class SmsIPCService final : public nsISmsService
|
||||
, public nsIMmsService
|
||||
, public nsIMobileMessageDatabaseService
|
||||
, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISMSSERVICE
|
||||
NS_DECL_NSIMMSSERVICE
|
||||
NS_DECL_NSIMOBILEMESSAGEDATABASESERVICE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
static already_AddRefed<SmsIPCService>
|
||||
GetSingleton();
|
||||
|
||||
private:
|
||||
SmsIPCService();
|
||||
|
||||
// final suppresses -Werror,-Wdelete-non-virtual-dtor
|
||||
~SmsIPCService();
|
||||
|
||||
uint32_t mMmsDefaultServiceId;
|
||||
uint32_t mSmsDefaultServiceId;
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_SmsIPCService_h
|
@ -1,967 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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 "SmsParent.h"
|
||||
|
||||
#include "nsISmsService.h"
|
||||
#include "nsIMmsService.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsISmsMessage.h"
|
||||
#include "nsIMmsMessage.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "SmsMessageInternal.h"
|
||||
#include "MmsMessageInternal.h"
|
||||
#include "nsIMobileMessageDatabaseService.h"
|
||||
#include "MobileMessageThreadInternal.h"
|
||||
#include "mozilla/dom/ipc/BlobParent.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/ToJSValue.h"
|
||||
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsTArrayHelpers.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "DeletedMessageInfo.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
static JSObject*
|
||||
MmsAttachmentDataToJSObject(JSContext* aContext,
|
||||
const MmsAttachmentData& aAttachment)
|
||||
{
|
||||
JS::Rooted<JSObject*> obj(aContext, JS_NewPlainObject(aContext));
|
||||
NS_ENSURE_TRUE(obj, nullptr);
|
||||
|
||||
JS::Rooted<JSString*> idStr(aContext, JS_NewUCStringCopyN(aContext,
|
||||
aAttachment.id().get(),
|
||||
aAttachment.id().Length()));
|
||||
NS_ENSURE_TRUE(idStr, nullptr);
|
||||
if (!JS_DefineProperty(aContext, obj, "id", idStr, 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
JS::Rooted<JSString*> locStr(aContext, JS_NewUCStringCopyN(aContext,
|
||||
aAttachment.location().get(),
|
||||
aAttachment.location().Length()));
|
||||
NS_ENSURE_TRUE(locStr, nullptr);
|
||||
if (!JS_DefineProperty(aContext, obj, "location", locStr, 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<BlobImpl> blobImpl = static_cast<BlobParent*>(aAttachment.contentParent())->GetBlobImpl();
|
||||
|
||||
// RefPtr<File> needs to go out of scope before toObjectOrNull() is
|
||||
// called because the static analysis thinks dereferencing XPCOM objects
|
||||
// can GC (because in some cases it can!), and a return statement with a
|
||||
// JSObject* type means that JSObject* is on the stack as a raw pointer
|
||||
// while destructors are running.
|
||||
JS::Rooted<JS::Value> content(aContext);
|
||||
{
|
||||
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext));
|
||||
MOZ_ASSERT(global);
|
||||
|
||||
RefPtr<Blob> blob = Blob::Create(global, blobImpl);
|
||||
if (!ToJSValue(aContext, blob, &content)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
if (!JS_DefineProperty(aContext, obj, "content", content, 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetParamsFromSendMmsMessageRequest(JSContext* aCx,
|
||||
const SendMmsMessageRequest& aRequest,
|
||||
JS::Value* aParam)
|
||||
{
|
||||
JS::Rooted<JSObject*> paramsObj(aCx, JS_NewPlainObject(aCx));
|
||||
NS_ENSURE_TRUE(paramsObj, false);
|
||||
|
||||
// smil
|
||||
JS::Rooted<JSString*> smilStr(aCx, JS_NewUCStringCopyN(aCx,
|
||||
aRequest.smil().get(),
|
||||
aRequest.smil().Length()));
|
||||
NS_ENSURE_TRUE(smilStr, false);
|
||||
if(!JS_DefineProperty(aCx, paramsObj, "smil", smilStr, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// subject
|
||||
JS::Rooted<JSString*> subjectStr(aCx, JS_NewUCStringCopyN(aCx,
|
||||
aRequest.subject().get(),
|
||||
aRequest.subject().Length()));
|
||||
NS_ENSURE_TRUE(subjectStr, false);
|
||||
if(!JS_DefineProperty(aCx, paramsObj, "subject", subjectStr, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// receivers
|
||||
JS::Rooted<JSObject*> receiverArray(aCx);
|
||||
if (NS_FAILED(nsTArrayToJSArray(aCx, aRequest.receivers(), &receiverArray)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!JS_DefineProperty(aCx, paramsObj, "receivers", receiverArray, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// attachments
|
||||
JS::Rooted<JSObject*> attachmentArray(aCx, JS_NewArrayObject(aCx,
|
||||
aRequest.attachments().Length()));
|
||||
for (uint32_t i = 0; i < aRequest.attachments().Length(); i++) {
|
||||
JS::Rooted<JSObject*> obj(aCx,
|
||||
MmsAttachmentDataToJSObject(aCx, aRequest.attachments().ElementAt(i)));
|
||||
NS_ENSURE_TRUE(obj, false);
|
||||
if (!JS_DefineElement(aCx, attachmentArray, i, obj, JSPROP_ENUMERATE)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!JS_DefineProperty(aCx, paramsObj, "attachments", attachmentArray, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aParam->setObject(*paramsObj);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetMobileMessageDataFromMessage(ContentParent* aParent,
|
||||
nsISupports *aMsg,
|
||||
MobileMessageData &aData)
|
||||
{
|
||||
if (!aMsg) {
|
||||
NS_WARNING("Invalid message to convert!");
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMmsMessage> mmsMsg = do_QueryInterface(aMsg);
|
||||
if (mmsMsg) {
|
||||
if (!aParent) {
|
||||
NS_ERROR("Invalid ContentParent to convert MMS Message!");
|
||||
return false;
|
||||
}
|
||||
MmsMessageData data;
|
||||
if (!static_cast<MmsMessageInternal*>(mmsMsg.get())->GetData(aParent, data)) {
|
||||
return false;
|
||||
}
|
||||
aData = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISmsMessage> smsMsg = do_QueryInterface(aMsg);
|
||||
if (smsMsg) {
|
||||
aData = static_cast<SmsMessageInternal*>(smsMsg.get())->GetData();
|
||||
return true;
|
||||
}
|
||||
|
||||
NS_WARNING("Cannot get MobileMessageData");
|
||||
return false;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(SmsParent, nsIObserver)
|
||||
|
||||
SmsParent::SmsParent()
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsParent);
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
obs->AddObserver(this, kSmsReceivedObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsRetrievingObserverTopic, 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);
|
||||
obs->AddObserver(this, kSilentSmsReceivedObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsReadSuccessObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsReadErrorObserverTopic, false);
|
||||
obs->AddObserver(this, kSmsDeletedObserverTopic, false);
|
||||
}
|
||||
|
||||
void
|
||||
SmsParent::ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (!obs) {
|
||||
return;
|
||||
}
|
||||
|
||||
obs->RemoveObserver(this, kSmsReceivedObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsRetrievingObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsSendingObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsSentObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsFailedObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsDeliverySuccessObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsDeliveryErrorObserverTopic);
|
||||
obs->RemoveObserver(this, kSilentSmsReceivedObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsReadSuccessObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
|
||||
obs->RemoveObserver(this, kSmsDeletedObserverTopic);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsParent::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
ContentParent *parent = static_cast<ContentParent*>(Manager());
|
||||
|
||||
if (!strcmp(aTopic, kSmsReceivedObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-received' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyReceivedMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsRetrievingObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-retrieving' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyRetrievingMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsSendingObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-sending' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifySendingMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsSentObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-sent' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifySentMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsFailedObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-failed' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyFailedMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsDeliverySuccessObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-sending' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyDeliverySuccessMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsDeliveryErrorObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-delivery-error' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyDeliveryErrorMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSilentSmsReceivedObserverTopic)) {
|
||||
nsCOMPtr<nsISmsMessage> smsMsg = do_QueryInterface(aSubject);
|
||||
if (!smsMsg) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsString sender;
|
||||
if (NS_FAILED(smsMsg->GetSender(sender)) ||
|
||||
!mSilentNumbers.Contains(sender)) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MobileMessageData msgData =
|
||||
static_cast<SmsMessageInternal*>(smsMsg.get())->GetData();
|
||||
Unused << SendNotifyReceivedSilentMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsReadSuccessObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-read-success' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyReadSuccessMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsReadErrorObserverTopic)) {
|
||||
MobileMessageData msgData;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aSubject, msgData)) {
|
||||
NS_ERROR("Got a 'sms-read-error' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyReadErrorMessage(msgData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, kSmsDeletedObserverTopic)) {
|
||||
nsCOMPtr<nsIDeletedMessageInfo> deletedInfo = do_QueryInterface(aSubject);
|
||||
if (!deletedInfo) {
|
||||
NS_ERROR("Got a 'sms-deleted' topic without a valid message!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
Unused << SendNotifyDeletedMessageInfo(
|
||||
static_cast<DeletedMessageInfo*>(deletedInfo.get())->GetData());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvAddSilentNumber(const nsString& aNumber)
|
||||
{
|
||||
if (mSilentNumbers.Contains(aNumber)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(smsService, true);
|
||||
|
||||
nsresult rv = smsService->AddSilentNumber(aNumber);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mSilentNumbers.AppendElement(aNumber);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvRemoveSilentNumber(const nsString& aNumber)
|
||||
{
|
||||
if (!mSilentNumbers.Contains(aNumber)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(smsService, true);
|
||||
|
||||
nsresult rv = smsService->RemoveSilentNumber(aNumber);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mSilentNumbers.RemoveElement(aNumber);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvPSmsRequestConstructor(PSmsRequestParent* aActor,
|
||||
const IPCSmsRequest& aRequest)
|
||||
{
|
||||
SmsRequestParent* actor = static_cast<SmsRequestParent*>(aActor);
|
||||
|
||||
switch (aRequest.type()) {
|
||||
case IPCSmsRequest::TSendMessageRequest:
|
||||
return actor->DoRequest(aRequest.get_SendMessageRequest());
|
||||
case IPCSmsRequest::TRetrieveMessageRequest:
|
||||
return actor->DoRequest(aRequest.get_RetrieveMessageRequest());
|
||||
case IPCSmsRequest::TGetMessageRequest:
|
||||
return actor->DoRequest(aRequest.get_GetMessageRequest());
|
||||
case IPCSmsRequest::TDeleteMessageRequest:
|
||||
return actor->DoRequest(aRequest.get_DeleteMessageRequest());
|
||||
case IPCSmsRequest::TMarkMessageReadRequest:
|
||||
return actor->DoRequest(aRequest.get_MarkMessageReadRequest());
|
||||
case IPCSmsRequest::TGetSegmentInfoForTextRequest:
|
||||
return actor->DoRequest(aRequest.get_GetSegmentInfoForTextRequest());
|
||||
case IPCSmsRequest::TGetSmscAddressRequest:
|
||||
return actor->DoRequest(aRequest.get_GetSmscAddressRequest());
|
||||
case IPCSmsRequest::TSetSmscAddressRequest:
|
||||
return actor->DoRequest(aRequest.get_SetSmscAddressRequest());
|
||||
default:
|
||||
MOZ_CRASH("Unknown type!");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
PSmsRequestParent*
|
||||
SmsParent::AllocPSmsRequestParent(const IPCSmsRequest& aRequest)
|
||||
{
|
||||
SmsRequestParent* actor = new SmsRequestParent();
|
||||
// Add an extra ref for IPDL. Will be released in
|
||||
// SmsParent::DeallocPSmsRequestParent().
|
||||
actor->AddRef();
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::DeallocPSmsRequestParent(PSmsRequestParent* aActor)
|
||||
{
|
||||
// SmsRequestParent is refcounted, must not be freed manually.
|
||||
static_cast<SmsRequestParent*>(aActor)->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor,
|
||||
const IPCMobileMessageCursor& aRequest)
|
||||
{
|
||||
MobileMessageCursorParent* actor =
|
||||
static_cast<MobileMessageCursorParent*>(aActor);
|
||||
|
||||
switch (aRequest.type()) {
|
||||
case IPCMobileMessageCursor::TCreateMessageCursorRequest:
|
||||
return actor->DoRequest(aRequest.get_CreateMessageCursorRequest());
|
||||
case IPCMobileMessageCursor::TCreateThreadCursorRequest:
|
||||
return actor->DoRequest(aRequest.get_CreateThreadCursorRequest());
|
||||
default:
|
||||
MOZ_CRASH("Unknown type!");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
PMobileMessageCursorParent*
|
||||
SmsParent::AllocPMobileMessageCursorParent(const IPCMobileMessageCursor& aRequest)
|
||||
{
|
||||
MobileMessageCursorParent* actor = new MobileMessageCursorParent();
|
||||
// Add an extra ref for IPDL. Will be released in
|
||||
// SmsParent::DeallocPMobileMessageCursorParent().
|
||||
actor->AddRef();
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::DeallocPMobileMessageCursorParent(PMobileMessageCursorParent* aActor)
|
||||
{
|
||||
// MobileMessageCursorParent is refcounted, must not be freed manually.
|
||||
static_cast<MobileMessageCursorParent*>(aActor)->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* SmsRequestParent
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS(SmsRequestParent, nsIMobileMessageCallback)
|
||||
|
||||
void
|
||||
SmsRequestParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
mActorDestroyed = true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const SendMessageRequest& aRequest)
|
||||
{
|
||||
switch(aRequest.type()) {
|
||||
case SendMessageRequest::TSendSmsMessageRequest: {
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(smsService, true);
|
||||
|
||||
const SendSmsMessageRequest &req = aRequest.get_SendSmsMessageRequest();
|
||||
smsService->Send(req.serviceId(), req.number(), req.message(),
|
||||
req.silent(), this);
|
||||
}
|
||||
break;
|
||||
case SendMessageRequest::TSendMmsMessageRequest: {
|
||||
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mmsService, true);
|
||||
|
||||
// There are cases (see bug 981202) where this is called with no JS on the
|
||||
// stack. And since mmsService might be JS-Implemented, we need to pass a
|
||||
// jsval to ::Send. Only system code should be looking at the result here,
|
||||
// so we just create it in the System-Principaled Junk Scope.
|
||||
AutoJSContext cx;
|
||||
JSAutoCompartment ac(cx, xpc::PrivilegedJunkScope());
|
||||
JS::Rooted<JS::Value> params(cx);
|
||||
const SendMmsMessageRequest &req = aRequest.get_SendMmsMessageRequest();
|
||||
if (!GetParamsFromSendMmsMessageRequest(cx,
|
||||
req,
|
||||
params.address())) {
|
||||
NS_WARNING("SmsRequestParent: Fail to build MMS params.");
|
||||
return true;
|
||||
}
|
||||
mmsService->Send(req.serviceId(), params, this);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Unknown type of SendMessageRequest!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const RetrieveMessageRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIMmsService> mmsService = do_GetService(MMS_SERVICE_CONTRACTID);
|
||||
if (mmsService) {
|
||||
rv = mmsService->Retrieve(aRequest.messageId(), this);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyGetMessageFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const GetMessageRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (dbService) {
|
||||
rv = dbService->GetMessageMoz(aRequest.messageId(), this);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyGetMessageFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const GetSmscAddressRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
if (smsService) {
|
||||
rv = smsService->GetSmscAddress(aRequest.serviceId(), this);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyGetSmscAddressFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const SetSmscAddressRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
if (smsService) {
|
||||
rv = smsService->SetSmscAddress(aRequest.serviceId(),
|
||||
aRequest.number(),
|
||||
aRequest.typeOfNumber(),
|
||||
aRequest.numberPlanIdentification(),
|
||||
this);
|
||||
} else {
|
||||
return NS_SUCCEEDED(NotifySetSmscAddressFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifySetSmscAddressFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const DeleteMessageRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (dbService) {
|
||||
const InfallibleTArray<int32_t>& messageIds = aRequest.messageIds();
|
||||
rv = dbService->DeleteMessage(const_cast<int32_t *>(messageIds.Elements()),
|
||||
messageIds.Length(), this);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyDeleteMessageFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const MarkMessageReadRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (dbService) {
|
||||
rv = dbService->MarkMessageRead(aRequest.messageId(), aRequest.value(),
|
||||
aRequest.sendReadReport(), this);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyMarkMessageReadFailed(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const GetSegmentInfoForTextRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
|
||||
if (smsService) {
|
||||
rv = smsService->GetSegmentInfoForText(aRequest.text(), this);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyGetSegmentInfoForTextFailed(
|
||||
nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
nsresult
|
||||
SmsRequestParent::SendReply(const MessageReply& aReply)
|
||||
{
|
||||
// The child process could die before this asynchronous notification, in which
|
||||
// case ActorDestroy() was called and mActorDestroyed is set to true. Return
|
||||
// an error here to avoid sending a message to the dead process.
|
||||
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
|
||||
|
||||
return Send__delete__(this, aReply) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// nsIMobileMessageCallback
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyMessageSent(nsISupports *aMessage)
|
||||
{
|
||||
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
|
||||
|
||||
ContentParent *parent = static_cast<ContentParent*>(Manager()->Manager());
|
||||
MobileMessageData data;
|
||||
if (GetMobileMessageDataFromMessage(parent, aMessage, data)) {
|
||||
return SendReply(ReplyMessageSend(data));
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifySendMessageFailed(int32_t aError, nsISupports *aMessage)
|
||||
{
|
||||
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
|
||||
|
||||
ContentParent *parent = static_cast<ContentParent*>(Manager()->Manager());
|
||||
MobileMessageData data;
|
||||
if (!GetMobileMessageDataFromMessage(parent, aMessage, data)) {
|
||||
return SendReply(ReplyMessageSendFail(aError, OptionalMobileMessageData(void_t())));
|
||||
}
|
||||
|
||||
return SendReply(ReplyMessageSendFail(aError, OptionalMobileMessageData(data)));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyMessageGot(nsISupports *aMessage)
|
||||
{
|
||||
NS_ENSURE_TRUE(!mActorDestroyed, NS_ERROR_FAILURE);
|
||||
|
||||
ContentParent *parent = static_cast<ContentParent*>(Manager()->Manager());
|
||||
MobileMessageData data;
|
||||
if (GetMobileMessageDataFromMessage(parent, aMessage, data)) {
|
||||
return SendReply(ReplyGetMessage(data));
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyGetMessageFailed(int32_t aError)
|
||||
{
|
||||
return SendReply(ReplyGetMessageFail(aError));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyMessageDeleted(bool *aDeleted, uint32_t aSize)
|
||||
{
|
||||
ReplyMessageDelete data;
|
||||
data.deleted().AppendElements(aDeleted, aSize);
|
||||
return SendReply(data);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyDeleteMessageFailed(int32_t aError)
|
||||
{
|
||||
return SendReply(ReplyMessageDeleteFail(aError));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyMessageMarkedRead(bool aRead)
|
||||
{
|
||||
return SendReply(ReplyMarkeMessageRead(aRead));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyMarkMessageReadFailed(int32_t aError)
|
||||
{
|
||||
return SendReply(ReplyMarkeMessageReadFail(aError));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifySegmentInfoForTextGot(int32_t aSegments,
|
||||
int32_t aCharsPerSegment,
|
||||
int32_t aCharsAvailableInLastSegment)
|
||||
{
|
||||
return SendReply(ReplyGetSegmentInfoForText(aSegments,
|
||||
aCharsPerSegment,
|
||||
aCharsAvailableInLastSegment));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyGetSegmentInfoForTextFailed(int32_t aError)
|
||||
{
|
||||
return SendReply(ReplyGetSegmentInfoForTextFail(aError));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyGetSmscAddress(const nsAString& aSmscAddress,
|
||||
uint32_t aTypeOfNumber,
|
||||
uint32_t aNumberPlanIdentification)
|
||||
{
|
||||
return SendReply(ReplyGetSmscAddress(nsString(aSmscAddress),
|
||||
aTypeOfNumber,
|
||||
aNumberPlanIdentification));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifyGetSmscAddressFailed(int32_t aError)
|
||||
{
|
||||
return SendReply(ReplyGetSmscAddressFail(aError));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifySetSmscAddress()
|
||||
{
|
||||
return SendReply(ReplySetSmscAddress());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsRequestParent::NotifySetSmscAddressFailed(int32_t aError)
|
||||
{
|
||||
return SendReply(ReplySetSmscAddressFail(aError));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* MobileMessageCursorParent
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS(MobileMessageCursorParent, nsIMobileMessageCursorCallback)
|
||||
|
||||
void
|
||||
MobileMessageCursorParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
// Two possible scenarios here:
|
||||
// 1) When parent fails to SendNotifyResult() in NotifyCursorResult(), it's
|
||||
// destroyed without nulling out mContinueCallback.
|
||||
// 2) When parent dies normally, mContinueCallback should have been cleared in
|
||||
// NotifyCursorError(), but just ensure this again.
|
||||
mContinueCallback = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileMessageCursorParent::RecvContinue()
|
||||
{
|
||||
MOZ_ASSERT(mContinueCallback);
|
||||
|
||||
if (NS_FAILED(mContinueCallback->HandleContinue())) {
|
||||
return NS_SUCCEEDED(NotifyCursorError(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileMessageCursorParent::DoRequest(const CreateMessageCursorRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (dbService) {
|
||||
const SmsFilterData& filter = aRequest.filter();
|
||||
|
||||
const nsTArray<nsString>& numbers = filter.numbers();
|
||||
UniquePtr<const char16_t*[]> ptrNumbers;
|
||||
uint32_t numbersCount = numbers.Length();
|
||||
if (numbersCount) {
|
||||
uint32_t index;
|
||||
|
||||
ptrNumbers = MakeUnique<const char16_t*[]>(numbersCount);
|
||||
for (index = 0; index < numbersCount; index++) {
|
||||
ptrNumbers[index] = numbers[index].get();
|
||||
}
|
||||
}
|
||||
|
||||
rv = dbService->CreateMessageCursor(filter.hasStartDate(),
|
||||
filter.startDate(),
|
||||
filter.hasEndDate(),
|
||||
filter.endDate(),
|
||||
ptrNumbers.get(), numbersCount,
|
||||
filter.delivery(),
|
||||
filter.hasRead(),
|
||||
filter.read(),
|
||||
filter.hasThreadId(),
|
||||
filter.threadId(),
|
||||
aRequest.reverse(),
|
||||
this,
|
||||
getter_AddRefs(mContinueCallback));
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyCursorError(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
MobileMessageCursorParent::DoRequest(const CreateThreadCursorRequest& aRequest)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> dbService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
if (dbService) {
|
||||
rv = dbService->CreateThreadCursor(this,
|
||||
getter_AddRefs(mContinueCallback));
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_SUCCEEDED(NotifyCursorError(nsIMobileMessageCallback::INTERNAL_ERROR));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// nsIMobileMessageCursorCallback
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorParent::NotifyCursorError(int32_t aError)
|
||||
{
|
||||
// The child process could die before this asynchronous notification, in which
|
||||
// case ActorDestroy() was called and mContinueCallback is now null. Return an
|
||||
// error here to avoid sending a message to the dead process.
|
||||
NS_ENSURE_TRUE(mContinueCallback, NS_ERROR_FAILURE);
|
||||
|
||||
mContinueCallback = nullptr;
|
||||
|
||||
return Send__delete__(this, aError) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorParent::NotifyCursorResult(nsISupports** aResults,
|
||||
uint32_t aSize)
|
||||
{
|
||||
MOZ_ASSERT(aResults && *aResults && aSize);
|
||||
|
||||
// The child process could die before this asynchronous notification, in which
|
||||
// case ActorDestroy() was called and mContinueCallback is now null. Return an
|
||||
// error here to avoid sending a message to the dead process.
|
||||
NS_ENSURE_TRUE(mContinueCallback, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIMobileMessageThread> iThread =
|
||||
do_QueryInterface(aResults[0]);
|
||||
if (iThread) {
|
||||
nsTArray<ThreadData> threads;
|
||||
|
||||
for (uint32_t i = 0; i < aSize; i++) {
|
||||
nsCOMPtr<nsIMobileMessageThread> iThread =
|
||||
do_QueryInterface(aResults[i]);
|
||||
NS_ENSURE_TRUE(iThread, NS_ERROR_FAILURE);
|
||||
|
||||
MobileMessageThreadInternal* thread =
|
||||
static_cast<MobileMessageThreadInternal*>(iThread.get());
|
||||
threads.AppendElement(thread->GetData());
|
||||
}
|
||||
|
||||
return SendNotifyResult(MobileMessageCursorData(ThreadArrayData(threads)))
|
||||
? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
ContentParent* parent = static_cast<ContentParent*>(Manager()->Manager());
|
||||
nsTArray<MobileMessageData> messages;
|
||||
for (uint32_t i = 0; i < aSize; i++) {
|
||||
nsCOMPtr<nsISmsMessage> sms = do_QueryInterface(aResults[i]);
|
||||
if (sms) {
|
||||
messages.AppendElement(
|
||||
static_cast<SmsMessageInternal*>(sms.get())->GetData());
|
||||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIMmsMessage> mms = do_QueryInterface(aResults[i]);
|
||||
if (mms) {
|
||||
MmsMessageData mmsData;
|
||||
NS_ENSURE_TRUE(
|
||||
static_cast<MmsMessageInternal*>(mms.get())->GetData(parent, mmsData),
|
||||
NS_ERROR_FAILURE
|
||||
);
|
||||
messages.AppendElement(mmsData);
|
||||
continue;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return SendNotifyResult(MobileMessageCursorData(MobileMessageArrayData(messages)))
|
||||
? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorParent::NotifyCursorDone()
|
||||
{
|
||||
return NotifyCursorError(nsIMobileMessageCallback::SUCCESS_NO_ERROR);
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -1,167 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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_SmsParent_h
|
||||
#define mozilla_dom_mobilemessage_SmsParent_h
|
||||
|
||||
#include "mozilla/dom/mobilemessage/PSmsParent.h"
|
||||
#include "mozilla/dom/mobilemessage/PSmsRequestParent.h"
|
||||
#include "mozilla/dom/mobilemessage/PMobileMessageCursorParent.h"
|
||||
#include "nsIDOMDOMCursor.h"
|
||||
#include "nsIMobileMessageCallback.h"
|
||||
#include "nsIMobileMessageCursorCallback.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ContentParent;
|
||||
|
||||
namespace mobilemessage {
|
||||
|
||||
class SmsParent : public PSmsParent
|
||||
, public nsIObserver
|
||||
{
|
||||
friend class mozilla::dom::ContentParent;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
protected:
|
||||
virtual bool
|
||||
RecvAddSilentNumber(const nsString& aNumber) override;
|
||||
|
||||
virtual bool
|
||||
RecvRemoveSilentNumber(const nsString& aNumber) override;
|
||||
|
||||
SmsParent();
|
||||
virtual ~SmsParent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsParent);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual bool
|
||||
RecvPSmsRequestConstructor(PSmsRequestParent* aActor,
|
||||
const IPCSmsRequest& aRequest) override;
|
||||
|
||||
virtual PSmsRequestParent*
|
||||
AllocPSmsRequestParent(const IPCSmsRequest& aRequest) override;
|
||||
|
||||
virtual bool
|
||||
DeallocPSmsRequestParent(PSmsRequestParent* aActor) override;
|
||||
|
||||
virtual bool
|
||||
RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor,
|
||||
const IPCMobileMessageCursor& aCursor) override;
|
||||
|
||||
virtual PMobileMessageCursorParent*
|
||||
AllocPMobileMessageCursorParent(const IPCMobileMessageCursor& aCursor) override;
|
||||
|
||||
virtual bool
|
||||
DeallocPMobileMessageCursorParent(PMobileMessageCursorParent* aActor) override;
|
||||
|
||||
private:
|
||||
nsTArray<nsString> mSilentNumbers;
|
||||
};
|
||||
|
||||
class SmsRequestParent : public PSmsRequestParent
|
||||
, public nsIMobileMessageCallback
|
||||
{
|
||||
friend class SmsParent;
|
||||
|
||||
bool mActorDestroyed;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMOBILEMESSAGECALLBACK
|
||||
|
||||
protected:
|
||||
SmsRequestParent()
|
||||
: mActorDestroyed(false)
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsRequestParent);
|
||||
}
|
||||
|
||||
virtual ~SmsRequestParent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsRequestParent);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
bool
|
||||
DoRequest(const SendMessageRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const RetrieveMessageRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const GetMessageRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const DeleteMessageRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const MarkMessageReadRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const GetSegmentInfoForTextRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const GetSmscAddressRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const SetSmscAddressRequest& aRequest);
|
||||
|
||||
nsresult
|
||||
SendReply(const MessageReply& aReply);
|
||||
};
|
||||
|
||||
class MobileMessageCursorParent : public PMobileMessageCursorParent
|
||||
, public nsIMobileMessageCursorCallback
|
||||
{
|
||||
friend class SmsParent;
|
||||
|
||||
nsCOMPtr<nsICursorContinueCallback> mContinueCallback;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMOBILEMESSAGECURSORCALLBACK
|
||||
|
||||
protected:
|
||||
MobileMessageCursorParent()
|
||||
{
|
||||
MOZ_COUNT_CTOR(MobileMessageCursorParent);
|
||||
}
|
||||
|
||||
virtual ~MobileMessageCursorParent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(MobileMessageCursorParent);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual bool
|
||||
RecvContinue() override;
|
||||
|
||||
bool
|
||||
DoRequest(const CreateMessageCursorRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const CreateThreadCursorRequest& aRequest);
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_mobilemessage_SmsParent_h
|
@ -1,127 +0,0 @@
|
||||
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* 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 protocol PBlob;
|
||||
|
||||
using DeliveryState from "mozilla/dom/mobilemessage/Types.h";
|
||||
using DeliveryStatus from "mozilla/dom/mobilemessage/Types.h";
|
||||
using MessageClass from "mozilla/dom/mobilemessage/Types.h";
|
||||
using ReadStatus from "mozilla/dom/mobilemessage/Types.h";
|
||||
using ReadState from "mozilla/dom/mobilemessage/Types.h";
|
||||
using MessageType from "mozilla/dom/mobilemessage/Types.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
struct SmsMessageData
|
||||
{
|
||||
int32_t id;
|
||||
uint64_t threadId;
|
||||
nsString iccId;
|
||||
DeliveryState delivery;
|
||||
DeliveryStatus deliveryStatus;
|
||||
nsString sender;
|
||||
nsString receiver;
|
||||
nsString body;
|
||||
MessageClass messageClass;
|
||||
uint64_t timestamp; // ms since epoch.
|
||||
uint64_t sentTimestamp; // ms since epoch.
|
||||
uint64_t deliveryTimestamp; // ms since epoch.
|
||||
bool read;
|
||||
};
|
||||
|
||||
struct MmsAttachmentData
|
||||
{
|
||||
nsString id;
|
||||
nsString location;
|
||||
PBlob content;
|
||||
};
|
||||
|
||||
struct MmsDeliveryInfoData
|
||||
{
|
||||
nsString receiver;
|
||||
DeliveryStatus deliveryStatus;
|
||||
uint64_t deliveryTimestamp;
|
||||
ReadStatus readStatus;
|
||||
uint64_t readTimestamp;
|
||||
};
|
||||
|
||||
struct MmsMessageData
|
||||
{
|
||||
int32_t id;
|
||||
uint64_t threadId;
|
||||
nsString iccId;
|
||||
DeliveryState delivery;
|
||||
MmsDeliveryInfoData[] deliveryInfo;
|
||||
nsString sender;
|
||||
nsString[] receivers;
|
||||
uint64_t timestamp; // ms since epoch.
|
||||
uint64_t sentTimestamp; // ms since epoch.
|
||||
bool read;
|
||||
nsString subject;
|
||||
nsString smil;
|
||||
MmsAttachmentData[] attachments;
|
||||
uint64_t expiryDate; // ms since epoch.
|
||||
bool readReportRequested;
|
||||
};
|
||||
|
||||
union MobileMessageData
|
||||
{
|
||||
MmsMessageData;
|
||||
SmsMessageData;
|
||||
};
|
||||
|
||||
struct SmsFilterData
|
||||
{
|
||||
bool hasStartDate;
|
||||
uint64_t startDate;
|
||||
bool hasEndDate;
|
||||
uint64_t endDate;
|
||||
nsString[] numbers;
|
||||
nsString delivery;
|
||||
bool hasRead;
|
||||
bool read;
|
||||
bool hasThreadId;
|
||||
uint64_t threadId;
|
||||
};
|
||||
|
||||
struct ThreadData
|
||||
{
|
||||
uint64_t id;
|
||||
nsString[] participants;
|
||||
uint64_t timestamp;
|
||||
nsString lastMessageSubject;
|
||||
nsString body;
|
||||
uint64_t unreadCount;
|
||||
MessageType lastMessageType;
|
||||
};
|
||||
|
||||
struct MobileMessageArrayData
|
||||
{
|
||||
MobileMessageData[] messages;
|
||||
};
|
||||
|
||||
struct ThreadArrayData
|
||||
{
|
||||
ThreadData[] threads;
|
||||
};
|
||||
|
||||
union MobileMessageCursorData
|
||||
{
|
||||
MobileMessageArrayData;
|
||||
ThreadArrayData;
|
||||
};
|
||||
|
||||
struct DeletedMessageInfoData
|
||||
{
|
||||
int32_t[] deletedMessageIds;
|
||||
uint64_t[] deletedThreadIds;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
DIRS += ['interfaces']
|
||||
|
||||
MOCHITEST_CHROME_MANIFESTS += ['tests/mochitest/chrome.ini']
|
||||
XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
|
||||
|
||||
EXPORTS.mozilla.dom.mobilemessage += [
|
||||
'Constants.h', # Required by almost all cpp files
|
||||
'ipc/SmsChild.h',
|
||||
'ipc/SmsParent.h',
|
||||
'Types.h', # Required by IPDL SmsTypes.h
|
||||
]
|
||||
|
||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android' and CONFIG['MOZ_WEBSMS_BACKEND']:
|
||||
SOURCES += [
|
||||
'android/MobileMessageDatabaseService.cpp',
|
||||
'android/SmsManager.cpp',
|
||||
'android/SmsService.cpp',
|
||||
]
|
||||
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk' and CONFIG['MOZ_B2G_RIL']:
|
||||
EXTRA_JS_MODULES += [
|
||||
'gonk/mms_consts.js',
|
||||
'gonk/MmsPduHelper.jsm',
|
||||
'gonk/MobileMessageDB.jsm',
|
||||
'gonk/SmsSegmentHelper.jsm',
|
||||
'gonk/wap_consts.js',
|
||||
'gonk/WspPduHelper.jsm',
|
||||
]
|
||||
EXTRA_COMPONENTS += [
|
||||
'gonk/MmsService.js',
|
||||
'gonk/MmsService.manifest',
|
||||
'gonk/MobileMessageDatabaseService.js',
|
||||
'gonk/MobileMessageDatabaseService.manifest',
|
||||
]
|
||||
if not CONFIG['DISABLE_MOZ_RIL_GEOLOC']:
|
||||
EXTRA_COMPONENTS += [
|
||||
'gonk/SmsService.js',
|
||||
'gonk/SmsService.manifest',
|
||||
]
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'DOMMobileMessageError.h',
|
||||
'MmsMessage.h',
|
||||
'MobileMessageManager.h',
|
||||
'MobileMessageThread.h',
|
||||
'SmsMessage.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'Assertions.cpp',
|
||||
'Constants.cpp',
|
||||
'DeletedMessageInfo.cpp',
|
||||
'DOMMobileMessageError.cpp',
|
||||
'ipc/SmsChild.cpp',
|
||||
'ipc/SmsIPCService.cpp',
|
||||
'ipc/SmsParent.cpp',
|
||||
'MmsMessage.cpp',
|
||||
'MmsMessageInternal.cpp',
|
||||
'MobileMessageCallback.cpp',
|
||||
'MobileMessageCursorCallback.cpp',
|
||||
'MobileMessageManager.cpp',
|
||||
'MobileMessageService.cpp',
|
||||
'MobileMessageThread.cpp',
|
||||
'MobileMessageThreadInternal.cpp',
|
||||
'SmsMessage.cpp',
|
||||
'SmsMessageInternal.cpp',
|
||||
]
|
||||
|
||||
IPDL_SOURCES += [
|
||||
'ipc/PMobileMessageCursor.ipdl',
|
||||
'ipc/PSms.ipdl',
|
||||
'ipc/PSmsRequest.ipdl',
|
||||
'ipc/SmsTypes.ipdlh',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
'/widget/android',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
if CONFIG['GNU_CXX']:
|
||||
CXXFLAGS += ['-Wno-error=shadow']
|
@ -1,722 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const {Cc: Cc, Ci: Ci, Cr: Cr, Cu: Cu} = SpecialPowers;
|
||||
|
||||
// Emulate Promise.jsm semantics.
|
||||
Promise.defer = function() { return new Deferred(); }
|
||||
function Deferred() {
|
||||
this.promise = new Promise(function(resolve, reject) {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
}.bind(this));
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a list of preference settings. Never reject.
|
||||
*
|
||||
* Fulfill params: (none)
|
||||
*
|
||||
* @param aPrefs
|
||||
* An JS object. For example:
|
||||
*
|
||||
* {'set': [['foo.bar', 2], ['magic.pref', 'baz']],
|
||||
* 'clear': [['clear.this'], ['also.this']] };
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function pushPrefEnv(aPrefs) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
SpecialPowers.pushPrefEnv(aPrefs, function() {
|
||||
ok(true, "preferences pushed: " + JSON.stringify(aPrefs));
|
||||
deferred.resolve();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push required permissions and test if |navigator.mozMobileMessage| exists.
|
||||
* Resolve if it does, reject otherwise.
|
||||
*
|
||||
* Fulfill params:
|
||||
* manager -- an reference to navigator.mozMobileMessage.
|
||||
*
|
||||
* Reject params: (none)
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
var manager;
|
||||
function ensureMobileMessage() {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let permissions = [{
|
||||
"type": "sms",
|
||||
"allow": 1,
|
||||
"context": document,
|
||||
}];
|
||||
SpecialPowers.pushPermissions(permissions, function() {
|
||||
ok(true, "permissions pushed: " + JSON.stringify(permissions));
|
||||
|
||||
manager = window.navigator.mozMobileMessage;
|
||||
if (manager) {
|
||||
log("navigator.mozMobileMessage is instance of " + manager.constructor);
|
||||
} else {
|
||||
log("navigator.mozMobileMessage is undefined.");
|
||||
}
|
||||
|
||||
if (manager instanceof MozMobileMessageManager) {
|
||||
deferred.resolve(manager);
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push required permissions and test if |navigator.mozMobileConnections| exists.
|
||||
* Resolve if it does, reject otherwise.
|
||||
*
|
||||
* Fulfill params:
|
||||
* manager -- an reference to navigator.mozMobileConnections.
|
||||
*
|
||||
* Reject params: (none)
|
||||
*
|
||||
* @param aServiceId [optional]
|
||||
* A numeric DSDS service id. Default: 0.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
var mobileConnection;
|
||||
function ensureMobileConnection(aServiceId) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
let permissions = [{
|
||||
"type": "mobileconnection",
|
||||
"allow": 1,
|
||||
"context": document,
|
||||
}];
|
||||
SpecialPowers.pushPermissions(permissions, function() {
|
||||
ok(true, "permissions pushed: " + JSON.stringify(permissions));
|
||||
|
||||
let serviceId = aServiceId || 0;
|
||||
mobileConnection = window.navigator.mozMobileConnections[serviceId];
|
||||
if (mobileConnection) {
|
||||
log("navigator.mozMobileConnections[" + serviceId + "] is instance of " +
|
||||
mobileConnection.constructor);
|
||||
} else {
|
||||
log("navigator.mozMobileConnections[" + serviceId + "] is undefined");
|
||||
}
|
||||
|
||||
if (mobileConnection instanceof MozMobileConnection) {
|
||||
resolve(mobileConnection);
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for one named MobileMessageManager event.
|
||||
*
|
||||
* Resolve if that named event occurs. Never reject.
|
||||
*
|
||||
* Fulfill params: the DOMEvent passed.
|
||||
*
|
||||
* @param aEventName
|
||||
* A string event name.
|
||||
* @param aMatchFunc [optional]
|
||||
* An additional callback function to match the interested event
|
||||
* before removing the listener and going to resolve the promise.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function waitForManagerEvent(aEventName, aMatchFunc) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
manager.addEventListener(aEventName, function onevent(aEvent) {
|
||||
if (aMatchFunc && !aMatchFunc(aEvent)) {
|
||||
ok(true, "MobileMessageManager event '" + aEventName + "' got" +
|
||||
" but is not interested.");
|
||||
return;
|
||||
}
|
||||
|
||||
ok(true, "MobileMessageManager event '" + aEventName + "' got.");
|
||||
manager.removeEventListener(aEventName, onevent);
|
||||
deferred.resolve(aEvent);
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a SMS message to a single receiver. Resolve if it succeeds, reject
|
||||
* otherwise.
|
||||
*
|
||||
* Fulfill params:
|
||||
* message -- the sent SmsMessage.
|
||||
*
|
||||
* Reject params:
|
||||
* error -- a DOMError.
|
||||
*
|
||||
* @param aReceiver the address of the receiver.
|
||||
* @param aText the text body of the message.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendSmsWithSuccess(aReceiver, aText) {
|
||||
return manager.send(aReceiver, aText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a SMS message to a single receiver.
|
||||
* Resolve if it fails, reject otherwise.
|
||||
*
|
||||
* Fulfill params:
|
||||
* {
|
||||
* message, -- the failed MmsMessage
|
||||
* error, -- error of the send request
|
||||
* }
|
||||
*
|
||||
* Reject params: (none)
|
||||
*
|
||||
* @param aReceiver the address of the receiver.
|
||||
* @param aText the text body of the message.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendSmsWithFailure(aReceiver, aText) {
|
||||
let promises = [];
|
||||
promises.push(waitForManagerEvent("failed")
|
||||
.then((aEvent) => { return aEvent.message; }));
|
||||
promises.push(manager.send(aReceiver, aText)
|
||||
.then((aResult) => { throw aResult; },
|
||||
(aError) => { return aError; }));
|
||||
|
||||
return Promise.all(promises)
|
||||
.then((aResults) => { return { message: aResults[0],
|
||||
error: aResults[1] }; });
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a MMS message with specified parameters. Resolve if it fails, reject
|
||||
* otherwise.
|
||||
*
|
||||
* Fulfill params:
|
||||
* {
|
||||
* message, -- the failed MmsMessage
|
||||
* error, -- error of the send request
|
||||
* }
|
||||
*
|
||||
* Reject params: (none)
|
||||
*
|
||||
* @param aMmsParameters a MmsParameters instance.
|
||||
*
|
||||
* @param aSendParameters a MmsSendParameters instance.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendMmsWithFailure(aMmsParameters, aSendParameters) {
|
||||
let promises = [];
|
||||
promises.push(waitForManagerEvent("failed")
|
||||
.then((aEvent) => { return aEvent.message; }));
|
||||
promises.push(manager.sendMMS(aMmsParameters, aSendParameters)
|
||||
.then((aResult) => { throw aResult; },
|
||||
(aError) => { return aError; }));
|
||||
|
||||
return Promise.all(promises)
|
||||
.then((aResults) => { return { message: aResults[0],
|
||||
error: aResults[1] }; });
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve message by message id.
|
||||
*
|
||||
* Fulfill params: SmsMessage
|
||||
* Reject params:
|
||||
* event -- a DOMEvent
|
||||
*
|
||||
* @param aId
|
||||
* A numeric message id.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getMessage(aId) {
|
||||
return manager.getMessage(aId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve messages from database.
|
||||
*
|
||||
* Fulfill params:
|
||||
* messages -- an array of {Sms,Mms}Message instances.
|
||||
*
|
||||
* Reject params:
|
||||
* event -- a DOMEvent
|
||||
*
|
||||
* @param aFilter [optional]
|
||||
* A MobileMessageFilter object.
|
||||
* @param aReverse [optional]
|
||||
* A boolean value indicating whether the order of the message should be
|
||||
* reversed. Default: false.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getMessages(aFilter, aReverse) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let messages = [];
|
||||
let cursor = manager.getMessages(aFilter, aReverse || false);
|
||||
cursor.onsuccess = function(aEvent) {
|
||||
if (cursor.result) {
|
||||
messages.push(cursor.result);
|
||||
cursor.continue();
|
||||
return;
|
||||
}
|
||||
|
||||
deferred.resolve(messages);
|
||||
};
|
||||
cursor.onerror = deferred.reject.bind(deferred);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all messages from database.
|
||||
*
|
||||
* Fulfill params:
|
||||
* messages -- an array of {Sms,Mms}Message instances.
|
||||
*
|
||||
* Reject params:
|
||||
* event -- a DOMEvent
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getAllMessages() {
|
||||
return getMessages(null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all threads from database.
|
||||
*
|
||||
* Fulfill params:
|
||||
* threads -- an array of MozMobileMessageThread instances.
|
||||
*
|
||||
* Reject params:
|
||||
* event -- a DOMEvent
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getAllThreads() {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let threads = [];
|
||||
let cursor = manager.getThreads();
|
||||
cursor.onsuccess = function(aEvent) {
|
||||
if (cursor.result) {
|
||||
threads.push(cursor.result);
|
||||
cursor.continue();
|
||||
return;
|
||||
}
|
||||
|
||||
deferred.resolve(threads);
|
||||
};
|
||||
cursor.onerror = deferred.reject.bind(deferred);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single specified thread from database.
|
||||
*
|
||||
* Fulfill params:
|
||||
* thread -- a MozMobileMessageThread instance.
|
||||
*
|
||||
* Reject params:
|
||||
* event -- a DOMEvent if an error occurs in the retrieving process, or
|
||||
* undefined if there's no such thread.
|
||||
*
|
||||
* @aThreadId a numeric value identifying the target thread.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getThreadById(aThreadId) {
|
||||
return getAllThreads()
|
||||
.then(function(aThreads) {
|
||||
for (let thread of aThreads) {
|
||||
if (thread.id === aThreadId) {
|
||||
return thread;
|
||||
}
|
||||
}
|
||||
throw undefined;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete messages specified from database.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- an array of boolean values indicating whether delesion was
|
||||
* actually performed on the message record with corresponding id.
|
||||
*
|
||||
* Reject params:
|
||||
* event -- a DOMEvent.
|
||||
*
|
||||
* @aMessageId an array of numeric values identifying the target messages.
|
||||
*
|
||||
* @return An empty array if nothing to be deleted; otherwise, a deferred promise.
|
||||
*/
|
||||
function deleteMessagesById(aMessageIds) {
|
||||
if (!aMessageIds.length) {
|
||||
ok(true, "no message to be deleted");
|
||||
return [];
|
||||
}
|
||||
|
||||
let promises = [];
|
||||
promises.push(waitForManagerEvent("deleted"));
|
||||
promises.push(manager.delete(aMessageIds));
|
||||
|
||||
return Promise.all(promises)
|
||||
.then((aResults) => {
|
||||
return { deletedInfo: aResults[0],
|
||||
deletedFlags: aResults[1] };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete messages specified from database.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- an array of boolean values indicating whether delesion was
|
||||
* actually performed on the message record with corresponding id.
|
||||
*
|
||||
* Reject params:
|
||||
* event -- a DOMEvent.
|
||||
*
|
||||
* @aMessages an array of {Sms,Mms}Message instances.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function deleteMessages(aMessages) {
|
||||
let ids = messagesToIds(aMessages);
|
||||
return deleteMessagesById(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all messages from database.
|
||||
*
|
||||
* Fulfill params:
|
||||
* ids -- an array of numeric values identifying those deleted
|
||||
* {Sms,Mms}Messages.
|
||||
*
|
||||
* Reject params:
|
||||
* event -- a DOMEvent.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function deleteAllMessages() {
|
||||
return getAllMessages().then(deleteMessages);
|
||||
}
|
||||
|
||||
var pendingEmulatorCmdCount = 0;
|
||||
|
||||
/**
|
||||
* Send emulator command with safe guard.
|
||||
*
|
||||
* We should only call |finish()| after all emulator command transactions
|
||||
* end, so here comes with the pending counter. Resolve when the emulator
|
||||
* gives positive response, and reject otherwise.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function runEmulatorCmdSafe(aCommand) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
++pendingEmulatorCmdCount;
|
||||
runEmulatorCmd(aCommand, function(aResult) {
|
||||
--pendingEmulatorCmdCount;
|
||||
|
||||
ok(true, "Emulator response: " + JSON.stringify(aResult));
|
||||
if (Array.isArray(aResult) && aResult[0] === "OK") {
|
||||
deferred.resolve(aResult);
|
||||
} else {
|
||||
deferred.reject(aResult);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send simple text SMS to emulator.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @param aFrom
|
||||
* A string-typed from address.
|
||||
* @param aText
|
||||
* A string-typed message body.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendTextSmsToEmulator(aFrom, aText) {
|
||||
let command = "sms send " + aFrom + " " + aText;
|
||||
return runEmulatorCmdSafe(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send simple text SMS to emulator and wait for a received event.
|
||||
*
|
||||
* Fulfill params: SmsMessage
|
||||
* Reject params: (none)
|
||||
*
|
||||
* @param aFrom
|
||||
* A string-typed from address.
|
||||
* @param aText
|
||||
* A string-typed message body.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendTextSmsToEmulatorAndWait(aFrom, aText) {
|
||||
let promises = [];
|
||||
promises.push(waitForManagerEvent("received"));
|
||||
promises.push(sendTextSmsToEmulator(aFrom, aText));
|
||||
return Promise.all(promises).then(aResults => aResults[0].message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send raw SMS TPDU to emulator.
|
||||
*
|
||||
* @param: aPdu
|
||||
* A hex string representing the whole SMS T-PDU.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendRawSmsToEmulator(aPdu) {
|
||||
let command = "sms pdu " + aPdu;
|
||||
return runEmulatorCmdSafe(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send multiple raw SMS TPDU to emulator and wait
|
||||
*
|
||||
* @param: aPdus
|
||||
* A array of hex strings. Each represents a SMS T-PDU.
|
||||
*
|
||||
* Fulfill params:
|
||||
* result -- array of resolved Promise, where
|
||||
* result[0].message representing the received message.
|
||||
* result[1-n] represents the response of sent emulator command.
|
||||
*
|
||||
* Reject params:
|
||||
* result -- an array of emulator response lines.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function sendMultipleRawSmsToEmulatorAndWait(aPdus) {
|
||||
let promises = [];
|
||||
|
||||
promises.push(waitForManagerEvent("received"));
|
||||
for (let pdu of aPdus) {
|
||||
promises.push(sendRawSmsToEmulator(pdu));
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set voice state and wait for state change.
|
||||
*
|
||||
* @param aState
|
||||
* "unregistered", "searching", "denied", "roaming", or "home".
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function setEmulatorVoiceStateAndWait(aState) {
|
||||
let promises = [];
|
||||
promises.push(new Promise(function(resolve, reject) {
|
||||
mobileConnection.addEventListener("voicechange", function onevent(aEvent) {
|
||||
log("voicechange: connected=" + mobileConnection.voice.connected);
|
||||
mobileConnection.removeEventListener("voicechange", onevent);
|
||||
resolve(aEvent);
|
||||
})
|
||||
}));
|
||||
|
||||
promises.push(runEmulatorCmdSafe("gsm voice " + aState));
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new array of id attribute of input messages.
|
||||
*
|
||||
* @param aMessages an array of {Sms,Mms}Message instances.
|
||||
*
|
||||
* @return an array of numeric values.
|
||||
*/
|
||||
function messagesToIds(aMessages) {
|
||||
let ids = [];
|
||||
for (let message of aMessages) {
|
||||
ids.push(message.id);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient function to compare two SMS messages.
|
||||
*/
|
||||
function compareSmsMessage(aFrom, aTo) {
|
||||
const FIELDS = ["id", "threadId", "iccId", "body", "delivery",
|
||||
"deliveryStatus", "read", "receiver", "sender",
|
||||
"messageClass", "timestamp", "deliveryTimestamp",
|
||||
"sentTimestamp"];
|
||||
|
||||
for (let field of FIELDS) {
|
||||
is(aFrom[field], aTo[field], "message." + field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for pending emulator transactions and call |finish()|.
|
||||
*/
|
||||
function cleanUp() {
|
||||
ok(true, ":: CLEANING UP ::");
|
||||
|
||||
waitFor(finish, function() {
|
||||
return pendingEmulatorCmdCount === 0;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test routine helper for mobile message tests.
|
||||
*
|
||||
* This helper does nothing but clean-ups.
|
||||
*
|
||||
* @param aTestCaseMain
|
||||
* A function that takes no parameter.
|
||||
*/
|
||||
function startTestBase(aTestCaseMain) {
|
||||
Promise.resolve()
|
||||
.then(aTestCaseMain)
|
||||
.then(cleanUp, function() {
|
||||
ok(false, 'promise rejects during test.');
|
||||
cleanUp();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Common test routine helper for mobile message tests.
|
||||
*
|
||||
* This function ensures global |manager| variable is available during the
|
||||
* process and performs clean-ups as well.
|
||||
*
|
||||
* @param aTestCaseMain
|
||||
* A function that takes no parameter.
|
||||
*/
|
||||
function startTestCommon(aTestCaseMain) {
|
||||
startTestBase(function() {
|
||||
return ensureMobileMessage()
|
||||
.then(deleteAllMessages)
|
||||
.then(aTestCaseMain)
|
||||
.then(deleteAllMessages);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to run the test case only needed in Multi-SIM environment.
|
||||
*
|
||||
* @param aTest
|
||||
* A function which will be invoked w/o parameter.
|
||||
* @return a Promise object.
|
||||
*/
|
||||
function runIfMultiSIM(aTest) {
|
||||
let numRIL;
|
||||
try {
|
||||
numRIL = SpecialPowers.getIntPref("ril.numRadioInterfaces");
|
||||
} catch (ex) {
|
||||
numRIL = 1; // Pref not set.
|
||||
}
|
||||
|
||||
if (numRIL > 1) {
|
||||
return aTest();
|
||||
} else {
|
||||
log("Not a Multi-SIM environment. Test is skipped.");
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to enable/disable connection radio state.
|
||||
*
|
||||
* @param aConnection
|
||||
* connection to enable / disable
|
||||
* @param aEnabled
|
||||
* True to enable the radio.
|
||||
* @return a Promise object.
|
||||
*/
|
||||
function setRadioEnabled(aConnection, aEnabled) {
|
||||
log("setRadioEnabled to " + aEnabled);
|
||||
|
||||
let deferred = Promise.defer();
|
||||
let finalState = (aEnabled) ? "enabled" : "disabled";
|
||||
if (aConnection.radioState == finalState) {
|
||||
return deferred.resolve(aConnection);
|
||||
}
|
||||
|
||||
aConnection.onradiostatechange = function() {
|
||||
log("Received 'radiostatechange', radioState: " + aConnection.radioState);
|
||||
|
||||
if (aConnection.radioState == finalState) {
|
||||
deferred.resolve(aConnection);
|
||||
aConnection.onradiostatechange = null;
|
||||
}
|
||||
};
|
||||
|
||||
let req = aConnection.setRadioEnabled(aEnabled);
|
||||
|
||||
req.onsuccess = function() {
|
||||
log("setRadioEnabled success");
|
||||
};
|
||||
|
||||
req.onerror = function() {
|
||||
ok(false, "setRadioEnabled should not fail");
|
||||
deferred.reject();
|
||||
};
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to enable/disable all connections radio state.
|
||||
*
|
||||
* @param aEnabled
|
||||
* True to enable the radio.
|
||||
* @return a Promise object.
|
||||
*/
|
||||
function setAllRadioEnabled(aEnabled) {
|
||||
let promises = []
|
||||
for (let i = 0; i < window.navigator.mozMobileConnections.length; ++i) {
|
||||
promises.push(ensureMobileConnection(i)
|
||||
.then((connection) => setRadioEnabled(connection, aEnabled)));
|
||||
}
|
||||
return Promise.all(promises);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
[DEFAULT]
|
||||
run-if = buildapp == 'b2g'
|
||||
|
||||
;[test_between_emulators.py]
|
||||
[test_bug814761.js]
|
||||
[test_decode_spanish_fallback.js]
|
||||
[test_emulator_loopback.js]
|
||||
[test_error_of_mms_manual_retrieval.js]
|
||||
[test_error_of_mms_send.js]
|
||||
[test_error_of_sms_send.js]
|
||||
[test_filter_date.js]
|
||||
[test_filter_mixed.js]
|
||||
[test_filter_number.js]
|
||||
[test_filter_read.js]
|
||||
[test_filter_received.js]
|
||||
[test_filter_sent.js]
|
||||
[test_filter_unread.js]
|
||||
[test_getmessage.js]
|
||||
[test_getmessage_notfound.js]
|
||||
[test_getmessages.js]
|
||||
[test_getsegmentinfofortext.js]
|
||||
[test_getthreads.js]
|
||||
[test_incoming_delete.js]
|
||||
[test_incoming.js]
|
||||
[test_incoming_max_segments.js]
|
||||
[test_invalid_address.js]
|
||||
[test_mark_msg_read_error.js]
|
||||
[test_mark_msg_read.js]
|
||||
[test_massive_incoming_delete.js]
|
||||
[test_message_classes.js]
|
||||
[test_mmdb_foreachmatchedmmsdeliveryinfo.js]
|
||||
[test_mmdb_full_storage.js]
|
||||
[test_mmdb_new.js]
|
||||
[test_mmdb_ports_in_cdma_wappush.js]
|
||||
[test_mmdb_setmessagedeliverybyid_sms.js]
|
||||
[test_mmdb_upgradeSchema_22.js]
|
||||
[test_mmdb_upgradeSchema_current_structure.js]
|
||||
[test_mmsmessage_attachments.js]
|
||||
[test_mobilemessage_dsds_default_service_id.js]
|
||||
[test_mt_sms_concatenation.js]
|
||||
[test_ondeleted_event.js]
|
||||
[test_outgoing_delete.js]
|
||||
[test_outgoing.js]
|
||||
[test_outgoing_max_segments.js]
|
||||
[test_outgoing_unstable_voice_connection.js]
|
||||
[test_phone_number_normalization.js]
|
||||
[test_replace_short_message_type.js]
|
||||
[test_segment_info.js]
|
||||
[test_smsc_address.js]
|
||||
[test_strict_7bit_encoding.js]
|
||||
[test_thread_subject.js]
|
||||
[test_update_gsm_nl_on_mcc_chanages.js]
|
||||
[test_update_thread_record_in_delete.js]
|
@ -1,404 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_CONTEXT = "chrome";
|
||||
|
||||
var Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
|
||||
|
||||
/**
|
||||
* Name space for MobileMessageDB.jsm. Only initialized after first call to
|
||||
* newMobileMessageDB.
|
||||
*/
|
||||
var MMDB;
|
||||
|
||||
/**
|
||||
* Create a new MobileMessageDB instance.
|
||||
*
|
||||
* @return A MobileMessageDB instance.
|
||||
*/
|
||||
function newMobileMessageDB() {
|
||||
if (!MMDB) {
|
||||
MMDB = Cu.import("resource://gre/modules/MobileMessageDB.jsm", {});
|
||||
is(typeof MMDB.MobileMessageDB, "function", "MMDB.MobileMessageDB");
|
||||
}
|
||||
|
||||
let mmdb = new MMDB.MobileMessageDB();
|
||||
ok(mmdb, "MobileMessageDB instance");
|
||||
return mmdb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a MobileMessageDB. Resolve if initialized with success, reject
|
||||
* otherwise.
|
||||
*
|
||||
* Fulfill params: a MobileMessageDB instance.
|
||||
* Reject params: a MobileMessageDB instance.
|
||||
*
|
||||
* @param aMmdb
|
||||
* A MobileMessageDB instance.
|
||||
* @param aDbName
|
||||
* A string name for that database.
|
||||
* @param aDbVersion
|
||||
* The version that MobileMessageDB should upgrade to. 0 for the lastest
|
||||
* version.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function initMobileMessageDB(aMmdb, aDbName, aDbVersion) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
aMmdb.init(aDbName, aDbVersion, function(aError) {
|
||||
if (aError) {
|
||||
deferred.reject(aMmdb);
|
||||
} else {
|
||||
deferred.resolve(aMmdb);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a MobileMessageDB.
|
||||
*
|
||||
* @param aMmdb
|
||||
* A MobileMessageDB instance.
|
||||
*
|
||||
* @return The passed MobileMessageDB instance.
|
||||
*/
|
||||
function closeMobileMessageDB(aMmdb) {
|
||||
aMmdb.close();
|
||||
return aMmdb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function for calling MMDB methods that takes either a
|
||||
* nsIGonkMobileMessageDatabaseCallback or a
|
||||
* nsIGonkMobileMessageDatabaseRecordCallback.
|
||||
*
|
||||
* Resolve when the target method notifies us with a successful result code;
|
||||
* reject otherwise. In either case, the arguments passed are packed into an
|
||||
* array and propagated to next action.
|
||||
*
|
||||
* Fulfill params: an array whose elements are the arguments of the original
|
||||
* callback.
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @param aMmdb
|
||||
* A MobileMessageDB instance.
|
||||
* @param aMethodName
|
||||
* A string name for that target method.
|
||||
* @param ...
|
||||
* Extra arguments to pass to that target method. The last callback
|
||||
* argument should always be excluded.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function callMmdbMethod(aMmdb, aMethodName) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let args = Array.slice(arguments, 2);
|
||||
args.push({
|
||||
notify: function(aRv) {
|
||||
if (!Components.isSuccessCode(aRv)) {
|
||||
ok(true, aMethodName + " returns a unsuccessful code: " + aRv);
|
||||
deferred.reject(Array.slice(arguments));
|
||||
} else {
|
||||
ok(true, aMethodName + " returns a successful code: " + aRv);
|
||||
deferred.resolve(Array.slice(arguments));
|
||||
}
|
||||
}
|
||||
});
|
||||
aMmdb[aMethodName].apply(aMmdb, args);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.saveSendingMessage(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <DOM message>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function saveSendingMessage(aMmdb, aMessage) {
|
||||
return callMmdbMethod(aMmdb, "saveSendingMessage", aMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.saveReceivedMessage(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <DOM message>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function saveReceivedMessage(aMmdb, aMessage) {
|
||||
return callMmdbMethod(aMmdb, "saveReceivedMessage", aMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.setMessageDeliveryByMessageId(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <DOM message>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function setMessageDeliveryByMessageId(aMmdb, aMessageId, aReceiver, aDelivery,
|
||||
aDeliveryStatus, aEnvelopeId) {
|
||||
return callMmdbMethod(aMmdb, "setMessageDeliveryByMessageId", aMessageId,
|
||||
aReceiver, aDelivery, aDeliveryStatus, aEnvelopeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling
|
||||
* |mmdb.setMessageDeliveryStatusByEnvelopeId(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <DOM message>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function setMessageDeliveryStatusByEnvelopeId(aMmdb, aEnvelopeId, aReceiver,
|
||||
aDeliveryStatus) {
|
||||
return callMmdbMethod(aMmdb, "setMessageDeliveryStatusByEnvelopeId",
|
||||
aMmdb, aEnvelopeId, aReceiver, aDeliveryStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling
|
||||
* |mmdb.setMessageReadStatusByEnvelopeId(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <DOM message>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function setMessageReadStatusByEnvelopeId(aMmdb, aEnvelopeId, aReceiver,
|
||||
aReadStatus) {
|
||||
return callMmdbMethod(aMmdb, "setMessageReadStatusByEnvelopeId",
|
||||
aEnvelopeId, aReceiver, aReadStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling
|
||||
* |mmdb.getMessageRecordByTransactionId(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <DB Record>, <DOM message>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getMessageRecordByTransactionId(aMmdb, aTransactionId) {
|
||||
return callMmdbMethod(aMmdb, "getMessageRecordByTransactionId",
|
||||
aTransactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.getMessageRecordById(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <DB Record>, <DOM message>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function getMessageRecordById(aMmdb, aMessageId) {
|
||||
return callMmdbMethod(aMmdb, "getMessageRecordById", aMessageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.markMessageRead(...)|.
|
||||
*
|
||||
* Fulfill params: Ci.nsIMobileMessageCallback.FOO.
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function markMessageRead(aMmdb, aMessageId, aRead) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
aMmdb.markMessageRead(aMessageId, aRead, false, {
|
||||
notifyMarkMessageReadFailed: function(aRv) {
|
||||
ok(true, "markMessageRead returns a unsuccessful code: " + aRv);
|
||||
deferred.reject(aRv);
|
||||
},
|
||||
|
||||
notifyMessageMarkedRead: function(aRead) {
|
||||
ok(true, "markMessageRead returns a successful code: " + Cr.NS_OK);
|
||||
deferred.resolve(Ci.nsIMobileMessageCallback.SUCCESS_NO_ERROR);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.deleteMessage(...)|.
|
||||
*
|
||||
* Fulfill params: array of deleted flags.
|
||||
* Reject params: Ci.nsIMobileMessageCallback.FOO.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function deleteMessage(aMmdb, aMessageIds, aLength) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
aMmdb.deleteMessage(aMessageIds, aLength, {
|
||||
notifyDeleteMessageFailed: function(aRv) {
|
||||
ok(true, "deleteMessage returns a unsuccessful code: " + aRv);
|
||||
deferred.reject(aRv);
|
||||
},
|
||||
|
||||
notifyMessageDeleted: function(aDeleted, aLength) {
|
||||
ok(true, "deleteMessage successfully!");
|
||||
deferred.resolve(aDeleted);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.saveSmsSegment(...)|.
|
||||
*
|
||||
* Fulfill params: [<Cr.NS_ERROR_FOO>, <completeMessage>].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function saveSmsSegment(aMmdb, aSmsSegment) {
|
||||
return callMmdbMethod(aMmdb, "saveSmsSegment", aSmsSegment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function for calling cursor-based MMDB methods.
|
||||
*
|
||||
* Resolve when the target method notifies us with |notifyCursorDone|,
|
||||
* reject otherwise.
|
||||
*
|
||||
* Fulfill params: [<Ci.nsIMobileMessageCallback.FOO>, [<DOM message/thread>]]
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @param aMmdb
|
||||
* A MobileMessageDB instance.
|
||||
* @param aMethodName
|
||||
* A string name for that target method.
|
||||
* @param ...
|
||||
* Extra arguments to pass to that target method. The last callback
|
||||
* argument should always be excluded.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function createMmdbCursor(aMmdb, aMethodName) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
let cursor;
|
||||
let results = [];
|
||||
let args = Array.slice(arguments, 2);
|
||||
args.push({
|
||||
notifyCursorError: function(aRv) {
|
||||
ok(true, "notifyCursorError: " + aRv);
|
||||
deferred.reject([aRv, results]);
|
||||
},
|
||||
|
||||
notifyCursorResult: function(aResults, aSize) {
|
||||
ok(true, "notifyCursorResult: " + aResults.map(function(aElement) { return aElement.id; }));
|
||||
results = results.concat(aResults);
|
||||
cursor.handleContinue();
|
||||
},
|
||||
|
||||
notifyCursorDone: function() {
|
||||
ok(true, "notifyCursorDone");
|
||||
deferred.resolve([Ci.nsIMobileMessageCallback.SUCCESS_NO_ERROR, results]);
|
||||
}
|
||||
});
|
||||
|
||||
cursor = aMmdb[aMethodName].apply(aMmdb, args);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.createMessageCursor(...)|.
|
||||
*
|
||||
* Fulfill params: [<Ci.nsIMobileMessageCallback.FOO>, [<DOM message>]].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function createMessageCursor(aMmdb, aStartDate = null, aEndDate = null,
|
||||
aNumbers = null, aDelivery = null, aRead = null,
|
||||
aThreadId = null, aReverse = false) {
|
||||
return createMmdbCursor(aMmdb, "createMessageCursor",
|
||||
aStartDate !== null,
|
||||
aStartDate || 0,
|
||||
aEndDate !== null,
|
||||
aEndDate || 0,
|
||||
aNumbers || null,
|
||||
aNumbers && aNumbers.length || 0,
|
||||
aDelivery || null,
|
||||
aRead !== null,
|
||||
aRead || false,
|
||||
aThreadId !== null,
|
||||
aThreadId || 0,
|
||||
aReverse || false);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient function for calling |mmdb.createThreadCursor(...)|.
|
||||
*
|
||||
* Fulfill params: [<Ci.nsIMobileMessageCallback.FOO>, [<DOM thread>]].
|
||||
* Reject params: same as fulfill params.
|
||||
*
|
||||
* @return A deferred promise.
|
||||
*/
|
||||
function createThreadCursor(aMmdb) {
|
||||
return createMmdbCursor(aMmdb, "createThreadCursor");
|
||||
}
|
||||
|
||||
// A reference to a nsIUUIDGenerator service.
|
||||
var _uuidGenerator;
|
||||
|
||||
/**
|
||||
* Generate a new UUID.
|
||||
*
|
||||
* @return A UUID string.
|
||||
*/
|
||||
function newUUID() {
|
||||
if (!_uuidGenerator) {
|
||||
_uuidGenerator = Cc["@mozilla.org/uuid-generator;1"]
|
||||
.getService(Ci.nsIUUIDGenerator);
|
||||
ok(_uuidGenerator, "uuidGenerator");
|
||||
}
|
||||
|
||||
return _uuidGenerator.generateUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush permission settings and call |finish()|.
|
||||
*/
|
||||
function cleanUp() {
|
||||
// Use ok here so that we have at least one test run.
|
||||
ok(true, "permissions flushed");
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test routine helper for mobile message tests.
|
||||
*
|
||||
* This helper does nothing but clean-ups.
|
||||
*
|
||||
* @param aTestCaseMain
|
||||
* A function that takes no parameter.
|
||||
*/
|
||||
function startTestBase(aTestCaseMain) {
|
||||
Promise.resolve()
|
||||
.then(aTestCaseMain)
|
||||
.then(null, function() {
|
||||
ok(false, 'promise rejects during test.');
|
||||
})
|
||||
.then(cleanUp);
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
from marionette_test import *
|
||||
|
||||
|
||||
class SMSTest(MarionetteTestCase):
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test_sms_between_emulators(self):
|
||||
# Tests always have one emulator available as self.marionette; we'll
|
||||
# use this for the receiving emulator. We'll also launch a second
|
||||
# emulator to use as the sender.
|
||||
sender = self.get_new_emulator()
|
||||
receiver = self.marionette
|
||||
|
||||
self.set_up_test_page(sender, "test.html", ["sms"])
|
||||
self.set_up_test_page(receiver, "test.html", ["sms"])
|
||||
|
||||
# Setup the event listsener on the receiver, which should store
|
||||
# a global variable when an SMS is received.
|
||||
message = 'hello world!'
|
||||
self.assertTrue(receiver.execute_script("return window.navigator.mozMobileMessage != null;"))
|
||||
receiver.execute_script("""
|
||||
global.smsreceived = null;
|
||||
window.navigator.mozMobileMessage.addEventListener("received", function(e) {
|
||||
global.smsreceived = e.message.body;
|
||||
});
|
||||
""", new_sandbox=False)
|
||||
|
||||
# Send the SMS from the sender.
|
||||
sender.execute_script("""
|
||||
window.navigator.mozMobileMessage.send("%d", "%s");
|
||||
""" % (receiver.emulator.port, message))
|
||||
|
||||
# On the receiver, wait up to 10s for an SMS to be received, by
|
||||
# checking the value of the global var that the listener will change.
|
||||
receiver.set_script_timeout(0) # TODO no timeout for now since the test fails
|
||||
received = receiver.execute_async_script("""
|
||||
waitFor(function () {
|
||||
marionetteScriptFinished(global.smsreceived);
|
||||
}, function () {
|
||||
return global.smsreceived
|
||||
});
|
||||
""", new_sandbox=False)
|
||||
self.assertEqual(received, message)
|
@ -1,72 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
|
||||
SpecialPowers.setBoolPref("dom.sms.enabled", true);
|
||||
SpecialPowers.addPermission("sms", true, document);
|
||||
|
||||
var manager = window.navigator.mozMobileMessage;
|
||||
ok(manager instanceof MozMobileMessageManager,
|
||||
"manager is instance of " + manager.constructor);
|
||||
|
||||
// Note: 378 chars and below is fine, but 379 and above will cause the issue.
|
||||
// Sending first message works, but second one we get emulator callback but
|
||||
// the actual SMS is never received, so script will timeout waiting for the
|
||||
// onreceived event. Also note that a single larger message (i.e. 1600
|
||||
// characters) works; so it is not a compounded send limit.
|
||||
var fromNumber = "5551110000";
|
||||
var msgLength = 379;
|
||||
var msgText = new Array(msgLength + 1).join('a');
|
||||
|
||||
var pendingEmulatorCmdCount = 0;
|
||||
function sendSmsToEmulator(from, text) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
let cmd = "sms send " + from + " " + text;
|
||||
runEmulatorCmd(cmd, function(result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
|
||||
is(result[0], "OK", "Emulator response");
|
||||
});
|
||||
}
|
||||
|
||||
function firstIncomingSms() {
|
||||
simulateIncomingSms(secondIncomingSms);
|
||||
}
|
||||
|
||||
function secondIncomingSms() {
|
||||
simulateIncomingSms(cleanUp);
|
||||
}
|
||||
|
||||
function simulateIncomingSms(nextFunction) {
|
||||
log("Simulating incoming multipart SMS (" + msgText.length
|
||||
+ " chars total).");
|
||||
|
||||
manager.onreceived = function onreceived(event) {
|
||||
log("Received 'onreceived' event.");
|
||||
manager.onreceived = null;
|
||||
|
||||
let incomingSms = event.message;
|
||||
ok(incomingSms, "incoming sms");
|
||||
is(incomingSms.body, msgText, "msg body");
|
||||
|
||||
window.setTimeout(nextFunction, 0);
|
||||
};
|
||||
|
||||
sendSmsToEmulator(fromNumber, msgText);
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("sms", document);
|
||||
SpecialPowers.clearUserPref("dom.sms.enabled");
|
||||
finish();
|
||||
}
|
||||
|
||||
// Start the test
|
||||
firstIncomingSms();
|
@ -1,52 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
const PDU_SMSC_NONE = "00"; // no SMSC Address
|
||||
|
||||
// | TP-RP|TP-UDHI| TP-SRI| Unused | TP-MMS| TP-MTI |
|
||||
// | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | => 0x40
|
||||
const PDU_FIRST_OCTET = "40";
|
||||
|
||||
// | | <= TON => | <=== NOI ===> |
|
||||
// | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | => 0xa8
|
||||
const PDU_OA = "0AA89021436587"; // 0912345678
|
||||
|
||||
const PDU_PID_NORMAL = "00";
|
||||
const PDU_DCS_GSM_7BIT = "00";
|
||||
const PDU_TIMESTAMP = "51302151740020"; // 2015/3/12 15:47:00 UTC+8
|
||||
|
||||
// ==> | <========== G ==========> |
|
||||
// | 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | => 0xc7
|
||||
// ======> | <========== S =========
|
||||
// | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | => 0x69
|
||||
// |<=padding=>| <========== M =====
|
||||
// | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | => 0x13
|
||||
const PDU_UD_GSM = "C76913";
|
||||
|
||||
const IE_USE_SPANISH_LOCKING_SHIFT_TABLE = "250102";
|
||||
const IE_USE_SPANISH_SINGLE_SHIFT_TABLE = "240102";
|
||||
const PDU_UDHL = "06";
|
||||
|
||||
const PDU_UDL = "0B"; // UDH occupies 7 octets = 8 septets, plus 3 septets data.
|
||||
|
||||
const PDU = PDU_SMSC_NONE + PDU_FIRST_OCTET + PDU_OA + PDU_PID_NORMAL
|
||||
+ PDU_DCS_GSM_7BIT + PDU_TIMESTAMP + PDU_UDL + PDU_UDHL
|
||||
+ IE_USE_SPANISH_LOCKING_SHIFT_TABLE + IE_USE_SPANISH_SINGLE_SHIFT_TABLE
|
||||
+ PDU_UD_GSM;
|
||||
|
||||
function verifyMessage(aMessage) {
|
||||
is(aMessage.body, "GSM", "SmsMessage body");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test and verify that user data encoded in GSM default alphabet can be
|
||||
* correctly decoded with Spanish locking shift table. See bug 1138841.
|
||||
*/
|
||||
startTestCommon(function testCaseMain() {
|
||||
return Promise.resolve()
|
||||
.then(() => sendMultipleRawSmsToEmulatorAndWait([PDU]))
|
||||
.then(results => verifyMessage(results[0].message));
|
||||
});
|
@ -1,71 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
const SELF = "5554";
|
||||
|
||||
function randomString16() {
|
||||
return Math.random().toString(36).substr(2, 16);
|
||||
}
|
||||
|
||||
function times(str, n) {
|
||||
return (new Array(n + 1)).join(str);
|
||||
}
|
||||
|
||||
function test(aBody) {
|
||||
let promises = [];
|
||||
|
||||
promises.push(waitForManagerEvent('received')
|
||||
.then(function(aEvent) {
|
||||
let message = aEvent.message;
|
||||
is(message.body, aBody, "message.body");
|
||||
}));
|
||||
|
||||
promises.push(sendSmsWithSuccess(SELF, aBody));
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
const TEST_DATA = [
|
||||
// Random alphanumeric string of 16 characters.
|
||||
randomString16(),
|
||||
// Long long text message for multipart messages.
|
||||
times(randomString16(), 100),
|
||||
|
||||
// UCS2 string for the first sentence of "The Cooing", Classic of Poetry.
|
||||
"\u95dc\u95dc\u96ce\u9ce9\uff0c\u5728\u6cb3\u4e4b\u6d32\u3002",
|
||||
// Long long UCS2 text message for multipart messages.
|
||||
times("\u95dc\u95dc\u96ce\u9ce9\uff0c\u5728\u6cb3\u4e4b\u6d32\u3002", 100),
|
||||
|
||||
// Test case from Bug 809553
|
||||
"zertuuuppzuzyeueieieyeieoeiejeheejrueufjfjfjjfjfkxifjfjfufjjfjfufujdjduxxjdu"
|
||||
+ "djdjdjdudhdjdhdjdbddhbfjfjxbuwjdjdudjddjdhdhdvdyudusjdudhdjjfjdvdudbddjdbd"
|
||||
+ "usjfbjdfudjdhdjbzuuzyzehdjjdjwybwudjvwywuxjdbfudsbwuwbwjdjdbwywhdbddudbdjd"
|
||||
+ "uejdhdudbdduwjdbjddudjdjdjdudjdbdjdhdhdjjdjbxudjdbxufjudbdjhdjdisjsjzusbzh"
|
||||
+ "xbdudksksuqjgdjdb jeudi jeudis duhebevzcevevsvs DVD suscite eh du d des jv"
|
||||
+ " y b Dj. Du wh. Hu Deb wh. Du web h w show d DVD h w v. Th\u00e9 \u00e9c"
|
||||
+ "hec d whdvdj. Wh d'h\u00f4tel DVD. IMAX eusjw ii ce",
|
||||
|
||||
// Android Emulator specific problems:
|
||||
// 1) wrong default 7Bit alphabet character for "Ň"(U+0147).
|
||||
"\u0147",
|
||||
// 2) problem in decoding strings encoded with GSM 7Bit Alphabets and
|
||||
// containing characters on extension tables.
|
||||
"\u20ac****",
|
||||
];
|
||||
|
||||
startTestBase(function testCaseMain() {
|
||||
return ensureMobileMessage()
|
||||
.then(function() {
|
||||
let promise = Promise.resolve();
|
||||
|
||||
for (let i = 0; i < TEST_DATA.length; i++) {
|
||||
let text = TEST_DATA[i];
|
||||
promise = promise.then(() => test(text));
|
||||
}
|
||||
|
||||
return promise;
|
||||
});
|
||||
});
|
@ -1,218 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
|
||||
// We apply "chrome" context to be more flexible to
|
||||
// specify the content of M-Notification.ind such as iccId
|
||||
// for different kinds of testing.
|
||||
MARIONETTE_CONTEXT = "chrome";
|
||||
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
var MMS = {};
|
||||
Cu.import("resource://gre/modules/MmsPduHelper.jsm", MMS);
|
||||
|
||||
var gMobileMessageDatabaseService =
|
||||
Cc["@mozilla.org/mobilemessage/gonkmobilemessagedatabaseservice;1"]
|
||||
.getService(Ci.nsIGonkMobileMessageDatabaseService);
|
||||
|
||||
var gUuidGenerator =
|
||||
Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
||||
|
||||
var gMmsService =
|
||||
Cc["@mozilla.org/mms/gonkmmsservice;1"].getService(Ci.nsIMmsService);
|
||||
|
||||
var gMobileConnectionService =
|
||||
Cc["@mozilla.org/mobileconnection/mobileconnectionservice;1"]
|
||||
.getService(Ci.nsIMobileConnectionService);
|
||||
|
||||
var gIccService =
|
||||
Cc["@mozilla.org/icc/gonkiccservice;1"].getService(Ci.nsIIccService);
|
||||
|
||||
function saveMmsNotification() {
|
||||
log("saveMmsNotification()");
|
||||
let tid = gUuidGenerator.generateUUID().toString();
|
||||
tid = tid.substr(1, tid.length - 2); // strip parentheses {}.
|
||||
|
||||
let headers = {};
|
||||
headers["x-mms-message-type"] = MMS.MMS_PDU_TYPE_NOTIFICATION_IND;
|
||||
headers["x-mms-transaction-id"] = tid;
|
||||
headers["x-mms-mms-version"] = MMS.MMS_VERSION;
|
||||
headers["x-mms-message-class"] = "personal";
|
||||
headers["x-mms-message-size"] = 255;
|
||||
headers["x-mms-expiry"] = 24 * 60 * 60;
|
||||
headers["x-mms-content-location"] = "http://192.168.0.1/mms.cgi" + "?tid=" + tid;
|
||||
let notification = {
|
||||
headers: headers,
|
||||
type: "mms",
|
||||
delivery: "not-downloaded",
|
||||
deliveryStatus: "manual",
|
||||
timestamp: Date.now(),
|
||||
receivers: [],
|
||||
phoneNumber: "+0987654321",
|
||||
iccId: "01234567899876543210"
|
||||
};
|
||||
|
||||
let deferred = Promise.defer();
|
||||
|
||||
gMobileMessageDatabaseService
|
||||
.saveReceivedMessage(notification, function(aRv, aDomMessage) {
|
||||
log("saveReceivedMessage(): " + aRv);
|
||||
if (Components.isSuccessCode(aRv)) {
|
||||
deferred.resolve(aDomMessage.QueryInterface(Ci.nsIMmsMessage));
|
||||
} else {
|
||||
deferred.reject();
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function deleteMessagesById(aIds) {
|
||||
log("deleteMessagesById()");
|
||||
let deferred = Promise.defer();
|
||||
let request = {
|
||||
notifyDeleteMessageFailed: function(aRv) {
|
||||
log("notifyDeleteMessageFailed()");
|
||||
deferred.reject();
|
||||
},
|
||||
notifyMessageDeleted: function(aDeleted, aLength) {
|
||||
log("notifyMessageDeleted()");
|
||||
deferred.resolve();
|
||||
},
|
||||
};
|
||||
gMobileMessageDatabaseService
|
||||
.deleteMessage(aIds, aIds.length, request);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function verifyErrorCause(aResponse, aCause) {
|
||||
is(aResponse, aCause, "Test error cause of retrieval.");
|
||||
|
||||
return deleteMessagesById([aResponse.id]);
|
||||
}
|
||||
|
||||
function retrieveMmsWithFailure(aId) {
|
||||
log("retrieveMmsWithFailure()");
|
||||
let deferred = Promise.defer();
|
||||
let request = {
|
||||
notifyGetMessageFailed: function(aRv) {
|
||||
log("notifyGetMessageFailed()");
|
||||
deferred.resolve(aRv);
|
||||
}
|
||||
};
|
||||
gMmsService.retrieve(aId, request);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function testRetrieve(aCause) {
|
||||
log("testRetrieve: aCause = " + aCause);
|
||||
return Promise.resolve()
|
||||
.then(saveMmsNotification)
|
||||
.then((message) => retrieveMmsWithFailure(message.id))
|
||||
.then((response) => verifyErrorCause(response, aCause));
|
||||
}
|
||||
|
||||
function setRadioEnabled(aConnection, aEnabled) {
|
||||
let deferred = Promise.defer();
|
||||
let finalState = (aEnabled) ?
|
||||
Ci.nsIMobileConnection.MOBILE_RADIO_STATE_ENABLED :
|
||||
Ci.nsIMobileConnection.MOBILE_RADIO_STATE_DISABLED;
|
||||
|
||||
if (aConnection.radioState == finalState) {
|
||||
return deferred.resolve(aConnection);
|
||||
}
|
||||
let listener = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionListener]),
|
||||
notifyVoiceChanged: function() {},
|
||||
notifyDataChanged: function() {},
|
||||
notifyDataError: function(message) {},
|
||||
notifyCFStateChanged: function(action, reason, number, timeSeconds, serviceClass) {},
|
||||
notifyEmergencyCbModeChanged: function(active, timeoutMs) {},
|
||||
notifyOtaStatusChanged: function(status) {},
|
||||
notifyRadioStateChanged: function() {
|
||||
log("setRadioEnabled state changed to " + aConnection.radioState);
|
||||
if (aConnection.radioState == finalState) {
|
||||
aConnection.unregisterListener(listener);
|
||||
deferred.resolve(aConnection);
|
||||
}
|
||||
},
|
||||
notifyClirModeChanged: function(mode) {},
|
||||
notifyLastKnownNetworkChanged: function() {},
|
||||
notifyLastKnownHomeNetworkChanged: function() {},
|
||||
notifyNetworkSelectionModeChanged: function() {},
|
||||
notifyDeviceIdentitiesChanged: function() {}
|
||||
};
|
||||
let callback = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMobileConnectionCallback]),
|
||||
notifySuccess() {},
|
||||
notifySuccessWithBoolean(result) {},
|
||||
notifyGetNetworksSuccess(count, networks) {},
|
||||
notifyGetCallForwardingSuccess(count, results) {},
|
||||
notifyGetCallBarringSuccess(program, enabled, serviceClass) {},
|
||||
notifyGetCallWaitingSuccess(serviceClass) {},
|
||||
notifyGetClirStatusSuccess(n, m) {},
|
||||
notifyGetPreferredNetworkTypeSuccess(type) {},
|
||||
notifyGetRoamingPreferenceSuccess(mode) {},
|
||||
notifyError(name) {
|
||||
log("setRadioEnabled reject");
|
||||
aConnection.unregisterListener(listener);
|
||||
deferred.reject();
|
||||
}
|
||||
};
|
||||
aConnection.registerListener(listener);
|
||||
aConnection.setRadioEnabled(aEnabled, callback);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function setAllRadioEnabled(aEnabled) {
|
||||
log("setAllRadioEnabled connection number = " +
|
||||
gMobileConnectionService.numItems);
|
||||
|
||||
let promises = [];
|
||||
for (let i = 0; i < gMobileConnectionService.numItems; ++i) {
|
||||
promises.push(setRadioEnabled(
|
||||
gMobileConnectionService.getItemByServiceId(i), aEnabled));
|
||||
}
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
function waitIccReady(aIcc) {
|
||||
let deferred = Promise.defer();
|
||||
if (aIcc.cardState == Ci.nsIIcc.CARD_STATE_READY) {
|
||||
return deferred.resolve(aIcc);
|
||||
}
|
||||
let listener = {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIIccListener]),
|
||||
notifyStkCommand(aStkProactiveCmd) {},
|
||||
notifyStkSessionEnd() {},
|
||||
notifyCardStateChanged() {
|
||||
if (aIcc.cardState == Ci.nsIIcc.CARD_STATE_READY) {
|
||||
aIcc.unregisterListener(listener);
|
||||
deferred.resolve(aIcc);
|
||||
}
|
||||
},
|
||||
notifyIccInfoChanged() {}
|
||||
};
|
||||
aIcc.registerListener(listener);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function waitAllIccReady() {
|
||||
let promises = [];
|
||||
for (let i = 0; i < gMobileConnectionService.numItems; ++i) {
|
||||
let icc = gIccService.getIccByServiceId(i);
|
||||
promises.push(waitIccReady(icc));
|
||||
}
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
setAllRadioEnabled(false)
|
||||
.then(() => testRetrieve(Ci.nsIMobileMessageCallback.RADIO_DISABLED_ERROR))
|
||||
.then(() => setAllRadioEnabled(true))
|
||||
.then(() => waitAllIccReady())
|
||||
.then(() => testRetrieve(Ci.nsIMobileMessageCallback.SIM_NOT_MATCHED_ERROR))
|
||||
.then(finish);
|
@ -1,50 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
function testSendFailed(aCause, aServiceId) {
|
||||
log("testSendFailed, aCause: " + aCause + ", aServiceId: " + aServiceId);
|
||||
let sendParameters;
|
||||
|
||||
if (aServiceId) {
|
||||
sendParameters = { serviceId: aServiceId };
|
||||
}
|
||||
|
||||
let testSubject = "Test";
|
||||
let testReceivers = ["+0987654321"];
|
||||
|
||||
let mmsParameters = { subject: testSubject,
|
||||
receivers: testReceivers,
|
||||
attachments: [] };
|
||||
|
||||
return sendMmsWithFailure(mmsParameters, sendParameters)
|
||||
.then((result) => {
|
||||
is(result.error.name, aCause, "Checking failure cause.");
|
||||
|
||||
let domMessage = result.error.data;
|
||||
is(domMessage.id, result.message.id, "Checking message id.");
|
||||
is(domMessage.subject, testSubject, "Checking subject.");
|
||||
is(domMessage.receivers.length, testReceivers.length, "Checking no. of receivers.");
|
||||
for (let i = 0; i < testReceivers.length; i++) {
|
||||
is(domMessage.receivers[i], testReceivers[i], "Checking receiver address.");
|
||||
}
|
||||
|
||||
let deliveryInfo = domMessage.deliveryInfo;
|
||||
is(deliveryInfo.length, testReceivers.length, "Checking no. of deliveryInfo.");
|
||||
for (let i = 0; i < deliveryInfo.length; i++) {
|
||||
is(deliveryInfo[i].receiver, testReceivers[i], "Checking receiver address.");
|
||||
is(deliveryInfo[i].deliveryStatus, "error", "Checking deliveryStatus.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
startTestCommon(function testCaseMain() {
|
||||
return Promise.resolve()
|
||||
.then(() => setAllRadioEnabled(false))
|
||||
.then(() => testSendFailed("RadioDisabledError"), 0)
|
||||
.then(() => setAllRadioEnabled(true))
|
||||
.then(() => runIfMultiSIM(
|
||||
() => testSendFailed("NonActiveSimCardError", 1)));
|
||||
});
|
@ -1,31 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
function testSendFailed(aCause) {
|
||||
log("testSendFailed, aCause: " + aCause);
|
||||
|
||||
let testReceiver = "+0987654321";
|
||||
let testMessage = "quick fox jump over the lazy dog";
|
||||
|
||||
return sendSmsWithFailure(testReceiver, testMessage)
|
||||
.then((result) => {
|
||||
is(result.error.name, aCause, "Checking failure cause.");
|
||||
|
||||
let domMessage = result.error.data;
|
||||
is(domMessage.id, result.message.id, "Checking message id.");
|
||||
is(domMessage.receiver, testReceiver, "Checking receiver address.");
|
||||
is(domMessage.body, testMessage, "Checking message body.");
|
||||
is(domMessage.delivery, "error", "Checking delivery.");
|
||||
is(domMessage.deliveryStatus, "error", "Checking deliveryStatus.");
|
||||
});
|
||||
}
|
||||
|
||||
startTestCommon(function testCaseMain() {
|
||||
return ensureMobileConnection()
|
||||
.then(() => setRadioEnabled(mobileConnection, false))
|
||||
.then(() => testSendFailed("RadioDisabledError"))
|
||||
.then(() => setRadioEnabled(mobileConnection, true));
|
||||
});
|
@ -1,119 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
const NUMBER_OF_MESSAGES = 10;
|
||||
const REMOTE = "5552229797";
|
||||
|
||||
function simulateIncomingSms() {
|
||||
let promise = Promise.resolve();
|
||||
let messages = [];
|
||||
|
||||
for (let i = 0; i < NUMBER_OF_MESSAGES; i++) {
|
||||
let text = "Incoming SMS number " + i;
|
||||
promise = promise.then(() => sendTextSmsToEmulatorAndWait(REMOTE, text))
|
||||
.then(function(aMessage) {
|
||||
messages.push(aMessage);
|
||||
return messages;
|
||||
});
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
function test(aStartDate, aEndDate, aExpectedMessages) {
|
||||
let filter = {};
|
||||
if (aStartDate !== null) {
|
||||
filter.startDate = aStartDate;
|
||||
}
|
||||
if (aEndDate !== null) {
|
||||
filter.endDate = aEndDate;
|
||||
}
|
||||
|
||||
return getMessages(filter, false)
|
||||
.then(function(aFoundMessages) {
|
||||
log(" Found " + aFoundMessages.length + " messages, expected " +
|
||||
aExpectedMessages.length);
|
||||
is(aFoundMessages.length, aExpectedMessages.length, "aFoundMessages.length");
|
||||
});
|
||||
}
|
||||
|
||||
function reduceMessages(aMessages, aCompare) {
|
||||
return aMessages.reduce(function(results, message) {
|
||||
if (aCompare(message.timestamp)) {
|
||||
results.push(message);
|
||||
}
|
||||
return results;
|
||||
}, []);
|
||||
}
|
||||
|
||||
startTestCommon(function testCaseMain() {
|
||||
let startTime, endTime;
|
||||
let allMessages;
|
||||
|
||||
return simulateIncomingSms()
|
||||
.then((aMessages) => {
|
||||
allMessages = aMessages;
|
||||
startTime = aMessages[0].timestamp;
|
||||
endTime = aMessages[NUMBER_OF_MESSAGES - 1].timestamp;
|
||||
log("startTime: " + startTime + ", endTime: " + endTime);
|
||||
})
|
||||
|
||||
// Should return all messages.
|
||||
//
|
||||
.then(() => log("Testing [startTime, )"))
|
||||
.then(() => test(startTime, null, allMessages))
|
||||
.then(() => log("Testing (, endTime]"))
|
||||
.then(() => test(null, endTime, allMessages))
|
||||
.then(() => log("Testing [startTime, endTime]"))
|
||||
.then(() => test(startTime, endTime, allMessages))
|
||||
|
||||
// Should return only messages with timestamp <= startTime.
|
||||
//
|
||||
.then(() => log("Testing [, startTime)"))
|
||||
.then(() => test(null, startTime,
|
||||
reduceMessages(allMessages,
|
||||
(function(a, b) {
|
||||
return b <= a;
|
||||
}).bind(null, startTime))))
|
||||
|
||||
// Should return only messages with timestamp <= startTime + 1.
|
||||
//
|
||||
.then(() => log("Testing [, startTime + 1)"))
|
||||
.then(() => test(null, startTime + 1,
|
||||
reduceMessages(allMessages,
|
||||
(function(a, b) {
|
||||
return b <= a;
|
||||
}).bind(null, startTime + 1))))
|
||||
|
||||
// Should return only messages with timestamp >= endTime.
|
||||
//
|
||||
.then(() => log("Testing [endTime, )"))
|
||||
.then(() => test(endTime, null,
|
||||
reduceMessages(allMessages,
|
||||
(function(a, b) {
|
||||
return b >= a;
|
||||
}).bind(null, endTime))))
|
||||
|
||||
// Should return only messages with timestamp >= endTime - 1.
|
||||
//
|
||||
.then(() => log("Testing [endTime - 1, )"))
|
||||
.then(() => test(endTime - 1, null,
|
||||
reduceMessages(allMessages,
|
||||
(function(a, b) {
|
||||
return b >= a;
|
||||
}).bind(null, endTime - 1))))
|
||||
|
||||
// Should return none.
|
||||
//
|
||||
.then(() => log("Testing [endTime + 1, )"))
|
||||
.then(() => test(endTime + 1, null, []))
|
||||
.then(() => log("Testing [endTime + 1, endTime + 86400000]"))
|
||||
.then(() => test(endTime + 1, endTime + 86400000, []))
|
||||
.then(() => log("Testing (, startTime - 1]"))
|
||||
.then(() => test(null, startTime - 1, []))
|
||||
.then(() => log("Testing [startTime - 86400000, startTime - 1]"))
|
||||
.then(() => test(startTime - 86400000, startTime - 1, []));
|
||||
});
|
@ -1,586 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
|
||||
const SELF = 5554;
|
||||
const NUM_THREADS = 10;
|
||||
|
||||
SpecialPowers.addPermission("sms", true, document);
|
||||
SpecialPowers.setBoolPref("dom.sms.enabled", true);
|
||||
|
||||
var manager = window.navigator.mozMobileMessage;
|
||||
ok(manager instanceof MozMobileMessageManager,
|
||||
"manager is instance of " + manager.constructor);
|
||||
|
||||
var pendingEmulatorCmdCount = 0;
|
||||
function sendSmsToEmulator(from, text) {
|
||||
++pendingEmulatorCmdCount;
|
||||
|
||||
let cmd = "sms send " + from + " " + text;
|
||||
runEmulatorCmd(cmd, function(result) {
|
||||
--pendingEmulatorCmdCount;
|
||||
|
||||
is(result[0], "OK", "Emulator response");
|
||||
});
|
||||
}
|
||||
|
||||
var tasks = {
|
||||
// List of test fuctions. Each of them should call |tasks.next()| when
|
||||
// completed or |tasks.finish()| to jump to the last one.
|
||||
_tasks: [],
|
||||
_nextTaskIndex: 0,
|
||||
|
||||
push: function(func) {
|
||||
this._tasks.push(func);
|
||||
},
|
||||
|
||||
next: function() {
|
||||
let index = this._nextTaskIndex++;
|
||||
let task = this._tasks[index];
|
||||
try {
|
||||
task();
|
||||
} catch (ex) {
|
||||
ok(false, "test task[" + index + "] throws: " + ex);
|
||||
// Run last task as clean up if possible.
|
||||
if (index != this._tasks.length - 1) {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
finish: function() {
|
||||
this._tasks[this._tasks.length - 1]();
|
||||
},
|
||||
|
||||
run: function() {
|
||||
this.next();
|
||||
}
|
||||
};
|
||||
|
||||
function getAllMessages(callback, filter, reverse) {
|
||||
let messages = [];
|
||||
let request = manager.getMessages(filter, reverse || false);
|
||||
request.onsuccess = function(event) {
|
||||
if (request.result) {
|
||||
messages.push(request.result);
|
||||
request.continue();
|
||||
return;
|
||||
}
|
||||
|
||||
window.setTimeout(callback.bind(null, messages), 0);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteAllMessages(next) {
|
||||
getAllMessages(function deleteAll(messages) {
|
||||
let message = messages.shift();
|
||||
if (!message) {
|
||||
ok(true, "all messages deleted");
|
||||
tasks.next();
|
||||
return;
|
||||
}
|
||||
|
||||
let request = manager.delete(message.id);
|
||||
request.onsuccess = deleteAll.bind(null, messages);
|
||||
request.onerror = function(event) {
|
||||
ok(false, "failed to delete all messages");
|
||||
tasks.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkSenderOrReceiver(message, number) {
|
||||
return message.sender == number ||
|
||||
message.sender == ("+1" + number) ||
|
||||
message.receiver == number ||
|
||||
message.receiver == ("+1" + number);
|
||||
}
|
||||
|
||||
tasks.push(deleteAllMessages);
|
||||
|
||||
/**
|
||||
* Populate MobileMessageDB with messages to being tests. We'll have NUM_THREADS
|
||||
* sent and received messages, and NUM_THREADS/2 unread received messages.
|
||||
*
|
||||
* send to "+15555315550"
|
||||
* receive from "5555315550", count = 1
|
||||
* mark received as read
|
||||
*
|
||||
* send to "+15555315551"
|
||||
* receive from "5555315551", count = 2
|
||||
*
|
||||
* send to "+15555315552"
|
||||
* receive from "5555315552", count = 3
|
||||
* mark received as read
|
||||
* ...
|
||||
* send to "+15555315559"
|
||||
* receive from "5555315559", count = 10
|
||||
*/
|
||||
var threadIds = [];
|
||||
tasks.push(function populateMessages() {
|
||||
let count = 0;
|
||||
|
||||
function sendMessage(iter) {
|
||||
let request = manager.send("+1555531555" + iter, "Nice to meet you");
|
||||
request.onsuccess = function onRequestSuccess(event) {
|
||||
manager.addEventListener("received", onReceived);
|
||||
|
||||
threadIds.push(request.result.threadId);
|
||||
|
||||
sendSmsToEmulator("555531555" + iter, "Nice to meet you, too");
|
||||
}
|
||||
request.onerror = function onRequestError(event) {
|
||||
tasks.finish();
|
||||
}
|
||||
}
|
||||
|
||||
function onReceived(event) {
|
||||
manager.removeEventListener("received", onReceived);
|
||||
|
||||
if (event.message.threadId != threadIds[threadIds.length - 1]) {
|
||||
ok(false, "Thread IDs of sent and received message mismatch.");
|
||||
tasks.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
++count;
|
||||
if (count % 2) {
|
||||
let request = manager.markMessageRead(event.message.id, true);
|
||||
request.onsuccess = function onRequestSuccess(event) {
|
||||
if (count < NUM_THREADS) {
|
||||
sendMessage(count);
|
||||
} else {
|
||||
tasks.next();
|
||||
}
|
||||
}
|
||||
request.onerror = function onRequestError(event) {
|
||||
tasks.finish();
|
||||
}
|
||||
} else if (count < NUM_THREADS) {
|
||||
sendMessage(count);
|
||||
} else {
|
||||
tasks.next();
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage(count);
|
||||
});
|
||||
|
||||
var INVALID_NUMBER = "12345";
|
||||
var INVALID_NUMBER2 = "6789";
|
||||
|
||||
var INVALID_THREAD_ID;
|
||||
tasks.push(function assignInvalidThreadID() {
|
||||
INVALID_THREAD_ID = threadIds[threadIds.length - 1] + 1;
|
||||
log("Set INVALID_THREAD_ID to be " + INVALID_THREAD_ID);
|
||||
tasks.next();
|
||||
});
|
||||
|
||||
tasks.push(function testDeliveryAndNumber() {
|
||||
log("Checking delivery == sent && number == 5555315550");
|
||||
let filter = {
|
||||
delivery: "sent",
|
||||
numbers: ["5555315550"],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// Only { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
is(messages.length, 1, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
is(message.delivery, filter.delivery, "message delivery");
|
||||
if (!checkSenderOrReceiver(message, filter.numbers[0])) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
}
|
||||
|
||||
getAllMessages(function(messages_r) {
|
||||
is(messages.length, messages_r.length, "message count");
|
||||
for (let i = 0; i < messages_r.length; i++) {
|
||||
is(messages_r[i].id, messages[messages.length - 1 - i].id, "message id");
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter, true);
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testDeliveryAndNumberNotFound() {
|
||||
log("Checking delivery == sent && number == INVALID_NUMBER");
|
||||
let filter = {
|
||||
delivery: "sent",
|
||||
numbers: [INVALID_NUMBER],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
is(messages.length, 0, "message count");
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testDeliveryAndRead() {
|
||||
log("Checking delivery == received && read == true");
|
||||
let filter = {
|
||||
delivery: "received",
|
||||
read: true,
|
||||
}
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "received", sender: "5555315550", read: true },
|
||||
// { delivery: "received", sender: "5555315552", read: true },
|
||||
// { delivery: "received", sender: "5555315554", read: true },
|
||||
// { delivery: "received", sender: "5555315556", read: true },
|
||||
// { delivery: "received", sender: "5555315558", read: true },
|
||||
is(messages.length, NUM_THREADS / 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
is(message.delivery, filter.delivery, "message delivery");
|
||||
is(message.read, filter.read, "message read");
|
||||
}
|
||||
|
||||
getAllMessages(function(messages_r) {
|
||||
is(messages.length, messages_r.length, "message count");
|
||||
for (let i = 0; i < messages_r.length; i++) {
|
||||
is(messages_r[i].id, messages[messages.length - 1 - i].id, "message id");
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter, true);
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testDeliveryAndReadNotFound() {
|
||||
log("Checking delivery == sent && read == false");
|
||||
let filter = {
|
||||
delivery: "sent",
|
||||
read: false,
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
is(messages.length, 0, "message count");
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testDeliveryAndThreadId() {
|
||||
log("Checking delivery == received && threadId == " + threadIds[0]);
|
||||
let filter = {
|
||||
delivery: "sent",
|
||||
threadId: threadIds[0],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", threadId: threadIds[0]}
|
||||
is(messages.length, 1, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
is(message.delivery, filter.delivery, "message delivery");
|
||||
is(message.threadId, filter.threadId, "message threadId");
|
||||
}
|
||||
|
||||
getAllMessages(function(messages_r) {
|
||||
is(messages.length, messages_r.length, "message count");
|
||||
for (let i = 0; i < messages_r.length; i++) {
|
||||
is(messages_r[i].id, messages[messages.length - 1 - i].id, "message id");
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter, true);
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testDeliveryAndThreadIdNotFound() {
|
||||
log("Checking delivery == sent && threadId == INVALID_THREAD_ID");
|
||||
let filter = {
|
||||
delivery: "sent",
|
||||
threadId: INVALID_THREAD_ID,
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
is(messages.length, 0, "message count");
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testNumberAndRead() {
|
||||
log("Checking number == 5555315550 && read == true");
|
||||
let filter = {
|
||||
numbers: ["5555315550"],
|
||||
read: true,
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
is(messages.length, 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
if (!checkSenderOrReceiver(message, filter.numbers[0])) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
is(message.read, filter.read, "message read");
|
||||
}
|
||||
|
||||
getAllMessages(function(messages_r) {
|
||||
is(messages.length, messages_r.length, "message count");
|
||||
for (let i = 0; i < messages_r.length; i++) {
|
||||
is(messages_r[i].id, messages[messages.length - 1 - i].id, "message id");
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter, true);
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testNumberAndReadNotFound() {
|
||||
log("Checking number == INVALID_NUMBER && read == true");
|
||||
let filter = {
|
||||
numbers: [INVALID_NUMBER],
|
||||
read: true,
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
is(messages.length, 0, "message count");
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testNumberAndThreadId() {
|
||||
log("Checking number == 5555315550 && threadId == " + threadIds[0]);
|
||||
let filter = {
|
||||
numbers: ["5555315550"],
|
||||
threadId: threadIds[0],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
is(messages.length, 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
if (!checkSenderOrReceiver(message, filter.numbers[0])) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
is(message.threadId, filter.threadId, "message threadId");
|
||||
}
|
||||
|
||||
getAllMessages(function(messages_r) {
|
||||
is(messages.length, messages_r.length, "message count");
|
||||
for (let i = 0; i < messages_r.length; i++) {
|
||||
is(messages_r[i].id, messages[messages.length - 1 - i].id, "message id");
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter, true);
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testNumberAndThreadIdNotFound() {
|
||||
log("Checking number == INVALID_NUMBER && threadId == INVALID_THREAD_ID");
|
||||
let filter = {
|
||||
numbers: [INVALID_NUMBER],
|
||||
threadId: INVALID_THREAD_ID,
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
is(messages.length, 0, "message count");
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testMultipleNumbers() {
|
||||
log("Checking number == 5555315550 || number == 5555315551");
|
||||
let filter = {
|
||||
numbers: ["5555315550", "5555315551"],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
// { delivery: "sent", receiver: "+15555315551", read: true }
|
||||
// { delivery: "received", sender: "5555315551", read: false }
|
||||
is(messages.length, 4, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
if (!(checkSenderOrReceiver(message, filter.numbers[0]) ||
|
||||
checkSenderOrReceiver(message, filter.numbers[1]))) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testMultipleNumbersNotFound() {
|
||||
log("Checking number == INVALID_NUMBER || number == INVALID_NUMBER2");
|
||||
let filter = {
|
||||
numbers: [INVALID_NUMBER, INVALID_NUMBER2],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
is(messages.length, 0, "message count");
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testDeliveryAndMultipleNumbers() {
|
||||
log("Checking delivery == sent && (number == 5555315550 || number == 5555315551)");
|
||||
let filter = {
|
||||
delivery: "sent",
|
||||
numbers: ["5555315550", "5555315551"],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "sent", receiver: "+15555315551", read: true }
|
||||
is(messages.length, 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
is(message.delivery, filter.delivery, "message delivery");
|
||||
if (!(checkSenderOrReceiver(message, filter.numbers[0]) ||
|
||||
checkSenderOrReceiver(message, filter.numbers[1]))) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testMultipleNumbersAndRead() {
|
||||
log("Checking (number == 5555315550 || number == 5555315551) && read == true");
|
||||
let filter = {
|
||||
numbers: ["5555315550", "5555315551"],
|
||||
read: true,
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
// { delivery: "sent", receiver: "+15555315551", read: true }
|
||||
is(messages.length, 3, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
is(message.read, filter.read, "message read");
|
||||
if (!(checkSenderOrReceiver(message, filter.numbers[0]) ||
|
||||
checkSenderOrReceiver(message, filter.numbers[1]))) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testMultipleNumbersAndThreadId() {
|
||||
log("Checking (number == 5555315550 || number == 5555315551) && threadId == " + threadIds[0]);
|
||||
let filter = {
|
||||
numbers: ["5555315550", "5555315551"],
|
||||
threadId: threadIds[0],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
is(messages.length, 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
is(message.threadId, filter.threadId, "message threadId");
|
||||
if (!(checkSenderOrReceiver(message, filter.numbers[0]) ||
|
||||
checkSenderOrReceiver(message, filter.numbers[1]))) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testNationalNumber() {
|
||||
log("Checking number = 5555315550");
|
||||
let filter = {
|
||||
numbers: ["5555315550"],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
is(messages.length, 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
if (!checkSenderOrReceiver(message, filter.numbers[0])) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testInternationalNumber() {
|
||||
log("Checking number = +15555315550");
|
||||
let filter = {
|
||||
numbers: ["+15555315550"],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
is(messages.length, 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
if (!checkSenderOrReceiver(message, "5555315550")) {
|
||||
ok(false, "message sender or receiver number");
|
||||
}
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testReadAndThreadId() {
|
||||
log("Checking read == true && threadId == " + threadIds[0]);
|
||||
let filter = {
|
||||
read: true,
|
||||
threadId: threadIds[0],
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
// { delivery: "sent", receiver: "+15555315550", read: true }
|
||||
// { delivery: "received", sender: "5555315550", read: true }
|
||||
is(messages.length, 2, "message count");
|
||||
for (let i = 0; i < messages.length; i++) {
|
||||
let message = messages[i];
|
||||
is(message.read, filter.read, "message read");
|
||||
is(message.threadId, filter.threadId, "message threadId");
|
||||
}
|
||||
|
||||
getAllMessages(function(messages_r) {
|
||||
is(messages.length, messages_r.length, "message count");
|
||||
for (let i = 0; i < messages_r.length; i++) {
|
||||
is(messages_r[i].id, messages[messages.length - 1 - i].id, "message id");
|
||||
}
|
||||
|
||||
tasks.next();
|
||||
}, filter, true);
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(function testReadAndThreadIdNotFound() {
|
||||
log("Checking read == true && threadId == INVALID_THREAD_ID");
|
||||
let filter = {
|
||||
read: true,
|
||||
threadId: INVALID_THREAD_ID,
|
||||
};
|
||||
getAllMessages(function(messages) {
|
||||
is(messages.length, 0, "message count");
|
||||
|
||||
tasks.next();
|
||||
}, filter);
|
||||
});
|
||||
|
||||
tasks.push(deleteAllMessages);
|
||||
|
||||
// WARNING: All tasks should be pushed before this!!!
|
||||
tasks.push(function cleanUp() {
|
||||
if (pendingEmulatorCmdCount) {
|
||||
window.setTimeout(cleanUp, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
SpecialPowers.removePermission("sms", document);
|
||||
SpecialPowers.clearUserPref("dom.sms.enabled");
|
||||
finish();
|
||||
});
|
||||
|
||||
tasks.run();
|
@ -1,100 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
MARIONETTE_HEAD_JS = 'head.js';
|
||||
|
||||
const REMOTE_NATIONAL_NUMBER = "552522555";
|
||||
const REMOTE_INTERNATIONAL_NUMBER = "+1" + REMOTE_NATIONAL_NUMBER;
|
||||
|
||||
const TEXT_1 = "Nice to meet you";
|
||||
const TEXT_2 = "Nice to meet you, too";
|
||||
|
||||
// Have a long long subject causes the send fails, so we don't need
|
||||
// networking here.
|
||||
const MMS_MAX_LENGTH_SUBJECT = 40;
|
||||
function genMmsSubject(sep) {
|
||||
return "Hello " + (new Array(MMS_MAX_LENGTH_SUBJECT).join(sep)) + " World!";
|
||||
}
|
||||
|
||||
function genFailingMms(aReceivers) {
|
||||
return {
|
||||
receivers: aReceivers,
|
||||
subject: genMmsSubject(' '),
|
||||
attachments: [],
|
||||
};
|
||||
}
|
||||
|
||||
function checkMessage(aNeedle, aValidNumbers) {
|
||||
log(" Verifying " + aNeedle);
|
||||
|
||||
let filter = { numbers: [aNeedle] };
|
||||
return getMessages(filter)
|
||||
.then(function(messages) {
|
||||
// Check the messages are sent to/received from aValidNumbers.
|
||||
is(messages.length, aValidNumbers.length, "messages.length");
|
||||
|
||||
for (let message of messages) {
|
||||
let number;
|
||||
if (message.type == "sms") {
|
||||
number = (message.delivery === "received") ? message.sender
|
||||
: message.receiver;
|
||||
} else {
|
||||
number = message.receivers[0];
|
||||
}
|
||||
|
||||
let index = aValidNumbers.indexOf(number);
|
||||
ok(index >= 0, "message.number");
|
||||
aValidNumbers.splice(index, 1); // Remove from aValidNumbers.
|
||||
}
|
||||
|
||||
is(aValidNumbers.length, 0, "aValidNumbers.length");
|
||||
});
|
||||
}
|
||||
|
||||
startTestCommon(function testCaseMain() {
|
||||
return Promise.resolve()
|
||||
|
||||
// SMS, MO:international, MT:national
|
||||
.then(() => sendSmsWithSuccess(REMOTE_INTERNATIONAL_NUMBER + '1', TEXT_1))
|
||||
.then(() => sendTextSmsToEmulator(REMOTE_NATIONAL_NUMBER + '1', TEXT_2))
|
||||
// SMS, MO:national, MT:international
|
||||
.then(() => sendSmsWithSuccess(REMOTE_NATIONAL_NUMBER + '2', TEXT_1))
|
||||
.then(() => sendTextSmsToEmulator(REMOTE_INTERNATIONAL_NUMBER + '2', TEXT_2))
|
||||
// MMS, international
|
||||
.then(() => sendMmsWithFailure(genFailingMms([REMOTE_INTERNATIONAL_NUMBER + '3'])))
|
||||
// MMS, national
|
||||
.then(() => sendMmsWithFailure(genFailingMms([REMOTE_NATIONAL_NUMBER + '3'])))
|
||||
// SMS, MO:international, MT:national, ambiguous number.
|
||||
.then(() => sendSmsWithSuccess(REMOTE_INTERNATIONAL_NUMBER + '4', TEXT_1))
|
||||
.then(() => sendTextSmsToEmulator(REMOTE_NATIONAL_NUMBER + '4', TEXT_2))
|
||||
.then(() => sendMmsWithFailure(genFailingMms(["jkalbcjklg"])))
|
||||
.then(() => sendMmsWithFailure(genFailingMms(["jk.alb.cjk.lg"])))
|
||||
// MMS, email
|
||||
.then(() => sendMmsWithFailure(genFailingMms(["jk@alb.cjk.lg"])))
|
||||
// MMS, IPv4
|
||||
.then(() => sendMmsWithFailure(genFailingMms(["55.252.255.54"])))
|
||||
// MMS, IPv6
|
||||
.then(() => sendMmsWithFailure(genFailingMms(["5:5:2:5:2:2:55:54"])))
|
||||
|
||||
.then(() => checkMessage(REMOTE_INTERNATIONAL_NUMBER + '1',
|
||||
[ REMOTE_INTERNATIONAL_NUMBER + '1',
|
||||
REMOTE_NATIONAL_NUMBER + '1' ]))
|
||||
.then(() => checkMessage(REMOTE_NATIONAL_NUMBER + '2',
|
||||
[ REMOTE_NATIONAL_NUMBER + '2',
|
||||
REMOTE_INTERNATIONAL_NUMBER + '2' ]))
|
||||
.then(() => checkMessage(REMOTE_INTERNATIONAL_NUMBER + '3',
|
||||
[ REMOTE_INTERNATIONAL_NUMBER + '3',
|
||||
REMOTE_NATIONAL_NUMBER + '3' ]))
|
||||
.then(() => checkMessage(REMOTE_NATIONAL_NUMBER + '3',
|
||||
[ REMOTE_NATIONAL_NUMBER + '3',
|
||||
REMOTE_INTERNATIONAL_NUMBER + '3' ]))
|
||||
.then(() => checkMessage(REMOTE_NATIONAL_NUMBER + '4',
|
||||
[ REMOTE_NATIONAL_NUMBER + '4',
|
||||
REMOTE_INTERNATIONAL_NUMBER + '4',
|
||||
"jkalbcjklg",
|
||||
"jk.alb.cjk.lg" ]))
|
||||
.then(() => checkMessage("jk@alb.cjk.lg", ["jk@alb.cjk.lg"]))
|
||||
.then(() => checkMessage("55.252.255.54", ["55.252.255.54"]))
|
||||
.then(() => checkMessage("5:5:2:5:2:2:55:54", ["5:5:2:5:2:2:55:54"]))
|
||||
});
|
@ -1,224 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
|
||||
SpecialPowers.addPermission("sms", true, document);
|
||||
SpecialPowers.setBoolPref("dom.sms.enabled", true);
|
||||
|
||||
var manager = window.navigator.mozMobileMessage;
|
||||
var numberMsgs = 10;
|
||||
var smsList = new Array();
|
||||
|
||||
function verifyInitialState() {
|
||||
log("Verifying initial state.");
|
||||
ok(manager instanceof MozMobileMessageManager,
|
||||
"manager is instance of " + manager.constructor);
|
||||
// Ensure test is starting clean with no existing sms messages
|
||||
deleteAllMsgs(simulateIncomingSms);
|
||||
}
|
||||
|
||||
function deleteAllMsgs(nextFunction) {
|
||||
let msgList = new Array();
|
||||
|
||||
let cursor = manager.getMessages();
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
// Check if message was found
|
||||
if (cursor.result) {
|
||||
msgList.push(cursor.result.id);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No (more) messages found
|
||||
if (msgList.length) {
|
||||
log("Found " + msgList.length + " SMS messages to delete.");
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("No SMS messages found.");
|
||||
nextFunction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function deleteMsgs(msgList, nextFunction) {
|
||||
let smsId = msgList.shift();
|
||||
|
||||
log("Deleting SMS (id: " + smsId + ").");
|
||||
let request = manager.delete(smsId);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if (event.target.result) {
|
||||
// Message deleted, continue until none are left
|
||||
if (msgList.length) {
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("Finished deleting SMS messages.");
|
||||
nextFunction();
|
||||
}
|
||||
} else {
|
||||
log("SMS delete failed.");
|
||||
ok(false,"manager.delete request returned false");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.delete request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function simulateIncomingSms() {
|
||||
let text = "Incoming SMS number " + (smsList.length + 1);
|
||||
let remoteNumber = "5552229797";
|
||||
|
||||
log("Simulating incoming SMS number " + (smsList.length + 1) + " of "
|
||||
+ numberMsgs + ".");
|
||||
|
||||
// Simulate incoming sms sent from remoteNumber to our emulator
|
||||
rcvdEmulatorCallback = false;
|
||||
runEmulatorCmd("sms send " + remoteNumber + " " + text, function(result) {
|
||||
is(result[0], "OK", "emulator callback");
|
||||
rcvdEmulatorCallback = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Callback for incoming sms
|
||||
manager.onreceived = function onreceived(event) {
|
||||
log("Received 'onreceived' sms event.");
|
||||
let incomingSms = event.message;
|
||||
log("Received SMS (id: " + incomingSms.id + ").");
|
||||
|
||||
// Add newly received message to array of received msgs
|
||||
smsList.push(incomingSms);
|
||||
|
||||
// Wait for emulator to catch up before continuing
|
||||
waitFor(nextRep,function() {
|
||||
return(rcvdEmulatorCallback);
|
||||
});
|
||||
};
|
||||
|
||||
function nextRep() {
|
||||
if (smsList.length < numberMsgs) {
|
||||
simulateIncomingSms();
|
||||
} else {
|
||||
// Marking all messages except first as read
|
||||
// Can remove first one from smsList array
|
||||
smsList.shift();
|
||||
markMsgRead(smsList.slice(0));
|
||||
}
|
||||
}
|
||||
|
||||
function markMsgRead(smsMsgs) {
|
||||
nextSms = smsMsgs.shift();
|
||||
log("Marking SMS (id: " + nextSms.id + ") as read.");
|
||||
let request = manager.markMessageRead(nextSms.id, true);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if (event.target.result) {
|
||||
// Message marked as read, continue until none are left
|
||||
if (smsMsgs.length) {
|
||||
markMsgRead(smsMsgs);
|
||||
} else {
|
||||
// Done, now test the filter
|
||||
getMsgs();
|
||||
}
|
||||
} else {
|
||||
log("SMS markMessageRead failed.");
|
||||
ok(false,"manager.markMessageRead request returned false");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.markMessageRead request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function getMsgs() {
|
||||
let foundSmsList = new Array();
|
||||
|
||||
// Set filter for read messages
|
||||
let filter = { read: true };
|
||||
|
||||
log("Getting the read SMS messages.");
|
||||
let cursor = manager.getMessages(filter, false);
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' event.");
|
||||
|
||||
if (cursor.result) {
|
||||
// Another message found
|
||||
log("Got SMS (id: " + cursor.result.id + ").");
|
||||
// Store found message
|
||||
foundSmsList.push(cursor.result);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No more messages; ensure correct number found
|
||||
if (foundSmsList.length == smsList.length) {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages as expected.");
|
||||
verifyFoundMsgs(foundSmsList);
|
||||
} else {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages, but expected " + smsList.length + ".");
|
||||
ok(false, "Incorrect number of messages returned by manager.getMessages");
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function verifyFoundMsgs(foundSmsList) {
|
||||
for (var x = 0; x < foundSmsList.length; x++) {
|
||||
is(foundSmsList[x].id, smsList[x].id, "id");
|
||||
is(foundSmsList[x].read, true, "read");
|
||||
}
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
manager.onreceived = null;
|
||||
SpecialPowers.removePermission("sms", document);
|
||||
SpecialPowers.clearUserPref("dom.sms.enabled");
|
||||
finish();
|
||||
}
|
||||
|
||||
// Start the test
|
||||
verifyInitialState();
|
@ -1,236 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
|
||||
SpecialPowers.addPermission("sms", true, document);
|
||||
SpecialPowers.setBoolPref("dom.sms.enabled", true);
|
||||
|
||||
var manager = window.navigator.mozMobileMessage;
|
||||
var numberMsgs = 10;
|
||||
var smsList = new Array();
|
||||
|
||||
function verifyInitialState() {
|
||||
log("Verifying initial state.");
|
||||
ok(manager instanceof MozMobileMessageManager,
|
||||
"manager is instance of " + manager.constructor);
|
||||
// Ensure test is starting clean with no existing sms messages
|
||||
deleteAllMsgs(simulateIncomingSms);
|
||||
}
|
||||
|
||||
function deleteAllMsgs(nextFunction) {
|
||||
let msgList = new Array();
|
||||
|
||||
let cursor = manager.getMessages();
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
// Check if message was found
|
||||
if (cursor.result) {
|
||||
msgList.push(cursor.result.id);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No (more) messages found
|
||||
if (msgList.length) {
|
||||
log("Found " + msgList.length + " SMS messages to delete.");
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("No SMS messages found.");
|
||||
nextFunction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function deleteMsgs(msgList, nextFunction) {
|
||||
let smsId = msgList.shift();
|
||||
|
||||
log("Deleting SMS (id: " + smsId + ").");
|
||||
let request = manager.delete(smsId);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if (event.target.result) {
|
||||
// Message deleted, continue until none are left
|
||||
if (msgList.length) {
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("Finished deleting SMS messages.");
|
||||
nextFunction();
|
||||
}
|
||||
} else {
|
||||
log("SMS delete failed.");
|
||||
ok(false,"manager.delete request returned false");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.delete request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function simulateIncomingSms() {
|
||||
let text = "Incoming SMS number " + (smsList.length + 1);
|
||||
let remoteNumber = "5552229797";
|
||||
|
||||
log("Simulating incoming SMS number " + (smsList.length + 1) + " of "
|
||||
+ (numberMsgs - 1) + ".");
|
||||
|
||||
// Simulate incoming sms sent from remoteNumber to our emulator
|
||||
rcvdEmulatorCallback = false;
|
||||
runEmulatorCmd("sms send " + remoteNumber + " " + text, function(result) {
|
||||
is(result[0], "OK", "emulator callback");
|
||||
rcvdEmulatorCallback = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Callback for incoming sms
|
||||
manager.onreceived = function onreceived(event) {
|
||||
log("Received 'onreceived' sms event.");
|
||||
let incomingSms = event.message;
|
||||
log("Received SMS (id: " + incomingSms.id + ").");
|
||||
|
||||
smsList.push(incomingSms);
|
||||
|
||||
// Wait for emulator to catch up before continuing
|
||||
waitFor(nextRep,function() {
|
||||
return(rcvdEmulatorCallback);
|
||||
});
|
||||
};
|
||||
|
||||
function nextRep() {
|
||||
if (smsList.length < (numberMsgs - 1)) {
|
||||
simulateIncomingSms();
|
||||
} else {
|
||||
// Now send one message also so the filter won't find all
|
||||
sendSms();
|
||||
}
|
||||
}
|
||||
|
||||
function sendSms() {
|
||||
let gotSmsSent = false;
|
||||
let gotRequestSuccess = false;
|
||||
let remoteNumber = "5557779999";
|
||||
let text = "Outgoing SMS brought to you by Firefox OS!";
|
||||
|
||||
log("Sending an SMS.");
|
||||
|
||||
manager.onsent = function(event) {
|
||||
log("Received 'onsent' event.");
|
||||
gotSmsSent = true;
|
||||
let sentSms = event.message;
|
||||
log("Sent SMS (id: " + sentSms.id + ").");
|
||||
is(sentSms.delivery, "sent", "delivery");
|
||||
if (gotSmsSent && gotRequestSuccess) {
|
||||
// Test the filter
|
||||
getMsgs();
|
||||
}
|
||||
};
|
||||
|
||||
let request = manager.send(remoteNumber, text);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if(event.target.result) {
|
||||
gotRequestSuccess = true;
|
||||
if (gotSmsSent && gotRequestSuccess) {
|
||||
// Test the filter
|
||||
getMsgs();
|
||||
}
|
||||
} else {
|
||||
log("smsrequest returned false for manager.send");
|
||||
ok(false,"SMS send failed");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.send request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function getMsgs() {
|
||||
let foundSmsList = new Array();
|
||||
|
||||
// Set filter for received messages
|
||||
let filter = { delivery: "received" };
|
||||
|
||||
log("Getting the received SMS messages.");
|
||||
let cursor = manager.getMessages(filter, false);
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' event.");
|
||||
|
||||
if (cursor.result) {
|
||||
// Another message found
|
||||
log("Got SMS (id: " + cursor.result.id + ").");
|
||||
// Store found message
|
||||
foundSmsList.push(cursor.result);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No more messages; ensure correct number found
|
||||
if (foundSmsList.length == smsList.length) {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages as expected.");
|
||||
verifyFoundMsgs(foundSmsList);
|
||||
} else {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages, but expected " + smsList.length + ".");
|
||||
ok(false, "Incorrect number of messages returned by manager.getMessages");
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function verifyFoundMsgs(foundSmsList) {
|
||||
for (var x = 0; x < foundSmsList.length; x++) {
|
||||
is(foundSmsList[x].id, smsList[x].id, "id");
|
||||
is(foundSmsList[x].delivery, "received", "delivery");
|
||||
}
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
manager.onreceived = null;
|
||||
SpecialPowers.removePermission("sms", document);
|
||||
SpecialPowers.clearUserPref("dom.sms.enabled");
|
||||
finish();
|
||||
}
|
||||
|
||||
// Start the test
|
||||
verifyInitialState();
|
@ -1,233 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
|
||||
SpecialPowers.addPermission("sms", true, document);
|
||||
SpecialPowers.setBoolPref("dom.sms.enabled", true);
|
||||
|
||||
var manager = window.navigator.mozMobileMessage;
|
||||
var numberMsgs = 10;
|
||||
var smsList = new Array();
|
||||
|
||||
function verifyInitialState() {
|
||||
log("Verifying initial state.");
|
||||
ok(manager instanceof MozMobileMessageManager,
|
||||
"manager is instance of " + manager.constructor);
|
||||
// Ensure test is starting clean with no existing sms messages
|
||||
deleteAllMsgs(sendSms);
|
||||
}
|
||||
|
||||
function deleteAllMsgs(nextFunction) {
|
||||
let msgList = new Array();
|
||||
|
||||
let cursor = manager.getMessages();
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
// Check if message was found
|
||||
if (cursor.result) {
|
||||
msgList.push(cursor.result.id);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No (more) messages found
|
||||
if (msgList.length) {
|
||||
log("Found " + msgList.length + " SMS messages to delete.");
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("No SMS messages found.");
|
||||
nextFunction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function deleteMsgs(msgList, nextFunction) {
|
||||
let smsId = msgList.shift();
|
||||
|
||||
log("Deleting SMS (id: " + smsId + ").");
|
||||
let request = manager.delete(smsId);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if (event.target.result) {
|
||||
// Message deleted, continue until none are left
|
||||
if (msgList.length) {
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("Finished deleting SMS messages.");
|
||||
nextFunction();
|
||||
}
|
||||
} else {
|
||||
log("SMS delete failed.");
|
||||
ok(false,"manager.delete request returned false");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.delete request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function sendSms() {
|
||||
let gotSmsSent = false;
|
||||
let gotRequestSuccess = false;
|
||||
let remoteNumber = "5557779999";
|
||||
let text = "Outgoing SMS brought to you by Firefox OS!";
|
||||
|
||||
log("Sending SMS " + (smsList.length + 1) + " of "
|
||||
+ (numberMsgs - 1) + ".");
|
||||
|
||||
manager.onsent = function(event) {
|
||||
log("Received 'onsent' event.");
|
||||
gotSmsSent = true;
|
||||
let sentSms = event.message;
|
||||
log("Sent SMS (id: " + sentSms.id + ").");
|
||||
is(sentSms.delivery, "sent", "delivery");
|
||||
smsList.push(sentSms);
|
||||
if (gotSmsSent && gotRequestSuccess) {
|
||||
nextRep();
|
||||
}
|
||||
};
|
||||
|
||||
let request = manager.send(remoteNumber, text);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if(event.target.result) {
|
||||
gotRequestSuccess = true;
|
||||
if (gotSmsSent && gotRequestSuccess) {
|
||||
nextRep();
|
||||
}
|
||||
} else {
|
||||
log("smsrequest returned false for manager.send");
|
||||
ok(false,"SMS send failed");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.send request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function nextRep() {
|
||||
if (smsList.length < (numberMsgs - 1)) {
|
||||
sendSms();
|
||||
} else {
|
||||
// Now receive one message so filter won't find all
|
||||
simulateIncomingSms();
|
||||
}
|
||||
}
|
||||
|
||||
function simulateIncomingSms() {
|
||||
let text = "Incoming SMS number " + (smsList.length + 1);
|
||||
let remoteNumber = "5552229797";
|
||||
|
||||
log("Simulating incoming SMS.");
|
||||
|
||||
// Simulate incoming sms sent from remoteNumber to our emulator
|
||||
rcvdEmulatorCallback = false;
|
||||
runEmulatorCmd("sms send " + remoteNumber + " " + text, function(result) {
|
||||
is(result[0], "OK", "emulator callback");
|
||||
rcvdEmulatorCallback = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Callback for incoming sms
|
||||
manager.onreceived = function onreceived(event) {
|
||||
log("Received 'onreceived' sms event.");
|
||||
let incomingSms = event.message;
|
||||
log("Received SMS (id: " + incomingSms.id + ").");
|
||||
|
||||
// Wait for emulator to catch up before continuing
|
||||
waitFor(getMsgs,function() {
|
||||
return(rcvdEmulatorCallback);
|
||||
});
|
||||
};
|
||||
|
||||
function getMsgs() {
|
||||
let foundSmsList = new Array();
|
||||
|
||||
// Set filter for sent messages
|
||||
let filter = { delivery: "sent" };
|
||||
|
||||
log("Getting the sent SMS messages.");
|
||||
let cursor = manager.getMessages(filter, false);
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' event.");
|
||||
|
||||
if (cursor.result) {
|
||||
// Another message found
|
||||
log("Got SMS (id: " + cursor.result.id + ").");
|
||||
// Store found message
|
||||
foundSmsList.push(cursor.result);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No more messages; ensure correct number found
|
||||
if (foundSmsList.length == smsList.length) {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages as expected.");
|
||||
verifyFoundMsgs(foundSmsList);
|
||||
} else {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages, but expected " + smsList.length + ".");
|
||||
ok(false, "Incorrect number of messages returned by manager.getMessages");
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function verifyFoundMsgs(foundSmsList) {
|
||||
for (var x = 0; x < foundSmsList.length; x++) {
|
||||
is(foundSmsList[x].id, smsList[x].id, "id");
|
||||
is(foundSmsList[x].delivery, "sent", "delivery");
|
||||
}
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
manager.onreceived = null;
|
||||
SpecialPowers.removePermission("sms", document);
|
||||
SpecialPowers.clearUserPref("dom.sms.enabled");
|
||||
finish();
|
||||
}
|
||||
|
||||
// Start the test
|
||||
verifyInitialState();
|
@ -1,218 +0,0 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
MARIONETTE_TIMEOUT = 60000;
|
||||
|
||||
SpecialPowers.addPermission("sms", true, document);
|
||||
SpecialPowers.setBoolPref("dom.sms.enabled", true);
|
||||
|
||||
var manager = window.navigator.mozMobileMessage;
|
||||
var numberMsgs = 10;
|
||||
var smsList = new Array();
|
||||
|
||||
function verifyInitialState() {
|
||||
log("Verifying initial state.");
|
||||
ok(manager instanceof MozMobileMessageManager,
|
||||
"manager is instance of " + manager.constructor);
|
||||
// Ensure test is starting clean with no existing sms messages
|
||||
deleteAllMsgs(simulateIncomingSms);
|
||||
}
|
||||
|
||||
function deleteAllMsgs(nextFunction) {
|
||||
let msgList = new Array();
|
||||
|
||||
let cursor = manager.getMessages();
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
// Check if message was found
|
||||
if (cursor.result) {
|
||||
msgList.push(cursor.result.id);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No (more) messages found
|
||||
if (msgList.length) {
|
||||
log("Found " + msgList.length + " SMS messages to delete.");
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("No SMS messages found.");
|
||||
nextFunction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function deleteMsgs(msgList, nextFunction) {
|
||||
let smsId = msgList.shift();
|
||||
|
||||
log("Deleting SMS (id: " + smsId + ").");
|
||||
let request = manager.delete(smsId);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if (event.target.result) {
|
||||
// Message deleted, continue until none are left
|
||||
if (msgList.length) {
|
||||
deleteMsgs(msgList, nextFunction);
|
||||
} else {
|
||||
log("Finished deleting SMS messages.");
|
||||
nextFunction();
|
||||
}
|
||||
} else {
|
||||
log("SMS delete failed.");
|
||||
ok(false,"manager.delete request returned false");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.delete request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function simulateIncomingSms() {
|
||||
let text = "Incoming SMS number " + (smsList.length + 1);
|
||||
let remoteNumber = "5552229797";
|
||||
|
||||
log("Simulating incoming SMS number " + (smsList.length + 1) + " of "
|
||||
+ numberMsgs + ".");
|
||||
|
||||
// Simulate incoming sms sent from remoteNumber to our emulator
|
||||
rcvdEmulatorCallback = false;
|
||||
runEmulatorCmd("sms send " + remoteNumber + " " + text, function(result) {
|
||||
is(result[0], "OK", "emulator callback");
|
||||
rcvdEmulatorCallback = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Callback for incoming sms
|
||||
manager.onreceived = function onreceived(event) {
|
||||
log("Received 'onreceived' sms event.");
|
||||
let incomingSms = event.message;
|
||||
log("Received SMS (id: " + incomingSms.id + ").");
|
||||
|
||||
// Add newly received message to array of received msgs
|
||||
smsList.push(incomingSms);
|
||||
|
||||
// Wait for emulator to catch up before continuing
|
||||
waitFor(nextRep,function() {
|
||||
return(rcvdEmulatorCallback);
|
||||
});
|
||||
};
|
||||
|
||||
function nextRep() {
|
||||
if (smsList.length < numberMsgs) {
|
||||
simulateIncomingSms();
|
||||
} else {
|
||||
markMsgRead();
|
||||
}
|
||||
}
|
||||
|
||||
function markMsgRead() {
|
||||
// Mark first message read so not all will be found by filter
|
||||
log("Marking SMS (id: " + smsList[0].id + ") as read.");
|
||||
let request = manager.markMessageRead(smsList[0].id, true);
|
||||
ok(request instanceof DOMRequest,
|
||||
"request is instanceof " + request.constructor);
|
||||
|
||||
request.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' smsrequest event.");
|
||||
if (event.target.result) {
|
||||
// First message was marked read, so remove from expected smsList
|
||||
smsList.shift();
|
||||
// Now test the filter
|
||||
getMsgs();
|
||||
} else {
|
||||
log("SMS markMessageRead failed.");
|
||||
ok(false,"manager.markMessageRead request returned false");
|
||||
cleanUp();
|
||||
}
|
||||
};
|
||||
|
||||
request.onerror = function(event) {
|
||||
log("Received 'onerror' smsrequest event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
ok(false, "manager.markMessageRead request returned unexpected error: "
|
||||
+ event.target.error.name );
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function getMsgs() {
|
||||
let foundSmsList = new Array();
|
||||
|
||||
// Set filter for read messages
|
||||
let filter = { read: false };
|
||||
|
||||
log("Getting the unread SMS messages.");
|
||||
let cursor = manager.getMessages(filter, false);
|
||||
ok(cursor instanceof DOMCursor,
|
||||
"cursor is instanceof " + cursor.constructor);
|
||||
|
||||
cursor.onsuccess = function(event) {
|
||||
log("Received 'onsuccess' event.");
|
||||
|
||||
if (cursor.result) {
|
||||
// Another message found
|
||||
log("Got SMS (id: " + cursor.result.id + ").");
|
||||
// Store found message
|
||||
foundSmsList.push(cursor.result);
|
||||
// Now get next message in the list
|
||||
cursor.continue();
|
||||
} else {
|
||||
// No more messages; ensure correct number found
|
||||
if (foundSmsList.length == smsList.length) {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages as expected.");
|
||||
verifyFoundMsgs(foundSmsList);
|
||||
} else {
|
||||
log("SMS getMessages returned " + foundSmsList.length +
|
||||
" messages, but expected " + smsList.length + ".");
|
||||
ok(false, "Incorrect number of messages returned by manager.getMessages");
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
cursor.onerror = function(event) {
|
||||
log("Received 'onerror' event.");
|
||||
ok(event.target.error, "domerror obj");
|
||||
log("manager.getMessages error: " + event.target.error.name);
|
||||
ok(false,"Could not get SMS messages");
|
||||
cleanUp();
|
||||
};
|
||||
}
|
||||
|
||||
function verifyFoundMsgs(foundSmsList) {
|
||||
for (var x = 0; x < foundSmsList.length; x++) {
|
||||
is(foundSmsList[x].id, smsList[x].id, "id");
|
||||
is(foundSmsList[x].read, false, "read");
|
||||
}
|
||||
deleteAllMsgs(cleanUp);
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
manager.onreceived = null;
|
||||
SpecialPowers.removePermission("sms", document);
|
||||
SpecialPowers.clearUserPref("dom.sms.enabled");
|
||||
finish();
|
||||
}
|
||||
|
||||
// Start the test
|
||||
verifyInitialState();
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user