Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

Calling JavaScript from C++ plugin

已查看 7 次
跳至第一个未读帖子

mcbr...@gmail.com

未读,
2007年8月31日 17:12:392007/8/31
收件人
Hello,

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!

JensLS...@gmail.com

未读,
2007年9月30日 00:37:292007/9/30
收件人

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

0 个新帖子