1999-09-22 01:11:29 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
|
1999-11-02 10:36:25 +03:00
|
|
|
/*
|
|
|
|
* No magic constructor behaviour, as is de rigeur for XPCOM.
|
|
|
|
* If you must perform some initialization, and it could possibly fail (even
|
|
|
|
* due to an out-of-memory condition), you should use an Init method, which
|
|
|
|
* can convey failure appropriately (thrown exception in JS,
|
|
|
|
* NS_FAILED(nsresult) return in C++).
|
|
|
|
*
|
|
|
|
* In JS, you can actually cheat, because a thrown exception will cause the
|
|
|
|
* CreateInstance call to fail in turn, but not all languages are so lucky.
|
|
|
|
* (Though ANSI C++ provides exceptions, they are verboten in Mozilla code
|
|
|
|
* for portability reasons -- and even when you're building completely
|
|
|
|
* platform-specific code, you can't throw across an XPCOM method boundary.)
|
|
|
|
*/
|
|
|
|
function mySample() { /* big comment for no code, eh? */ }
|
1999-09-22 01:11:29 +04:00
|
|
|
|
1999-11-02 10:36:25 +03:00
|
|
|
/* decorate prototype to provide ``class'' methods and property accessors */
|
|
|
|
mySample.prototype = {
|
|
|
|
/*
|
2000-09-18 06:31:11 +04:00
|
|
|
* get and set are new Magic in JS1.5, borrowing the intent -- if not
|
|
|
|
* the exact syntax -- from the JS2 design. They define accessors for
|
1999-11-02 10:36:25 +03:00
|
|
|
* properties on the JS object, follow the expected rules for prototype
|
|
|
|
* delegation, and make a mean cup of coffee.
|
|
|
|
*/
|
2000-06-14 08:46:22 +04:00
|
|
|
get value() { return this.val; },
|
2000-05-24 11:20:11 +04:00
|
|
|
set value(newval) { return this.val = newval; },
|
1999-09-22 01:11:29 +04:00
|
|
|
|
1999-11-02 10:36:25 +03:00
|
|
|
writeValue: function (aPrefix) {
|
2002-04-23 11:30:11 +04:00
|
|
|
debug("mySample::writeValue => " + aPrefix + this.val + "\n");
|
1999-11-02 10:36:25 +03:00
|
|
|
},
|
|
|
|
poke: function (aValue) { this.val = aValue; },
|
|
|
|
|
2000-09-18 06:31:11 +04:00
|
|
|
QueryInterface: function (iid) {
|
2004-05-18 03:38:25 +04:00
|
|
|
if (iid.equals(Components.interfaces.nsISample) ||
|
|
|
|
iid.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
return null;
|
2000-09-18 06:31:11 +04:00
|
|
|
},
|
|
|
|
|
1999-11-02 10:36:25 +03:00
|
|
|
val: "<default value>"
|
1999-09-22 01:11:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var myModule = {
|
1999-11-10 03:28:34 +03:00
|
|
|
firstTime: true,
|
|
|
|
|
1999-11-02 10:36:25 +03:00
|
|
|
/*
|
|
|
|
* RegisterSelf is called at registration time (component installation
|
|
|
|
* or the only-until-release startup autoregistration) and is responsible
|
|
|
|
* for notifying the component manager of all components implemented in
|
|
|
|
* this module. The fileSpec, location and type parameters are mostly
|
|
|
|
* opaque, and should be passed on to the registerComponent call
|
|
|
|
* unmolested.
|
|
|
|
*/
|
|
|
|
registerSelf: function (compMgr, fileSpec, location, type) {
|
1999-11-10 03:28:34 +03:00
|
|
|
if (this.firstTime) {
|
2002-04-23 11:30:11 +04:00
|
|
|
debug("*** Deferring registration of sample JS components\n");
|
1999-11-10 03:28:34 +03:00
|
|
|
this.firstTime = false;
|
|
|
|
throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
|
|
|
|
}
|
2002-04-23 11:30:11 +04:00
|
|
|
debug("*** Registering sample JS components\n");
|
2002-01-30 00:22:13 +03:00
|
|
|
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
compMgr.registerFactoryLocation(this.myCID,
|
|
|
|
"Sample JS Component",
|
2004-05-18 03:38:25 +04:00
|
|
|
this.myProgID,
|
2002-01-30 00:22:13 +03:00
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
1999-09-22 01:11:29 +04:00
|
|
|
},
|
|
|
|
|
1999-11-02 10:36:25 +03:00
|
|
|
/*
|
2004-09-02 19:38:56 +04:00
|
|
|
* The GetClassObject method is responsible for producing Factory objects
|
1999-11-02 10:36:25 +03:00
|
|
|
*/
|
|
|
|
getClassObject: function (compMgr, cid, iid) {
|
|
|
|
if (!cid.equals(this.myCID))
|
1999-09-22 01:11:29 +04:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
1999-11-02 10:36:25 +03:00
|
|
|
if (!iid.equals(Components.interfaces.nsIFactory))
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
return this.myFactory;
|
1999-09-22 01:11:29 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/* CID for this class */
|
1999-11-02 10:36:25 +03:00
|
|
|
myCID: Components.ID("{dea98e50-1dd1-11b2-9344-8902b4805a2e}"),
|
1999-09-22 01:11:29 +04:00
|
|
|
|
2000-09-18 06:31:11 +04:00
|
|
|
/* ProgID for this class */
|
|
|
|
myProgID: "@mozilla.org/jssample;1",
|
|
|
|
|
1999-09-22 01:11:29 +04:00
|
|
|
/* factory object */
|
1999-11-02 10:36:25 +03:00
|
|
|
myFactory: {
|
|
|
|
/*
|
2000-09-18 06:31:11 +04:00
|
|
|
* Construct an instance of the interface specified by iid, possibly
|
|
|
|
* aggregating it with the provided outer. (If you don't know what
|
|
|
|
* aggregation is all about, you don't need to. It reduces even the
|
|
|
|
* mightiest of XPCOM warriors to snivelling cowards.)
|
1999-11-02 10:36:25 +03:00
|
|
|
*/
|
2000-08-11 00:12:08 +04:00
|
|
|
createInstance: function (outer, iid) {
|
2002-04-23 11:30:11 +04:00
|
|
|
debug("CI: " + iid + "\n");
|
1999-11-02 10:36:25 +03:00
|
|
|
if (outer != null)
|
1999-09-22 01:11:29 +04:00
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
1999-11-02 10:36:25 +03:00
|
|
|
|
2000-09-18 06:31:11 +04:00
|
|
|
return (new mySample()).QueryInterface(iid);
|
1999-09-22 01:11:29 +04:00
|
|
|
}
|
1999-11-10 03:28:34 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2000-09-18 06:31:11 +04:00
|
|
|
* The canUnload method signals that the component is about to be unloaded.
|
|
|
|
* C++ components can return false to indicate that they don't wish to be
|
|
|
|
* unloaded, but the return value from JS components' canUnload is ignored:
|
|
|
|
* mark-and-sweep will keep everything around until it's no longer in use,
|
|
|
|
* making unconditional ``unload'' safe.
|
1999-11-10 03:28:34 +03:00
|
|
|
*
|
|
|
|
* You still need to provide a (likely useless) canUnload method, though:
|
|
|
|
* it's part of the nsIModule interface contract, and the JS loader _will_
|
|
|
|
* call it.
|
|
|
|
*/
|
|
|
|
canUnload: function(compMgr) {
|
2002-04-23 11:30:11 +04:00
|
|
|
debug("*** Unloading sample JS components\n");
|
1999-11-10 03:28:34 +03:00
|
|
|
return true;
|
1999-09-22 01:11:29 +04:00
|
|
|
}
|
|
|
|
};
|
2000-09-18 06:31:11 +04:00
|
|
|
|
1999-09-22 01:11:29 +04:00
|
|
|
function NSGetModule(compMgr, fileSpec) {
|
|
|
|
return myModule;
|
|
|
|
}
|
2002-01-30 00:22:13 +03:00
|
|
|
|
|
|
|
|