Ivan Kashtanov
Ivan Kashtanov

Reputation: 704

XUL dialog doesn't close after pressing "Close" button

I have a dialog in my addon which is opened when some deletion process is completed. I use for all such messages XUL dialog that looks like this:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://myaddon/skin/Style.css" type="text/css"?>
<!DOCTYPE overlay SYSTEM "chrome://myaddon/locale/mydtd.dtd">

<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        class="dialog" ondialogcancel="return true;">
    <dialogheader id="dlgHdr"/>
    <vbox flex="1" id="content" pack="center">
    </vbox>
    <script
        type="application/x-javascript"
        src="chrome://myaddon/content/mainScript.js"
    />
    <script
        type="application/x-javascript"
        src="chrome://myaddon/content/dialogInit.js"
    />
    <tfs_string id="new-profile-success" value="&newProfileSuccess.Text;"
                style="overflow: hidden" />
    <tfs_string id="delete-profile-success" value="&deleteProfileSuccess.Text;"
                style="overflow: hidden" />
</dialog>

It has cancel button, ondialogcancel handler returns true. But it doesn't close immediately after pressing button. I have to drag this dialog a little to make it disappear. Moreover, this problem only happens when I restart browser after reinstalling addon. After one more restart dialog is closed immediately after i press Cancel. I use this dialog for some other messages, and they don't have such a problem.

If I close window and open it again with Chromebug debugger instead of restarting using popup, I can't reproduce this bug. But if I lauch another FF version and then first version again (with debugger), I manage to reproduce it. But when I use step-by-step execution on dialogcancel handler, Chromebug's interface becomes unresponsive (except script content area) and dialog doesn't close after I see in debugger that window.close() is executed, so I have to drag dialog window around a little again to make it disappear. What should I do?

Upvotes: 0

Views: 324

Answers (1)

Ivan Kashtanov
Ivan Kashtanov

Reputation: 704

I finally found the reason. Problem was indeed caused by dialogInit.js script.

window.addEventListener('load', function () { myext.simpleDialogInitialize(); }, false);
window.addEventListener("MozAfterPaint", function () { window.sizeToContent(); }, false);
window.addEventListener('unload', function () { myext.simpleDialogFinalize(); }, false);

It contains even handlers for 'load' and 'unload' events. First one calls initializer specified in a method that opens this window. But there was one more handler for 'MozAfterPaint' event that called window.sizeToContent, so that infinite loop was triggered, I guess. Extension wasn't created from scratch so I didn't notice this mistake for some time. I moved resizing to the 'load' event handler after calling that initializer, works fine.

Upvotes: 1

Related Questions