On Nov 15, 2007 1:19 PM, joe ertaba <[EMAIL PROTECTED]> wrote: > would you please help me how to use js code in > "http://forums.mozillazine.org/viewtopic.php?p=1694347#1694347" > > first i generate guid then i put js code in components folder of my > extension, then what :)) > OK. Now you need to let Firefox know it needs to "register" your component. Registration is a costly process that builds a list of components Firefox knows about. Until your component is registered, you can't use it and it won't run. (I'm simplifying, if you're interested in details, read Creating XPCOM Components book or the code).
Since registration is costly it doesn't happen automatically when you copied the js file to your "components" folder. You need to let Firefox it needs to re-register components before you can use it. When a user installs an extension packaged as XPI, registration happens automatically. Since you're developing and probably don't want to package the extension as XPI yet, you can force registration by going to your profile folder and deleting compreg.dat (and xpti.dat if you have any .xpt files). > asqueella said: > Either put the .js file with this code in Firefox/components or in your XPI > file and install it. Delete compreg.dat to be safe, and it should get > registered. > > what does either main here ? OK, that was confusing. I replaced it with a link to http://developer.mozilla.org/en/docs/How_to_Build_an_XPCOM_Component_in_Javascript#Installation > am i need to create xpt file too ? > Not unless you want to use your own interface, which you probably don't right now. See http://developer.mozilla.org/en/docs/How_to_Build_an_XPCOM_Component_in_Javascript and http://developer.mozilla.org/en/docs/wrappedJSObject which it links to. Nickolay > > On Nov 15, 2007 1:01 PM, Michael Vincent van Rantwijk, MultiZilla < > [EMAIL PROTECTED]> wrote: > > Nickolay Ponomarev wrote: > > > On Nov 15, 2007 11:06 AM, Michael Vincent van Rantwijk, MultiZilla > > > > > <[EMAIL PROTECTED]> wrote: > > > > >>> //register Observer > > >>> window.addEventListener("load", MyObserver, false); > > >>> function MyObserver(){ > > >>> var observerService = > Components.classes["@mozilla.org/observer-service;1"] > > >>> .getService( Components.interfaces.nsIObserverService); > > >> Don't do that here, but outside the observer; because it will 'run' for > > >> all loads! > > >> > > > Huh? > > > > This is two fold as moving "var observerService" out of the observer > > scope, makes the observer a few ms faster, and there is probably no need > > to add a new observer for each time the load event is triggered. > > > > > > >>> 1. how can i find that observer is registered before or not ? > > >> Have you looked at enumerateObservers in nsIObserverService.idl > already? > > >> > > > > > Oops. Still you shouldn't use it, at least in your case. (I question > > > the kosherness of its in-tree uses). > > > > Choice is something good in my books, and it is an option, but I would > > rather use the other tip (see link) myself. > > > > > > >>> 2. when i register observer only when first window opens every > thing > > >>> is ok, when i open some other windows still every thing is ok and > observer > > >>> works perfectly, but when i close first window while other windows > are still > > >>> open the observer doesn't work anymore ?! > > >> There is a hidden window which you can use, or better use a > (JavaScript) > > >> component to store your global vars and observers, which makes > listening > > >> for opening and closing of (browser) windows also a lot easier. > > >> > > > > > Can we stop suggesting people use the hidden window? It's an > > > implementation detail really, not to be used by extensions. > > > > Well well... do we make progress ;) > > > > > > > > > > -- > > Michael Vincent van Rantwijk > > - MultiZilla Project Team Lead > > - XUL Boot Camp Staff member (ActiveState Training Partner) > > - iPhone Application Developer > > > > _______________________________________________ > > Project_owners mailing list > > [email protected] > > https://www.mozdev.org/mailman/listinfo/project_owners > > > > > _______________________________________________ > Project_owners mailing list > [email protected] > https://www.mozdev.org/mailman/listinfo/project_owners > > _______________________________________________ Project_owners mailing list [email protected] https://www.mozdev.org/mailman/listinfo/project_owners
