2010-06-03 13:56:36 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Android code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include <android/log.h>
|
2011-06-16 02:03:00 -07:00
|
|
|
#include <dlfcn.h>
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-11-02 08:35:11 -07:00
|
|
|
#include "mozilla/Hal.h"
|
2010-08-17 01:07:45 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
#include <prthread.h>
|
2010-06-29 19:22:08 -07:00
|
|
|
#include "nsXPCOMStrings.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
#include "AndroidBridge.h"
|
2010-06-14 19:17:37 -07:00
|
|
|
#include "nsAppShell.h"
|
2010-09-30 08:37:36 -07:00
|
|
|
#include "nsOSHelperAppService.h"
|
2011-04-11 13:41:03 -07:00
|
|
|
#include "nsWindow.h"
|
2011-06-07 00:38:00 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-08-04 00:32:57 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2012-01-29 12:39:30 -08:00
|
|
|
#include "nsIThreadManager.h"
|
2011-12-20 00:07:25 -08:00
|
|
|
#include "mozilla/dom/sms/PSms.h"
|
2012-02-03 22:48:26 -08:00
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2011-02-28 20:25:11 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
#define ALOG_BRIDGE(args...) ALOG(args)
|
|
|
|
#else
|
|
|
|
#define ALOG_BRIDGE(args...)
|
|
|
|
#endif
|
|
|
|
|
2012-03-08 16:42:31 -08:00
|
|
|
#define IME_FULLSCREEN_PREF "widget.ime.android.landscape_fullscreen"
|
|
|
|
#define IME_FULLSCREEN_THRESHOLD_PREF "widget.ime.android.fullscreen_threshold"
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
|
|
|
AndroidBridge *AndroidBridge::sBridge = 0;
|
|
|
|
|
|
|
|
AndroidBridge *
|
|
|
|
AndroidBridge::ConstructBridge(JNIEnv *jEnv,
|
|
|
|
jclass jGeckoAppShellClass)
|
|
|
|
{
|
|
|
|
/* NSS hack -- bionic doesn't handle recursive unloads correctly,
|
|
|
|
* because library finalizer functions are called with the dynamic
|
|
|
|
* linker lock still held. This results in a deadlock when trying
|
|
|
|
* to call dlclose() while we're already inside dlclose().
|
|
|
|
* Conveniently, NSS has an env var that can prevent it from unloading.
|
|
|
|
*/
|
2011-08-31 19:39:49 -07:00
|
|
|
putenv("NSS_DISABLE_UNLOAD=1");
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
sBridge = new AndroidBridge();
|
|
|
|
if (!sBridge->Init(jEnv, jGeckoAppShellClass)) {
|
|
|
|
delete sBridge;
|
|
|
|
sBridge = 0;
|
|
|
|
}
|
|
|
|
return sBridge;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-03 13:56:36 -07:00
|
|
|
AndroidBridge::Init(JNIEnv *jEnv,
|
|
|
|
jclass jGeckoAppShellClass)
|
|
|
|
{
|
2011-12-05 22:56:04 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::Init");
|
2010-06-03 13:56:36 -07:00
|
|
|
jEnv->GetJavaVM(&mJavaVM);
|
|
|
|
|
|
|
|
mJNIEnv = nsnull;
|
|
|
|
mThread = nsnull;
|
2011-09-21 09:46:00 -07:00
|
|
|
mOpenedGraphicsLibraries = false;
|
2011-06-16 02:03:00 -07:00
|
|
|
mHasNativeBitmapAccess = false;
|
2011-09-21 09:46:00 -07:00
|
|
|
mHasNativeWindowAccess = false;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
|
|
|
mGeckoAppShellClass = (jclass) jEnv->NewGlobalRef(jGeckoAppShellClass);
|
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
jNotifyIME = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIME", "(II)V");
|
2012-03-08 16:42:31 -08:00
|
|
|
jNotifyIMEEnabled = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIMEEnabled", "(ILjava/lang/String;Ljava/lang/String;Z)V");
|
2010-08-04 12:47:26 -07:00
|
|
|
jNotifyIMEChange = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyIMEChange", "(Ljava/lang/String;III)V");
|
2012-02-03 22:48:26 -08:00
|
|
|
jNotifyScreenShot = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "notifyScreenShot", "(Ljava/nio/ByteBuffer;III)V");
|
2011-03-02 09:23:02 -08:00
|
|
|
jAcknowledgeEventSync = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "acknowledgeEventSync", "()V");
|
|
|
|
|
2012-03-13 15:29:29 -07:00
|
|
|
jEnableDeviceMotion = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableDeviceMotion", "(Z)V");
|
2010-06-04 14:14:43 -07:00
|
|
|
jEnableLocation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableLocation", "(Z)V");
|
2012-03-13 15:29:29 -07:00
|
|
|
jEnableSensor =
|
|
|
|
(jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass,
|
|
|
|
"enableSensor", "(I)V");
|
|
|
|
jDisableSensor =
|
|
|
|
(jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass,
|
|
|
|
"disableSensor", "(I)V");
|
2010-06-03 13:56:36 -07:00
|
|
|
jReturnIMEQueryResult = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "returnIMEQueryResult", "(Ljava/lang/String;II)V");
|
|
|
|
jScheduleRestart = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scheduleRestart", "()V");
|
|
|
|
jNotifyXreExit = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "onXreExit", "()V");
|
2010-09-30 08:37:36 -07:00
|
|
|
jGetHandlersForMimeType = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getHandlersForMimeType", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;");
|
2010-11-23 15:40:46 -08:00
|
|
|
jGetHandlersForURL = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getHandlersForURL", "(Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;");
|
2010-10-01 18:04:23 -07:00
|
|
|
jOpenUriExternal = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "openUriExternal", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z");
|
2010-11-05 10:43:12 -07:00
|
|
|
jGetMimeTypeFromExtensions = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getMimeTypeFromExtensions", "(Ljava/lang/String;)Ljava/lang/String;");
|
2011-03-07 21:45:43 -08:00
|
|
|
jGetExtensionFromMimeType = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getExtensionFromMimeType", "(Ljava/lang/String;)Ljava/lang/String;");
|
2010-06-16 10:20:54 -07:00
|
|
|
jMoveTaskToBack = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "moveTaskToBack", "()V");
|
2010-08-26 16:43:23 -07:00
|
|
|
jGetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getClipboardText", "()Ljava/lang/String;");
|
|
|
|
jSetClipboardText = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setClipboardText", "(Ljava/lang/String;)V");
|
2010-06-14 19:17:37 -07:00
|
|
|
jShowAlertNotification = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showAlertNotification", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
2010-11-05 10:43:12 -07:00
|
|
|
jShowFilePicker = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showFilePicker", "(Ljava/lang/String;)Ljava/lang/String;");
|
2010-10-01 14:21:21 -07:00
|
|
|
jAlertsProgressListener_OnProgress = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "alertsProgressListener_OnProgress", "(Ljava/lang/String;JJLjava/lang/String;)V");
|
2010-10-12 19:17:12 -07:00
|
|
|
jAlertsProgressListener_OnCancel = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "alertsProgressListener_OnCancel", "(Ljava/lang/String;)V");
|
2010-10-07 10:28:27 -07:00
|
|
|
jGetDpi = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getDpi", "()I");
|
2010-11-08 18:11:13 -08:00
|
|
|
jSetFullScreen = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setFullScreen", "(Z)V");
|
2010-11-10 06:40:00 -08:00
|
|
|
jShowInputMethodPicker = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "showInputMethodPicker", "()V");
|
2012-02-01 15:01:47 -08:00
|
|
|
jSetPreventPanning = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setPreventPanning", "(Z)V");
|
2010-11-12 12:02:14 -08:00
|
|
|
jHideProgressDialog = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "hideProgressDialog", "()V");
|
2010-11-22 08:38:02 -08:00
|
|
|
jPerformHapticFeedback = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "performHapticFeedback", "(Z)V");
|
2011-09-30 00:00:48 -07:00
|
|
|
jVibrate1 = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "vibrate", "(J)V");
|
|
|
|
jVibrateA = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "vibrate", "([JI)V");
|
|
|
|
jCancelVibrate = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "cancelVibrate", "()V");
|
2010-12-21 14:34:29 -08:00
|
|
|
jSetKeepScreenOn = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setKeepScreenOn", "(Z)V");
|
2011-01-20 03:06:13 -08:00
|
|
|
jIsNetworkLinkUp = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isNetworkLinkUp", "()Z");
|
|
|
|
jIsNetworkLinkKnown = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isNetworkLinkKnown", "()Z");
|
2011-02-27 07:50:56 -08:00
|
|
|
jSetSelectedLocale = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "setSelectedLocale", "(Ljava/lang/String;)V");
|
2011-04-08 10:52:13 -07:00
|
|
|
jScanMedia = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "scanMedia", "(Ljava/lang/String;Ljava/lang/String;)V");
|
2011-03-30 11:04:41 -07:00
|
|
|
jGetSystemColors = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getSystemColors", "()[I");
|
2011-06-13 14:02:13 -07:00
|
|
|
jGetIconForExtension = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getIconForExtension", "(Ljava/lang/String;I)[B");
|
2011-08-04 00:32:57 -07:00
|
|
|
jFireAndWaitForTracerEvent = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "fireAndWaitForTracerEvent", "()V");
|
2011-08-08 19:37:57 -07:00
|
|
|
jCreateShortcut = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "createShortcut", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
2011-07-26 18:14:52 -07:00
|
|
|
jGetShowPasswordSetting = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getShowPasswordSetting", "()Z");
|
2011-09-16 14:34:31 -07:00
|
|
|
jPostToJavaThread = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "postToJavaThread", "(Z)V");
|
2011-09-26 17:25:41 -07:00
|
|
|
jInitCamera = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "initCamera", "(Ljava/lang/String;III)[I");
|
|
|
|
jCloseCamera = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "closeCamera", "()V");
|
2011-12-14 13:53:38 -08:00
|
|
|
jIsTablet = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "isTablet", "()Z");
|
2011-11-02 08:35:11 -07:00
|
|
|
jEnableBatteryNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableBatteryNotifications", "()V");
|
|
|
|
jDisableBatteryNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "disableBatteryNotifications", "()V");
|
2011-11-09 00:56:37 -08:00
|
|
|
jGetCurrentBatteryInformation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getCurrentBatteryInformation", "()[D");
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
jGetAccessibilityEnabled = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getAccessibilityEnabled", "()Z");
|
2011-10-24 10:05:18 -07:00
|
|
|
jHandleGeckoMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "handleGeckoMessage", "(Ljava/lang/String;)Ljava/lang/String;");
|
2011-10-25 08:39:32 -07:00
|
|
|
jCheckUriVisited = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "checkUriVisited", "(Ljava/lang/String;)V");
|
|
|
|
jMarkUriVisited = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "markUriVisited", "(Ljava/lang/String;)V");
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2011-11-25 01:48:51 -08:00
|
|
|
jNumberOfMessages = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getNumberOfMessagesForText", "(Ljava/lang/String;)I");
|
2012-01-13 05:26:50 -08:00
|
|
|
jSendMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "sendMessage", "(Ljava/lang/String;Ljava/lang/String;IJ)V");
|
2012-01-13 05:25:47 -08:00
|
|
|
jSaveSentMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "saveSentMessage", "(Ljava/lang/String;Ljava/lang/String;J)I");
|
2011-12-22 14:08:58 -08:00
|
|
|
jGetMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getMessage", "(IIJ)V");
|
2011-12-22 14:15:28 -08:00
|
|
|
jDeleteMessage = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "deleteMessage", "(IIJ)V");
|
2011-12-20 00:07:25 -08:00
|
|
|
jCreateMessageList = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "createMessageList", "(JJ[Ljava/lang/String;IIZIJ)V");
|
2011-12-22 14:16:59 -08:00
|
|
|
jGetNextMessageinList = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getNextMessageInList", "(IIJ)V");
|
2012-01-17 10:43:08 -08:00
|
|
|
jClearMessageList = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "clearMessageList", "(I)V");
|
2011-11-25 01:48:51 -08:00
|
|
|
|
2012-01-16 05:44:07 -08:00
|
|
|
jGetCurrentNetworkInformation = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "getCurrentNetworkInformation", "()[D");
|
2012-01-16 06:01:07 -08:00
|
|
|
jEnableNetworkNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "enableNetworkNotifications", "()V");
|
|
|
|
jDisableNetworkNotifications = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "disableNetworkNotifications", "()V");
|
2012-03-07 16:24:38 -08:00
|
|
|
jEmitGeckoAccessibilityEvent = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "emitGeckoAccessibilityEvent", "(I[Ljava/lang/String;Ljava/lang/String;ZZZ)V");
|
2012-01-16 05:44:07 -08:00
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
|
|
|
|
jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
|
|
|
|
jEGLSurfaceImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLSurfaceImpl"));
|
|
|
|
jEGLContextImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLContextImpl"));
|
|
|
|
jEGLConfigImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLConfigImpl"));
|
|
|
|
jEGLDisplayImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLDisplayImpl"));
|
|
|
|
|
2012-03-07 16:24:38 -08:00
|
|
|
jStringClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("java/lang/String"));
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
InitAndroidJavaWrappers(jEnv);
|
|
|
|
|
|
|
|
// jEnv should NOT be cached here by anything -- the jEnv here
|
|
|
|
// is not valid for the real gecko main thread, which is set
|
|
|
|
// at SetMainThread time.
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-03 13:56:36 -07:00
|
|
|
AndroidBridge::SetMainThread(void *thr)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::SetMainThread");
|
2010-06-03 13:56:36 -07:00
|
|
|
if (thr) {
|
|
|
|
mThread = thr;
|
2012-01-29 12:39:30 -08:00
|
|
|
mJavaVM->GetEnv((void**) &mJNIEnv, JNI_VERSION_1_2);
|
|
|
|
return (bool) mJNIEnv;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
mJNIEnv = nsnull;
|
|
|
|
mThread = nsnull;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2012-01-29 00:49:02 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::NotifyIME(int aType, int aState)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::NotifyIME");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(sBridge->mGeckoAppShellClass,
|
|
|
|
sBridge->jNotifyIME, aType, aState);
|
2010-08-04 12:47:26 -07:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:48:25 -08:00
|
|
|
void
|
2010-11-23 18:12:53 -08:00
|
|
|
AndroidBridge::NotifyIMEEnabled(int aState, const nsAString& aTypeHint,
|
|
|
|
const nsAString& aActionHint)
|
2010-11-22 22:48:25 -08:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::NotifyIMEEnabled");
|
2010-11-22 22:48:25 -08:00
|
|
|
if (!sBridge)
|
|
|
|
return;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2010-11-23 18:12:53 -08:00
|
|
|
nsPromiseFlatString typeHint(aTypeHint);
|
|
|
|
nsPromiseFlatString actionHint(aActionHint);
|
2010-11-22 22:48:25 -08:00
|
|
|
|
2012-03-08 16:42:31 -08:00
|
|
|
jvalue args[4];
|
2012-01-29 12:39:30 -08:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
2010-11-22 22:48:25 -08:00
|
|
|
args[0].i = aState;
|
2012-01-29 12:39:30 -08:00
|
|
|
args[1].l = env->NewString(typeHint.get(), typeHint.Length());
|
|
|
|
args[2].l = env->NewString(actionHint.get(), actionHint.Length());
|
2012-03-08 16:42:31 -08:00
|
|
|
args[3].z = false;
|
|
|
|
|
|
|
|
PRInt32 landscapeFS;
|
|
|
|
if (NS_SUCCEEDED(Preferences::GetInt(IME_FULLSCREEN_PREF, &landscapeFS))) {
|
|
|
|
if (landscapeFS == 1) {
|
|
|
|
args[3].z = true;
|
|
|
|
} else if (landscapeFS == -1){
|
|
|
|
if (NS_SUCCEEDED(
|
|
|
|
Preferences::GetInt(IME_FULLSCREEN_THRESHOLD_PREF,
|
|
|
|
&landscapeFS))) {
|
|
|
|
// the threshold is hundreths of inches, so convert the
|
|
|
|
// threshold to pixels and multiply the height by 100
|
|
|
|
if (nsWindow::GetAndroidScreenBounds().height * 100 <
|
|
|
|
landscapeFS * Bridge()->GetDPI()) {
|
|
|
|
args[3].z = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2011-06-07 00:38:00 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethodA(sBridge->mGeckoAppShellClass,
|
2012-03-08 16:42:31 -08:00
|
|
|
sBridge->jNotifyIMEEnabled, args);
|
2010-11-22 22:48:25 -08:00
|
|
|
}
|
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::NotifyIMEChange(const PRUnichar *aText, PRUint32 aTextLen,
|
|
|
|
int aStart, int aEnd, int aNewEnd)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::NotifyIMEChange");
|
2010-08-05 11:11:32 -07:00
|
|
|
if (!sBridge) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2010-08-04 12:47:26 -07:00
|
|
|
jvalue args[4];
|
2012-01-29 12:39:30 -08:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
|
|
|
args[0].l = env->NewString(aText, aTextLen);
|
2010-08-04 12:47:26 -07:00
|
|
|
args[1].i = aStart;
|
|
|
|
args[2].i = aEnd;
|
|
|
|
args[3].i = aNewEnd;
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethodA(sBridge->mGeckoAppShellClass,
|
2010-08-05 11:11:32 -07:00
|
|
|
sBridge->jNotifyIMEChange, args);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2011-03-02 09:23:02 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::AcknowledgeEventSync()
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::AcknowledgeEventSync");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jAcknowledgeEventSync);
|
2011-03-02 09:23:02 -08:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
2011-06-19 22:36:17 -07:00
|
|
|
AndroidBridge::EnableDeviceMotion(bool aEnable)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2011-06-19 22:36:17 -07:00
|
|
|
ALOG_BRIDGE("AndroidBridge::EnableDeviceMotion");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
2012-03-13 15:29:29 -07:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
2010-06-03 13:56:36 -07:00
|
|
|
|
2012-03-13 15:29:29 -07:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableDeviceMotion, aEnable);
|
|
|
|
}
|
2012-03-13 10:00:02 -07:00
|
|
|
|
2010-06-04 14:14:43 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::EnableLocation(bool aEnable)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::EnableLocation");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
2012-03-13 15:29:29 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableLocation, aEnable);
|
2010-06-04 14:14:43 -07:00
|
|
|
}
|
|
|
|
|
2012-02-05 11:51:05 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::EnableSensor(int aSensorType) {
|
|
|
|
ALOG_BRIDGE("AndroidBridge::EnableSensor");
|
2012-03-13 15:29:29 -07:00
|
|
|
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEnableSensor,
|
|
|
|
aSensorType);
|
2012-02-05 11:51:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::DisableSensor(int aSensorType) {
|
|
|
|
ALOG_BRIDGE("AndroidBridge::DisableSensor");
|
2012-03-13 15:29:29 -07:00
|
|
|
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jDisableSensor,
|
|
|
|
aSensorType);
|
2012-02-05 11:51:05 -08:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
2010-08-04 12:47:26 -07:00
|
|
|
AndroidBridge::ReturnIMEQueryResult(const PRUnichar *aResult, PRUint32 aLen,
|
|
|
|
int aSelStart, int aSelLen)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::ReturnIMEQueryResult");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
jvalue args[3];
|
2012-01-29 12:39:30 -08:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
|
|
|
args[0].l = env->NewString(aResult, aLen);
|
2010-08-04 12:47:26 -07:00
|
|
|
args[1].i = aSelStart;
|
|
|
|
args[2].i = aSelLen;
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethodA(mGeckoAppShellClass,
|
|
|
|
jReturnIMEQueryResult, args);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::ScheduleRestart()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("scheduling reboot");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jScheduleRestart);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::NotifyXreExit()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("xre exiting");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jNotifyXreExit);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2010-09-30 08:37:36 -07:00
|
|
|
static void
|
|
|
|
getHandlersFromStringArray(JNIEnv *aJNIEnv, jobjectArray jArr, jsize aLen,
|
|
|
|
nsIMutableArray *aHandlersArray,
|
|
|
|
nsIHandlerApp **aDefaultApp,
|
|
|
|
const nsAString& aAction = EmptyString(),
|
|
|
|
const nsACString& aMimeType = EmptyCString())
|
|
|
|
{
|
|
|
|
nsString empty = EmptyString();
|
|
|
|
for (jsize i = 0; i < aLen; i+=4) {
|
|
|
|
nsJNIString name(
|
|
|
|
static_cast<jstring>(aJNIEnv->GetObjectArrayElement(jArr, i)));
|
|
|
|
nsJNIString isDefault(
|
|
|
|
static_cast<jstring>(aJNIEnv->GetObjectArrayElement(jArr, i + 1)));
|
|
|
|
nsJNIString packageName(
|
|
|
|
static_cast<jstring>(aJNIEnv->GetObjectArrayElement(jArr, i + 2)));
|
|
|
|
nsJNIString className(
|
|
|
|
static_cast<jstring>(aJNIEnv->GetObjectArrayElement(jArr, i + 3)));
|
|
|
|
nsIHandlerApp* app = nsOSHelperAppService::
|
|
|
|
CreateAndroidHandlerApp(name, className, packageName,
|
|
|
|
className, aMimeType, aAction);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
aHandlersArray->AppendElement(app, false);
|
2010-09-30 08:37:36 -07:00
|
|
|
if (aDefaultApp && isDefault.Length() > 0)
|
|
|
|
*aDefaultApp = app;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-09-30 08:37:36 -07:00
|
|
|
AndroidBridge::GetHandlersForMimeType(const char *aMimeType,
|
|
|
|
nsIMutableArray *aHandlersArray,
|
|
|
|
nsIHandlerApp **aDefaultApp,
|
|
|
|
const nsAString& aAction)
|
2010-06-14 12:04:16 -07:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetHandlersForMimeType");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2010-06-14 12:04:16 -07:00
|
|
|
NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
|
2010-09-30 08:37:36 -07:00
|
|
|
jstring jstrMimeType =
|
2012-01-29 12:39:30 -08:00
|
|
|
env->NewString(wMimeType.get(), wMimeType.Length());
|
2011-05-24 08:58:59 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrAction = env->NewString(nsPromiseFlatString(aAction).get(),
|
2011-05-24 08:58:59 -07:00
|
|
|
aAction.Length());
|
2010-09-30 08:37:36 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass,
|
2010-06-29 19:22:08 -07:00
|
|
|
jGetHandlersForMimeType,
|
2010-09-30 08:37:36 -07:00
|
|
|
jstrMimeType, jstrAction);
|
2010-06-14 12:04:16 -07:00
|
|
|
jobjectArray arr = static_cast<jobjectArray>(obj);
|
2010-06-15 16:39:43 -07:00
|
|
|
if (!arr)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-29 19:22:08 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jsize len = env->GetArrayLength(arr);
|
2010-06-29 19:22:08 -07:00
|
|
|
|
2010-09-30 08:37:36 -07:00
|
|
|
if (!aHandlersArray)
|
2010-06-29 19:22:08 -07:00
|
|
|
return len > 0;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
getHandlersFromStringArray(env, arr, len, aHandlersArray,
|
2010-09-30 08:37:36 -07:00
|
|
|
aDefaultApp, aAction,
|
|
|
|
nsDependentCString(aMimeType));
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-29 19:22:08 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-11-23 15:40:46 -08:00
|
|
|
AndroidBridge::GetHandlersForURL(const char *aURL,
|
2011-09-30 00:00:48 -07:00
|
|
|
nsIMutableArray* aHandlersArray,
|
|
|
|
nsIHandlerApp **aDefaultApp,
|
|
|
|
const nsAString& aAction)
|
2010-06-29 19:22:08 -07:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetHandlersForURL");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2010-11-23 15:40:46 -08:00
|
|
|
NS_ConvertUTF8toUTF16 wScheme(aURL);
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrScheme = env->NewString(wScheme.get(), wScheme.Length());
|
|
|
|
jstring jstrAction = env->NewString(nsPromiseFlatString(aAction).get(),
|
2011-05-24 08:58:59 -07:00
|
|
|
aAction.Length());
|
2010-09-30 08:37:36 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass,
|
2010-11-23 15:40:46 -08:00
|
|
|
jGetHandlersForURL,
|
2010-09-30 08:37:36 -07:00
|
|
|
jstrScheme, jstrAction);
|
2010-06-29 19:22:08 -07:00
|
|
|
jobjectArray arr = static_cast<jobjectArray>(obj);
|
|
|
|
if (!arr)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-29 19:22:08 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jsize len = env->GetArrayLength(arr);
|
2010-06-29 19:22:08 -07:00
|
|
|
|
2010-09-30 08:37:36 -07:00
|
|
|
if (!aHandlersArray)
|
2010-06-29 19:22:08 -07:00
|
|
|
return len > 0;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
getHandlersFromStringArray(env, arr, len, aHandlersArray,
|
2010-09-30 08:37:36 -07:00
|
|
|
aDefaultApp, aAction);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-14 12:04:16 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-29 19:22:08 -07:00
|
|
|
AndroidBridge::OpenUriExternal(const nsACString& aUriSpec, const nsACString& aMimeType,
|
2010-09-30 08:37:36 -07:00
|
|
|
const nsAString& aPackageName, const nsAString& aClassName,
|
2010-10-01 18:04:23 -07:00
|
|
|
const nsAString& aAction, const nsAString& aTitle)
|
2010-06-14 12:04:16 -07:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::OpenUriExternal");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2010-06-14 12:04:16 -07:00
|
|
|
NS_ConvertUTF8toUTF16 wUriSpec(aUriSpec);
|
|
|
|
NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
|
2010-06-29 19:22:08 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrUri = env->NewString(wUriSpec.get(), wUriSpec.Length());
|
|
|
|
jstring jstrType = env->NewString(wMimeType.get(), wMimeType.Length());
|
2011-05-24 08:58:59 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrPackage = env->NewString(nsPromiseFlatString(aPackageName).get(),
|
2011-05-24 08:58:59 -07:00
|
|
|
aPackageName.Length());
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrClass = env->NewString(nsPromiseFlatString(aClassName).get(),
|
2011-05-24 08:58:59 -07:00
|
|
|
aClassName.Length());
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrAction = env->NewString(nsPromiseFlatString(aAction).get(),
|
2011-05-24 08:58:59 -07:00
|
|
|
aAction.Length());
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrTitle = env->NewString(nsPromiseFlatString(aTitle).get(),
|
2011-05-24 08:58:59 -07:00
|
|
|
aTitle.Length());
|
2010-09-30 08:37:36 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
return env->CallStaticBooleanMethod(mGeckoAppShellClass,
|
2010-06-14 12:04:16 -07:00
|
|
|
jOpenUriExternal,
|
2010-09-30 08:37:36 -07:00
|
|
|
jstrUri, jstrType, jstrPackage,
|
2010-10-01 18:04:23 -07:00
|
|
|
jstrClass, jstrAction, jstrTitle);
|
2010-06-14 12:04:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-28 20:25:11 -08:00
|
|
|
AndroidBridge::GetMimeTypeFromExtensions(const nsACString& aFileExt, nsCString& aMimeType)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetMimeTypeFromExtensions");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2010-06-14 12:04:16 -07:00
|
|
|
NS_ConvertUTF8toUTF16 wFileExt(aFileExt);
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrExt = env->NewString(wFileExt.get(), wFileExt.Length());
|
2011-03-07 21:45:43 -08:00
|
|
|
jstring jstrType = static_cast<jstring>(
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticObjectMethod(mGeckoAppShellClass,
|
2011-03-07 21:45:43 -08:00
|
|
|
jGetMimeTypeFromExtensions,
|
|
|
|
jstrExt));
|
2010-06-14 12:04:16 -07:00
|
|
|
nsJNIString jniStr(jstrType);
|
|
|
|
aMimeType.Assign(NS_ConvertUTF16toUTF8(jniStr.get()));
|
|
|
|
}
|
|
|
|
|
2011-03-07 21:45:43 -08:00
|
|
|
void
|
2011-09-15 00:40:17 -07:00
|
|
|
AndroidBridge::GetExtensionFromMimeType(const nsACString& aMimeType, nsACString& aFileExt)
|
2011-03-07 21:45:43 -08:00
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetExtensionFromMimeType");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2011-03-07 21:45:43 -08:00
|
|
|
NS_ConvertUTF8toUTF16 wMimeType(aMimeType);
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrType = env->NewString(wMimeType.get(), wMimeType.Length());
|
2011-03-07 21:45:43 -08:00
|
|
|
jstring jstrExt = static_cast<jstring>(
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticObjectMethod(mGeckoAppShellClass,
|
2011-03-07 21:45:43 -08:00
|
|
|
jGetExtensionFromMimeType,
|
|
|
|
jstrType));
|
|
|
|
nsJNIString jniStr(jstrExt);
|
|
|
|
aFileExt.Assign(NS_ConvertUTF16toUTF8(jniStr.get()));
|
|
|
|
}
|
|
|
|
|
2010-06-16 10:20:54 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::MoveTaskToBack()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::MoveTaskToBack");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jMoveTaskToBack);
|
2010-06-16 10:20:54 -07:00
|
|
|
}
|
|
|
|
|
2010-08-26 16:43:23 -07:00
|
|
|
bool
|
|
|
|
AndroidBridge::GetClipboardText(nsAString& aText)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetClipboardText");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
2010-08-26 16:43:23 -07:00
|
|
|
jstring jstrType =
|
2012-01-29 12:39:30 -08:00
|
|
|
static_cast<jstring>(env->
|
2010-08-26 16:43:23 -07:00
|
|
|
CallStaticObjectMethod(mGeckoAppShellClass,
|
|
|
|
jGetClipboardText));
|
|
|
|
if (!jstrType)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-26 16:43:23 -07:00
|
|
|
nsJNIString jniStr(jstrType);
|
|
|
|
aText.Assign(jniStr);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-26 16:43:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::SetClipboardText(const nsAString& aText)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::SetClipboardText");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
jstring jstr = env->NewString(nsPromiseFlatString(aText).get(),
|
2011-05-24 08:58:59 -07:00
|
|
|
aText.Length());
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jSetClipboardText, jstr);
|
2010-08-26 16:43:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidBridge::ClipboardHasText()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::ClipboardHasText");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
2010-08-26 16:43:23 -07:00
|
|
|
jstring jstrType =
|
2012-01-29 12:39:30 -08:00
|
|
|
static_cast<jstring>(env->
|
2010-08-26 16:43:23 -07:00
|
|
|
CallStaticObjectMethod(mGeckoAppShellClass,
|
|
|
|
jGetClipboardText));
|
|
|
|
if (!jstrType)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
|
|
|
return true;
|
2010-08-26 16:43:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::EmptyClipboard()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::EmptyClipboard");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jSetClipboardText, nsnull);
|
2010-08-26 16:43:23 -07:00
|
|
|
}
|
|
|
|
|
2010-06-14 19:17:37 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::ShowAlertNotification(const nsAString& aImageUrl,
|
|
|
|
const nsAString& aAlertTitle,
|
|
|
|
const nsAString& aAlertText,
|
|
|
|
const nsAString& aAlertCookie,
|
|
|
|
nsIObserver *aAlertListener,
|
|
|
|
const nsAString& aAlertName)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("ShowAlertNotification");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2010-06-14 19:17:37 -07:00
|
|
|
|
|
|
|
if (nsAppShell::gAppShell && aAlertListener)
|
|
|
|
nsAppShell::gAppShell->AddObserver(aAlertName, aAlertListener);
|
|
|
|
|
|
|
|
jvalue args[5];
|
2012-01-29 12:39:30 -08:00
|
|
|
args[0].l = env->NewString(nsPromiseFlatString(aImageUrl).get(), aImageUrl.Length());
|
|
|
|
args[1].l = env->NewString(nsPromiseFlatString(aAlertTitle).get(), aAlertTitle.Length());
|
|
|
|
args[2].l = env->NewString(nsPromiseFlatString(aAlertText).get(), aAlertText.Length());
|
|
|
|
args[3].l = env->NewString(nsPromiseFlatString(aAlertCookie).get(), aAlertCookie.Length());
|
|
|
|
args[4].l = env->NewString(nsPromiseFlatString(aAlertName).get(), aAlertName.Length());
|
|
|
|
env->CallStaticVoidMethodA(mGeckoAppShellClass, jShowAlertNotification, args);
|
2010-06-14 19:17:37 -07:00
|
|
|
}
|
|
|
|
|
2010-10-01 14:21:21 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::AlertsProgressListener_OnProgress(const nsAString& aAlertName,
|
|
|
|
PRInt64 aProgress,
|
|
|
|
PRInt64 aProgressMax,
|
|
|
|
const nsAString& aAlertText)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AlertsProgressListener_OnProgress");
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2010-10-01 14:21:21 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrName = env->NewString(nsPromiseFlatString(aAlertName).get(), aAlertName.Length());
|
|
|
|
jstring jstrText = env->NewString(nsPromiseFlatString(aAlertText).get(), aAlertText.Length());
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jAlertsProgressListener_OnProgress,
|
2010-10-01 14:21:21 -07:00
|
|
|
jstrName, aProgress, aProgressMax, jstrText);
|
|
|
|
}
|
|
|
|
|
2010-10-12 19:17:12 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::AlertsProgressListener_OnCancel(const nsAString& aAlertName)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AlertsProgressListener_OnCancel");
|
2010-10-12 19:17:12 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
|
|
|
|
jstring jstrName = env->NewString(nsPromiseFlatString(aAlertName).get(), aAlertName.Length());
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jAlertsProgressListener_OnCancel, jstrName);
|
2010-10-12 19:17:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-07 10:28:27 -07:00
|
|
|
int
|
|
|
|
AndroidBridge::GetDPI()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetDPI");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return 72; // what is a better value. If we don't have a env here, we are hosed.
|
|
|
|
|
|
|
|
return (int) env->CallStaticIntMethod(mGeckoAppShellClass, jGetDpi);
|
2010-10-07 10:28:27 -07:00
|
|
|
}
|
|
|
|
|
2010-09-30 08:37:36 -07:00
|
|
|
void
|
2010-11-05 10:43:12 -07:00
|
|
|
AndroidBridge::ShowFilePicker(nsAString& aFilePath, nsAString& aFilters)
|
2010-09-30 08:37:36 -07:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::ShowFilePicker");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
jstring jstrFilers = env->NewString(nsPromiseFlatString(aFilters).get(),
|
2010-11-05 10:43:12 -07:00
|
|
|
aFilters.Length());
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstr = static_cast<jstring>(env->CallStaticObjectMethod(
|
2010-11-05 10:43:12 -07:00
|
|
|
mGeckoAppShellClass,
|
|
|
|
jShowFilePicker, jstrFilers));
|
2010-09-30 08:37:36 -07:00
|
|
|
aFilePath.Assign(nsJNIString(jstr));
|
|
|
|
}
|
|
|
|
|
2010-11-08 18:11:13 -08:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
AndroidBridge::SetFullScreen(bool aFullScreen)
|
2010-11-08 18:11:13 -08:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::SetFullScreen");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jSetFullScreen, aFullScreen);
|
2010-11-08 18:11:13 -08:00
|
|
|
}
|
|
|
|
|
2010-11-12 12:02:14 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::HideProgressDialogOnce()
|
|
|
|
{
|
|
|
|
static bool once = false;
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2010-11-12 12:02:14 -08:00
|
|
|
if (!once) {
|
2011-03-02 07:50:25 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::HideProgressDialogOnce");
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jHideProgressDialog);
|
2010-11-12 12:02:14 -08:00
|
|
|
once = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
bool
|
|
|
|
AndroidBridge::GetAccessibilityEnabled()
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetAccessibilityEnabled");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return env->CallStaticBooleanMethod(mGeckoAppShellClass, jGetAccessibilityEnabled);
|
2011-11-14 19:12:14 -08:00
|
|
|
}
|
|
|
|
|
2010-11-22 08:38:02 -08:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
AndroidBridge::PerformHapticFeedback(bool aIsLongPress)
|
2010-11-22 08:38:02 -08:00
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::PerformHapticFeedback");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass,
|
2010-11-22 08:38:02 -08:00
|
|
|
jPerformHapticFeedback, aIsLongPress);
|
|
|
|
}
|
|
|
|
|
2011-09-30 00:00:48 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::Vibrate(const nsTArray<PRUint32>& aPattern)
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2011-11-11 08:11:41 -08:00
|
|
|
AutoLocalJNIFrame frame;
|
|
|
|
|
2011-09-30 00:00:48 -07:00
|
|
|
ALOG_BRIDGE("AndroidBridge::Vibrate");
|
|
|
|
|
|
|
|
PRUint32 len = aPattern.Length();
|
|
|
|
if (!len) {
|
|
|
|
ALOG_BRIDGE(" invalid 0-length array");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's clear if this worth special-casing, but it creates less
|
|
|
|
// java junk, so dodges the GC.
|
|
|
|
if (len == 1) {
|
|
|
|
jlong d = aPattern[0];
|
|
|
|
if (d < 0) {
|
|
|
|
ALOG_BRIDGE(" invalid vibration duration < 0");
|
|
|
|
return;
|
|
|
|
}
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jVibrate1, d);
|
2011-09-30 00:00:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First element of the array vibrate() expects is how long to wait
|
|
|
|
// *before* vibrating. For us, this is always 0.
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jlongArray array = env->NewLongArray(len + 1);
|
2011-09-30 00:00:48 -07:00
|
|
|
if (!array) {
|
|
|
|
ALOG_BRIDGE(" failed to allocate array");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jlong* elts = env->GetLongArrayElements(array, nsnull);
|
2011-09-30 00:00:48 -07:00
|
|
|
elts[0] = 0;
|
|
|
|
for (PRUint32 i = 0; i < aPattern.Length(); ++i) {
|
|
|
|
jlong d = aPattern[i];
|
|
|
|
if (d < 0) {
|
|
|
|
ALOG_BRIDGE(" invalid vibration duration < 0");
|
2012-01-29 12:39:30 -08:00
|
|
|
env->ReleaseLongArrayElements(array, elts, JNI_ABORT);
|
2011-09-30 00:00:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
elts[i + 1] = d;
|
|
|
|
}
|
2012-01-29 12:39:30 -08:00
|
|
|
env->ReleaseLongArrayElements(array, elts, 0);
|
2011-09-30 00:00:48 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jVibrateA,
|
2011-09-30 00:00:48 -07:00
|
|
|
array, -1/*don't repeat*/);
|
|
|
|
// GC owns |array| now?
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::CancelVibrate()
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jCancelVibrate);
|
2011-09-30 00:00:48 -07:00
|
|
|
}
|
|
|
|
|
2011-01-20 03:06:13 -08:00
|
|
|
bool
|
|
|
|
AndroidBridge::IsNetworkLinkUp()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::IsNetworkLinkUp");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !!env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsNetworkLinkUp);
|
2011-01-20 03:06:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidBridge::IsNetworkLinkKnown()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::IsNetworkLinkKnown");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return !!env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsNetworkLinkKnown);
|
2011-01-20 03:06:13 -08:00
|
|
|
}
|
|
|
|
|
2011-02-27 07:50:56 -08:00
|
|
|
void
|
2011-03-16 16:17:59 -07:00
|
|
|
AndroidBridge::SetSelectedLocale(const nsAString& aLocale)
|
2011-02-28 20:25:11 -08:00
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::SetSelectedLocale");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
jstring jLocale = env->NewString(PromiseFlatString(aLocale).get(), aLocale.Length());
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jSetSelectedLocale, jLocale);
|
2011-02-27 07:50:56 -08:00
|
|
|
}
|
|
|
|
|
2011-03-30 11:04:41 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::GetSystemColors(AndroidSystemColors *aColors)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetSystemColors");
|
|
|
|
|
|
|
|
NS_ASSERTION(aColors != nsnull, "AndroidBridge::GetSystemColors: aColors is null!");
|
|
|
|
if (!aColors)
|
|
|
|
return;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2011-03-30 11:04:41 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetSystemColors);
|
2011-03-30 11:04:41 -07:00
|
|
|
jintArray arr = static_cast<jintArray>(obj);
|
|
|
|
if (!arr)
|
|
|
|
return;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jsize len = env->GetArrayLength(arr);
|
|
|
|
jint *elements = env->GetIntArrayElements(arr, 0);
|
2011-03-30 11:04:41 -07:00
|
|
|
|
|
|
|
PRUint32 colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor);
|
|
|
|
if (len < colorsCount)
|
|
|
|
colorsCount = len;
|
|
|
|
|
|
|
|
// Convert Android colors to nscolor by switching R and B in the ARGB 32 bit value
|
|
|
|
nscolor *colors = (nscolor*)aColors;
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < colorsCount; i++) {
|
|
|
|
PRUint32 androidColor = static_cast<PRUint32>(elements[i]);
|
|
|
|
PRUint8 r = (androidColor & 0x00ff0000) >> 16;
|
|
|
|
PRUint8 b = (androidColor & 0x000000ff);
|
|
|
|
colors[i] = androidColor & 0xff00ff00 | b << 16 | r;
|
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->ReleaseIntArrayElements(arr, elements, 0);
|
2011-03-30 11:04:41 -07:00
|
|
|
}
|
|
|
|
|
2011-06-13 14:02:13 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::GetIconForExtension(const nsACString& aFileExt, PRUint32 aIconSize, PRUint8 * const aBuf)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetIconForExtension");
|
|
|
|
NS_ASSERTION(aBuf != nsnull, "AndroidBridge::GetIconForExtension: aBuf is null!");
|
|
|
|
if (!aBuf)
|
|
|
|
return;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2011-06-13 14:02:13 -07:00
|
|
|
|
|
|
|
nsString fileExt;
|
|
|
|
CopyUTF8toUTF16(aFileExt, fileExt);
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrFileExt = env->NewString(nsPromiseFlatString(fileExt).get(), fileExt.Length());
|
2011-06-13 14:02:13 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetIconForExtension, jstrFileExt, aIconSize);
|
2011-06-13 14:02:13 -07:00
|
|
|
jbyteArray arr = static_cast<jbyteArray>(obj);
|
|
|
|
NS_ASSERTION(arr != nsnull, "AndroidBridge::GetIconForExtension: Returned pixels array is null!");
|
|
|
|
if (!arr)
|
|
|
|
return;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jsize len = env->GetArrayLength(arr);
|
|
|
|
jbyte *elements = env->GetByteArrayElements(arr, 0);
|
2011-06-13 14:02:13 -07:00
|
|
|
|
|
|
|
PRUint32 bufSize = aIconSize * aIconSize * 4;
|
|
|
|
NS_ASSERTION(len == bufSize, "AndroidBridge::GetIconForExtension: Pixels array is incomplete!");
|
|
|
|
if (len == bufSize)
|
|
|
|
memcpy(aBuf, elements, bufSize);
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->ReleaseByteArrayElements(arr, elements, 0);
|
2011-06-13 14:02:13 -07:00
|
|
|
}
|
|
|
|
|
2011-07-26 18:14:52 -07:00
|
|
|
bool
|
|
|
|
AndroidBridge::GetShowPasswordSetting()
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetShowPasswordSetting");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return env->CallStaticBooleanMethod(mGeckoAppShellClass, jGetShowPasswordSetting);
|
2011-07-26 18:14:52 -07:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::SetSurfaceView(jobject obj)
|
2011-11-04 06:47:18 -07:00
|
|
|
{
|
2010-06-03 13:56:36 -07:00
|
|
|
mSurfaceView.Init(obj);
|
2011-11-04 06:47:18 -07:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
void
|
2011-11-09 17:39:29 -08:00
|
|
|
AndroidBridge::SetSoftwareLayerClient(jobject obj)
|
2010-06-03 13:56:36 -07:00
|
|
|
{
|
2011-11-09 17:39:29 -08:00
|
|
|
mSoftwareLayerClient.Init(obj);
|
2010-06-03 13:56:36 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 06:40:00 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::ShowInputMethodPicker()
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::ShowInputMethodPicker");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jShowInputMethodPicker);
|
2010-11-10 06:40:00 -08:00
|
|
|
}
|
|
|
|
|
2010-06-25 17:52:37 -07:00
|
|
|
void *
|
|
|
|
AndroidBridge::CallEglCreateWindowSurface(void *dpy, void *config, AndroidGeckoSurfaceView &sview)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::CallEglCreateWindowSurface");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2010-06-25 17:52:37 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is basically:
|
|
|
|
*
|
|
|
|
* s = EGLContext.getEGL().eglCreateWindowSurface(new EGLDisplayImpl(dpy),
|
|
|
|
* new EGLConfigImpl(config),
|
|
|
|
* view.getHolder(), null);
|
|
|
|
* return s.mEGLSurface;
|
|
|
|
*
|
|
|
|
* We can't do it from java, because the EGLConfigImpl constructor is private.
|
|
|
|
*/
|
|
|
|
|
|
|
|
jobject surfaceHolder = sview.GetSurfaceHolder();
|
|
|
|
if (!surfaceHolder)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// grab some fields and methods we'll need
|
2012-01-29 12:39:30 -08:00
|
|
|
jmethodID constructConfig = env->GetMethodID(jEGLConfigImplClass, "<init>", "(I)V");
|
|
|
|
jmethodID constructDisplay = env->GetMethodID(jEGLDisplayImplClass, "<init>", "(I)V");
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jmethodID getEgl = env->GetStaticMethodID(jEGLContextClass, "getEGL", "()Ljavax/microedition/khronos/egl/EGL;");
|
|
|
|
jmethodID createWindowSurface = env->GetMethodID(jEGL10Class, "eglCreateWindowSurface", "(Ljavax/microedition/khronos/egl/EGLDisplay;Ljavax/microedition/khronos/egl/EGLConfig;Ljava/lang/Object;[I)Ljavax/microedition/khronos/egl/EGLSurface;");
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject egl = env->CallStaticObjectMethod(jEGLContextClass, getEgl);
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject jdpy = env->NewObject(jEGLDisplayImplClass, constructDisplay, (int) dpy);
|
|
|
|
jobject jconf = env->NewObject(jEGLConfigImplClass, constructConfig, (int) config);
|
2010-06-25 17:52:37 -07:00
|
|
|
|
|
|
|
// make the call
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject surf = env->CallObjectMethod(egl, createWindowSurface, jdpy, jconf, surfaceHolder, NULL);
|
2010-06-25 17:52:37 -07:00
|
|
|
if (!surf)
|
|
|
|
return nsnull;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jfieldID sfield = env->GetFieldID(jEGLSurfaceImplClass, "mEGLSurface", "I");
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jint realSurface = env->GetIntField(surf, sfield);
|
2010-06-25 17:52:37 -07:00
|
|
|
|
|
|
|
return (void*) realSurface;
|
|
|
|
}
|
|
|
|
|
2011-02-28 08:32:05 -08:00
|
|
|
bool
|
|
|
|
AndroidBridge::GetStaticIntField(const char *className, const char *fieldName, PRInt32* aInt)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetStaticIntField %s", fieldName);
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env, 3);
|
|
|
|
jclass cls = env->FindClass(className);
|
2011-02-28 08:32:05 -08:00
|
|
|
if (!cls)
|
|
|
|
return false;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jfieldID field = env->GetStaticFieldID(cls, fieldName, "I");
|
2011-02-28 08:32:05 -08:00
|
|
|
if (!field)
|
|
|
|
return false;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
*aInt = static_cast<PRInt32>(env->GetStaticIntField(cls, field));
|
2011-02-28 08:32:05 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-11 06:20:20 -07:00
|
|
|
bool
|
|
|
|
AndroidBridge::GetStaticStringField(const char *className, const char *fieldName, nsAString &result)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::GetStaticIntField %s", fieldName);
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env, 3);
|
|
|
|
jclass cls = env->FindClass(className);
|
2010-09-11 06:20:20 -07:00
|
|
|
if (!cls)
|
|
|
|
return false;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jfieldID field = env->GetStaticFieldID(cls, fieldName, "Ljava/lang/String;");
|
2010-09-11 06:20:20 -07:00
|
|
|
if (!field)
|
|
|
|
return false;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstr = (jstring) env->GetStaticObjectField(cls, field);
|
2010-09-11 06:20:20 -07:00
|
|
|
if (!jstr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
result.Assign(nsJNIString(jstr));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-21 14:34:29 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::SetKeepScreenOn(bool on)
|
|
|
|
{
|
2011-02-28 20:25:11 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::SetKeepScreenOn");
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(sBridge->mGeckoAppShellClass,
|
|
|
|
sBridge->jSetKeepScreenOn, on);
|
2010-12-21 14:34:29 -08:00
|
|
|
}
|
|
|
|
|
2010-06-03 13:56:36 -07:00
|
|
|
// Available for places elsewhere in the code to link to.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-06-03 13:56:36 -07:00
|
|
|
mozilla_AndroidBridge_SetMainThread(void *thr)
|
|
|
|
{
|
|
|
|
return AndroidBridge::Bridge()->SetMainThread(thr);
|
|
|
|
}
|
|
|
|
|
2010-10-15 11:16:45 -07:00
|
|
|
jclass GetGeckoAppShellClass()
|
|
|
|
{
|
|
|
|
return mozilla::AndroidBridge::GetGeckoAppShellClass();
|
|
|
|
}
|
2011-04-08 10:52:13 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::ScanMedia(const nsAString& aFile, const nsACString& aMimeType)
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
jstring jstrFile = env->NewString(nsPromiseFlatString(aFile).get(), aFile.Length());
|
2011-04-08 10:52:13 -07:00
|
|
|
|
|
|
|
nsString mimeType2;
|
|
|
|
CopyUTF8toUTF16(aMimeType, mimeType2);
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrMimeTypes = env->NewString(nsPromiseFlatString(mimeType2).get(), mimeType2.Length());
|
2011-04-08 10:52:13 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jScanMedia, jstrFile, jstrMimeTypes);
|
2011-04-08 10:52:13 -07:00
|
|
|
}
|
|
|
|
|
2011-08-08 19:37:57 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::CreateShortcut(const nsAString& aTitle, const nsAString& aURI, const nsAString& aIconData, const nsAString& aIntent)
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
jstring jstrTitle = env->NewString(nsPromiseFlatString(aTitle).get(), aTitle.Length());
|
|
|
|
jstring jstrURI = env->NewString(nsPromiseFlatString(aURI).get(), aURI.Length());
|
|
|
|
jstring jstrIconData = env->NewString(nsPromiseFlatString(aIconData).get(), aIconData.Length());
|
|
|
|
jstring jstrIntent = env->NewString(nsPromiseFlatString(aIntent).get(), aIntent.Length());
|
2011-08-08 19:37:57 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
if (!jstrURI || !jstrTitle || !jstrIconData)
|
|
|
|
return;
|
2011-08-08 19:37:57 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jCreateShortcut, jstrTitle, jstrURI, jstrIconData, jstrIntent);
|
2011-08-08 19:37:57 -07:00
|
|
|
}
|
|
|
|
|
2011-09-16 14:34:31 -07:00
|
|
|
void
|
2012-01-29 12:39:30 -08:00
|
|
|
AndroidBridge::PostToJavaThread(JNIEnv *env, nsIRunnable* aRunnable, bool aMainThread)
|
2011-09-16 14:34:31 -07:00
|
|
|
{
|
|
|
|
mRunnableQueue.AppendObject(aRunnable);
|
2012-01-29 00:49:02 -08:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jPostToJavaThread, (jboolean)aMainThread);
|
2011-09-16 14:34:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-29 12:39:30 -08:00
|
|
|
AndroidBridge::ExecuteNextRunnable(JNIEnv *env)
|
2011-09-16 14:34:31 -07:00
|
|
|
{
|
|
|
|
if (mRunnableQueue.Count() > 0) {
|
|
|
|
nsIRunnable* r = mRunnableQueue[0];
|
|
|
|
r->Run();
|
|
|
|
mRunnableQueue.RemoveObjectAt(0);
|
|
|
|
}
|
2011-10-25 08:39:32 -07:00
|
|
|
}
|
|
|
|
|
2011-09-21 09:46:00 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::OpenGraphicsLibraries()
|
2011-06-16 02:03:00 -07:00
|
|
|
{
|
2011-09-21 09:46:00 -07:00
|
|
|
if (!mOpenedGraphicsLibraries) {
|
2011-06-16 02:03:00 -07:00
|
|
|
// Try to dlopen libjnigraphics.so for direct bitmap access on
|
|
|
|
// Android 2.2+ (API level 8)
|
2011-09-21 09:46:00 -07:00
|
|
|
mOpenedGraphicsLibraries = true;
|
2011-09-28 11:43:02 -07:00
|
|
|
mHasNativeWindowAccess = false;
|
|
|
|
mHasNativeBitmapAccess = false;
|
2011-06-16 02:03:00 -07:00
|
|
|
|
2012-01-12 22:23:02 -08:00
|
|
|
void *handle = dlopen("libjnigraphics.so", RTLD_LAZY | RTLD_LOCAL);
|
2011-09-21 09:46:00 -07:00
|
|
|
if (handle) {
|
|
|
|
AndroidBitmap_getInfo = (int (*)(JNIEnv *, jobject, void *))dlsym(handle, "AndroidBitmap_getInfo");
|
|
|
|
AndroidBitmap_lockPixels = (int (*)(JNIEnv *, jobject, void **))dlsym(handle, "AndroidBitmap_lockPixels");
|
|
|
|
AndroidBitmap_unlockPixels = (int (*)(JNIEnv *, jobject))dlsym(handle, "AndroidBitmap_unlockPixels");
|
2011-06-16 02:03:00 -07:00
|
|
|
|
2011-09-28 11:43:02 -07:00
|
|
|
mHasNativeBitmapAccess = AndroidBitmap_getInfo && AndroidBitmap_lockPixels && AndroidBitmap_unlockPixels;
|
|
|
|
|
|
|
|
ALOG_BRIDGE("Successfully opened libjnigraphics.so, have native bitmap access? %d", mHasNativeBitmapAccess);
|
2011-09-21 09:46:00 -07:00
|
|
|
}
|
2011-06-16 02:03:00 -07:00
|
|
|
|
2011-09-21 09:46:00 -07:00
|
|
|
// Try to dlopen libandroid.so for and native window access on
|
|
|
|
// Android 2.3+ (API level 9)
|
2012-01-12 22:23:02 -08:00
|
|
|
handle = dlopen("libandroid.so", RTLD_LAZY | RTLD_LOCAL);
|
2011-09-21 09:46:00 -07:00
|
|
|
if (handle) {
|
|
|
|
ANativeWindow_fromSurface = (void* (*)(JNIEnv*, jobject))dlsym(handle, "ANativeWindow_fromSurface");
|
|
|
|
ANativeWindow_release = (void (*)(void*))dlsym(handle, "ANativeWindow_release");
|
|
|
|
ANativeWindow_setBuffersGeometry = (int (*)(void*, int, int, int)) dlsym(handle, "ANativeWindow_setBuffersGeometry");
|
|
|
|
ANativeWindow_lock = (int (*)(void*, void*, void*)) dlsym(handle, "ANativeWindow_lock");
|
|
|
|
ANativeWindow_unlockAndPost = (int (*)(void*))dlsym(handle, "ANativeWindow_unlockAndPost");
|
2011-09-21 09:46:00 -07:00
|
|
|
|
2011-09-28 11:43:02 -07:00
|
|
|
mHasNativeWindowAccess = ANativeWindow_fromSurface && ANativeWindow_release && ANativeWindow_lock && ANativeWindow_unlockAndPost;
|
|
|
|
|
|
|
|
ALOG_BRIDGE("Successfully opened libandroid.so, have native window access? %d", mHasNativeWindowAccess);
|
|
|
|
}
|
2011-09-24 08:51:46 -07:00
|
|
|
}
|
2011-09-21 09:46:00 -07:00
|
|
|
}
|
|
|
|
|
2011-08-04 00:32:57 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::FireAndWaitForTracerEvent() {
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass,
|
|
|
|
jFireAndWaitForTracerEvent);
|
2011-08-04 00:32:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class TracerRunnable : public nsRunnable{
|
|
|
|
public:
|
|
|
|
TracerRunnable() {
|
|
|
|
mTracerLock = new Mutex("TracerRunnable");
|
|
|
|
mTracerCondVar = new CondVar(*mTracerLock, "TracerRunnable");
|
|
|
|
mMainThread = do_GetMainThread();
|
|
|
|
|
|
|
|
}
|
|
|
|
~TracerRunnable() {
|
|
|
|
delete mTracerCondVar;
|
|
|
|
delete mTracerLock;
|
|
|
|
mTracerLock = nsnull;
|
|
|
|
mTracerCondVar = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult Run() {
|
|
|
|
MutexAutoLock lock(*mTracerLock);
|
|
|
|
if (!AndroidBridge::Bridge())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
AndroidBridge::Bridge()->FireAndWaitForTracerEvent();
|
|
|
|
mHasRun = PR_TRUE;
|
|
|
|
mTracerCondVar->Notify();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Fire() {
|
|
|
|
if (!mTracerLock || !mTracerCondVar)
|
|
|
|
return false;
|
|
|
|
MutexAutoLock lock(*mTracerLock);
|
|
|
|
mHasRun = PR_FALSE;
|
|
|
|
mMainThread->Dispatch(this, NS_DISPATCH_NORMAL);
|
|
|
|
while (!mHasRun)
|
|
|
|
mTracerCondVar->Wait();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Signal() {
|
|
|
|
MutexAutoLock lock(*mTracerLock);
|
|
|
|
mHasRun = PR_TRUE;
|
|
|
|
mTracerCondVar->Notify();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Mutex* mTracerLock;
|
|
|
|
CondVar* mTracerCondVar;
|
|
|
|
PRBool mHasRun;
|
|
|
|
nsCOMPtr<nsIThread> mMainThread;
|
|
|
|
|
|
|
|
};
|
|
|
|
nsCOMPtr<TracerRunnable> sTracerRunnable;
|
|
|
|
|
|
|
|
bool InitWidgetTracing() {
|
|
|
|
if (!sTracerRunnable)
|
|
|
|
sTracerRunnable = new TracerRunnable();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CleanUpWidgetTracing() {
|
|
|
|
if (sTracerRunnable)
|
|
|
|
delete sTracerRunnable;
|
|
|
|
sTracerRunnable = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FireAndWaitForTracerEvent() {
|
|
|
|
if (sTracerRunnable)
|
|
|
|
return sTracerRunnable->Fire();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SignalTracerThread()
|
|
|
|
{
|
|
|
|
if (sTracerRunnable)
|
|
|
|
return sTracerRunnable->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-09-21 09:46:00 -07:00
|
|
|
bool
|
|
|
|
AndroidBridge::HasNativeBitmapAccess()
|
|
|
|
{
|
|
|
|
OpenGraphicsLibraries();
|
2011-06-16 02:03:00 -07:00
|
|
|
|
|
|
|
return mHasNativeBitmapAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidBridge::ValidateBitmap(jobject bitmap, int width, int height)
|
|
|
|
{
|
|
|
|
// This structure is defined in Android API level 8's <android/bitmap.h>
|
|
|
|
// Because we can't depend on this, we get the function pointers via dlsym
|
|
|
|
// and define this struct ourselves.
|
|
|
|
struct BitmapInfo {
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t stride;
|
|
|
|
uint32_t format;
|
|
|
|
uint32_t flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
int err;
|
|
|
|
struct BitmapInfo info = { 0, };
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((err = AndroidBitmap_getInfo(env, bitmap, &info)) != 0) {
|
2011-06-16 02:03:00 -07:00
|
|
|
ALOG_BRIDGE("AndroidBitmap_getInfo failed! (error %d)", err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.width != width || info.height != height)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-26 17:25:41 -07:00
|
|
|
bool
|
|
|
|
AndroidBridge::InitCamera(const nsCString& contentType, PRUint32 camera, PRUint32 *width, PRUint32 *height, PRUint32 *fps)
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2011-09-26 17:25:41 -07:00
|
|
|
|
|
|
|
NS_ConvertASCIItoUTF16 s(contentType);
|
2012-01-29 12:39:30 -08:00
|
|
|
jstring jstrContentType = env->NewString(s.get(), NS_strlen(s.get()));
|
|
|
|
jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass, jInitCamera, jstrContentType, camera, *width, *height);
|
2011-09-26 17:25:41 -07:00
|
|
|
jintArray arr = static_cast<jintArray>(obj);
|
|
|
|
if (!arr)
|
|
|
|
return false;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jint *elements = env->GetIntArrayElements(arr, 0);
|
2011-09-26 17:25:41 -07:00
|
|
|
|
|
|
|
*width = elements[1];
|
|
|
|
*height = elements[2];
|
|
|
|
*fps = elements[3];
|
|
|
|
|
|
|
|
bool res = elements[0] == 1;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->ReleaseIntArrayElements(arr, elements, 0);
|
2011-09-26 17:25:41 -07:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::CloseCamera() {
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jCloseCamera);
|
2011-09-26 17:25:41 -07:00
|
|
|
}
|
|
|
|
|
2011-11-02 08:35:11 -07:00
|
|
|
void
|
|
|
|
AndroidBridge::EnableBatteryNotifications()
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::EnableBatteryObserver");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableBatteryNotifications);
|
2011-11-02 08:35:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::DisableBatteryNotifications()
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::DisableBatteryNotifications");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableBatteryNotifications);
|
2011-11-02 08:35:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetCurrentBatteryInformation");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2011-11-02 08:35:11 -07:00
|
|
|
|
|
|
|
// To prevent calling too many methods through JNI, the Java method returns
|
2011-11-09 00:56:37 -08:00
|
|
|
// an array of double even if we actually want a double and a boolean.
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetCurrentBatteryInformation);
|
2011-11-09 00:56:37 -08:00
|
|
|
jdoubleArray arr = static_cast<jdoubleArray>(obj);
|
2012-01-29 12:39:30 -08:00
|
|
|
if (!arr || env->GetArrayLength(arr) != 3) {
|
2011-11-02 08:35:11 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jdouble* info = env->GetDoubleArrayElements(arr, 0);
|
2011-11-02 08:35:11 -07:00
|
|
|
|
|
|
|
aBatteryInfo->level() = info[0];
|
|
|
|
aBatteryInfo->charging() = info[1] == 1.0f;
|
2011-11-09 06:13:37 -08:00
|
|
|
aBatteryInfo->remainingTime() = info[2];
|
2011-11-02 08:35:11 -07:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->ReleaseDoubleArrayElements(arr, info, 0);
|
2011-11-02 08:35:11 -07:00
|
|
|
}
|
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::HandleGeckoMessage(const nsAString &aMessage, nsAString &aRet)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("%s", __PRETTY_FUNCTION__);
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
2011-11-14 19:12:14 -08:00
|
|
|
return;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
|
|
|
jstring jMessage = env->NewString(nsPromiseFlatString(aMessage).get(), aMessage.Length());
|
2011-11-14 19:12:14 -08:00
|
|
|
jstring returnMessage = static_cast<jstring>(env->CallStaticObjectMethod(mGeckoAppShellClass, jHandleGeckoMessage, jMessage));
|
|
|
|
|
|
|
|
jthrowable ex = env->ExceptionOccurred();
|
|
|
|
if (ex) {
|
|
|
|
env->ExceptionDescribe();
|
|
|
|
env->ExceptionClear();
|
|
|
|
}
|
|
|
|
nsJNIString jniStr(returnMessage);
|
|
|
|
aRet.Assign(jniStr);
|
|
|
|
ALOG_BRIDGE("leaving %s", __PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
|
2011-11-17 19:20:29 -08:00
|
|
|
static nsCOMPtr<nsIAndroidDrawMetadataProvider> gDrawMetadataProvider = NULL;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAndroidDrawMetadataProvider>
|
|
|
|
AndroidBridge::GetDrawMetadataProvider()
|
|
|
|
{
|
|
|
|
return gDrawMetadataProvider;
|
|
|
|
}
|
|
|
|
|
2011-11-14 19:12:14 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::CheckURIVisited(const nsAString& aURI)
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
|
|
|
jstring jstrURI = env->NewString(nsPromiseFlatString(aURI).get(), aURI.Length());
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jCheckUriVisited, jstrURI);
|
2011-11-14 19:12:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::MarkURIVisited(const nsAString& aURI)
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
|
|
|
jstring jstrURI = env->NewString(nsPromiseFlatString(aURI).get(), aURI.Length());
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jMarkUriVisited, jstrURI);
|
2011-11-02 08:35:11 -07:00
|
|
|
}
|
|
|
|
|
2012-03-07 16:24:38 -08:00
|
|
|
void AndroidBridge::EmitGeckoAccessibilityEvent (PRInt32 eventType, const nsTArray<nsString>& text, const nsAString& description, bool enabled, bool checked, bool password) {
|
|
|
|
AutoLocalJNIFrame jniFrame;
|
|
|
|
jobjectArray jarrayText = mJNIEnv->NewObjectArray(text.Length(),
|
|
|
|
jStringClass, 0);
|
|
|
|
for (PRUint32 i = 0; i < text.Length() ; i++) {
|
|
|
|
jstring jstrText = mJNIEnv->NewString(nsPromiseFlatString(text[i]).get(),
|
|
|
|
text[i].Length());
|
|
|
|
mJNIEnv->SetObjectArrayElement(jarrayText, i, jstrText);
|
|
|
|
}
|
|
|
|
jstring jstrDescription = mJNIEnv->NewString(nsPromiseFlatString(description).get(), description.Length());
|
|
|
|
mJNIEnv->CallStaticVoidMethod(mGeckoAppShellClass, jEmitGeckoAccessibilityEvent, eventType, jarrayText, jstrDescription, enabled, checked, password);
|
2011-11-04 06:56:24 -07:00
|
|
|
}
|
|
|
|
|
2011-11-25 01:48:51 -08:00
|
|
|
PRUint16
|
|
|
|
AndroidBridge::GetNumberOfMessagesForText(const nsAString& aText)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetNumberOfMessagesForText");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
jstring jText = env->NewString(PromiseFlatString(aText).get(), aText.Length());
|
|
|
|
return env->CallStaticIntMethod(mGeckoAppShellClass, jNumberOfMessages, jText);
|
2011-11-25 01:48:51 -08:00
|
|
|
}
|
|
|
|
|
2011-11-20 15:00:46 -08:00
|
|
|
void
|
2012-01-13 05:26:50 -08:00
|
|
|
AndroidBridge::SendMessage(const nsAString& aNumber, const nsAString& aMessage, PRInt32 aRequestId, PRUint64 aProcessId)
|
2011-11-20 15:00:46 -08:00
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::SendMessage");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
|
|
|
jstring jNumber = env->NewString(PromiseFlatString(aNumber).get(), aNumber.Length());
|
|
|
|
jstring jMessage = env->NewString(PromiseFlatString(aMessage).get(), aMessage.Length());
|
2011-11-20 15:00:46 -08:00
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jSendMessage, jNumber, jMessage, aRequestId, aProcessId);
|
2011-11-20 15:00:46 -08:00
|
|
|
}
|
|
|
|
|
2012-01-13 05:25:47 -08:00
|
|
|
PRInt32
|
|
|
|
AndroidBridge::SaveSentMessage(const nsAString& aRecipient,
|
|
|
|
const nsAString& aBody, PRUint64 aDate)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::SaveSentMessage");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env, 1);
|
|
|
|
jstring jRecipient = env->NewString(PromiseFlatString(aRecipient).get(), aRecipient.Length());
|
|
|
|
jstring jBody = env->NewString(PromiseFlatString(aBody).get(), aBody.Length());
|
|
|
|
return env->CallStaticIntMethod(mGeckoAppShellClass, jSaveSentMessage, jRecipient, jBody, aDate);
|
2012-01-13 05:25:47 -08:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:08:58 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::GetMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetMessage");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = env;
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jGetMessage, aMessageId, aRequestId, aProcessId);
|
2011-12-22 14:08:58 -08:00
|
|
|
}
|
|
|
|
|
2011-12-22 14:15:28 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::DeleteMessage(PRInt32 aMessageId, PRInt32 aRequestId, PRUint64 aProcessId)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::DeleteMessage");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jDeleteMessage, aMessageId, aRequestId, aProcessId);
|
2011-12-22 14:15:28 -08:00
|
|
|
}
|
|
|
|
|
2011-12-20 00:07:25 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::CreateMessageList(const dom::sms::SmsFilterData& aFilter, bool aReverse,
|
|
|
|
PRInt32 aRequestId, PRUint64 aProcessId)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::CreateMessageList");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2011-12-20 00:07:25 -08:00
|
|
|
|
|
|
|
jobjectArray numbers =
|
2012-01-29 12:39:30 -08:00
|
|
|
(jobjectArray)env->NewObjectArray(aFilter.numbers().Length(),
|
2012-03-07 16:24:38 -08:00
|
|
|
jStringClass,
|
|
|
|
env->NewStringUTF(""));
|
2011-12-20 00:07:25 -08:00
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < aFilter.numbers().Length(); ++i) {
|
2012-01-29 12:39:30 -08:00
|
|
|
env->SetObjectArrayElement(numbers, i,
|
|
|
|
env->NewStringUTF(NS_ConvertUTF16toUTF8(aFilter.numbers()[i]).get()));
|
2011-12-20 00:07:25 -08:00
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jCreateMessageList,
|
2011-12-20 00:07:25 -08:00
|
|
|
aFilter.startDate(), aFilter.endDate(),
|
|
|
|
numbers, aFilter.numbers().Length(),
|
|
|
|
aFilter.delivery(), aReverse, aRequestId,
|
|
|
|
aProcessId);
|
|
|
|
}
|
|
|
|
|
2011-12-22 14:16:59 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::GetNextMessageInList(PRInt32 aListId, PRInt32 aRequestId, PRUint64 aProcessId)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetNextMessageInList");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jGetNextMessageinList, aListId, aRequestId, aProcessId);
|
2011-12-22 14:16:59 -08:00
|
|
|
}
|
|
|
|
|
2012-01-17 10:43:08 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::ClearMessageList(PRInt32 aListId)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::ClearMessageList");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jClearMessageList, aListId);
|
2012-01-17 10:43:08 -08:00
|
|
|
}
|
|
|
|
|
2012-01-16 05:44:07 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo)
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::GetCurrentNetworkInformation");
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AutoLocalJNIFrame jniFrame(env);
|
2012-01-16 05:44:07 -08:00
|
|
|
|
|
|
|
// To prevent calling too many methods through JNI, the Java method returns
|
|
|
|
// an array of double even if we actually want a double and a boolean.
|
2012-01-29 12:39:30 -08:00
|
|
|
jobject obj = env->CallStaticObjectMethod(mGeckoAppShellClass, jGetCurrentNetworkInformation);
|
2012-01-16 05:44:07 -08:00
|
|
|
jdoubleArray arr = static_cast<jdoubleArray>(obj);
|
2012-01-29 12:39:30 -08:00
|
|
|
if (!arr || env->GetArrayLength(arr) != 2) {
|
2012-01-16 05:44:07 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
jdouble* info = env->GetDoubleArrayElements(arr, 0);
|
2012-01-16 05:44:07 -08:00
|
|
|
|
|
|
|
aNetworkInfo->bandwidth() = info[0];
|
|
|
|
aNetworkInfo->canBeMetered() = info[1] == 1.0f;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
env->ReleaseDoubleArrayElements(arr, info, 0);
|
2012-01-16 05:44:07 -08:00
|
|
|
}
|
|
|
|
|
2012-01-16 06:01:07 -08:00
|
|
|
void
|
|
|
|
AndroidBridge::EnableNetworkNotifications()
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::EnableNetworkNotifications");
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jEnableNetworkNotifications);
|
2012-01-16 06:01:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::DisableNetworkNotifications()
|
|
|
|
{
|
|
|
|
ALOG_BRIDGE("AndroidBridge::DisableNetworkNotifications");
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jDisableNetworkNotifications);
|
2012-01-16 06:01:07 -08:00
|
|
|
}
|
|
|
|
|
2011-06-16 02:03:00 -07:00
|
|
|
void *
|
|
|
|
AndroidBridge::LockBitmap(jobject bitmap)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
void *buf;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
if ((err = AndroidBitmap_lockPixels(env, bitmap, &buf)) != 0) {
|
2011-06-16 02:03:00 -07:00
|
|
|
ALOG_BRIDGE("AndroidBitmap_lockPixels failed! (error %d)", err);
|
|
|
|
buf = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::UnlockBitmap(jobject bitmap)
|
|
|
|
{
|
|
|
|
int err;
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((err = AndroidBitmap_unlockPixels(env, bitmap)) != 0)
|
2011-06-16 02:03:00 -07:00
|
|
|
ALOG_BRIDGE("AndroidBitmap_unlockPixels failed! (error %d)", err);
|
|
|
|
}
|
2011-09-21 09:46:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidBridge::HasNativeWindowAccess()
|
|
|
|
{
|
|
|
|
OpenGraphicsLibraries();
|
|
|
|
|
|
|
|
return mHasNativeWindowAccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
AndroidBridge::AcquireNativeWindow(jobject surface)
|
|
|
|
{
|
|
|
|
if (!HasNativeWindowAccess())
|
|
|
|
return nsnull;
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return ANativeWindow_fromSurface(env, surface);
|
2011-09-21 09:46:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::ReleaseNativeWindow(void *window)
|
|
|
|
{
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ANativeWindow_release(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-01-31 06:40:58 -08:00
|
|
|
AndroidBridge::SetNativeWindowFormat(void *window, int width, int height, int format)
|
2011-09-21 09:46:00 -07:00
|
|
|
{
|
2012-01-31 06:40:58 -08:00
|
|
|
return ANativeWindow_setBuffersGeometry(window, width, height, format) == 0;
|
2011-09-21 09:46:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidBridge::LockWindow(void *window, unsigned char **bits, int *width, int *height, int *format, int *stride)
|
|
|
|
{
|
|
|
|
/* Copied from native_window.h in Android NDK (platform-9) */
|
|
|
|
typedef struct ANativeWindow_Buffer {
|
|
|
|
// The number of pixels that are show horizontally.
|
|
|
|
int32_t width;
|
|
|
|
|
|
|
|
// The number of pixels that are shown vertically.
|
|
|
|
int32_t height;
|
|
|
|
|
|
|
|
// The number of *pixels* that a line in the buffer takes in
|
|
|
|
// memory. This may be >= width.
|
|
|
|
int32_t stride;
|
|
|
|
|
|
|
|
// The format of the buffer. One of WINDOW_FORMAT_*
|
|
|
|
int32_t format;
|
|
|
|
|
|
|
|
// The actual bits.
|
|
|
|
void* bits;
|
|
|
|
|
|
|
|
// Do not touch.
|
|
|
|
uint32_t reserved[6];
|
|
|
|
} ANativeWindow_Buffer;
|
|
|
|
|
|
|
|
int err;
|
|
|
|
ANativeWindow_Buffer buffer;
|
|
|
|
|
|
|
|
*bits = NULL;
|
|
|
|
*width = *height = *format = 0;
|
|
|
|
if ((err = ANativeWindow_lock(window, (void*)&buffer, NULL)) != 0) {
|
|
|
|
ALOG_BRIDGE("ANativeWindow_lock failed! (error %d)", err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bits = (unsigned char*)buffer.bits;
|
|
|
|
*width = buffer.width;
|
|
|
|
*height = buffer.height;
|
|
|
|
*format = buffer.format;
|
|
|
|
*stride = buffer.stride;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AndroidBridge::UnlockWindow(void* window)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if ((err = ANativeWindow_unlockAndPost(window)) != 0) {
|
|
|
|
ALOG_BRIDGE("ANativeWindow_unlockAndPost failed! (error %d)", err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-10 17:40:17 -07:00
|
|
|
|
2011-12-14 13:53:38 -08:00
|
|
|
bool
|
|
|
|
AndroidBridge::IsTablet()
|
|
|
|
{
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return env->CallStaticBooleanMethod(mGeckoAppShellClass, jIsTablet);
|
2011-12-14 13:53:38 -08:00
|
|
|
}
|
|
|
|
|
2011-10-10 17:40:17 -07:00
|
|
|
/* Implementation file */
|
|
|
|
NS_IMPL_ISUPPORTS1(nsAndroidBridge, nsIAndroidBridge)
|
|
|
|
|
|
|
|
nsAndroidBridge::nsAndroidBridge()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAndroidBridge::~nsAndroidBridge()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void handleGeckoEvent (in AString message); */
|
2011-10-24 10:05:18 -07:00
|
|
|
NS_IMETHODIMP nsAndroidBridge::HandleGeckoMessage(const nsAString & message, nsAString &aRet NS_OUTPARAM)
|
2011-10-10 17:40:17 -07:00
|
|
|
{
|
2011-10-24 10:05:18 -07:00
|
|
|
AndroidBridge::Bridge()->HandleGeckoMessage(message, aRet);
|
2011-10-10 17:40:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-11-17 19:20:29 -08:00
|
|
|
|
|
|
|
/* void SetDrawMetadataProvider (in nsIAndroidDrawMetadataProvider message); */
|
|
|
|
NS_IMETHODIMP nsAndroidBridge::SetDrawMetadataProvider(nsIAndroidDrawMetadataProvider *aProvider)
|
|
|
|
{
|
|
|
|
gDrawMetadataProvider = aProvider;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-24 16:31:33 -08:00
|
|
|
void
|
2012-02-01 15:01:47 -08:00
|
|
|
AndroidBridge::SetPreventPanning(bool aPreventPanning) {
|
2012-01-24 16:31:33 -08:00
|
|
|
ALOG_BRIDGE("AndroidBridge::PreventPanning");
|
2012-01-29 12:39:30 -08:00
|
|
|
JNIEnv *env = GetJNIEnv();
|
|
|
|
if (!env)
|
|
|
|
return;
|
|
|
|
|
2012-02-01 15:01:47 -08:00
|
|
|
env->CallStaticVoidMethod(mGeckoAppShellClass, jSetPreventPanning, (jboolean)aPreventPanning);
|
2012-01-24 16:31:33 -08:00
|
|
|
}
|
|
|
|
|
2012-01-29 12:39:30 -08:00
|
|
|
|
|
|
|
// DO NOT USE THIS unless you need to access JNI from
|
|
|
|
// non-main threads. This is probably not what you want.
|
|
|
|
// Questions, ask blassey or dougt.
|
|
|
|
|
|
|
|
static void
|
|
|
|
JavaThreadDetachFunc(void *arg)
|
|
|
|
{
|
|
|
|
JNIEnv *env = (JNIEnv*) arg;
|
|
|
|
JavaVM *vm = NULL;
|
|
|
|
env->GetJavaVM(&vm);
|
|
|
|
vm->DetachCurrentThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
JNIEnv * GetJNIForThread()
|
|
|
|
{
|
|
|
|
JNIEnv *jEnv = NULL;
|
|
|
|
JavaVM *jVm = mozilla::AndroidBridge::GetVM();
|
|
|
|
if (!jVm) {
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "GetJNIForThread", "Returned a null VM");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
int status = jVm->GetEnv((void**) &jEnv, JNI_VERSION_1_2);
|
|
|
|
if (status < 0) {
|
|
|
|
|
|
|
|
status = jVm->AttachCurrentThread(&jEnv, NULL);
|
|
|
|
if (status < 0) {
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "GetJNIForThread", "Could not attach");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
static PRUintn sJavaEnvThreadIndex = 0;
|
|
|
|
PR_NewThreadPrivateIndex(&sJavaEnvThreadIndex, JavaThreadDetachFunc);
|
|
|
|
PR_SetThreadPrivate(sJavaEnvThreadIndex, jEnv);
|
|
|
|
}
|
|
|
|
if (!jEnv) {
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "GetJNIForThread", "returning NULL");
|
|
|
|
}
|
|
|
|
return jEnv;
|
|
|
|
}
|
|
|
|
}
|
2012-01-31 06:40:58 -08:00
|
|
|
|
|
|
|
jobject
|
|
|
|
AndroidBridge::CreateSurface()
|
|
|
|
{
|
|
|
|
#ifndef MOZ_JAVA_COMPOSITOR
|
|
|
|
return NULL;
|
|
|
|
#else
|
|
|
|
AutoLocalJNIFrame frame(1);
|
|
|
|
|
|
|
|
JNIEnv* env = GetJNIForThread();
|
|
|
|
jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
|
|
|
|
|
|
|
|
jmethodID method = env->GetStaticMethodID(cls,
|
|
|
|
"createSurface",
|
|
|
|
"()Landroid/view/Surface;");
|
|
|
|
|
|
|
|
jobject surface = env->CallStaticObjectMethod(cls, method);
|
|
|
|
if (surface)
|
|
|
|
env->NewGlobalRef(surface);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::DestroySurface(jobject surface)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
AutoLocalJNIFrame frame(1);
|
|
|
|
|
|
|
|
JNIEnv* env = GetJNIForThread();
|
|
|
|
jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
|
|
|
|
|
|
|
|
jmethodID method = env->GetStaticMethodID(cls,
|
|
|
|
"destroySurface",
|
|
|
|
"(Landroid/view/Surface;)V");
|
|
|
|
env->CallStaticVoidMethod(cls, method, surface);
|
|
|
|
env->DeleteGlobalRef(surface);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::ShowSurface(jobject surface, const gfxRect& aRect, bool aInverted, bool aBlend)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
AutoLocalJNIFrame frame;
|
|
|
|
|
|
|
|
JNIEnv* env = GetJNIForThread();
|
|
|
|
jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
|
|
|
|
|
|
|
|
nsAutoString metadata;
|
|
|
|
nsCOMPtr<nsIAndroidDrawMetadataProvider> metadataProvider = GetDrawMetadataProvider();
|
|
|
|
metadataProvider->GetDrawMetadata(metadata);
|
|
|
|
|
|
|
|
jstring jMetadata = env->NewString(nsPromiseFlatString(metadata).get(), metadata.Length());
|
|
|
|
|
|
|
|
jmethodID method = env->GetStaticMethodID(cls,
|
|
|
|
"showSurface",
|
|
|
|
"(Landroid/view/Surface;IIIIZZLjava/lang/String;)V");
|
|
|
|
|
|
|
|
env->CallStaticVoidMethod(cls, method, surface,
|
|
|
|
(int)aRect.x, (int)aRect.y,
|
|
|
|
(int)aRect.width, (int)aRect.height,
|
|
|
|
aInverted, aBlend, jMetadata);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AndroidBridge::HideSurface(jobject surface)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_JAVA_COMPOSITOR
|
|
|
|
AutoLocalJNIFrame frame(1);
|
|
|
|
|
|
|
|
JNIEnv* env = GetJNIForThread();
|
|
|
|
jclass cls = env->FindClass("org/mozilla/gecko/GeckoAppShell");
|
|
|
|
|
|
|
|
jmethodID method = env->GetStaticMethodID(cls,
|
|
|
|
"hideSurface",
|
|
|
|
"(Landroid/view/Surface;)V");
|
|
|
|
env->CallStaticVoidMethod(cls, method, surface);
|
|
|
|
#endif
|
|
|
|
}
|
2012-02-03 22:48:26 -08:00
|
|
|
|
|
|
|
|
2012-02-17 10:52:26 -08:00
|
|
|
/* attribute nsIAndroidBrowserApp browserApp; */
|
|
|
|
NS_IMETHODIMP nsAndroidBridge::GetBrowserApp(nsIAndroidBrowserApp * *aBrowserApp)
|
|
|
|
{
|
|
|
|
if (nsAppShell::gAppShell)
|
|
|
|
nsAppShell::gAppShell->GetBrowserApp(aBrowserApp);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHODIMP nsAndroidBridge::SetBrowserApp(nsIAndroidBrowserApp *aBrowserApp)
|
|
|
|
{
|
|
|
|
if (nsAppShell::gAppShell)
|
|
|
|
nsAppShell::gAppShell->SetBrowserApp(aBrowserApp);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
jobject JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *jenv, jclass, jlong size);
|
|
|
|
|
|
|
|
|
2012-03-12 11:05:43 -07:00
|
|
|
nsresult AndroidBridge::TakeScreenshot(nsIDOMWindow *window, PRInt32 srcX, PRInt32 srcY, PRInt32 srcW, PRInt32 srcH, PRInt32 dstW, PRInt32 dstH, PRInt32 tabId, float scale)
|
2012-02-03 22:48:26 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(window);
|
|
|
|
if (!win)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsRefPtr<nsPresContext> presContext;
|
|
|
|
nsIDocShell* docshell = win->GetDocShell();
|
|
|
|
if (docshell) {
|
|
|
|
docshell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
}
|
|
|
|
if (!presContext)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nscolor bgColor = NS_RGB(255, 255, 255);
|
|
|
|
nsIPresShell* presShell = presContext->PresShell();
|
|
|
|
PRUint32 renderDocFlags = (nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING |
|
|
|
|
nsIPresShell::RENDER_DOCUMENT_RELATIVE);
|
|
|
|
nsRect r(nsPresContext::CSSPixelsToAppUnits(srcX),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(srcY),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(srcW),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(srcH));
|
|
|
|
|
2012-02-17 10:52:26 -08:00
|
|
|
JNIEnv* jenv = AndroidBridge::GetJNIEnv();
|
|
|
|
if (!jenv)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRUint32 stride = dstW * 2;
|
|
|
|
PRUint32 bufferSize = dstH * stride;
|
|
|
|
|
|
|
|
jobject buffer = Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(jenv, NULL, bufferSize);
|
|
|
|
if (!buffer)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
void* data = jenv->GetDirectBufferAddress(buffer);
|
2012-03-12 11:05:43 -07:00
|
|
|
memset(data, 0, bufferSize);
|
2012-02-17 10:52:26 -08:00
|
|
|
nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(static_cast<unsigned char*>(data), nsIntSize(dstW, dstH), stride, gfxASurface::ImageFormatRGB16_565);
|
2012-02-03 22:48:26 -08:00
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(surf);
|
2012-03-12 11:05:43 -07:00
|
|
|
context->Scale(scale * dstW / srcW, scale * dstH / srcH);
|
2012-02-03 22:48:26 -08:00
|
|
|
nsresult rv = presShell->RenderDocument(r, renderDocFlags, bgColor, context);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-02-17 10:52:26 -08:00
|
|
|
AndroidBridge::AutoLocalJNIFrame jniFrame(jenv, 1);
|
|
|
|
jenv->CallStaticVoidMethod(AndroidBridge::Bridge()->mGeckoAppShellClass, AndroidBridge::Bridge()->jNotifyScreenShot, buffer, tabId, dstW, dstH);
|
2012-02-03 22:48:26 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|