[Project_owners] HTTP Auth's opening URL

Michael Vincent mv_van_rantwijk at yahoo.com
Wed Sep 28 01:54:44 EDT 2005


Eric Jung wrote:
> Thanks, but in FF aXULWindow.docshell doesn't to contain anything.
> The following dumps empty/nothing. Anyone have other ideas?

You need to QI the docShell before that works.

Look at:

http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#260

and:

http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#478

> const gWindowManagerListener = {
>   onOpenWindow: function(aXULWindow) {
>     for (i in aXULWindow.docshell)
>       dump(i + "=" + aXULWindow.docshell[i] + "\n");
>     dump("======================================");
>   },
>   onCloseWindow: function(aXULWindow) {},
>   onWindowTitleChange: function(aXULWindow, aWindowTitle) {}
> };
> 
> const gWindowManager = 
>   Components.classes['@mozilla.org/appshell/window-mediator;1']
>   .getService(Components.interfaces.nsIWindowMediator);
> 
> gWindowManager.addListener(gWindowManagerListener);
> 
> 
> 
> --- Michael Vincent <mv_van_rantwijk at yahoo.com> wrote:
> 
>> Eric Jung wrote:
>>> Hi,
>>> My extension is watching for HTTP Basic Authorization dialog
>> prompts
>>> with the following code. I'm trying to determine the URL to which
>> the
>>> dialog attached, but
>>> aEvent.currentTarget.opener.content.document.location is not
>> reliable
>>> when multiple tabs are open.
>>>
>>> var watcher =
>>>   Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
>>>   .createInstance(Components.interfaces.nsIWindowWatcher);
>>>   watcher.registerNotification(this);
>>>
>>> observe : function(domWindow, topic, data) {
>>>   if (topic == "domwindowopened") {
>>>     // wait for xul to load
>>>     domWindow.addEventListener("load", this.onNewWnd, true);
>>>   }
>>> },
>>>
>>> onNewWnd : function(aEvent) {
>>>   var wnd = aEvent.currentTarget;
>>>   if (wnd.document.getElementById("commonDialog") != null) {
>>>     if (wnd.opener.content) {      
>>>       dump("wnd.opener.content.document.location+"\n");
>>>     }
>>>   }
>>> }
>>>
>>> Does anyone know what I might be doing wrong?
>>>
>>> Thanks in advance for any help,
>>> Eric
>> Don't use that, but use something similar like this instead:
>>
>> const gWindowManager = 
>> Components.classes['@mozilla.org/appshell/window-mediator;1']
>>  
>> .getService(Components.interfaces.nsIWindowMediator);
>>
>> const gWindowManagerListener =
>> {
>>    onOpenWindow: function(aXULWindow) {},
>>    onCloseWindow: function(aXULWindow) {},
>>    onWindowTitleChange: function(aXULWindow, aWindowTitle) {}
>> };
>>
>> gWindowManager.addListener(gWindowManagerListener);
>> gWindowManager.removeListener(gWindowManagerListener);
>>
>> ...and the 'magic' is: aXULWindow.docShell;
>> because that ultimately leads to anything you want...like the tab, 
>> browser, uri, chrome window...you name it. It's all there ;)
>>
>> Michael


More information about the Project_owners mailing list