Bug 674725 - Part I - Implement mozSms.getNumberOfMessagesForText(). r=smaug,cjones

This commit is contained in:
Mounir Lamouri 2011-11-25 10:48:51 +01:00
Родитель e873629ace
Коммит 25739c722c
14 изменённых файлов: 131 добавлений и 1 удалений

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

@ -36,7 +36,8 @@
#include "nsISupports.idl"
[scriptable, function, uuid(562eade6-6dee-4c0a-bee9-bfc7f2bcadbe)]
[scriptable, function, uuid(acff4eca-ae08-4c4a-bc6d-34a960134314)]
interface nsIDOMMozSmsManager : nsISupports
{
unsigned short getNumberOfMessagesForText(in DOMString text);
};

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

@ -45,4 +45,5 @@
interface nsISmsService : nsISupports
{
boolean hasSupport();
unsigned short getNumberOfMessagesForText(in DOMString text);
};

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

@ -37,6 +37,7 @@
#include "SmsManager.h"
#include "nsIDOMClassInfo.h"
#include "nsISmsService.h"
DOMCI_DATA(MozSmsManager, mozilla::dom::sms::SmsManager)
@ -53,6 +54,17 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(SmsManager)
NS_IMPL_RELEASE(SmsManager)
NS_IMETHODIMP
SmsManager::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult)
{
nsCOMPtr<nsISmsService> smsService = do_GetService(SMSSERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, NS_OK);
smsService->GetNumberOfMessagesForText(aText, aResult);
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -36,6 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#include "SmsService.h"
#include "AndroidBridge.h"
namespace mozilla {
namespace dom {
@ -50,6 +51,18 @@ SmsService::HasSupport(bool* aHasSupport)
return NS_OK;
}
NS_IMETHODIMP
SmsService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult)
{
if (!AndroidBridge::Bridge()) {
*aResult = 0;
return NS_OK;
}
*aResult = AndroidBridge::Bridge()->GetNumberOfMessagesForText(aText);
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -50,6 +50,14 @@ SmsService::HasSupport(bool* aHasSupport)
return NS_OK;
}
NS_IMETHODIMP
SmsService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult)
{
NS_ERROR("We should not be here!");
*aResult = 0;
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -50,6 +50,9 @@ parent:
sync HasSupport()
returns (bool aHasSupport);
sync GetNumberOfMessagesForText(nsString aText)
returns (PRUint16 aNumber);
__delete__();
};

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

@ -66,6 +66,14 @@ SmsIPCService::HasSupport(bool* aHasSupport)
return NS_OK;
}
NS_IMETHODIMP
SmsIPCService::GetNumberOfMessagesForText(const nsAString& aText, PRUint16* aResult)
{
GetSmsChild()->SendGetNumberOfMessagesForText(nsString(aText), aResult);
return NS_OK;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -54,6 +54,18 @@ SmsParent::RecvHasSupport(bool* aHasSupport)
return true;
}
bool
SmsParent::RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResult)
{
*aResult = 0;
nsCOMPtr<nsISmsService> smsService = do_GetService(SMSSERVICE_CONTRACTID);
NS_ENSURE_TRUE(smsService, true);
smsService->GetNumberOfMessagesForText(aText, aResult);
return true;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

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

@ -47,6 +47,7 @@ namespace sms {
class SmsParent : public PSmsParent
{
NS_OVERRIDE virtual bool RecvHasSupport(bool* aHasSupport);
NS_OVERRIDE virtual bool RecvGetNumberOfMessagesForText(const nsString& aText, PRUint16* aResult);
};
} // namespace sms

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

@ -1648,4 +1648,8 @@ public class GeckoAppShell
public static double[] getCurrentBatteryInformation() {
return GeckoBatteryManager.getCurrentInformation();
}
public static int getNumberOfMessagesForText(String aText) {
return GeckoSmsManager.getNumberOfMessagesForText(aText);
}
}

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

@ -0,0 +1,51 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* ***** 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 Mozilla Android code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* 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 ***** */
package org.mozilla.gecko;
import java.util.ArrayList;
import android.util.Log;
import android.telephony.SmsManager;
public class GeckoSmsManager
{
public static int getNumberOfMessagesForText(String aText) {
return SmsManager.getDefault().divideMessage(aText).size();
}
}

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

@ -55,6 +55,7 @@ JAVAFILES = \
AlertNotification.java \
SurfaceInfo.java \
GeckoBatteryManager.java \
GeckoSmsManager.java \
$(NULL)
PROCESSEDJAVAFILES = \

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

@ -169,6 +169,8 @@ AndroidBridge::Init(JNIEnv *jEnv,
jCheckUriVisited = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "checkUriVisited", "(Ljava/lang/String;)V");
jMarkUriVisited = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "markUriVisited", "(Ljava/lang/String;)V");
jNumberOfMessages = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getNumberOfMessagesForText", "(Ljava/lang/String;)I");
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
jEGLSurfaceImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLSurfaceImpl"));
@ -1357,6 +1359,16 @@ void AndroidBridge::EmitGeckoAccessibilityEvent (PRInt32 eventType, const nsAStr
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEmitGeckoAccessibilityEvent, eventType, jstrRole, jstrText, jstrDescription, enabled, checked, password);
}
PRUint16
AndroidBridge::GetNumberOfMessagesForText(const nsAString& aText)
{
ALOG_BRIDGE("AndroidBridge::GetNumberOfMessagesForText");
AutoLocalJNIFrame jniFrame;
jstring jText = GetJNIForThread()->NewString(PromiseFlatString(aText).get(), aText.Length());
return GetJNIForThread()->CallStaticIntMethod(mGeckoAppShellClass, jNumberOfMessages, jText);
}
void *
AndroidBridge::LockBitmap(jobject bitmap)
{

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

@ -318,6 +318,8 @@ public:
void DisableBatteryNotifications();
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
PRUint16 GetNumberOfMessagesForText(const nsAString& aText);
protected:
static AndroidBridge *sBridge;
@ -401,6 +403,7 @@ protected:
jmethodID jCheckUriVisited;
jmethodID jMarkUriVisited;
jmethodID jEmitGeckoAccessibilityEvent;
jmethodID jNumberOfMessages;
// stuff we need for CallEglCreateWindowSurface
jclass jEGLSurfaceImplClass;