home *** CD-ROM | disk | FTP | other *** search
Wrap
var sitecontrols; if (!sitecontrols) { sitecontrols = { // Set to true to enable debug output DEBUG : true, SC_NS : "http://home.netscape.com/SC-rdf#", NC_NS : "http://home.netscape.com/NC-rdf#", WEB_NS : "http://home.netscape.com/WEB-rdf#", RDF_NS : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", XUL_NS : "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", NC_NS_CMD : null, SC_VERIFIED_DEFAULT : "SiteControls:VerifiedDefault", SC_NOT_VERIFIED_DEFAULT : "SiteControls:NotVerifiedDefault", SC_WARNING_DEFAULT : "SiteControls:WarningDefault", SC_LOCAL : "SiteControls:Local", DEFAULT_URI : "SiteControls:Default", DEFAULT_SITE : "Default", defaults : null, // definition of the services frequently used for site controls kRDFContractID : "@mozilla.org/rdf/rdf-service;1", kRDFSVCIID : Components.interfaces.nsIRDFService, kRDFRSCIID : Components.interfaces.nsIRDFResource, kRDFLITIID : Components.interfaces.nsIRDFLiteral, kRDFDSIID : Components.interfaces.nsIRDFDataSource, RDF : null, kRDFCContractID : "@mozilla.org/rdf/container;1", kRDFCIID : Components.interfaces.nsIRDFContainer, RDFC : null, kRDFCUContractID : "@mozilla.org/rdf/container-utils;1", kRDFCUIID : Components.interfaces.nsIRDFContainerUtils, RDFCU : null, kPREFContractID : "@mozilla.org/preferences-service;1", kPREFIID : Components.interfaces.nsIPrefService, kPBIID : Components.interfaces.nsIPrefBranch, PREF : null, kSOUNDContractID : "@mozilla.org/sound;1", kSOUNDIID : Components.interfaces.nsISound, SOUND : null, kWINDOWContractID : "@mozilla.org/appshell/window-mediator;1", kWINDOWIID : Components.interfaces.nsIWindowMediator, WINDOWSVC : null, kDSContractID : "@mozilla.org/widget/dragservice;1", kDSIID : Components.interfaces.nsIDragService, DS : null, kSCContractID : "@mozilla.org/browser/sitecontrols-service;1", kSCSVCIID : Components.interfaces.nsISiteControlsService, SCSVC : null, SCDS : null, initServices : function() { this.debug('initServices()'); if (!this.SCDS) { this.NS_NS_CMD = this.NC_NS + "command?cmd="; this.RDF = Components.classes[this.kRDFContractID].getService(this.kRDFSVCIID); this.RDFC = Components.classes[this.kRDFCContractID].createInstance(this.kRDFCIID); this.RDFCU = Components.classes[this.kRDFCUContractID].getService(this.kRDFCUIID); this.PREF = Components.classes[this.kPREFContractID].getService(this.kPBIID); this.SOUND = Components.classes[this.kSOUNDContractID].createInstance(this.kSOUNDIID); this.WINDOWSVC = Components.classes[this.kWINDOWContractID].getService(this.kWINDOWIID); this.DS = Components.classes[this.kDSContractID].getService(this.kDSIID); this.SCSVC = Components.classes[this.kSCContractID].getService(this.kSCSVCIID); this.SCDS = this.SCSVC.QueryInterface(this.kRDFDSIID); } }, notifyUser : function(actionType) { if (!this.promptService) this.promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); if (this.PREF.getBoolPref("browser.sitecontrols.notify." + actionType)) { var promptTitle; var promptMsg; switch (actionType) { case "switch_to_ie" : promptTitle = "Vulnerability Warning"; promptMsg = "You have chosen to view this web site using the Internet Explorer display engine. Your setting will be remembered the next time you visit this site. Please be aware that there are known security vulnerabilities with the Internet Explorer display engine."; break; case "enable_activex" : promptTitle = "Vulnerability Warning"; promptMsg = "You have chosen to enable ActiveX on this web site. Your setting will be remembered the next time you visit this site. Please be aware that there are known security vulnerabilities with ActiveX."; break; case "enable_vbscript" : promptTitle = "Vulnerability Warning"; promptMsg = "You have chosen to enable VB Script on this web site. Your setting will be remembered the next time you visit this site. Please be aware that there are known security vulnerabilities with VB Script."; break; case "disable_javascript" : promptTitle = "Compatibility Warning"; promptMsg = "You have chosen to disable javascript on this web site. Your setting will be remembered the next time you visit this site. Please be aware that many web sites will not display correctly without javascript turned on."; break; case "disable_cookies" : promptTitle = "Compatibility Warning"; promptMsg = "You have chosen to disable cookies on this web site. Your setting will be remembered the next time you visit this site. Please be aware that many web sites will not display correctly without cookies turned on."; break; } var checkResult = {}; checkResult.value = true; var flags = this.promptService.BUTTON_TITLE_IS_STRING * this.promptService.BUTTON_POS_0 + this.promptService.BUTTON_TITLE_IS_STRING * this.promptService.BUTTON_POS_1 + this.promptService.BUTTON_POS_1_DEFAULT; // promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 + var result = this.promptService.confirmEx(window, promptTitle, promptMsg, flags, "Open Site Controls Options", "OK", null, "Don't show this message again", checkResult); if (checkResult.value) this.PREF.setBoolPref("browser.sitecontrols.notify." + actionType, false); dump('**** result value: ' + result + '\n'); if (!result) openSiteControlPrefs(); } }, // It's *probably* okay to get rid of this entirely... but first make sure it's not // being called from anywhere else updateSecurityLevel : function(currentURI) { this.SCSVC.updateSiteControl(this.getHostStringFromURL(currentURI), 'securityLevel', 'Custom'); this.debug('*** set securityLevel to CUSTOM'); }, setSecurityLevel : function(site, level) { this.debug('setSecurityLevel(...,'+level+')'); var resourceToCopy = null; switch (level) { case 'low': // I Trust resourceToCopy = this.RDF.GetResource(this.SC_VERIFIED_DEFAULT); this.SCSVC.updateSiteControlResource(site, 'securityLevel', 'Low'); break; case 'medium': // I'm not sure resourceToCopy = this.RDF.GetResource(this.SC_NOT_VERIFIED_DEFAULT); this.SCSVC.updateSiteControlResource(site, 'securityLevel', 'Medium'); break; case 'high': // I don't trust resourceToCopy = this.RDF.GetResource(this.SC_WARNING_DEFAULT); this.SCSVC.updateSiteControlResource(site, 'securityLevel', 'High'); break; default: this.debug('WARNING: unrecognized security level ['+level+']'); return; } var propertiesToCopy = [ 'displayEngine', 'allowPopups', 'requestedPopupsInTab', 'allowImages', 'imagesFromOrigOnly', 'enableActiveX', 'enableJava', 'enableJavaScript', 'jsMoveResize', 'jsRaiseLower', 'jsContextMenu', 'jsHideStatusBar', 'jsStatusBarText', 'jsChangeImages', 'allowCookies', 'cookiesFromOrigOnly' ]; this.debug(' about to copy properties...'); for (var p in propertiesToCopy) { var prop = propertiesToCopy[p]; try { var value = this.SCSVC.readSiteControlResource(resourceToCopy, prop); this.SCSVC.updateSiteControlResource(site, prop, value); } catch (ex) { this.debug('WARNING: error copying property "'+prop+'"'); } } BrowserReload(); // If the current display engine is Trident then notify var displayEngine = this.SCSVC.readSiteControlResource(site, 'displayEngine'); if (displayEngine.value == 'Trident') this.notifyUser('switch_to_ie'); this.debug(' ...END setSecurityLevel.'); }, getHostStringFromURL : function(url) { var dbg = false; var host = url; if (dbg) this.debug('Parsing URL: '+url); // if this is a local file if(url.indexOf("file://") == 0) { return this.SC_LOCAL; } host = host.substring(host.indexOf('://')+3); if (dbg) this.debug('Stripped proto: '+host); var postHostSlash = host.indexOf('/'); if (postHostSlash > -1) { host = host.substring(0, postHostSlash); if (dbg) this.debug('Stripped path: '+host); } var userInfo = host.indexOf('@'); if (userInfo > -1) { host = host.substring(userInfo+1); if (dbg) this.debug('Stripped user: '+host); } var port = host.indexOf(':'); if (port > -1) { host = host.substring(0, port); if (dbg) this.debug('Stripped port: '+host); } return host; }, getStrippedHostFromURL : function(url) { var host = this.getHostStringFromURL(url); return this.stripWWW(host); }, getDomainFromURL : function(url) { var host = this.getHostStringFromURL(url); return this.getDomainFromHost(host); }, getDomainFromHost : function(host) { var matches = this.getSiteStringsFromHost(host); return matches[matches.length-1]; }, getSiteStringsFromHost : function(host) { var matches = []; matches[matches.length] = host; var str = host; while ((str.indexOf('.') > -1) && (str.substring(str.indexOf('.')+1).indexOf('.') > -1)) { // There are at least two periods '.' in str str = str.substring(str.indexOf('.')+1); matches[matches.length] = str; } //for (i = 0; i < matches.length; i++) this.debug('match: '+matches[i]); return matches; }, getSiteStringsFromURL : function(url) { var host = this.getHostStringFromURL(url); return this.getSiteStringsFromHost(host); }, getControlledSiteFromHost : function(host) { return this.SCSVC.getControlledSite(host); }, getControlledSiteFromURL : function(url) { var host = this.getHostStringFromURL(url); return this.getControlledSiteFromHost(host); }, stripWWW : function(host) { if (host.substring(0,4)=='www.') return host.substring(4); else return host; }, debug : function(msg) { if (this.DEBUG) dump('sitecontrols.js: '+msg+'\n'); }, dumpRDF : function() { var resources = this.SCDS.GetAllResources(); while (resources.hasMoreElements()) { var res = resources.getNext(); res.QueryInterface(this.kRDFRSCIID); this.debug('resource: '+res.Value); var labels = this.SCDS.ArcLabelsOut(res); while (labels.hasMoreElements()) { var label = labels.getNext(); if (label instanceof this.kRDFRSCIID) { var dbg = ' * '+label.Value; var target = this.SCDS.GetTarget(res, label, true); if (target instanceof this.kRDFRSCIID) { dbg += ' => '+target.Value; } else if (target instanceof this.kRDFLITIID) { dbg += ' => '+target.Value; } else { try { dbg += ' => '+target.Value; } catch (ex) { } } this.debug(dbg); } } } } }; sitecontrols.initServices(); } /***** Site Controls RDF Filter Wrapper *****/ // This is a wrapper for the rdf:sitecontrols datasource so that // we can implement the filtering behaviour in the tree const NS_RDF_NO_VALUE = 0xa0002; const NS_RDF_ASSERTION_REJECTED = 0xa0003; const SC_TITLE = sitecontrols.RDF.GetResource(sitecontrols.SC_NS + "title"); function SiteControlsFilterDataSource() { dump("sitecontrols.js : SiteControlsFilterDataSource\t\t"); this.mInner = sitecontrols.RDF.GetDataSource("rdf:sitecontrols"); this.mInner.AddObserver(this); this.mObservers = new Array(); this.mFilter = null; } SiteControlsFilterDataSource.prototype = { SetFilter : function(str) { if (!str || (str == '')) this.mFilter = null; else this.mFilter = str; }, /* nsIRDFDataSource */ URI: "rdf:sitecontrols-filtered", GetSource: function(pred, obj, tv) { return this.mInner.GetSource(pred, obj, tv); }, GetSources: function(pred, obj, tv) { return this.mInner.GetSources(pred, obj, tv); }, GetTarget: function(subj, pred, tv) { // All resources other than TITLEs are handled normally var target = this.mInner.GetTarget(subj, pred, tv); if (pred != SC_TITLE) return target; var name = this.mInner.GetTarget(subj, NC_NAME, true) .QueryInterface(Components.interfaces.nsIRDFLiteral) .Value; // Omit the 'special' site controls if (name == 'Verified Default' || name == 'Not Verified Default' || name == 'Warning Default' || name == 'Local Files') { return null; } if (this.mFilter) { // Only return the value if it matches the filter if (name.indexOf(this.mFilter) == -1) return null; else return sitecontrols.RDF.GetLiteral(name); } else { return target; } }, GetTargets: function(subj, pred, tv) { // All resources other than TITLEs are handled normally var targets = this.mInner.GetTargets(subj, pred, tv); if (pred != SC_TITLE) return targets; // Create a wrapper enumerator that will skip any // items that don't match the filter, etc. var enumerator = { mInner : null, mFilter : null, mTotal : 0, mNext : 1, init : function(initEnum) { while (initEnum.hasMoreElements()) { node = initEnum.getNext(); lit = node.QueryInterface(Components.interfaces.nsIRDFLiteral); if (lit.Value == 'Verified Default' || lit.Value == 'Not Verified Default' || lit.Value == 'Warning Default' || lit.Value == 'Local Files') { continue; } if (!this.mFilter || lit.Value.indexOf(this.mFilter) != -1) this.mTotal++; } }, hasMoreElements : function() { return (this.mNext <= this.mTotal); }, getNext : function() { while (this.mInner.hasMoreElements()) { node = this.mInner.getNext(); if (!node) return null; lit = node.QueryInterface(Components.interfaces.nsIRDFLiteral); if (lit.Value == 'Verified Default' || lit.Value == 'Not Verified Default' || lit.Value == 'Warning Default' || lit.Value == 'Local Files') { continue; } if (!this.mFilter || lit.Value.indexOf(this.mFilter) != -1) { this.mNext++; return lit; } } return null; } }; enumerator.mInner = targets; enumerator.mFilter = this.mFilter; enumerator.init(this.mInner.GetTargets(subj, pred, tv)); return enumerator; }, Assert: function(subj, pred, obj, tv) { throw NS_RDF_ASSERTION_REJECTED; }, Unassert: function(subj, pred, obj, tv) { throw NS_RDF_ASSERTION_REJECTED; }, Change: function(subj, pred, oldobj, newobj) { throw NS_RDF_ASSERTION_REJECTED; }, Move: function(oldsubj, newsubj, pred, obj) { throw NS_RDF_ASSERTION_REJECTED; }, HasAssertion: function(subj, pred, obj, tv) { // All resources other than TITLEs are handled normally var hasAssert = this.mInner.HasAssertion(subj, pred, obj, tv); if (pred != SC_TITLE) return hasAssert; var lit = obj.QueryInterface(Components.interfaces.nsIRDFLiteral); if (lit.Value == 'Verified Default' || lit.Value == 'Not Verified Default' || lit.Value == 'Warning Default' || lit.Value == 'Local Files') { return null; } if (this.mFilter && lit.Value.indexOf(this.mFilter) == -1) return null; else return hasAssert; }, AddObserver: function(aObserver) { this.mObservers.push(aObserver); }, RemoveObserver: function(aObserver) { for (var i = 0; i < this.mObservers.length; ++i) { if (aObserver == this.mObservers[i]) { this.mObservers.splice(i, 1); break; } } }, ArcLabelsIn: function(obj) { return this.mInner.ArcLabelsIn(obj); }, ArcLabelsOut: function(subj) { return this.mInner.ArcLabelsOut(obj); }, GetAllResources: function() { return this.mInner.GetAllResources(); }, hasArcIn: function(obj, pred) { return this.mInner.hasArcIn(obj, pred); }, hasArcOut: function(subj, pred) { return this.mInner.hasArcOut(subj, pred); }, /* nsIRDFObserver */ onAssert: function(ds, subj, pred, obj) { for (var obs in this.mObservers) obs.onAssert(this, subj, pred, obj); }, onUnassert: function(ds, subj, pred, obj) { for (var obs in this.mObservers) obs.onUnassert(this, subj, pred, obj); }, onChange: function(ds, subj, pred, oldobj, newobj) { for (var obs in this.mObservers) obs.onChange(ds, subj, pred, oldobj, newobj); }, onMove: function(ds, oldsubj, newsubj, pred, obj) { for (var obs in this.mObservers) obs.onMove(ds, oldsubj, newsubj, pred, obj); } };