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