2010-06-03 20:56:36 +00:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
#ifndef AndroidBridge_h__
|
|
|
|
#define AndroidBridge_h__
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <android/log.h>
|
2011-11-15 03:12:14 +00:00
|
|
|
#include <cstdlib>
|
2012-01-29 20:39:30 +00:00
|
|
|
#include <pthread.h>
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2011-09-16 21:34:31 +00:00
|
|
|
#include "nsCOMArray.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2013-11-12 18:41:01 +00:00
|
|
|
#include "GeneratedJNIWrappers.h"
|
2015-01-10 00:33:57 +00:00
|
|
|
#include "AndroidJavaWrappers.h"
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2010-09-30 15:37:36 +00:00
|
|
|
#include "nsIMutableArray.h"
|
|
|
|
#include "nsIMIMEInfo.h"
|
2011-03-30 18:04:41 +00:00
|
|
|
#include "nsColor.h"
|
2012-01-31 14:40:58 +00:00
|
|
|
#include "gfxRect.h"
|
2015-04-11 02:14:00 +00:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2010-06-14 19:04:16 +00:00
|
|
|
|
2011-11-15 03:12:14 +00:00
|
|
|
#include "nsIAndroidBridge.h"
|
2013-03-09 07:22:02 +00:00
|
|
|
#include "nsIMobileMessageCallback.h"
|
2011-11-15 03:12:14 +00:00
|
|
|
|
2012-10-26 13:32:10 +00:00
|
|
|
#include "mozilla/Likely.h"
|
2012-11-06 22:13:58 +00:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2013-04-26 17:26:46 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2014-05-06 05:26:46 +00:00
|
|
|
#include "mozilla/Types.h"
|
2015-01-10 00:33:57 +00:00
|
|
|
#include "mozilla/jni/Utils.h"
|
2012-10-26 13:32:10 +00:00
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
// Some debug #defines
|
2011-08-29 18:29:39 +00:00
|
|
|
// #define DEBUG_ANDROID_EVENTS
|
|
|
|
// #define DEBUG_ANDROID_WIDGET
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2013-09-19 13:54:39 +00:00
|
|
|
class nsIObserver;
|
2014-08-08 21:42:20 +00:00
|
|
|
class Task;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2012-02-04 02:35:58 +00:00
|
|
|
namespace base {
|
|
|
|
class Thread;
|
|
|
|
} // end namespace base
|
|
|
|
|
2013-03-04 16:54:06 +00:00
|
|
|
typedef void* EGLSurface;
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
2011-11-02 15:35:11 +00:00
|
|
|
namespace hal {
|
|
|
|
class BatteryInformation;
|
2012-01-16 13:44:07 +00:00
|
|
|
class NetworkInformation;
|
2011-11-02 15:35:11 +00:00
|
|
|
} // namespace hal
|
|
|
|
|
2011-12-20 08:07:25 +00:00
|
|
|
namespace dom {
|
2013-03-01 08:38:47 +00:00
|
|
|
namespace mobilemessage {
|
2015-08-15 02:22:50 +00:00
|
|
|
class SmsFilterData;
|
2013-03-01 08:38:47 +00:00
|
|
|
} // namespace mobilemessage
|
2011-12-20 08:07:25 +00:00
|
|
|
} // namespace dom
|
|
|
|
|
2011-03-30 18:04:41 +00: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 05:50:06 +00:00
|
|
|
class nsFilePickerCallback : nsISupports {
|
|
|
|
public:
|
2013-07-19 02:24:15 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-04-05 05:50:06 +00:00
|
|
|
virtual void handleResult(nsAString& filePath) = 0;
|
|
|
|
nsFilePickerCallback() {}
|
|
|
|
protected:
|
|
|
|
virtual ~nsFilePickerCallback() {}
|
|
|
|
};
|
|
|
|
|
2013-04-26 17:26:46 +00:00
|
|
|
class DelayedTask {
|
|
|
|
public:
|
|
|
|
DelayedTask(Task* aTask, int aDelayMs) {
|
|
|
|
mTask = aTask;
|
2014-08-08 21:42:20 +00:00
|
|
|
mRunTime = mozilla::TimeStamp::Now() + mozilla::TimeDuration::FromMilliseconds(aDelayMs);
|
2013-04-26 17:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEarlierThan(DelayedTask *aOther) {
|
|
|
|
return mRunTime < aOther->mRunTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t MillisecondsToRunTime() {
|
2014-08-08 21:42:20 +00:00
|
|
|
mozilla::TimeDuration timeLeft = mRunTime - mozilla::TimeStamp::Now();
|
2013-04-26 17:26:46 +00:00
|
|
|
return (int64_t)timeLeft.ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
Task* GetTask() {
|
|
|
|
return mTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Task* mTask;
|
2014-08-08 21:42:20 +00:00
|
|
|
mozilla::TimeStamp mRunTime;
|
2013-04-26 17:26:46 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class AndroidBridge final
|
2010-06-03 20:56:36 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-08-04 19:47:26 +00:00
|
|
|
enum {
|
2013-03-19 20:54:49 +00:00
|
|
|
// Values for NotifyIME, in addition to values from the Gecko
|
2014-02-18 00:00:15 +00:00
|
|
|
// IMEMessage enum; use negative values here to prevent conflict
|
2013-08-14 15:32:44 +00:00
|
|
|
NOTIFY_IME_OPEN_VKB = -2,
|
2013-03-19 20:54:49 +00:00
|
|
|
NOTIFY_IME_REPLY_EVENT = -1,
|
2010-08-04 19:47:26 +00:00
|
|
|
};
|
|
|
|
|
2012-02-03 07:30:41 +00:00
|
|
|
enum {
|
|
|
|
LAYER_CLIENT_TYPE_NONE = 0,
|
|
|
|
LAYER_CLIENT_TYPE_GL = 2 // AndroidGeckoGLLayerClient
|
|
|
|
};
|
|
|
|
|
2014-08-08 22:15:38 +00:00
|
|
|
static void RegisterJavaUiThread() {
|
|
|
|
sJavaUiThread = pthread_self();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsJavaUiThread() {
|
|
|
|
return pthread_equal(pthread_self(), sJavaUiThread);
|
|
|
|
}
|
|
|
|
|
2015-08-13 04:53:39 +00:00
|
|
|
static void ConstructBridge();
|
|
|
|
static void DeconstructBridge();
|
2010-06-03 20:56:36 +00:00
|
|
|
|
|
|
|
static AndroidBridge *Bridge() {
|
2014-08-08 21:42:20 +00:00
|
|
|
return sBridge;
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* These are all implemented in Java */
|
2013-04-23 17:10:29 +00:00
|
|
|
bool GetThreadNameJavaProfiling(uint32_t aThreadId, nsCString & aResult);
|
|
|
|
bool GetFrameNameJavaProfiling(uint32_t aThreadId, uint32_t aSampleId, uint32_t aFrameId, nsCString & aResult);
|
|
|
|
|
2015-01-21 04:59:23 +00:00
|
|
|
nsresult CaptureZoomedView(nsIDOMWindow *window, nsIntRect zoomedViewRect, jni::Object::Param buffer, float zoomFactor);
|
2015-01-10 00:33:57 +00:00
|
|
|
nsresult CaptureThumbnail(nsIDOMWindow *window, int32_t bufW, int32_t bufH, int32_t tabId, jni::Object::Param buffer, bool &shouldStore);
|
2013-05-30 13:55:08 +00:00
|
|
|
void GetDisplayPort(bool aPageSizeUpdate, bool aIsBrowserContentDisplayed, int32_t tabId, nsIAndroidViewport* metrics, nsIAndroidDisplayport** displayPort);
|
2013-05-30 13:55:23 +00:00
|
|
|
void ContentDocumentChanged();
|
|
|
|
bool IsContentDocumentDisplayed();
|
2012-04-24 19:13:36 +00:00
|
|
|
|
2014-06-23 12:42:53 +00:00
|
|
|
bool ProgressiveUpdateCallback(bool aHasPendingNewThebesContent, const LayerRect& aDisplayPort, float aDisplayResolution, bool aDrawingCritical,
|
2014-11-10 19:35:11 +00:00
|
|
|
mozilla::ParentLayerPoint& aScrollOffset, mozilla::CSSToParentLayerScale& aZoom);
|
2012-10-04 18:45:16 +00:00
|
|
|
|
2015-01-10 00:33:57 +00:00
|
|
|
void SetLayerClient(widget::GeckoLayerClient::Param jobj);
|
|
|
|
const widget::GeckoLayerClient::Ref& GetLayerClient() { return mLayerClient; }
|
2011-11-15 03:12:14 +00:00
|
|
|
|
2013-09-09 12:57:36 +00:00
|
|
|
bool GetHandlersForURL(const nsAString& aURL,
|
|
|
|
nsIMutableArray* handlersArray = nullptr,
|
|
|
|
nsIHandlerApp **aDefaultApp = nullptr,
|
|
|
|
const nsAString& aAction = EmptyString());
|
2010-06-14 19:04:16 +00:00
|
|
|
|
2013-09-09 12:57:36 +00:00
|
|
|
bool GetHandlersForMimeType(const nsAString& aMimeType,
|
|
|
|
nsIMutableArray* handlersArray = nullptr,
|
|
|
|
nsIHandlerApp **aDefaultApp = nullptr,
|
|
|
|
const nsAString& aAction = EmptyString());
|
2010-06-30 02:22:08 +00:00
|
|
|
|
2015-07-24 19:45:55 +00:00
|
|
|
bool GetHWEncoderCapability();
|
|
|
|
bool GetHWDecoderCapability();
|
|
|
|
|
2010-11-05 17:43:12 +00:00
|
|
|
void GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType);
|
2011-09-15 07:40:17 +00:00
|
|
|
void GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt);
|
2010-06-14 19:04:16 +00:00
|
|
|
|
2010-08-26 23:43:23 +00:00
|
|
|
bool GetClipboardText(nsAString& aText);
|
|
|
|
|
2010-06-15 02:17:37 +00:00
|
|
|
void ShowAlertNotification(const nsAString& aImageUrl,
|
|
|
|
const nsAString& aAlertTitle,
|
|
|
|
const nsAString& aAlertText,
|
|
|
|
const nsAString& aAlertData,
|
|
|
|
nsIObserver *aAlertListener,
|
|
|
|
const nsAString& aAlertName);
|
|
|
|
|
2010-10-07 17:28:27 +00:00
|
|
|
int GetDPI();
|
2013-07-04 13:53:25 +00:00
|
|
|
int GetScreenDepth();
|
2010-10-07 17:28:27 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void Vibrate(const nsTArray<uint32_t>& aPattern);
|
2012-01-25 00:31:33 +00:00
|
|
|
|
2011-03-30 18:04:41 +00:00
|
|
|
void GetSystemColors(AndroidSystemColors *aColors);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void GetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t * const aBuf);
|
2011-06-13 21:02:13 +00:00
|
|
|
|
2012-01-26 19:23:13 +00:00
|
|
|
// Switch Java to composite with the Gecko Compositor thread
|
2013-10-10 20:42:52 +00:00
|
|
|
void RegisterCompositor(JNIEnv* env = nullptr);
|
2013-11-15 16:28:59 +00:00
|
|
|
EGLSurface CreateEGLSurfaceForCompositor();
|
2012-01-26 19:23:13 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
bool GetStaticStringField(const char *classID, const char *field, nsAString &result, JNIEnv* env = nullptr);
|
2010-09-11 13:20:20 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool GetStaticIntField(const char *className, const char *fieldName, int32_t* aInt, JNIEnv* env = nullptr);
|
2011-02-28 16:32:05 +00:00
|
|
|
|
2011-06-16 09:03:00 +00: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 21:38:08 +00: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);
|
|
|
|
|
2011-06-16 09:03:00 +00:00
|
|
|
void UnlockBitmap(jobject bitmap);
|
|
|
|
|
2011-09-21 16:46:00 +00: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 00:00:12 +00:00
|
|
|
WINDOW_FORMAT_RGB_565 = 4
|
2011-09-21 16:46:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool HasNativeWindowAccess();
|
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
void *AcquireNativeWindow(JNIEnv* aEnv, jobject aSurface);
|
2011-09-21 16:46:00 +00:00
|
|
|
void ReleaseNativeWindow(void *window);
|
2015-04-11 02:14:00 +00:00
|
|
|
mozilla::gfx::IntSize GetNativeWindowSize(void* window);
|
2012-07-20 19:20:51 +00:00
|
|
|
|
|
|
|
void *AcquireNativeWindowFromSurfaceTexture(JNIEnv* aEnv, jobject aSurface);
|
|
|
|
void ReleaseNativeWindowForSurfaceTexture(void *window);
|
|
|
|
|
2011-09-21 16:46:00 +00:00
|
|
|
bool LockWindow(void *window, unsigned char **bits, int *width, int *height, int *format, int *stride);
|
|
|
|
bool UnlockWindow(void *window);
|
2014-04-04 16:33:49 +00:00
|
|
|
|
|
|
|
void HandleGeckoMessage(JSContext* cx, JS::HandleObject message);
|
2011-11-15 03:12:14 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool InitCamera(const nsCString& contentType, uint32_t camera, uint32_t *width, uint32_t *height, uint32_t *fps);
|
2011-09-27 00:25:41 +00:00
|
|
|
|
2011-11-02 15:35:11 +00:00
|
|
|
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
|
|
|
|
|
2013-03-09 07:22:02 +00:00
|
|
|
nsresult GetSegmentInfoForText(const nsAString& aText,
|
2013-08-09 13:25:53 +00:00
|
|
|
nsIMobileMessageCallback* aRequest);
|
2013-03-09 07:22:02 +00:00
|
|
|
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);
|
|
|
|
already_AddRefed<nsIMobileMessageCallback> DequeueSmsRequest(uint32_t aRequestId);
|
2011-11-25 09:48:51 +00:00
|
|
|
|
2012-01-16 13:44:07 +00:00
|
|
|
void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
|
|
|
|
|
2013-06-21 21:03:56 +00:00
|
|
|
void SetFirstPaintViewport(const LayerIntPoint& aOffset, const CSSToLayerScale& aZoom, const CSSRect& aCssPageRect);
|
2013-06-03 13:52:44 +00:00
|
|
|
void SetPageRect(const CSSRect& aCssPageRect);
|
2013-06-21 21:03:56 +00:00
|
|
|
void SyncViewportInfo(const LayerIntRect& aDisplayPort, const CSSToLayerScale& aDisplayResolution,
|
2015-08-18 18:27:20 +00:00
|
|
|
bool aLayersUpdated, int32_t aPaintSyncId, ParentLayerRect& aScrollRect, CSSToParentLayerScale& aScale,
|
2015-08-18 18:27:19 +00:00
|
|
|
ScreenMargin& aFixedLayerMargins);
|
2014-11-10 19:35:11 +00:00
|
|
|
void SyncFrameMetrics(const ParentLayerPoint& aScrollOffset, float aZoom, const CSSRect& aCssPageRect,
|
2013-06-21 21:03:56 +00:00
|
|
|
bool aLayersUpdated, const CSSRect& aDisplayPort, const CSSToLayerScale& aDisplayResolution,
|
2015-08-18 18:27:19 +00:00
|
|
|
bool aIsFirstPaint, ScreenMargin& aFixedLayerMargins);
|
2012-02-04 02:35:58 +00:00
|
|
|
|
2013-08-13 15:49:21 +00:00
|
|
|
void AddPluginView(jobject view, const LayoutDeviceRect& rect, bool isFullScreen);
|
2012-04-27 20:04:47 +00:00
|
|
|
|
2012-05-08 21:36:07 +00: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 21:36:07 +00:00
|
|
|
uint32_t GetScreenOrientation();
|
2015-08-18 21:55:15 +00:00
|
|
|
uint16_t GetScreenAngle();
|
2012-06-07 02:39:01 +00:00
|
|
|
|
2012-07-20 19:20:51 +00:00
|
|
|
int GetAPIVersion() { return mAPIVersion; }
|
|
|
|
bool IsHoneycomb() { return mAPIVersion >= 11 && mAPIVersion <= 13; }
|
|
|
|
|
2015-06-11 15:20:04 +00:00
|
|
|
void InvalidateAndScheduleComposite();
|
2013-04-23 17:10:29 +00:00
|
|
|
|
2012-11-13 19:25:18 +00:00
|
|
|
nsresult GetProxyForURI(const nsACString & aSpec,
|
|
|
|
const nsACString & aScheme,
|
|
|
|
const nsACString & aHost,
|
|
|
|
const int32_t aPort,
|
|
|
|
nsACString & aResult);
|
2013-09-09 12:57:36 +00:00
|
|
|
|
2015-04-28 00:52:52 +00:00
|
|
|
bool PumpMessageLoop();
|
|
|
|
|
2013-09-09 12:57:36 +00:00
|
|
|
// Utility methods.
|
2014-01-04 15:02:17 +00:00
|
|
|
static jstring NewJavaString(JNIEnv* env, const char16_t* string, uint32_t len);
|
2013-09-09 12:57:37 +00:00
|
|
|
static jstring NewJavaString(JNIEnv* env, const nsAString& string);
|
|
|
|
static jstring NewJavaString(JNIEnv* env, const char* string);
|
|
|
|
static jstring NewJavaString(JNIEnv* env, const nsACString& string);
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
static jstring NewJavaString(AutoLocalJNIFrame* frame, const char16_t* string, uint32_t len);
|
2013-09-09 12:57:37 +00:00
|
|
|
static jstring NewJavaString(AutoLocalJNIFrame* frame, const nsAString& string);
|
|
|
|
static jstring NewJavaString(AutoLocalJNIFrame* frame, const char* string);
|
|
|
|
static jstring NewJavaString(AutoLocalJNIFrame* frame, const nsACString& string);
|
|
|
|
|
2013-09-09 12:57:36 +00:00
|
|
|
static jclass GetClassGlobalRef(JNIEnv* env, const char* className);
|
|
|
|
static jfieldID GetFieldID(JNIEnv* env, jclass jClass, const char* fieldName, const char* fieldType);
|
|
|
|
static jfieldID GetStaticFieldID(JNIEnv* env, jclass jClass, const char* fieldName, const char* fieldType);
|
|
|
|
static jmethodID GetMethodID(JNIEnv* env, jclass jClass, const char* methodName, const char* methodType);
|
|
|
|
static jmethodID GetStaticMethodID(JNIEnv* env, jclass jClass, const char* methodName, const char* methodType);
|
2014-06-04 19:28:04 +00:00
|
|
|
|
2015-01-10 00:33:57 +00:00
|
|
|
static jni::Object::LocalRef ChannelCreate(jni::Object::Param);
|
2014-06-04 19:28:04 +00:00
|
|
|
|
2015-01-10 00:33:57 +00:00
|
|
|
static void InputStreamClose(jni::Object::Param obj);
|
|
|
|
static uint32_t InputStreamAvailable(jni::Object::Param obj);
|
|
|
|
static nsresult InputStreamRead(jni::Object::Param obj, char *aBuf, uint32_t aCount, uint32_t *aRead);
|
2014-06-04 19:28:04 +00:00
|
|
|
|
2014-07-24 20:42:50 +00:00
|
|
|
static nsresult GetExternalPublicDirectory(const nsAString& aType, nsAString& aPath);
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
protected:
|
2014-08-08 22:15:38 +00:00
|
|
|
static pthread_t sJavaUiThread;
|
2014-08-08 21:42:20 +00:00
|
|
|
static AndroidBridge* sBridge;
|
2013-04-08 14:29:34 +00:00
|
|
|
nsTArray<nsCOMPtr<nsIMobileMessageCallback> > mSmsRequests;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2015-01-10 00:33:57 +00:00
|
|
|
widget::GeckoLayerClient::GlobalRef mLayerClient;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2013-01-04 06:26:27 +00:00
|
|
|
// the android.telephony.SmsMessage class
|
|
|
|
jclass mAndroidSmsMessageClass;
|
2010-06-03 20:56:36 +00:00
|
|
|
|
2012-02-04 02:35:58 +00:00
|
|
|
AndroidBridge();
|
|
|
|
~AndroidBridge();
|
|
|
|
|
2011-09-21 16:46:00 +00:00
|
|
|
bool mOpenedGraphicsLibraries;
|
|
|
|
void OpenGraphicsLibraries();
|
2012-04-27 20:04:47 +00:00
|
|
|
void* GetNativeSurface(JNIEnv* env, jobject surface);
|
2011-09-21 16:46:00 +00:00
|
|
|
|
2011-06-16 09:03:00 +00:00
|
|
|
bool mHasNativeBitmapAccess;
|
2011-09-21 16:46:00 +00:00
|
|
|
bool mHasNativeWindowAccess;
|
2012-04-27 20:04:47 +00:00
|
|
|
bool mHasNativeWindowFallback;
|
2011-06-16 09:03:00 +00:00
|
|
|
|
2012-07-20 19:20:51 +00:00
|
|
|
int mAPIVersion;
|
|
|
|
|
2013-03-09 07:22:02 +00:00
|
|
|
bool QueueSmsRequest(nsIMobileMessageCallback* aRequest, uint32_t* aRequestIdOut);
|
2012-11-06 21:32:07 +00:00
|
|
|
|
2014-06-04 19:28:04 +00:00
|
|
|
// intput stream
|
|
|
|
jclass jReadableByteChannel;
|
|
|
|
jclass jChannels;
|
|
|
|
jmethodID jChannelCreate;
|
|
|
|
jmethodID jByteBufferRead;
|
|
|
|
|
|
|
|
jclass jInputStream;
|
|
|
|
jmethodID jClose;
|
|
|
|
jmethodID jAvailable;
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
// other things
|
2010-10-26 03:10:07 +00:00
|
|
|
jmethodID jNotifyAppShellReady;
|
2010-06-03 20:56:36 +00:00
|
|
|
jmethodID jGetOutstandingDrawEvents;
|
2011-09-16 21:34:31 +00:00
|
|
|
jmethodID jPostToJavaThread;
|
2012-04-27 20:04:47 +00:00
|
|
|
jmethodID jCreateSurface;
|
|
|
|
jmethodID jShowSurface;
|
|
|
|
jmethodID jHideSurface;
|
|
|
|
jmethodID jDestroySurface;
|
|
|
|
|
2013-01-04 06:26:27 +00:00
|
|
|
jmethodID jCalculateLength;
|
2012-07-05 14:12:10 +00:00
|
|
|
|
2012-04-27 20:04:47 +00:00
|
|
|
// For native surface stuff
|
|
|
|
jclass jSurfaceClass;
|
|
|
|
jfieldID jSurfacePointerField;
|
|
|
|
|
2012-04-05 15:28:50 +00:00
|
|
|
jclass jLayerView;
|
2013-09-09 12:57:37 +00:00
|
|
|
|
2013-02-28 18:28:24 +00:00
|
|
|
jfieldID jEGLSurfacePointerField;
|
2015-01-10 00:33:57 +00:00
|
|
|
widget::GLController::GlobalRef mGLControllerObj;
|
2012-02-03 03:28:22 +00:00
|
|
|
|
2012-03-08 00:24:38 +00:00
|
|
|
// some convinient types to have around
|
|
|
|
jclass jStringClass;
|
|
|
|
|
2015-01-10 00:33:57 +00:00
|
|
|
jni::Object::GlobalRef mClassLoader;
|
|
|
|
jmethodID mClassLoaderLoadClass;
|
|
|
|
|
2015-04-28 00:52:52 +00:00
|
|
|
jni::Object::GlobalRef mMessageQueue;
|
|
|
|
jfieldID mMessageQueueMessages;
|
|
|
|
jmethodID mMessageQueueNext;
|
|
|
|
|
2011-06-16 09:03:00 +00: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 16:46:00 +00:00
|
|
|
|
|
|
|
void* (*ANativeWindow_fromSurface)(JNIEnv *env, jobject surface);
|
2012-07-20 19:20:51 +00:00
|
|
|
void* (*ANativeWindow_fromSurfaceTexture)(JNIEnv *env, jobject surfaceTexture);
|
2011-09-21 16:46:00 +00: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);
|
2015-04-11 02:14:00 +00:00
|
|
|
int (* ANativeWindow_getWidth)(void * window);
|
|
|
|
int (* ANativeWindow_getHeight)(void * window);
|
2012-04-27 20:04:47 +00: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 17:24:28 +00:00
|
|
|
|
|
|
|
private:
|
2014-08-08 21:42:20 +00:00
|
|
|
// This will always be accessed from one thread (the Java UI thread),
|
|
|
|
// so we don't need to do locking to touch it.
|
2013-04-26 17:26:46 +00:00
|
|
|
nsTArray<DelayedTask*> mDelayedTaskQueue;
|
2013-04-26 17:24:28 +00:00
|
|
|
public:
|
2014-08-08 21:42:20 +00:00
|
|
|
void PostTaskToUiThread(Task* aTask, int aDelayMs);
|
|
|
|
int64_t RunDelayedUiThreadTasks();
|
2015-04-11 02:14:00 +00:00
|
|
|
|
|
|
|
void* GetPresentationWindow();
|
|
|
|
void SetPresentationWindow(void* aPresentationWindow);
|
|
|
|
|
|
|
|
EGLSurface GetPresentationSurface();
|
|
|
|
void SetPresentationSurface(EGLSurface aPresentationSurface);
|
|
|
|
private:
|
|
|
|
void* mPresentationWindow;
|
|
|
|
EGLSurface mPresentationSurface;
|
2010-06-03 20:56:36 +00:00
|
|
|
};
|
|
|
|
|
2015-01-10 00:33:56 +00:00
|
|
|
class AutoJNIClass {
|
|
|
|
private:
|
|
|
|
JNIEnv* const mEnv;
|
|
|
|
const jclass mClass;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AutoJNIClass(JNIEnv* jEnv, const char* name)
|
|
|
|
: mEnv(jEnv)
|
|
|
|
, mClass(AndroidBridge::GetClassGlobalRef(jEnv, name))
|
|
|
|
{}
|
|
|
|
|
|
|
|
~AutoJNIClass() {
|
|
|
|
mEnv->DeleteGlobalRef(mClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
jclass getRawRef() const {
|
|
|
|
return mClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
jclass getGlobalRef() const {
|
|
|
|
return static_cast<jclass>(mEnv->NewGlobalRef(mClass));
|
|
|
|
}
|
|
|
|
|
|
|
|
jfieldID getField(const char* name, const char* type) const {
|
|
|
|
return AndroidBridge::GetFieldID(mEnv, mClass, name, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
jfieldID getStaticField(const char* name, const char* type) const {
|
|
|
|
return AndroidBridge::GetStaticFieldID(mEnv, mClass, name, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID getMethod(const char* name, const char* type) const {
|
|
|
|
return AndroidBridge::GetMethodID(mEnv, mClass, name, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID getStaticMethod(const char* name, const char* type) const {
|
|
|
|
return AndroidBridge::GetStaticMethodID(mEnv, mClass, name, type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-11-16 20:13:57 +00:00
|
|
|
class AutoJObject {
|
|
|
|
public:
|
2013-10-10 20:42:52 +00:00
|
|
|
AutoJObject(JNIEnv* aJNIEnv = nullptr) : mObject(nullptr)
|
2012-11-16 20:13:57 +00:00
|
|
|
{
|
2015-08-13 04:53:39 +00:00
|
|
|
mJNIEnv = aJNIEnv ? aJNIEnv : jni::GetGeckoThreadEnv();
|
2012-11-16 20:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoJObject(JNIEnv* aJNIEnv, jobject aObject)
|
|
|
|
{
|
2015-08-13 04:53:39 +00:00
|
|
|
mJNIEnv = aJNIEnv ? aJNIEnv : jni::GetGeckoThreadEnv();
|
2012-11-16 20:13:57 +00:00
|
|
|
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 15:08:47 +00:00
|
|
|
class AutoLocalJNIFrame {
|
|
|
|
public:
|
2014-03-25 16:02:43 +00:00
|
|
|
AutoLocalJNIFrame(int nEntries = 15)
|
|
|
|
: mEntries(nEntries)
|
2015-08-13 04:53:39 +00:00
|
|
|
, mJNIEnv(jni::GetGeckoThreadEnv())
|
2014-03-25 16:02:43 +00:00
|
|
|
, mHasFrameBeenPushed(false)
|
2012-05-04 15:08:47 +00:00
|
|
|
{
|
2014-03-25 16:02:43 +00:00
|
|
|
MOZ_ASSERT(mJNIEnv);
|
2012-05-04 15:08:47 +00:00
|
|
|
Push();
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:02:43 +00:00
|
|
|
AutoLocalJNIFrame(JNIEnv* aJNIEnv, int nEntries = 15)
|
|
|
|
: mEntries(nEntries)
|
2015-08-13 04:53:39 +00:00
|
|
|
, mJNIEnv(aJNIEnv ? aJNIEnv : jni::GetGeckoThreadEnv())
|
2014-03-25 16:02:43 +00:00
|
|
|
, mHasFrameBeenPushed(false)
|
2012-05-04 15:08:47 +00:00
|
|
|
{
|
2014-03-25 16:02:43 +00:00
|
|
|
MOZ_ASSERT(mJNIEnv);
|
2012-05-04 15:08:47 +00:00
|
|
|
Push();
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:02:43 +00:00
|
|
|
~AutoLocalJNIFrame() {
|
|
|
|
if (mHasFrameBeenPushed) {
|
|
|
|
Pop();
|
2012-05-04 15:08:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-08 13:35:59 +00:00
|
|
|
JNIEnv* GetEnv() {
|
|
|
|
return mJNIEnv;
|
|
|
|
}
|
|
|
|
|
2012-05-04 15:08:47 +00:00
|
|
|
bool CheckForException() {
|
|
|
|
if (mJNIEnv->ExceptionCheck()) {
|
2015-01-10 00:33:57 +00:00
|
|
|
jni::HandleUncaughtException(mJNIEnv);
|
2012-05-04 15:08:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-25 16:02:43 +00:00
|
|
|
// 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() {
|
|
|
|
Pop();
|
|
|
|
Push();
|
|
|
|
}
|
2012-05-04 15:08:47 +00:00
|
|
|
|
2014-03-25 16:02:43 +00:00
|
|
|
template <typename ReturnType = jobject>
|
|
|
|
ReturnType Pop(ReturnType aResult = nullptr) {
|
|
|
|
MOZ_ASSERT(mHasFrameBeenPushed);
|
|
|
|
mHasFrameBeenPushed = false;
|
|
|
|
return static_cast<ReturnType>(
|
|
|
|
mJNIEnv->PopLocalFrame(static_cast<jobject>(aResult)));
|
2012-05-04 15:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Push() {
|
2014-03-25 16:02:43 +00:00
|
|
|
MOZ_ASSERT(!mHasFrameBeenPushed);
|
2012-05-04 15:08:47 +00:00
|
|
|
// 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.
|
2014-03-25 16:02:43 +00:00
|
|
|
if (mJNIEnv->PushLocalFrame(mEntries + 1) != 0) {
|
2012-05-04 15:08:47 +00:00
|
|
|
CheckForException();
|
2014-03-25 16:02:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mHasFrameBeenPushed = true;
|
2012-05-04 15:08:47 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 16:02:43 +00:00
|
|
|
const int mEntries;
|
|
|
|
JNIEnv* const mJNIEnv;
|
2012-05-09 00:21:36 +00:00
|
|
|
bool mHasFrameBeenPushed;
|
2012-05-04 15:08:47 +00:00
|
|
|
};
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 03:12:14 +00:00
|
|
|
#define NS_ANDROIDBRIDGE_CID \
|
|
|
|
{ 0x0FE2321D, 0xEBD9, 0x467D, \
|
|
|
|
{ 0xA7, 0x43, 0x03, 0xA6, 0x8D, 0x40, 0x59, 0x9E } }
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsAndroidBridge final : public nsIAndroidBridge
|
2011-11-15 03:12:14 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIANDROIDBRIDGE
|
|
|
|
|
|
|
|
nsAndroidBridge();
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAndroidBridge();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
2010-06-03 20:56:36 +00:00
|
|
|
#endif /* AndroidBridge_h__ */
|