зеркало из https://github.com/mozilla/gecko-dev.git
Bug 838467 3/5: IPC. r=sicking,bent
This commit is contained in:
Родитель
d7cb9ae399
Коммит
d1948ae387
|
@ -35,16 +35,6 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
|
||||
SmsChild::SmsChild()
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsChild);
|
||||
}
|
||||
|
||||
SmsChild::~SmsChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsChild);
|
||||
}
|
||||
|
||||
void
|
||||
SmsChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
|
@ -106,22 +96,33 @@ SmsChild::DeallocPSmsRequest(PSmsRequestChild* aActor)
|
|||
return true;
|
||||
}
|
||||
|
||||
PMobileMessageCursorChild*
|
||||
SmsChild::AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest)
|
||||
{
|
||||
MOZ_NOT_REACHED("Caller is supposed to manually construct a cursor!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsChild::DeallocPMobileMessageCursor(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)
|
||||
: mReplyRequest(aReplyRequest)
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsRequestChild);
|
||||
MOZ_ASSERT(aReplyRequest);
|
||||
}
|
||||
|
||||
SmsRequestChild::~SmsRequestChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsRequestChild);
|
||||
}
|
||||
|
||||
void
|
||||
SmsRequestChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
|
@ -155,21 +156,6 @@ SmsRequestChild::Recv__delete__(const MessageReply& aReply)
|
|||
case MessageReply::TReplyMessageDeleteFail:
|
||||
mReplyRequest->NotifyMessageDeleted(aReply.get_ReplyMessageDeleteFail().error());
|
||||
break;
|
||||
case MessageReply::TReplyNoMessageInList:
|
||||
mReplyRequest->NotifyNoMessageInList();
|
||||
break;
|
||||
case MessageReply::TReplyCreateMessageList:
|
||||
message = new SmsMessage(aReply.get_ReplyCreateMessageList().messageData());
|
||||
mReplyRequest->NotifyMessageListCreated(aReply.get_ReplyCreateMessageList().listId(),
|
||||
message);
|
||||
break;
|
||||
case MessageReply::TReplyCreateMessageListFail:
|
||||
mReplyRequest->NotifyReadMessageListFailed(aReply.get_ReplyCreateMessageListFail().error());
|
||||
break;
|
||||
case MessageReply::TReplyGetNextMessage:
|
||||
message = new SmsMessage(aReply.get_ReplyGetNextMessage().messageData());
|
||||
mReplyRequest->NotifyNextMessageInListGot(message);
|
||||
break;
|
||||
case MessageReply::TReplyMarkeMessageRead:
|
||||
mReplyRequest->NotifyMessageMarkedRead(aReply.get_ReplyMarkeMessageRead().read());
|
||||
break;
|
||||
|
@ -192,6 +178,61 @@ SmsRequestChild::Recv__delete__(const MessageReply& aReply)
|
|||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* MobileMessageCursorChild
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(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 SmsMessageData& aMessageData)
|
||||
{
|
||||
MOZ_ASSERT(mCursorCallback);
|
||||
|
||||
nsCOMPtr<nsISupports> result = new SmsMessage(aMessageData);
|
||||
mCursorCallback->NotifyCursorResult(result);
|
||||
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;
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -8,8 +8,10 @@
|
|||
|
||||
#include "mozilla/dom/mobilemessage/PSmsChild.h"
|
||||
#include "mozilla/dom/mobilemessage/PSmsRequestChild.h"
|
||||
|
||||
class nsIMobileMessageCallback;
|
||||
#include "mozilla/dom/mobilemessage/PMobileMessageCursorChild.h"
|
||||
#include "nsIDOMDOMCursor.h"
|
||||
#include "nsIMobileMessageCallback.h"
|
||||
#include "nsIMobileMessageCursorCallback.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -18,10 +20,16 @@ namespace mobilemessage {
|
|||
class SmsChild : public PSmsChild
|
||||
{
|
||||
public:
|
||||
SmsChild();
|
||||
SmsChild()
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsChild);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~SmsChild();
|
||||
virtual ~SmsChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsChild);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
|
||||
|
@ -49,6 +57,12 @@ protected:
|
|||
|
||||
virtual bool
|
||||
DeallocPSmsRequest(PSmsRequestChild* aActor) MOZ_OVERRIDE;
|
||||
|
||||
virtual PMobileMessageCursorChild*
|
||||
AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
DeallocPMobileMessageCursor(PMobileMessageCursorChild* aActor) MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
class SmsRequestChild : public PSmsRequestChild
|
||||
|
@ -61,7 +75,10 @@ public:
|
|||
SmsRequestChild(nsIMobileMessageCallback* aReplyRequest);
|
||||
|
||||
protected:
|
||||
virtual ~SmsRequestChild();
|
||||
virtual ~SmsRequestChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsRequestChild);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
|
||||
|
@ -70,6 +87,35 @@ protected:
|
|||
Recv__delete__(const MessageReply& aReply) MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
class MobileMessageCursorChild : public PMobileMessageCursorChild
|
||||
, public nsICursorContinueCallback
|
||||
{
|
||||
friend class SmsChild;
|
||||
|
||||
nsCOMPtr<nsIMobileMessageCursorCallback> mCursorCallback;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICURSORCONTINUECALLBACK
|
||||
|
||||
MobileMessageCursorChild(nsIMobileMessageCursorCallback* aCallback);
|
||||
|
||||
protected:
|
||||
virtual ~MobileMessageCursorChild()
|
||||
{
|
||||
MOZ_COUNT_DTOR(MobileMessageCursorChild);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
RecvNotifyResult(const SmsMessageData& aMessageData) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
Recv__delete__(const int32_t& aError) MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -13,46 +13,79 @@
|
|||
#include "SmsRequest.h"
|
||||
#include "SmsSegmentInfo.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
namespace mobilemessage {
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::dom::mobilemessage;
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO: Bug 767082 - WebSMS: sSmsChild leaks at shutdown
|
||||
PSmsChild* gSmsChild;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(SmsIPCService, nsISmsService, nsIMobileMessageDatabaseService)
|
||||
|
||||
void
|
||||
SendRequest(const IPCSmsRequest& aRequest, nsIMobileMessageCallback* aRequestReply)
|
||||
PSmsChild*
|
||||
GetSmsChild()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
NS_WARN_IF_FALSE(gSmsChild,
|
||||
"Calling methods on SmsIPCService during "
|
||||
"shutdown!");
|
||||
|
||||
if (gSmsChild) {
|
||||
SmsRequestChild* actor = new SmsRequestChild(aRequestReply);
|
||||
gSmsChild->SendPSmsRequestConstructor(actor, aRequest);
|
||||
}
|
||||
}
|
||||
|
||||
PSmsChild*
|
||||
SmsIPCService::GetSmsChild()
|
||||
{
|
||||
if (!gSmsChild) {
|
||||
gSmsChild = ContentChild::GetSingleton()->SendPSmsConstructor();
|
||||
|
||||
NS_WARN_IF_FALSE(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 CreateMessageCursorRequest& aRequest,
|
||||
nsIMobileMessageCursorCallback* aRequestReply,
|
||||
nsICursorContinueCallback** aResult)
|
||||
{
|
||||
PSmsChild* smsChild = GetSmsChild();
|
||||
NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
|
||||
|
||||
nsRefPtr<MobileMessageCursorChild> actor =
|
||||
new MobileMessageCursorChild(aRequestReply);
|
||||
|
||||
// Add an extra ref for IPDL. Will be released in
|
||||
// SmsChild::DeallocPMobileMessageCursor().
|
||||
actor->AddRef();
|
||||
|
||||
smsChild->SendPMobileMessageCursorConstructor(actor, aRequest);
|
||||
|
||||
actor.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
NS_IMPL_ISUPPORTS2(SmsIPCService,
|
||||
nsISmsService,
|
||||
nsIMobileMessageDatabaseService);
|
||||
|
||||
/*
|
||||
* Implementation of nsISmsService.
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::HasSupport(bool* aHasSupport)
|
||||
{
|
||||
GetSmsChild()->SendHasSupport(aHasSupport);
|
||||
PSmsChild* smsChild = GetSmsChild();
|
||||
NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
|
||||
|
||||
smsChild->SendHasSupport(aHasSupport);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -61,8 +94,11 @@ NS_IMETHODIMP
|
|||
SmsIPCService::GetSegmentInfoForText(const nsAString & aText,
|
||||
nsIDOMMozSmsSegmentInfo** aResult)
|
||||
{
|
||||
PSmsChild* smsChild = GetSmsChild();
|
||||
NS_ENSURE_TRUE(smsChild, NS_ERROR_FAILURE);
|
||||
|
||||
SmsSegmentInfoData data;
|
||||
bool ok = GetSmsChild()->SendGetSegmentInfoForText(nsString(aText), &data);
|
||||
bool ok = smsChild->SendGetSegmentInfoForText(nsString(aText), &data);
|
||||
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMMozSmsSegmentInfo> info = new SmsSegmentInfo(data);
|
||||
|
@ -75,8 +111,8 @@ SmsIPCService::Send(const nsAString& aNumber,
|
|||
const nsAString& aMessage,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
SendRequest(SendMessageRequest(nsString(aNumber), nsString(aMessage)), aRequest);
|
||||
return NS_OK;
|
||||
return SendRequest(SendMessageRequest(nsString(aNumber), nsString(aMessage)),
|
||||
aRequest);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -86,41 +122,27 @@ NS_IMETHODIMP
|
|||
SmsIPCService::GetMessageMoz(int32_t aMessageId,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
SendRequest(GetMessageRequest(aMessageId), aRequest);
|
||||
return NS_OK;
|
||||
return SendRequest(GetMessageRequest(aMessageId), aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::DeleteMessage(int32_t aMessageId,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
SendRequest(DeleteMessageRequest(aMessageId), aRequest);
|
||||
return NS_OK;
|
||||
return SendRequest(DeleteMessageRequest(aMessageId), aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::CreateMessageList(nsIDOMMozSmsFilter* aFilter,
|
||||
bool aReverse,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
SmsIPCService::CreateMessageCursor(nsIDOMMozSmsFilter* aFilter,
|
||||
bool aReverse,
|
||||
nsIMobileMessageCursorCallback* aCursorCallback,
|
||||
nsICursorContinueCallback** aResult)
|
||||
{
|
||||
SmsFilterData data = SmsFilterData(static_cast<SmsFilter*>(aFilter)->GetData());
|
||||
SendRequest(CreateMessageListRequest(data, aReverse), aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
const SmsFilterData& data =
|
||||
SmsFilterData(static_cast<SmsFilter*>(aFilter)->GetData());
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::GetNextMessageInList(int32_t aListId,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
SendRequest(GetNextMessageInListRequest(aListId), aRequest);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::ClearMessageList(int32_t aListId)
|
||||
{
|
||||
GetSmsChild()->SendClearMessageList(aListId);
|
||||
return NS_OK;
|
||||
return SendCursorRequest(CreateMessageCursorRequest(data, aReverse),
|
||||
aCursorCallback, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -128,17 +150,11 @@ SmsIPCService::MarkMessageRead(int32_t aMessageId,
|
|||
bool aValue,
|
||||
nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
SendRequest(MarkMessageReadRequest(aMessageId, aValue), aRequest);
|
||||
return NS_OK;
|
||||
return SendRequest(MarkMessageReadRequest(aMessageId, aValue), aRequest);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SmsIPCService::GetThreadList(nsIMobileMessageCallback* aRequest)
|
||||
{
|
||||
SendRequest(GetThreadListRequest(), aRequest);
|
||||
return NS_OK;
|
||||
return SendRequest(GetThreadListRequest(), aRequest);
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -23,9 +23,6 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISMSSERVICE
|
||||
NS_DECL_NSIMOBILEMESSAGEDATABASESERVICE
|
||||
|
||||
private:
|
||||
static PSmsChild* GetSmsChild();
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
|
|
|
@ -38,11 +38,6 @@ SmsParent::SmsParent()
|
|||
obs->AddObserver(this, kSmsDeliveryErrorObserverTopic, false);
|
||||
}
|
||||
|
||||
SmsParent::~SmsParent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsParent);
|
||||
}
|
||||
|
||||
void
|
||||
SmsParent::ActorDestroy(ActorDestroyReason why)
|
||||
{
|
||||
|
@ -173,17 +168,6 @@ SmsParent::RecvGetSegmentInfoForText(const nsString& aText,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvClearMessageList(const int32_t& aListId)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(mobileMessageDBService, true);
|
||||
|
||||
mobileMessageDBService->ClearMessageList(aListId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvPSmsRequestConstructor(PSmsRequestParent* aActor,
|
||||
const IPCSmsRequest& aRequest)
|
||||
|
@ -191,16 +175,12 @@ SmsParent::RecvPSmsRequestConstructor(PSmsRequestParent* aActor,
|
|||
SmsRequestParent* actor = static_cast<SmsRequestParent*>(aActor);
|
||||
|
||||
switch (aRequest.type()) {
|
||||
case IPCSmsRequest::TCreateMessageListRequest:
|
||||
return actor->DoRequest(aRequest.get_CreateMessageListRequest());
|
||||
case IPCSmsRequest::TSendMessageRequest:
|
||||
return actor->DoRequest(aRequest.get_SendMessageRequest());
|
||||
case IPCSmsRequest::TGetMessageRequest:
|
||||
return actor->DoRequest(aRequest.get_GetMessageRequest());
|
||||
case IPCSmsRequest::TDeleteMessageRequest:
|
||||
return actor->DoRequest(aRequest.get_DeleteMessageRequest());
|
||||
case IPCSmsRequest::TGetNextMessageInListRequest:
|
||||
return actor->DoRequest(aRequest.get_GetNextMessageInListRequest());
|
||||
case IPCSmsRequest::TMarkMessageReadRequest:
|
||||
return actor->DoRequest(aRequest.get_MarkMessageReadRequest());
|
||||
case IPCSmsRequest::TGetThreadListRequest:
|
||||
|
@ -227,10 +207,39 @@ SmsParent::DeallocPSmsRequest(PSmsRequestParent* aActor)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor,
|
||||
const CreateMessageCursorRequest& aRequest)
|
||||
{
|
||||
MobileMessageCursorParent* actor =
|
||||
static_cast<MobileMessageCursorParent*>(aActor);
|
||||
|
||||
return actor->DoRequest(aRequest);
|
||||
}
|
||||
|
||||
PMobileMessageCursorParent*
|
||||
SmsParent::AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest)
|
||||
{
|
||||
MobileMessageCursorParent* actor = new MobileMessageCursorParent();
|
||||
// Add an extra ref for IPDL. Will be released in
|
||||
// SmsParent::DeallocPMobileMessageCursor().
|
||||
actor->AddRef();
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsParent::DeallocPMobileMessageCursor(PMobileMessageCursorParent* aActor)
|
||||
{
|
||||
// MobileMessageCursorParent is refcounted, must not be freed manually.
|
||||
static_cast<MobileMessageCursorParent*>(aActor)->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* SmsRequestParent
|
||||
******************************************************************************/
|
||||
|
||||
SmsRequestParent::SmsRequestParent()
|
||||
{
|
||||
MOZ_COUNT_CTOR(SmsRequestParent);
|
||||
|
@ -303,37 +312,6 @@ SmsRequestParent::DoRequest(const DeleteMessageRequest& aRequest)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const CreateMessageListRequest& aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
|
||||
NS_ENSURE_TRUE(mobileMessageDBService, true);
|
||||
mSmsRequest = SmsRequest::Create(this);
|
||||
nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
|
||||
SmsFilter *filter = new SmsFilter(aRequest.filter());
|
||||
nsresult rv = mobileMessageDBService->CreateMessageList(filter, aRequest.reverse(), forwarder);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const GetNextMessageInListRequest& aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIMobileMessageDatabaseService> mobileMessageDBService =
|
||||
do_GetService(MOBILE_MESSAGE_DATABASE_SERVICE_CONTRACTID);
|
||||
|
||||
NS_ENSURE_TRUE(mobileMessageDBService, true);
|
||||
mSmsRequest = SmsRequest::Create(this);
|
||||
nsCOMPtr<nsIMobileMessageCallback> forwarder = new SmsRequestForwarder(mSmsRequest);
|
||||
nsresult rv = mobileMessageDBService->GetNextMessageInList(aRequest.aListId(), forwarder);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
SmsRequestParent::DoRequest(const MarkMessageReadRequest& aRequest)
|
||||
{
|
||||
|
@ -364,6 +342,90 @@ SmsRequestParent::DoRequest(const GetThreadListRequest& aRequest)
|
|||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* MobileMessageCursorParent
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(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) {
|
||||
nsCOMPtr<nsIDOMMozSmsFilter> filter = new SmsFilter(aRequest.filter());
|
||||
bool reverse = aRequest.reverse();
|
||||
|
||||
rv = dbService->CreateMessageCursor(filter, reverse, 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* aResult)
|
||||
{
|
||||
// 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);
|
||||
|
||||
SmsMessage* message = static_cast<SmsMessage*>(aResult);
|
||||
return SendNotifyResult(message->GetData()) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MobileMessageCursorParent::NotifyCursorDone()
|
||||
{
|
||||
return NotifyCursorError(nsIMobileMessageCallback::SUCCESS_NO_ERROR);
|
||||
}
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
#include "mozilla/dom/mobilemessage/PSmsParent.h"
|
||||
#include "mozilla/dom/mobilemessage/PSmsRequestParent.h"
|
||||
#include "mozilla/dom/mobilemessage/PMobileMessageCursorParent.h"
|
||||
#include "nsIDOMDOMCursor.h"
|
||||
#include "nsIMobileMessageCursorCallback.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -34,11 +37,11 @@ protected:
|
|||
virtual bool
|
||||
RecvGetSegmentInfoForText(const nsString& aText, SmsSegmentInfoData* aResult) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
RecvClearMessageList(const int32_t& aListId) MOZ_OVERRIDE;
|
||||
|
||||
SmsParent();
|
||||
virtual ~SmsParent();
|
||||
virtual ~SmsParent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(SmsParent);
|
||||
}
|
||||
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason why);
|
||||
|
@ -52,6 +55,16 @@ protected:
|
|||
|
||||
virtual bool
|
||||
DeallocPSmsRequest(PSmsRequestParent* aActor) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
RecvPMobileMessageCursorConstructor(PMobileMessageCursorParent* aActor,
|
||||
const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE;
|
||||
|
||||
virtual PMobileMessageCursorParent*
|
||||
AllocPMobileMessageCursor(const CreateMessageCursorRequest& aRequest) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
DeallocPMobileMessageCursor(PMobileMessageCursorParent* aActor) MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
class SmsRequestParent : public PSmsRequestParent
|
||||
|
@ -80,12 +93,6 @@ protected:
|
|||
bool
|
||||
DoRequest(const DeleteMessageRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const CreateMessageListRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const GetNextMessageInListRequest& aRequest);
|
||||
|
||||
bool
|
||||
DoRequest(const MarkMessageReadRequest& aRequest);
|
||||
|
||||
|
@ -93,6 +100,38 @@ protected:
|
|||
DoRequest(const GetThreadListRequest& aRequest);
|
||||
};
|
||||
|
||||
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) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
RecvContinue() MOZ_OVERRIDE;
|
||||
|
||||
bool
|
||||
DoRequest(const CreateMessageCursorRequest& aRequest);
|
||||
};
|
||||
|
||||
} // namespace mobilemessage
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -6,4 +6,5 @@ IPDLSRCS = \
|
|||
SmsTypes.ipdlh \
|
||||
PSms.ipdl \
|
||||
PSmsRequest.ipdl \
|
||||
PMobileMessageCursor.ipdl \
|
||||
$(NULL)
|
||||
|
|
Загрузка…
Ссылка в новой задаче