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
|
|
|
|
|
|
|
#ifndef AndroidBridge_h__
|
|
|
|
#define AndroidBridge_h__
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <android/log.h>
|
2011-11-14 19:12:14 -08:00
|
|
|
#include <cstdlib>
|
2012-01-29 12:39:30 -08:00
|
|
|
#include <pthread.h>
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2011-09-16 14:34:31 -07:00
|
|
|
#include "nsCOMArray.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
#include "nsIRunnable.h"
|
2010-06-14 19:17:37 -07:00
|
|
|
#include "nsIObserver.h"
|
2012-01-29 12:39:30 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include "AndroidJavaWrappers.h"
|
|
|
|
|
2010-09-30 08:37:36 -07:00
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsIMIMEInfo.h"
|
2011-03-30 11:04:41 -07:00
|
|
|
#include "nsColor.h"
|
2012-01-31 06:40:58 -08:00
|
|
|
#include "gfxRect.h"
|
2010-06-14 12:04:16 -07:00
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
#include "nsIAndroidBridge.h"
|
2013-03-08 23:22:02 -08:00
|
|
|
#include "nsIMobileMessageCallback.h"
|
2011-11-14 19:12:14 -08:00
|
|
|
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2012-11-06 14:13:58 -08:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-04-26 10:24:28 -07:00
|
|
|
#include "mozilla/layers/GeckoContentController.h"
|
2013-04-26 10:26:46 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
// Some debug #defines
|
2011-08-29 11:29:39 -07:00
|
|
|
// #define DEBUG_ANDROID_EVENTS
|
|
|
|
// #define DEBUG_ANDROID_WIDGET
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
class nsWindow;
|
2012-01-13 05:25:47 -08:00
|
|
|
class nsIDOMMozSmsMessage;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
/* See the comment in AndroidBridge about this function before using it */
|
|
|
|
extern "C" JNIEnv * GetJNIForThread();
|
|
|
|
|
|
|
|
extern bool mozilla_AndroidBridge_SetMainThread(void *);
|
|
|
|
extern jclass GetGeckoAppShellClass();
|
|
|
|
|
2012-02-03 18:35:58 -08:00
|
|
|
namespace base {
|
|
|
|
class Thread;
|
|
|
|
} // end namespace base
|
|
|
|
|
2013-03-04 08:54:06 -08:00
|
|
|
typedef void* EGLSurface;
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
2011-11-02 08:35:11 -07:00
|
|
|
namespace hal {
|
|
|
|
class BatteryInformation;
|
2012-01-16 05:44:07 -08:00
|
|
|
class NetworkInformation;
|
2011-11-02 08:35:11 -07:00
|
|
|
} // namespace hal
|
|
|
|
|
2011-12-20 00:07:25 -08:00
|
|
|
namespace dom {
|
2013-03-01 00:38:47 -08:00
|
|
|
namespace mobilemessage {
|
2011-12-20 00:07:25 -08:00
|
|
|
struct SmsFilterData;
|
2013-01-03 22:26:27 -08:00
|
|
|
struct SmsSegmentInfoData;
|
2013-03-01 00:38:47 -08:00
|
|
|
} // namespace mobilemessage
|
2011-12-20 00:07:25 -08:00
|
|
|
} // namespace dom
|
|
|
|
|
2012-02-03 18:35:58 -08:00
|
|
|
namespace layers {
|
|
|
|
class CompositorParent;
|
|
|
|
} // namespace layers
|
|
|
|
|
2011-03-30 11:04:41 -07:00
|
|
|
// The order and number of the members in this structure must correspond
|
|
|
|
// to the attrsAppearance array in GeckoAppShell.getSystemColors()
|
|
|
|
typedef struct AndroidSystemColors {
|
|
|
|
nscolor textColorPrimary;
|
|
|
|
nscolor textColorPrimaryInverse;
|
|
|
|
nscolor textColorSecondary;
|
|
|
|
nscolor textColorSecondaryInverse;
|
|
|
|
nscolor textColorTertiary;
|
|
|
|
nscolor textColorTertiaryInverse;
|
|
|
|
nscolor textColorHighlight;
|
|
|
|
nscolor colorForeground;
|
|
|
|
nscolor colorBackground;
|
|
|
|
nscolor panelColorForeground;
|
|
|
|
nscolor panelColorBackground;
|
|
|
|
} AndroidSystemColors;
|
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
class nsFilePickerCallback : nsISupports {
|
|
|
|
public:
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-04-04 22:50:06 -07:00
|
|
|
virtual void handleResult(nsAString& filePath) = 0;
|
|
|
|
nsFilePickerCallback() {}
|
|
|
|
protected:
|
|
|
|
virtual ~nsFilePickerCallback() {}
|
|
|
|
};
|
|
|
|
|
2013-04-26 10:26:46 -07:00
|
|
|
class DelayedTask {
|
|
|
|
public:
|
|
|
|
DelayedTask(Task* aTask, int aDelayMs) {
|
|
|
|
mTask = aTask;
|
|
|
|
mRunTime = TimeStamp::Now() + TimeDuration::FromMilliseconds(aDelayMs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEarlierThan(DelayedTask *aOther) {
|
|
|
|
return mRunTime < aOther->mRunTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t MillisecondsToRunTime() {
|
|
|
|
TimeDuration timeLeft = mRunTime - TimeStamp::Now();
|
|
|
|
return (int64_t)timeLeft.ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
Task* GetTask() {
|
|
|
|
return mTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Task* mTask;
|
|
|
|
TimeStamp mRunTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-05-30 11:26:02 -07:00
|
|
|
class AndroidBridge MOZ_FINAL : public mozilla::layers::GeckoContentController
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-08-04 12:47:26 -07:00
|
|
|
enum {
|
2013-03-19 13:54:49 -07:00
|
|
|
// Values for NotifyIME, in addition to values from the Gecko
|
|
|
|
// NotificationToIME enum; use negative values here to prevent conflict
|
2013-08-14 08:32:44 -07:00
|
|
|
NOTIFY_IME_OPEN_VKB = -2,
|
2013-03-19 13:54:49 -07:00
|
|
|
NOTIFY_IME_REPLY_EVENT = -1,
|
2010-08-04 12:47:26 -07:00
|
|
|
};
|
|
|
|
|
2012-02-02 23:30:41 -08:00
|
|
|
enum {
|
|
|
|
LAYER_CLIENT_TYPE_NONE = 0,
|
|
|
|
LAYER_CLIENT_TYPE_GL = 2 // AndroidGeckoGLLayerClient
|
|
|
|
};
|
|
|
|
|
2012-07-31 14:34:06 -07:00
|
|
|
static void ConstructBridge(JNIEnv *jEnv, jclass jGeckoAppShellClass);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
static AndroidBridge *Bridge() {
|
2013-04-26 10:24:28 -07:00
|
|
|
return sBridge.get();
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
static JavaVM *GetVM() {
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(sBridge))
|
2012-01-29 12:39:30 -08:00
|
|
|
return sBridge->mJavaVM;
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
static JNIEnv *GetJNIEnv() {
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_LIKELY(sBridge)) {
|
2012-01-29 12:39:30 -08:00
|
|
|
if ((void*)pthread_self() != sBridge->mThread) {
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "AndroidBridge",
|
|
|
|
"###!!!!!!! Something's grabbing the JNIEnv from the wrong thread! (thr %p should be %p)",
|
|
|
|
(void*)pthread_self(), (void*)sBridge->mThread);
|
2013-04-18 16:58:20 -07:00
|
|
|
MOZ_ASSERT(false, "###!!!!!!! Something's grabbing the JNIEnv from the wrong thread!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-01-29 12:39:30 -08:00
|
|
|
}
|
|
|
|
return sBridge->mJNIEnv;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
2013-04-18 16:58:20 -07:00
|
|
|
|
2010-10-15 11:16:45 -07:00
|
|
|
static jclass GetGeckoAppShellClass() {
|
|
|
|
return sBridge->mGeckoAppShellClass;
|
|
|
|
}
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
// The bridge needs to be constructed via ConstructBridge first,
|
|
|
|
// and then once the Gecko main thread is spun up (Gecko side),
|
|
|
|
// SetMainThread should be called which will create the JNIEnv for
|
|
|
|
// us to use. toolkit/xre/nsAndroidStartup.cpp calls
|
|
|
|
// SetMainThread.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetMainThread(void *thr);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
/* These are all implemented in Java */
|
2013-03-19 13:54:49 -07:00
|
|
|
static void NotifyIME(int aType);
|
2010-08-04 12:47:26 -07:00
|
|
|
|
2013-03-19 13:54:48 -07:00
|
|
|
static void NotifyIMEContext(int aState, const nsAString& aTypeHint,
|
2012-08-26 19:16:22 -07:00
|
|
|
const nsAString& aModeHint, const nsAString& aActionHint);
|
2010-11-22 22:48:25 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static void NotifyIMEChange(const PRUnichar *aText, uint32_t aTextLen, int aStart, int aEnd, int aNewEnd);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2013-04-23 10:10:29 -07:00
|
|
|
void StartJavaProfiling(int aInterval, int aSamples);
|
|
|
|
void StopJavaProfiling();
|
|
|
|
void PauseJavaProfiling();
|
|
|
|
void UnpauseJavaProfiling();
|
|
|
|
bool GetThreadNameJavaProfiling(uint32_t aThreadId, nsCString & aResult);
|
|
|
|
bool GetFrameNameJavaProfiling(uint32_t aThreadId, uint32_t aSampleId, uint32_t aFrameId, nsCString & aResult);
|
|
|
|
double GetSampleTimeJavaProfiling(uint32_t aThreadId, uint32_t aSampleId);
|
|
|
|
|
2012-12-15 07:43:52 -08:00
|
|
|
nsresult CaptureThumbnail(nsIDOMWindow *window, int32_t bufW, int32_t bufH, int32_t tabId, jobject buffer);
|
2013-01-23 09:18:05 -08:00
|
|
|
void SendThumbnail(jobject buffer, int32_t tabId, bool success);
|
2013-05-30 06:55:08 -07:00
|
|
|
void GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort);
|
2013-05-30 06:55:23 -07:00
|
|
|
void ContentDocumentChanged();
|
|
|
|
bool IsContentDocumentDisplayed();
|
2012-04-24 12:13:36 -07:00
|
|
|
|
2013-06-10 06:05:42 -07:00
|
|
|
bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const LayerRect& aDisplayPort, float aDisplayResolution, bool aDrawingCritical, gfx::Rect& aViewport, float& aScaleX, float& aScaleY);
|
2012-10-04 11:45:16 -07:00
|
|
|
|
2013-03-10 15:43:30 -07:00
|
|
|
void AcknowledgeEvent();
|
2011-03-02 09:23:02 -08:00
|
|
|
|
2010-06-04 14:14:43 -07:00
|
|
|
void EnableLocation(bool aEnable);
|
2012-03-21 10:52:35 -07:00
|
|
|
void EnableLocationHighAccuracy(bool aEnable);
|
2010-06-04 14:14:43 -07:00
|
|
|
|
2012-02-05 11:51:05 -08:00
|
|
|
void EnableSensor(int aSensorType);
|
|
|
|
|
|
|
|
void DisableSensor(int aSensorType);
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void NotifyXreExit();
|
|
|
|
|
|
|
|
void ScheduleRestart();
|
|
|
|
|
2012-07-13 07:19:46 -07:00
|
|
|
void SetLayerClient(JNIEnv* env, jobject jobj);
|
2012-02-02 23:30:41 -08:00
|
|
|
AndroidGeckoLayerClient &GetLayerClient() { return *mLayerClient; }
|
2011-11-14 19:12:14 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool GetHandlersForURL(const char *aURL,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIMutableArray* handlersArray = nullptr,
|
|
|
|
nsIHandlerApp **aDefaultApp = nullptr,
|
2010-11-23 15:40:46 -08:00
|
|
|
const nsAString& aAction = EmptyString());
|
2010-06-14 12:04:16 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool GetHandlersForMimeType(const char *aMimeType,
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIMutableArray* handlersArray = nullptr,
|
|
|
|
nsIHandlerApp **aDefaultApp = nullptr,
|
2010-09-30 08:37:36 -07:00
|
|
|
const nsAString& aAction = EmptyString());
|
2010-06-29 19:22:08 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool OpenUriExternal(const nsACString& aUriSpec, const nsACString& aMimeType,
|
2010-10-01 18:04:23 -07:00
|
|
|
const nsAString& aPackageName = EmptyString(),
|
2010-09-30 08:37:36 -07:00
|
|
|
const nsAString& aClassName = EmptyString(),
|
2010-10-01 18:04:23 -07:00
|
|
|
const nsAString& aAction = EmptyString(),
|
|
|
|
const nsAString& aTitle = EmptyString());
|
2010-06-14 12:04:16 -07:00
|
|
|
|
2010-11-05 10:43:12 -07:00
|
|
|
void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType);
|
2011-09-15 00:40:17 -07:00
|
|
|
void GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt);
|
2010-06-14 12:04:16 -07:00
|
|
|
|
2010-06-16 10:20:54 -07:00
|
|
|
void MoveTaskToBack();
|
|
|
|
|
2010-08-26 16:43:23 -07:00
|
|
|
bool GetClipboardText(nsAString& aText);
|
|
|
|
|
|
|
|
void SetClipboardText(const nsAString& aText);
|
|
|
|
|
|
|
|
void EmptyClipboard();
|
|
|
|
|
|
|
|
bool ClipboardHasText();
|
|
|
|
|
2010-06-14 19:17:37 -07:00
|
|
|
void ShowAlertNotification(const nsAString& aImageUrl,
|
|
|
|
const nsAString& aAlertTitle,
|
|
|
|
const nsAString& aAlertText,
|
|
|
|
const nsAString& aAlertData,
|
|
|
|
nsIObserver *aAlertListener,
|
|
|
|
const nsAString& aAlertName);
|
|
|
|
|
2010-10-01 14:21:21 -07:00
|
|
|
void AlertsProgressListener_OnProgress(const nsAString& aAlertName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aProgress,
|
|
|
|
int64_t aProgressMax,
|
2010-10-01 14:21:21 -07:00
|
|
|
const nsAString& aAlertText);
|
|
|
|
|
2013-03-18 06:24:53 -07:00
|
|
|
void CloseNotification(const nsAString& aAlertName);
|
2010-10-12 19:17:12 -07:00
|
|
|
|
2010-10-07 10:28:27 -07:00
|
|
|
int GetDPI();
|
2013-07-04 06:53:25 -07:00
|
|
|
int GetScreenDepth();
|
2010-10-07 10:28:27 -07:00
|
|
|
|
2012-03-18 09:15:56 -07:00
|
|
|
void ShowFilePickerForExtensions(nsAString& aFilePath, const nsAString& aExtensions);
|
|
|
|
void ShowFilePickerForMimeType(nsAString& aFilePath, const nsAString& aMimeType);
|
2012-04-04 22:50:06 -07:00
|
|
|
void ShowFilePickerAsync(const nsAString& aMimeType, nsFilePickerCallback* callback);
|
2010-09-30 08:37:36 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void PerformHapticFeedback(bool aIsLongPress);
|
2010-11-22 08:38:02 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void Vibrate(const nsTArray<uint32_t>& aPattern);
|
2011-09-30 00:00:48 -07:00
|
|
|
void CancelVibrate();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetFullScreen(bool aFullScreen);
|
2010-11-08 18:11:13 -08:00
|
|
|
|
2010-11-10 06:40:00 -08:00
|
|
|
void ShowInputMethodPicker();
|
|
|
|
|
2012-04-07 00:09:26 -07:00
|
|
|
void NotifyDefaultPrevented(bool aDefaultPrevented);
|
2012-01-24 16:31:33 -08:00
|
|
|
|
2010-11-12 12:02:14 -08:00
|
|
|
void HideProgressDialogOnce();
|
|
|
|
|
2011-01-20 03:06:13 -08:00
|
|
|
bool IsNetworkLinkUp();
|
|
|
|
|
|
|
|
bool IsNetworkLinkKnown();
|
|
|
|
|
2011-03-16 16:17:59 -07:00
|
|
|
void SetSelectedLocale(const nsAString&);
|
2011-02-27 07:50:56 -08:00
|
|
|
|
2011-03-30 11:04:41 -07:00
|
|
|
void GetSystemColors(AndroidSystemColors *aColors);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void GetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t * const aBuf);
|
2011-06-13 14:02:13 -07:00
|
|
|
|
2011-07-26 18:14:52 -07:00
|
|
|
bool GetShowPasswordSetting();
|
|
|
|
|
2012-01-26 11:23:13 -08:00
|
|
|
// Switch Java to composite with the Gecko Compositor thread
|
2013-02-28 10:28:23 -08:00
|
|
|
void RegisterCompositor(JNIEnv* env = NULL);
|
2013-02-28 10:28:23 -08:00
|
|
|
EGLSurface ProvideEGLSurface();
|
2012-01-26 11:23:13 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
bool GetStaticStringField(const char *classID, const char *field, nsAString &result, JNIEnv* env = nullptr);
|
2010-09-11 06:20:20 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool GetStaticIntField(const char *className, const char *fieldName, int32_t* aInt, JNIEnv* env = nullptr);
|
2011-02-28 08:32:05 -08:00
|
|
|
|
2010-12-21 14:34:29 -08:00
|
|
|
void SetKeepScreenOn(bool on);
|
|
|
|
|
2011-04-08 10:52:13 -07:00
|
|
|
void ScanMedia(const nsAString& aFile, const nsACString& aMimeType);
|
|
|
|
|
2011-08-08 19:37:57 -07:00
|
|
|
void CreateShortcut(const nsAString& aTitle, const nsAString& aURI, const nsAString& aIconData, const nsAString& aIntent);
|
|
|
|
|
2011-06-16 02:03:00 -07:00
|
|
|
// These next four functions are for native Bitmap access in Android 2.2+
|
|
|
|
bool HasNativeBitmapAccess();
|
|
|
|
|
|
|
|
bool ValidateBitmap(jobject bitmap, int width, int height);
|
|
|
|
|
|
|
|
void *LockBitmap(jobject bitmap);
|
|
|
|
|
2013-02-09 13:38:08 -08:00
|
|
|
// Returns a global reference to the Context for Fennec's Activity. The
|
|
|
|
// caller is responsible for ensuring this doesn't leak by calling
|
|
|
|
// DeleteGlobalRef() when the context is no longer needed.
|
|
|
|
jobject GetGlobalContextRef(void);
|
|
|
|
|
2013-05-28 09:49:04 -07:00
|
|
|
// Returns a local reference. Caller must manage this reference
|
|
|
|
jobject GetContext(void);
|
|
|
|
|
2011-06-16 02:03:00 -07:00
|
|
|
void UnlockBitmap(jobject bitmap);
|
|
|
|
|
2012-10-05 12:35:26 -07:00
|
|
|
bool UnlockProfile();
|
|
|
|
|
|
|
|
void KillAnyZombies();
|
|
|
|
|
2011-09-21 09:46:00 -07:00
|
|
|
/* Copied from Android's native_window.h in newer (platform 9) NDK */
|
|
|
|
enum {
|
|
|
|
WINDOW_FORMAT_RGBA_8888 = 1,
|
|
|
|
WINDOW_FORMAT_RGBX_8888 = 2,
|
2012-05-08 17:00:12 -07:00
|
|
|
WINDOW_FORMAT_RGB_565 = 4
|
2011-09-21 09:46:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
bool HasNativeWindowAccess();
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
void *AcquireNativeWindow(JNIEnv* aEnv, jobject aSurface);
|
2011-09-21 09:46:00 -07:00
|
|
|
void ReleaseNativeWindow(void *window);
|
2012-07-20 12:20:51 -07:00
|
|
|
|
|
|
|
void *AcquireNativeWindowFromSurfaceTexture(JNIEnv* aEnv, jobject aSurface);
|
|
|
|
void ReleaseNativeWindowForSurfaceTexture(void *window);
|
|
|
|
|
2011-09-21 09:46:00 -07:00
|
|
|
bool LockWindow(void *window, unsigned char **bits, int *width, int *height, int *format, int *stride);
|
|
|
|
bool UnlockWindow(void *window);
|
2011-11-14 19:12:14 -08:00
|
|
|
|
|
|
|
void HandleGeckoMessage(const nsAString& message, nsAString &aRet);
|
|
|
|
|
|
|
|
void CheckURIVisited(const nsAString& uri);
|
|
|
|
void MarkURIVisited(const nsAString& uri);
|
2013-02-18 09:27:30 -08:00
|
|
|
void SetURITitle(const nsAString& uri, const nsAString& title);
|
2011-09-21 09:46:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
bool InitCamera(const nsCString& contentType, uint32_t camera, uint32_t *width, uint32_t *height, uint32_t *fps);
|
2011-09-26 17:25:41 -07:00
|
|
|
|
|
|
|
void CloseCamera();
|
|
|
|
|
2011-11-02 08:35:11 -07:00
|
|
|
void EnableBatteryNotifications();
|
|
|
|
void DisableBatteryNotifications();
|
|
|
|
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
|
|
|
|
|
2013-03-08 23:22:02 -08:00
|
|
|
nsresult GetSegmentInfoForText(const nsAString& aText,
|
|
|
|
dom::mobilemessage::SmsSegmentInfoData* aData);
|
|
|
|
void SendMessage(const nsAString& aNumber, const nsAString& aText,
|
|
|
|
nsIMobileMessageCallback* aRequest);
|
|
|
|
void GetMessage(int32_t aMessageId, nsIMobileMessageCallback* aRequest);
|
|
|
|
void DeleteMessage(int32_t aMessageId, nsIMobileMessageCallback* aRequest);
|
|
|
|
void CreateMessageList(const dom::mobilemessage::SmsFilterData& aFilter,
|
|
|
|
bool aReverse, nsIMobileMessageCallback* aRequest);
|
|
|
|
void GetNextMessageInList(int32_t aListId, nsIMobileMessageCallback* aRequest);
|
2012-08-22 08:56:38 -07:00
|
|
|
void ClearMessageList(int32_t aListId);
|
2013-03-08 23:22:02 -08:00
|
|
|
already_AddRefed<nsIMobileMessageCallback> DequeueSmsRequest(uint32_t aRequestId);
|
2011-11-25 01:48:51 -08:00
|
|
|
|
2011-12-14 13:53:38 -08:00
|
|
|
bool IsTablet();
|
|
|
|
|
2012-01-16 05:44:07 -08:00
|
|
|
void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
|
2012-01-16 06:01:07 -08:00
|
|
|
void EnableNetworkNotifications();
|
|
|
|
void DisableNetworkNotifications();
|
2012-01-16 05:44:07 -08:00
|
|
|
|
2013-06-21 14:03:56 -07:00
|
|
|
void SetFirstPaintViewport(const LayerIntPoint& aOffset, const CSSToLayerScale& aZoom, const CSSRect& aCssPageRect);
|
2013-06-03 06:52:44 -07:00
|
|
|
void SetPageRect(const CSSRect& aCssPageRect);
|
2013-06-21 14:03:56 -07:00
|
|
|
void SyncViewportInfo(const LayerIntRect& aDisplayPort, const CSSToLayerScale& aDisplayResolution,
|
|
|
|
bool aLayersUpdated, ScreenPoint& aScrollOffset, CSSToScreenScale& aScale,
|
2013-07-22 01:50:13 -07:00
|
|
|
LayerMargin& aFixedLayerMargins, ScreenPoint& aOffset);
|
2013-06-14 13:11:29 -07:00
|
|
|
void SyncFrameMetrics(const ScreenPoint& aScrollOffset, float aZoom, const CSSRect& aCssPageRect,
|
2013-06-21 14:03:56 -07:00
|
|
|
bool aLayersUpdated, const CSSRect& aDisplayPort, const CSSToLayerScale& aDisplayResolution,
|
2013-07-22 01:50:13 -07:00
|
|
|
bool aIsFirstPaint, LayerMargin& aFixedLayerMargins, ScreenPoint& aOffset);
|
2012-02-03 18:35:58 -08:00
|
|
|
|
2013-08-13 08:49:21 -07:00
|
|
|
void AddPluginView(jobject view, const LayoutDeviceRect& rect, bool isFullScreen);
|
2012-05-30 09:10:49 -07:00
|
|
|
void RemovePluginView(jobject view, bool isFullScreen);
|
2012-04-27 13:04:47 -07:00
|
|
|
|
2012-05-08 14:36:07 -07:00
|
|
|
// These methods don't use a ScreenOrientation because it's an
|
|
|
|
// enum and that would require including the header which requires
|
|
|
|
// include IPC headers which requires including basictypes.h which
|
|
|
|
// requires a lot of changes...
|
2012-05-08 14:36:07 -07:00
|
|
|
uint32_t GetScreenOrientation();
|
2012-03-20 06:09:45 -07:00
|
|
|
void EnableScreenOrientationNotifications();
|
|
|
|
void DisableScreenOrientationNotifications();
|
2012-05-08 14:36:07 -07:00
|
|
|
void LockScreenOrientation(uint32_t aOrientation);
|
2012-03-29 23:31:12 -07:00
|
|
|
void UnlockScreenOrientation();
|
2012-03-20 06:09:45 -07:00
|
|
|
|
2012-06-04 22:14:12 -07:00
|
|
|
bool PumpMessageLoop();
|
2012-05-03 07:53:31 -07:00
|
|
|
|
2012-06-06 19:39:01 -07:00
|
|
|
void NotifyWakeLockChanged(const nsAString& topic, const nsAString& state);
|
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
int GetAPIVersion() { return mAPIVersion; }
|
|
|
|
bool IsHoneycomb() { return mAPIVersion >= 11 && mAPIVersion <= 13; }
|
|
|
|
|
|
|
|
void ScheduleComposite();
|
|
|
|
void RegisterSurfaceTextureFrameListener(jobject surfaceTexture, int id);
|
|
|
|
void UnregisterSurfaceTextureFrameListener(jobject surfaceTexture);
|
|
|
|
|
2013-04-23 10:10:29 -07:00
|
|
|
jclass jGeckoJavaSamplerClass;
|
|
|
|
jmethodID jStart;
|
|
|
|
jmethodID jStop;
|
|
|
|
jmethodID jPause;
|
|
|
|
jmethodID jUnpause;
|
|
|
|
jmethodID jGetThreadName;
|
|
|
|
jmethodID jGetFrameName;
|
|
|
|
jmethodID jGetSampleTime;
|
|
|
|
|
2012-07-05 07:12:10 -07:00
|
|
|
void GetGfxInfoData(nsACString& aRet);
|
2012-11-13 11:25:18 -08:00
|
|
|
nsresult GetProxyForURI(const nsACString & aSpec,
|
|
|
|
const nsACString & aScheme,
|
|
|
|
const nsACString & aHost,
|
|
|
|
const int32_t aPort,
|
|
|
|
nsACString & aResult);
|
2010-06-03 13:56:36 -07:00
|
|
|
protected:
|
2013-08-12 07:58:36 -07:00
|
|
|
static StaticRefPtr<AndroidBridge> sBridge;
|
2013-04-08 07:29:34 -07:00
|
|
|
nsTArray<nsCOMPtr<nsIMobileMessageCallback> > mSmsRequests;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
// the global JavaVM
|
|
|
|
JavaVM *mJavaVM;
|
|
|
|
|
|
|
|
// the JNIEnv for the main thread
|
|
|
|
JNIEnv *mJNIEnv;
|
|
|
|
void *mThread;
|
|
|
|
|
2012-02-02 23:30:41 -08:00
|
|
|
AndroidGeckoLayerClient *mLayerClient;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
// the GeckoAppShell java class
|
|
|
|
jclass mGeckoAppShellClass;
|
2013-01-03 22:26:27 -08:00
|
|
|
// the android.telephony.SmsMessage class
|
|
|
|
jclass mAndroidSmsMessageClass;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-02-03 18:35:58 -08:00
|
|
|
AndroidBridge();
|
|
|
|
~AndroidBridge();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Init(JNIEnv *jEnv, jclass jGeckoApp);
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-09-21 09:46:00 -07:00
|
|
|
bool mOpenedGraphicsLibraries;
|
|
|
|
void OpenGraphicsLibraries();
|
2012-04-27 13:04:47 -07:00
|
|
|
void* GetNativeSurface(JNIEnv* env, jobject surface);
|
2011-09-21 09:46:00 -07:00
|
|
|
|
2011-06-16 02:03:00 -07:00
|
|
|
bool mHasNativeBitmapAccess;
|
2011-09-21 09:46:00 -07:00
|
|
|
bool mHasNativeWindowAccess;
|
2012-04-27 13:04:47 -07:00
|
|
|
bool mHasNativeWindowFallback;
|
2011-06-16 02:03:00 -07:00
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
int mAPIVersion;
|
|
|
|
|
2013-03-08 23:22:02 -08:00
|
|
|
bool QueueSmsRequest(nsIMobileMessageCallback* aRequest, uint32_t* aRequestIdOut);
|
2012-11-06 13:32:07 -08:00
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
// other things
|
2010-08-04 12:47:26 -07:00
|
|
|
jmethodID jNotifyIME;
|
2013-03-19 13:54:48 -07:00
|
|
|
jmethodID jNotifyIMEContext;
|
2010-08-04 12:47:26 -07:00
|
|
|
jmethodID jNotifyIMEChange;
|
2013-03-10 15:43:30 -07:00
|
|
|
jmethodID jAcknowledgeEvent;
|
2010-06-04 14:14:43 -07:00
|
|
|
jmethodID jEnableLocation;
|
2012-03-21 10:52:35 -07:00
|
|
|
jmethodID jEnableLocationHighAccuracy;
|
2012-02-05 11:51:05 -08:00
|
|
|
jmethodID jEnableSensor;
|
|
|
|
jmethodID jDisableSensor;
|
2010-10-25 20:10:07 -07:00
|
|
|
jmethodID jNotifyAppShellReady;
|
2010-06-03 13:56:36 -07:00
|
|
|
jmethodID jNotifyXreExit;
|
|
|
|
jmethodID jScheduleRestart;
|
|
|
|
jmethodID jGetOutstandingDrawEvents;
|
2010-06-14 12:04:16 -07:00
|
|
|
jmethodID jGetHandlersForMimeType;
|
2010-11-23 15:40:46 -08:00
|
|
|
jmethodID jGetHandlersForURL;
|
2010-06-14 12:04:16 -07:00
|
|
|
jmethodID jOpenUriExternal;
|
2010-11-05 10:43:12 -07:00
|
|
|
jmethodID jGetMimeTypeFromExtensions;
|
2011-03-07 21:45:43 -08:00
|
|
|
jmethodID jGetExtensionFromMimeType;
|
2010-06-16 10:20:54 -07:00
|
|
|
jmethodID jMoveTaskToBack;
|
2010-06-14 19:17:37 -07:00
|
|
|
jmethodID jShowAlertNotification;
|
2012-03-18 09:15:56 -07:00
|
|
|
jmethodID jShowFilePickerForExtensions;
|
|
|
|
jmethodID jShowFilePickerForMimeType;
|
2012-04-04 22:50:06 -07:00
|
|
|
jmethodID jShowFilePickerAsync;
|
2012-10-05 12:35:26 -07:00
|
|
|
jmethodID jUnlockProfile;
|
|
|
|
jmethodID jKillAnyZombies;
|
2010-10-01 14:21:21 -07:00
|
|
|
jmethodID jAlertsProgressListener_OnProgress;
|
2013-03-18 06:24:53 -07:00
|
|
|
jmethodID jCloseNotification;
|
2010-10-07 10:28:27 -07:00
|
|
|
jmethodID jGetDpi;
|
2013-07-04 06:53:25 -07:00
|
|
|
jmethodID jGetScreenDepth;
|
2010-11-08 18:11:13 -08:00
|
|
|
jmethodID jSetFullScreen;
|
2010-11-10 06:40:00 -08:00
|
|
|
jmethodID jShowInputMethodPicker;
|
2012-04-07 00:09:26 -07:00
|
|
|
jmethodID jNotifyDefaultPrevented;
|
2010-11-12 12:02:14 -08:00
|
|
|
jmethodID jHideProgressDialog;
|
2010-11-22 08:38:02 -08:00
|
|
|
jmethodID jPerformHapticFeedback;
|
2011-09-30 00:00:48 -07:00
|
|
|
jmethodID jVibrate1;
|
|
|
|
jmethodID jVibrateA;
|
|
|
|
jmethodID jCancelVibrate;
|
2010-12-21 14:34:29 -08:00
|
|
|
jmethodID jSetKeepScreenOn;
|
2011-01-20 03:06:13 -08:00
|
|
|
jmethodID jIsNetworkLinkUp;
|
|
|
|
jmethodID jIsNetworkLinkKnown;
|
2011-02-27 07:50:56 -08:00
|
|
|
jmethodID jSetSelectedLocale;
|
2011-04-08 10:52:13 -07:00
|
|
|
jmethodID jScanMedia;
|
2011-03-30 11:04:41 -07:00
|
|
|
jmethodID jGetSystemColors;
|
2011-06-13 14:02:13 -07:00
|
|
|
jmethodID jGetIconForExtension;
|
2011-08-08 19:37:57 -07:00
|
|
|
jmethodID jCreateShortcut;
|
2011-07-26 18:14:52 -07:00
|
|
|
jmethodID jGetShowPasswordSetting;
|
2011-09-16 14:34:31 -07:00
|
|
|
jmethodID jPostToJavaThread;
|
2011-09-26 17:25:41 -07:00
|
|
|
jmethodID jInitCamera;
|
|
|
|
jmethodID jCloseCamera;
|
2011-12-14 13:53:38 -08:00
|
|
|
jmethodID jIsTablet;
|
2011-11-02 08:35:11 -07:00
|
|
|
jmethodID jEnableBatteryNotifications;
|
|
|
|
jmethodID jDisableBatteryNotifications;
|
|
|
|
jmethodID jGetCurrentBatteryInformation;
|
2011-11-14 19:12:14 -08:00
|
|
|
jmethodID jHandleGeckoMessage;
|
|
|
|
jmethodID jCheckUriVisited;
|
|
|
|
jmethodID jMarkUriVisited;
|
2013-02-18 09:27:30 -08:00
|
|
|
jmethodID jSetUriTitle;
|
2012-04-27 13:04:47 -07:00
|
|
|
jmethodID jAddPluginView;
|
2012-03-26 22:31:57 -07:00
|
|
|
jmethodID jRemovePluginView;
|
2012-04-27 13:04:47 -07:00
|
|
|
jmethodID jCreateSurface;
|
|
|
|
jmethodID jShowSurface;
|
|
|
|
jmethodID jHideSurface;
|
|
|
|
jmethodID jDestroySurface;
|
2012-11-13 11:25:18 -08:00
|
|
|
jmethodID jGetProxyForURI;
|
2012-04-27 13:04:47 -07:00
|
|
|
|
2013-01-03 22:26:27 -08:00
|
|
|
jmethodID jCalculateLength;
|
2011-11-20 15:00:46 -08:00
|
|
|
jmethodID jSendMessage;
|
2011-12-22 14:08:58 -08:00
|
|
|
jmethodID jGetMessage;
|
2011-12-22 14:15:28 -08:00
|
|
|
jmethodID jDeleteMessage;
|
2011-12-20 00:07:25 -08:00
|
|
|
jmethodID jCreateMessageList;
|
2011-12-22 14:16:59 -08:00
|
|
|
jmethodID jGetNextMessageinList;
|
2012-01-17 10:43:08 -08:00
|
|
|
jmethodID jClearMessageList;
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2012-01-16 05:44:07 -08:00
|
|
|
jmethodID jGetCurrentNetworkInformation;
|
2012-01-16 06:01:07 -08:00
|
|
|
jmethodID jEnableNetworkNotifications;
|
|
|
|
jmethodID jDisableNetworkNotifications;
|
2012-01-16 05:44:07 -08:00
|
|
|
|
2012-03-20 06:09:45 -07:00
|
|
|
jmethodID jGetScreenOrientation;
|
|
|
|
jmethodID jEnableScreenOrientationNotifications;
|
|
|
|
jmethodID jDisableScreenOrientationNotifications;
|
2012-03-29 23:31:12 -07:00
|
|
|
jmethodID jLockScreenOrientation;
|
|
|
|
jmethodID jUnlockScreenOrientation;
|
2012-05-03 07:53:31 -07:00
|
|
|
jmethodID jPumpMessageLoop;
|
2012-06-06 19:39:01 -07:00
|
|
|
jmethodID jNotifyWakeLockChanged;
|
2012-07-20 12:20:51 -07:00
|
|
|
jmethodID jRegisterSurfaceTextureFrameListener;
|
|
|
|
jmethodID jUnregisterSurfaceTextureFrameListener;
|
2012-03-20 06:09:45 -07:00
|
|
|
|
2012-12-15 07:43:52 -08:00
|
|
|
jclass jThumbnailHelperClass;
|
|
|
|
jmethodID jNotifyThumbnail;
|
2012-09-19 14:15:55 -07:00
|
|
|
|
2013-02-09 13:38:08 -08:00
|
|
|
jmethodID jGetContext;
|
|
|
|
|
2012-07-05 07:12:10 -07:00
|
|
|
// for GfxInfo (gfx feature detection and blacklisting)
|
|
|
|
jmethodID jGetGfxInfoData;
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
// For native surface stuff
|
|
|
|
jclass jSurfaceClass;
|
|
|
|
jfieldID jSurfacePointerField;
|
|
|
|
|
2012-04-05 08:28:50 -07:00
|
|
|
jclass jLayerView;
|
2013-02-28 10:28:24 -08:00
|
|
|
jmethodID jProvideEGLSurfaceMethod;
|
|
|
|
jfieldID jEGLSurfacePointerField;
|
|
|
|
jobject mGLControllerObj;
|
2012-02-02 19:28:22 -08:00
|
|
|
|
2013-04-26 10:26:46 -07:00
|
|
|
jmethodID jRequestContentRepaint;
|
2013-04-26 10:26:46 -07:00
|
|
|
jmethodID jPostDelayedCallback;
|
2013-04-26 10:26:46 -07:00
|
|
|
|
2013-06-07 13:39:37 -07:00
|
|
|
jclass jClipboardClass;
|
|
|
|
jmethodID jClipboardGetText;
|
|
|
|
jmethodID jClipboardSetText;
|
|
|
|
|
2012-03-07 16:24:38 -08:00
|
|
|
// some convinient types to have around
|
|
|
|
jclass jStringClass;
|
|
|
|
|
2011-06-16 02:03:00 -07:00
|
|
|
// calls we've dlopened from libjnigraphics.so
|
|
|
|
int (* AndroidBitmap_getInfo)(JNIEnv *env, jobject bitmap, void *info);
|
|
|
|
int (* AndroidBitmap_lockPixels)(JNIEnv *env, jobject bitmap, void **buffer);
|
|
|
|
int (* AndroidBitmap_unlockPixels)(JNIEnv *env, jobject bitmap);
|
2011-09-21 09:46:00 -07:00
|
|
|
|
|
|
|
void* (*ANativeWindow_fromSurface)(JNIEnv *env, jobject surface);
|
2012-07-20 12:20:51 -07:00
|
|
|
void* (*ANativeWindow_fromSurfaceTexture)(JNIEnv *env, jobject surfaceTexture);
|
2011-09-21 09:46:00 -07:00
|
|
|
void (*ANativeWindow_release)(void *window);
|
|
|
|
int (*ANativeWindow_setBuffersGeometry)(void *window, int width, int height, int format);
|
|
|
|
|
|
|
|
int (* ANativeWindow_lock)(void *window, void *outBuffer, void *inOutDirtyBounds);
|
|
|
|
int (* ANativeWindow_unlockAndPost)(void *window);
|
2012-04-27 13:04:47 -07:00
|
|
|
|
|
|
|
int (* Surface_lock)(void* surface, void* surfaceInfo, void* region, bool block);
|
|
|
|
int (* Surface_unlockAndPost)(void* surface);
|
|
|
|
void (* Region_constructor)(void* region);
|
|
|
|
void (* Region_set)(void* region, void* rect);
|
2013-04-26 10:24:28 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
jobject mNativePanZoomController;
|
2013-04-26 10:26:46 -07:00
|
|
|
// This will always be accessed from one thread (the APZC "controller"
|
|
|
|
// thread, which is the Java UI thread), so we don't need to do locking
|
|
|
|
// to touch it
|
|
|
|
nsTArray<DelayedTask*> mDelayedTaskQueue;
|
|
|
|
|
2013-04-26 10:24:28 -07:00
|
|
|
public:
|
|
|
|
jobject SetNativePanZoomController(jobject obj);
|
|
|
|
// GeckoContentController methods
|
|
|
|
void RequestContentRepaint(const mozilla::layers::FrameMetrics& aFrameMetrics) MOZ_OVERRIDE;
|
2013-06-10 06:05:44 -07:00
|
|
|
void HandleDoubleTap(const CSSIntPoint& aPoint) MOZ_OVERRIDE;
|
|
|
|
void HandleSingleTap(const CSSIntPoint& aPoint) MOZ_OVERRIDE;
|
|
|
|
void HandleLongTap(const CSSIntPoint& aPoint) MOZ_OVERRIDE;
|
2013-07-30 11:03:42 -07:00
|
|
|
void SendAsyncScrollDOMEvent(mozilla::layers::FrameMetrics::ViewID aScrollId,
|
|
|
|
const CSSRect& aContentRect,
|
|
|
|
const CSSSize& aScrollableSize) MOZ_OVERRIDE;
|
2013-04-26 10:26:46 -07:00
|
|
|
void PostDelayedTask(Task* aTask, int aDelayMs) MOZ_OVERRIDE;
|
|
|
|
int64_t RunDelayedTasks();
|
2010-06-03 13:56:36 -07:00
|
|
|
};
|
|
|
|
|
2012-11-16 12:13:57 -08:00
|
|
|
class AutoJObject {
|
|
|
|
public:
|
|
|
|
AutoJObject(JNIEnv* aJNIEnv = NULL) : mObject(NULL)
|
|
|
|
{
|
|
|
|
mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv();
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoJObject(JNIEnv* aJNIEnv, jobject aObject)
|
|
|
|
{
|
|
|
|
mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv();
|
|
|
|
mObject = aObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoJObject() {
|
|
|
|
if (mObject)
|
|
|
|
mJNIEnv->DeleteLocalRef(mObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject operator=(jobject aObject)
|
|
|
|
{
|
|
|
|
if (mObject) {
|
|
|
|
mJNIEnv->DeleteLocalRef(mObject);
|
|
|
|
}
|
|
|
|
return mObject = aObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator jobject() {
|
|
|
|
return mObject;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
JNIEnv* mJNIEnv;
|
|
|
|
jobject mObject;
|
|
|
|
};
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
class AutoLocalJNIFrame {
|
|
|
|
public:
|
|
|
|
AutoLocalJNIFrame(int nEntries = 128)
|
2012-05-08 17:21:36 -07:00
|
|
|
: mEntries(nEntries), mHasFrameBeenPushed(false)
|
2012-05-04 08:08:47 -07:00
|
|
|
{
|
|
|
|
mJNIEnv = AndroidBridge::GetJNIEnv();
|
|
|
|
Push();
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoLocalJNIFrame(JNIEnv* aJNIEnv, int nEntries = 128)
|
2012-05-08 17:21:36 -07:00
|
|
|
: mEntries(nEntries), mHasFrameBeenPushed(false)
|
2012-05-04 08:08:47 -07:00
|
|
|
{
|
|
|
|
mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv();
|
|
|
|
|
|
|
|
Push();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note! Calling Purge makes all previous local refs created in
|
|
|
|
// the AutoLocalJNIFrame's scope INVALID; be sure that you locked down
|
|
|
|
// any local refs that you need to keep around in global refs!
|
|
|
|
void Purge() {
|
|
|
|
if (mJNIEnv) {
|
2012-05-08 17:21:36 -07:00
|
|
|
if (mHasFrameBeenPushed)
|
|
|
|
mJNIEnv->PopLocalFrame(NULL);
|
2012-05-04 08:08:47 -07:00
|
|
|
Push();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 06:35:59 -07:00
|
|
|
JNIEnv* GetEnv() {
|
|
|
|
return mJNIEnv;
|
|
|
|
}
|
|
|
|
|
2012-05-04 08:08:47 -07:00
|
|
|
bool CheckForException() {
|
|
|
|
if (mJNIEnv->ExceptionCheck()) {
|
|
|
|
mJNIEnv->ExceptionDescribe();
|
|
|
|
mJNIEnv->ExceptionClear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoLocalJNIFrame() {
|
|
|
|
if (!mJNIEnv)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CheckForException();
|
|
|
|
|
2012-05-08 17:21:36 -07:00
|
|
|
if (mHasFrameBeenPushed)
|
|
|
|
mJNIEnv->PopLocalFrame(NULL);
|
2012-05-04 08:08:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Push() {
|
|
|
|
if (!mJNIEnv)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Make sure there is enough space to store a local ref to the
|
|
|
|
// exception. I am not completely sure this is needed, but does
|
|
|
|
// not hurt.
|
|
|
|
jint ret = mJNIEnv->PushLocalFrame(mEntries + 1);
|
|
|
|
NS_ABORT_IF_FALSE(ret == 0, "Failed to push local JNI frame");
|
2012-05-08 17:21:36 -07:00
|
|
|
if (ret < 0)
|
2012-05-04 08:08:47 -07:00
|
|
|
CheckForException();
|
2012-05-08 17:21:36 -07:00
|
|
|
else
|
|
|
|
mHasFrameBeenPushed = true;
|
2012-05-04 08:08:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int mEntries;
|
|
|
|
JNIEnv* mJNIEnv;
|
2012-05-08 17:21:36 -07:00
|
|
|
bool mHasFrameBeenPushed;
|
2012-05-04 08:08:47 -07:00
|
|
|
};
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
#define NS_ANDROIDBRIDGE_CID \
|
|
|
|
{ 0x0FE2321D, 0xEBD9, 0x467D, \
|
|
|
|
{ 0xA7, 0x43, 0x03, 0xA6, 0x8D, 0x40, 0x59, 0x9E } }
|
|
|
|
|
2013-05-30 11:26:02 -07:00
|
|
|
class nsAndroidBridge MOZ_FINAL : public nsIAndroidBridge
|
2011-11-14 19:12:14 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIANDROIDBRIDGE
|
|
|
|
|
|
|
|
nsAndroidBridge();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAndroidBridge();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
#endif /* AndroidBridge_h__ */
|