2010-06-03 20:56:36 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2011-11-02 15:35:11 +00:00
|
|
|
#include "mozilla/Hal.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2010-06-15 02:17:37 +00:00
|
|
|
#include "nsString.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2011-12-21 19:05:23 +00:00
|
|
|
#include "AndroidGraphicBuffer.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <dlfcn.h>
|
2011-11-15 03:12:14 +00:00
|
|
|
#include <stdio.h>
|
2012-04-27 20:04:47 +00:00
|
|
|
#include <unistd.h>
|
2013-06-14 16:42:10 +00:00
|
|
|
#include <sched.h>
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include "nsWindow.h"
|
|
|
|
#include <android/log.h>
|
2010-08-31 17:37:54 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
2013-09-24 20:45:13 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2011-01-20 06:14:12 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsICrashReporter.h"
|
2011-06-01 17:54:53 +00:00
|
|
|
#include "nsExceptionHandler.h"
|
2011-01-20 06:14:12 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-13 13:26:50 +00:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
|
2013-03-01 08:38:47 +00:00
|
|
|
#include "mozilla/dom/SmsMessage.h"
|
|
|
|
#include "mozilla/dom/mobilemessage/Constants.h"
|
|
|
|
#include "mozilla/dom/mobilemessage/Types.h"
|
|
|
|
#include "mozilla/dom/mobilemessage/PSms.h"
|
|
|
|
#include "mozilla/dom/mobilemessage/SmsParent.h"
|
2013-07-30 18:03:40 +00:00
|
|
|
#include "mozilla/layers/APZCTreeManager.h"
|
2013-02-05 11:39:44 +00:00
|
|
|
#include "nsIMobileMessageDatabaseService.h"
|
2012-05-30 16:10:49 +00:00
|
|
|
#include "nsPluginInstanceOwner.h"
|
2012-07-20 19:20:51 +00:00
|
|
|
#include "nsSurfaceTexture.h"
|
2013-04-23 17:10:29 +00:00
|
|
|
#include "GeckoProfiler.h"
|
2011-01-20 06:14:12 +00:00
|
|
|
|
2013-06-14 16:42:10 +00:00
|
|
|
#include "GeckoProfiler.h"
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
using namespace mozilla;
|
2013-03-01 08:38:47 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::dom::mobilemessage;
|
2013-04-26 17:24:28 +00:00
|
|
|
using namespace mozilla::layers;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
/* Forward declare all the JNI methods as extern "C" */
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
/*
|
|
|
|
* Incoming JNI methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_nativeInit(JNIEnv *jenv, jclass jc)
|
|
|
|
{
|
2013-09-09 12:57:36 +00:00
|
|
|
AndroidBridge::ConstructBridge(jenv);
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_notifyGeckoOfEvent(JNIEnv *jenv, jclass jc, jobject event)
|
|
|
|
{
|
|
|
|
// poke the appshell
|
|
|
|
if (nsAppShell::gAppShell)
|
2013-04-17 21:39:12 +00:00
|
|
|
nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeFromJavaObject(jenv, event));
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 02:30:22 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-05-10 01:48:00 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_processNextNativeEvent(JNIEnv *jenv, jclass, jboolean mayWait)
|
2011-08-19 02:30:22 +00:00
|
|
|
{
|
|
|
|
// poke the appshell
|
|
|
|
if (nsAppShell::gAppShell)
|
2013-05-10 01:48:00 +00:00
|
|
|
nsAppShell::gAppShell->ProcessNextNativeEvent(mayWait != JNI_FALSE);
|
2011-08-19 02:30:22 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 03:12:14 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2012-02-17 14:16:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_setLayerClient(JNIEnv *jenv, jclass, jobject obj)
|
2011-11-15 03:12:14 +00:00
|
|
|
{
|
2012-07-13 14:19:46 +00:00
|
|
|
AndroidBridge::Bridge()->SetLayerClient(jenv, obj);
|
2011-11-15 03:12:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-02 06:34:12 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *jenv, jclass jc)
|
|
|
|
{
|
|
|
|
if (nsAppShell::gAppShell)
|
|
|
|
nsAppShell::gAppShell->OnResume();
|
|
|
|
}
|
|
|
|
|
2011-06-01 17:54:53 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2012-01-23 20:02:56 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_reportJavaCrash(JNIEnv *jenv, jclass, jstring jStackTrace)
|
2011-06-01 17:54:53 +00:00
|
|
|
{
|
2011-06-02 05:44:27 +00:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-01-23 20:02:56 +00:00
|
|
|
const nsJNIString stackTrace16(jStackTrace, jenv);
|
|
|
|
const NS_ConvertUTF16toUTF8 stackTrace8(stackTrace16);
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("JavaStackTrace"), stackTrace8);
|
|
|
|
#endif // MOZ_CRASHREPORTER
|
|
|
|
|
2011-06-01 17:54:53 +00:00
|
|
|
abort();
|
|
|
|
}
|
2011-09-16 21:34:31 +00:00
|
|
|
|
2011-11-02 15:35:11 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass,
|
2011-11-09 08:56:37 +00:00
|
|
|
jdouble aLevel,
|
2011-11-09 14:13:37 +00:00
|
|
|
jboolean aCharging,
|
|
|
|
jdouble aRemainingTime)
|
2011-11-02 15:35:11 +00:00
|
|
|
{
|
|
|
|
class NotifyBatteryChangeRunnable : public nsRunnable {
|
|
|
|
public:
|
2011-11-09 14:13:37 +00:00
|
|
|
NotifyBatteryChangeRunnable(double aLevel, bool aCharging, double aRemainingTime)
|
2011-11-02 15:35:11 +00:00
|
|
|
: mLevel(aLevel)
|
|
|
|
, mCharging(aCharging)
|
2011-11-09 14:13:37 +00:00
|
|
|
, mRemainingTime(aRemainingTime)
|
2011-11-02 15:35:11 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2011-11-09 14:13:37 +00:00
|
|
|
hal::NotifyBatteryChange(hal::BatteryInformation(mLevel, mCharging, mRemainingTime));
|
2011-11-02 15:35:11 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-11-09 08:56:37 +00:00
|
|
|
double mLevel;
|
|
|
|
bool mCharging;
|
2011-11-09 14:13:37 +00:00
|
|
|
double mRemainingTime;
|
2011-11-02 15:35:11 +00:00
|
|
|
};
|
|
|
|
|
2011-11-09 14:13:37 +00:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifyBatteryChangeRunnable(aLevel, aCharging, aRemainingTime);
|
2011-11-02 15:35:11 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:42:14 +00:00
|
|
|
#ifdef MOZ_WEBSMS_BACKEND
|
|
|
|
|
2011-11-24 13:10:20 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived(JNIEnv* jenv, jclass,
|
|
|
|
jstring aSender,
|
|
|
|
jstring aBody,
|
|
|
|
jint aMessageClass,
|
|
|
|
jlong aTimestamp)
|
2011-11-24 13:10:20 +00:00
|
|
|
{
|
|
|
|
class NotifySmsReceivedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 21:32:07 +00:00
|
|
|
NotifySmsReceivedRunnable(const SmsMessageData& aMessageData)
|
2011-11-24 13:10:20 +00:00
|
|
|
: mMessageData(aMessageData)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
2012-07-30 14:20:58 +00:00
|
|
|
obs->NotifyObservers(message, kSmsReceivedObserverTopic, nullptr);
|
2011-11-24 13:10:20 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmsMessageData mMessageData;
|
|
|
|
};
|
|
|
|
|
2013-04-08 09:53:48 +00:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(0, 0, eDeliveryState_Received, eDeliveryStatus_Success,
|
2012-10-30 10:53:31 +00:00
|
|
|
nsJNIString(aSender, jenv), EmptyString(),
|
2012-10-31 09:10:53 +00:00
|
|
|
nsJNIString(aBody, jenv),
|
|
|
|
static_cast<MessageClass>(aMessageClass),
|
|
|
|
aTimestamp, false);
|
2011-11-24 13:10:20 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifySmsReceivedRunnable(message);
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
2011-12-21 19:05:23 +00:00
|
|
|
|
2012-01-13 13:25:47 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsSent(JNIEnv* jenv, jclass,
|
|
|
|
jint aId,
|
|
|
|
jstring aReceiver,
|
|
|
|
jstring aBody,
|
|
|
|
jlong aTimestamp,
|
|
|
|
jint aRequestId)
|
2012-01-13 13:25:47 +00:00
|
|
|
{
|
2012-01-13 13:26:24 +00:00
|
|
|
class NotifySmsSentRunnable : public nsRunnable {
|
2012-01-13 13:25:47 +00:00
|
|
|
public:
|
2012-01-13 13:26:50 +00:00
|
|
|
NotifySmsSentRunnable(const SmsMessageData& aMessageData,
|
2012-11-06 21:32:07 +00:00
|
|
|
int32_t aRequestId)
|
2012-01-13 13:26:24 +00:00
|
|
|
: mMessageData(aMessageData)
|
2012-01-13 13:26:50 +00:00
|
|
|
, mRequestId(aRequestId)
|
2012-01-13 13:25:47 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2012-01-13 13:26:50 +00:00
|
|
|
/*
|
|
|
|
* First, we are going to notify all SmsManager that a message has
|
|
|
|
* been sent. Then, we will notify the SmsRequest object about it.
|
|
|
|
*/
|
2012-01-13 13:26:24 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs) {
|
2012-01-13 13:25:47 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-13 13:26:24 +00:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
2012-07-30 14:20:58 +00:00
|
|
|
obs->NotifyObservers(message, kSmsSentObserverTopic, nullptr);
|
2012-01-13 13:25:47 +00:00
|
|
|
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2012-01-13 13:26:50 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
request->NotifyMessageSent(message);
|
2012-01-13 13:26:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRequestId;
|
2012-01-13 13:26:24 +00:00
|
|
|
};
|
2012-01-10 19:34:50 +00:00
|
|
|
|
2012-10-31 09:10:53 +00:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 09:53:48 +00:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aId, 0, eDeliveryState_Sent, eDeliveryStatus_Pending,
|
2012-10-30 10:53:31 +00:00
|
|
|
EmptyString(), nsJNIString(aReceiver, jenv),
|
2012-10-31 09:10:53 +00:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2012-01-13 13:26:24 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifySmsSentRunnable(message, aRequestId);
|
2012-01-13 13:26:24 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsDelivery(JNIEnv* jenv, jclass,
|
|
|
|
jint aId,
|
|
|
|
jint aDeliveryStatus,
|
|
|
|
jstring aReceiver,
|
|
|
|
jstring aBody,
|
|
|
|
jlong aTimestamp)
|
2012-01-13 13:26:24 +00:00
|
|
|
{
|
|
|
|
class NotifySmsDeliveredRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NotifySmsDeliveredRunnable(const SmsMessageData& aMessageData)
|
|
|
|
: mMessageData(aMessageData)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2012-01-10 19:34:50 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs) {
|
2012-01-13 13:26:24 +00:00
|
|
|
return NS_OK;
|
2012-01-10 19:34:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 13:26:24 +00:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
2012-10-30 10:53:31 +00:00
|
|
|
const char* topic = (mMessageData.deliveryStatus() == eDeliveryStatus_Success)
|
|
|
|
? kSmsDeliverySuccessObserverTopic
|
|
|
|
: kSmsDeliveryErrorObserverTopic;
|
|
|
|
obs->NotifyObservers(message, topic, nullptr);
|
2012-01-13 13:25:47 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-01-13 13:26:24 +00:00
|
|
|
SmsMessageData mMessageData;
|
2012-01-13 13:25:47 +00:00
|
|
|
};
|
|
|
|
|
2012-10-31 09:10:53 +00:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 09:53:48 +00:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aId, 0, eDeliveryState_Sent,
|
2012-10-30 10:53:31 +00:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
EmptyString(), nsJNIString(aReceiver, jenv),
|
2012-10-31 09:10:53 +00:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2012-01-13 13:26:24 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifySmsDeliveredRunnable(message);
|
2012-01-13 13:25:47 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:06:35 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsSendFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:06:35 +00:00
|
|
|
{
|
|
|
|
class NotifySmsSendFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
NotifySmsSendFailedRunnable(int32_t aError,
|
2012-11-06 21:32:07 +00:00
|
|
|
int32_t aRequestId)
|
2011-12-22 22:06:35 +00:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 22:06:35 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
request->NotifySendMessageFailed(mError);
|
2011-12-22 22:06:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 22:06:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifySmsSendFailedRunnable(aError, aRequestId);
|
2011-12-22 22:06:35 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:08:58 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyGetSms(JNIEnv* jenv, jclass,
|
|
|
|
jint aId,
|
|
|
|
jint aDeliveryStatus,
|
|
|
|
jstring aReceiver,
|
|
|
|
jstring aSender,
|
|
|
|
jstring aBody,
|
|
|
|
jlong aTimestamp,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:08:58 +00:00
|
|
|
{
|
|
|
|
class NotifyGetSmsRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NotifyGetSmsRunnable(const SmsMessageData& aMessageData,
|
2012-11-06 21:32:07 +00:00
|
|
|
int32_t aRequestId)
|
2011-12-22 22:08:58 +00:00
|
|
|
: mMessageData(aMessageData)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 22:08:58 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
|
|
|
request->NotifyMessageGot(message);
|
2011-12-22 22:08:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRequestId;
|
2011-12-22 22:08:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nsJNIString receiver = nsJNIString(aReceiver, jenv);
|
|
|
|
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
|
|
|
: eDeliveryState_Sent;
|
|
|
|
|
2012-05-17 19:42:38 +00:00
|
|
|
// TODO Need to add the message `read` parameter value. Bug 748391
|
2012-10-31 09:10:53 +00:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 09:53:48 +00:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aId, 0, state,
|
2012-10-30 10:53:31 +00:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
nsJNIString(aSender, jenv), receiver,
|
2012-10-31 09:10:53 +00:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2011-12-22 22:08:58 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifyGetSmsRunnable(message, aRequestId);
|
2011-12-22 22:08:58 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:14:45 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyGetSmsFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:14:45 +00:00
|
|
|
{
|
|
|
|
class NotifyGetSmsFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
NotifyGetSmsFailedRunnable(int32_t aError,
|
2012-11-06 21:32:07 +00:00
|
|
|
int32_t aRequestId)
|
2011-12-22 22:14:45 +00:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 22:14:45 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
request->NotifyGetMessageFailed(mError);
|
2011-12-22 22:14:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 22:14:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifyGetSmsFailedRunnable(aError, aRequestId);
|
2011-12-22 22:14:45 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:15:28 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsDeleted(JNIEnv* jenv, jclass,
|
|
|
|
jboolean aDeleted,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:15:28 +00:00
|
|
|
{
|
|
|
|
class NotifySmsDeletedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 21:32:07 +00:00
|
|
|
NotifySmsDeletedRunnable(bool aDeleted, int32_t aRequestId)
|
2011-12-22 22:15:28 +00:00
|
|
|
: mDeleted(aDeleted)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 22:15:28 +00:00
|
|
|
|
2013-05-16 03:13:39 +00:00
|
|
|
// For android, we support only single SMS deletion.
|
|
|
|
request->NotifyMessageDeleted(&mDeleted, 1);
|
2011-12-22 22:15:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mDeleted;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRequestId;
|
2011-12-22 22:15:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifySmsDeletedRunnable(aDeleted, aRequestId);
|
2011-12-22 22:15:28 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:15:44 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsDeleteFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:15:44 +00:00
|
|
|
{
|
|
|
|
class NotifySmsDeleteFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
NotifySmsDeleteFailedRunnable(int32_t aError,
|
2012-11-06 21:32:07 +00:00
|
|
|
int32_t aRequestId)
|
2011-12-22 22:15:44 +00:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 22:15:44 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
request->NotifyDeleteMessageFailed(mError);
|
2011-12-22 22:15:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 22:15:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifySmsDeleteFailedRunnable(aError, aRequestId);
|
2011-12-22 22:15:44 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:16:22 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyNoMessageInList(JNIEnv* jenv, jclass,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:16:22 +00:00
|
|
|
{
|
2011-12-19 11:04:53 +00:00
|
|
|
class NotifyNoMessageInListRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 21:32:07 +00:00
|
|
|
NotifyNoMessageInListRunnable(int32_t aRequestId)
|
2011-12-19 11:04:53 +00:00
|
|
|
: mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-19 11:04:53 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
request->NotifyNoMessageInList();
|
2011-12-19 11:04:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRequestId;
|
2011-12-19 11:04:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifyNoMessageInListRunnable(aRequestId);
|
2011-12-19 11:04:53 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
2011-12-22 22:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyListCreated(JNIEnv* jenv, jclass,
|
|
|
|
jint aListId,
|
|
|
|
jint aMessageId,
|
|
|
|
jint aDeliveryStatus,
|
|
|
|
jstring aReceiver,
|
|
|
|
jstring aSender,
|
|
|
|
jstring aBody,
|
|
|
|
jlong aTimestamp,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:16:22 +00:00
|
|
|
{
|
2011-12-19 11:07:03 +00:00
|
|
|
class NotifyCreateMessageListRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
NotifyCreateMessageListRunnable(int32_t aListId,
|
2012-11-06 21:32:07 +00:00
|
|
|
const SmsMessageData& aMessageData,
|
|
|
|
int32_t aRequestId)
|
2011-12-19 11:07:03 +00:00
|
|
|
: mListId(aListId)
|
2012-11-06 21:32:07 +00:00
|
|
|
, mMessageData(aMessageData)
|
2011-12-19 11:07:03 +00:00
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-19 11:07:03 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
|
|
|
request->NotifyMessageListCreated(mListId, message);
|
2011-12-19 11:07:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mListId;
|
2012-11-06 21:32:07 +00:00
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRequestId;
|
2011-12-19 11:07:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsJNIString receiver = nsJNIString(aReceiver, jenv);
|
|
|
|
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
|
|
|
: eDeliveryState_Sent;
|
|
|
|
|
2012-05-17 19:42:38 +00:00
|
|
|
// TODO Need to add the message `read` parameter value. Bug 748391
|
2012-10-31 09:10:53 +00:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 09:53:48 +00:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aMessageId, 0, state,
|
2012-10-30 10:53:31 +00:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
nsJNIString(aSender, jenv), receiver,
|
2012-10-31 09:10:53 +00:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2011-12-19 11:07:03 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifyCreateMessageListRunnable(aListId, message, aRequestId);
|
2011-12-19 11:07:03 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
2011-12-22 22:16:22 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:16:59 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyGotNextMessage(JNIEnv* jenv, jclass,
|
|
|
|
jint aMessageId,
|
|
|
|
jint aDeliveryStatus,
|
|
|
|
jstring aReceiver,
|
|
|
|
jstring aSender,
|
|
|
|
jstring aBody,
|
|
|
|
jlong aTimestamp,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:16:59 +00:00
|
|
|
{
|
|
|
|
class NotifyGotNextMessageRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 21:32:07 +00:00
|
|
|
NotifyGotNextMessageRunnable(const SmsMessageData& aMessageData,
|
|
|
|
int32_t aRequestId)
|
|
|
|
: mMessageData(aMessageData)
|
2011-12-22 22:16:59 +00:00
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 22:16:59 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
|
|
|
request->NotifyNextMessageInListGot(message);
|
2011-12-22 22:16:59 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-11-06 21:32:07 +00:00
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mRequestId;
|
2011-12-22 22:16:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsJNIString receiver = nsJNIString(aReceiver, jenv);
|
|
|
|
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
|
|
|
: eDeliveryState_Sent;
|
2012-11-06 21:32:07 +00:00
|
|
|
|
2012-05-17 19:42:38 +00:00
|
|
|
// TODO Need to add the message `read` parameter value. Bug 748391
|
2012-10-31 09:10:53 +00:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 09:53:48 +00:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aMessageId, 0, state,
|
2012-10-30 10:53:31 +00:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
nsJNIString(aSender, jenv), receiver,
|
2012-10-31 09:10:53 +00:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2011-12-22 22:16:59 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifyGotNextMessageRunnable(message, aRequestId);
|
2011-12-22 22:16:59 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:25:14 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 21:42:14 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyReadingMessageListFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 22:25:14 +00:00
|
|
|
{
|
|
|
|
class NotifyReadListFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
NotifyReadListFailedRunnable(int32_t aError,
|
2012-11-06 21:32:07 +00:00
|
|
|
int32_t aRequestId)
|
2011-12-22 22:25:14 +00:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-09 07:22:02 +00:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 21:32:07 +00:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 22:25:14 +00:00
|
|
|
|
2012-11-06 21:32:07 +00:00
|
|
|
request->NotifyReadMessageListFailed(mError);
|
2011-12-22 22:25:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 22:25:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 21:32:07 +00:00
|
|
|
new NotifyReadListFailedRunnable(aError, aRequestId);
|
2011-12-22 22:25:14 +00:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2013-02-08 21:42:14 +00:00
|
|
|
#endif // MOZ_WEBSMS_BACKEND
|
|
|
|
|
2012-02-04 02:35:58 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_scheduleComposite(JNIEnv*, jclass)
|
|
|
|
{
|
2012-03-14 04:15:11 +00:00
|
|
|
nsWindow::ScheduleComposite();
|
2012-02-04 02:35:58 +00:00
|
|
|
}
|
|
|
|
|
2012-02-05 18:33:38 +00:00
|
|
|
NS_EXPORT void JNICALL
|
2012-04-20 15:46:30 +00:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_scheduleResumeComposition(JNIEnv*, jclass, jint width, jint height)
|
2012-02-05 18:33:38 +00:00
|
|
|
{
|
2012-04-20 15:46:30 +00:00
|
|
|
nsWindow::ScheduleResumeComposition(width, height);
|
2012-02-05 18:33:38 +00:00
|
|
|
}
|
|
|
|
|
2012-10-25 16:23:47 +00:00
|
|
|
NS_EXPORT float JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_computeRenderIntegrity(JNIEnv*, jclass)
|
|
|
|
{
|
|
|
|
return nsWindow::ComputeRenderIntegrity();
|
|
|
|
}
|
|
|
|
|
2012-04-05 05:50:06 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_notifyFilePickerResult(JNIEnv* jenv, jclass, jstring filePath, jlong callback)
|
|
|
|
{
|
|
|
|
class NotifyFilePickerResultRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NotifyFilePickerResultRunnable(nsString& fileDir, long callback) :
|
|
|
|
mFileDir(fileDir), mCallback(callback) {}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
|
|
|
nsFilePickerCallback* handler = (nsFilePickerCallback*)mCallback;
|
|
|
|
handler->handleResult(mFileDir);
|
|
|
|
handler->Release();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsString mFileDir;
|
|
|
|
long mCallback;
|
|
|
|
};
|
|
|
|
nsString path = nsJNIString(filePath, jenv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
new NotifyFilePickerResultRunnable(path, (long)callback);
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
static int
|
|
|
|
NextPowerOfTwo(int value) {
|
|
|
|
// code taken from http://acius2.blogspot.com/2007/11/calculating-next-power-of-2.html
|
|
|
|
if (0 == value--) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
value = (value >> 1) | value;
|
|
|
|
value = (value >> 2) | value;
|
|
|
|
value = (value >> 4) | value;
|
|
|
|
value = (value >> 8) | value;
|
|
|
|
value = (value >> 16) | value;
|
|
|
|
return value + 1;
|
|
|
|
}
|
|
|
|
|
2012-05-07 18:18:30 +00:00
|
|
|
#define MAX_LOCK_ATTEMPTS 10
|
|
|
|
|
|
|
|
static bool LockWindowWithRetry(void* window, unsigned char** bits, int* width, int* height, int* format, int* stride)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while (count < MAX_LOCK_ATTEMPTS) {
|
|
|
|
if (AndroidBridge::Bridge()->LockWindow(window, bits, width, height, format, stride))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
usleep(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
NS_EXPORT jobject JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_getSurfaceBits(JNIEnv* jenv, jclass, jobject surface)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
static jclass jSurfaceBitsClass = nullptr;
|
2012-04-27 20:04:47 +00:00
|
|
|
static jmethodID jSurfaceBitsCtor = 0;
|
|
|
|
static jfieldID jSurfaceBitsWidth, jSurfaceBitsHeight, jSurfaceBitsFormat, jSurfaceBitsBuffer;
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
jobject surfaceBits = nullptr;
|
|
|
|
unsigned char* bitsCopy = nullptr;
|
2012-04-27 20:04:47 +00:00
|
|
|
int dstWidth, dstHeight, dstSize;
|
|
|
|
|
|
|
|
void* window = AndroidBridge::Bridge()->AcquireNativeWindow(jenv, surface);
|
|
|
|
if (!window)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-04-27 20:04:47 +00:00
|
|
|
|
|
|
|
unsigned char* bits;
|
|
|
|
int srcWidth, srcHeight, format, srcStride;
|
|
|
|
|
|
|
|
// So we lock/unlock once here in order to get whatever is currently the front buffer. It sucks.
|
2012-05-07 18:18:30 +00:00
|
|
|
if (!LockWindowWithRetry(window, &bits, &srcWidth, &srcHeight, &format, &srcStride))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-05-07 18:18:30 +00:00
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
AndroidBridge::Bridge()->UnlockWindow(window);
|
|
|
|
|
|
|
|
// This is lock will result in the front buffer, since the last unlock rotated it to the back. Probably.
|
2012-05-07 18:18:30 +00:00
|
|
|
if (!LockWindowWithRetry(window, &bits, &srcWidth, &srcHeight, &format, &srcStride))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-04-27 20:04:47 +00:00
|
|
|
|
|
|
|
// These are from android.graphics.PixelFormat
|
|
|
|
int bpp;
|
|
|
|
switch (format) {
|
|
|
|
case 1: // RGBA_8888
|
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
case 4: // RGB_565
|
|
|
|
bpp = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
dstWidth = NextPowerOfTwo(srcWidth);
|
|
|
|
dstHeight = NextPowerOfTwo(srcHeight);
|
|
|
|
dstSize = dstWidth * dstHeight * bpp;
|
|
|
|
|
|
|
|
bitsCopy = (unsigned char*)malloc(dstSize);
|
|
|
|
bzero(bitsCopy, dstSize);
|
|
|
|
for (int i = 0; i < srcHeight; i++) {
|
|
|
|
memcpy(bitsCopy + ((dstHeight - i - 1) * dstWidth * bpp), bits + (i * srcStride * bpp), srcStride * bpp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!jSurfaceBitsClass) {
|
|
|
|
jSurfaceBitsClass = (jclass)jenv->NewGlobalRef(jenv->FindClass("org/mozilla/gecko/SurfaceBits"));
|
|
|
|
jSurfaceBitsCtor = jenv->GetMethodID(jSurfaceBitsClass, "<init>", "()V");
|
|
|
|
|
|
|
|
jSurfaceBitsWidth = jenv->GetFieldID(jSurfaceBitsClass, "width", "I");
|
|
|
|
jSurfaceBitsHeight = jenv->GetFieldID(jSurfaceBitsClass, "height", "I");
|
|
|
|
jSurfaceBitsFormat = jenv->GetFieldID(jSurfaceBitsClass, "format", "I");
|
|
|
|
jSurfaceBitsBuffer = jenv->GetFieldID(jSurfaceBitsClass, "buffer", "Ljava/nio/ByteBuffer;");
|
|
|
|
}
|
|
|
|
|
|
|
|
surfaceBits = jenv->NewObject(jSurfaceBitsClass, jSurfaceBitsCtor);
|
|
|
|
jenv->SetIntField(surfaceBits, jSurfaceBitsWidth, dstWidth);
|
|
|
|
jenv->SetIntField(surfaceBits, jSurfaceBitsHeight, dstHeight);
|
|
|
|
jenv->SetIntField(surfaceBits, jSurfaceBitsFormat, format);
|
|
|
|
jenv->SetObjectField(surfaceBits, jSurfaceBitsBuffer, jenv->NewDirectByteBuffer(bitsCopy, dstSize));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
AndroidBridge::Bridge()->UnlockWindow(window);
|
|
|
|
AndroidBridge::Bridge()->ReleaseNativeWindow(window);
|
|
|
|
|
|
|
|
return surfaceBits;
|
|
|
|
}
|
|
|
|
|
2012-05-30 16:10:49 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_onFullScreenPluginHidden(JNIEnv* jenv, jclass, jobject view)
|
|
|
|
{
|
|
|
|
class ExitFullScreenRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
ExitFullScreenRunnable(jobject view) : mView(view) {}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
|
|
|
JNIEnv* env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env) {
|
|
|
|
NS_WARNING("Failed to acquire JNI env, can't exit plugin fullscreen mode");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginInstanceOwner::ExitFullScreen(mView);
|
|
|
|
env->DeleteGlobalRef(mView);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
jobject mView;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new ExitFullScreenRunnable(jenv->NewGlobalRef(view));
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
2012-04-27 20:04:47 +00:00
|
|
|
|
2012-06-01 03:24:07 +00:00
|
|
|
NS_EXPORT jobject JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_getNextMessageFromQueue(JNIEnv* jenv, jclass, jobject queue)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
static jclass jMessageQueueCls = nullptr;
|
2013-07-26 19:02:00 +00:00
|
|
|
static jfieldID jMessagesField;
|
2012-06-01 03:24:07 +00:00
|
|
|
static jmethodID jNextMethod;
|
|
|
|
if (!jMessageQueueCls) {
|
|
|
|
jMessageQueueCls = (jclass) jenv->NewGlobalRef(jenv->FindClass("android/os/MessageQueue"));
|
|
|
|
jNextMethod = jenv->GetMethodID(jMessageQueueCls, "next", "()Landroid/os/Message;");
|
2013-07-26 19:02:00 +00:00
|
|
|
jMessagesField = jenv->GetFieldID(jMessageQueueCls, "mMessages", "Landroid/os/Message;");
|
2012-06-01 03:24:07 +00:00
|
|
|
}
|
2013-07-26 19:02:00 +00:00
|
|
|
|
2013-07-09 20:25:55 +00:00
|
|
|
if (!jMessageQueueCls || !jNextMethod)
|
2013-10-10 20:42:52 +00:00
|
|
|
return nullptr;
|
2013-07-26 19:02:00 +00:00
|
|
|
|
|
|
|
if (jMessagesField) {
|
|
|
|
jobject msg = jenv->GetObjectField(queue, jMessagesField);
|
|
|
|
// if queue.mMessages is null, queue.next() will block, which we don't want
|
|
|
|
// It turns out to be an order of magnitude more performant to do this extra check here and
|
|
|
|
// block less vs. one fewer checks here and more blocking.
|
|
|
|
if (!msg) {
|
2013-10-10 20:42:52 +00:00
|
|
|
return nullptr;
|
2013-07-26 19:02:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-09 20:25:55 +00:00
|
|
|
return jenv->CallObjectMethod(queue, jNextMethod);
|
2012-06-01 03:24:07 +00:00
|
|
|
}
|
|
|
|
|
2012-07-20 19:20:51 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_onSurfaceTextureFrameAvailable(JNIEnv* jenv, jclass, jobject surfaceTexture, jint id)
|
|
|
|
{
|
|
|
|
nsSurfaceTexture* st = nsSurfaceTexture::Find(id);
|
|
|
|
if (!st) {
|
|
|
|
__android_log_print(ANDROID_LOG_ERROR, "GeckoJNI", "Failed to find nsSurfaceTexture with id %d", id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
st->NotifyFrameAvailable();
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:10:29 +00:00
|
|
|
NS_EXPORT jdouble JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime(JNIEnv *jenv, jclass jc)
|
|
|
|
{
|
|
|
|
return profiler_time();
|
|
|
|
}
|
|
|
|
|
2013-07-23 20:41:22 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation(JNIEnv* env, jobject instance)
|
|
|
|
{
|
2013-07-30 18:03:43 +00:00
|
|
|
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
|
2013-07-30 18:03:40 +00:00
|
|
|
if (controller) {
|
2013-07-30 18:03:43 +00:00
|
|
|
controller->CancelAnimation(ScrollableLayerGuid(nsWindow::RootLayerTreeId()));
|
2013-07-30 18:03:40 +00:00
|
|
|
}
|
2013-07-23 20:41:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-26 17:24:28 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_init(JNIEnv* env, jobject instance)
|
|
|
|
{
|
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject oldRef = AndroidBridge::Bridge()->SetNativePanZoomController(env->NewGlobalRef(instance));
|
|
|
|
if (oldRef) {
|
|
|
|
MOZ_ASSERT(false, "Registering a new NPZC when we already have one");
|
|
|
|
env->DeleteGlobalRef(oldRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(JNIEnv* env, jobject instance, jobject event)
|
|
|
|
{
|
2013-07-30 18:03:43 +00:00
|
|
|
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
|
2013-04-26 17:24:28 +00:00
|
|
|
if (controller) {
|
|
|
|
AndroidGeckoEvent* wrapper = AndroidGeckoEvent::MakeFromJavaObject(env, event);
|
|
|
|
const MultiTouchInput& input = wrapper->MakeMultiTouchInput(nsWindow::TopWindow());
|
|
|
|
delete wrapper;
|
|
|
|
if (input.mType >= 0) {
|
2013-11-10 16:43:17 +00:00
|
|
|
controller->ReceiveInputEvent(input, nullptr);
|
2013-04-26 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-26 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent(JNIEnv* env, jobject instance, jobject event)
|
|
|
|
{
|
|
|
|
// FIXME implement this
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:26:46 +00:00
|
|
|
NS_EXPORT jlong JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_runDelayedCallback(JNIEnv* env, jobject instance)
|
|
|
|
{
|
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return AndroidBridge::Bridge()->RunDelayedTasks();
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:24:28 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(JNIEnv* env, jobject instance)
|
|
|
|
{
|
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-10 20:42:52 +00:00
|
|
|
jobject oldRef = AndroidBridge::Bridge()->SetNativePanZoomController(nullptr);
|
2013-04-26 17:24:28 +00:00
|
|
|
if (!oldRef) {
|
|
|
|
MOZ_ASSERT(false, "Clearing a non-existent NPZC");
|
|
|
|
} else {
|
|
|
|
env->DeleteGlobalRef(oldRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented(JNIEnv* env, jobject instance, jboolean prevented)
|
|
|
|
{
|
2013-07-30 18:03:43 +00:00
|
|
|
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
|
2013-04-26 17:24:28 +00:00
|
|
|
if (controller) {
|
2013-07-30 18:03:43 +00:00
|
|
|
controller->ContentReceivedTouch(ScrollableLayerGuid(nsWindow::RootLayerTreeId()), prevented);
|
2013-04-26 17:24:28 +00:00
|
|
|
}
|
2013-04-26 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT jboolean JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_getRedrawHint(JNIEnv* env, jobject instance)
|
|
|
|
{
|
|
|
|
// FIXME implement this
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_setOverScrollMode(JNIEnv* env, jobject instance, jint overscrollMode)
|
|
|
|
{
|
|
|
|
// FIXME implement this
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT jint JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_getOverScrollMode(JNIEnv* env, jobject instance)
|
|
|
|
{
|
|
|
|
// FIXME implement this
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-23 02:33:05 +00:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_updateScrollOffset(JNIEnv* env, jobject instance, jfloat cssX, jfloat cssY)
|
|
|
|
{
|
2013-07-30 18:03:43 +00:00
|
|
|
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
|
2013-07-23 02:33:05 +00:00
|
|
|
if (controller) {
|
2013-07-30 18:03:43 +00:00
|
|
|
controller->UpdateScrollOffset(ScrollableLayerGuid(nsWindow::RootLayerTreeId()), CSSPoint(cssX, cssY));
|
2013-07-23 02:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-14 16:42:10 +00:00
|
|
|
NS_EXPORT jboolean JNICALL
|
|
|
|
Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass)
|
|
|
|
{
|
2013-06-14 16:42:10 +00:00
|
|
|
if (profiler_is_active()) {
|
|
|
|
// Don't proceed if profiler is already running
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
// WARNING: we are on the ANR reporter thread at this point and it is
|
|
|
|
// generally unsafe to use the profiler from off the main thread. However,
|
|
|
|
// the risk here is limited because for most users, the profiler is not run
|
|
|
|
// elsewhere. See the discussion in Bug 863777, comment 13
|
2013-06-14 16:42:10 +00:00
|
|
|
const char *NATIVE_STACK_FEATURES[] = {"leaf", "threads", "privacy"};
|
2013-06-14 16:42:10 +00:00
|
|
|
// Buffer one sample and let the profiler wait a long time
|
|
|
|
profiler_start(100, 10000, NATIVE_STACK_FEATURES,
|
2013-05-16 20:31:50 +00:00
|
|
|
sizeof(NATIVE_STACK_FEATURES) / sizeof(char*),
|
2013-10-10 20:42:52 +00:00
|
|
|
nullptr, 0);
|
2013-06-14 16:42:10 +00:00
|
|
|
return JNI_TRUE;
|
2013-06-14 16:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT jstring JNICALL
|
|
|
|
Java_org_mozilla_gecko_ANRReporter_getNativeStack(JNIEnv* jenv, jclass)
|
|
|
|
{
|
2013-06-14 16:42:10 +00:00
|
|
|
if (!profiler_is_active()) {
|
|
|
|
// Maybe profiler support is disabled?
|
2013-10-10 20:42:52 +00:00
|
|
|
return nullptr;
|
2013-06-14 16:42:10 +00:00
|
|
|
}
|
|
|
|
char *profile = profiler_get_profile();
|
|
|
|
while (profile && !strlen(profile)) {
|
|
|
|
// no sample yet?
|
|
|
|
sched_yield();
|
|
|
|
profile = profiler_get_profile();
|
|
|
|
}
|
2013-10-10 20:42:52 +00:00
|
|
|
jstring result = nullptr;
|
2013-06-14 16:42:10 +00:00
|
|
|
if (profile) {
|
|
|
|
result = jenv->NewStringUTF(profile);
|
|
|
|
free(profile);
|
|
|
|
}
|
|
|
|
return result;
|
2013-06-14 16:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_ANRReporter_releaseNativeStack(JNIEnv* jenv, jclass)
|
|
|
|
{
|
2013-06-14 16:42:10 +00:00
|
|
|
if (!profiler_is_active()) {
|
|
|
|
// Maybe profiler support is disabled?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mozilla_sampler_stop();
|
2013-06-14 16:42:10 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 22:53:57 +00:00
|
|
|
}
|