I want to be notified every time a new window is opened in Thunderbird.
I am interested only in the UI windows like: Main Window (messenger?),
Message window (where a message is loaded), and the others extensions,
themes, etc.)
I am using the code below but it seems that the object received in
onassert is of type "nsIXULWindow"
while the normal windows in Thunderbird are nsIDOMWindow
For example (for the listener case), despite I receive the window as a
parameter (xul_window), these properties:
xul_window.title
xul_window.windowtype
Always return "undefined" (nsIXULWindow?)
I tried using also an observer, but I do not know how to get the window
object from the parameters:
dataSource , source , property , target
Any help would be appreciated
Thanks in advance
=========
var windowMediator_Listener = {
onCloseWindow : function(xul_window)
{
var m_consoleService =
Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
m_consoleService.logStringMessage("closed: "+xul_window.title+"
-- "+xul_window.windowtype);
},
onOpenWindow : function(xul_window)
{
var m_consoleService =
Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
m_consoleService.logStringMessage("Opened: "+xul_window+" --
"+xul_window.title+" -- "+xul_window.windowtype+" --
"+xul_window.close);
},
onWindowTitleChange : function( xul_window , newTitle )
{
var m_consoleService =
Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
m_consoleService.logStringMessage("ChangeTitle:
"+xul_window.title+" -- "+xul_window.windowtype+" -- "+newTitle);
}
};
var observer = {
m_RDF :
Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService),
onAssert : function(ds, s, p, t) {
var m_consoleService =
Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
m_consoleService.logStringMessage("**onAssert** s: "+s.Value+"
p: "+p.Value);
m_consoleService.logStringMessage("**onAssert** t: "+t+"
t_val: "+t.Value+" -- "+t.getAttribute);
},
onUnassert : function(ds, s, p, t) {
},
onChange : function(ds, s, p, oldt, newt) {
},
onMove : function(ds, olds, news, p, t) {},
beginUpdateBatch : function(ds) {},
endUpdateBatch : function(ds) {}
};
var windowMediator =
Components.classes["@mozilla.org/appshell/window-mediator;1"].
getService(Components.interfaces.nsIWindowMediator);
windowMediator.addListener(windowMediator_Listener);
var window_mediator2 =
Components.classes["@mozilla.org/rdf/datasource;1?name=window-mediator"].
getService(Components.interfaces.nsIRDFDataSource);
window_mediator2.AddObserver(observer);
=========
>For example (for the listener case), despite I receive the window as a parameter (xul_window), these properties:
>
> xul_window.title
> xul_window.windowtype
>
>Always return "undefined" (nsIXULWindow?)
>
>
You need to use the properties of nsIXULWindow. In your case, start with
the docShell property which gives you an nsIDocShell. You then need to
QueryInterface that into an nsIInterfaceRequestor. You can then call the
getInterface method to give you an nsIDOMWindow.
--
Warning: May contain traces of nuts.
A toplevel window in a XUL app is an nsXULWindow. Inside that there is an
nsGlobalWindow (aka nsIDOMWindow).
You can get the nsIDOMWindow you want via getInterface on the docShell property
of nsIXULWindow.
-Boris
Just for the record, this is the code that did the job
========
var dom_win = xul_window
.docShell
.QueryInterface(Components.interfaces.nsIInterfaceR
equestor)
.getInterface(Components.interfaces.nsIDOMWindow);
========
I want to block the opening of any window for a certain period of
time. If after the line above I use:
dom_win.close();
or
setTimeout(dom_win.close(), 0);
Thunderbird crashes :-S for any window like, say, a message window
If this is not the best way of doiung it (ie. monitoring the opening
of windows and inmediately close such opened window), is there any
other way?
Thanks in advance
On Jan 26, 6:31 am, Neil <n...@parkwaycc.co.uk> wrote:
> Mark wrote:
> >For example (for the listener case), despite I receive the window as a parameter (xul_window), these properties:
>
> > xul_window.title
> > xul_window.windowtype
>
> >Always return "undefined" (nsIXULWindow?)You need to use the properties of nsIXULWindow. In your case, start with
>I want to block the opening of any window for a certain period of time. If after the line above I use:
>
>dom_win.close();
>
>or
>
>setTimeout(dom_win.close(), 0);
>
>Thunderbird crashes :-S for any window like, say, a message window
>
>
Well, I guess that's a bug, but to work around it you could try waiting
until the window has loaded.
Those calls are equivalent -- they call dom_win.close immediately. Did you mean
setTimeout(dom_win.close, 0)?
> Well, I guess that's a bug
Agreed. Please file, with attached testcase XPI as needed?
-Boris
Nickolay
Good question. ;)
> I'd use one of the safer methods described in the yellow box here:
> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:this_Operator#Method_binding
Yeah, good idea.
-Boris