カスタム要素CustomizableUI
に基づくウィジェットである再起動不要のアドオンを作成しました。XBL
今後のバージョンでは、メインXBL
要素を変更しました<slyzoom>
。
ただし、アップグレードをテストして DOM インスペクターでマークアップを検査すると、XBL
現在開いているウィンドウでメイン要素が更新されません。新しく開いたウィンドウでのみ、XBL
要素が意図したとおりに表示されます。
CustomizableUI
問題が適切に更新されていないことにあるのか、それともXBL
バインディングが適切に更新されていないことにあるのかは完全にはわかりません。
また、Firefox を再起動する必要はありませんが、アップグレードの変更を有効にするために新しいウィンドウを開くことは、再起動不要のアドオンを使用する目的に反しています。
Noitidart による別の質問は、同様の問題を示唆しているように見えますが、Noitidart はバインディング ルールのロードにわずかに異なるアプローチを使用しているように見えるため、私の問題がまったく同じかどうかは完全にはわかりません。
問題がどこにある可能性が最も高いかを明らかにできますか?
私の1つのファイルはかなり複雑なので、ここでは単純化されたスリム化されたバージョンのみを掲載します.bootstrap.js
startup()
shutdown()
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const NSXUL = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul';
const URI_CSS_BINDINGS = 'chrome://slyzoom/content/bindings.css';
let ioService = Cc[ '@mozilla.org/network/io-service;1' ].getService( Ci.nsIIOService );
let windowMediator = Cc[ '@mozilla.org/appshell/window-mediator;1' ].getService( Ci.nsIWindowMediator );
let styleSheetUri = ioService.newURI( URI_CSS_BINDINGS, null, null );
function startup( data, reason ) {
let CustomizableUI = Cu.import( 'resource:///modules/CustomizableUI.jsm', {} ).CustomizableUI;
// create the widget, this all works fine
CustomizableUI.createWidget( {
id: 'slyzoom',
type: 'custom',
defaultArea: null,
onBuild: function( document ) {
let window = document.defaultView;
let windowUtils = window.getInterface( Ci.nsIDOMWindowUtils );
// load the XBL bindings stylesheet in the window where my widget is being build
windowUtils.loadSheet( styleSheetUri, Ci.nsIDOMWindowUtils.AUTHOR_SHEET );
let toolBarItemAttributes = {
id: 'slyzoom',
label: 'SlyZoom',
title: 'SlyZoom',
removable: 'true',
overflows: false
}
let toolBarItem = document.createElementNS( NSXUL, 'toolbaritem' );
let slyZoom = document.createElementNS( NSXUL, 'slyzoom' );
for( let attributeName in toolBarItemAttributes ) {
toolBarItem.setAttribute( attributeName, toolBarItemAttributes[ attributeName ] );
}
toolBarItem.appendChild( slyZoom );
let listener = {
onWidgetInstanceRemoved: function( id, widgetDocument ) {
if( id == this.id && widgetDocument == document ) {
CustomizableUI.removeListener( listener );
// unload the XBL bindings stylesheet from the window where my widget is being removed
windowUtils.removeSheet( styleSheetUri, Ci.nsIDOMWindowUtils.AUTHOR_SHEET );
}
}.bind( this ),
};
CustomizableUI.addListener( listener );
return toolBarItem;
}
} );
}
// I thought everything in here would be enough to force a reload in startup(), but apparently it isn't
function shutdown( data, reason ) {
if( APP_SHUTDOWN == reason ) {
return;
}
let CustomizableUI = Cu.import( 'resource:///modules/CustomizableUI.jsm', {} ).CustomizableUI;
// I thought this would destroy any DOM instance of my widget/XBL elements
// and it actually does; I know this because I log messages
// in the destructor of the XBL elements,
// but this doesn't seem to be enough
CustomizableUI.destroyWidget( 'slyzoom' );
// unload the XBL bindings stylesheet from the every navigator window;
// this doesn't do the job I expected it to do either
let domWindows = windowMediator.getEnumerator( 'navigator:browser' );
while( domWindows.hasMoreElements() ) {
let domWindow = domWindows.getNext();
let windowUtils = domWindow.getInterface( Ci.nsIDOMWindowUtils );
windowUtils.removeSheet( styleSheetUri, Ci.nsIDOMWindowUtils.AUTHOR_SHEET );
}
}
1) リンクをたどって完全版を表示する