Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

observer for windows (and nsIXULWindow vs nsIDOMWindow)

81 views
Skip to first unread message

Mark

unread,
Jan 26, 2007, 3:54:54 AM1/26/07
to
Hello,

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);

=========

Neil

unread,
Jan 26, 2007, 6:31:48 AM1/26/07
to
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
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.

Boris Zbarsky

unread,
Jan 26, 2007, 10:58:11 AM1/26/07
to
Mark wrote:
> 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

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

Mark

unread,
Jan 27, 2007, 7:16:10 PM1/27/07
to mozilla.dev.extensions
Thanks again, it worked :-)

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

Neil

unread,
Jan 27, 2007, 7:35:19 PM1/27/07
to
Mark wrote:

>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.

Boris Zbarsky

unread,
Jan 28, 2007, 11:58:55 AM1/28/07
to
Neil wrote:
>> 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);

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 Ponomarev

unread,
Jan 28, 2007, 12:30:34 PM1/28/07
to dev-g...@lists.mozilla.org
On 1/28/07, Boris Zbarsky <bzba...@mit.edu> wrote:
> Neil wrote:
> >> 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);
>
> Those calls are equivalent -- they call dom_win.close immediately. Did you mean
> setTimeout(dom_win.close, 0)?
>
Will it work / close the right window? 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

Nickolay

Boris Zbarsky

unread,
Jan 28, 2007, 12:39:32 PM1/28/07
to
Nickolay Ponomarev wrote:
> Will it work / close the right window?

Good question. ;)

Yeah, good idea.

-Boris

0 new messages