Bug 820780 - Part 2/5: DOM, IPC changes. r=bent, a=blocking-basecamp

This commit is contained in:
Vicamo Yang 2013-01-04 14:26:20 +08:00
Родитель bd87be95e4
Коммит 369789ec57
14 изменённых файлов: 187 добавлений и 18 удалений

Просмотреть файл

@ -501,6 +501,7 @@ using mozilla::dom::indexedDB::IDBWrapperCache;
#include "nsIDOMSmsRequest.h"
#include "nsIDOMSmsFilter.h"
#include "nsIDOMSmsCursor.h"
#include "nsIDOMSmsSegmentInfo.h"
#include "nsIDOMConnection.h"
#ifdef MOZ_B2G_RIL
#include "nsIDOMMobileConnection.h"
@ -1531,6 +1532,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)
@ -4171,6 +4175,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)

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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);
};

Просмотреть файл

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

Просмотреть файл

@ -138,14 +138,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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
};

Просмотреть файл

@ -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.
*/

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;