gpt4 book ai didi

c++ - 我的 Firefox 扩展不工作。使用 C++ XPCOM 组件的 Firefox 扩展(XPI 文件)的结构是什么?

转载 作者:行者123 更新时间:2023-11-30 04:25:56 25 4
gpt4 key购买 nike

我已经尝试了一百万种不同的东西,但无法让它发挥作用。

在我的 xpi 文件中:

* content folder
-browserOverlay.js
-browserOverlay.xul

* locale folder
*en-US folder
-browserOverlay.dtd
-browserOverlay.properties
* skin folder
-browserOverlay.css

我有 Firefox 14.0.1,我的“Hello World”扩展中不使用 XPCOM 的部分正在运行。目前,它所做的只是添加一个带有按钮的工具栏,单击该按钮时会显示“Hello World”,然后尝试运行我使用 Gecko SDK 构建并使用 VS 2005 编译的 C++ XPCOM 组件。

browserOverlay.js 文件包含以下代码:

/**
* XULSchoolChrome namespace.
*/
if ("undefined" == typeof(XULSchoolChrome)) {
var XULSchoolChrome = {};
};

/**
* Controls the browser overlay for the Hello World extension.
*/
XULSchoolChrome.BrowserOverlay = {
/**
* Says 'Hello' to the user.
*/
sayHello : function(aEvent) {
let stringBundle = document.getElementById("xulschoolhello-string-bundle");
let message = stringBundle.getString("xulschoolhello.greeting.label");

window.alert(message);


try
{
// normally Firefox extensions implicitly have XPCOM privileges
//but since this is a file we have to request it.

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@example.com/XPCOMSample/MyComponent;1";
obj = Components.classes[cid].createInstance();
// bind the instance we just created to our interface
obj = obj.QueryInterface(Components.interfaces.IMyComponent);
} catch (err) {
alert(err);
return;
}
var res = obj.Add(3, 4);
alert('Performing 3+4. Returned ' + res + '.');
}
};

当我点击按钮时,我看到了第一个警告窗口。当我单击“确定”时,我看到一个带有以下错误消息的窗口:

TypeError: Components.classes[cid] is undefined

我做错了什么?我应该将 .dll 文件放在 xpi 文件中的什么位置? .idl 文件? .xpt 文件?

最佳答案

我猜你正在学习过时的教程,大多数教程还没有更新到 XPCOM changes in Gecko 2.0 .但是对于你的问题:

Where within the xpi file am I supposed to place the .dll file?

任何你喜欢的地方。传统的放置在 components/ 子目录中。

the .idl file?

它不应该是你的扩展的一部分,只有 .xpt 文件。

the .xpt file?

再次在您喜欢的任何位置,但通常与 .dll 文件位于同一目录中。

将必要的声明添加到 chrome.manifest 文件中很重要,但是通常是这样的:

interfaces components/mycomponent.xpt
binary-component components/mycomponent.dll ABI=WINNT_x86-msvc

另见 documentation关于组件代码中需要更改的内容(如果您愿意,Firefox 源代码树中有一个 example)。请注意,您必须使用 Gecko SDK 编译您的组件。与您要在其中使用该组件的 Firefox 版本相匹配的版本。因此,对于 Firefox 14,您需要使用 Gecko SDK 14。由于不再有任何二进制兼容性,您的组件将只能在 Firefox 14 中运行,而不能在 Firefox 13 或 Firefox 15 中运行。

关于c++ - 我的 Firefox 扩展不工作。使用 C++ XPCOM 组件的 Firefox 扩展(XPI 文件)的结构是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11871059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com