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
|
|
|
|
|
|
|
#ifndef AndroidBridge_h__
|
|
|
|
#define AndroidBridge_h__
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <android/log.h>
|
2011-11-15 07:12:14 +04:00
|
|
|
#include <cstdlib>
|
2012-01-30 00:39:30 +04:00
|
|
|
#include <pthread.h>
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2011-09-17 01:34:31 +04:00
|
|
|
#include "nsCOMArray.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "nsIRunnable.h"
|
2010-06-15 06:17:37 +04:00
|
|
|
#include "nsIObserver.h"
|
2012-01-30 00:39:30 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2012-04-05 19:28:50 +04:00
|
|
|
#include "AndroidLayerViewWrapper.h"
|
2010-06-04 00:56:36 +04:00
|
|
|
#include "AndroidJavaWrappers.h"
|
|
|
|
|
2010-09-30 19:37:36 +04:00
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsIMIMEInfo.h"
|
2011-03-30 22:04:41 +04:00
|
|
|
#include "nsColor.h"
|
2012-02-04 06:35:58 +04:00
|
|
|
#include "BasicLayers.h"
|
2012-01-31 18:40:58 +04:00
|
|
|
#include "gfxRect.h"
|
2010-06-14 23:04:16 +04:00
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
#include "nsIAndroidBridge.h"
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
// Some debug #defines
|
2011-08-29 22:29:39 +04:00
|
|
|
// #define DEBUG_ANDROID_EVENTS
|
|
|
|
// #define DEBUG_ANDROID_WIDGET
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
class nsWindow;
|
2012-01-13 17:25:47 +04:00
|
|
|
class nsIDOMMozSmsMessage;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2012-01-30 00:39:30 +04: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-04 06:35:58 +04:00
|
|
|
namespace base {
|
|
|
|
class Thread;
|
|
|
|
} // end namespace base
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2011-11-02 19:35:11 +04:00
|
|
|
namespace hal {
|
|
|
|
class BatteryInformation;
|
2012-01-16 17:44:07 +04:00
|
|
|
class NetworkInformation;
|
2011-11-02 19:35:11 +04:00
|
|
|
} // namespace hal
|
|
|
|
|
2011-12-20 12:07:25 +04:00
|
|
|
namespace dom {
|
|
|
|
namespace sms {
|
|
|
|
struct SmsFilterData;
|
|
|
|
} // namespace sms
|
|
|
|
} // namespace dom
|
|
|
|
|
2012-02-04 06:35:58 +04:00
|
|
|
namespace layers {
|
|
|
|
class CompositorParent;
|
|
|
|
} // namespace layers
|
|
|
|
|
2011-03-30 22:04:41 +04: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-05 09:50:06 +04:00
|
|
|
class nsFilePickerCallback : nsISupports {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
virtual void handleResult(nsAString& filePath) = 0;
|
|
|
|
nsFilePickerCallback() {}
|
|
|
|
protected:
|
|
|
|
virtual ~nsFilePickerCallback() {}
|
|
|
|
};
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
class AndroidBridge
|
|
|
|
{
|
|
|
|
public:
|
2010-08-04 23:47:26 +04:00
|
|
|
enum {
|
|
|
|
NOTIFY_IME_RESETINPUTSTATE = 0,
|
|
|
|
NOTIFY_IME_SETOPENSTATE = 1,
|
2010-11-23 09:48:25 +03:00
|
|
|
NOTIFY_IME_CANCELCOMPOSITION = 2,
|
|
|
|
NOTIFY_IME_FOCUSCHANGE = 3
|
2010-08-04 23:47:26 +04:00
|
|
|
};
|
|
|
|
|
2012-02-03 11:30:41 +04:00
|
|
|
enum {
|
|
|
|
LAYER_CLIENT_TYPE_NONE = 0,
|
|
|
|
LAYER_CLIENT_TYPE_GL = 2 // AndroidGeckoGLLayerClient
|
|
|
|
};
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
static AndroidBridge *ConstructBridge(JNIEnv *jEnv,
|
|
|
|
jclass jGeckoAppShellClass);
|
|
|
|
|
|
|
|
static AndroidBridge *Bridge() {
|
|
|
|
return sBridge;
|
|
|
|
}
|
|
|
|
|
2012-01-30 00:39:30 +04:00
|
|
|
static JavaVM *GetVM() {
|
|
|
|
if (NS_LIKELY(sBridge))
|
|
|
|
return sBridge->mJavaVM;
|
|
|
|
return nsnull;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2012-01-30 00:39:30 +04:00
|
|
|
static JNIEnv *GetJNIEnv() {
|
|
|
|
if (NS_LIKELY(sBridge)) {
|
|
|
|
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);
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return sBridge->mJNIEnv;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2012-01-30 00:39:30 +04:00
|
|
|
}
|
2010-09-23 05:03:46 +04:00
|
|
|
return nsnull;
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
2010-10-15 22:16:45 +04:00
|
|
|
|
|
|
|
static jclass GetGeckoAppShellClass() {
|
|
|
|
return sBridge->mGeckoAppShellClass;
|
|
|
|
}
|
2010-06-04 00:56:36 +04: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-29 10:19:26 +04:00
|
|
|
bool SetMainThread(void *thr);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
/* These are all implemented in Java */
|
2010-08-05 22:11:32 +04:00
|
|
|
static void NotifyIME(int aType, int aState);
|
2010-08-04 23:47:26 +04:00
|
|
|
|
2010-11-24 05:12:53 +03:00
|
|
|
static void NotifyIMEEnabled(int aState, const nsAString& aTypeHint,
|
|
|
|
const nsAString& aActionHint);
|
2010-11-23 09:48:25 +03:00
|
|
|
|
2010-08-05 22:11:32 +04:00
|
|
|
static void NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen, int aStart, int aEnd, int aNewEnd);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2012-04-26 21:45:31 +04:00
|
|
|
/* These are defined in mobile/android/base/GeckoAppShell.java */
|
|
|
|
enum {
|
|
|
|
SCREENSHOT_THUMBNAIL = 0,
|
|
|
|
SCREENSHOT_WHOLE_PAGE = 1,
|
|
|
|
SCREENSHOT_UPDATE = 2
|
|
|
|
};
|
|
|
|
|
2012-06-06 06:55:18 +04:00
|
|
|
nsresult TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt32 srcY, PRInt32 srcW, PRInt32 srcH, PRInt32 dstW, PRInt32 dstH, PRInt32 tabId, float scale, PRInt32 token);
|
2012-04-24 23:13:36 +04:00
|
|
|
|
|
|
|
static void NotifyPaintedRect(float top, float left, float bottom, float right);
|
2012-02-04 10:48:26 +04:00
|
|
|
|
2011-03-02 20:23:02 +03:00
|
|
|
void AcknowledgeEventSync();
|
|
|
|
|
2010-06-05 01:14:43 +04:00
|
|
|
void EnableLocation(bool aEnable);
|
2012-03-21 21:52:35 +04:00
|
|
|
void EnableLocationHighAccuracy(bool aEnable);
|
2010-06-05 01:14:43 +04:00
|
|
|
|
2012-02-05 23:51:05 +04:00
|
|
|
void EnableSensor(int aSensorType);
|
|
|
|
|
|
|
|
void DisableSensor(int aSensorType);
|
|
|
|
|
2010-08-04 23:47:26 +04:00
|
|
|
void ReturnIMEQueryResult(const PRUnichar *aResult, PRUint32 aLen, int aSelStart, int aSelLen);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
void NotifyXreExit();
|
|
|
|
|
|
|
|
void ScheduleRestart();
|
|
|
|
|
2012-02-17 18:16:14 +04:00
|
|
|
void SetLayerClient(jobject jobj);
|
2012-02-03 11:30:41 +04:00
|
|
|
AndroidGeckoLayerClient &GetLayerClient() { return *mLayerClient; }
|
2011-11-15 07:12:14 +04:00
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
void SetSurfaceView(jobject jobj);
|
|
|
|
AndroidGeckoSurfaceView& SurfaceView() { return mSurfaceView; }
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetHandlersForURL(const char *aURL,
|
2010-11-24 02:40:46 +03:00
|
|
|
nsIMutableArray* handlersArray = nsnull,
|
|
|
|
nsIHandlerApp **aDefaultApp = nsnull,
|
|
|
|
const nsAString& aAction = EmptyString());
|
2010-06-14 23:04:16 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetHandlersForMimeType(const char *aMimeType,
|
2010-09-30 19:37:36 +04:00
|
|
|
nsIMutableArray* handlersArray = nsnull,
|
|
|
|
nsIHandlerApp **aDefaultApp = nsnull,
|
|
|
|
const nsAString& aAction = EmptyString());
|
2010-06-30 06:22:08 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool OpenUriExternal(const nsACString& aUriSpec, const nsACString& aMimeType,
|
2010-10-02 05:04:23 +04:00
|
|
|
const nsAString& aPackageName = EmptyString(),
|
2010-09-30 19:37:36 +04:00
|
|
|
const nsAString& aClassName = EmptyString(),
|
2010-10-02 05:04:23 +04:00
|
|
|
const nsAString& aAction = EmptyString(),
|
|
|
|
const nsAString& aTitle = EmptyString());
|
2010-06-14 23:04:16 +04:00
|
|
|
|
2010-11-05 20:43:12 +03:00
|
|
|
void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType);
|
2011-09-15 11:40:17 +04:00
|
|
|
void GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt);
|
2010-06-14 23:04:16 +04:00
|
|
|
|
2010-06-16 21:20:54 +04:00
|
|
|
void MoveTaskToBack();
|
|
|
|
|
2010-08-27 03:43:23 +04:00
|
|
|
bool GetClipboardText(nsAString& aText);
|
|
|
|
|
|
|
|
void SetClipboardText(const nsAString& aText);
|
|
|
|
|
|
|
|
void EmptyClipboard();
|
|
|
|
|
|
|
|
bool ClipboardHasText();
|
|
|
|
|
2010-06-15 06:17:37 +04:00
|
|
|
void ShowAlertNotification(const nsAString& aImageUrl,
|
|
|
|
const nsAString& aAlertTitle,
|
|
|
|
const nsAString& aAlertText,
|
|
|
|
const nsAString& aAlertData,
|
|
|
|
nsIObserver *aAlertListener,
|
|
|
|
const nsAString& aAlertName);
|
|
|
|
|
2010-10-02 01:21:21 +04:00
|
|
|
void AlertsProgressListener_OnProgress(const nsAString& aAlertName,
|
|
|
|
PRInt64 aProgress,
|
|
|
|
PRInt64 aProgressMax,
|
|
|
|
const nsAString& aAlertText);
|
|
|
|
|
2010-10-13 06:17:12 +04:00
|
|
|
void AlertsProgressListener_OnCancel(const nsAString& aAlertName);
|
|
|
|
|
2010-10-07 21:28:27 +04:00
|
|
|
int GetDPI();
|
|
|
|
|
2012-03-18 20:15:56 +04:00
|
|
|
void ShowFilePickerForExtensions(nsAString& aFilePath, const nsAString& aExtensions);
|
|
|
|
void ShowFilePickerForMimeType(nsAString& aFilePath, const nsAString& aMimeType);
|
2012-04-05 09:50:06 +04:00
|
|
|
void ShowFilePickerAsync(const nsAString& aMimeType, nsFilePickerCallback* callback);
|
2010-09-30 19:37:36 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void PerformHapticFeedback(bool aIsLongPress);
|
2010-11-22 19:38:02 +03:00
|
|
|
|
2011-09-30 11:00:48 +04:00
|
|
|
void Vibrate(const nsTArray<PRUint32>& aPattern);
|
|
|
|
void CancelVibrate();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetFullScreen(bool aFullScreen);
|
2010-11-09 05:11:13 +03:00
|
|
|
|
2010-11-10 17:40:00 +03:00
|
|
|
void ShowInputMethodPicker();
|
|
|
|
|
2012-04-07 11:09:26 +04:00
|
|
|
void NotifyDefaultPrevented(bool aDefaultPrevented);
|
2012-01-25 04:31:33 +04:00
|
|
|
|
2010-11-12 23:02:14 +03:00
|
|
|
void HideProgressDialogOnce();
|
|
|
|
|
2011-01-20 14:06:13 +03:00
|
|
|
bool IsNetworkLinkUp();
|
|
|
|
|
|
|
|
bool IsNetworkLinkKnown();
|
|
|
|
|
2011-03-17 02:17:59 +03:00
|
|
|
void SetSelectedLocale(const nsAString&);
|
2011-02-27 18:50:56 +03:00
|
|
|
|
2011-03-30 22:04:41 +04:00
|
|
|
void GetSystemColors(AndroidSystemColors *aColors);
|
|
|
|
|
2011-06-14 01:02:13 +04:00
|
|
|
void GetIconForExtension(const nsACString& aFileExt, PRUint32 aIconSize, PRUint8 * const aBuf);
|
|
|
|
|
2011-07-27 05:14:52 +04:00
|
|
|
bool GetShowPasswordSetting();
|
|
|
|
|
2011-08-04 11:32:57 +04:00
|
|
|
void FireAndWaitForTracerEvent();
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
/* See GLHelpers.java as to why this is needed */
|
|
|
|
void *CallEglCreateWindowSurface(void *dpy, void *config, AndroidGeckoSurfaceView& surfaceView);
|
|
|
|
|
2012-01-26 23:23:13 +04:00
|
|
|
// Switch Java to composite with the Gecko Compositor thread
|
2012-02-07 01:53:09 +04:00
|
|
|
void RegisterCompositor();
|
|
|
|
EGLSurface ProvideEGLSurface();
|
2012-01-26 23:23:13 +04:00
|
|
|
|
2012-04-28 00:04:47 +04:00
|
|
|
bool GetStaticStringField(const char *classID, const char *field, nsAString &result, JNIEnv* env = nsnull);
|
2010-09-11 17:20:20 +04:00
|
|
|
|
2012-04-28 00:04:47 +04:00
|
|
|
bool GetStaticIntField(const char *className, const char *fieldName, PRInt32* aInt, JNIEnv* env = nsnull);
|
2011-02-28 19:32:05 +03:00
|
|
|
|
2010-12-22 01:34:29 +03:00
|
|
|
void SetKeepScreenOn(bool on);
|
|
|
|
|
2011-04-08 21:52:13 +04:00
|
|
|
void ScanMedia(const nsAString& aFile, const nsACString& aMimeType);
|
|
|
|
|
2011-08-09 06:37:57 +04:00
|
|
|
void CreateShortcut(const nsAString& aTitle, const nsAString& aURI, const nsAString& aIconData, const nsAString& aIntent);
|
|
|
|
|
2011-06-16 13:03:00 +04: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);
|
|
|
|
|
|
|
|
void UnlockBitmap(jobject bitmap);
|
|
|
|
|
2012-01-30 00:39:30 +04:00
|
|
|
void PostToJavaThread(JNIEnv *aEnv, nsIRunnable* aRunnable, bool aMainThread = false);
|
2011-09-17 01:34:31 +04:00
|
|
|
|
2012-01-30 00:39:30 +04:00
|
|
|
void ExecuteNextRunnable(JNIEnv *aEnv);
|
2011-09-17 01:34:31 +04:00
|
|
|
|
2011-09-21 20:46:00 +04: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-09 04:00:12 +04:00
|
|
|
WINDOW_FORMAT_RGB_565 = 4
|
2011-09-21 20:46:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
bool HasNativeWindowAccess();
|
|
|
|
|
2012-04-28 00:04:47 +04:00
|
|
|
void *AcquireNativeWindow(JNIEnv* aEnv, jobject aSurface);
|
2011-09-21 20:46:00 +04:00
|
|
|
void ReleaseNativeWindow(void *window);
|
2012-01-31 18:40:58 +04:00
|
|
|
bool SetNativeWindowFormat(void *window, int width, int height, int format);
|
2011-09-21 20:46:00 +04:00
|
|
|
|
|
|
|
bool LockWindow(void *window, unsigned char **bits, int *width, int *height, int *format, int *stride);
|
|
|
|
bool UnlockWindow(void *window);
|
2011-11-15 07:12:14 +04:00
|
|
|
|
|
|
|
void HandleGeckoMessage(const nsAString& message, nsAString &aRet);
|
|
|
|
|
|
|
|
void CheckURIVisited(const nsAString& uri);
|
|
|
|
void MarkURIVisited(const nsAString& uri);
|
2011-09-21 20:46:00 +04:00
|
|
|
|
2011-09-27 04:25:41 +04:00
|
|
|
bool InitCamera(const nsCString& contentType, PRUint32 camera, PRUint32 *width, PRUint32 *height, PRUint32 *fps);
|
|
|
|
|
|
|
|
void CloseCamera();
|
|
|
|
|
2011-11-02 19:35:11 +04:00
|
|
|
void EnableBatteryNotifications();
|
|
|
|
void DisableBatteryNotifications();
|
|
|
|
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
|
|
|
|
|
2011-11-25 13:48:51 +04:00
|
|
|
PRUint16 GetNumberOfMessagesForText(const nsAString& aText);
|
2012-01-13 17:26:50 +04:00
|
|
|
void SendMessage(const nsAString& aNumber, const nsAString& aText, PRInt32 aRequestId, PRUint64 aProcessId);
|
2012-01-13 17:25:47 +04:00
|
|
|
PRInt32 SaveSentMessage(const nsAString& aRecipient, const nsAString& aBody, PRUint64 aDate);
|
2011-12-23 02:08:58 +04:00
|
|
|
void GetMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId);
|
2011-12-23 02:15:28 +04:00
|
|
|
void DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId);
|
2011-12-20 12:07:25 +04:00
|
|
|
void CreateMessageList(const dom::sms::SmsFilterData& aFilter, bool aReverse, PRInt32 aRequestId, PRUint64 aProcessId);
|
2011-12-23 02:16:59 +04:00
|
|
|
void GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, PRUint64 aProcessId);
|
2012-01-17 22:43:08 +04:00
|
|
|
void ClearMessageList(PRInt32 aListId);
|
2011-11-25 13:48:51 +04:00
|
|
|
|
2011-12-15 01:53:38 +04:00
|
|
|
bool IsTablet();
|
|
|
|
|
2012-01-16 17:44:07 +04:00
|
|
|
void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
|
2012-01-16 18:01:07 +04:00
|
|
|
void EnableNetworkNotifications();
|
|
|
|
void DisableNetworkNotifications();
|
2012-01-16 17:44:07 +04:00
|
|
|
|
2012-05-23 18:51:39 +04:00
|
|
|
void SetFirstPaintViewport(const nsIntPoint& aOffset, float aZoom, const nsIntRect& aPageRect, const gfx::Rect& aCssPageRect);
|
|
|
|
void SetPageRect(float aZoom, const nsIntRect& aPageRect, const gfx::Rect& aCssPageRect);
|
2012-03-20 08:06:56 +04:00
|
|
|
void SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated,
|
|
|
|
nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY);
|
2012-02-04 06:35:58 +04:00
|
|
|
|
2012-01-31 18:40:58 +04:00
|
|
|
jobject CreateSurface();
|
|
|
|
void DestroySurface(jobject surface);
|
|
|
|
void ShowSurface(jobject surface, const gfxRect& aRect, bool aInverted, bool aBlend);
|
|
|
|
void HideSurface(jobject surface);
|
|
|
|
|
2012-06-07 06:39:36 +04:00
|
|
|
void AddPluginView(jobject view, const gfxRect& rect, bool isFullScreen);
|
2012-05-30 20:10:49 +04:00
|
|
|
void RemovePluginView(jobject view, bool isFullScreen);
|
2012-04-28 00:04:47 +04:00
|
|
|
|
2012-05-09 01:36:07 +04: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-09 01:36:07 +04:00
|
|
|
uint32_t GetScreenOrientation();
|
2012-03-20 17:09:45 +04:00
|
|
|
void EnableScreenOrientationNotifications();
|
|
|
|
void DisableScreenOrientationNotifications();
|
2012-05-09 01:36:07 +04:00
|
|
|
void LockScreenOrientation(uint32_t aOrientation);
|
2012-03-30 10:31:12 +04:00
|
|
|
void UnlockScreenOrientation();
|
2012-03-20 17:09:45 +04:00
|
|
|
|
2012-06-05 19:28:37 +04:00
|
|
|
void PumpMessageLoop();
|
2012-05-03 18:53:31 +04:00
|
|
|
|
2012-06-07 06:39:01 +04:00
|
|
|
void NotifyWakeLockChanged(const nsAString& topic, const nsAString& state);
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
protected:
|
|
|
|
static AndroidBridge *sBridge;
|
|
|
|
|
|
|
|
// the global JavaVM
|
|
|
|
JavaVM *mJavaVM;
|
|
|
|
|
|
|
|
// the JNIEnv for the main thread
|
|
|
|
JNIEnv *mJNIEnv;
|
|
|
|
void *mThread;
|
|
|
|
|
|
|
|
// the GeckoSurfaceView
|
|
|
|
AndroidGeckoSurfaceView mSurfaceView;
|
2012-02-03 11:30:41 +04:00
|
|
|
|
|
|
|
AndroidGeckoLayerClient *mLayerClient;
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
// the GeckoAppShell java class
|
|
|
|
jclass mGeckoAppShellClass;
|
|
|
|
|
2012-02-04 06:35:58 +04:00
|
|
|
AndroidBridge();
|
|
|
|
~AndroidBridge();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Init(JNIEnv *jEnv, jclass jGeckoApp);
|
2010-06-04 00:56:36 +04:00
|
|
|
|
2011-09-21 20:46:00 +04:00
|
|
|
bool mOpenedGraphicsLibraries;
|
|
|
|
void OpenGraphicsLibraries();
|
2012-04-28 00:04:47 +04:00
|
|
|
void* GetNativeSurface(JNIEnv* env, jobject surface);
|
2011-09-21 20:46:00 +04:00
|
|
|
|
2011-06-16 13:03:00 +04:00
|
|
|
bool mHasNativeBitmapAccess;
|
2011-09-21 20:46:00 +04:00
|
|
|
bool mHasNativeWindowAccess;
|
2012-04-28 00:04:47 +04:00
|
|
|
bool mHasNativeWindowFallback;
|
2011-06-16 13:03:00 +04:00
|
|
|
|
2011-09-17 01:34:31 +04:00
|
|
|
nsCOMArray<nsIRunnable> mRunnableQueue;
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
// other things
|
2010-08-04 23:47:26 +04:00
|
|
|
jmethodID jNotifyIME;
|
2010-11-23 09:48:25 +03:00
|
|
|
jmethodID jNotifyIMEEnabled;
|
2010-08-04 23:47:26 +04:00
|
|
|
jmethodID jNotifyIMEChange;
|
2012-02-04 10:48:26 +04:00
|
|
|
jmethodID jNotifyScreenShot;
|
2011-03-02 20:23:02 +03:00
|
|
|
jmethodID jAcknowledgeEventSync;
|
2010-06-05 01:14:43 +04:00
|
|
|
jmethodID jEnableLocation;
|
2012-03-21 21:52:35 +04:00
|
|
|
jmethodID jEnableLocationHighAccuracy;
|
2012-02-05 23:51:05 +04:00
|
|
|
jmethodID jEnableSensor;
|
|
|
|
jmethodID jDisableSensor;
|
2010-06-04 00:56:36 +04:00
|
|
|
jmethodID jReturnIMEQueryResult;
|
2010-10-26 07:10:07 +04:00
|
|
|
jmethodID jNotifyAppShellReady;
|
2010-06-04 00:56:36 +04:00
|
|
|
jmethodID jNotifyXreExit;
|
|
|
|
jmethodID jScheduleRestart;
|
|
|
|
jmethodID jGetOutstandingDrawEvents;
|
2010-06-14 23:04:16 +04:00
|
|
|
jmethodID jGetHandlersForMimeType;
|
2010-11-24 02:40:46 +03:00
|
|
|
jmethodID jGetHandlersForURL;
|
2010-06-14 23:04:16 +04:00
|
|
|
jmethodID jOpenUriExternal;
|
2010-11-05 20:43:12 +03:00
|
|
|
jmethodID jGetMimeTypeFromExtensions;
|
2011-03-08 08:45:43 +03:00
|
|
|
jmethodID jGetExtensionFromMimeType;
|
2010-06-16 21:20:54 +04:00
|
|
|
jmethodID jMoveTaskToBack;
|
2010-08-27 03:43:23 +04:00
|
|
|
jmethodID jGetClipboardText;
|
|
|
|
jmethodID jSetClipboardText;
|
2010-06-15 06:17:37 +04:00
|
|
|
jmethodID jShowAlertNotification;
|
2012-03-18 20:15:56 +04:00
|
|
|
jmethodID jShowFilePickerForExtensions;
|
|
|
|
jmethodID jShowFilePickerForMimeType;
|
2012-04-05 09:50:06 +04:00
|
|
|
jmethodID jShowFilePickerAsync;
|
2010-10-02 01:21:21 +04:00
|
|
|
jmethodID jAlertsProgressListener_OnProgress;
|
2010-10-13 06:17:12 +04:00
|
|
|
jmethodID jAlertsProgressListener_OnCancel;
|
2010-10-07 21:28:27 +04:00
|
|
|
jmethodID jGetDpi;
|
2010-11-09 05:11:13 +03:00
|
|
|
jmethodID jSetFullScreen;
|
2010-11-10 17:40:00 +03:00
|
|
|
jmethodID jShowInputMethodPicker;
|
2012-04-07 11:09:26 +04:00
|
|
|
jmethodID jNotifyDefaultPrevented;
|
2010-11-12 23:02:14 +03:00
|
|
|
jmethodID jHideProgressDialog;
|
2010-11-22 19:38:02 +03:00
|
|
|
jmethodID jPerformHapticFeedback;
|
2011-09-30 11:00:48 +04:00
|
|
|
jmethodID jVibrate1;
|
|
|
|
jmethodID jVibrateA;
|
|
|
|
jmethodID jCancelVibrate;
|
2010-12-22 01:34:29 +03:00
|
|
|
jmethodID jSetKeepScreenOn;
|
2011-01-20 14:06:13 +03:00
|
|
|
jmethodID jIsNetworkLinkUp;
|
|
|
|
jmethodID jIsNetworkLinkKnown;
|
2011-02-27 18:50:56 +03:00
|
|
|
jmethodID jSetSelectedLocale;
|
2011-04-08 21:52:13 +04:00
|
|
|
jmethodID jScanMedia;
|
2011-03-30 22:04:41 +04:00
|
|
|
jmethodID jGetSystemColors;
|
2011-06-14 01:02:13 +04:00
|
|
|
jmethodID jGetIconForExtension;
|
2011-08-04 11:32:57 +04:00
|
|
|
jmethodID jFireAndWaitForTracerEvent;
|
2011-08-09 06:37:57 +04:00
|
|
|
jmethodID jCreateShortcut;
|
2011-07-27 05:14:52 +04:00
|
|
|
jmethodID jGetShowPasswordSetting;
|
2011-09-17 01:34:31 +04:00
|
|
|
jmethodID jPostToJavaThread;
|
2011-09-27 04:25:41 +04:00
|
|
|
jmethodID jInitCamera;
|
|
|
|
jmethodID jCloseCamera;
|
2011-12-15 01:53:38 +04:00
|
|
|
jmethodID jIsTablet;
|
2011-11-02 19:35:11 +04:00
|
|
|
jmethodID jEnableBatteryNotifications;
|
|
|
|
jmethodID jDisableBatteryNotifications;
|
|
|
|
jmethodID jGetCurrentBatteryInformation;
|
2011-11-15 07:12:14 +04:00
|
|
|
jmethodID jHandleGeckoMessage;
|
|
|
|
jmethodID jCheckUriVisited;
|
|
|
|
jmethodID jMarkUriVisited;
|
2012-04-28 00:04:47 +04:00
|
|
|
jmethodID jAddPluginView;
|
2012-03-27 09:31:57 +04:00
|
|
|
jmethodID jRemovePluginView;
|
2012-04-28 00:04:47 +04:00
|
|
|
jmethodID jCreateSurface;
|
|
|
|
jmethodID jShowSurface;
|
|
|
|
jmethodID jHideSurface;
|
|
|
|
jmethodID jDestroySurface;
|
|
|
|
|
2012-04-24 23:13:36 +04:00
|
|
|
jmethodID jNotifyPaintedRect;
|
2010-06-26 04:52:37 +04:00
|
|
|
|
2011-11-25 13:48:51 +04:00
|
|
|
jmethodID jNumberOfMessages;
|
2011-11-21 03:00:46 +04:00
|
|
|
jmethodID jSendMessage;
|
2012-01-13 17:25:47 +04:00
|
|
|
jmethodID jSaveSentMessage;
|
2011-12-23 02:08:58 +04:00
|
|
|
jmethodID jGetMessage;
|
2011-12-23 02:15:28 +04:00
|
|
|
jmethodID jDeleteMessage;
|
2011-12-20 12:07:25 +04:00
|
|
|
jmethodID jCreateMessageList;
|
2011-12-23 02:16:59 +04:00
|
|
|
jmethodID jGetNextMessageinList;
|
2012-01-17 22:43:08 +04:00
|
|
|
jmethodID jClearMessageList;
|
2010-06-26 04:52:37 +04:00
|
|
|
|
2012-01-16 17:44:07 +04:00
|
|
|
jmethodID jGetCurrentNetworkInformation;
|
2012-01-16 18:01:07 +04:00
|
|
|
jmethodID jEnableNetworkNotifications;
|
|
|
|
jmethodID jDisableNetworkNotifications;
|
2012-01-16 17:44:07 +04:00
|
|
|
|
2012-03-20 17:09:45 +04:00
|
|
|
jmethodID jGetScreenOrientation;
|
|
|
|
jmethodID jEnableScreenOrientationNotifications;
|
|
|
|
jmethodID jDisableScreenOrientationNotifications;
|
2012-03-30 10:31:12 +04:00
|
|
|
jmethodID jLockScreenOrientation;
|
|
|
|
jmethodID jUnlockScreenOrientation;
|
2012-05-03 18:53:31 +04:00
|
|
|
jmethodID jPumpMessageLoop;
|
2012-06-07 06:39:01 +04:00
|
|
|
jmethodID jNotifyWakeLockChanged;
|
2012-03-20 17:09:45 +04:00
|
|
|
|
2012-04-28 00:04:47 +04:00
|
|
|
// For native surface stuff
|
|
|
|
jclass jSurfaceClass;
|
|
|
|
jfieldID jSurfacePointerField;
|
|
|
|
|
2010-06-26 04:52:37 +04:00
|
|
|
// stuff we need for CallEglCreateWindowSurface
|
|
|
|
jclass jEGLSurfaceImplClass;
|
|
|
|
jclass jEGLContextImplClass;
|
|
|
|
jclass jEGLConfigImplClass;
|
|
|
|
jclass jEGLDisplayImplClass;
|
|
|
|
jclass jEGLContextClass;
|
|
|
|
jclass jEGL10Class;
|
2011-06-16 13:03:00 +04:00
|
|
|
|
2012-04-05 19:28:50 +04:00
|
|
|
jclass jLayerView;
|
2012-02-03 07:28:22 +04:00
|
|
|
jmethodID jRegisterCompositorMethod;
|
|
|
|
|
2012-03-08 04:24:38 +04:00
|
|
|
// some convinient types to have around
|
|
|
|
jclass jStringClass;
|
|
|
|
|
2011-06-16 13:03:00 +04: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 20:46:00 +04:00
|
|
|
|
|
|
|
void* (*ANativeWindow_fromSurface)(JNIEnv *env, jobject surface);
|
|
|
|
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-28 00:04:47 +04: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);
|
2010-06-04 00:56:36 +04:00
|
|
|
};
|
|
|
|
|
2012-05-04 19:08:47 +04:00
|
|
|
class AutoLocalJNIFrame {
|
|
|
|
public:
|
|
|
|
AutoLocalJNIFrame(int nEntries = 128)
|
2012-05-09 04:21:36 +04:00
|
|
|
: mEntries(nEntries), mHasFrameBeenPushed(false)
|
2012-05-04 19:08:47 +04:00
|
|
|
{
|
|
|
|
mJNIEnv = AndroidBridge::GetJNIEnv();
|
|
|
|
Push();
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoLocalJNIFrame(JNIEnv* aJNIEnv, int nEntries = 128)
|
2012-05-09 04:21:36 +04:00
|
|
|
: mEntries(nEntries), mHasFrameBeenPushed(false)
|
2012-05-04 19:08:47 +04: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-09 04:21:36 +04:00
|
|
|
if (mHasFrameBeenPushed)
|
|
|
|
mJNIEnv->PopLocalFrame(NULL);
|
2012-05-04 19:08:47 +04:00
|
|
|
Push();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 17:35:59 +04:00
|
|
|
JNIEnv* GetEnv() {
|
|
|
|
return mJNIEnv;
|
|
|
|
}
|
|
|
|
|
2012-05-04 19:08:47 +04:00
|
|
|
bool CheckForException() {
|
|
|
|
if (mJNIEnv->ExceptionCheck()) {
|
|
|
|
mJNIEnv->ExceptionDescribe();
|
|
|
|
mJNIEnv->ExceptionClear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoLocalJNIFrame() {
|
|
|
|
if (!mJNIEnv)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CheckForException();
|
|
|
|
|
2012-05-09 04:21:36 +04:00
|
|
|
if (mHasFrameBeenPushed)
|
|
|
|
mJNIEnv->PopLocalFrame(NULL);
|
2012-05-04 19:08:47 +04: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-09 04:21:36 +04:00
|
|
|
if (ret < 0)
|
2012-05-04 19:08:47 +04:00
|
|
|
CheckForException();
|
2012-05-09 04:21:36 +04:00
|
|
|
else
|
|
|
|
mHasFrameBeenPushed = true;
|
2012-05-04 19:08:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int mEntries;
|
|
|
|
JNIEnv* mJNIEnv;
|
2012-05-09 04:21:36 +04:00
|
|
|
bool mHasFrameBeenPushed;
|
2012-05-04 19:08:47 +04:00
|
|
|
};
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
}
|
|
|
|
|
2011-11-15 07:12:14 +04:00
|
|
|
#define NS_ANDROIDBRIDGE_CID \
|
|
|
|
{ 0x0FE2321D, 0xEBD9, 0x467D, \
|
|
|
|
{ 0xA7, 0x43, 0x03, 0xA6, 0x8D, 0x40, 0x59, 0x9E } }
|
|
|
|
|
|
|
|
class nsAndroidBridge : public nsIAndroidBridge
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIANDROIDBRIDGE
|
|
|
|
|
|
|
|
nsAndroidBridge();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAndroidBridge();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
2010-06-04 00:56:36 +04:00
|
|
|
|
|
|
|
#endif /* AndroidBridge_h__ */
|