Bug 1406168 - 1. Remove JNI.jsm; r=sebastian

Remove JNI.jsm. Convert code that used JNI.jsm to the equivalent using
EventDispatcher.

MozReview-Commit-ID: JQdCubcTBAR
This commit is contained in:
Jim Chen 2017-11-01 14:48:48 -04:00
Родитель fd96b7623b
Коммит d19eceacd5
12 изменённых файлов: 44 добавлений и 1326 удалений

Просмотреть файл

@ -289,6 +289,9 @@ public class GeckoApplication extends Application
IntentHelper.init();
EventDispatcher.getInstance().registerGeckoThreadListener(mListener,
"Distribution:GetDirectories",
null);
EventDispatcher.getInstance().registerUiThreadListener(mListener,
"Gecko:Exited",
"RuntimePermissions:Check",
@ -307,6 +310,9 @@ public class GeckoApplication extends Application
* replaces an old one due to assets change.
*/
private void onDestroy() {
EventDispatcher.getInstance().unregisterGeckoThreadListener(mListener,
"Distribution:GetDirectories",
null);
EventDispatcher.getInstance().unregisterUiThreadListener(mListener,
"Gecko:Exited",
"RuntimePermissions:Check",
@ -494,6 +500,9 @@ public class GeckoApplication extends Application
.fromEvent(message)
.callback(callback)
.buildAndShow();
} else if ("Distribution:GetDirectories".equals(event)) {
callback.sendSuccess(Distribution.getDistributionDirectories());
}
}
}

Просмотреть файл

@ -16,7 +16,6 @@ import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.mozilla.gecko.annotation.JNITarget;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.distribution.PartnerBrowserCustomizationsClient;
@ -143,6 +142,10 @@ public class Tabs implements BundleEventListener {
};
private Tabs() {
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Tab:GetNextTabId",
null);
EventDispatcher.getInstance().registerUiThreadListener(this,
"Content:LocationChange",
"Content:SubframeNavigation",
@ -543,6 +546,10 @@ public class Tabs implements BundleEventListener {
}
});
return;
} else if ("Tab:GetNextTabId".equals(event)) {
callback.sendSuccess(getNextTabId());
return;
}
// All other events handled below should contain a tabID property
@ -1118,8 +1125,7 @@ public class Tabs implements BundleEventListener {
/**
* Gets the next tab ID.
*/
@JNITarget
public static int getNextTabId() {
private static int getNextTabId() {
return sTabId.getAndIncrement();
}

Просмотреть файл

@ -44,7 +44,6 @@ import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.annotation.JNITarget;
import org.mozilla.gecko.util.FileUtils;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.HardwareUtils;
@ -926,7 +925,6 @@ public class Distribution {
return context.getApplicationInfo().dataDir;
}
@JNITarget
public static String[] getDistributionDirectories() {
final Context context = GeckoAppShell.getApplicationContext();

Просмотреть файл

@ -31,9 +31,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Manifests",
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "JNI",
"resource://gre/modules/JNI.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UITelemetry",
"resource://gre/modules/UITelemetry.jsm");
@ -3626,14 +3623,10 @@ Tab.prototype = {
this.id = aParams.tabID;
stub = true;
} else {
let jenv = JNI.GetForThread();
let jTabs = JNI.LoadClass(jenv, "org.mozilla.gecko.Tabs", {
static_methods: [
{ name: "getNextTabId", sig: "()I" }
],
// Send a synchronous Gecko thread event.
GlobalEventDispatcher.dispatch("Tab:GetNextTabId", null, {
onSuccess: response => this.id = response,
});
this.id = jTabs.getNextTabId();
JNI.UnloadClasses(jenv);
}
this.desktopMode = ("desktopMode" in aParams) ? aParams.desktopMode : false;

Просмотреть файл

@ -6,12 +6,14 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "JNI", "resource://gre/modules/JNI.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
AppConstants: "resource://gre/modules/AppConstants.jsm",
EventDispatcher: "resource://gre/modules/Messaging.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm",
Services: "resource://gre/modules/Services.jsm",
});
// -----------------------------------------------------------------------
// Directory Provider for special browser folders and files
@ -178,29 +180,12 @@ DirectoryProvider.prototype = {
_getDistributionDirectories: function() {
let directories = [];
let jenv = null;
try {
jenv = JNI.GetForThread();
let jDistribution = JNI.LoadClass(jenv, "org.mozilla.gecko.distribution.Distribution", {
static_methods: [
{ name: "getDistributionDirectories", sig: "()[Ljava/lang/String;" }
],
});
let jDirectories = jDistribution.getDistributionDirectories();
for (let i = 0; i < jDirectories.length; i++) {
directories.push(new FileUtils.File(
JNI.ReadString(jenv, jDirectories.get(i))
));
}
} finally {
if (jenv) {
JNI.UnloadClasses(jenv);
}
}
// Send a synchronous Gecko thread event.
EventDispatcher.instance.dispatch("Distribution:GetDirectories", null, {
onSuccess: response =>
directories = response.map(dir => new FileUtils.File(dir)),
});
return directories;
}

Просмотреть файл

@ -17,18 +17,19 @@ const OMA_DRM_RIGHTS_MIME = "application/vnd.oma.drm.rights+wbxml";
const PREF_BD_USEDOWNLOADDIR = "browser.download.useDownloadDir";
const URI_GENERIC_ICON_DOWNLOAD = "drawable://alert_download";
Cu.import("resource://gre/modules/Downloads.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/HelperApps.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "RuntimePermissions", "resource://gre/modules/RuntimePermissions.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "EventDispatcher", "resource://gre/modules/Messaging.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Snackbars", "resource://gre/modules/Snackbars.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "JNI", "resource://gre/modules/JNI.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
Downloads: "resource://gre/modules/Downloads.jsm",
EventDispatcher: "resource://gre/modules/Messaging.jsm",
FileUtils: "resource://gre/modules/FileUtils.jsm",
HelperApps: "resource://gre/modules/HelperApps.jsm",
NetUtil: "resource://gre/modules/NetUtil.jsm",
RuntimePermissions: "resource://gre/modules/RuntimePermissions.jsm",
Services: "resource://gre/modules/Services.jsm",
Snackbars: "resource://gre/modules/Snackbars.jsm",
Task: "resource://gre/modules/Task.jsm",
});
// -----------------------------------------------------------------------
// HelperApp Launcher Dialog
@ -241,25 +242,7 @@ HelperAppLauncherDialog.prototype = {
* around starting from Lollipop.
*/
_useNewButtonOrder: function() {
let useNewButtonOrder = true;
let jenv = null;
try {
jenv = JNI.GetForThread();
let jAppConstants = JNI.LoadClass(jenv, "org.mozilla.gecko.AppConstants$Versions", {
static_fields: [
{ name: "feature21Plus", sig: "Z" }
],
});
useNewButtonOrder = jAppConstants.feature21Plus;
} finally {
if (jenv) {
JNI.UnloadClasses(jenv);
}
}
return useNewButtonOrder;
return Services.sysinfo.getPropertyAsUint32("version") >= 21;
},
_refuseDownload: function(aLauncher) {

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -32,7 +32,6 @@ EXTRA_JS_MODULES += [
'Home.jsm',
'HomeProvider.jsm',
'InputWidgetHelper.jsm',
'JNI.jsm',
'LightweightThemeConsumer.jsm',
'MediaPlayerApp.jsm',
'NetErrorHelper.jsm',

Просмотреть файл

@ -34,7 +34,6 @@ skip-if = debug
[test_home_provider.html]
[test_hidden_select_option.html]
[test_identity_mode.html]
[test_jni.html]
[test_media_playback.html]
[test_migrate_ui.html]
[test_network_manager.html]

Просмотреть файл

@ -1,82 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=873569
Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 873569</title>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
<script type="application/javascript">
Components.utils.import("resource://gre/modules/ctypes.jsm");
Components.utils.import("resource://gre/modules/JNI.jsm");
function test_JNI() {
var jenv = null;
try {
jenv = JNI.GetForThread();
// Test a simple static method.
var geckoAppShell = JNI.LoadClass(jenv, "org.mozilla.gecko.GeckoAppShell", {
static_methods: [
{ name: "getPreferredIconSize", sig: "()I" },
{ name: "getApplicationContext", sig: "()Landroid/content/Context;" },
],
});
let iconSize = -1;
iconSize = geckoAppShell.getPreferredIconSize();
isnot(iconSize, -1, "icon size is valid");
// 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" },
],
});
is(typeof jGeckoNetworkManager.getMNC(), "number", "typeof getMNC is number");
is(typeof jGeckoNetworkManager.getMCC(), "number", "typeof getMCC is number");
// Test retrieving the context's class's name, which tests dynamic method
// invocation as well as converting a Java string to JavaScript.
JNI.LoadClass(jenv, "android.content.Context", {
methods: [
{ name: "getClass", sig: "()Ljava/lang/Class;" },
],
});
JNI.LoadClass(jenv, "java.lang.Class", {
methods: [
{ name: "getName", sig: "()Ljava/lang/String;" },
],
});
is("org.mozilla.gecko.GeckoApplication", JNI.ReadString(jenv, geckoAppShell.getApplicationContext().getClass().getName()), "class name is correct");
} finally {
if (jenv) {
JNI.UnloadClasses(jenv);
}
}
}
test_JNI();
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=873569">Mozilla Bug 873569</a>
<br>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184186">Migrated from Robocop testJNI</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

Просмотреть файл

@ -14,10 +14,6 @@ Migrated from Robocop: https://bugzilla.mozilla.org/show_bug.cgi?id=1184186
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/ctypes.jsm");
Cu.import("resource://gre/modules/JNI.jsm");
Cu.import("resource://gre/modules/Task.jsm");
function test_isUserRestricted() {
// Make sure the parental controls service is available
ok("@mozilla.org/parental-controls-service;1" in Cc);

Просмотреть файл

@ -107,7 +107,6 @@
"import_module.jsm": ["MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope", "SUBMODULE_IMPORTED_TO_SCOPE"],
"import_sub_module.jsm": ["SUBMODULE_IMPORTED", "test_obj"],
"InlineSpellChecker.jsm": ["InlineSpellChecker", "SpellCheckHelper"],
"JNI.jsm": ["JNI", "android_log"],
"JSDOMParser.js": ["JSDOMParser"],
"jsdebugger.jsm": ["addDebuggerToGlobal"],
"json2.js": ["JSON"],