Firefox 扩展/插件二进制组件向后兼容性

发布于 2024-11-17 09:24:51 字数 1452 浏览 2 评论 0原文

我一直在阅读并寻找为 Firefox 扩展编译二进制组件的方法。由于 Firefox 5 即将发布(并且 6 和 7 即将发布),我想知道二进制组件是否值得再制作,或者只是使用独立的可执行文件来运行我想要的功能。

我有一个为 Firefox 5 编译的示例二进制组件,但当我在 Firefox 3.6 上测试它时,我收到此错误:

[Exception... "Could not convert Native argument arg 0 [nsISupports.QueryInterface]" nsresult: "0x8057000a (NS_ERROR_XPC_BAD_CONVERT_NATIVE)"

运行此代码

var obj = Components.classes['@example.com/MyComponent;1'].QueryInterface(Components.interfaces.IMyComponent);

并在 QueryInterface 处出现错误。显然是为 Firefox 4 构建的(XULrunner-sdk 2.0 而不是 5.0 可以工作)。

这是模块代码:

#include "mozilla/ModuleUtils.h"
#include "MyComponent.h"

NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent)

NS_DEFINE_NAMED_CID(MY_COMPONENT_CID);

static const mozilla::Module::CIDEntry kMyComponentCIDs[] = {
    { &kMY_COMPONENT_CID, false, NULL, MyComponentConstructor },
    { NULL }
};

static const mozilla::Module::ContractIDEntry kMyComponentContracts[] = {
    { MY_COMPONENT_CONTRACTID, &kMY_COMPONENT_CID },
    { NULL }
};

static const mozilla::Module kMyComponentModule = {
    mozilla::Module::kVersion,
    kMyComponentCIDs,
    kMyComponentContracts,
    NULL
};

NSMODULE_DEFN(NS_MyComponent_Module) = &kMyComponentModule;
NS_IMPL_MOZILLA192_NSGETMODULE(&kMyComponentModule)

我还听说 FF3.6 不需要在清单文件中包含 xpt 或 dll。

所以基本上我的问题是,为了向后兼容,制作可执行文件或继续制作二进制组件会更好吗? (因为它看起来像为 FF5 编译,所以 FF3.6 崩溃了。)

I have been reading up and looking at ways to compile binary components for Firefox extensions. Since Firefox 5 is being released (and 6 & 7 coming up soon) I was wondering if binary components are worth making anymore or just use a standalone executable to run the functionality I want.

I got a sample binary component to compile for Firefox 5 but when I tested it on Firefox 3.6, I get this error:

[Exception... "Could not convert Native argument arg 0 [nsISupports.QueryInterface]" nsresult: "0x8057000a (NS_ERROR_XPC_BAD_CONVERT_NATIVE)"

Running this code

var obj = Components.classes['@example.com/MyComponent;1'].QueryInterface(Components.interfaces.IMyComponent);

And errors at the QueryInterface. Apparently building for Firefox 4 (XULrunner-sdk 2.0 instead of 5.0 will work).

Here is the module code:

#include "mozilla/ModuleUtils.h"
#include "MyComponent.h"

NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent)

NS_DEFINE_NAMED_CID(MY_COMPONENT_CID);

static const mozilla::Module::CIDEntry kMyComponentCIDs[] = {
    { &kMY_COMPONENT_CID, false, NULL, MyComponentConstructor },
    { NULL }
};

static const mozilla::Module::ContractIDEntry kMyComponentContracts[] = {
    { MY_COMPONENT_CONTRACTID, &kMY_COMPONENT_CID },
    { NULL }
};

static const mozilla::Module kMyComponentModule = {
    mozilla::Module::kVersion,
    kMyComponentCIDs,
    kMyComponentContracts,
    NULL
};

NSMODULE_DEFN(NS_MyComponent_Module) = &kMyComponentModule;
NS_IMPL_MOZILLA192_NSGETMODULE(&kMyComponentModule)

I also heard that FF3.6 doesn't need to have the xpt or the dll inside the manifest file.

So basically my question is, for backward compatibility would it be better to make an executable or continue to make binary components? (Since it looks like compiling for FF5, FF3.6 broke.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陪你搞怪i 2024-11-24 09:24:51

您的错误消息应该是由于未正确识别 XPT 文件造成的(Components.interfaces.IMyComponent未定义)。也许这是因为它位于错误的目录中 - 在 Firefox 3.6 中,您不会在 chrome.manifest 文件中声明它,而是必须位于 compoments/ 中目录以及您的 dll 文件。

从 Firefox 4 开始,XPCOM 组件的向后兼容性变得更糟,请参阅 https:// developer.mozilla.org/En/Developer_Guide/Interface_Compatibility#Binary_Interfaces。理论上,如果您想要支持多个 Firefox 版本,您需要将多个版本的 XPCOM 组件放入您的 XPI 包中,这对于每六周发布一次的版本来说需要付出很大的努力。如果重点确实是从本机库调用一些函数,那么您应该认真考虑切换到 js-ctypes 。您还可以随扩展一起提供本机库(普通库,而不是 XPCOM),并使用 js-ctypes 来调用它。 Firefox 从版本 4 (Gecko 2.0) 开始支持 js-ctypes,对于 Firefox 3.6,您仍然需要不同的解决方案。

Your error message should be due to the XPT file not being recognized correctly (Components.interfaces.IMyComponent is undefined). Maybe that's because it is in the wrong directory - in Firefox 3.6 you don't declare it in the chrome.manifest file, instead it has to be located in the compoments/ directory along with your dll file.

The backwards compatibility story of XPCOM components got a lot worse starting with Firefox 4, see https://developer.mozilla.org/En/Developer_Guide/Interface_Compatibility#Binary_Interfaces. Theoretically, if you want to support multiple Firefox versions you need to put multiple versions of your XPCOM component into your XPI package, that's lots of effort for releases that come out every six weeks. If the point is really calling a few functions from a native library then you should seriously consider switching to js-ctypes. You can also ship a native library (plain, not XPCOM) with your extension and use js-ctypes to call it. Firefox supports js-ctypes starting with version 4 (Gecko 2.0), for Firefox 3.6 you would still need a different solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文