protected void makeMenu(final Menu menu, final int instance) {
super.makeMenu(menu, instance);
if (_documentLoaded
&& _browserField.getDocumentUrl().equals("local:///index.html")) {
try {
final Scriptable contextMenuItems =
(Scriptable) _browserField.getScriptEngine()
.executeScript("makeContextMenu()", null);
if (contextMenuItems != null) {
MenuItem defaultItem = null;
final Integer length =
(Integer) contextMenuItems.getField("length");
for (int i = 0; i < length.intValue(); i++) {
final Scriptable menuItem =
(Scriptable) contextMenuItems.getElement(i);
if (menuItem != null) {
final String label =
(String) menuItem.getField("label");
final Object action = menuItem.getField("action");
MenuItem item = null;
if (action instanceof String) {
item =
new ScriptableMenuItem(label,
new SimpleScriptableFunction(
(String) action));
} else if (action instanceof ScriptableFunction) {
item =
new ScriptableMenuItem(label,
(ScriptableFunction) action);
}
if (item != null) {
menu.add(item);
final Object isDefault =
menuItem.getField("defaultItem");
if (isDefault != null
&& Scriptable.UNDEFINED
.equals(isDefault) == false
&& ((Boolean) isDefault).booleanValue()) {
defaultItem = item;