简体   繁体   English

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

[英]Firefox Extension/Addon Binary Component Backward Compatibility

I have been reading up and looking at ways to compile binary components for Firefox extensions. 我一直在阅读并寻找为Firefox扩展编译二进制组件的方法。 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. 由于Firefox 5即将发布(即将推出6和7),我想知道二进制组件是否值得再制造,还是仅使用独立的可执行文件来运行所需的功能。

I got a sample binary component to compile for Firefox 5 but when I tested it on Firefox 3.6, I get this error: 我有一个供Firefox 5编译的示例二进制组件,但是在Firefox 3.6上对其进行测试时,出现此错误:

[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. 以及QueryInterface上的错误。 Apparently building for Firefox 4 (XULrunner-sdk 2.0 instead of 5.0 will work). 显然是针对Firefox 4构建的(可以使用XULrunner-sdk 2.0代替5.0)。

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. 我还听说FF3.6不需要在清单文件中包含xpt或dll。

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.) (由于看起来是为FF5进行编译,因此FF3.6崩溃了。)

Your error message should be due to the XPT file not being recognized correctly ( Components.interfaces.IMyComponent is undefined ). 您的错误消息应该是由于无法正确识别XPT文件( Components.interfaces.IMyComponent 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. 可能是因为它位于错误的目录中-在Firefox 3.6中,您无需在chrome.manifest文件中声明它,而是必须将其与dll文件一起位于compoments/目录中。

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 . 从Firefox 4开始,XPCOM组件的向后兼容性问题变得更糟,请参阅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. 从理论上讲,如果要支持多个Firefox版本,则需要将XPCOM组件的多个版本放入XPI软件包中,因此,每六周发布一次该版本会付出很多努力。 If the point is really calling a few functions from a native library then you should seriously consider switching to js-ctypes . 如果真正要从本地库调用一些函数,那么您应该认真考虑切换到js-ctypes You can also ship a native library (plain, not XPCOM) with your extension and use js-ctypes to call it. 您还可以使用扩展名附带本机库(普通库,而不是XPCOM),并使用js-ctypes进行调用。 Firefox supports js-ctypes starting with version 4 (Gecko 2.0), for Firefox 3.6 you would still need a different solution. Firefox支持从版本4(Gecko 2.0)开始的js-ctypes,对于Firefox 3.6,您仍然需要其他解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM