初学者帮助 - 该代码属于哪里?

发布于 2024-07-10 05:48:46 字数 387 浏览 10 评论 0原文

我正在尝试开发一个 Firefox 扩展,它将额外的 HTTP 标头字段插入到传出的 HTTP 请求中(以与我同时开发的 apache 扩展交互)。

虽然我了解扩展的各个组件并了解网络上提供的基本教程,但我发现很难从“Hello World”教程扩展转向开发完整的扩展。

我想要根据自己的目的进行调整的示例代码位于设置 HTTP 请求标头 的底部。

我想知道,此代码应放置在扩展层次结构中的何处以及如何调用/构造/激活此类代码,它会在扩展初始化时自动运行吗?



提前致谢。

I'm trying to develop a firefox extension that inserts additional HTTP header fields into outgoing HTTP requests (to interface with an apache extension i'm concurrently developing).

While I understand the individual components of an extension and understand the basic tutorials that are presented on the web, I'm finding it difficult going from the "Hello World" tutorial extensions, into developing a full blown extension.

The sample code I am wanting to adapt for my purposes is presented at the bottom of Setting HTTP request headers.

I am wondering, where in the extension hierarchy should this code be placed and how is such code called/constructed/activated, will it run automatically when the extension is initialised?

Thanks in advance.

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

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

发布评论

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

评论(2

紙鸢 2024-07-17 05:48:46

对于基本扩展,您可以将代码放置在扩展的 chrome/content 目录中。 您可以使用叠加层将此内容挂钩到 Firefox 中。 虽然覆盖层通常是 xul 内容(按钮等),但它们可以是任何内容。 包括一个脚本标签,它将加载并触发您的 Javascript 代码。

For a basic extension, you would place your code in the chrome/content directory of the extension. You would hook this content into Firefox using an overlay. While overlays are usually xul content (buttons, etc) they can be anything. Including a script tag which would load fire off your Javascript code.

雨轻弹 2024-07-17 05:48:46

该代码是一个 XPCOM 组件,位于 components/.js 文件中。

如果你想深入了解 XPCOM 组件,你应该阅读它,但是,是的,components 中的 .js 文件是在启动时加载的。 此类文件包含注册代码(在该示例中从 var myModule = { 行开始),它告诉 Firefox 文件中定义的组件是否可根据请求使用,或者是否应该自动实例化。

在该示例中,您可以看到组件已注册以接收应用程序启动的通知:

catMgr.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);

并且在处理应用程序启动通知时,它会自行注册以接收 http-on-modify-request 通知:

os.addObserver(this, "http-on-modify-request", false);

That code is an XPCOM component and goes into a components/<some name>.js file.

You should read up on XPCOM components if you want to dig it, but yes, .js files in components are loaded at startup. Such files contain registration code (starts at the var myModule = { line in that example), which tells Firefox whether the component defined in the file is available upon request or should it be instantiated automatically.

In that example you can see the component getting registered to be notified of the application's startup:

catMgr.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);

and when handling the app-startup notification it registers itself for the http-on-modify-request notification:

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