Bug 794479 - Add a NativeWindow API to load java code. r=mfinkle

This commit is contained in:
Kartikaya Gupta 2012-10-09 15:20:36 -04:00
parent 84b8223156
commit 27f9111b3f
2 changed files with 27 additions and 0 deletions

View File

@ -37,6 +37,9 @@ import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;
import dalvik.system.DexClassLoader;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.EnumSet;
@ -214,6 +217,7 @@ abstract public class BrowserApp extends GeckoApp
registerEventListener("Feedback:LastUrl");
registerEventListener("Feedback:OpenPlayStore");
registerEventListener("Feedback:MaybeLater");
registerEventListener("Dex:Load");
}
@Override
@ -227,6 +231,7 @@ abstract public class BrowserApp extends GeckoApp
unregisterEventListener("Feedback:LastUrl");
unregisterEventListener("Feedback:OpenPlayStore");
unregisterEventListener("Feedback:MaybeLater");
unregisterEventListener("Dex:Load");
}
@Override
@ -432,6 +437,18 @@ abstract public class BrowserApp extends GeckoApp
menu.findItem(R.id.settings).setEnabled(true);
}
});
} else if (event.equals("Dex:Load")) {
String zipFile = message.getString("zipfile");
String implClass = message.getString("impl");
Log.d(LOGTAG, "Attempting to load classes.dex file from " + zipFile + " and instantiate " + implClass);
try {
File tmpDir = getDir("dex", 0);
DexClassLoader loader = new DexClassLoader(zipFile, tmpDir.getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
Class<?> c = loader.loadClass(implClass);
c.newInstance();
} catch (Exception e) {
Log.e(LOGTAG, "Unable to initialize addon", e);
}
} else {
super.handleMessage(event, message);
}

View File

@ -1185,6 +1185,16 @@ var NativeWindow = {
this.contextmenus.uninit();
},
loadDex: function(zipFile, implClass) {
sendMessageToJava({
gecko: {
type: "Dex:Load",
zipfile: zipFile,
impl: implClass || "Main"
}
});
},
toast: {
show: function(aMessage, aDuration) {
sendMessageToJava({