I overlay chrome://browser/content/browser.xul with an .xul adding a button to the main-menu. clicking it opens another ChromeWindow with a .xul-window.
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
var bgwin = ww.openWindow(null, 'chrome://myextension/content/myBrowser.xul', 'MyName', "chrome, resizable=yes, width=1024, height=600, minimizable, maximizable", []);
chrome://myextension/content/myBrowser.xul:
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="myextension-my-browser"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="mybrowser"
windowtype="mybrowser"
>
<script type="application/x-javascript" src="chrome://myextension/content/myBrowser.js" />
<browser id="browser" type="content" flex="1" src="about:blank" />
</window>
which works fine. but then, i want to hide that window. make it completely invisible, doing (in myBrowser.js). But nothing happens:
var topXulWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIXULWindow);
var appShellService = Components.classes["@mozilla.org/appshell/appShellService;1"].getService(Components.interfaces.nsIAppShellService);
appShellService.unregisterTopLevelWindow(topXulWindow);
What am i doing wrong? Why doesn't the window disappear?
Prepend you code with the following snippet
var basewindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
.QueryInterface(Components.interfaces.nsIBaseWindow);
basewindow.visibility = false;
basewindow.enabled = false;
// now unregister