I've written a scriptable firefox plugin that is able to receive
messages from JavaScript. I now need to send messages from the plugin
to JS. The only way I've found to do this is through the use of the
nsIObserverService using the following code:
nsCOMPtr<nsIServiceManager> servMan;
nsresult rv = NS_GetServiceManager(getter_AddRefs(servMan));
nsCOMPtr<nsIObserverService> observerService;
rv = servMan->GetServiceByContractID("@mozilla.org/observer-
service;1",
NS_GET_IID(nsIObserverService),
getter_AddRefs(observerService));
observerService->NotifyObservers(NULL, "Topic", 0);
On the JS side, I will declare an observer that listens for "Topic".
First of all, is this the recommended way to communicate from the
plugin to JS?
Second, when I linked my plugin with xpcom.lib, it no longer gets
instantiated by firefox (I just get a blank window). I checked the
dependencies on my plugin dll and they are all satisfied.
Any suggestions would be greatly appreciated.
Thanks!
You can use methods such as JS_CallFunctionName to call java script
from C/C++ if this is what you are looking for. You basically get a
hold of the JS Context and JS Object and then pass in the name of the
function you want to call + the arguments that you want to pass into
this function.
Here are some examples..
http://developer.mozilla.org/en/docs/JS_CallFunctionName
http://www.mozilla.org/js/spidermonkey/tutorial.html
-Jens