简体   繁体   English

Firefox扩展程序通过XBL转换为无重启

[英]Firefox extension convert to restartless with XBL

I'm developing a Firefox extension and need some help with it. 我正在开发Firefox扩展,并需要一些帮助。
My extension is overlayed and uses XBL binding to add new items to the user interface. 我的扩展程序已覆盖并使用XBL绑定将新项目添加到用户界面。
Is it possible to convert this extension to a bootstrap type? 是否可以将此扩展名转换为引导程序类型?

I'm trying to add a button to the findbar. 我正在尝试将一个按钮添加到查找栏。
Used XBL to override the findbar interface. 使用XBL覆盖findbar界面。

To start with the bootstrap I included "findbar{ -moz-binding:... }" rule to the style.css and register this sheet on startup() 首先从引导程序开始,我在style.css中包含了“ findbar {-moz-binding:...}”规则,并在startup()上注册了此表单
(with nsIStyleSheetService.loadAndRegisterSheet()). (使用nsIStyleSheetService.loadAndRegisterSheet())。
In this case my button is added to the bar without restart. 在这种情况下,我的按钮将添加到栏中,而无需重新启动。

But when I disable or remove the addon I need to restart the browser so that the button disappear. 但是,当我禁用或删除插件时,我需要重新启动浏览器,以便该按钮消失。
I tried to remove it on shutdown() in the bootstrap.js using: 我试图使用以下命令在bootstrap.js中的shutdown()上将其删除:

var fb=window.gFindBar.getElement("findbar-container")  
var but=window.gFindBar.getElement("the-button")  
fb.removeChild(but)  

But this didn't remove it. 但这并没有将其删除。 I debugged the code and all the elements (fb, but) were found and removed but it didn't touch the real findbars in any tab I had or opened. 我调试了代码,发现并删除了所有元素(fb,但是),但是它没有触及我拥有或打开的任何选项卡中的真实查找栏。

So I tried to unregister the stylesheet which bind my XBL to the findbar. 因此,我尝试取消注册将XBL绑定到findbar的样式表。 This time the findbar just didn't open in the current tabs. 这次,查找栏只是没有在当前选项卡中打开。
But in new tabs it opened and without the button (a little better...). 但是在新标签页中它没有按钮就打开了(更好一点...)。

Also I've found that the findbar didn't open in the opened tabs because of a strange error: "this.browser is undefined". 我还发现由于一个奇怪的错误:“ this.browser is undefined”,findbar没有在打开的选项卡中打开。
This error pointed to the findbar.xml line 533 where the code tried to run _unpdateCaseSensitivity() but it couldn't get the "gFindBar._browser" prorperty. 该错误指向findbar.xml第533行,代码在该行尝试运行_unpdateCaseSensitivity(),但无法获得“ gFindBar._browser”属性。
Maybe it's because this property wasn't loaded for the original findbar object from the browser start (it was used by the overriden findbar object)... 可能是因为从浏览器启动时未为原始findbar对象加载此属性(已被覆盖的findbar对象使用)...

So this is the point I stuck on... 这就是我坚持的重点...

And the question now is: 现在的问题是:
How can I delete the button without restart and so that the findbar opens? 如何在不重新启动的情况下删除按钮,以便打开查找栏?

From the Findbar Tweak addon I extracted this method to add new checkbox to the findbar (and changed it for my needs): 我从Findbar Tweak插件中提取了此方法,以将新复选框添加到findbar(并根据我的需要进行了更改):

var findbar=window.gFindBar
var container = findbar.getElement("findbar-container")
var button = $('<toolbarbutton>')
button.setAttribute('anonid', 'test-find-tabs')
button.setAttribute('label', 'Test')
button.setAttribute('type', 'checkbox')
button.addEventListener('command', test,false)
container.insertBefore(button, findbar.getElement('find-case-sensitive').nextSibling)

But for my final purpose it needs some additional editings. 但出于我的最终目的,它需要一些其他编辑。 So for now I'll leave this problem. 所以现在我将离开这个问题。 Maybe a wise thought will occur me later. 也许以后会发生一个明智的想法。 Cause a good idea often comes in mind after we change the focus from the problem and then return to it... 在我们将重点从问题中转移到问题之后,通常会想到一个好主意...

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

相关问题 使用SDK重启Firefox扩展 - Restartless firefox extension using the SDK firefox重新启动引导扩展脚本无法重新加载 - firefox restartless bootstrap extension script not reloading 等效于简单存储API,用于无重启的Firefox扩展 - Equivalent of simple storage API for restartless firefox extension 使用Addon SDK构建不重启的Firefox扩展 - Building restartless Firefox extension with Addon SDK Firefox的无重启(自举)扩展名中的getElementsByName - getElementsByName in restartless (bootstrapped) extension for firefox mobile 在 Firefox Restartless Extension 中使用 while 循环是一个很好的等待策略吗? - Is using a while loop a good waiting strategy in a Firefox Restartless Extension? 使用SDK通过Firefox重启扩展添加新的搜索引擎 - Adding a new search engine through a firefox restartless extension using SDK 如何将Greasemonkey脚本转换为无重启的Firefox插件? - How can I convert a Greasemonkey script into a restartless Firefox addon? 在无重启扩展中与jsctypes异步工作 - Working asynchronously with jsctypes in restartless extension 关于找出XUL元素的段落在MDN文档中的含义是:“如何将覆盖扩展名转换为不重启” - What does paragraph about figuring out XUL elements mean in MDN document: “How to convert an overlay extension to restartless”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM