Bug 1023695 - Part 2: Add implementation of .idl/.ipdl. r=vyang.

This commit is contained in:
Bevis Tseng 2014-06-27 13:17:47 +08:00
parent eedb9d31d1
commit b278f1ed6f
9 changed files with 233 additions and 0 deletions

View File

@ -17,6 +17,7 @@ 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

View File

@ -21,6 +21,7 @@ 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")

View File

@ -0,0 +1,124 @@
/* -*- 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 "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;
}
nsresult rv;
mDeletedMessageIds = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, 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;
}
nsresult rv;
mDeletedThreadIds = do_CreateInstance(NS_VARIANT_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, 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

View File

@ -0,0 +1,58 @@
/* -*- 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/. */
#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 MOZ_FINAL : public nsIDeletedMessageInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDELETEDMESSAGEINFO
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

View File

@ -7,6 +7,7 @@
#include "MobileMessageThread.h"
#include "MobileMessageService.h"
#include "SmsSegmentInfo.h"
#include "DeletedMessageInfo.h"
namespace mozilla {
namespace dom {
@ -134,6 +135,20 @@ MobileMessageService::CreateThread(uint64_t aId,
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

View File

@ -6,6 +6,7 @@
#include "SmsMessage.h"
#include "MmsMessage.h"
#include "SmsSegmentInfo.h"
#include "DeletedMessageInfo.h"
#include "nsIObserverService.h"
#include "mozilla/Services.h"
#include "mozilla/dom/ContentChild.h"
@ -132,6 +133,21 @@ SmsChild::RecvNotifyReadErrorMessage(const MobileMessageData& 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)
{

View File

@ -64,6 +64,9 @@ protected:
virtual bool
RecvNotifyReadErrorMessage(const MobileMessageData& aMessage) MOZ_OVERRIDE;
virtual bool
RecvNotifyDeletedMessageInfo(const DeletedMessageInfoData& aDeletedInfo) MOZ_OVERRIDE;
virtual PSmsRequestChild*
AllocPSmsRequestChild(const IPCSmsRequest& aRequest) MOZ_OVERRIDE;

View File

@ -26,6 +26,7 @@
#include "nsCxPusher.h"
#include "xpcpublic.h"
#include "nsServiceManagerUtils.h"
#include "DeletedMessageInfo.h"
namespace mozilla {
namespace dom {
@ -179,6 +180,7 @@ SmsParent::SmsParent()
obs->AddObserver(this, kSilentSmsReceivedObserverTopic, false);
obs->AddObserver(this, kSmsReadSuccessObserverTopic, false);
obs->AddObserver(this, kSmsReadErrorObserverTopic, false);
obs->AddObserver(this, kSmsDeletedObserverTopic, false);
}
void
@ -199,6 +201,7 @@ SmsParent::ActorDestroy(ActorDestroyReason why)
obs->RemoveObserver(this, kSilentSmsReceivedObserverTopic);
obs->RemoveObserver(this, kSmsReadSuccessObserverTopic);
obs->RemoveObserver(this, kSmsReadErrorObserverTopic);
obs->RemoveObserver(this, kSmsDeletedObserverTopic);
}
NS_IMETHODIMP
@ -324,6 +327,17 @@ SmsParent::Observe(nsISupports* aSubject, const char* aTopic,
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;
}

View File

@ -47,6 +47,7 @@ EXPORTS.mozilla.dom += [
UNIFIED_SOURCES += [
'Constants.cpp',
'DeletedMessageInfo.cpp',
'DOMMobileMessageError.cpp',
'ipc/SmsChild.cpp',
'ipc/SmsIPCService.cpp',