mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
6d90091662
--HG-- rename : dom/mobilemessage/src/Constants.cpp => dom/mobilemessage/Constants.cpp rename : dom/mobilemessage/src/Constants.h => dom/mobilemessage/Constants.h rename : dom/mobilemessage/src/DOMMobileMessageError.cpp => dom/mobilemessage/DOMMobileMessageError.cpp rename : dom/mobilemessage/src/DOMMobileMessageError.h => dom/mobilemessage/DOMMobileMessageError.h rename : dom/mobilemessage/src/DeletedMessageInfo.cpp => dom/mobilemessage/DeletedMessageInfo.cpp rename : dom/mobilemessage/src/DeletedMessageInfo.h => dom/mobilemessage/DeletedMessageInfo.h rename : dom/mobilemessage/src/MmsMessage.cpp => dom/mobilemessage/MmsMessage.cpp rename : dom/mobilemessage/src/MmsMessage.h => dom/mobilemessage/MmsMessage.h rename : dom/mobilemessage/src/MobileMessageCallback.cpp => dom/mobilemessage/MobileMessageCallback.cpp rename : dom/mobilemessage/src/MobileMessageCallback.h => dom/mobilemessage/MobileMessageCallback.h rename : dom/mobilemessage/src/MobileMessageCursorCallback.cpp => dom/mobilemessage/MobileMessageCursorCallback.cpp rename : dom/mobilemessage/src/MobileMessageCursorCallback.h => dom/mobilemessage/MobileMessageCursorCallback.h rename : dom/mobilemessage/src/MobileMessageManager.cpp => dom/mobilemessage/MobileMessageManager.cpp rename : dom/mobilemessage/src/MobileMessageManager.h => dom/mobilemessage/MobileMessageManager.h rename : dom/mobilemessage/src/MobileMessageService.cpp => dom/mobilemessage/MobileMessageService.cpp rename : dom/mobilemessage/src/MobileMessageService.h => dom/mobilemessage/MobileMessageService.h rename : dom/mobilemessage/src/MobileMessageThread.cpp => dom/mobilemessage/MobileMessageThread.cpp rename : dom/mobilemessage/src/MobileMessageThread.h => dom/mobilemessage/MobileMessageThread.h rename : dom/mobilemessage/src/SmsMessage.cpp => dom/mobilemessage/SmsMessage.cpp rename : dom/mobilemessage/src/SmsMessage.h => dom/mobilemessage/SmsMessage.h rename : dom/mobilemessage/src/SmsServicesFactory.cpp => dom/mobilemessage/SmsServicesFactory.cpp rename : dom/mobilemessage/src/SmsServicesFactory.h => dom/mobilemessage/SmsServicesFactory.h rename : dom/mobilemessage/src/Types.h => dom/mobilemessage/Types.h rename : dom/mobilemessage/src/android/MobileMessageDatabaseService.cpp => dom/mobilemessage/android/MobileMessageDatabaseService.cpp rename : dom/mobilemessage/src/android/MobileMessageDatabaseService.h => dom/mobilemessage/android/MobileMessageDatabaseService.h rename : dom/mobilemessage/src/android/SmsService.cpp => dom/mobilemessage/android/SmsService.cpp rename : dom/mobilemessage/src/android/SmsService.h => dom/mobilemessage/android/SmsService.h rename : dom/mobilemessage/src/gonk/MmsPduHelper.jsm => dom/mobilemessage/gonk/MmsPduHelper.jsm rename : dom/mobilemessage/src/gonk/MmsService.js => dom/mobilemessage/gonk/MmsService.js rename : dom/mobilemessage/src/gonk/MmsService.manifest => dom/mobilemessage/gonk/MmsService.manifest rename : dom/mobilemessage/src/gonk/MobileMessageDB.jsm => dom/mobilemessage/gonk/MobileMessageDB.jsm rename : dom/mobilemessage/src/gonk/MobileMessageDatabaseService.js => dom/mobilemessage/gonk/MobileMessageDatabaseService.js rename : dom/mobilemessage/src/gonk/MobileMessageDatabaseService.manifest => dom/mobilemessage/gonk/MobileMessageDatabaseService.manifest rename : dom/mobilemessage/src/gonk/SmsService.cpp => dom/mobilemessage/gonk/SmsService.cpp rename : dom/mobilemessage/src/gonk/SmsService.h => dom/mobilemessage/gonk/SmsService.h rename : dom/mobilemessage/src/gonk/WspPduHelper.jsm => dom/mobilemessage/gonk/WspPduHelper.jsm rename : dom/mobilemessage/src/gonk/mms_consts.js => dom/mobilemessage/gonk/mms_consts.js rename : dom/mobilemessage/src/gonk/wap_consts.js => dom/mobilemessage/gonk/wap_consts.js rename : dom/mobilemessage/src/ipc/PMobileMessageCursor.ipdl => dom/mobilemessage/ipc/PMobileMessageCursor.ipdl rename : dom/mobilemessage/src/ipc/PSms.ipdl => dom/mobilemessage/ipc/PSms.ipdl rename : dom/mobilemessage/src/ipc/PSmsRequest.ipdl => dom/mobilemessage/ipc/PSmsRequest.ipdl rename : dom/mobilemessage/src/ipc/SmsChild.cpp => dom/mobilemessage/ipc/SmsChild.cpp rename : dom/mobilemessage/src/ipc/SmsChild.h => dom/mobilemessage/ipc/SmsChild.h rename : dom/mobilemessage/src/ipc/SmsIPCService.cpp => dom/mobilemessage/ipc/SmsIPCService.cpp rename : dom/mobilemessage/src/ipc/SmsIPCService.h => dom/mobilemessage/ipc/SmsIPCService.h rename : dom/mobilemessage/src/ipc/SmsParent.cpp => dom/mobilemessage/ipc/SmsParent.cpp rename : dom/mobilemessage/src/ipc/SmsParent.h => dom/mobilemessage/ipc/SmsParent.h rename : dom/mobilemessage/src/ipc/SmsTypes.ipdlh => dom/mobilemessage/ipc/SmsTypes.ipdlh
190 lines
5.2 KiB
C++
190 lines
5.2 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "MobileMessageThread.h"
|
|
#include "nsIDOMClassInfo.h"
|
|
#include "jsapi.h" // For OBJECT_TO_JSVAL and JS_NewDateObjectMsec
|
|
#include "jsfriendapi.h" // For js_DateGetMsecSinceEpoch
|
|
#include "nsJSUtils.h" // For nsAutoJSString
|
|
#include "nsTArrayHelpers.h" // For nsTArrayToJSArray
|
|
#include "mozilla/dom/mobilemessage/Constants.h" // For MessageType
|
|
|
|
using namespace mozilla::dom::mobilemessage;
|
|
|
|
DOMCI_DATA(MozMobileMessageThread, mozilla::dom::MobileMessageThread)
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
|
|
NS_INTERFACE_MAP_BEGIN(MobileMessageThread)
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozMobileMessageThread)
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozMobileMessageThread)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_ADDREF(MobileMessageThread)
|
|
NS_IMPL_RELEASE(MobileMessageThread)
|
|
|
|
/* static */ nsresult
|
|
MobileMessageThread::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,
|
|
nsIDOMMozMobileMessageThread** 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());
|
|
if (!JS_IsArrayObject(aCx, obj)) {
|
|
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<nsIDOMMozMobileMessageThread> thread = new MobileMessageThread(data);
|
|
thread.forget(aThread);
|
|
return NS_OK;
|
|
}
|
|
|
|
MobileMessageThread::MobileMessageThread(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());
|
|
}
|
|
|
|
MobileMessageThread::MobileMessageThread(const ThreadData& aData)
|
|
: mData(aData)
|
|
{
|
|
MOZ_ASSERT(aData.participants().Length());
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MobileMessageThread::GetId(uint64_t* aId)
|
|
{
|
|
*aId = mData.id();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MobileMessageThread::GetLastMessageSubject(nsAString& aLastMessageSubject)
|
|
{
|
|
aLastMessageSubject = mData.lastMessageSubject();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MobileMessageThread::GetBody(nsAString& aBody)
|
|
{
|
|
aBody = mData.body();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MobileMessageThread::GetUnreadCount(uint64_t* aUnreadCount)
|
|
{
|
|
*aUnreadCount = mData.unreadCount();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MobileMessageThread::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
|
|
MobileMessageThread::GetTimestamp(DOMTimeStamp* aDate)
|
|
{
|
|
*aDate = mData.timestamp();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
MobileMessageThread::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 dom
|
|
} // namespace mozilla
|