Bug 820780 - Part 2/5: DOM, IPC changes, r=bent

This commit is contained in:
Vicamo Yang 2013-01-04 14:26:20 +08:00
parent 3a388ebc91
commit fbe684362d
14 changed files with 187 additions and 18 deletions

View File

@ -459,6 +459,7 @@ using mozilla::dom::workers::ResolveWorkerClasses;
#include "nsIDOMSmsRequest.h"
#include "nsIDOMSmsFilter.h"
#include "nsIDOMSmsCursor.h"
#include "nsIDOMSmsSegmentInfo.h"
#include "nsIDOMConnection.h"
#ifdef MOZ_B2G_RIL
#include "nsIDOMMobileConnection.h"
@ -1373,6 +1374,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(MozSmsCursor, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozSmsSegmentInfo, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozConnection, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -3680,6 +3684,10 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsCursor)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozSmsSegmentInfo, nsIDOMMozSmsSegmentInfo)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsSegmentInfo)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozConnection, nsIDOMMozConnection)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozConnection)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)

View File

@ -344,6 +344,7 @@ DOMCI_CLASS(MozSmsEvent)
DOMCI_CLASS(MozSmsRequest)
DOMCI_CLASS(MozSmsFilter)
DOMCI_CLASS(MozSmsCursor)
DOMCI_CLASS(MozSmsSegmentInfo)
DOMCI_CLASS(MozConnection)
#ifdef MOZ_B2G_RIL

View File

@ -21,6 +21,7 @@ XPIDLSRCS = \
nsIDOMSmsRequest.idl \
nsIDOMSmsFilter.idl \
nsIDOMSmsCursor.idl \
nsIDOMSmsSegmentInfo.idl \
nsISmsDatabaseService.idl \
nsISmsRequest.idl \
nsISmsService.idl \

View File

@ -5,6 +5,7 @@
#include "nsISupports.idl"
interface nsIDOMMozSmsMessage;
interface nsIDOMMozSmsSegmentInfo;
interface nsISmsRequest;
%{C++
@ -12,11 +13,13 @@ interface nsISmsRequest;
#define SMS_SERVICE_CONTRACTID "@mozilla.org/sms/smsservice;1"
%}
[scriptable, builtinclass, uuid(d4772337-3754-49ba-81cc-e141fff30377)]
[scriptable, builtinclass, uuid(4310bdb5-eefa-4f70-965a-74041228ab26)]
interface nsISmsService : nsISupports
{
boolean hasSupport();
unsigned short getNumberOfMessagesForText(in DOMString text);
nsIDOMMozSmsSegmentInfo getSegmentInfoForText(in DOMString text);
void send(in DOMString number,
in DOMString message,
in nsISmsRequest request);
@ -31,4 +34,8 @@ interface nsISmsService : nsISupports
in DOMString messageClass,
in jsval timestamp,
in bool read);
nsIDOMMozSmsSegmentInfo createSmsSegmentInfo(in long segments,
in long charsPerSegment,
in long charsAvailableInLastSegment);
};

View File

@ -39,6 +39,7 @@ EXPORTS_mozilla/dom/sms = \
Types.h \
SmsMessage.h \
SmsRequest.h \
SmsSegmentInfo.h \
$(NULL)
CPPSRCS = \
@ -53,6 +54,7 @@ CPPSRCS = \
SmsChild.cpp \
SmsRequest.cpp \
SmsFilter.cpp \
SmsSegmentInfo.cpp \
SmsCursor.cpp \
$(NULL)

View File

@ -130,14 +130,13 @@ SmsManager::Shutdown()
}
NS_IMETHODIMP
SmsManager::GetNumberOfMessagesForText(const nsAString& aText, uint16_t* aResult)
SmsManager::GetSegmentInfoForText(const nsAString& aText,
nsIDOMMozSmsSegmentInfo** aResult)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, NS_OK);
NS_ENSURE_TRUE(smsService, NS_ERROR_FAILURE);
smsService->GetNumberOfMessagesForText(aText, aResult);
return NS_OK;
return smsService->GetSegmentInfoForText(aText, aResult);
}
nsresult

View File

@ -0,0 +1,59 @@
/* -*- 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 "SmsSegmentInfo.h"
#include "nsIDOMClassInfo.h"
DOMCI_DATA(MozSmsSegmentInfo, mozilla::dom::sms::SmsSegmentInfo)
namespace mozilla {
namespace dom {
namespace sms {
NS_INTERFACE_MAP_BEGIN(SmsSegmentInfo)
NS_INTERFACE_MAP_ENTRY(nsIDOMMozSmsSegmentInfo)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozSmsSegmentInfo)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(SmsSegmentInfo)
NS_IMPL_RELEASE(SmsSegmentInfo)
SmsSegmentInfo::SmsSegmentInfo(int32_t aSegments,
int32_t aCharsPerSegment,
int32_t aCharsAvailableInLastSegment)
: mData(aSegments, aCharsPerSegment, aCharsAvailableInLastSegment)
{
}
SmsSegmentInfo::SmsSegmentInfo(const SmsSegmentInfoData& aData)
: mData(aData)
{
}
NS_IMETHODIMP
SmsSegmentInfo::GetSegments(int32_t* aSegments)
{
*aSegments = mData.segments();
return NS_OK;
}
NS_IMETHODIMP
SmsSegmentInfo::GetCharsPerSegment(int32_t* aCharsPerSegment)
{
*aCharsPerSegment = mData.charsPerSegment();
return NS_OK;
}
NS_IMETHODIMP
SmsSegmentInfo::GetCharsAvailableInLastSegment(int32_t* aCharsAvailableInLastSegment)
{
*aCharsAvailableInLastSegment = mData.charsAvailableInLastSegment();
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,36 @@
/* -*- 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_sms_SmsSegmentInfo_h
#define mozilla_dom_sms_SmsSegmentInfo_h
#include "nsIDOMSmsSegmentInfo.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/sms/SmsTypes.h"
namespace mozilla {
namespace dom {
namespace sms {
class SmsSegmentInfo MOZ_FINAL : public nsIDOMMozSmsSegmentInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMMOZSMSSEGMENTINFO
SmsSegmentInfo(int32_t aSegments,
int32_t aCharsPerSegment,
int32_t aCharsAvailableInLastSegment);
SmsSegmentInfo(const SmsSegmentInfoData& aData);
private:
SmsSegmentInfoData mData;
};
} // namespace sms
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_sms_SmsSegmentInfo_h

View File

@ -4,6 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/sms/SmsMessage.h"
#include "SmsSegmentInfo.h"
#include "SmsService.h"
#include "jsapi.h"
@ -21,11 +22,11 @@ SmsService::HasSupport(bool* aHasSupport)
}
NS_IMETHODIMP
SmsService::GetNumberOfMessagesForText(const nsAString& aText, uint16_t* aResult)
SmsService::GetSegmentInfoForText(const nsAString & aText,
nsIDOMMozSmsSegmentInfo** aResult)
{
NS_ERROR("We should not be here!");
*aResult = 0;
return NS_OK;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -56,6 +57,18 @@ SmsService::CreateSmsMessage(int32_t aId,
aCx, aMessage);
}
NS_IMETHODIMP
SmsService::CreateSmsSegmentInfo(int32_t aSegments,
int32_t aCharsPerSegment,
int32_t aCharsAvailableInLastSegment,
nsIDOMMozSmsSegmentInfo** aSegmentInfo)
{
nsCOMPtr<nsIDOMMozSmsSegmentInfo> info =
new SmsSegmentInfo(aSegments, aCharsPerSegment, aCharsAvailableInLastSegment);
info.forget(aSegmentInfo);
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@ -99,8 +99,8 @@ parent:
sync HasSupport()
returns (bool aHasSupport);
sync GetNumberOfMessagesForText(nsString aText)
returns (uint16_t aNumber);
sync GetSegmentInfoForText(nsString aText)
returns (SmsSegmentInfoData aResult);
ClearMessageList(int32_t aListId);
};

View File

@ -11,6 +11,7 @@
#include "mozilla/dom/sms/SmsMessage.h"
#include "SmsFilter.h"
#include "SmsRequest.h"
#include "SmsSegmentInfo.h"
namespace mozilla {
namespace dom {
@ -57,10 +58,15 @@ SmsIPCService::HasSupport(bool* aHasSupport)
}
NS_IMETHODIMP
SmsIPCService::GetNumberOfMessagesForText(const nsAString& aText, uint16_t* aResult)
SmsIPCService::GetSegmentInfoForText(const nsAString & aText,
nsIDOMMozSmsSegmentInfo** aResult)
{
GetSmsChild()->SendGetNumberOfMessagesForText(nsString(aText), aResult);
SmsSegmentInfoData data;
bool ok = GetSmsChild()->SendGetSegmentInfoForText(nsString(aText), &data);
NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMMozSmsSegmentInfo> info = new SmsSegmentInfo(data);
info.forget(aResult);
return NS_OK;
}
@ -92,6 +98,18 @@ SmsIPCService::CreateSmsMessage(int32_t aId,
aCx, aMessage);
}
NS_IMETHODIMP
SmsIPCService::CreateSmsSegmentInfo(int32_t aSegments,
int32_t aCharsPerSegment,
int32_t aCharsAvailableInLastSegment,
nsIDOMMozSmsSegmentInfo** aSegmentInfo)
{
nsCOMPtr<nsIDOMMozSmsSegmentInfo> info =
new SmsSegmentInfo(aSegments, aCharsPerSegment, aCharsAvailableInLastSegment);
info.forget(aSegmentInfo);
return NS_OK;
}
/*
* Implementation of nsISmsDatabaseService.
*/

View File

@ -14,6 +14,7 @@
#include "nsISmsDatabaseService.h"
#include "SmsFilter.h"
#include "SmsRequest.h"
#include "SmsSegmentInfo.h"
namespace mozilla {
namespace dom {
@ -144,14 +145,31 @@ SmsParent::RecvHasSupport(bool* aHasSupport)
}
bool
SmsParent::RecvGetNumberOfMessagesForText(const nsString& aText, uint16_t* aResult)
SmsParent::RecvGetSegmentInfoForText(const nsString& aText,
SmsSegmentInfoData* aResult)
{
*aResult = 0;
aResult->segments() = 0;
aResult->charsPerSegment() = 0;
aResult->charsAvailableInLastSegment() = 0;
nsCOMPtr<nsISmsService> smsService = do_GetService(SMS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, true);
smsService->GetNumberOfMessagesForText(aText, aResult);
nsCOMPtr<nsIDOMMozSmsSegmentInfo> info;
nsresult rv = smsService->GetSegmentInfoForText(aText, getter_AddRefs(info));
NS_ENSURE_SUCCESS(rv, true);
int segments, charsPerSegment, charsAvailableInLastSegment;
if (NS_FAILED(info->GetSegments(&segments)) ||
NS_FAILED(info->GetCharsPerSegment(&charsPerSegment)) ||
NS_FAILED(info->GetCharsAvailableInLastSegment(&charsAvailableInLastSegment))) {
NS_ERROR("Can't get attribute values from nsIDOMMozSmsSegmentInfo");
return true;
}
aResult->segments() = segments;
aResult->charsPerSegment() = charsPerSegment;
aResult->charsAvailableInLastSegment() = charsAvailableInLastSegment;
return true;
}

View File

@ -38,7 +38,7 @@ protected:
RecvHasSupport(bool* aHasSupport) MOZ_OVERRIDE;
virtual bool
RecvGetNumberOfMessagesForText(const nsString& aText, uint16_t* aResult) MOZ_OVERRIDE;
RecvGetSegmentInfoForText(const nsString& aText, SmsSegmentInfoData* aResult) MOZ_OVERRIDE;
virtual bool
RecvClearMessageList(const int32_t& aListId) MOZ_OVERRIDE;

View File

@ -15,6 +15,13 @@ namespace mozilla {
namespace dom {
namespace sms {
struct SmsSegmentInfoData
{
int32_t segments;
int32_t charsPerSegment;
int32_t charsAvailableInLastSegment;
};
struct SmsMessageData
{
int32_t id;