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 / sitecontrolsOverlay.js < prev    next >
Encoding:
Text File  |  2005-07-29  |  31.2 KB  |  854 lines

  1. var scPopup = {
  2.     DEBUG : true,
  3.  
  4.     currentURI : null,
  5.     dirty : false,
  6.     switchingEngines : false,
  7.     prefService : null,
  8.     engineDisableDelay : 2000,
  9.  
  10.     mStrings : null,
  11.     mSiteName : null,
  12.     mTabbox : null,
  13.     mTrustImg : null,
  14.     mTrustDeck : null,
  15.     mPartnerBox : null,
  16.     mTrustRadioGroup : null,
  17.     mTrustRadio : null,
  18.     mStandardRadio : null,
  19.     mCautionRadio : null,
  20.     mCustomRadioBox: null,
  21.     mCustomRadio : null,
  22.     mTrustEngine : null,
  23.     mTrustGecko : null,
  24.     mTrustTrident : null,
  25.     mAdvEngine : null,
  26.     mAdvGecko : null,
  27.     mAdvTrident : null,
  28.     mAllowPopups : null,
  29.     mAllowImages : null,
  30.     mOpenPopupsInTab : null,
  31.     mAllowCookies : null,
  32.     mImagesOrig : null,
  33.     mCookiesOrig : null,
  34.     mEnableJS : null,
  35.     mEnableJava : null,
  36.     mEnableActiveX : null,
  37.     mBtnBar : null,
  38.     mManageButton : null,
  39.  
  40.     init : function() {
  41.         this.debug('init()');
  42.         this.prefService = Components.classes["@mozilla.org/preferences-service;1"]
  43.                                      .getService(Components.interfaces.nsIPrefBranch);
  44.         this.mStrings = document.getElementById('sc_strings');
  45.         this.mSiteName = document.getElementById('scp_siteName');
  46.         this.mTitleDeck = document.getElementById('scp_title_deck');
  47.         this.mTabbox = document.getElementById('scp_tabbox');
  48.         this.mTrustImg = document.getElementById('scp_trust_img');
  49.         this.mTrustDeck = document.getElementById('scp_trust_desc_deck');
  50.         this.mPartnerBox = document.getElementById('scp_partner_box');
  51.         this.mTrustRadioGroup = document.getElementById('scp_trust_radios');
  52.         this.mTrustRadio = document.getElementById('scp_radio_trust');
  53.         this.mStandardRadio = document.getElementById('scp_radio_standard');
  54.         this.mCautionRadio = document.getElementById('scp_radio_caution');
  55.         this.mCustomRadio = document.getElementById('scp_radio_custom');
  56.         this.mCustomRadioBox = document.getElementById('scp_radio_custom_box');
  57.         this.mTrustEngine = document.getElementById('scp_trust_displayEngine');
  58.         this.mTrustGecko = document.getElementById('scp_trust_gecko');
  59.         this.mTrustTrident = document.getElementById('scp_trust_trident');
  60.         this.mAdvEngine = document.getElementById('scp_adv_displayEngine');
  61.         this.mAdvGecko = document.getElementById('scp_adv_gecko');
  62.         this.mAdvTrident = document.getElementById('scp_adv_trident');
  63.         this.mAllowPopups = document.getElementById('scp_allowPopups');
  64.         this.mOpenPopupsInTab = document.getElementById('scp_openPopupsInTab');
  65.         this.mAllowImages = document.getElementById('scp_allowImages');
  66.         this.mImagesOrig = document.getElementById('scp_imagesFromOrigOnly');
  67.         this.mAllowCookies = document.getElementById('scp_allowCookies');
  68.         this.mCookiesOrig = document.getElementById('scp_cookiesFromOrigOnly');
  69.         this.mEnableJS = document.getElementById('scp_enableJavaScript');
  70.         this.mEnableJava = document.getElementById('scp_enableJava');
  71.         this.mEnableActiveX = document.getElementById('scp_enableActiveX');
  72.         this.mBtnBar = document.getElementById('scp_btnbar');
  73.         this.mManageButton = document.getElementById('scp_manage_button');
  74.         this.switchingEngines = false;
  75.     },
  76.  
  77.     findSecurityPartners : function() {
  78.         // remove all the partners first
  79.         while(this.mPartnerBox.firstChild) {
  80.             this.mPartnerBox.removeChild(this.mPartnerBox.firstChild);
  81.         }
  82.  
  83.         this.debug('findSecurityPartners(): ' + this.currentURI.spec + '\n');
  84.         var sc = sitecontrols.SCSVC;
  85.         
  86.         switch(sc.getSiteTrustLevel(this.currentURI.spec)) {
  87.             case 0:
  88.                 // whitelisted
  89.                 var whiteListCode = sc.getSiteTrustLevelDetail(this.currentURI.spec, sc.SC_TRUST_WHITELIST_IDX);
  90.                 var whiteListStr = sc.getSiteTrustProviderName(whiteListCode);
  91.                 var whiteListArray = whiteListStr.split('|');
  92.                 var whiteListURLStr = sc.getSiteTrustProviderURL(whiteListCode);
  93.                 var whiteListURLArray = whiteListURLStr.split('|');
  94.                 var whiteListIconStr = sc.getSiteTrustProviderIcon(whiteListCode);
  95.                 var whiteListIconArray = whiteListIconStr.split('|');
  96.                 
  97.                 var hboxElem;
  98.                 var iconElem;
  99.                 var descElem;
  100.                 var tmpURL;
  101.                 for(var i = 0; i < whiteListArray.length; i++) {
  102.                     hboxElem = document.createElement("hbox");
  103.                     iconElem = document.createElement("image");
  104.                     iconElem.setAttribute("src", whiteListIconArray[i] );
  105.                     iconElem.setAttribute("class", "scp_partner_icon");
  106.                     descElem = document.createElement("label");
  107.                     descElem.setAttribute("value", whiteListArray[i]);
  108.                     descElem.setAttribute("class", "scp_partner_text");
  109.                     tmpURL = "scPopup.loadTrustPartnersTab('" + whiteListURLArray[i] + "');";
  110.                     descElem.setAttribute("onclick", tmpURL);
  111.                     hboxElem.appendChild(iconElem);
  112.                     hboxElem.appendChild(descElem);
  113.                     this.mPartnerBox.appendChild(hboxElem);
  114.                 }
  115.                 break;
  116.             case 2:
  117.                 // phish
  118.                 var phishListCode = sc.getSiteTrustLevelDetail(this.currentURI.spec, sc.SC_TRUST_PHISHLIST_IDX);
  119.                 var phishListStr = sc.getSiteTrustProviderName(phishListCode);
  120.                 var phishListArray = phishListStr.split('|');
  121.                 var phishListURLStr = sc.getSiteTrustProviderURL(phishListCode);
  122.                 var phishListURLArray = phishListURLStr.split('|');
  123.                 var phishListIconStr = sc.getSiteTrustProviderIcon(phishListCode);
  124.                 var phishListIconArray = phishListIconStr.split('|');
  125.                 
  126.                 var hboxElem;
  127.                 var iconElem;
  128.                 var descElem;
  129.                 var tmpURL;
  130.                 for(var i = 0; i < phishListArray.length; i++) {
  131.                     hboxElem = document.createElement("hbox");
  132.                     iconElem = document.createElement("image");
  133.                     iconElem.setAttribute("src", phishListIconArray[i]);
  134.                     iconElem.setAttribute("class", "scp_partner_icon");
  135.                     descElem = document.createElement("label");
  136.                     descElem.setAttribute("value", phishListArray[i]);
  137.                     descElem.setAttribute("class", "scp_partner_text");
  138.                     tmpURL = "scPopup.loadTrustPartnersTab('" + phishListURLArray[i] + "');";
  139.                     descElem.setAttribute("onclick", tmpURL);
  140.                     hboxElem.appendChild(iconElem);
  141.                     hboxElem.appendChild(descElem);
  142.                     this.mPartnerBox.appendChild(hboxElem);
  143.                 }
  144.                 break;
  145.             case 4:
  146.                 // spy
  147.                 var spyListCode = sc.getSiteTrustLevelDetail(this.currentURI.spec, sc.SC_TRUST_SPYLIST_IDX);
  148.                 var spyListStr = sc.getSiteTrustProviderName(spyListCode);
  149.                 var spyListArray = spyListStr.split('|');
  150.                 var spyListURLStr = sc.getSiteTrustProviderURL(spyListCode);
  151.                 var spyListURLArray = spyListURLStr.split('|');
  152.                 var spyListIconStr = sc.getSiteTrustProviderIcon(spyListCode);
  153.                 var spyListIconArray = spyListIconStr.split('|');
  154.                 
  155.                 var hboxElem;
  156.                 var iconElem;
  157.                 var descElem;
  158.                 var tmpURL;
  159.                 for(var i = 0; i < spyListArray.length; i++) {
  160.                     hboxElem = document.createElement("hbox");
  161.                     iconElem = document.createElement("image");
  162.                     iconElem.setAttribute("src", spyListIconArray[i]);
  163.                     iconElem.setAttribute("class", "scp_partner_icon");
  164.                     descElem = document.createElement("label");
  165.                     descElem.setAttribute("value", spyListArray[i]);
  166.                     descElem.setAttribute("class", "scp_partner_text");
  167.                     tmpURL = "scPopup.loadTrustPartnersTab('" + spyListURLArray[i] + "');";
  168.                     descElem.setAttribute("onclick", tmpURL);
  169.                     hboxElem.appendChild(iconElem);
  170.                     hboxElem.appendChild(descElem);
  171.                     this.mPartnerBox.appendChild(hboxElem);
  172.                 }
  173.                 break;
  174.             case 6:
  175.                 // both phish and spy
  176.                 var phishListCode = sc.getSiteTrustLevelDetail(this.currentURI.spec, sc.SC_TRUST_PHISHLIST_IDX);
  177.                 var phishListStr = sc.getSiteTrustProviderName(phishListCode);
  178.                 var phishListArray = phishListStr.split('|');
  179.                 var phishListURLStr = sc.getSiteTrustProviderURL(phishListCode);
  180.                 var phishListURLArray = phishListURLStr.split('|');
  181.                 var phishListIconStr = sc.getSiteTrustProviderIcon(phishListCode);
  182.                 var phishListIconArray = phishListIconStr.split('|');
  183.  
  184.                 var spyListCode = sc.getSiteTrustLevelDetail(this.currentURI.spec, sc.SC_TRUST_SPYLIST_IDX);
  185.                 var spyListStr = sc.getSiteTrustProviderName(spyListCode);
  186.                 var spyListArray = spyListStr.split('|');
  187.                 var spyListURLStr = sc.getSiteTrustProviderURL(spyListCode);
  188.                 var spyListURLArray = spyListURLStr.split('|');
  189.                 var spyListIconStr = sc.getSiteTrustProviderIcon(spyListCode);
  190.                 var spyListIconArray = spyListIconStr.split('|');
  191.                 
  192.                 var combinedArray = phishListArray;
  193.                 var combinedURLArray = phishListURLArray;
  194.                 var combinedIconArray = phishListIconArray;
  195.                 var found;
  196.  
  197.                 for(var arrayItem in spyListArray) {
  198.                     found = false;
  199.                     for(var k = 0; k < phishListArray.length; k++) {
  200.                         if(spyListArray[arrayItem] == phishListArray[k]) {
  201.                             found = true;
  202.                             break;
  203.                         }
  204.                     }
  205.                     if(!found) {
  206.                         combinedArray.push(spyListArray[arrayItem]);
  207.                         combinedURLArray.push(spyListURLArray[arrayItem]);
  208.                         combinedIconArray.push(spyListIconArray[arrayItem]);
  209.                     }
  210.                 }
  211.  
  212. /*
  213.                 for(var arrayItem in spyListURLArray) {
  214.                     found = false;
  215.                     for(var k = 0; k < phishListURLArray.length; k++) {
  216.                         if(spyListURLArray[arrayItem] == phishListURLArray[k]) {
  217.                             found = true;
  218.                             break;
  219.                         }
  220.                     }
  221.                     if(!found) {
  222.                         combinedURLArray.push(spyListURLArray[arrayItem]);
  223.                     }
  224.                 }
  225. */
  226.                 var hboxElem;
  227.                 var iconElem;
  228.                 var descElem;
  229.                 var tmpURL;
  230.                 for(var i = 0; i < combinedArray.length; i++) {
  231.                     hboxElem = document.createElement("hbox");
  232.                     iconElem = document.createElement("image");
  233.                     iconElem.setAttribute("src", combinedIconArray[i]);
  234.                     iconElem.setAttribute("class", "scp_partner_icon");
  235.                     descElem = document.createElement("label");
  236.                     descElem.setAttribute("value", combinedArray[i]);
  237.                     descElem.setAttribute("class", "scp_partner_text");
  238.                     tmpURL = "scPopup.loadTrustPartnersTab('" + combinedURLArray[i] + "');";
  239.                     descElem.setAttribute("onclick", tmpURL);
  240.                     hboxElem.appendChild(iconElem);
  241.                     hboxElem.appendChild(descElem);
  242.                     this.mPartnerBox.appendChild(hboxElem);
  243.                 }
  244.                 break;
  245.             case 1:
  246.             default:
  247.                 // unknown
  248.         }
  249.     },
  250.  
  251.     loadTrustPartnersTab : function(url)
  252.     {
  253.         dump('*** foobar\n');
  254.         var gBrowser = document.getElementById('content');
  255.         document.getElementById('SiteControlsPopup').hidePopup();
  256.         if (url) {
  257.             var trustTab = gBrowser.addTabAt(url);
  258.             if (!gPrefService.getBoolPref("browser.tabs.loadInBackground"))
  259.                 gBrowser.selectedTab = trustTab;
  260.         }
  261.     },
  262.  
  263.     loadCurrentSite : function() {
  264.         this.debug('loadCurrentSite()');
  265.         this.currentURI = gBrowser.currentURI;
  266.         var sc = sitecontrols.SCSVC;
  267.  
  268.         if (sc.isControllableURI(this.currentURI.spec)) {
  269.             this.debug(' { controllable: '+this.currentURI.spec+' }');
  270.             // Controllable URI, so enable controls as appropriate
  271.             this.mTrustImg.removeAttribute('disabled');
  272.             this.mTrustDeck.removeAttribute('disabled');
  273.             this.enableDisableSwitching(true);
  274.             this.mAllowPopups.removeAttribute('disabled');
  275.             this.mOpenPopupsInTab.removeAttribute('disabled');
  276.             this.mAllowImages.removeAttribute('disabled');
  277.             this.mAllowCookies.removeAttribute('disabled');
  278.             this.mCookiesOrig.removeAttribute('disabled');
  279.             this.mImagesOrig.removeAttribute('disabled');
  280.             this.mEnableJS.removeAttribute('disabled');
  281.             this.mEnableJava.removeAttribute('disabled');
  282.             this.mEnableActiveX.removeAttribute('disabled');
  283.  
  284.             // Set control values
  285.             var site = sc.getResourceForURI(this.currentURI.spec);
  286.  
  287.             var trustLevel;
  288.             if (this.currentURI.scheme == 'http' ||
  289.                 this.currentURI.scheme == 'https' ||
  290.                 this.currentURI.scheme == 'ftp')
  291.             {
  292.                 trustLevel = sc.getSiteTrustLevel(this.currentURI.spec);
  293.             } else {
  294.                 trustLevel = 1; // local files, etc...
  295.             }
  296.  
  297.             var useBrowserSettingDefault = false;
  298.  
  299.             // if we are forcing a default browser setting AND the site is not controlled
  300.             var securityLevel;
  301.             if(!this.prefService.getBoolPref("trustsettings.partnerratings.auto") && !sitecontrols.SCSVC.isControlledSite(this.currentURI.host)) {
  302.                 securityLevel = this.prefService.getCharPref("trustsettings.default");
  303.                 useBrowserSettingDefault = true;
  304.             } else {
  305.                 securityLevel = sc.readSiteControlResource(site, 'securityLevel');
  306.             }
  307.  
  308.             switch (trustLevel)
  309.             {
  310.                 case -1:
  311.                     this.mTrustImg.setAttribute('trust', 'disabled');
  312.                     this.mTrustDeck.selectedIndex = 3;
  313.                     if(!sitecontrols.SCSVC.isControlledSite(this.currentURI.host)) {
  314.                         securityLevel = this.prefService.getCharPref("trustsettings.default");
  315.                         useBrowserSettingDefault = true;
  316.                     }
  317.                     break;                
  318.                 case 0:
  319.                     this.mTrustImg.setAttribute('trust', 'verified');
  320.                     this.mTrustDeck.selectedIndex = 0;
  321.                     break;
  322.                 case 1:
  323.                     this.mTrustImg.setAttribute('trust', 'notVerified');
  324.                     this.mTrustDeck.selectedIndex = 1;
  325.                     break;
  326.                 case 2:
  327.                 default:
  328.                     this.mTrustImg.setAttribute('trust', 'warning');
  329.                     this.mTrustDeck.selectedIndex = 2;
  330.                     break;
  331.             }
  332.  
  333.             switch (securityLevel)
  334.             {
  335.                 case 'Low':
  336.                     this.mCustomRadioBox.setAttribute('hidden', 'true');
  337.                     this.mTrustRadioGroup.selectedItem = this.mTrustRadio;
  338.                     break;
  339.                 case 'Medium':
  340.                     this.mCustomRadioBox.setAttribute('hidden', 'true');
  341.                     this.mTrustRadioGroup.selectedItem = this.mStandardRadio;
  342.                     break;
  343.                 case 'Custom':
  344.                     this.mCustomRadioBox.removeAttribute('hidden');
  345.                     this.mTrustRadioGroup.selectedItem = this.mCustomRadio;
  346.                     break;
  347.                 case 'High':
  348.                 default:
  349.                     this.mCustomRadioBox.setAttribute('hidden', 'true');
  350.                     this.mTrustRadioGroup.selectedItem = this.mCautionRadio;
  351.                     break;
  352.             }
  353.  
  354.             // If Trust settings is turned off (i.e. trustsettings.partnerratings = false) AND
  355.             // the url is not controlled, we should use the default given by
  356.             // trustsettings.default
  357.             if(useBrowserSettingDefault) {
  358.                 switch (securityLevel)
  359.                 {
  360.                     case 'Low':
  361.                         site = sitecontrols.RDF.GetResource(sitecontrols.SC_VERIFIED_DEFAULT);
  362.                         break;
  363.                     case 'Medium':
  364.                         site = sitecontrols.RDF.GetResource(sitecontrols.SC_NOT_VERIFIED_DEFAULT);
  365.                         break;
  366.                     case 'High':
  367.                     default:
  368.                         site = sitecontrols.RDF.GetResource(sitecontrols.SC_WARNING_DEFAULT);
  369.                         break;
  370.                 }
  371.             }
  372.             
  373.             // set title
  374.             if (site.Value == sitecontrols.SC_LOCAL) {
  375.                 this.mSiteName.setAttribute('value', sc.readSiteControlResource(site, 'title'));
  376.             } else {
  377.                 this.mSiteName.setAttribute('value', this.currentURI.host);
  378.             }
  379.  
  380.             this.mTitleDeck.selectedIndex = 0;
  381.  
  382.             var engine = sc.readSiteControlResource(site, 'displayEngine');
  383.             var jsAndVBScriptDeck = document.getElementById('jsAndVBScriptDeck');
  384.             if (engine == 'Gecko') {
  385.                 this.mTrustEngine.selectedIndex = 0;
  386.                 this.mAdvEngine.selectedIndex = 0;
  387.                 this.mAllowCookies.removeAttribute('disabled');
  388.                 this.mCookiesOrig.removeAttribute('disabled');
  389.                 jsAndVBScriptDeck.selectedIndex = 0;
  390.             } else {
  391.                 this.mTrustEngine.selectedIndex = 1;
  392.                 this.mAdvEngine.selectedIndex = 1;
  393.                 this.mAllowCookies.setAttribute('disabled', 'true');
  394.                 this.mCookiesOrig.setAttribute('disabled', 'true');
  395.                 jsAndVBScriptDeck.selectedIndex = 1;
  396.             }
  397.             this.mAllowPopups.checked = eval(sc.readSiteControlResource(site, 'allowPopups'));
  398.             this.mOpenPopupsInTab.checked = eval(sc.readSiteControlResource(site, 'requestedPopupsInTab'));
  399.  
  400.             this.mAllowImages.checked = eval(sc.readSiteControlResource(site, 'allowImages'));
  401.  
  402.             if (this.mTrustEngine.selectedIndex == 1) {
  403.                 this.mImagesOrig.checked = false;
  404.                 this.mImagesOrig.setAttribute('disabled', 'true');
  405.             } else {
  406.                 this.mImagesOrig.checked = eval(sc.readSiteControlResource(site, 'imagesFromOrigOnly'));
  407.                 if(!this.mAllowImages.checked)
  408.                     this.mImagesOrig.setAttribute('disabled', 'true');
  409.             }                
  410.  
  411.             this.mAllowCookies.checked = eval(sc.readSiteControlResource(site, 'allowCookies'));
  412.             this.mCookiesOrig.checked = eval(sc.readSiteControlResource(site, 'cookiesFromOrigOnly'));
  413.             if (!this.mAllowCookies.checked)
  414.                 this.mCookiesOrig.setAttribute('disabled','true');
  415.             this.mEnableJS.checked = eval(sc.readSiteControlResource(site, 'enableJavaScript'));
  416.             this.mEnableJava.checked = eval(sc.readSiteControlResource(site, 'enableJava'));
  417.             this.mEnableActiveX.checked = eval(sc.readSiteControlResource(site, 'enableActiveX'));
  418.             if (this.mAdvEngine.value!='Trident') {
  419.                 this.mEnableActiveX.setAttribute('checked', 'false');
  420.                 this.mEnableActiveX.setAttribute('disabled','true');        
  421.             }
  422.         } else {
  423.             this.debug(' { NOT controllable: '+this.currentURI.spec+' }');
  424.             // Not a controllable URI, so disable controls
  425.             //this.mTitleDeck.selectedIndex = 1;
  426.             this.mTrustImg.setAttribute('disabled','true');
  427.             this.mTrustDeck.setAttribute('disabled','true');
  428.             this.enableDisableSwitching(false);
  429.             this.mAllowPopups.setAttribute('disabled','true');
  430.             this.mOpenPopupsInTab.setAttribute('disabled','true');
  431.             this.mAllowImages.setAttribute('disabled','true');
  432.             this.mImagesOrig.setAttribute('disabled','true');
  433.             this.mAllowCookies.setAttribute('disabled','true');
  434.             this.mCookiesOrig.setAttribute('disabled','true');
  435.             this.mEnableJS.setAttribute('disabled','true');
  436.             this.mEnableJava.setAttribute('disabled','true');
  437.             this.mEnableActiveX.setAttribute('disabled','true');
  438.             this.debug(' done disabling fields');
  439.         }
  440.  
  441.         // Uncheck disabled activeX checkbox if Gecko is engine.
  442.         this.removeCheckFromDisabled();
  443.     },
  444.  
  445.     // MERC - JCH: Ensure that disabled activeX checkbox is unchecked if Gecko applies. 
  446.     // See BLT bug #120260.
  447.     removeCheckFromDisabled : function() {
  448.  
  449.         var uncheck = (this.mEnableActiveX.disabled && (this.mAdvEngine.value == 'Gecko'));
  450.  
  451.         if (uncheck)
  452.         {
  453.             this.mEnableActiveX.checked = false;
  454.         }
  455.     },
  456.  
  457.  
  458.     enableDisableSwitching : function(enable) {
  459.         this.debug('enableDisableSwitching('+enable+')');
  460.         if (enable && !this.switchingEngines) {
  461.             this.mTrustEngine.removeAttribute('disabled');
  462.             this.mTrustGecko.removeAttribute('disabled');
  463.             this.mTrustTrident.removeAttribute('disabled');
  464.             this.mAdvEngine.removeAttribute('disabled');
  465.             this.mAdvGecko.removeAttribute('disabled');
  466.             this.mAdvTrident.removeAttribute('disabled');
  467.         } else {
  468.             this.mTrustEngine.setAttribute('disabled','true');
  469.             this.mTrustGecko.setAttribute('disabled','true');
  470.             this.mTrustTrident.setAttribute('disabled','true');
  471.             this.mAdvEngine.setAttribute('disabled','true');
  472.             this.mAdvGecko.setAttribute('disabled','true');
  473.             this.mAdvTrident.setAttribute('disabled','true');
  474.             setTimeout("scPopup.mTrustEngine.removeAttribute('disabled');", this.engineDisableDelay);
  475.             setTimeout("scPopup.mTrustGecko.removeAttribute('disabled');", this.engineDisableDelay);
  476.             setTimeout("scPopup.mTrustTrident.removeAttribute('disabled');", this.engineDisableDelay);
  477.             setTimeout("scPopup.mAdvEngine.removeAttribute('disabled');", this.engineDisableDelay);
  478.             setTimeout("scPopup.mAdvGecko.removeAttribute('disabled');", this.engineDisableDelay);
  479.             setTimeout("scPopup.mAdvTrident.removeAttribute('disabled');", this.engineDisableDelay);
  480.         }
  481.     },
  482.  
  483.  
  484.     onPopupShown : function(event) {    
  485.         this.debug('onPopupShown()');
  486.         this.init();
  487.         this.mTitleDeck.style.display='-moz-deck';
  488.         this.mTabbox.style.display='-moz-box';
  489.         this.mBtnBar.style.display='-moz-box';
  490.         this.loadCurrentSite();
  491.         this.findSecurityPartners();
  492.         this.dirty = false;
  493.         gBrowser.mCurrentTab.setAttribute("popupvisible", "true");
  494.     },
  495.  
  496.  
  497.     onPopupHidden : function(event) {
  498.         this.mTitleDeck.style.display='none';
  499.         this.mTabbox.style.display='none';
  500.         this.mBtnBar.style.display='none';
  501.         gBrowser.mCurrentTab.setAttribute("popupvisible", "false");
  502.         if (this.dirty)
  503.             BrowserReload();
  504.     },
  505.  
  506.  
  507.     addParent : function(fullURI, event) {
  508.         if (!event.target.id) return;
  509.         
  510.         var tldArray = new Array();
  511.         
  512.         tldArray["AERO"] = "OK";
  513.         tldArray["BIZ"] = "OK";
  514.         tldArray["COM"] = "OK";
  515.         tldArray["COOP"] = "OK";
  516.         tldArray["EDU"] = "OK";
  517.         tldArray["GOV"] = "OK";
  518.         tldArray["INFO"] = "OK";
  519.         tldArray["INT"] = "OK";
  520.         tldArray["MIL"] = "OK";
  521.         tldArray["MUSEUM"] = "OK";
  522.         tldArray["NAME"] = "OK";
  523.         tldArray["NET"] = "OK";
  524.         tldArray["ORG"] = "OK";
  525.         tldArray["PRO"] = "OK";
  526.  
  527.         // Remove any sub domains
  528.         var host = sitecontrols.getStrippedHostFromURL(fullURI);
  529.         if (host && (host != "")) {
  530.             var reg = /.*\.([0-9a-zA-Z\-]+\.[0-9a-zA-Z\-]+)$/;
  531.             if (reg.test(host)) {
  532.                 var ar = reg.exec(host);
  533.                 host = ar[1];
  534.                 
  535.                 var pattern = sitecontrols.SCSVC.getControlledSite(host);
  536.                 if ((pattern != null) || (host && (host != "") && (host != pattern))) {
  537.                     // Just confirm that this is a normal top level domain (ie .com, .org... not .ca, .uk...)
  538.                     reg = /[0-9a-zA-Z\-]+\.([0-9a-zA-Z\-]+)$/;
  539.                     ar = reg.exec(host);
  540.                     var tldPart = ar[1].toUpperCase();
  541.                     if (tldArray[tldPart] == "OK") {
  542.  
  543.                         var sc = sitecontrols.SCSVC;
  544.                         var site = sc.getResourceForURI(host);
  545.                         if (site.Value != sitecontrols.SC_LOCAL)
  546.                         {
  547.                             var pattern = sitecontrols.SCSVC.getControlledSite(host);
  548.                             if ((pattern != null) || (host && (host != "") && (host != pattern))) {
  549.                                 sitecontrols.SCSVC.addControlledSite(host);
  550.                                 site = sitecontrols.SCSVC.getResourceForURI(host);
  551.                             }
  552.                         } else {
  553.                             return;
  554.                         }
  555.  
  556.                         switch (event.target.id) {
  557.                 
  558.                         case 'scp_trust_gecko':
  559.                         case 'scp_trust_trident':
  560.                             sc.updateSiteControlResource(site, 'displayEngine', this.mTrustEngine.value);
  561.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  562.                             break;
  563.                         case 'scp_adv_gecko':
  564.                         case 'scp_adv_trident':
  565.                             sc.updateSiteControlResource(site, 'displayEngine', this.mAdvEngine.value);
  566.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  567.                             break;
  568.                 
  569.                         case 'scp_allowPopups':
  570.                             sc.updateSiteControlResource(site, 'allowPopups',
  571.                                                          (event.target.checked) ? 'true' : 'false');
  572.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  573.                             break;
  574.                 
  575.                         case 'scp_openPopupsInTab':
  576.                             sc.updateSiteControlResource(site, 'requestedPopupsInTab',
  577.                                                          (event.target.checked) ? 'true' : 'false');
  578.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  579.                             break;
  580.                 
  581.                         case 'scp_allowImages':
  582.                             sc.updateSiteControlResource(site, 'allowImages',
  583.                                                          (event.target.checked) ? 'true' : 'false');
  584.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  585.                             break; 
  586.                 
  587.                         case 'scp_imagesFromOrigOnly':
  588.                             sc.updateSiteControlResource(site, 'imagesFromOrigOnly',
  589.                                                          (event.target.checked) ? 'true' : 'false');
  590.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  591.                             break;
  592.                 
  593.                         case 'scp_allowPopupCount':
  594.                             sc.updateSiteControlResource(site, 'showBlockedCount',
  595.                                                          (event.target.checked) ? 'true' : 'false');
  596.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  597.                             break;
  598.                 
  599.                         case 'scp_allowPopupSound':
  600.                             sc.updateSiteControlResource(site, 'playBlockedSound',
  601.                                                          (event.target.checked) ? 'true' : 'false');
  602.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  603.                             break;
  604.                 
  605.                         case 'scp_allowCookies':
  606.                             sc.updateSiteControlResource(site, 'allowCookies',
  607.                                                          (event.target.checked) ? 'true' : 'false');
  608.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  609.                             break;
  610.                 
  611.                         case 'scp_cookiesFromOrigOnly':
  612.                             sc.updateSiteControlResource(site, 'cookiesFromOrigOnly',
  613.                                                          (event.target.checked) ? 'true' : 'false');
  614.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  615.                             break;
  616.                 
  617.                         case 'scp_enableJavaScript':
  618.                             sc.updateSiteControlResource(site, 'enableJavaScript',
  619.                                                          (event.target.checked) ? 'true' : 'false');
  620.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  621.                             break;
  622.                 
  623.                         case 'scp_enableJava':
  624.                             sc.updateSiteControlResource(site, 'enableJava',
  625.                                                          (event.target.checked) ? 'true' : 'false');
  626.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  627.                             break;
  628.                 
  629.                         case 'scp_enableActiveX':
  630.                             sc.updateSiteControlResource(site, 'enableActiveX',
  631.                                                          (event.target.checked) ? 'true' : 'false');
  632.                             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  633.                             break;
  634.                 
  635.                         case 'scp_radio_trust':
  636.                             sitecontrols.setSecurityLevel(site, 'low');
  637.                             break;
  638.                 
  639.                         case 'scp_radio_standard':
  640.                             sitecontrols.setSecurityLevel(site, 'medium');
  641.                             break;
  642.                 
  643.                         case 'scp_radio_caution':
  644.                             sitecontrols.setSecurityLevel(site, 'high');
  645.                             break;
  646.                 
  647.                         }
  648.                     }
  649.                 }
  650.             }
  651.         }        
  652.     },
  653.  
  654.     onCommand : function(event) {
  655.         this.debug('onCommand()');
  656.         if (!event.target.id) return;
  657.  
  658.         var sc = sitecontrols.SCSVC;
  659.  
  660.         switch (event.target.id) {
  661.  
  662.         case 'scp_trust_gecko':
  663.         case 'scp_trust_trident':
  664.             var site = this.ensureExplicitSiteControl();
  665.             sc.updateSiteControlResource(site, 'displayEngine', this.mTrustEngine.value);
  666.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  667.             this.switchingEngines = true;
  668.             this.enableDisableSwitching(false);
  669.             BrowserReload();
  670.  
  671.             if (event.target.id == 'scp_trust_trident') {
  672.                 this.mAllowCookies.setAttribute('disabled', 'true');
  673.                 this.mCookiesOrig.setAttribute('disabled', 'true');
  674.               sitecontrols.notifyUser('switch_to_ie');
  675.             } else {
  676.                 this.mAllowCookies.removeAttribute('disabled');
  677.                 this.mCookiesOrig.removeAttribute('disabled');
  678.             }
  679.             break;
  680.         case 'scp_adv_gecko':
  681.         case 'scp_adv_trident':
  682.             var site = this.ensureExplicitSiteControl();
  683.             sc.updateSiteControlResource(site, 'displayEngine', this.mAdvEngine.value);
  684.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  685.             this.switchingEngines = true;
  686.             this.enableDisableSwitching(false);
  687.             BrowserReload();
  688.  
  689.  
  690.             if (event.target.id == 'scp_adv_trident') {
  691.               sitecontrols.notifyUser('switch_to_ie');
  692.             }
  693.                 
  694.             break;
  695.  
  696.         case 'scp_allowPopups':
  697.             var site = this.ensureExplicitSiteControl();
  698.             sc.updateSiteControlResource(site, 'allowPopups',
  699.                                          (event.target.checked) ? 'true' : 'false');
  700.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  701.             //this.dirty = true;
  702.             BrowserReload();
  703.             break;
  704.  
  705.         case 'scp_openPopupsInTab':
  706.             var site = this.ensureExplicitSiteControl();
  707.             sc.updateSiteControlResource(site, 'requestedPopupsInTab',
  708.                                          (event.target.checked) ? 'true' : 'false');
  709.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  710.             BrowserReload();
  711.             break;
  712.  
  713.         case 'scp_allowImages':
  714.             var site = this.ensureExplicitSiteControl();
  715.             sc.updateSiteControlResource(site, 'allowImages',
  716.                                          (event.target.checked) ? 'true' : 'false');
  717.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  718.             BrowserReload();
  719.             break; 
  720.  
  721.         case 'scp_imagesFromOrigOnly':
  722.             var site = this.ensureExplicitSiteControl();
  723.             sc.updateSiteControlResource(site, 'imagesFromOrigOnly',
  724.                                          (event.target.checked) ? 'true' : 'false');
  725.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  726.             BrowserReload();
  727.             break;
  728.  
  729.         case 'scp_allowPopupCount':
  730.             var site = this.ensureExplicitSiteControl();
  731.             sc.updateSiteControlResource(site, 'showBlockedCount',
  732.                                          (event.target.checked) ? 'true' : 'false');
  733.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  734.             BrowserReload();
  735.             break;
  736.  
  737.         case 'scp_allowPopupSound':
  738.             var site = this.ensureExplicitSiteControl();
  739.             sc.updateSiteControlResource(site, 'playBlockedSound',
  740.                                          (event.target.checked) ? 'true' : 'false');
  741.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  742.             BrowserReload();
  743.             break;
  744.  
  745.         case 'scp_allowCookies':
  746.             var site = this.ensureExplicitSiteControl();
  747.             sc.updateSiteControlResource(site, 'allowCookies',
  748.                                          (event.target.checked) ? 'true' : 'false');
  749.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  750.             BrowserReload();
  751.             if (!event.target.checked) sitecontrols.notifyUser('disable_cookies');
  752.             break;
  753.  
  754.         case 'scp_cookiesFromOrigOnly':
  755.             var site = this.ensureExplicitSiteControl();
  756.             sc.updateSiteControlResource(site, 'cookiesFromOrigOnly',
  757.                                          (event.target.checked) ? 'true' : 'false');
  758.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  759.             BrowserReload();
  760.             break;
  761.  
  762.         case 'scp_enableJavaScript':
  763.             var site = this.ensureExplicitSiteControl();
  764.             sc.updateSiteControlResource(site, 'enableJavaScript',
  765.                                          (event.target.checked) ? 'true' : 'false');
  766.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  767.             BrowserReload();
  768.             if (!event.target.checked) sitecontrols.notifyUser('disable_javascript');
  769.             break;
  770.  
  771.         case 'scp_enableJava':
  772.             var site = this.ensureExplicitSiteControl();
  773.             sc.updateSiteControlResource(site, 'enableJava',
  774.                                          (event.target.checked) ? 'true' : 'false');
  775.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  776.             BrowserReload();
  777.             break;
  778.  
  779.         case 'scp_enableActiveX':
  780.             var site = this.ensureExplicitSiteControl();
  781.             sc.updateSiteControlResource(site, 'enableActiveX',
  782.                                          (event.target.checked) ? 'true' : 'false');
  783.             sc.updateSiteControlResource(site, 'securityLevel', 'Custom');
  784.             BrowserReload();
  785.             if (event.target.checked) sitecontrols.notifyUser('enable_activex');
  786.             break;
  787.  
  788.         case 'scp_radio_trust':
  789.             var site = this.ensureExplicitSiteControl();
  790.             sitecontrols.setSecurityLevel(site, 'low');
  791.             BrowserReload();
  792.             break;
  793.  
  794.         case 'scp_radio_standard':
  795.             var site = this.ensureExplicitSiteControl();
  796.             sitecontrols.setSecurityLevel(site, 'medium');
  797.             BrowserReload();
  798.             break;
  799.  
  800.         case 'scp_radio_caution':
  801.             var site = this.ensureExplicitSiteControl();
  802.             sitecontrols.setSecurityLevel(site, 'high');
  803.             BrowserReload();
  804.             break;
  805.  
  806.         default:
  807.             return;
  808.         }
  809.         
  810.         this.addParent(this.currentURI.spec, event);        
  811.         this.loadCurrentSite();
  812.     },
  813.  
  814.  
  815.     ensureExplicitSiteControl : function() {
  816.         var sc = sitecontrols.SCSVC;
  817.         var site = sc.getResourceForURI(this.currentURI.spec);
  818.         if (site.Value != sitecontrols.SC_LOCAL)
  819.         {
  820.             var host = sitecontrols.getStrippedHostFromURL(this.currentURI.spec);
  821.             var pattern = sitecontrols.SCSVC.getControlledSite(host);
  822.             if ((pattern != null) || (host && (host != "") && (host != pattern))) {
  823.                 sitecontrols.SCSVC.addControlledSite(host);
  824.                 site = sitecontrols.SCSVC.getResourceForURI(host);
  825.             }
  826.         }
  827.         return site;
  828.     },
  829.  
  830.     manageSiteList : function() {
  831.         this.close(document.getElementById('SiteControlsPopup'));
  832.         openSiteControlPrefs();
  833.     },
  834.  
  835.  
  836.     close : function(elm) {
  837.         while (elm.localName != 'popup')
  838.             elm = elm.parentNode;
  839.         elm.hidePopup();
  840.     },
  841.  
  842.     debug : function(msg) {
  843.         if (this.DEBUG)
  844.             dump('sitecontrolsOverlay.js: '+msg+'\n');
  845.     }
  846. };
  847.  
  848.  
  849. function showSiteControlsPopup(x, y) {
  850.     var myTab = gBrowser.selectedTab;
  851.     var siteControlPopup = document.getElementById('SiteControlsPopup');
  852.     document.getElementById('SiteControlsPopup')
  853.             .showPopup(myTab, -1, -1, "popup", "bottomleft", "topleft");
  854. }