> I have seen a document describing creating a XPCOM interface IDL file > and then implementing it in c++ and building it as a shared library and > putting it with the xpt file into the Components directory. Is there any > way I can avoid this and just have the calls in javascript come straight > to the application, instead of going to a DLL? If the method invocations > are going to the DLL I create how should I get them back into the > context of my main application?
There is... There are apparently several ways of doing this. Using XPConnect like you describe is one. The FAQ mentions one which I never got working. (the section 'I need the Javascript inside the browser window to talk to my embedding client. How do I do it?' at http://www.mozilla.org/projects/embedding/faq.html#section-3) What I use and what once worked was use JS_InitClass and JS_DefineObject. The first is enough if you don't mind calling new from Javascript. The second creates an object for you as a child of another object. I create my object as a child of the global JS object. Here is my code, but for some reason it doesn't work anymore. nsCOMPtr<nsIDocShell> theDocShell(do_GetInterface(iWebBrowser)); if (theDocShell) { nsCOMPtr<nsIScriptGlobalObjectOwner> theGlobalObjectOwner(do_GetInterface(theDocShell)); if (theGlobalObjectOwner) { nsIScriptGlobalObject *theGlobalObject = theGlobalObjectOwner->GetScriptGlobalObject(); nsIScriptContext *theScriptContext = theGlobalObject->GetContext(); JSObject *theGlobalJSObject = theGlobalObject->GetGlobalJSObject(); JSContext *theJSContext = (JSContext *)theScriptContext->GetNativeContext(); // Register our C++ class JSObject *newObj = JS_InitClass(theJSContext, theGlobalJSObject, NULL, &JSTT::TTClass, JSTT::JSConstructor, 0, JSTT::tt_properties, NULL, NULL, NULL); JS_DefineObject(theJSContext, theGlobalJSObject, "ttds", &JSTT::TTClass, NULL, JSPROP_READONLY | JSPROP_ENUMERATE | JSPROP_EXPORTED); } } the JSTT::TTClass looks like: JSClass JSTT::TTClass = { "TTClass", JSCLASS_HAS_PRIVATE, JS_PropertyStub, JS_PropertyStub, JSTT::JSGetProperty, JSTT::JSSetProperty, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; The main code for the JSClass came from http://users.skynet.be/saw/SpiderMonkey.htm this describes the process very well. I'm trying to figure out why my code is not working anymore. I guess I'm using the wrong context to define my object in. The code above is called when my implementation of nsIWebProgressListener::OnStateChange gets called with (aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT) which should mean the page is done loading. You have to define your object over and over, because the context is cleared every page-load. _______________________________________________ dev-embedding mailing list [email protected] https://lists.mozilla.org/listinfo/dev-embedding
