Bug 918309 - Import and use public domain JNI.jsm implementation; r=wesj

This commit is contained in:
Myk Melez 2014-08-08 10:04:01 -07:00
parent 341da280cf
commit e714df250d
4 changed files with 1185 additions and 192 deletions

View File

@ -7,21 +7,37 @@ Components.utils.import("resource://gre/modules/ctypes.jsm");
Components.utils.import("resource://gre/modules/JNI.jsm");
add_task(function test_JNI() {
let iconSize = -1;
let jni = null;
var jenv = null;
try {
jni = new JNI();
let cls = jni.findClass("org/mozilla/gecko/GeckoAppShell");
let method = jni.getStaticMethodID(cls, "getPreferredIconSize", "()I");
iconSize = jni.callStaticIntMethod(cls, method);
jenv = JNI.GetForThread();
// Test a simple static method.
var geckoAppShell = JNI.LoadClass(jenv, "org.mozilla.gecko.GeckoAppShell", {
static_methods: [
{ name: "getPreferredIconSize", sig: "()I" }
],
});
let iconSize = -1;
iconSize = geckoAppShell.getPreferredIconSize();
do_check_neq(iconSize, -1);
// Test GeckoNetworkManager methods that are accessed by PaymentsUI.js.
// The return values can vary, so we can't test for equivalence, but we
// can ensure that the method calls return values of the correct type.
let jGeckoNetworkManager = JNI.LoadClass(jenv, "org/mozilla/gecko/GeckoNetworkManager", {
static_methods: [
{ name: "getMNC", sig: "()I" },
{ name: "getMCC", sig: "()I" },
],
});
do_check_eq(typeof jGeckoNetworkManager.getMNC(), "number");
do_check_eq(typeof jGeckoNetworkManager.getMCC(), "number");
} finally {
if (jni != null) {
jni.close();
if (jenv) {
JNI.UnloadClasses(jenv);
}
}
do_check_neq(iconSize, -1);
});
run_next_test();

View File

@ -3172,11 +3172,14 @@ Tab.prototype = {
this.id = aParams.tabID;
stub = true;
} else {
let jni = new JNI();
let cls = jni.findClass("org/mozilla/gecko/Tabs");
let method = jni.getStaticMethodID(cls, "getNextTabId", "()I");
this.id = jni.callStaticIntMethod(cls, method);
jni.close();
let jenv = JNI.GetForThread();
let jTabs = JNI.LoadClass(jenv, "org.mozilla.gecko.Tabs", {
static_methods: [
{ name: "getNextTabId", sig: "()I" }
],
});
this.id = jTabs.getNextTabId();
JNI.UnloadClasses(jenv);
}
this.desktopMode = ("desktopMode" in aParams) ? aParams.desktopMode : false;

View File

@ -142,11 +142,15 @@ PaymentUI.prototype = {
},
_getNetworkInfo: function(type) {
let jni = new JNI();
let cls = jni.findClass("org/mozilla/gecko/GeckoNetworkManager");
let method = jni.getStaticMethodID(cls, "get" + type.toUpperCase(), "()I");
let val = jni.callStaticIntMethod(cls, method);
jni.close();
let jenv = JNI.GetForThread();
let jMethodName = "get" + type.toUpperCase();
let jGeckoNetworkManager = JNI.LoadClass(jenv, "org/mozilla/gecko/GeckoNetworkManager", {
static_methods: [
{ name: jMethodName, sig: "()I" },
],
});
let val = jGeckoNetworkManager[jMethodName]();
JNI.UnloadClasses(jenv);
if (val < 0)
return null;

File diff suppressed because it is too large Load Diff