On Apr 7, 12:26*am, don rhummy wrote:
> Thanks! That's a good idea and good to know.
>
> Is that the best way to check something via http in an extension? Or is there another Components.classes 9or even something else) interface to use?
>
> --- On Mon, 4/6/09, 0x000000 wrote:
>
> > From: 0x000000
> > Subject: Re: How use XMLHttpRequest in extension toolbar?
> > To: dev-extensi...@lists.mozilla.org
> > Date: Monday, April 6, 2009, 3:28 PM
> > Well actually only the XPCOM objects can do it since it has
> > the right
> > ownership, or should I say: SHOULD do it. Otherwise
> > JavaScript that is
> > resourced from the extension could access it, which you
> > wouldn't want
> > since that's a security hole. ;-)

>
> > So this works only in your extension:

>
> > ----------------------------------------------8<-------------------------------------------------------------
> > var xml =
> > Components.classes["@mozilla.org/xmlextras/xmlhttprequest;
> > 1"]

>
> > .createInstance(Components.interfaces.nsIXMLHttpRe quest);

>
> > * *// xml.onprogress = INIT.onprogress('httpresult');

>
> > * *xml.open("GET",
> > "http://www.google.com" , false);
> > * *xml.overrideMimeType("text/xml");
> > * *// bypass cache?
> > * *xml.channel.loadFlags |=
> > Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE ;
> > * *xml.send(null);

>
> > * *if(xml.status == 200) {
> > * * * * * *// do stuff.
> > * *}
> > ----------------------------------------------
> > >8-------------------------------------------------------------

> > _______________________________________________
> > dev-extensions mailing list
> > dev-extensi...@lists.mozilla.org
> >https://lists.mozilla.org/listinfo/dev-extensions


Well, you could use sockets also for example. But I guess that's a bit
overkill if you only want to check the status or simply pull some info
from a site. And you'll probably have to do that in an asynchronous
way also, due to the asynchronous character of networking. So a xml
http request would suffice for most uses.