2010-06-03 13:56:36 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07: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 13:56:36 -07:00
|
|
|
|
2011-11-02 08:35:11 -07:00
|
|
|
#include "mozilla/Hal.h"
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2010-06-14 19:17:37 -07:00
|
|
|
#include "nsString.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2011-12-21 11:05:23 -08:00
|
|
|
#include "AndroidGraphicBuffer.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <dlfcn.h>
|
2011-11-14 19:12:14 -08:00
|
|
|
#include <stdio.h>
|
2012-04-27 13:04:47 -07:00
|
|
|
#include <unistd.h>
|
2013-06-14 09:42:10 -07:00
|
|
|
#include <sched.h>
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include "nsAppShell.h"
|
|
|
|
#include "nsWindow.h"
|
|
|
|
#include <android/log.h>
|
2010-08-31 10:37:54 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "mozilla/Services.h"
|
2013-09-24 13:45:13 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-01-19 22:14:12 -08:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsICrashReporter.h"
|
2011-06-01 10:54:53 -07:00
|
|
|
#include "nsExceptionHandler.h"
|
2011-01-19 22:14:12 -08:00
|
|
|
#endif
|
|
|
|
|
2012-01-13 05:26:50 -08:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
|
2013-03-01 00:38:47 -08: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 11:03:40 -07:00
|
|
|
#include "mozilla/layers/APZCTreeManager.h"
|
2013-02-05 03:39:44 -08:00
|
|
|
#include "nsIMobileMessageDatabaseService.h"
|
2012-05-30 09:10:49 -07:00
|
|
|
#include "nsPluginInstanceOwner.h"
|
2012-07-20 12:20:51 -07:00
|
|
|
#include "nsSurfaceTexture.h"
|
2013-04-23 10:10:29 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2013-11-27 03:52:05 -08:00
|
|
|
#include "nsMemoryPressure.h"
|
2013-06-14 09:42:10 -07:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
using namespace mozilla;
|
2013-03-01 00:38:47 -08:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::dom::mobilemessage;
|
2013-04-26 10:24:28 -07:00
|
|
|
using namespace mozilla::layers;
|
2014-04-01 05:29:25 -07:00
|
|
|
using namespace mozilla::widget::android;
|
2010-06-03 13:56:36 -07: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 05:57:36 -07:00
|
|
|
AndroidBridge::ConstructBridge(jenv);
|
2010-06-03 13:56:36 -07: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 14:39:12 -07:00
|
|
|
nsAppShell::gAppShell->PostEvent(AndroidGeckoEvent::MakeFromJavaObject(jenv, event));
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-08-18 19:30:22 -07:00
|
|
|
NS_EXPORT void JNICALL
|
2013-05-09 18:48:00 -07:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_processNextNativeEvent(JNIEnv *jenv, jclass, jboolean mayWait)
|
2011-08-18 19:30:22 -07:00
|
|
|
{
|
|
|
|
// poke the appshell
|
|
|
|
if (nsAppShell::gAppShell)
|
2013-05-09 18:48:00 -07:00
|
|
|
nsAppShell::gAppShell->ProcessNextNativeEvent(mayWait != JNI_FALSE);
|
2011-08-18 19:30:22 -07:00
|
|
|
}
|
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2012-02-17 06:16:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_setLayerClient(JNIEnv *jenv, jclass, jobject obj)
|
2011-11-14 19:12:14 -08:00
|
|
|
{
|
2012-07-13 07:19:46 -07:00
|
|
|
AndroidBridge::Bridge()->SetLayerClient(jenv, obj);
|
2011-11-14 19:12:14 -08:00
|
|
|
}
|
|
|
|
|
2011-02-01 22:34:12 -08:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_onResume(JNIEnv *jenv, jclass jc)
|
|
|
|
{
|
|
|
|
if (nsAppShell::gAppShell)
|
|
|
|
nsAppShell::gAppShell->OnResume();
|
|
|
|
}
|
|
|
|
|
2011-06-01 10:54:53 -07:00
|
|
|
NS_EXPORT void JNICALL
|
2012-01-23 12:02:56 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_reportJavaCrash(JNIEnv *jenv, jclass, jstring jStackTrace)
|
2011-06-01 10:54:53 -07:00
|
|
|
{
|
2011-06-01 22:44:27 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-01-23 12:02:56 -08:00
|
|
|
const nsJNIString stackTrace16(jStackTrace, jenv);
|
|
|
|
const NS_ConvertUTF16toUTF8 stackTrace8(stackTrace16);
|
|
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("JavaStackTrace"), stackTrace8);
|
|
|
|
#endif // MOZ_CRASHREPORTER
|
|
|
|
|
2011-06-01 10:54:53 -07:00
|
|
|
abort();
|
|
|
|
}
|
2011-09-16 14:34:31 -07:00
|
|
|
|
2011-11-02 08:35:11 -07:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_notifyBatteryChange(JNIEnv* jenv, jclass,
|
2011-11-09 00:56:37 -08:00
|
|
|
jdouble aLevel,
|
2011-11-09 06:13:37 -08:00
|
|
|
jboolean aCharging,
|
|
|
|
jdouble aRemainingTime)
|
2011-11-02 08:35:11 -07:00
|
|
|
{
|
|
|
|
class NotifyBatteryChangeRunnable : public nsRunnable {
|
|
|
|
public:
|
2011-11-09 06:13:37 -08:00
|
|
|
NotifyBatteryChangeRunnable(double aLevel, bool aCharging, double aRemainingTime)
|
2011-11-02 08:35:11 -07:00
|
|
|
: mLevel(aLevel)
|
|
|
|
, mCharging(aCharging)
|
2011-11-09 06:13:37 -08:00
|
|
|
, mRemainingTime(aRemainingTime)
|
2011-11-02 08:35:11 -07:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2011-11-09 06:13:37 -08:00
|
|
|
hal::NotifyBatteryChange(hal::BatteryInformation(mLevel, mCharging, mRemainingTime));
|
2011-11-02 08:35:11 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-11-09 00:56:37 -08:00
|
|
|
double mLevel;
|
|
|
|
bool mCharging;
|
2011-11-09 06:13:37 -08:00
|
|
|
double mRemainingTime;
|
2011-11-02 08:35:11 -07:00
|
|
|
};
|
|
|
|
|
2011-11-09 06:13:37 -08:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifyBatteryChangeRunnable(aLevel, aCharging, aRemainingTime);
|
2011-11-02 08:35:11 -07:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2013-02-08 13:42:14 -08:00
|
|
|
#ifdef MOZ_WEBSMS_BACKEND
|
|
|
|
|
2011-11-24 05:10:20 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsReceived(JNIEnv* jenv, jclass,
|
|
|
|
jstring aSender,
|
|
|
|
jstring aBody,
|
|
|
|
jint aMessageClass,
|
|
|
|
jlong aTimestamp)
|
2011-11-24 05:10:20 -08:00
|
|
|
{
|
|
|
|
class NotifySmsReceivedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 13:32:07 -08:00
|
|
|
NotifySmsReceivedRunnable(const SmsMessageData& aMessageData)
|
2011-11-24 05:10:20 -08: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 07:20:58 -07:00
|
|
|
obs->NotifyObservers(message, kSmsReceivedObserverTopic, nullptr);
|
2011-11-24 05:10:20 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmsMessageData mMessageData;
|
|
|
|
};
|
|
|
|
|
2013-04-08 02:53:48 -07:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(0, 0, eDeliveryState_Received, eDeliveryStatus_Success,
|
2012-10-30 03:53:31 -07:00
|
|
|
nsJNIString(aSender, jenv), EmptyString(),
|
2012-10-31 02:10:53 -07:00
|
|
|
nsJNIString(aBody, jenv),
|
|
|
|
static_cast<MessageClass>(aMessageClass),
|
|
|
|
aTimestamp, false);
|
2011-11-24 05:10:20 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifySmsReceivedRunnable(message);
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
2011-12-21 11:05:23 -08:00
|
|
|
|
2012-01-13 05:25:47 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsSent(JNIEnv* jenv, jclass,
|
|
|
|
jint aId,
|
|
|
|
jstring aReceiver,
|
|
|
|
jstring aBody,
|
|
|
|
jlong aTimestamp,
|
|
|
|
jint aRequestId)
|
2012-01-13 05:25:47 -08:00
|
|
|
{
|
2012-01-13 05:26:24 -08:00
|
|
|
class NotifySmsSentRunnable : public nsRunnable {
|
2012-01-13 05:25:47 -08:00
|
|
|
public:
|
2012-01-13 05:26:50 -08:00
|
|
|
NotifySmsSentRunnable(const SmsMessageData& aMessageData,
|
2012-11-06 13:32:07 -08:00
|
|
|
int32_t aRequestId)
|
2012-01-13 05:26:24 -08:00
|
|
|
: mMessageData(aMessageData)
|
2012-01-13 05:26:50 -08:00
|
|
|
, mRequestId(aRequestId)
|
2012-01-13 05:25:47 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2012-01-13 05:26:50 -08: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 05:26:24 -08:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs) {
|
2012-01-13 05:25:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-13 05:26:24 -08:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
2012-07-30 07:20:58 -07:00
|
|
|
obs->NotifyObservers(message, kSmsSentObserverTopic, nullptr);
|
2012-01-13 05:25:47 -08:00
|
|
|
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2012-01-13 05:26:50 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
request->NotifyMessageSent(message);
|
2012-01-13 05:26:24 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRequestId;
|
2012-01-13 05:26:24 -08:00
|
|
|
};
|
2012-01-10 11:34:50 -08:00
|
|
|
|
2012-10-31 02:10:53 -07:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 02:53:48 -07:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aId, 0, eDeliveryState_Sent, eDeliveryStatus_Pending,
|
2012-10-30 03:53:31 -07:00
|
|
|
EmptyString(), nsJNIString(aReceiver, jenv),
|
2012-10-31 02:10:53 -07:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2012-01-13 05:26:24 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifySmsSentRunnable(message, aRequestId);
|
2012-01-13 05:26:24 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsDelivery(JNIEnv* jenv, jclass,
|
|
|
|
jint aId,
|
|
|
|
jint aDeliveryStatus,
|
|
|
|
jstring aReceiver,
|
|
|
|
jstring aBody,
|
|
|
|
jlong aTimestamp)
|
2012-01-13 05:26:24 -08:00
|
|
|
{
|
|
|
|
class NotifySmsDeliveredRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NotifySmsDeliveredRunnable(const SmsMessageData& aMessageData)
|
|
|
|
: mMessageData(aMessageData)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2012-01-10 11:34:50 -08:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (!obs) {
|
2012-01-13 05:26:24 -08:00
|
|
|
return NS_OK;
|
2012-01-10 11:34:50 -08:00
|
|
|
}
|
|
|
|
|
2012-01-13 05:26:24 -08:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
2012-10-30 03:53:31 -07:00
|
|
|
const char* topic = (mMessageData.deliveryStatus() == eDeliveryStatus_Success)
|
|
|
|
? kSmsDeliverySuccessObserverTopic
|
|
|
|
: kSmsDeliveryErrorObserverTopic;
|
|
|
|
obs->NotifyObservers(message, topic, nullptr);
|
2012-01-13 05:25:47 -08:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-01-13 05:26:24 -08:00
|
|
|
SmsMessageData mMessageData;
|
2012-01-13 05:25:47 -08:00
|
|
|
};
|
|
|
|
|
2012-10-31 02:10:53 -07:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 02:53:48 -07:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aId, 0, eDeliveryState_Sent,
|
2012-10-30 03:53:31 -07:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
EmptyString(), nsJNIString(aReceiver, jenv),
|
2012-10-31 02:10:53 -07:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2012-01-13 05:26:24 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifySmsDeliveredRunnable(message);
|
2012-01-13 05:25:47 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:06:35 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsSendFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 14:06:35 -08:00
|
|
|
{
|
|
|
|
class NotifySmsSendFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
NotifySmsSendFailedRunnable(int32_t aError,
|
2012-11-06 13:32:07 -08:00
|
|
|
int32_t aRequestId)
|
2011-12-22 14:06:35 -08:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 14:06:35 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
request->NotifySendMessageFailed(mError);
|
2011-12-22 14:06:35 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 14:06:35 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifySmsSendFailedRunnable(aError, aRequestId);
|
2011-12-22 14:06:35 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:08:58 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08: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 14:08:58 -08:00
|
|
|
{
|
|
|
|
class NotifyGetSmsRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NotifyGetSmsRunnable(const SmsMessageData& aMessageData,
|
2012-11-06 13:32:07 -08:00
|
|
|
int32_t aRequestId)
|
2011-12-22 14:08:58 -08:00
|
|
|
: mMessageData(aMessageData)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 14:08:58 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
|
|
|
request->NotifyMessageGot(message);
|
2011-12-22 14:08:58 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRequestId;
|
2011-12-22 14:08:58 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
nsJNIString receiver = nsJNIString(aReceiver, jenv);
|
|
|
|
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
|
|
|
: eDeliveryState_Sent;
|
|
|
|
|
2012-05-17 12:42:38 -07:00
|
|
|
// TODO Need to add the message `read` parameter value. Bug 748391
|
2012-10-31 02:10:53 -07:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 02:53:48 -07:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aId, 0, state,
|
2012-10-30 03:53:31 -07:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
nsJNIString(aSender, jenv), receiver,
|
2012-10-31 02:10:53 -07:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2011-12-22 14:08:58 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = new NotifyGetSmsRunnable(message, aRequestId);
|
2011-12-22 14:08:58 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:14:45 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyGetSmsFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 14:14:45 -08:00
|
|
|
{
|
|
|
|
class NotifyGetSmsFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
NotifyGetSmsFailedRunnable(int32_t aError,
|
2012-11-06 13:32:07 -08:00
|
|
|
int32_t aRequestId)
|
2011-12-22 14:14:45 -08:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 14:14:45 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
request->NotifyGetMessageFailed(mError);
|
2011-12-22 14:14:45 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 14:14:45 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifyGetSmsFailedRunnable(aError, aRequestId);
|
2011-12-22 14:14:45 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:15:28 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsDeleted(JNIEnv* jenv, jclass,
|
|
|
|
jboolean aDeleted,
|
|
|
|
jint aRequestId)
|
2011-12-22 14:15:28 -08:00
|
|
|
{
|
|
|
|
class NotifySmsDeletedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 13:32:07 -08:00
|
|
|
NotifySmsDeletedRunnable(bool aDeleted, int32_t aRequestId)
|
2011-12-22 14:15:28 -08:00
|
|
|
: mDeleted(aDeleted)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 14:15:28 -08:00
|
|
|
|
2013-05-15 20:13:39 -07:00
|
|
|
// For android, we support only single SMS deletion.
|
|
|
|
request->NotifyMessageDeleted(&mDeleted, 1);
|
2011-12-22 14:15:28 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mDeleted;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRequestId;
|
2011-12-22 14:15:28 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifySmsDeletedRunnable(aDeleted, aRequestId);
|
2011-12-22 14:15:28 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:15:44 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifySmsDeleteFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 14:15:44 -08:00
|
|
|
{
|
|
|
|
class NotifySmsDeleteFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
NotifySmsDeleteFailedRunnable(int32_t aError,
|
2012-11-06 13:32:07 -08:00
|
|
|
int32_t aRequestId)
|
2011-12-22 14:15:44 -08:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 14:15:44 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
request->NotifyDeleteMessageFailed(mError);
|
2011-12-22 14:15:44 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 14:15:44 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifySmsDeleteFailedRunnable(aError, aRequestId);
|
2011-12-22 14:15:44 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:16:22 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyNoMessageInList(JNIEnv* jenv, jclass,
|
|
|
|
jint aRequestId)
|
2011-12-22 14:16:22 -08:00
|
|
|
{
|
2011-12-19 03:04:53 -08:00
|
|
|
class NotifyNoMessageInListRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 13:32:07 -08:00
|
|
|
NotifyNoMessageInListRunnable(int32_t aRequestId)
|
2011-12-19 03:04:53 -08:00
|
|
|
: mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-19 03:04:53 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
request->NotifyNoMessageInList();
|
2011-12-19 03:04:53 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRequestId;
|
2011-12-19 03:04:53 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifyNoMessageInListRunnable(aRequestId);
|
2011-12-19 03:04:53 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
2011-12-22 14:16:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08: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 14:16:22 -08:00
|
|
|
{
|
2011-12-19 03:07:03 -08:00
|
|
|
class NotifyCreateMessageListRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
NotifyCreateMessageListRunnable(int32_t aListId,
|
2012-11-06 13:32:07 -08:00
|
|
|
const SmsMessageData& aMessageData,
|
|
|
|
int32_t aRequestId)
|
2011-12-19 03:07:03 -08:00
|
|
|
: mListId(aListId)
|
2012-11-06 13:32:07 -08:00
|
|
|
, mMessageData(aMessageData)
|
2011-12-19 03:07:03 -08:00
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-19 03:07:03 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
|
|
|
request->NotifyMessageListCreated(mListId, message);
|
2011-12-19 03:07:03 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mListId;
|
2012-11-06 13:32:07 -08:00
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRequestId;
|
2011-12-19 03:07:03 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsJNIString receiver = nsJNIString(aReceiver, jenv);
|
|
|
|
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
|
|
|
: eDeliveryState_Sent;
|
|
|
|
|
2012-05-17 12:42:38 -07:00
|
|
|
// TODO Need to add the message `read` parameter value. Bug 748391
|
2012-10-31 02:10:53 -07:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 02:53:48 -07:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aMessageId, 0, state,
|
2012-10-30 03:53:31 -07:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
nsJNIString(aSender, jenv), receiver,
|
2012-10-31 02:10:53 -07:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2011-12-19 03:07:03 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifyCreateMessageListRunnable(aListId, message, aRequestId);
|
2011-12-19 03:07:03 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
2011-12-22 14:16:22 -08:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:16:59 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08: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 14:16:59 -08:00
|
|
|
{
|
|
|
|
class NotifyGotNextMessageRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-11-06 13:32:07 -08:00
|
|
|
NotifyGotNextMessageRunnable(const SmsMessageData& aMessageData,
|
|
|
|
int32_t aRequestId)
|
|
|
|
: mMessageData(aMessageData)
|
2011-12-22 14:16:59 -08:00
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 14:16:59 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
nsCOMPtr<nsIDOMMozSmsMessage> message = new SmsMessage(mMessageData);
|
|
|
|
request->NotifyNextMessageInListGot(message);
|
2011-12-22 14:16:59 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-11-06 13:32:07 -08:00
|
|
|
SmsMessageData mMessageData;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mRequestId;
|
2011-12-22 14:16:59 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsJNIString receiver = nsJNIString(aReceiver, jenv);
|
|
|
|
DeliveryState state = receiver.IsEmpty() ? eDeliveryState_Received
|
|
|
|
: eDeliveryState_Sent;
|
2012-11-06 13:32:07 -08:00
|
|
|
|
2012-05-17 12:42:38 -07:00
|
|
|
// TODO Need to add the message `read` parameter value. Bug 748391
|
2012-10-31 02:10:53 -07:00
|
|
|
// TODO Need to add the message `messageClass` parameter value. Bug 804476
|
2013-04-08 02:53:48 -07:00
|
|
|
// TODO Need to correct the message `threadId` parameter value. Bug 859098
|
|
|
|
SmsMessageData message(aMessageId, 0, state,
|
2012-10-30 03:53:31 -07:00
|
|
|
static_cast<DeliveryStatus>(aDeliveryStatus),
|
|
|
|
nsJNIString(aSender, jenv), receiver,
|
2012-10-31 02:10:53 -07:00
|
|
|
nsJNIString(aBody, jenv), eMessageClass_Normal,
|
|
|
|
aTimestamp, true);
|
2011-12-22 14:16:59 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifyGotNextMessageRunnable(message, aRequestId);
|
2011-12-22 14:16:59 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:25:14 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2013-02-08 13:42:14 -08:00
|
|
|
Java_org_mozilla_gecko_GeckoSmsManager_notifyReadingMessageListFailed(JNIEnv* jenv, jclass,
|
|
|
|
jint aError,
|
|
|
|
jint aRequestId)
|
2011-12-22 14:25:14 -08:00
|
|
|
{
|
|
|
|
class NotifyReadListFailedRunnable : public nsRunnable {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
NotifyReadListFailedRunnable(int32_t aError,
|
2012-11-06 13:32:07 -08:00
|
|
|
int32_t aRequestId)
|
2011-12-22 14:25:14 -08:00
|
|
|
: mError(aError)
|
|
|
|
, mRequestId(aRequestId)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Run() {
|
2013-03-08 23:22:02 -08:00
|
|
|
nsCOMPtr<nsIMobileMessageCallback> request =
|
2012-11-06 13:32:07 -08:00
|
|
|
AndroidBridge::Bridge()->DequeueSmsRequest(mRequestId);
|
|
|
|
NS_ENSURE_TRUE(request, NS_ERROR_FAILURE);
|
2011-12-22 14:25:14 -08:00
|
|
|
|
2012-11-06 13:32:07 -08:00
|
|
|
request->NotifyReadMessageListFailed(mError);
|
2011-12-22 14:25:14 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mError;
|
|
|
|
int32_t mRequestId;
|
2011-12-22 14:25:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2012-11-06 13:32:07 -08:00
|
|
|
new NotifyReadListFailedRunnable(aError, aRequestId);
|
2011-12-22 14:25:14 -08:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2013-02-08 13:42:14 -08:00
|
|
|
#endif // MOZ_WEBSMS_BACKEND
|
|
|
|
|
2012-02-03 18:35:58 -08:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_scheduleComposite(JNIEnv*, jclass)
|
|
|
|
{
|
2012-03-13 21:15:11 -07:00
|
|
|
nsWindow::ScheduleComposite();
|
2012-02-03 18:35:58 -08:00
|
|
|
}
|
|
|
|
|
2012-02-05 10:33:38 -08:00
|
|
|
NS_EXPORT void JNICALL
|
2012-04-20 08:46:30 -07:00
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_scheduleResumeComposition(JNIEnv*, jclass, jint width, jint height)
|
2012-02-05 10:33:38 -08:00
|
|
|
{
|
2012-04-20 08:46:30 -07:00
|
|
|
nsWindow::ScheduleResumeComposition(width, height);
|
2012-02-05 10:33:38 -08:00
|
|
|
}
|
|
|
|
|
2012-10-25 09:23:47 -07:00
|
|
|
NS_EXPORT float JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_computeRenderIntegrity(JNIEnv*, jclass)
|
|
|
|
{
|
|
|
|
return nsWindow::ComputeRenderIntegrity();
|
|
|
|
}
|
|
|
|
|
2012-04-04 22:50:06 -07: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 13:04:47 -07: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 11:18:30 -07: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 13:04:47 -07:00
|
|
|
NS_EXPORT jobject JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_getSurfaceBits(JNIEnv* jenv, jclass, jobject surface)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
static jclass jSurfaceBitsClass = nullptr;
|
2012-04-27 13:04:47 -07:00
|
|
|
static jmethodID jSurfaceBitsCtor = 0;
|
|
|
|
static jfieldID jSurfaceBitsWidth, jSurfaceBitsHeight, jSurfaceBitsFormat, jSurfaceBitsBuffer;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
jobject surfaceBits = nullptr;
|
|
|
|
unsigned char* bitsCopy = nullptr;
|
2012-04-27 13:04:47 -07:00
|
|
|
int dstWidth, dstHeight, dstSize;
|
|
|
|
|
|
|
|
void* window = AndroidBridge::Bridge()->AcquireNativeWindow(jenv, surface);
|
|
|
|
if (!window)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-04-27 13:04:47 -07: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 11:18:30 -07:00
|
|
|
if (!LockWindowWithRetry(window, &bits, &srcWidth, &srcHeight, &format, &srcStride))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-05-07 11:18:30 -07:00
|
|
|
|
2012-04-27 13:04:47 -07: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 11:18:30 -07:00
|
|
|
if (!LockWindowWithRetry(window, &bits, &srcWidth, &srcHeight, &format, &srcStride))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-04-27 13:04:47 -07: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 09:10:49 -07: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();
|
|
|
|
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 13:04:47 -07:00
|
|
|
|
2012-05-31 20:24:07 -07:00
|
|
|
NS_EXPORT jobject JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_getNextMessageFromQueue(JNIEnv* jenv, jclass, jobject queue)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
static jclass jMessageQueueCls = nullptr;
|
2013-07-26 12:02:00 -07:00
|
|
|
static jfieldID jMessagesField;
|
2012-05-31 20:24:07 -07: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 12:02:00 -07:00
|
|
|
jMessagesField = jenv->GetFieldID(jMessageQueueCls, "mMessages", "Landroid/os/Message;");
|
2012-05-31 20:24:07 -07:00
|
|
|
}
|
2013-07-26 12:02:00 -07:00
|
|
|
|
2013-07-09 13:25:55 -07:00
|
|
|
if (!jMessageQueueCls || !jNextMethod)
|
2013-10-10 13:42:52 -07:00
|
|
|
return nullptr;
|
2013-07-26 12:02:00 -07: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 13:42:52 -07:00
|
|
|
return nullptr;
|
2013-07-26 12:02:00 -07:00
|
|
|
}
|
|
|
|
}
|
2013-07-09 13:25:55 -07:00
|
|
|
return jenv->CallObjectMethod(queue, jNextMethod);
|
2012-05-31 20:24:07 -07:00
|
|
|
}
|
|
|
|
|
2012-07-20 12:20:51 -07: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-11-27 03:52:05 -08:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_dispatchMemoryPressure(JNIEnv* jenv, jclass)
|
|
|
|
{
|
|
|
|
NS_DispatchMemoryPressure(MemPressure_New);
|
|
|
|
}
|
|
|
|
|
2013-04-23 10:10:29 -07:00
|
|
|
NS_EXPORT jdouble JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoJavaSampler_getProfilerTime(JNIEnv *jenv, jclass jc)
|
|
|
|
{
|
|
|
|
return profiler_time();
|
|
|
|
}
|
|
|
|
|
2013-07-23 13:41:22 -07:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_abortAnimation(JNIEnv* env, jobject instance)
|
|
|
|
{
|
2013-07-30 11:03:43 -07:00
|
|
|
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
|
2013-07-30 11:03:40 -07:00
|
|
|
if (controller) {
|
2013-11-08 16:07:00 -08:00
|
|
|
// TODO: Pass in correct values for presShellId and viewId.
|
|
|
|
controller->CancelAnimation(ScrollableLayerGuid(nsWindow::RootLayerTreeId(), 0, 0));
|
2013-07-30 11:03:40 -07:00
|
|
|
}
|
2013-07-23 13:41:22 -07:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:24:28 -07:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_init(JNIEnv* env, jobject instance)
|
|
|
|
{
|
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-12 10:41:01 -08:00
|
|
|
NativePanZoomController* oldRef = AndroidBridge::Bridge()->SetNativePanZoomController(instance);
|
|
|
|
if (oldRef && !oldRef->isNull()) {
|
2013-04-26 10:24:28 -07:00
|
|
|
MOZ_ASSERT(false, "Registering a new NPZC when we already have one");
|
2013-11-12 10:41:01 -08:00
|
|
|
delete oldRef;
|
2013-04-26 10:24:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleTouchEvent(JNIEnv* env, jobject instance, jobject event)
|
|
|
|
{
|
2013-07-30 11:03:43 -07:00
|
|
|
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
|
2013-04-26 10:24:28 -07: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 08:43:17 -08:00
|
|
|
controller->ReceiveInputEvent(input, nullptr);
|
2013-04-26 10:24:28 -07:00
|
|
|
}
|
|
|
|
}
|
2013-04-26 10:24:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_handleMotionEvent(JNIEnv* env, jobject instance, jobject event)
|
|
|
|
{
|
|
|
|
// FIXME implement this
|
|
|
|
}
|
|
|
|
|
2013-04-26 10:26:46 -07: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 10:24:28 -07:00
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_destroy(JNIEnv* env, jobject instance)
|
|
|
|
{
|
|
|
|
if (!AndroidBridge::Bridge()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-06 07:06:04 -08:00
|
|
|
NativePanZoomController* oldRef = AndroidBridge::Bridge()->SetNativePanZoomController(nullptr);
|
2013-11-12 10:41:01 -08:00
|
|
|
if (!oldRef || oldRef->isNull()) {
|
2013-04-26 10:24:28 -07:00
|
|
|
MOZ_ASSERT(false, "Clearing a non-existent NPZC");
|
|
|
|
} else {
|
2013-11-12 10:41:01 -08:00
|
|
|
delete oldRef;
|
2013-04-26 10:24:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_gfx_NativePanZoomController_notifyDefaultActionPrevented(JNIEnv* env, jobject instance, jboolean prevented)
|
|
|
|
{
|
2013-07-30 11:03:43 -07:00
|
|
|
APZCTreeManager *controller = nsWindow::GetAPZCTreeManager();
|
2013-04-26 10:24:28 -07:00
|
|
|
if (controller) {
|
2013-11-08 16:07:00 -08:00
|
|
|
// TODO: Pass in correct values for presShellId and viewId.
|
|
|
|
controller->ContentReceivedTouch(ScrollableLayerGuid(nsWindow::RootLayerTreeId(), 0, 0), prevented);
|
2013-04-26 10:24:28 -07:00
|
|
|
}
|
2013-04-26 10:24:28 -07: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-06-14 09:42:10 -07:00
|
|
|
NS_EXPORT jboolean JNICALL
|
2014-02-05 10:37:54 -08:00
|
|
|
Java_org_mozilla_gecko_ANRReporter_requestNativeStack(JNIEnv*, jclass, jboolean aUnwind)
|
2013-06-14 09:42:10 -07:00
|
|
|
{
|
2013-06-14 09:42:10 -07: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
|
2014-02-05 10:37:54 -08:00
|
|
|
const char *NATIVE_STACK_FEATURES[] =
|
|
|
|
{"leaf", "threads", "privacy"};
|
|
|
|
const char *NATIVE_STACK_UNWIND_FEATURES[] =
|
|
|
|
{"leaf", "threads", "privacy", "stackwalk"};
|
|
|
|
|
|
|
|
const char **features = NATIVE_STACK_FEATURES;
|
|
|
|
size_t features_size = sizeof(NATIVE_STACK_FEATURES);
|
|
|
|
if (aUnwind) {
|
|
|
|
features = NATIVE_STACK_UNWIND_FEATURES;
|
|
|
|
features_size = sizeof(NATIVE_STACK_UNWIND_FEATURES);
|
|
|
|
// We want the new unwinder if the unwind mode has not been set yet
|
|
|
|
putenv("MOZ_PROFILER_NEW=1");
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *NATIVE_STACK_THREADS[] =
|
|
|
|
{"GeckoMain", "Compositor"};
|
2013-06-14 09:42:10 -07:00
|
|
|
// Buffer one sample and let the profiler wait a long time
|
2014-02-05 10:37:54 -08:00
|
|
|
profiler_start(100, 10000, features, features_size / sizeof(char*),
|
|
|
|
NATIVE_STACK_THREADS, sizeof(NATIVE_STACK_THREADS) / sizeof(char*));
|
2013-06-14 09:42:10 -07:00
|
|
|
return JNI_TRUE;
|
2013-06-14 09:42:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT jstring JNICALL
|
|
|
|
Java_org_mozilla_gecko_ANRReporter_getNativeStack(JNIEnv* jenv, jclass)
|
|
|
|
{
|
2013-06-14 09:42:10 -07:00
|
|
|
if (!profiler_is_active()) {
|
|
|
|
// Maybe profiler support is disabled?
|
2013-10-10 13:42:52 -07:00
|
|
|
return nullptr;
|
2013-06-14 09:42:10 -07:00
|
|
|
}
|
|
|
|
char *profile = profiler_get_profile();
|
|
|
|
while (profile && !strlen(profile)) {
|
|
|
|
// no sample yet?
|
|
|
|
sched_yield();
|
|
|
|
profile = profiler_get_profile();
|
|
|
|
}
|
2013-10-10 13:42:52 -07:00
|
|
|
jstring result = nullptr;
|
2013-06-14 09:42:10 -07:00
|
|
|
if (profile) {
|
|
|
|
result = jenv->NewStringUTF(profile);
|
|
|
|
free(profile);
|
|
|
|
}
|
|
|
|
return result;
|
2013-06-14 09:42:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_EXPORT void JNICALL
|
|
|
|
Java_org_mozilla_gecko_ANRReporter_releaseNativeStack(JNIEnv* jenv, jclass)
|
|
|
|
{
|
2013-06-14 09:42:10 -07:00
|
|
|
if (!profiler_is_active()) {
|
|
|
|
// Maybe profiler support is disabled?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mozilla_sampler_stop();
|
2013-06-14 09:42:10 -07:00
|
|
|
}
|
|
|
|
|
2012-04-24 15:53:57 -07:00
|
|
|
}
|