Extending Native javascript in dom

Kenny <[email protected]>
Newsgroups gmane.comp.mozilla.devel.embedding
Organization http://groups.google.com
Message-ID <c4806d53-9f1b-4483-a988-bdf971cdb159@t19g2000prd.googlegroups.com>
Hi,

I have embedded mozilla/gecko in a windows app and would like to add
some native javascript properties/functions/classes to enable the
embedded browser to be able to script at least some of the
functionality of the main program.

Here's what i came up with

nsCOMPtr<nsPIDOMWindow> outer(do_QueryInterface(GetDOMWindow()));
nsCOMPtr<nsPIDOMWindow>(outer->EnsureInnerWindow());
JSContext *cx = 0;
nsCOMPtr<nsIScriptGlobalObject> sgo(do_GetInterface(mPrivate-
>mWebBrowser));
if (sgo) {
	nsIScriptContext *scx = sgo->GetContext();
	if (scx)
		cx = (JSContext *) scx->GetNativeContext();
}
{
	JS_BeginRequest(cx);
	JS_SetErrorReporter(cx, &reportError);
JSObject * global = JS_GetGlobalObject(cx)->getParent();
	JSFunction* f = JS_DefineFunction(cx, global, "boo", &js::js_add,
2,JSPROP_ENUMERATE);
	JS_EndRequest(cx);
}

But unfortunately, when loading a webpage which contains
	<script type="text/javascript">boo(1,2);</script>
I get a javascript error.
Some-one has changed the global object in the JScontext object!
This seems to happen in mozJSComponentLoader::GlobalForLocation: every
time a new location is loaded a new global is set. Seems logical but
where can I inject my javascript objects? Is there a hook between the
setting up of the new global object and the actual loading of the web
page?

Many thanx!

Kenny
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.