home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / browser.jar / content / browser / sitecontrols / sitecontrols.js < prev    next >
Encoding:
Text File  |  2005-07-29  |  16.0 KB  |  524 lines

  1. var sitecontrols;
  2. if (!sitecontrols) {
  3.  
  4. sitecontrols = {
  5.  
  6.     // Set to true to enable debug output
  7.     DEBUG : true,
  8.  
  9.     SC_NS : "http://home.netscape.com/SC-rdf#",
  10.     NC_NS : "http://home.netscape.com/NC-rdf#",
  11.     WEB_NS : "http://home.netscape.com/WEB-rdf#",
  12.     RDF_NS : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
  13.     XUL_NS : "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
  14.     NC_NS_CMD : null,
  15.  
  16.     SC_VERIFIED_DEFAULT        :    "SiteControls:VerifiedDefault",
  17.     SC_NOT_VERIFIED_DEFAULT    :    "SiteControls:NotVerifiedDefault",
  18.     SC_WARNING_DEFAULT        :    "SiteControls:WarningDefault",
  19.     SC_LOCAL                :    "SiteControls:Local",
  20.     DEFAULT_URI                :    "SiteControls:Default",
  21.     DEFAULT_SITE            :    "Default",
  22.     defaults                :     null,
  23.  
  24.     // definition of the services frequently used for site controls
  25.     kRDFContractID : "@mozilla.org/rdf/rdf-service;1",
  26.     kRDFSVCIID : Components.interfaces.nsIRDFService,
  27.     kRDFRSCIID : Components.interfaces.nsIRDFResource,
  28.     kRDFLITIID : Components.interfaces.nsIRDFLiteral,
  29.     kRDFDSIID : Components.interfaces.nsIRDFDataSource,
  30.     RDF : null,
  31.  
  32.     kRDFCContractID : "@mozilla.org/rdf/container;1",
  33.     kRDFCIID :  Components.interfaces.nsIRDFContainer,
  34.     RDFC : null,
  35.  
  36.     kRDFCUContractID : "@mozilla.org/rdf/container-utils;1",
  37.     kRDFCUIID : Components.interfaces.nsIRDFContainerUtils,
  38.     RDFCU : null,
  39.  
  40.     kPREFContractID : "@mozilla.org/preferences-service;1",
  41.     kPREFIID : Components.interfaces.nsIPrefService,
  42.     kPBIID : Components.interfaces.nsIPrefBranch,
  43.     PREF : null,
  44.  
  45.     kSOUNDContractID : "@mozilla.org/sound;1",
  46.     kSOUNDIID : Components.interfaces.nsISound,
  47.     SOUND : null,
  48.  
  49.     kWINDOWContractID : "@mozilla.org/appshell/window-mediator;1",
  50.     kWINDOWIID : Components.interfaces.nsIWindowMediator,
  51.     WINDOWSVC : null,
  52.  
  53.     kDSContractID : "@mozilla.org/widget/dragservice;1",
  54.     kDSIID : Components.interfaces.nsIDragService,
  55.     DS : null,
  56.  
  57.     kSCContractID : "@mozilla.org/browser/sitecontrols-service;1",
  58.     kSCSVCIID : Components.interfaces.nsISiteControlsService,
  59.     SCSVC : null,
  60.     SCDS : null,
  61.  
  62.  
  63.     initServices : function() {
  64.         this.debug('initServices()');
  65.         if (!this.SCDS) {
  66.             this.NS_NS_CMD = this.NC_NS + "command?cmd=";
  67.             this.RDF       = Components.classes[this.kRDFContractID].getService(this.kRDFSVCIID);
  68.             this.RDFC      = Components.classes[this.kRDFCContractID].createInstance(this.kRDFCIID);
  69.             this.RDFCU     = Components.classes[this.kRDFCUContractID].getService(this.kRDFCUIID);
  70.             this.PREF      = Components.classes[this.kPREFContractID].getService(this.kPBIID);
  71.             this.SOUND     = Components.classes[this.kSOUNDContractID].createInstance(this.kSOUNDIID);
  72.             this.WINDOWSVC = Components.classes[this.kWINDOWContractID].getService(this.kWINDOWIID);
  73.             this.DS        = Components.classes[this.kDSContractID].getService(this.kDSIID);
  74.             this.SCSVC     = Components.classes[this.kSCContractID].getService(this.kSCSVCIID);
  75.             this.SCDS      = this.SCSVC.QueryInterface(this.kRDFDSIID);
  76.         }
  77.     },
  78.  
  79.  
  80.     notifyUser : function(actionType) {
  81.         if (!this.promptService)
  82.             this.promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
  83.                     .getService(Components.interfaces.nsIPromptService);
  84.  
  85.         if (this.PREF.getBoolPref("browser.sitecontrols.notify." + actionType)) {
  86.  
  87.             var promptTitle;
  88.             var promptMsg;
  89.             switch (actionType) {
  90.  
  91.                 case "switch_to_ie" :
  92.                     promptTitle = "Vulnerability Warning";
  93.                     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.";
  94.                     break;
  95.  
  96.                 case "enable_activex" :
  97.                     promptTitle = "Vulnerability Warning";
  98.                     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.";
  99.                     break;
  100.  
  101.                 case "enable_vbscript" :
  102.                     promptTitle = "Vulnerability Warning";
  103.                     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.";
  104.                     break;
  105.  
  106.                 case "disable_javascript" :
  107.                     promptTitle = "Compatibility Warning";
  108.                     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.";
  109.                     break;
  110.  
  111.                 case "disable_cookies" :
  112.                     promptTitle = "Compatibility Warning";
  113.                     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.";
  114.                     break;
  115.  
  116.  
  117.             }
  118.             var checkResult = {};
  119.             checkResult.value = true;
  120.  
  121.             var flags = this.promptService.BUTTON_TITLE_IS_STRING * this.promptService.BUTTON_POS_0 +
  122.                                     this.promptService.BUTTON_TITLE_IS_STRING * this.promptService.BUTTON_POS_1 +
  123.                                     this.promptService.BUTTON_POS_1_DEFAULT;
  124.                    //   promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1 +
  125.                           
  126.  
  127.             var result = this.promptService.confirmEx(window, promptTitle,
  128.                     promptMsg, flags, "Open Site Controls Options", "OK", null, "Don't show this message again",  checkResult);
  129.  
  130.             if (checkResult.value)
  131.                 this.PREF.setBoolPref("browser.sitecontrols.notify." + actionType, false);
  132.  
  133.             dump('**** result value: ' + result + '\n');
  134.             if (!result)
  135.                 openSiteControlPrefs();
  136.         }
  137.  
  138.     },
  139.  
  140.  
  141.     // It's *probably* okay to get rid of this entirely... but first make sure it's not
  142.     // being called from anywhere else
  143.     updateSecurityLevel : function(currentURI) {
  144.         this.SCSVC.updateSiteControl(this.getHostStringFromURL(currentURI), 'securityLevel', 'Custom');
  145.         this.debug('*** set securityLevel to CUSTOM');
  146.     },
  147.  
  148.  
  149.     setSecurityLevel : function(site, level) {
  150.         this.debug('setSecurityLevel(...,'+level+')');
  151.         var resourceToCopy = null;
  152.         switch (level) {
  153.         case 'low': // I Trust
  154.             resourceToCopy = this.RDF.GetResource(this.SC_VERIFIED_DEFAULT);
  155.             this.SCSVC.updateSiteControlResource(site, 'securityLevel', 'Low');
  156.             break;
  157.         case 'medium': // I'm not sure
  158.             resourceToCopy = this.RDF.GetResource(this.SC_NOT_VERIFIED_DEFAULT);
  159.             this.SCSVC.updateSiteControlResource(site, 'securityLevel', 'Medium');
  160.             break;
  161.         case 'high': // I don't trust
  162.             resourceToCopy = this.RDF.GetResource(this.SC_WARNING_DEFAULT);
  163.             this.SCSVC.updateSiteControlResource(site, 'securityLevel', 'High');
  164.             break;
  165.         default:
  166.             this.debug('WARNING: unrecognized security level ['+level+']');
  167.             return;
  168.         }
  169.         var propertiesToCopy = [ 'displayEngine', 'allowPopups', 'requestedPopupsInTab',
  170.                                  'allowImages', 'imagesFromOrigOnly', 'enableActiveX',
  171.                                  'enableJava', 'enableJavaScript', 'jsMoveResize',
  172.                                  'jsRaiseLower', 'jsContextMenu', 'jsHideStatusBar',
  173.                                  'jsStatusBarText', 'jsChangeImages', 'allowCookies',
  174.                                  'cookiesFromOrigOnly' ];
  175.         this.debug(' about to copy properties...');
  176.         for (var p in propertiesToCopy) {
  177.             var prop = propertiesToCopy[p];
  178.             try {
  179.                 var value = this.SCSVC.readSiteControlResource(resourceToCopy, prop);
  180.                 this.SCSVC.updateSiteControlResource(site, prop, value);
  181.             } catch (ex) {
  182.                 this.debug('WARNING: error copying property "'+prop+'"');
  183.             }
  184.         }
  185.         BrowserReload();
  186.         // If the current display engine is Trident then notify
  187.         var displayEngine = this.SCSVC.readSiteControlResource(site, 'displayEngine');            
  188.         if (displayEngine.value == 'Trident') this.notifyUser('switch_to_ie');
  189.         this.debug(' ...END setSecurityLevel.');
  190.     },
  191.  
  192.  
  193.     getHostStringFromURL : function(url) {
  194.         var dbg = false;
  195.         var host = url;
  196.         if (dbg) this.debug('Parsing URL: '+url);
  197.  
  198.         // if this is a local file
  199.         if(url.indexOf("file://") == 0) {
  200.             return this.SC_LOCAL;
  201.         }
  202.  
  203.         host = host.substring(host.indexOf('://')+3);
  204.         if (dbg) this.debug('Stripped proto: '+host);
  205.         var postHostSlash = host.indexOf('/');
  206.         if (postHostSlash > -1) {
  207.             host = host.substring(0, postHostSlash);
  208.             if (dbg) this.debug('Stripped path: '+host);
  209.         }
  210.         var userInfo = host.indexOf('@');
  211.         if (userInfo > -1) {
  212.             host = host.substring(userInfo+1);
  213.             if (dbg) this.debug('Stripped user: '+host);
  214.         }
  215.         var port = host.indexOf(':');
  216.         if (port > -1) {
  217.             host = host.substring(0, port);
  218.             if (dbg) this.debug('Stripped port: '+host);
  219.         }
  220.         return host;
  221.     },
  222.  
  223.  
  224.     getStrippedHostFromURL : function(url) {
  225.         var host = this.getHostStringFromURL(url);
  226.         return this.stripWWW(host);
  227.     },
  228.  
  229.  
  230.     getDomainFromURL : function(url) {
  231.         var host = this.getHostStringFromURL(url);
  232.         return this.getDomainFromHost(host);
  233.     },
  234.  
  235.  
  236.     getDomainFromHost : function(host) {
  237.         var matches = this.getSiteStringsFromHost(host);
  238.         return matches[matches.length-1];
  239.     },
  240.  
  241.  
  242.     getSiteStringsFromHost : function(host) {
  243.         var matches = [];
  244.         matches[matches.length] = host;
  245.         var str = host;
  246.         while ((str.indexOf('.') > -1) && (str.substring(str.indexOf('.')+1).indexOf('.') > -1)) {
  247.             // There are at least two periods '.' in str
  248.             str = str.substring(str.indexOf('.')+1);
  249.             matches[matches.length] = str;
  250.         }
  251.         //for (i = 0; i < matches.length; i++) this.debug('match: '+matches[i]);
  252.         return matches;
  253.     },
  254.  
  255.  
  256.     getSiteStringsFromURL : function(url) {
  257.         var host = this.getHostStringFromURL(url);
  258.         return this.getSiteStringsFromHost(host);
  259.     },
  260.  
  261.  
  262.     getControlledSiteFromHost : function(host) {
  263.         return this.SCSVC.getControlledSite(host);
  264.     },
  265.  
  266.  
  267.     getControlledSiteFromURL : function(url) {
  268.         var host = this.getHostStringFromURL(url);
  269.         return this.getControlledSiteFromHost(host);
  270.     },
  271.  
  272.  
  273.     stripWWW : function(host) {
  274.         if (host.substring(0,4)=='www.')
  275.             return host.substring(4);
  276.         else
  277.             return host;
  278.     },
  279.  
  280.  
  281.     debug : function(msg) {
  282.         if (this.DEBUG)
  283.             dump('sitecontrols.js: '+msg+'\n');
  284.     },
  285.  
  286.  
  287.     dumpRDF : function() {
  288.         var resources = this.SCDS.GetAllResources();
  289.         while (resources.hasMoreElements()) {
  290.             var res = resources.getNext();
  291.             res.QueryInterface(this.kRDFRSCIID);
  292.             this.debug('resource: '+res.Value);
  293.             var labels = this.SCDS.ArcLabelsOut(res);
  294.             while (labels.hasMoreElements()) {
  295.                 var label = labels.getNext();
  296.                 if (label instanceof this.kRDFRSCIID) {
  297.                     var dbg = ' * '+label.Value;
  298.                     var target = this.SCDS.GetTarget(res, label, true);
  299.                     if (target instanceof this.kRDFRSCIID) {
  300.                         dbg += ' => '+target.Value;
  301.                     } else if (target instanceof this.kRDFLITIID) {
  302.                         dbg += ' => '+target.Value;
  303.                     } else {
  304.                         try {
  305.                             dbg += ' => '+target.Value;
  306.                         } catch (ex) { }
  307.                     }
  308.                     this.debug(dbg);
  309.                 }
  310.             }
  311.         }
  312.     }
  313. };
  314.  
  315.  
  316.     sitecontrols.initServices();
  317. }
  318.  
  319.  
  320.  
  321. /***** Site Controls RDF Filter Wrapper *****/
  322.  
  323. // This is a wrapper for the rdf:sitecontrols datasource so that
  324. // we can implement the filtering behaviour in the tree
  325.  
  326. const NS_RDF_NO_VALUE           = 0xa0002;
  327. const NS_RDF_ASSERTION_REJECTED = 0xa0003;
  328.  
  329. const SC_TITLE = sitecontrols.RDF.GetResource(sitecontrols.SC_NS + "title");
  330.  
  331. function SiteControlsFilterDataSource()
  332. {
  333.     dump("sitecontrols.js : SiteControlsFilterDataSource\t\t");
  334.     this.mInner = sitecontrols.RDF.GetDataSource("rdf:sitecontrols");
  335.     this.mInner.AddObserver(this);
  336.     this.mObservers = new Array();
  337.     this.mFilter = null;
  338. }
  339.  
  340. SiteControlsFilterDataSource.prototype = {
  341.  
  342.     SetFilter : function(str) {
  343.         if (!str || (str == ''))
  344.             this.mFilter = null;
  345.         else
  346.             this.mFilter = str;
  347.     },
  348.  
  349.     /* nsIRDFDataSource */
  350.     URI: "rdf:sitecontrols-filtered",
  351.  
  352.     GetSource: function(pred, obj, tv) {
  353.         return this.mInner.GetSource(pred, obj, tv);
  354.     },
  355.  
  356.     GetSources: function(pred, obj, tv) {
  357.         return this.mInner.GetSources(pred, obj, tv);
  358.     },
  359.  
  360.     GetTarget: function(subj, pred, tv) {
  361.         // All resources other than TITLEs are handled normally
  362.         var target = this.mInner.GetTarget(subj, pred, tv);
  363.         if (pred != SC_TITLE) return target;
  364.  
  365.         var name = this.mInner.GetTarget(subj, NC_NAME, true)
  366.                        .QueryInterface(Components.interfaces.nsIRDFLiteral)
  367.                        .Value;
  368.  
  369.         // Omit the 'special' site controls
  370.         if (name == 'Verified Default' ||
  371.             name == 'Not Verified Default' ||
  372.             name == 'Warning Default' ||
  373.             name == 'Local Files')
  374.         {
  375.             return null;
  376.         }
  377.  
  378.            if (this.mFilter) {
  379.             // Only return the value if it matches the filter
  380.             if (name.indexOf(this.mFilter) == -1)
  381.                 return null;
  382.             else
  383.                 return sitecontrols.RDF.GetLiteral(name);
  384.         } else {
  385.             return target;
  386.         }
  387.     },
  388.  
  389.     GetTargets: function(subj, pred, tv) {
  390.         // All resources other than TITLEs are handled normally
  391.         var targets = this.mInner.GetTargets(subj, pred, tv);
  392.         if (pred != SC_TITLE) return targets;
  393.  
  394.         // Create a wrapper enumerator that will skip any
  395.         // items that don't match the filter, etc.
  396.         var enumerator = {
  397.             mInner : null,
  398.             mFilter : null,
  399.             mTotal : 0,
  400.             mNext : 1,
  401.             init : function(initEnum) {
  402.                 while (initEnum.hasMoreElements()) {
  403.                     node = initEnum.getNext();
  404.                     lit = node.QueryInterface(Components.interfaces.nsIRDFLiteral);
  405.                     if (lit.Value == 'Verified Default' ||
  406.                         lit.Value == 'Not Verified Default' ||
  407.                         lit.Value == 'Warning Default' ||
  408.                         lit.Value == 'Local Files')
  409.                     {
  410.                         continue;
  411.                     }
  412.                     if (!this.mFilter || lit.Value.indexOf(this.mFilter) != -1)
  413.                         this.mTotal++;
  414.                 }
  415.             },
  416.             hasMoreElements : function() {
  417.                 return (this.mNext <= this.mTotal);
  418.             },
  419.             getNext : function() {
  420.                 while (this.mInner.hasMoreElements()) {
  421.                     node = this.mInner.getNext();
  422.                     if (!node) return null;
  423.                     lit = node.QueryInterface(Components.interfaces.nsIRDFLiteral);
  424.                     if (lit.Value == 'Verified Default' ||
  425.                         lit.Value == 'Not Verified Default' ||
  426.                         lit.Value == 'Warning Default' ||
  427.                         lit.Value == 'Local Files')
  428.                     {
  429.                         continue;
  430.                     }
  431.                     if (!this.mFilter || lit.Value.indexOf(this.mFilter) != -1) {
  432.                         this.mNext++;
  433.                         return lit;
  434.                     }
  435.                 }
  436.                 return null;
  437.             }
  438.         };
  439.         enumerator.mInner = targets;
  440.         enumerator.mFilter = this.mFilter;
  441.         enumerator.init(this.mInner.GetTargets(subj, pred, tv));
  442.         return enumerator;
  443.     },
  444.  
  445.     Assert: function(subj, pred, obj, tv)        { throw NS_RDF_ASSERTION_REJECTED; },
  446.     Unassert: function(subj, pred, obj, tv)      { throw NS_RDF_ASSERTION_REJECTED; },
  447.     Change: function(subj, pred, oldobj, newobj) { throw NS_RDF_ASSERTION_REJECTED; },
  448.     Move: function(oldsubj, newsubj, pred, obj)  { throw NS_RDF_ASSERTION_REJECTED; },
  449.  
  450.     HasAssertion: function(subj, pred, obj, tv) {
  451.         // All resources other than TITLEs are handled normally
  452.         var hasAssert = this.mInner.HasAssertion(subj, pred, obj, tv);
  453.         if (pred != SC_TITLE) return hasAssert;
  454.  
  455.         var lit = obj.QueryInterface(Components.interfaces.nsIRDFLiteral);
  456.         if (lit.Value == 'Verified Default' ||
  457.             lit.Value == 'Not Verified Default' ||
  458.             lit.Value == 'Warning Default' ||
  459.             lit.Value == 'Local Files')
  460.         {
  461.             return null;
  462.         }
  463.  
  464.         if (this.mFilter && lit.Value.indexOf(this.mFilter) == -1)
  465.             return null;
  466.         else
  467.             return hasAssert;
  468.     },
  469.  
  470.     AddObserver: function(aObserver) {
  471.         this.mObservers.push(aObserver);
  472.     },
  473.  
  474.     RemoveObserver: function(aObserver) {
  475.         for (var i = 0; i < this.mObservers.length; ++i) {
  476.             if (aObserver == this.mObservers[i]) {
  477.                 this.mObservers.splice(i, 1);
  478.                 break;
  479.             }
  480.         }
  481.     },
  482.  
  483.     ArcLabelsIn: function(obj) {
  484.         return this.mInner.ArcLabelsIn(obj);
  485.     },
  486.  
  487.     ArcLabelsOut: function(subj) {
  488.         return this.mInner.ArcLabelsOut(obj);
  489.     },
  490.  
  491.        GetAllResources: function() {
  492.         return this.mInner.GetAllResources();
  493.     },
  494.  
  495.     hasArcIn: function(obj, pred) {
  496.         return this.mInner.hasArcIn(obj, pred);
  497.     },
  498.  
  499.     hasArcOut: function(subj, pred) {
  500.         return this.mInner.hasArcOut(subj, pred);
  501.     },
  502.  
  503.     /* nsIRDFObserver */
  504.     onAssert: function(ds, subj, pred, obj) {
  505.         for (var obs in this.mObservers)
  506.             obs.onAssert(this, subj, pred, obj);
  507.     },
  508.  
  509.     onUnassert: function(ds, subj, pred, obj) {
  510.         for (var obs in this.mObservers)
  511.             obs.onUnassert(this, subj, pred, obj);
  512.     },
  513.  
  514.     onChange: function(ds, subj, pred, oldobj, newobj) {
  515.         for (var obs in this.mObservers)
  516.             obs.onChange(ds, subj, pred, oldobj, newobj);
  517.     },
  518.  
  519.        onMove: function(ds, oldsubj, newsubj, pred, obj) {
  520.         for (var obs in this.mObservers)
  521.             obs.onMove(ds, oldsubj, newsubj, pred, obj);
  522.     }
  523. };
  524.