如何创建类似Firebug的底部窗口Firefox扩展

Mik*_*ell 6 firefox xul firefox-addon

几个扩展提供了查看其内容的"底部窗口".Firebug和ScribeFire是主要内容出现在浏览器底部的好例子.这似乎与浏览器中的侧边栏功能非常相似.

是否有最佳实践/方法在扩展中创建底部窗口,因为浏览器没有"底部侧边栏"?

Tom*_*omC 8

您可以使用叠加创建扩展UI.在叠加层中,您可以指定UI与主浏览器页面browser.xul相关的插入点.

摘自Firefox的主页browser.xul我们有

<vbox id="appcontent" flex="1">
    <tabbrowser id="content" disablehistory="true"
                flex="1" contenttooltip="aHTMLTooltip"
                contentcontextmenu="contentAreaContextMenu"
                onnewtab="BrowserOpenTab();"
                autocompletepopup="PopupAutoComplete"
                ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);"
                onclick="return contentAreaClick(event, false);"
                />
  </vbox>
Run Code Online (Sandbox Code Playgroud)

并摘自我们之前版本的Firebug文件browserOverlay.xul

<vbox id="appcontent">
    <splitter id="fbContentSplitter" collapsed="true"/>
    <vbox id="fbContentBox" collapsed="true" persist="height">
        <toolbox id="fbToolbox">
            <toolbar id="fbToolbar">
                <toolbarbutton id="fbFirebugMenu" type="menu">
                    <menupopup onpopupshowing="return FirebugChrome.onOptionsShowing(this);">
                        <menuitem label="&firebug.DisableFirebug;" type="checkbox"
                                  oncommand="FirebugChrome.onToggleOption(this)" option="disabledAlways"/>
                        <menuitem type="checkbox"
                                  oncommand="FirebugChrome.onToggleOption(this)" option="disabledForSite"/>
                        <menuitem label="&firebug.AllowedSites;" command="cmd_openFirebugPermissions"/>
                        <menuseparator/>

                        <menu label="&firebug.TextSize;">
                            <menupopup>
                                <menuitem label="&firebug.IncreaseTextSize;"
                                          oncommand="Firebug.increaseTextSize(1)"/>
                                <menuitem label="&firebug.DecreaseTextSize;"
                                          oncommand="Firebug.increaseTextSize(-1)"/>
                                <menuitem label="&firebug.NormalTextSize;" oncommand="Firebug.setTextSize(0)"/>
                            </menupopup>
                        </menu>

                        <menu label="&firebug.Options;">
                            <menupopup onpopupshowing="return FirebugChrome.onOptionsShowing(this);">
                                <menuitem type="checkbox" label="&firebug.AlwaysOpenInWindow;"
                                           oncommand="FirebugChrome.onToggleOption(this)"
                                           option="openInWindow"/>

                                <menuitem type="checkbox" label="&firebug.ShowTooltips;"
                                           oncommand="FirebugChrome.onToggleOption(this)"
                                           option="showInfoTips"/>

                                <menuitem type="checkbox" label="&firebug.ShadeBoxModel;"
                                          oncommand="FirebugChrome.onToggleOption(this)"
                                          option="shadeBoxModel"/>
                            </menupopup>
                        </menu>
                        <menuseparator/>

                        <menuitem label="&firebug.Website;" oncommand="Firebug.visitWebsite('main')"/>
                        <menuitem label="&firebug.Documentation;" oncommand="Firebug.visitWebsite('docs')"/>
                        <menuitem label="&firebug.Forums;" oncommand="Firebug.visitWebsite('discuss')"/>
                        <menuseparator/>
                        <menuitem label="&firebug.Donate;" oncommand="Firebug.visitWebsite('donate')"/>
                    </menupopup>
                </toolbarbutton>

                <toolbarbutton id="fbDetachButton" class="toolbarbutton-iconic"
                               tooltiptext="&firebug.DetachFirebug;" command="cmd_detachFirebug"/>

                <toolbarbutton id="fbCloseButton" class="toolbarbutton-iconic"
                               tooltiptext="&firebug.CloseFirebug;" command="cmd_toggleFirebug"/>
            </toolbar>
        </toolbox>

        <hbox id="fbPanelBox" flex="1"/>
        <hbox id="fbCommandBox"/>
    </vbox>
</vbox>
Run Code Online (Sandbox Code Playgroud)

请注意,两个XUL标记块都以

<vbox id="appcontent".../>
Run Code Online (Sandbox Code Playgroud)

这就是Gecko引擎用来确定叠加如何与被覆盖的页面组合在一起的内容.如果您查看browserOverlay.xul,您还会看到其他插入点commandset, statusbar等.

有关更多信息,请参阅Mozilla开发人员中心.