[Project_owners] Hooking HTTP Basic Authentication dialog

Eric Jung grimholtz at yahoo.com
Sat Sep 17 14:42:56 EDT 2005


Hi,

I finally got it. I didn't need the other interfaces you mentioned.
My final question, if anyone's willing to answer, is do I need to
call removeEventListener() when the commonDialog is closing? What
happens if I don't "clean up" the listener? Is it a memory leak, or
are things ok?


var watcher=
  Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  .createInstance(Components.interfaces.nsIWindowWatcher);
watcher.registerNotification(this);

observe : function(domWindow, topic, data) {
  // Chrome isn't loaded yet, so listen for load evt
  if (topic == "domwindowopened")
    domWindow.addEventListener("load", this.onNewWnd, true);
},

onNewWnd : function(aEvent) {
  var wnd = aEvent.currentTarget;
  if (wnd.document.getElementById("commonDialog") != null) {
    wnd.document.getElementById("loginTextbox").value = "michael";
    wnd.document.getElementById("password1Textbox").value =
"vincent";
  }
},

Regards,
Eric


--- Michael Vincent <mv_van_rantwijk at yahoo.com> wrote:

> Eric Jung wrote:
> > Hi,
> > 
> > 
> > --- Michael Vincent <mv_van_rantwijk at yahoo.com> wrote:
> > 
> >> Eric Jung wrote:
> >>> Hi,
> >>> I'd like my extension to be notified when an HTTP Basic
> >>> Authentication dialog (like when you go here:
> >>> http://passwordmaker.org:2082/) is displayed and be able to
> write
> >> to
> >>> the input boxes of this dialog.
> >>>
> >>> Does a standard pageLoad eventListener intercept this, or is it
> >> more
> >>> complex?
> >>>
> >>> Thanks for any advice,
> >>> Eric Jung
> >> FYI: that dialog is commonDialog.xul/commonDialog.js
> >> and you can use  registerNotification in nsIWindowWatcher.idl
> >>
> > 
> > OK, I'm getting notifications now but can't find references to
> the
> > username & password input boxes:
> 
> You got the right window ID also?
> 
> > 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") {
> >     domWindow = 
> >      
> domWindow.QueryInterface(Components.interfaces.nsIDOMWindow);
> >       var user =
> domWindow.document.getElementById("loginTextbox");
> >       var pw =
> domWindow.document.getElementById("password1Textbox");
> >       dump(user + "\n");
> >       dump(pw + "\n");
> >     }
> >   },
> > 
> > This dumps null and null to the console.... :(
> 
> Yeah, you probably want to read nsIDialogParamBlock.idl and 
> nsPIPromptService.idl first
> 
> > FWIW, I can't find commonDialog.xul/commonDialog.js in FF (but
> maybe
> > I missed it?), just Mozilla.
> 
> Both are part of toolkit.jar and just remember that the DOM
> Inspector 
> can be a good friend ;)
> 
> >> Yeah, I'm totally crazy to be still awake at 12:40AM, but I got
> the
> >> day 
> >> off tomorrow, and I still have to fix something ;)
> >>
> > 
> > Heh. An all-night coding session. Those can be fun, but take care
> of
> > your health.
> 
> Thanks, and I sure will ;)
> 
> Michael
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Project_owners mailing list