home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2005 December
/
PCWorld_2005-12_cd.bin
/
komunikace
/
netscape
/
nsb-install-8-0.exe
/
components
/
optout.js
< prev
next >
Wrap
Text File
|
2005-09-26
|
9KB
|
300 lines
/*
* Constants
*/
const OPTOUT_CONTRACTID = '@mozilla.org/optout;1';
const OPTOUT_CID = Components.ID('{FF17BE30-85F8-11D9-9669-0800200C9A66}');
const OPTOUT_IID = Components.interfaces.nsIOptOutService;
/*
* Class definitions
*/
/* The nsOptOut class constructor. */
function nsOptOut() {
// this.Init();
}
/* the nsOptOut class def */
nsOptOut.prototype = {
OPTOUT_NS : "http://home.netscape.com/NC-optout#",
OO_FILENAME : "optout.rdf",
OO_REMOTEURL : null,
RES_HOSTNAME : null,
RDFService : null,
RDFDataSource : null,
RDFLoadObserver : null,
RemoteRDFLoadObserver : null,
SiteList : null,
MyInit : function () {
// dump("OPTOUT: MyInit()\n");
if (!this.RDFService) {
this.RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
this.RES_HOSTNAME = this.RDFService.GetResource(this.OPTOUT_NS+"hostname");
}
if (!this.SiteList) {
this.SiteList = new Array();
}
if (!this.RDFLoadObserver) {
this.debug("Instantiating observer");
this.RDFLoadObserver = {
onBeginLoad : function(sink){},
onInterrupt : function(sink){},
onResume : function(sink){},
onError : function(sink,status,msg){},
onEndLoad : function(sink) {
RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
this.debug("onEndLoad()");
sink.removeXMLSinkObserver(this);
sink.QueryInterface(Components.interfaces.nsIRDFDataSource);
this.debug('Loaded datasource: '+sink.URI);
resources = sink.GetAllResources();
while (resources.hasMoreElements()) {
res = resources.getNext();
res.QueryInterface(Components.interfaces.nsIRDFResource);
this.parent.HandleResource(sink, res);
RDFService.UnregisterResource(res);
}
RDFService.UnregisterDataSource(sink);
// Now update from the server
this.parent.RefreshRemoteComponents();
},
debug : function(msg) {
this.parent.debug('RDFLoadObserver: '+msg);
},
QueryInterface: function(aIID)
{ if (!aIID.equals(Components.interfaces.nsIObserver) &&
!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.nsIRDFXMLSinkObserver))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};
this.RDFLoadObserver.parent = this;
}
if (!this.RemoteRDFLoadObserver) {
this.debug("Instantiating other observer");
this.RemoteRDFLoadObserver = {
bNewComponents : false,
newList : null,
onBeginLoad : function(sink){},
onInterrupt : function(sink){},
onResume : function(sink){},
onError : function(sink,status,msg){},
onEndLoad : function(sink) {
RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
this.debug("onEndLoad()");
sink.removeXMLSinkObserver(this);
this.debug('Loaded datasource: '+sink.URI);
var fileURI = this.parent.GetLocalFile();
sink.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
sink.FlushTo(fileURI.spec);
RDFService.UnregisterDataSource(sink);
},
debug : function(msg) {
this.parent.debug('RemoteRDFLoadObserver: '+msg);
},
QueryInterface: function(aIID)
{ if (!aIID.equals(Components.interfaces.nsIObserver) &&
!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.nsIRDFXMLSinkObserver))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};
this.RemoteRDFLoadObserver.parent = this;
}
},
RefreshRemoteComponents : function() {
var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
this.debug("RefreshRemoteComponents()");
var user_guid = gPrefService.getCharPref("browser.info.guid");
var partnerId;
try {
partnerId = gPrefService.getCharPref("browser.partnerId");
} catch (ex) {
partnerId = 'chapera';
}
var REMOTE_RDF_URL = gPrefService.getCharPref("optout.URL");
// + "?guid=" + user_guid + "&partnerId=" + partnerId;
try {
this.RDFDataSource = this.RDFService.GetDataSource(REMOTE_RDF_URL);
this.RDFDataSource.QueryInterface(Components.interfaces.nsIRDFXMLSink);
this.RDFDataSource.addXMLSinkObserver(this.RemoteRDFLoadObserver);
} catch (ex) { }
this.debug("Finished RefreshRemoteComponents()");
},
/**
* Grabs a local RDF file describing what SPUI components are
* currently available, and sets listener on the loading of that
* file.
**/
RefreshSiteList : function() {
this.debug("RefreshSiteList()");
this.MyInit();
var fileURI = this.GetLocalFile();
try {
this.RDFDataSource = this.RDFService.GetDataSource(fileURI.spec);
this.RDFDataSource.QueryInterface(Components.interfaces.nsIRDFXMLSink);
this.RDFDataSource.addXMLSinkObserver(this.RDFLoadObserver);
} catch (ex) {
this.RefreshRemoteComponents();
}
this.debug("Finished RefreshSiteList()");
},
GetLocalFile : function() {
var profileDir = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("ProfD", Components.interfaces.nsIFile);
profileDir.append(this.OO_FILENAME);
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var fileURI = ios.newFileURI(profileDir);
return fileURI;
},
/**
* Parse the description for a particular resource
**/
HandleResource : function(datasource, res) {
this.debug('Found resource: '+res.Value);
var labels = datasource.ArcLabelsOut(res);
while (labels.hasMoreElements()) {
var label = labels.getNext();
if (label instanceof Components.interfaces.nsIRDFResource) {
var dbg = '* '+label.Value;
var target = datasource.GetTarget(res, label, true);
if (target instanceof Components.interfaces.nsIRDFResource) {
dbg += ' => '+target.Value;
} else if (target instanceof Components.interfaces.nsIRDFLiteral) {
dbg += ' => '+target.Value;
} else {
try {
dbg += ' => '+target.Value;
} catch (ex) { }
}
this.debug(dbg);
}
}
// See if this resource specifies an actual SPUI component
if (datasource.hasArcOut(res, this.RES_HOSTNAME))
{
this.debug('^** this is an optout site! **^');
var siteHostName = datasource.GetTarget(res, this.RES_HOSTNAME, true);
siteHostName.QueryInterface(Components.interfaces.nsIRDFLiteral);
this.SiteList.push(siteHostName.Value);
}
},
isInList: function (aSiteName) {
this.debug("IsInList()");
this.MyInit();
if (!this.SiteList) return false;
for (var i=0; i< this.SiteList.length; i++) {
this.debug("Checking against site : " + this.SiteList[i] + " \n");
if (this.siteMatch(this.SiteList[i],aSiteName))
return true;
}
return false;
},
siteMatch: function (aSiteName, bSiteName) {
if (bSiteName.indexOf(aSiteName) > -1)
return true;
return false;
},
debug : function (aStr) {
var gPrefService =
Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (gPrefService.getPrefType("optout.debug") &&
gPrefService.getBoolPref("optout.debug"))
{
dump("OPTOUT: " + aStr + "\n");
}
},
QueryInterface: function(iid) {
if (!iid.equals(Components.interfaces.nsISupports) &&
!iid.equals(OPTOUT_IID))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};
/*
* Objects
*/
/* nsOptOut Module (for XPCOM registration) */
var nsOptOutModule = {
registerSelf: function(compMgr, fileSpec, location, type) {
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
compMgr.registerFactoryLocation(OPTOUT_CID,
"nsOptOut JS component",
OPTOUT_CONTRACTID,
fileSpec,
location,
type);
},
getClassObject: function(compMgr, cid, iid) {
if (!cid.equals(OPTOUT_CID))
throw Components.results.NS_ERROR_NO_INTERFACE;
if (!iid.equals(Components.interfaces.nsIFactory))
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
return nsOptOutFactory;
},
canUnload: function(compMgr) {
return true;
}
};
/* nsOptOut Class Factory */
var nsOptOutFactory = {
createInstance: function(outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
if (!iid.equals(OPTOUT_IID) &&
!iid.equals(Components.interfaces.nsISupports))
throw Components.results.NS_ERROR_INVALID_ARG;
return new nsOptOut();
}
}
/*
* Functions
*/
/* module initialisation */
function NSGetModule(comMgr, fileSpec) {
return nsOptOutModule;
}