From 9a5b88b84e7533e6552ac00c5636b839461efbdb Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Tue, 17 Jan 2012 19:42:39 +0100 Subject: [PATCH] Bug 674725 - Part AP - Implementation of cursor.continue() in the DOM code. r=smaug --- dom/sms/interfaces/nsISmsDatabaseService.idl | 3 ++- dom/sms/src/SmsCursor.cpp | 24 +++++++++++++++----- dom/sms/src/SmsCursor.h | 3 ++- dom/sms/src/SmsRequest.cpp | 15 ++++++++++++ dom/sms/src/SmsRequest.h | 2 ++ dom/sms/src/SmsRequestManager.cpp | 22 +++++++++++++++++- dom/sms/src/SmsRequestManager.h | 2 ++ dom/sms/src/android/SmsDatabaseService.cpp | 8 +++++++ dom/sms/src/fallback/SmsDatabaseService.cpp | 8 +++++++ dom/sms/src/ipc/PSms.ipdl | 2 ++ dom/sms/src/ipc/SmsIPCService.cpp | 9 ++++++++ dom/sms/src/ipc/SmsParent.cpp | 14 ++++++++++++ dom/sms/src/ipc/SmsParent.h | 1 + 13 files changed, 104 insertions(+), 9 deletions(-) diff --git a/dom/sms/interfaces/nsISmsDatabaseService.idl b/dom/sms/interfaces/nsISmsDatabaseService.idl index db306bae56a..89270eb5d2d 100644 --- a/dom/sms/interfaces/nsISmsDatabaseService.idl +++ b/dom/sms/interfaces/nsISmsDatabaseService.idl @@ -45,7 +45,7 @@ interface nsIDOMMozSmsFilter; -[scriptable, function, uuid(33358749-d1b3-4bd6-835c-ef3869f0e966)] +[scriptable, function, uuid(a253ec42-142e-490b-a479-1e9c605c0a58)] interface nsISmsDatabaseService : nsISupports { // Takes some information required to save the message and returns its id. @@ -55,4 +55,5 @@ interface nsISmsDatabaseService : nsISupports void deleteMessage(in long messageId, in long requestId, [optional] in unsigned long long processId); void createMessageList(in nsIDOMMozSmsFilter filter, in boolean reverse, in long requestId, [optional] in unsigned long long processId); + void getNextMessageInList(in long listId, in long requestId, in unsigned long long processId); }; diff --git a/dom/sms/src/SmsCursor.cpp b/dom/sms/src/SmsCursor.cpp index 11f2221a7bc..21d4e60447b 100644 --- a/dom/sms/src/SmsCursor.cpp +++ b/dom/sms/src/SmsCursor.cpp @@ -41,6 +41,9 @@ #include "nsIDOMSmsFilter.h" #include "nsIDOMSmsMessage.h" #include "nsIDOMSmsRequest.h" +#include "SmsRequest.h" +#include "SmsRequestManager.h" +#include "nsISmsDatabaseService.h" DOMCI_DATA(MozSmsCursor, mozilla::dom::sms::SmsCursor) @@ -60,12 +63,14 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(SmsCursor) NS_IMPL_CYCLE_COLLECTING_RELEASE(SmsCursor) SmsCursor::SmsCursor(nsIDOMMozSmsFilter* aFilter) - : mFilter(aFilter) + : mListId(-1) + , mFilter(aFilter) { } -SmsCursor::SmsCursor(nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest) - : mFilter(aFilter) +SmsCursor::SmsCursor(PRInt32 aListId, nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest) + : mListId(aListId) + , mFilter(aFilter) , mRequest(aRequest) { } @@ -92,9 +97,16 @@ SmsCursor::Continue() return NS_ERROR_DOM_INVALID_STATE_ERR; } - // TODO: ask for the next message and reset the request - // TODO: add the associated request to the request manager - // and send the id to the backend + mMessage = nsnull; + static_cast(mRequest.get())->Reset(); + + PRInt32 requestId = SmsRequestManager::GetInstance()->AddRequest(mRequest); + + nsCOMPtr smsDBService = + do_GetService(SMS_DATABASE_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(smsDBService, NS_ERROR_FAILURE); + + smsDBService->GetNextMessageInList(mListId, requestId, 0); return NS_OK; } diff --git a/dom/sms/src/SmsCursor.h b/dom/sms/src/SmsCursor.h index ee79c860feb..8f1bd52ed5d 100644 --- a/dom/sms/src/SmsCursor.h +++ b/dom/sms/src/SmsCursor.h @@ -59,11 +59,12 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS(SmsCursor) SmsCursor(nsIDOMMozSmsFilter* aFilter); - SmsCursor(nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest); + SmsCursor(PRInt32 aListId, nsIDOMMozSmsFilter* aFilter, nsIDOMMozSmsRequest* aRequest); void SetMessage(nsIDOMMozSmsMessage* aMessage); private: + PRInt32 mListId; nsCOMPtr mFilter; nsCOMPtr mRequest; nsCOMPtr mMessage; diff --git a/dom/sms/src/SmsRequest.cpp b/dom/sms/src/SmsRequest.cpp index 88100a31311..9529fb45ba8 100644 --- a/dom/sms/src/SmsRequest.cpp +++ b/dom/sms/src/SmsRequest.cpp @@ -105,6 +105,21 @@ SmsRequest::~SmsRequest() } } +void +SmsRequest::Reset() +{ + NS_ASSERTION(mDone, "mDone should be true if we try to reset!"); + NS_ASSERTION(mResult != JSVAL_VOID, "mResult should be set if we try to reset!"); + NS_ASSERTION(mError == eNoError, "There should be no error if we try to reset!"); + + if (mResultRooted) { + UnrootResult(); + } + + mResult = JSVAL_VOID; + mDone = false; +} + void SmsRequest::RootResult() { diff --git a/dom/sms/src/SmsRequest.h b/dom/sms/src/SmsRequest.h index e8813fe4abc..ca43a7fd8bd 100644 --- a/dom/sms/src/SmsRequest.h +++ b/dom/sms/src/SmsRequest.h @@ -75,6 +75,8 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(SmsRequest, nsDOMEventTargetWrapperCache) + void Reset(); + private: SmsRequest() MOZ_DELETE; diff --git a/dom/sms/src/SmsRequestManager.cpp b/dom/sms/src/SmsRequestManager.cpp index 2cb3aa296e3..e4921923a66 100644 --- a/dom/sms/src/SmsRequestManager.cpp +++ b/dom/sms/src/SmsRequestManager.cpp @@ -76,6 +76,26 @@ SmsRequestManager::GetInstance() return sInstance; } +PRInt32 +SmsRequestManager::AddRequest(nsIDOMMozSmsRequest* aRequest) +{ + // TODO: merge with CreateRequest + PRInt32 size = mRequests.Count(); + + // Look for empty slots. + for (PRInt32 i=0; i cursor = new SmsCursor(nsnull, request); + nsCOMPtr cursor = new SmsCursor(aListId, nsnull, request); cursor->SetMessage(aMessage); NotifySuccess(aRequestId, cursor); diff --git a/dom/sms/src/SmsRequestManager.h b/dom/sms/src/SmsRequestManager.h index 50c3572e62d..c57310b9ead 100644 --- a/dom/sms/src/SmsRequestManager.h +++ b/dom/sms/src/SmsRequestManager.h @@ -62,6 +62,8 @@ public: nsIScriptContext* aScriptContext, nsIDOMMozSmsRequest** aRequest); + PRInt32 AddRequest(nsIDOMMozSmsRequest* aRequest); + void NotifySmsSent(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage); void NotifySmsSendFailed(PRInt32 aRequestId, SmsRequest::ErrorType aError); void NotifyGotSms(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage); diff --git a/dom/sms/src/android/SmsDatabaseService.cpp b/dom/sms/src/android/SmsDatabaseService.cpp index f5d4ddff9f1..ac4caf09694 100644 --- a/dom/sms/src/android/SmsDatabaseService.cpp +++ b/dom/sms/src/android/SmsDatabaseService.cpp @@ -99,6 +99,14 @@ SmsDatabaseService::CreateMessageList(nsIDOMMozSmsFilter* aFilter, return NS_OK; } +NS_IMETHODIMP +SmsDatabaseService::GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, + PRUint64 aProcessId) +{ + // TODO: implement + return NS_OK; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/fallback/SmsDatabaseService.cpp b/dom/sms/src/fallback/SmsDatabaseService.cpp index 0f246deb5de..7eeec00e9a1 100644 --- a/dom/sms/src/fallback/SmsDatabaseService.cpp +++ b/dom/sms/src/fallback/SmsDatabaseService.cpp @@ -78,6 +78,14 @@ SmsDatabaseService::CreateMessageList(nsIDOMMozSmsFilter* aFilter, return NS_OK; } +NS_IMETHODIMP +SmsDatabaseService::GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, + PRUint64 aProcessId) +{ + NS_ERROR("We should not be here!"); + return NS_OK; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/ipc/PSms.ipdl b/dom/sms/src/ipc/PSms.ipdl index 5f3f8fb8370..2d0d678bfbc 100644 --- a/dom/sms/src/ipc/PSms.ipdl +++ b/dom/sms/src/ipc/PSms.ipdl @@ -113,6 +113,8 @@ parent: CreateMessageList(SmsFilterData aFilter, bool aReverse, PRInt32 aRequestId, PRUint64 aProcessId); + GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, PRUint64 aProcessId); + __delete__(); }; diff --git a/dom/sms/src/ipc/SmsIPCService.cpp b/dom/sms/src/ipc/SmsIPCService.cpp index 1faebc80bc9..78bf0ac18b6 100644 --- a/dom/sms/src/ipc/SmsIPCService.cpp +++ b/dom/sms/src/ipc/SmsIPCService.cpp @@ -147,6 +147,15 @@ SmsIPCService::CreateMessageList(nsIDOMMozSmsFilter* aFilter, bool aReverse, return NS_OK; } +NS_IMETHODIMP +SmsIPCService::GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, + PRUint64 aProcessId) +{ + GetSmsChild()->SendGetNextMessageInList(aListId, aRequestId, + ContentChild::GetSingleton()->GetID()); + return NS_OK; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/ipc/SmsParent.cpp b/dom/sms/src/ipc/SmsParent.cpp index 1d6de2eb15a..6d05190dc9c 100644 --- a/dom/sms/src/ipc/SmsParent.cpp +++ b/dom/sms/src/ipc/SmsParent.cpp @@ -233,6 +233,20 @@ SmsParent::RecvCreateMessageList(const SmsFilterData& aFilter, return true; } +bool +SmsParent::RecvGetNextMessageInList(const PRInt32& aListId, + const PRInt32& aRequestId, + const PRUint64& aProcessId) +{ + nsCOMPtr smsDBService = + do_GetService(SMS_DATABASE_SERVICE_CONTRACTID); + NS_ENSURE_TRUE(smsDBService, true); + + smsDBService->GetNextMessageInList(aListId, aRequestId, aProcessId); + + return true; +} + } // namespace sms } // namespace dom } // namespace mozilla diff --git a/dom/sms/src/ipc/SmsParent.h b/dom/sms/src/ipc/SmsParent.h index ae0ab92436a..14e9f037038 100644 --- a/dom/sms/src/ipc/SmsParent.h +++ b/dom/sms/src/ipc/SmsParent.h @@ -63,6 +63,7 @@ public: NS_OVERRIDE virtual bool RecvGetMessage(const PRInt32& aMessageId, const PRInt32& aRequestId, const PRUint64& aProcessId); NS_OVERRIDE virtual bool RecvDeleteMessage(const PRInt32& aMessageId, const PRInt32& aRequestId, const PRUint64& aProcessId); NS_OVERRIDE virtual bool RecvCreateMessageList(const SmsFilterData& aFilter, const bool& aReverse, const PRInt32& aRequestId, const PRUint64& aProcessId); + NS_OVERRIDE virtual bool RecvGetNextMessageInList(const PRInt32& aListId, const PRInt32& aRequestId, const PRUint64& aProcessId); protected: virtual void ActorDestroy(ActorDestroyReason why);