Bug 709568 - Part 1: nsISmsService for gonk and RIL <-> DOM glue for outgoing SMS. r=smaug

This commit is contained in:
Philipp von Weitershausen 2011-12-24 06:02:52 +01:00
parent 0d3ae88292
commit cc4e633aef
5 changed files with 203 additions and 6 deletions

View File

@ -46,6 +46,8 @@ include $(DEPTH)/config/autoconf.mk
ifeq (android,$(MOZ_WIDGET_TOOLKIT))
VPATH += $(srcdir)/android
else ifdef MOZ_B2G_RIL
VPATH += $(srcdir)/ril
else
VPATH += $(srcdir)/fallback
endif
@ -87,6 +89,13 @@ LOCAL_INCLUDES = \
# subdirectory (and the ipc one).
LOCAL_INCLUDES += $(VPATH:%=-I%)
ifdef MOZ_B2G_RIL
LOCAL_INCLUDES += \
-I$(topsrcdir)/dom/telephony \
-I$(topsrcdir)/dom/system/b2g \
$(NULL)
endif
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/ipc/chromium/chromium-config.mk
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,102 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is SMS DOM API.
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Philipp von Weitershausen <philipp@weitershausen.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/dom/sms/SmsMessage.h"
#include "SmsService.h"
#include "RadioManager.h"
#include "jsapi.h"
using mozilla::dom::telephony::RadioManager;
namespace mozilla {
namespace dom {
namespace sms {
NS_IMPL_ISUPPORTS1(SmsService, nsISmsService)
SmsService::SmsService()
: mRIL(RadioManager::GetTelephone())
{
}
NS_IMETHODIMP
SmsService::HasSupport(bool* aHasSupport)
{
*aHasSupport = true;
return NS_OK;
}
NS_IMETHODIMP
SmsService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult)
{
if (!mRIL) {
*aResult = 0;
return NS_OK;
}
mRIL->GetNumberOfMessagesForText(aText, aResult);
return NS_OK;
}
NS_IMETHODIMP
SmsService::Send(const nsAString& aNumber, const nsAString& aMessage)
{
if (!mRIL) {
return NS_OK;
}
mRIL->SendSMS(aNumber, aMessage);
return NS_OK;
}
NS_IMETHODIMP
SmsService::CreateSmsMessage(PRInt32 aId,
const nsAString& aDelivery,
const nsAString& aSender,
const nsAString& aReceiver,
const nsAString& aBody,
const jsval& aTimestamp,
JSContext* aCx,
nsIDOMMozSmsMessage** aMessage)
{
return SmsMessage::Create(
aId, aDelivery, aSender, aReceiver, aBody, aTimestamp, aCx, aMessage);
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,64 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is SMS DOM API.
*
* The Initial Developer of the Original Code is
* the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Philipp von Weitershausen <philipp@weitershausen.de>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_dom_sms_SmsService_h
#define mozilla_dom_sms_SmsService_h
#include "nsISmsService.h"
#include "nsCOMPtr.h"
#include "nsITelephone.h"
namespace mozilla {
namespace dom {
namespace sms {
class SmsService : public nsISmsService
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISMSSERVICE
SmsService();
protected:
nsCOMPtr<nsITelephone> mRIL;
};
} // namespace sms
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_sms_SmsService_h

View File

@ -38,7 +38,8 @@
#include "nsISupports.idl"
[scriptable, uuid(9b7e3a01-9c45-4af3-81bb-1bf08a842226)]
interface nsITelephoneCallback : nsISupports {
interface nsITelephoneCallback : nsISupports
{
void oncallstatechange(in jsval event);
//XXX philikon's additions
@ -48,11 +49,16 @@ interface nsITelephoneCallback : nsISupports {
void onsignalstrengthchange(in jsval event);
};
[scriptable, uuid(f6baa721-665e-403e-8a98-acaa0d8bf267)]
interface nsITelephone : nsISupports {
[scriptable, uuid(5be6e41d-3aee-4f5c-8284-95cf529dd6fe)]
interface nsITelephone : nsISupports
{
readonly attribute jsval currentState;
void registerCallback(in nsITelephoneCallback callback);
void unregisterCallback(in nsITelephoneCallback callback);
/**
* Functionality for making and managing phone calls.
*/
void dial(in DOMString number);
void hangUp(in long callIndex);
void startTone(in DOMString dtmfChar);
@ -62,6 +68,9 @@ interface nsITelephone : nsISupports {
attribute bool microphoneMuted;
attribute bool speakerEnabled;
void registerCallback(in nsITelephoneCallback callback);
void unregisterCallback(in nsITelephoneCallback callback);
/**
* SMS-related functionality.
*/
unsigned short getNumberOfMessagesForText(in DOMString text);
void sendSMS(in DOMString number, in DOMString message);
};

View File

@ -279,6 +279,19 @@ nsTelephonyWorker.prototype = {
gAudioManager.setForceUse(Ci.nsIAudioManager.USE_COMMUNICATION, force);
},
getNumberOfMessagesForText: function getNumberOfMessagesForText(text) {
//TODO: this assumes 7bit encoding, which is incorrect. Need to look
// for characters not supported by 7bit alphabets and then calculate
// length in UCS2 encoding.
return Math.ceil(text.length / 160);
},
sendSMS: function sendSMS(number, message) {
this.worker.postMessage({type: "sendSMS",
number: number,
body: message});
},
_callbacks: null,
registerCallback: function registerCallback(callback) {