Skip to content

Instantly share code, notes, and snippets.

@chrisforbes
Created November 4, 2009 21:59
Show Gist options
  • Save chrisforbes/226423 to your computer and use it in GitHub Desktop.
Save chrisforbes/226423 to your computer and use it in GitHub Desktop.
// c# / xulrunner host call interface [for geckofx-1.9, xulrunner-1.9.1.3]
// allows arb. calls to window.host.SomeMethod() to be marshaled to the host.
var last_host_call = 0;
window.host = { __noSuchMethod__: function(id, xs)
{
/* host bridge for gecko-1.9.1 / geckofx-1.9.0 */
/* set up the args object */
$("callinfo").remove();
var callinfo = $.tag("callinfo");
callinfo.attr("funcname", id);
callinfo.attr("argc", xs.length);
for (var i = 0; i < xs.length; i++)
callinfo.attr("arg_" + i, xs[i]);
$("#main").append(callinfo);
/* make the call: we use the doc title to make host calls because
it's otherwise not used with our frame */
document.title = "host_call_" + (last_host_call++);
/* fetch the result */
return callinfo.attr("retval");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment